| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- 'use client'
- import { useState } from 'react'
- import { AlertTriangle } from 'lucide-react'
- import { showSubmittedData } from '@/utils/show-submitted-data'
- import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
- import { Input } from '@/components/ui/input'
- import { Label } from '@/components/ui/label'
- import { ConfirmDialog } from '@/components/confirm-dialog'
- import { type User } from '../data/schema'
- type UserDeleteDialogProps = {
- open: boolean
- onOpenChange: (open: boolean) => void
- currentRow: User
- }
- export function UsersDeleteDialog({
- open,
- onOpenChange,
- currentRow,
- }: UserDeleteDialogProps) {
- const [value, setValue] = useState('')
- const handleDelete = () => {
- if (value.trim() !== currentRow.username) return
- onOpenChange(false)
- showSubmittedData(currentRow, 'The following user has been deleted:')
- }
- return (
- <ConfirmDialog
- open={open}
- onOpenChange={onOpenChange}
- handleConfirm={handleDelete}
- disabled={value.trim() !== currentRow.username}
- title={
- <span className='text-destructive'>
- <AlertTriangle
- className='stroke-destructive me-1 inline-block'
- size={18}
- />{' '}
- Delete User
- </span>
- }
- desc={
- <div className='space-y-4'>
- <p className='mb-2'>
- Are you sure you want to delete{' '}
- <span className='font-bold'>{currentRow.username}</span>?
- <br />
- This action will permanently remove the user with the role of{' '}
- <span className='font-bold'>
- {currentRow.role.toUpperCase()}
- </span>{' '}
- from the system. This cannot be undone.
- </p>
- <Label className='my-2'>
- Username:
- <Input
- value={value}
- onChange={(e) => setValue(e.target.value)}
- placeholder='Enter username to confirm deletion.'
- />
- </Label>
- <Alert variant='destructive'>
- <AlertTitle>Warning!</AlertTitle>
- <AlertDescription>
- Please be careful, this operation can not be rolled back.
- </AlertDescription>
- </Alert>
- </div>
- }
- confirmText='Delete'
- destructive
- />
- )
- }
|