DeleteUser.tsx 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { Form } from '@inertiajs/react';
  2. import { useRef } from 'react';
  3. import ProfileController from '@/actions/App/Http/Controllers/Settings/ProfileController';
  4. import { HeadingSmall } from '@/common/HeadingSmall';
  5. import { InputError } from '@/common/InputError';
  6. import { Button } from '@/shadcn/button';
  7. import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogTitle, DialogTrigger } from '@/shadcn/dialog';
  8. import { Input } from '@/shadcn/input';
  9. import { Label } from '@/shadcn/label';
  10. export function DeleteUser() {
  11. const passwordInput = useRef<HTMLInputElement>(null);
  12. return (
  13. <div className="space-y-6">
  14. <HeadingSmall title="Delete account" description="Delete your account and all of its resources" />
  15. <div className="space-y-4 rounded-lg border border-red-100 bg-red-50 p-4 dark:border-red-200/10 dark:bg-red-700/10">
  16. <div className="relative space-y-0.5 text-red-600 dark:text-red-100">
  17. <p className="font-medium">Warning</p>
  18. <p className="text-sm">Please proceed with caution, this cannot be undone.</p>
  19. </div>
  20. <Dialog>
  21. <DialogTrigger asChild>
  22. <Button variant="destructive">Delete account</Button>
  23. </DialogTrigger>
  24. <DialogContent>
  25. <DialogTitle>Are you sure you want to delete your account?</DialogTitle>
  26. <DialogDescription>
  27. Once your account is deleted, all of its resources and data will also be permanently deleted. Please enter your password
  28. to confirm you would like to permanently delete your account.
  29. </DialogDescription>
  30. <Form
  31. {...ProfileController.destroy.form()}
  32. options={{
  33. preserveScroll: true,
  34. }}
  35. onError={() => passwordInput.current?.focus()}
  36. resetOnSuccess
  37. className="space-y-6"
  38. >
  39. {({ resetAndClearErrors, processing, errors }) => (
  40. <>
  41. <div className="grid gap-2">
  42. <Label htmlFor="password" className="sr-only">
  43. Password
  44. </Label>
  45. <Input
  46. id="password"
  47. type="password"
  48. name="password"
  49. ref={passwordInput}
  50. placeholder="Password"
  51. autoComplete="current-password"
  52. />
  53. <InputError message={errors.password} />
  54. </div>
  55. <DialogFooter className="gap-2">
  56. <DialogClose asChild>
  57. <Button variant="secondary" onClick={() => resetAndClearErrors()}>
  58. Cancel
  59. </Button>
  60. </DialogClose>
  61. <Button variant="destructive" disabled={processing} asChild>
  62. <button type="submit">Delete account</button>
  63. </Button>
  64. </DialogFooter>
  65. </>
  66. )}
  67. </Form>
  68. </DialogContent>
  69. </Dialog>
  70. </div>
  71. </div>
  72. );
  73. }