Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/shared/src/components/profile/AccountDangerZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface AccountDangerZoneProps {
onDelete: () => void;
className?: string;
children?: ReactNode;
buttonDisabled?: boolean;
buttonLoading?: boolean;
}

const Important = () => (
Expand Down Expand Up @@ -48,6 +50,8 @@ const ImportantActiveAppleSubscription = () => {
function AccountDangerZone({
onDelete,
className,
buttonDisabled = false,
buttonLoading = false,
}: AccountDangerZoneProps): ReactElement {
const { isPlus, status, plusProvider } = usePlusSubscription();

Expand All @@ -70,7 +74,8 @@ function AccountDangerZone({
important={
disableDeletion ? <ImportantActiveAppleSubscription /> : <Important />
}
buttonDisabled={disableDeletion}
buttonDisabled={disableDeletion || buttonDisabled}
buttonLoading={buttonLoading}
/>
);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/components/widgets/DangerZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface DangerZoneProps {
onClick: () => void;
className?: string;
buttonDisabled?: boolean;
buttonLoading?: boolean;
}

export function DangerZone({
Expand All @@ -29,6 +30,7 @@ export function DangerZone({
onClick,
children,
buttonDisabled = false,
buttonLoading = false,
}: DangerZoneProps): ReactElement {
return (
<section
Expand Down Expand Up @@ -59,6 +61,7 @@ export function DangerZone({
className="mt-6 self-start"
type="button"
disabled={buttonDisabled}
loading={buttonLoading}
>
{cta}
</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React, { useState } from 'react';
import type { FormEvent, MutableRefObject, ReactElement } from 'react';
import { providerMap } from '@dailydotdev/shared/src/components/auth/common';
import {
Button,
Expand All @@ -7,9 +9,7 @@ import {
} from '@dailydotdev/shared/src/components/buttons/Button';
import { LockIcon, MailIcon } from '@dailydotdev/shared/src/components/icons';
import AccountDangerZone from '@dailydotdev/shared/src/components/profile/AccountDangerZone';
import AuthContext from '@dailydotdev/shared/src/contexts/AuthContext';
import type { FormEvent, MutableRefObject, ReactElement } from 'react';
import React, { useContext, useState } from 'react';
import { useAuthContext } from '@dailydotdev/shared/src/contexts/AuthContext';
import type {
AuthSession,
KratosProviderData,
Expand All @@ -33,6 +33,7 @@ import { capitalize } from '@dailydotdev/shared/src/lib/strings';
import { BOOT_LOCAL_KEY } from '@dailydotdev/shared/src/contexts/common';
import { DEFAULT_ERROR } from '@dailydotdev/shared/src/graphql/common';
import { Tooltip } from '@dailydotdev/shared/src/components/tooltip/Tooltip';
import { useMutation } from '@tanstack/react-query';
import AccountContentSection from '../AccountContentSection';
import { AccountPageContainer } from '../AccountPageContainer';
import type { ManageSocialProvidersProps } from '../common';
Expand Down Expand Up @@ -118,7 +119,7 @@ function AccountSecurityDefault({
onUpdatePassword,
onUpdateProviders,
}: AccountSecurityDefaultProps): ReactElement {
const { deleteAccount } = useContext(AuthContext);
const { deleteAccount } = useAuthContext();
const { displayToast } = useToastNotification();
const { onUpdateSignBack } = useSignBack();
const [linkProvider, setLinkProvider] = useState(null);
Expand Down Expand Up @@ -152,19 +153,22 @@ function AccountSecurityDefault({
manageSocialProviders({ type: 'unlink', provider });
}
};
const deleteAccountPrompt = async () => {
if (await showPrompt(deleteAccountPromptOptions)) {
try {
const { mutate: deleteAccountPrompt, isPending: isDeleting } = useMutation({
mutationKey: ['deleteAccount'],
mutationFn: async () => {
if (await showPrompt(deleteAccountPromptOptions)) {
await deleteAccount();
} catch (error) {
displayToast(DEFAULT_ERROR);
return;
}
},
onError: () => {
displayToast(DEFAULT_ERROR);
},
onSuccess: async () => {
await onUpdateSignBack(null, null);
globalThis?.localStorage.removeItem(BOOT_LOCAL_KEY);
window.location.replace('/');
}
};
},
});

useEventListener(globalThis, 'message', async (e) => {
if (e.data?.eventKey !== AuthEvent.SocialRegistration) {
Expand Down Expand Up @@ -287,6 +291,7 @@ function AccountSecurityDefault({
<AccountDangerZone
onDelete={() => deleteAccountPrompt()}
className="mt-6"
buttonLoading={isDeleting}
/>
</AccountContentSection>
</AccountPageContainer>
Expand Down