mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
chore: code refactor to avoid repetitions
This commit is contained in:
@ -113,9 +113,7 @@ export const ProfileForm = ({ className, user }: ProfileFormProps) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onDeleteAccount = async (hasTwoFactorAuthentication: boolean) => {
|
const deleteAccoutAndSignOut = async () => {
|
||||||
try {
|
|
||||||
if (!hasTwoFactorAuthentication) {
|
|
||||||
await deleteAccount();
|
await deleteAccount();
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
@ -125,6 +123,12 @@ export const ProfileForm = ({ className, user }: ProfileFormProps) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return await signOut({ callbackUrl: '/' });
|
return await signOut({ callbackUrl: '/' });
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDeleteAccount = async (hasTwoFactorAuthentication: boolean) => {
|
||||||
|
try {
|
||||||
|
if (!hasTwoFactorAuthentication) {
|
||||||
|
return await deleteAccoutAndSignOut();
|
||||||
}
|
}
|
||||||
|
|
||||||
const { token } = deleteAccountTwoFactorTokenForm.getValues();
|
const { token } = deleteAccountTwoFactorTokenForm.getValues();
|
||||||
@ -140,15 +144,7 @@ export const ProfileForm = ({ className, user }: ProfileFormProps) => {
|
|||||||
throw new Error('We were unable to validate your Two Factor Authentication token.');
|
throw new Error('We were unable to validate your Two Factor Authentication token.');
|
||||||
});
|
});
|
||||||
|
|
||||||
await deleteAccount();
|
await deleteAccoutAndSignOut();
|
||||||
|
|
||||||
toast({
|
|
||||||
title: 'Account deleted',
|
|
||||||
description: 'Your account has been deleted successfully.',
|
|
||||||
duration: 5000,
|
|
||||||
});
|
|
||||||
|
|
||||||
await signOut({ callbackUrl: '/' });
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof TRPCClientError && err.data?.code === 'BAD_REQUEST') {
|
if (err instanceof TRPCClientError && err.data?.code === 'BAD_REQUEST') {
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
import { DocumentStatus } from '@documenso/prisma/client';
|
||||||
|
|
||||||
export type DeleteUserOptions = {
|
export type DeleteUserOptions = {
|
||||||
email: string;
|
email: string;
|
||||||
@ -31,7 +32,7 @@ export const deletedServiceAccount = async ({ email }: DeleteUserOptions) => {
|
|||||||
where: {
|
where: {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
status: {
|
status: {
|
||||||
in: ['PENDING', 'COMPLETED'],
|
in: [DocumentStatus.PENDING, DocumentStatus.COMPLETED],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
Reference in New Issue
Block a user