From bec14bb09a8fbdd6d178cb4e1ca7b3d9bd3d6a93 Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Fri, 7 May 2021 01:45:37 +0100 Subject: [PATCH] Remove unnecessary delete function from user settings --- src/pages/UserSettings/index.tsx | 183 ++++++++++--------------------- 1 file changed, 59 insertions(+), 124 deletions(-) diff --git a/src/pages/UserSettings/index.tsx b/src/pages/UserSettings/index.tsx index 9cca628..fbd78b8 100644 --- a/src/pages/UserSettings/index.tsx +++ b/src/pages/UserSettings/index.tsx @@ -13,7 +13,6 @@ import { Select, Alert, Spinner, - Modal, } from '../../components'; import { Wrapper } from './styles'; import { ArrowLeft, Profile, Security } from '../../assets'; @@ -24,14 +23,11 @@ import { UpdateUserPasswordMutationVariables, GetCountryCodesQuery, GetCountryCodesQueryVariables, - DeleteUserMutation, - DeleteUserMutationVariables, GetUserByIdQuery, GetUserByIdQueryVariables, UserResponseModel, } from '../../graphql/types'; import { - DELETE_USER, GET_COUNTRY_CODES, GET_USER_BY_ID, UPDATE_USER_INFO, @@ -64,7 +60,6 @@ const UserSettings = () => { >('general'); const [error, setError] = useState(''); const [success, setSuccess] = useState(false); - const [deleteAccountModal, setDeleteAccountModal] = useState(false); const [updateUserInfo, { loading: generalLoading }] = useMutation< UpdateUserInfoMutation, @@ -184,39 +179,6 @@ const UserSettings = () => { }), }); - const [deleteUser] = useMutation< - DeleteUserMutation, - DeleteUserMutationVariables - >(DELETE_USER, { - onCompleted() { - setDeleteAccountModal(false); - history.goBack(); - }, - onError({ graphQLErrors }) { - setDeleteAccountModal(false); - setError(graphQLErrors[0]?.extensions?.info); - setTimeout(() => setError(''), 3000); - }, - }); - - const deleteAccountForm = useFormik({ - initialValues: { - password: '', - }, - validationSchema: Yup.object().shape({ - password: Yup.string() - .required('Password is required') - .min(6, 'Password is 6 characters minimum'), - }), - onSubmit: ({ password }, { resetForm }) => { - try { - deleteUser({ variables: { id: userToEdit?.id!, password } }); - } finally { - resetForm(); - } - }, - }); - return role === 'admin' ? ( @@ -446,98 +408,71 @@ const UserSettings = () => { )} {selectedSection === 'security' && ( - <> - {deleteAccountModal && ( - + + setDeleteAccountModal(false)} - onConfirm={deleteAccountForm.handleSubmit} - > - - - )} -
+ type='password' + value={securityForm.values.oldPassword} + onChange={securityForm.handleChange} + onBlur={securityForm.handleBlur} + error={ + securityForm.touched.oldPassword && + !!securityForm.errors.oldPassword + } + errorMessage={securityForm.errors.oldPassword} + /> + + - - - - -