-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
265 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use client" | ||
|
||
import * as React from "react" | ||
import { ProfileDeleteDialog } from "./ProfileDeleteDialog" | ||
import { Button } from "./ui/button" | ||
|
||
export default function ProfileDeleteButton() { | ||
const [showDeleteDialog, setShowDeleteDialog] = React.useState(false) | ||
return ( | ||
<> | ||
<ProfileDeleteDialog | ||
open={showDeleteDialog} | ||
onOpenChange={setShowDeleteDialog} | ||
showTrigger={false} | ||
onSuccess={() => setShowDeleteDialog(false)} | ||
/> | ||
<Button | ||
onClick={() => setShowDeleteDialog(true)} | ||
size={"sm"} | ||
variant={"destructive"} | ||
> | ||
Delete | ||
</Button> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use client" | ||
|
||
import ProfileDeleteButton from "./ProfileDeleteButton" | ||
import { Card, CardContent, CardFooter, CardHeader } from "./ui/card" | ||
|
||
export function ProfileDeleteCard() { | ||
return ( | ||
<Card> | ||
<CardHeader className="text-red-400">Delete account</CardHeader> | ||
<CardContent className="flex flex-col gap-4"> | ||
Once you delete your account, there is no going back. Please be certain. | ||
</CardContent> | ||
<CardFooter> | ||
<ProfileDeleteButton /> | ||
</CardFooter> | ||
</Card> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
"use client" | ||
|
||
import { Button } from "@/components/ui/button" | ||
import { | ||
Dialog, | ||
DialogClose, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "@/components/ui/dialog" | ||
import { | ||
Drawer, | ||
DrawerClose, | ||
DrawerContent, | ||
DrawerDescription, | ||
DrawerFooter, | ||
DrawerHeader, | ||
DrawerTitle, | ||
DrawerTrigger, | ||
} from "@/components/ui/drawer" | ||
import { useMediaQuery } from "@/hooks/useMediaQuery" | ||
import { deleteOwnAccount } from "@/services/settings/api" | ||
import { TrashIcon } from "@radix-ui/react-icons" | ||
import { useRouter } from "next/navigation" | ||
import * as React from "react" | ||
import { toast } from "sonner" | ||
import { Icons } from "./icons" | ||
|
||
interface DeleteProfileDialogProps | ||
extends React.ComponentPropsWithoutRef<typeof Dialog> { | ||
showTrigger?: boolean | ||
onSuccess?: () => void | ||
} | ||
|
||
export function ProfileDeleteDialog({ | ||
showTrigger = true, | ||
onSuccess, | ||
...props | ||
}: DeleteProfileDialogProps) { | ||
const router = useRouter() | ||
const [isDeletePending, startDeleteTransition] = React.useTransition() | ||
const isDesktop = useMediaQuery("(min-width: 640px)") | ||
const DRAWER_TITLE = "Are you absolutely sure?" | ||
const DRAWER_DESCRIPTION = | ||
"This action cannot be undone. It will permanently delete your account from your Myntenance. This action will not affect your GitHub repository." | ||
|
||
function onDelete() { | ||
startDeleteTransition(async () => { | ||
try { | ||
const res = await deleteOwnAccount() | ||
router.push("/") | ||
onSuccess?.() | ||
toast.success(`Your account was successfully deleted!`) | ||
} catch (error: unknown) { | ||
const message = | ||
error instanceof Error | ||
? error.message | ||
: "An error occurred while deleting your account." | ||
toast.error(message) | ||
} | ||
}) | ||
} | ||
|
||
if (isDesktop) { | ||
return ( | ||
<Dialog {...props}> | ||
{showTrigger ? ( | ||
<DialogTrigger asChild> | ||
<Button variant="outline" size="sm"> | ||
<TrashIcon className="mr-2 size-4" aria-hidden="true" /> | ||
Delete | ||
</Button> | ||
</DialogTrigger> | ||
) : null} | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>{DRAWER_TITLE}</DialogTitle> | ||
<DialogDescription>{DRAWER_DESCRIPTION}</DialogDescription> | ||
</DialogHeader> | ||
<DialogFooter className="gap-2 sm:space-x-0"> | ||
<DialogClose asChild> | ||
<Button variant="outline">Cancel</Button> | ||
</DialogClose> | ||
<Button | ||
aria-label="Delete your account" | ||
variant="destructive" | ||
onClick={onDelete} | ||
disabled={isDeletePending} | ||
> | ||
{isDeletePending && ( | ||
<Icons.spinner | ||
className="mr-2 size-4 animate-spin" | ||
aria-hidden="true" | ||
/> | ||
)} | ||
Delete | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
} | ||
|
||
return ( | ||
<Drawer {...props}> | ||
{showTrigger ? ( | ||
<DrawerTrigger asChild> | ||
<Button variant="outline" size="sm"> | ||
<TrashIcon className="mr-2 size-4" aria-hidden="true" /> | ||
Delete | ||
</Button> | ||
</DrawerTrigger> | ||
) : null} | ||
<DrawerContent> | ||
<DrawerHeader> | ||
<DrawerTitle>{DRAWER_TITLE}</DrawerTitle> | ||
<DrawerDescription>{DRAWER_DESCRIPTION}</DrawerDescription> | ||
</DrawerHeader> | ||
<DrawerFooter className="gap-2 sm:space-x-0"> | ||
<DrawerClose asChild> | ||
<Button variant="outline">Cancel</Button> | ||
</DrawerClose> | ||
<Button | ||
aria-label="Delete selected repository" | ||
variant="destructive" | ||
onClick={onDelete} | ||
disabled={isDeletePending} | ||
> | ||
{isDeletePending && ( | ||
<Icons.spinner | ||
className="mr-2 size-4 animate-spin" | ||
aria-hidden="true" | ||
/> | ||
)} | ||
Delete | ||
</Button> | ||
</DrawerFooter> | ||
</DrawerContent> | ||
</Drawer> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters