Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(organizations): hide organization fields from settings for mmo organizations - TASK-978 #5280

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 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 './organization/organizationQuery';

bem.AccountSettings = makeBem(null, 'account-settings', 'form');
bem.AccountSettings__left = makeBem(bem.AccountSettings, 'left');
Expand All @@ -39,12 +40,17 @@ 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 +66,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: should be "an MMO organization".

It might be more accurate to say "We will not display organization fields if user is a member of an MMO ..."

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