From aa22083e8abd327d1583b894c70e90322af3b2cb Mon Sep 17 00:00:00 2001 From: Paulo Amorim Date: Tue, 19 Nov 2024 16:12:53 -0500 Subject: [PATCH 1/3] Hide organization fields from settings for MMOs --- jsapp/js/account/accountSettingsRoute.tsx | 35 ++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/jsapp/js/account/accountSettingsRoute.tsx b/jsapp/js/account/accountSettingsRoute.tsx index bdaf7368ce..c9ed2c6b4a 100644 --- a/jsapp/js/account/accountSettingsRoute.tsx +++ b/jsapp/js/account/accountSettingsRoute.tsx @@ -20,6 +20,7 @@ import type { } from './account.constants'; import {HELP_ARTICLE_ANON_SUBMISSIONS_URL} from 'js/constants'; import {useSession} from '../stores/useSession'; +import {useOrganizationQuery} from './stripe.api'; bem.AccountSettings = makeBem(null, 'account-settings', 'form'); bem.AccountSettings__left = makeBem(bem.AccountSettings, 'left'); @@ -39,12 +40,16 @@ const AccountSettings = () => { const {currentLoggedAccount, refreshAccount} = useSession(); + const [displayedFields, setDisplayedFields] = useState>([]); + + const orgQuery = useOrganizationQuery(); + useEffect(() => { - if (!currentLoggedAccount) { + if (!currentLoggedAccount || !orgQuery.data) { return; } - setFormFields({ + const fields = { name: currentLoggedAccount.extra_details.name, organization_type: currentLoggedAccount.extra_details.organization_type, organization: currentLoggedAccount.extra_details.organization, @@ -60,8 +65,29 @@ const AccountSettings = () => { instagram: currentLoggedAccount.extra_details.instagram, newsletter_subscription: currentLoggedAccount.extra_details.newsletter_subscription, - }); - }, [currentLoggedAccount]); + }; + + setFormFields(fields); + + const fieldKeys = Object.keys(fields) as Array; + + const organization = orgQuery.data; + + // We will not display organization fields if it's and MMO organization + // in favor of only displaying those fields in organization settings view + setDisplayedFields( + !organization?.is_mmo + ? fieldKeys + : fieldKeys.filter((key) => + ![ + 'organization', + 'organization_website', + 'organization_type', + ].includes(key) + ) + ); + + }, [currentLoggedAccount, orgQuery.data]); usePrompt({ when: !isPristine, @@ -159,6 +185,7 @@ const AccountSettings = () => { errors={fieldErrors} values={formFields} onFieldChange={onFieldChange} + displayedFields={displayedFields} /> )} From 25c0b2cd4ccc5dc2692b76a3566309abb19d7a7c Mon Sep 17 00:00:00 2001 From: Paulo Amorim Date: Thu, 28 Nov 2024 17:10:14 -0300 Subject: [PATCH 2/3] fix import and formatting --- jsapp/js/account/accountSettingsRoute.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jsapp/js/account/accountSettingsRoute.tsx b/jsapp/js/account/accountSettingsRoute.tsx index c9ed2c6b4a..929b12a9f5 100644 --- a/jsapp/js/account/accountSettingsRoute.tsx +++ b/jsapp/js/account/accountSettingsRoute.tsx @@ -20,7 +20,7 @@ import type { } from './account.constants'; import {HELP_ARTICLE_ANON_SUBMISSIONS_URL} from 'js/constants'; import {useSession} from '../stores/useSession'; -import {useOrganizationQuery} from './stripe.api'; +import {useOrganizationQuery} from './organization/organizationQuery'; bem.AccountSettings = makeBem(null, 'account-settings', 'form'); bem.AccountSettings__left = makeBem(bem.AccountSettings, 'left'); @@ -45,6 +45,7 @@ const AccountSettings = () => { const orgQuery = useOrganizationQuery(); useEffect(() => { + if (!currentLoggedAccount || !orgQuery.data) { return; } From f129f12a790225724cf85683947e8eee4d88c859 Mon Sep 17 00:00:00 2001 From: Paulo Amorim Date: Thu, 5 Dec 2024 05:26:08 -0300 Subject: [PATCH 3/3] fix typo --- jsapp/js/account/accountSettingsRoute.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jsapp/js/account/accountSettingsRoute.tsx b/jsapp/js/account/accountSettingsRoute.tsx index 929b12a9f5..3a145b44e1 100644 --- a/jsapp/js/account/accountSettingsRoute.tsx +++ b/jsapp/js/account/accountSettingsRoute.tsx @@ -74,8 +74,8 @@ const AccountSettings = () => { const organization = orgQuery.data; - // We will not display organization fields if it's and MMO organization - // in favor of only displaying those fields in organization settings view + // We will not display organization fields if user is a member of an MMO, + // only displaying these fields in organization settings view setDisplayedFields( !organization?.is_mmo ? fieldKeys