Skip to content

Commit

Permalink
Hide organization fields from settings for MMOs
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloamorimbr committed Nov 28, 2024
1 parent aaa8aac commit aa22083
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions jsapp/js/account/accountSettingsRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 23 in jsapp/js/account/accountSettingsRoute.tsx

View workflow job for this annotation

GitHub Actions / build (16.15.0)

Module '"./stripe.api"' has no exported member 'useOrganizationQuery'.

Check failure on line 23 in jsapp/js/account/accountSettingsRoute.tsx

View workflow job for this annotation

GitHub Actions / build (20.17.0)

Module '"./stripe.api"' has no exported member 'useOrganizationQuery'.

Check failure on line 23 in jsapp/js/account/accountSettingsRoute.tsx

View workflow job for this annotation

GitHub Actions / build (20)

Module '"./stripe.api"' has no exported member 'useOrganizationQuery'.

Check failure on line 23 in jsapp/js/account/accountSettingsRoute.tsx

View workflow job for this annotation

GitHub Actions / build (22)

Module '"./stripe.api"' has no exported member 'useOrganizationQuery'.

bem.AccountSettings = makeBem(null, 'account-settings', 'form');
bem.AccountSettings__left = makeBem(bem.AccountSettings, 'left');
Expand All @@ -39,12 +40,16 @@ const AccountSettings = () => {

const {currentLoggedAccount, refreshAccount} = useSession();

const [displayedFields, setDisplayedFields] = useState<Array<keyof AccountFieldsValues>>([]);

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,
Expand All @@ -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<keyof AccountFieldsValues>;

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,
Expand Down Expand Up @@ -159,6 +185,7 @@ const AccountSettings = () => {
errors={fieldErrors}
values={formFields}
onFieldChange={onFieldChange}
displayedFields={displayedFields}
/>
</bem.AccountSettings__item>
)}
Expand Down

0 comments on commit aa22083

Please sign in to comment.