|
| 1 | +import { useState } from 'react' |
| 2 | +import { useParams } from 'react-router-dom' |
| 3 | + |
1 | 4 | import Card from 'old_ui/Card'
|
2 |
| -import A from 'ui/A' |
| 5 | +import { useEraseAccount } from 'services/account' |
| 6 | +import Button from 'ui/Button' |
| 7 | + |
| 8 | +import EraseOwnerModal from './EraseOwnerModal' |
3 | 9 |
|
4 | 10 | interface DeletionCardProps {
|
5 | 11 | isPersonalSettings: boolean
|
6 | 12 | }
|
7 | 13 |
|
| 14 | +interface EraseOwnerButtonProps { |
| 15 | + isPersonalSettings: boolean |
| 16 | + isLoading: boolean |
| 17 | + setShowModal: (_: boolean) => void |
| 18 | +} |
| 19 | + |
| 20 | +function EraseOwnerButton({ |
| 21 | + isPersonalSettings, |
| 22 | + isLoading, |
| 23 | + setShowModal, |
| 24 | +}: EraseOwnerButtonProps) { |
| 25 | + const button = isPersonalSettings |
| 26 | + ? 'Erase Personal Account' |
| 27 | + : 'Erase Organization' |
| 28 | + |
| 29 | + if (isLoading) { |
| 30 | + return ( |
| 31 | + <div className="font-light italic"> |
| 32 | + processing erase, this may take a while |
| 33 | + </div> |
| 34 | + ) |
| 35 | + } |
| 36 | + |
| 37 | + return ( |
| 38 | + <Button |
| 39 | + variant="danger" |
| 40 | + hook="show-modal" |
| 41 | + onClick={() => setShowModal(true)} |
| 42 | + > |
| 43 | + {button} |
| 44 | + </Button> |
| 45 | + ) |
| 46 | +} |
| 47 | + |
| 48 | +interface URLParams { |
| 49 | + provider?: string |
| 50 | + owner?: string |
| 51 | +} |
| 52 | + |
8 | 53 | function DeletionCard({ isPersonalSettings }: DeletionCardProps) {
|
| 54 | + const { provider, owner } = useParams<URLParams>() |
| 55 | + const [showModal, setShowModal] = useState(false) |
| 56 | + const { mutate: eraseOwner, isLoading } = useEraseAccount({ provider, owner }) |
| 57 | + |
| 58 | + const title = isPersonalSettings ? 'Delete account' : 'Delete organization' |
| 59 | + const text = isPersonalSettings |
| 60 | + ? 'Erase my personal account and all my repositories.' |
| 61 | + : 'Erase organization and all its repositories.' |
| 62 | + |
9 | 63 | return (
|
10 | 64 | <div className="flex flex-col gap-4">
|
11 |
| - <h2 className="text-lg font-semibold"> |
12 |
| - {isPersonalSettings ? 'Delete account' : 'Delete organization'} |
13 |
| - </h2> |
14 |
| - <Card> |
15 |
| - <p> |
16 |
| - {isPersonalSettings |
17 |
| - ? 'Erase my personal account and all my repositories. ' |
18 |
| - : 'Erase organization and all its repositories. '} |
19 |
| - <A |
20 |
| - to={{ pageName: 'support' }} |
21 |
| - hook="contact-support-link" |
22 |
| - isExternal |
23 |
| - > |
24 |
| - Contact support |
25 |
| - </A> |
26 |
| - </p> |
| 65 | + <h2 className="text-lg font-semibold">{title}</h2> |
| 66 | + <Card className="flex flex-col sm:flex-row"> |
| 67 | + <div className="flex flex-1 flex-col gap-1"> |
| 68 | + <p> {text} </p> |
| 69 | + </div> |
| 70 | + <div> |
| 71 | + <EraseOwnerButton |
| 72 | + isPersonalSettings={isPersonalSettings} |
| 73 | + isLoading={isLoading} |
| 74 | + setShowModal={setShowModal} |
| 75 | + /> |
| 76 | + <EraseOwnerModal |
| 77 | + isPersonalSettings={isPersonalSettings} |
| 78 | + isLoading={isLoading} |
| 79 | + showModal={showModal} |
| 80 | + closeModal={() => setShowModal(false)} |
| 81 | + eraseOwner={eraseOwner} |
| 82 | + /> |
| 83 | + </div> |
27 | 84 | </Card>
|
28 | 85 | </div>
|
29 | 86 | )
|
|
0 commit comments