Remove unnecessary delete function from user settings

This commit is contained in:
Hazem Krimi
2021-05-07 01:45:37 +01:00
parent ccfc863728
commit bec14bb09a
-65
View File
@@ -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<string>('');
const [success, setSuccess] = useState<boolean>(false);
const [deleteAccountModal, setDeleteAccountModal] = useState<boolean>(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' ? (
<Wrapper>
<Box>
@@ -446,32 +408,6 @@ const UserSettings = () => {
</>
)}
{selectedSection === 'security' && (
<>
{deleteAccountModal && (
<Modal
color={role || 'client'}
title='Delete Account'
description='Enter password to confirm account deletion.
If you delete your account you cannot recover any of your projects.'
onClose={() => setDeleteAccountModal(false)}
onConfirm={deleteAccountForm.handleSubmit}
>
<Input
type='password'
placeholder='Password'
name='password'
value={deleteAccountForm.values.password}
onChange={deleteAccountForm.handleChange}
onBlur={deleteAccountForm.handleBlur}
color={role || 'client'}
error={
deleteAccountForm.touched.password &&
!!deleteAccountForm.errors.password
}
errorMessage={deleteAccountForm.errors.password}
/>
</Modal>
)}
<form onSubmit={securityForm.handleSubmit}>
<Box
display='grid'
@@ -537,7 +473,6 @@ const UserSettings = () => {
</Box>
</Box>
</form>
</>
)}
</Box>
</Box>