diff --git a/src/pages/AccountSettings/tabs/DeletionCard/DeletionCard.test.tsx b/src/pages/AccountSettings/tabs/DeletionCard/DeletionCard.test.tsx index 909838b001..4ffa43b2e4 100644 --- a/src/pages/AccountSettings/tabs/DeletionCard/DeletionCard.test.tsx +++ b/src/pages/AccountSettings/tabs/DeletionCard/DeletionCard.test.tsx @@ -1,12 +1,19 @@ +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { render, screen } from '@testing-library/react' import { MemoryRouter, Route } from 'react-router-dom' import DeletionCard from './DeletionCard' +const queryClient = new QueryClient({ + defaultOptions: { queries: { retry: false } }, +}) + const wrapper: React.FC = ({ children }) => ( - - {children} - + + + {children} + + ) describe('DeletionCard', () => { diff --git a/src/pages/AccountSettings/tabs/DeletionCard/DeletionCard.tsx b/src/pages/AccountSettings/tabs/DeletionCard/DeletionCard.tsx index 55d8864049..ca348fbf98 100644 --- a/src/pages/AccountSettings/tabs/DeletionCard/DeletionCard.tsx +++ b/src/pages/AccountSettings/tabs/DeletionCard/DeletionCard.tsx @@ -1,29 +1,86 @@ +import { useState } from 'react' +import { useParams } from 'react-router-dom' + import Card from 'old_ui/Card' -import A from 'ui/A' +import { useEraseAccount } from 'services/account' +import Button from 'ui/Button' + +import EraseOwnerModal from './EraseOwnerModal' interface DeletionCardProps { isPersonalSettings: boolean } +interface EraseOwnerButtonProps { + isPersonalSettings: boolean + isLoading: boolean + setShowModal: (_: boolean) => void +} + +function EraseOwnerButton({ + isPersonalSettings, + isLoading, + setShowModal, +}: EraseOwnerButtonProps) { + const button = isPersonalSettings + ? 'Erase Personal Account' + : 'Erase Organization' + + if (isLoading) { + return ( +
+ processing erase, this may take a while +
+ ) + } + + return ( + + ) +} + +interface URLParams { + provider?: string + owner?: string +} + function DeletionCard({ isPersonalSettings }: DeletionCardProps) { + const { provider, owner } = useParams() + const [showModal, setShowModal] = useState(false) + const { mutate: eraseOwner, isLoading } = useEraseAccount({ provider, owner }) + + const title = isPersonalSettings ? 'Delete account' : 'Delete organization' + const text = isPersonalSettings + ? 'Erase my personal account and all my repositories.' + : 'Erase organization and all its repositories.' + return (
-

- {isPersonalSettings ? 'Delete account' : 'Delete organization'} -

- -

- {isPersonalSettings - ? 'Erase my personal account and all my repositories. ' - : 'Erase organization and all its repositories. '} - - Contact support - -

+

{title}

+ +
+

{text}

+
+
+ + setShowModal(false)} + eraseOwner={eraseOwner} + /> +
) diff --git a/src/pages/AccountSettings/tabs/DeletionCard/EraseOwnerModal.tsx b/src/pages/AccountSettings/tabs/DeletionCard/EraseOwnerModal.tsx new file mode 100644 index 0000000000..09026bdef4 --- /dev/null +++ b/src/pages/AccountSettings/tabs/DeletionCard/EraseOwnerModal.tsx @@ -0,0 +1,65 @@ +import Button from 'ui/Button' +import Modal from 'ui/Modal' + +interface EraseOwnerModelProps { + isPersonalSettings: boolean + isLoading: boolean + showModal: boolean + closeModal: () => void + eraseOwner: () => void +} + +function EraseOwnerModal({ + isPersonalSettings, + closeModal, + eraseOwner, + isLoading, + showModal, +}: EraseOwnerModelProps) { + const title = isPersonalSettings + ? 'Are you sure you want to delete your personal account?' + : 'Are you sure you want to erase this organization?' + let text = isPersonalSettings + ? 'This action will delete all personal data, including login information and personal tokens.' + : 'This action will delete all organization content and associated tokens.' + text += + ' It will also erase all of the repositories, including all of their contents.' + text += + ' This action is irreversible and if you proceed, you will permanently erase all of the associated content.' + const button = isPersonalSettings + ? 'Erase Personal Account' + : 'Erase Organization' + + return ( + {text}

} + footer={ +
+
+ +
+
+ +
+
+ } + /> + ) +} + +export default EraseOwnerModal