Skip to content

Commit

Permalink
feat(profile): update non-admin delete flow
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao authored Nov 26, 2024
1 parent fa78dab commit bae45b2
Showing 1 changed file with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const useDeleteAccount = (closeDialog: VoidFunction) => {
const [isDeleteCong, setIsDeleteCong] = useState(false);
const [isManageAccess, setIsManageAccess] = useState(false);

const { data } = useQuery({
const { data, isLoading: isLoadingUsers } = useQuery({
queryKey: ['admin-users'],
queryFn: apiCongregationUsersGet,
enabled: isAdmin,
Expand Down Expand Up @@ -84,15 +84,18 @@ const useDeleteAccount = (closeDialog: VoidFunction) => {
navigate('/manage-access');
};

useEffect(() => {
if (!isAdmin) {
setDesc(t('tr_deleteAccountDesc'));
setIsLoading(false);
}
}, [isAdmin]);

Check warning on line 92 in src/features/my_profile/security/delete_account/useDeleteAccount.tsx

View workflow job for this annotation

GitHub Actions / CPE Cypress CI

React Hook useEffect has a missing dependency: 't'. Either include it or remove the dependency array

useEffect(() => {
const loadDetails = async () => {
try {
if (!isAdmin) {
setDesc(t('tr_deleteAccountDesc'));
setIsLoading(false);
return;
}
setIsLoading(true);

try {
if (users.length === 1) {
setDesc(t('tr_deleteAccountWithCongregationDesc'));
setIsDeleteCong(true);
Expand All @@ -106,9 +109,11 @@ const useDeleteAccount = (closeDialog: VoidFunction) => {
return;
}

setDesc(t('tr_deleteAccountAssignAdminFirst'));
setIsManageAccess(true);
setIsLoading(false);
if (adminCount === 1) {
setDesc(t('tr_deleteAccountAssignAdminFirst'));
setIsManageAccess(true);
setIsLoading(false);
}
} catch (error) {
closeDialog();

Expand All @@ -120,8 +125,8 @@ const useDeleteAccount = (closeDialog: VoidFunction) => {
}
};

loadDetails();
}, [isAdmin, t, closeDialog, users, adminCount]);
if (isAdmin && !isLoadingUsers) loadDetails();
}, [isAdmin, t, closeDialog, users, adminCount, isLoadingUsers]);

return {
isProcessing,
Expand Down

0 comments on commit bae45b2

Please sign in to comment.