From b5b661316b69ab34bd4730a49e4045d1d8781f5b Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 4 Oct 2023 12:24:53 +0800 Subject: [PATCH] Add a confirmation when switching from social to email based login --- packages/web/pages/settings/account.tsx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/web/pages/settings/account.tsx b/packages/web/pages/settings/account.tsx index 18f66b19e..88f67e075 100644 --- a/packages/web/pages/settings/account.tsx +++ b/packages/web/pages/settings/account.tsx @@ -17,6 +17,7 @@ import { useGetViewerQuery } from '../../lib/networking/queries/useGetViewerQuer import { useValidateUsernameQuery } from '../../lib/networking/queries/useValidateUsernameQuery' import { applyStoredTheme } from '../../lib/themeUpdater' import { showErrorToast, showSuccessToast } from '../../lib/toastHelpers' +import { ConfirmationModal } from '../../components/patterns/ConfirmationModal' const StyledLabel = styled('label', { fontWeight: 600, @@ -51,6 +52,8 @@ export default function Account(): JSX.Element { const [email, setEmail] = useState('') const [emailUpdating, setEmailUpdating] = useState(false) const [source, setSource] = useState('') + const [showUpdateEmailConfirmation, setShowUpdateEmailConfirmation] = + useState(false) const [debouncedUsername, setDebouncedUsername] = useState('') const { usernameErrorMessage, isLoading: isUsernameValidationLoading } = @@ -170,6 +173,7 @@ export default function Account(): JSX.Element { const updateEmail = useCallback(() => { setEmailUpdating(true) + setShowUpdateEmailConfirmation(false) ;(async () => { const response = await updateEmailMutation({ email }) if (response) { @@ -329,7 +333,12 @@ export default function Account(): JSX.Element { >
{ - updateEmail() + // Show a confirmation dialog if switching from social login + if (source == 'EMAIL') { + updateEmail() + } else { + setShowUpdateEmailConfirmation(true) + } event.preventDefault() }} > @@ -389,6 +398,16 @@ export default function Account(): JSX.Element { */} + + {showUpdateEmailConfirmation ? ( + setShowUpdateEmailConfirmation(false)} + /> + ) : null} ) }