import { useMutation } from '@apollo/client'; import { yupResolver } from '@hookform/resolvers/yup'; import Alert from '@mui/material/Alert'; import AlertTitle from '@mui/material/AlertTitle'; import Button from '@mui/material/Button'; import Grid from '@mui/material/Grid'; import Typography from '@mui/material/Typography'; import { styled } from '@mui/material/styles'; import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar'; import * as React from 'react'; import * as yup from 'yup'; import Container from 'components/Container'; import DeleteAccountDialog from 'components/DeleteAccountDialog/index.ee'; import Form from 'components/Form'; import PageTitle from 'components/PageTitle'; import TextField from 'components/TextField'; import { UPDATE_CURRENT_USER } from 'graphql/mutations/update-current-user'; import useCurrentUser from 'hooks/useCurrentUser'; import useFormatMessage from 'hooks/useFormatMessage'; import { useQueryClient } from '@tanstack/react-query'; const validationSchema = yup .object({ fullName: yup.string().required(), email: yup.string().email().required(), password: yup.string(), confirmPassword: yup .string() .oneOf([yup.ref('password')], 'Passwords must match'), }) .required(); const StyledForm = styled(Form)` display: flex; align-items: end; flex-direction: column; `; function ProfileSettings() { const [showDeleteAccountConfirmation, setShowDeleteAccountConfirmation] = React.useState(false); const enqueueSnackbar = useEnqueueSnackbar(); const { data } = useCurrentUser(); const currentUser = data?.data; const formatMessage = useFormatMessage(); const [updateCurrentUser] = useMutation(UPDATE_CURRENT_USER); const queryClient = useQueryClient(); const handleProfileSettingsUpdate = async (data) => { const { fullName, password, email } = data; const mutationInput = { fullName, email, }; if (password) { mutationInput.password = password; } await updateCurrentUser({ variables: { input: mutationInput, }, optimisticResponse: { updateCurrentUser: { __typename: 'User', id: currentUser.id, fullName, email, }, }, }); await queryClient.invalidateQueries({ queryKey: ['users', 'me'] }); enqueueSnackbar(formatMessage('profileSettings.updatedProfile'), { variant: 'success', SnackbarProps: { 'data-test': 'snackbar-update-profile-settings-success', }, }); }; return ( {formatMessage('profileSettings.title')} ( <> )} /> {formatMessage('profileSettings.deleteMyAccount')} {formatMessage('profileSettings.deleteAccountSubtitle')}
  1. {formatMessage('profileSettings.deleteAccountResult1')}
  2. {formatMessage('profileSettings.deleteAccountResult2')}
  3. {formatMessage('profileSettings.deleteAccountResult3')}
  4. {formatMessage('profileSettings.deleteAccountResult4')}
{showDeleteAccountConfirmation && ( setShowDeleteAccountConfirmation(false)} /> )}
); } export default ProfileSettings;