mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-02 02:30:29 +00:00
Remove unnecessary delete function from user settings
This commit is contained in:
@@ -13,7 +13,6 @@ import {
|
|||||||
Select,
|
Select,
|
||||||
Alert,
|
Alert,
|
||||||
Spinner,
|
Spinner,
|
||||||
Modal,
|
|
||||||
} from '../../components';
|
} from '../../components';
|
||||||
import { Wrapper } from './styles';
|
import { Wrapper } from './styles';
|
||||||
import { ArrowLeft, Profile, Security } from '../../assets';
|
import { ArrowLeft, Profile, Security } from '../../assets';
|
||||||
@@ -24,14 +23,11 @@ import {
|
|||||||
UpdateUserPasswordMutationVariables,
|
UpdateUserPasswordMutationVariables,
|
||||||
GetCountryCodesQuery,
|
GetCountryCodesQuery,
|
||||||
GetCountryCodesQueryVariables,
|
GetCountryCodesQueryVariables,
|
||||||
DeleteUserMutation,
|
|
||||||
DeleteUserMutationVariables,
|
|
||||||
GetUserByIdQuery,
|
GetUserByIdQuery,
|
||||||
GetUserByIdQueryVariables,
|
GetUserByIdQueryVariables,
|
||||||
UserResponseModel,
|
UserResponseModel,
|
||||||
} from '../../graphql/types';
|
} from '../../graphql/types';
|
||||||
import {
|
import {
|
||||||
DELETE_USER,
|
|
||||||
GET_COUNTRY_CODES,
|
GET_COUNTRY_CODES,
|
||||||
GET_USER_BY_ID,
|
GET_USER_BY_ID,
|
||||||
UPDATE_USER_INFO,
|
UPDATE_USER_INFO,
|
||||||
@@ -64,7 +60,6 @@ const UserSettings = () => {
|
|||||||
>('general');
|
>('general');
|
||||||
const [error, setError] = useState<string>('');
|
const [error, setError] = useState<string>('');
|
||||||
const [success, setSuccess] = useState<boolean>(false);
|
const [success, setSuccess] = useState<boolean>(false);
|
||||||
const [deleteAccountModal, setDeleteAccountModal] = useState<boolean>(false);
|
|
||||||
|
|
||||||
const [updateUserInfo, { loading: generalLoading }] = useMutation<
|
const [updateUserInfo, { loading: generalLoading }] = useMutation<
|
||||||
UpdateUserInfoMutation,
|
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' ? (
|
return role === 'admin' ? (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<Box>
|
<Box>
|
||||||
@@ -446,32 +408,6 @@ const UserSettings = () => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{selectedSection === 'security' && (
|
{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}>
|
<form onSubmit={securityForm.handleSubmit}>
|
||||||
<Box
|
<Box
|
||||||
display='grid'
|
display='grid'
|
||||||
@@ -537,7 +473,6 @@ const UserSettings = () => {
|
|||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</form>
|
</form>
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
Reference in New Issue
Block a user