users-delete-dialog.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use client'
  2. import { useState } from 'react'
  3. import { AlertTriangle } from 'lucide-react'
  4. import { showSubmittedData } from '@/utils/show-submitted-data'
  5. import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
  6. import { Input } from '@/components/ui/input'
  7. import { Label } from '@/components/ui/label'
  8. import { ConfirmDialog } from '@/components/confirm-dialog'
  9. import { type User } from '../data/schema'
  10. type UserDeleteDialogProps = {
  11. open: boolean
  12. onOpenChange: (open: boolean) => void
  13. currentRow: User
  14. }
  15. export function UsersDeleteDialog({
  16. open,
  17. onOpenChange,
  18. currentRow,
  19. }: UserDeleteDialogProps) {
  20. const [value, setValue] = useState('')
  21. const handleDelete = () => {
  22. if (value.trim() !== currentRow.username) return
  23. onOpenChange(false)
  24. showSubmittedData(currentRow, 'The following user has been deleted:')
  25. }
  26. return (
  27. <ConfirmDialog
  28. open={open}
  29. onOpenChange={onOpenChange}
  30. handleConfirm={handleDelete}
  31. disabled={value.trim() !== currentRow.username}
  32. title={
  33. <span className='text-destructive'>
  34. <AlertTriangle
  35. className='stroke-destructive me-1 inline-block'
  36. size={18}
  37. />{' '}
  38. Delete User
  39. </span>
  40. }
  41. desc={
  42. <div className='space-y-4'>
  43. <p className='mb-2'>
  44. Are you sure you want to delete{' '}
  45. <span className='font-bold'>{currentRow.username}</span>?
  46. <br />
  47. This action will permanently remove the user with the role of{' '}
  48. <span className='font-bold'>
  49. {currentRow.role.toUpperCase()}
  50. </span>{' '}
  51. from the system. This cannot be undone.
  52. </p>
  53. <Label className='my-2'>
  54. Username:
  55. <Input
  56. value={value}
  57. onChange={(e) => setValue(e.target.value)}
  58. placeholder='Enter username to confirm deletion.'
  59. />
  60. </Label>
  61. <Alert variant='destructive'>
  62. <AlertTitle>Warning!</AlertTitle>
  63. <AlertDescription>
  64. Please be careful, this operation can not be rolled back.
  65. </AlertDescription>
  66. </Alert>
  67. </div>
  68. }
  69. confirmText='Delete'
  70. destructive
  71. />
  72. )
  73. }