diff --git a/services/web/frontend/extracted-translations.json b/services/web/frontend/extracted-translations.json index 4ccacf1639..17c1f35251 100644 --- a/services/web/frontend/extracted-translations.json +++ b/services/web/frontend/extracted-translations.json @@ -2,7 +2,9 @@ "access_your_projects_with_git": "", "account_not_linked_to_dropbox": "", "account_settings": "", + "add_another_email": "", "add_files": "", + "add_new_email": "", "add_role_and_department": "", "also": "", "anyone_with_link_can_edit": "", @@ -203,6 +205,7 @@ "invalid_filename": "", "invalid_request": "", "invite_not_accepted": "", + "is_email_affiliated": "", "last_name": "", "layout": "", "layout_processing": "", @@ -210,6 +213,7 @@ "learn_more": "", "learn_more_about_link_sharing": "", "learn_more_about_the_symbol_palette": "", + "let_us_know": "", "link": "", "link_sharing_is_off": "", "link_sharing_is_on": "", diff --git a/services/web/frontend/js/features/settings/components/emails-section.tsx b/services/web/frontend/js/features/settings/components/emails-section.tsx index e42b69f56a..cc010d38e5 100644 --- a/services/web/frontend/js/features/settings/components/emails-section.tsx +++ b/services/web/frontend/js/features/settings/components/emails-section.tsx @@ -7,6 +7,7 @@ import { } from '../context/user-email-context' import EmailsHeader from './emails/header' import EmailsRow from './emails/row' +import AddEmail from './emails/add-email' import Icon from '../../../shared/components/icon' import { Alert } from 'react-bootstrap' import { ExposedSettings } from '../../../../../types/exposed-settings' @@ -16,7 +17,6 @@ function EmailsSectionContent() { const { state: { data: userEmailsData }, isInitializing, - isInitializingSuccess, isInitializingError, } = useUserEmailsContext() const userEmails = Object.values(userEmailsData.byId) @@ -32,30 +32,30 @@ function EmailsSectionContent() {

- {isInitializing && ( -
- {t('loading')}... -
- )} - {isInitializingSuccess && ( - <> - - {userEmails?.map((userEmail, i) => ( - - - {i + 1 !== userEmails.length && ( +
+ + {isInitializing ? ( +
+ {t('loading')}... +
+ ) : ( + <> + {userEmails?.map(userEmail => ( + +
- )} - - ))} - - )} - {isInitializingError && ( - - {' '} - {t('error_performing_request')} - - )} + + ))} + + )} + + {isInitializingError && ( + + {' '} + {t('error_performing_request')} + + )} +
) } diff --git a/services/web/frontend/js/features/settings/components/emails/add-email.tsx b/services/web/frontend/js/features/settings/components/emails/add-email.tsx new file mode 100644 index 0000000000..b337e65f4f --- /dev/null +++ b/services/web/frontend/js/features/settings/components/emails/add-email.tsx @@ -0,0 +1,145 @@ +import { useState, useEffect } from 'react' +import { useTranslation } from 'react-i18next' +import { Button, Row, Col } from 'react-bootstrap' +import Cell from './cell' +import useAsync from '../../../../shared/hooks/use-async' +import { useUserEmailsContext } from '../../context/user-email-context' +import { postJSON } from '../../../../infrastructure/fetch-json' +import Icon from '../../../../shared/components/icon' + +const isValidEmail = (email: string) => { + return Boolean(email) +} + +function AddEmail() { + const { t } = useTranslation() + const [isFormVisible, setIsFormVisible] = useState( + () => window.location.hash === '#add-email' + ) + const [newEmail, setNewEmail] = useState('') + const [isInstitutionFieldsVisible, setIsInstitutionFieldsVisible] = + useState(false) + const { isLoading, isError, runAsync } = useAsync() + const { + state, + setLoading: setUserEmailsContextLoading, + getEmails, + } = useUserEmailsContext() + + useEffect(() => { + setUserEmailsContextLoading(isLoading) + }, [setUserEmailsContextLoading, isLoading]) + + const handleShowAddEmailForm = () => { + setIsFormVisible(true) + } + + const handleShowInstitutionFields = () => { + setIsInstitutionFieldsVisible(true) + } + + const handleEmailChange = (event: React.ChangeEvent) => { + setNewEmail(event.target.value) + } + + const handleAddNewEmail = () => { + runAsync( + postJSON('/user/emails', { + body: { + email: newEmail, + }, + }) + ) + .then(() => { + getEmails() + setIsFormVisible(false) + setNewEmail('') + }) + .catch(error => { + console.error(error) + }) + } + + return ( +
+ + {!isFormVisible ? ( + + + + + + ) : ( +
+ + + + + + + + + {isInstitutionFieldsVisible ? ( + <> +
+ +
+
+ +
+ + ) : ( +
+ {t('is_email_affiliated')} +
+ +
+ )} +
+ + + + + {isError && ( +
+ {' '} + {t('error_performing_request')} +
+ )} +
+ +
+ )} +
+
+ ) +} + +export default AddEmail diff --git a/services/web/frontend/js/features/settings/components/emails/institution-and-role.tsx b/services/web/frontend/js/features/settings/components/emails/institution-and-role.tsx index 2d87ad7d50..602f7fde4b 100644 --- a/services/web/frontend/js/features/settings/components/emails/institution-and-role.tsx +++ b/services/web/frontend/js/features/settings/components/emails/institution-and-role.tsx @@ -99,7 +99,7 @@ function InstitutionAndRole({ userEmailData }: InstitutionAndRoleProps) { setValue={setDepartment} />