| 1 | "use client"; |
| 2 | |
| 3 | import { Trash2 } from |
| 4 | import { useAction } |
| 5 | |
| 6 | import { deleteBranch } |
| 7 | import { |
| 8 | AlertDialog, |
| 9 | AlertDialogCancel, |
| 10 | AlertDialogContent, |
| 11 | AlertDialogDescription, |
| 12 | AlertDialogFooter, |
| 13 | AlertDialogHeader, |
| 14 | AlertDialogTitle, |
| 15 | AlertDialogTrigger, |
| 16 | } from "@/components/ui/alert-dialog"; |
| 17 | import { Button } |
| 18 | import { FieldError } |
| 19 | import { Spinner } |
| 20 | |
| 21 | export function DeleteBranchButton({ |
| 22 | username, |
| 23 | repo, |
| 24 | branch, |
| 25 | }: { |
| 26 | username: string |
| 27 | repo: string |
| 28 | branch: string |
| 29 | }) { |
| 30 | const { execute, |
| 31 | |
| 32 | return ( |
| 33 | <AlertDialog> |
| 34 | <AlertDialogTrigger asChild> |
| 35 | <Button variant=" |
| 36 | <Trash2 /> |
| 37 | </Button> |
| 38 | </AlertDialogTrigger> |
| 39 | <AlertDialogContent> |
| 40 | <AlertDialogHeader> |
| 41 | <AlertDialogTitle>Delete {branch |
| 42 | <AlertDialogDescription> |
| 43 | The branch is removed from the repository. Clones that already have |
| 44 | it keep their copy. |
| 45 | </AlertDialogDescription> |
| 46 | </AlertDialogHeader> |
| 47 | {result.serverError && |
| 48 | <AlertDialogFooter> |
| 49 | <AlertDialogCancel>Cancel</AlertDialogCancel |
| 50 | <Button |
| 51 | variant="destructive" |
| 52 | disabled={isExecuting} |
| 53 | onClick={() => |
| 54 | > |
| 55 | {isExecuting && <Spinner |
| 56 | Delete branch |
| 57 | </Button> |
| 58 | </AlertDialogFooter> |
| 59 | </AlertDialogContent> |
| 60 | </AlertDialog> |
| 61 | ); |
| 62 | } |