deploy 1
This commit is contained in:
73
src/components/confirm-dialog.tsx
Normal file
73
src/components/confirm-dialog.tsx
Normal file
@@ -0,0 +1,73 @@
|
||||
import { AlertTriangle, Loader2 } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
|
||||
type ConfirmDialogProps = {
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
title: React.ReactNode
|
||||
disabled?: boolean
|
||||
desc: React.JSX.Element | string
|
||||
cancelBtnText?: string
|
||||
confirmText?: React.ReactNode
|
||||
destructive?: boolean
|
||||
handleConfirm: () => void
|
||||
isLoading?: boolean
|
||||
className?: string
|
||||
children?: React.ReactNode
|
||||
}
|
||||
|
||||
export function ConfirmDialog(props: ConfirmDialogProps) {
|
||||
const {
|
||||
title,
|
||||
desc,
|
||||
children,
|
||||
className,
|
||||
confirmText,
|
||||
cancelBtnText,
|
||||
destructive,
|
||||
isLoading,
|
||||
disabled = false,
|
||||
handleConfirm,
|
||||
...actions
|
||||
} = props
|
||||
return (
|
||||
<AlertDialog {...actions}>
|
||||
<AlertDialogContent className={cn(className && className)}>
|
||||
<AlertDialogHeader className='text-start'>
|
||||
<div className='mb-4 flex size-14 items-center justify-center rounded-full bg-destructive/10 text-destructive'>
|
||||
<AlertTriangle className='size-6' />
|
||||
</div>
|
||||
<AlertDialogTitle className='text-xl'>{title}</AlertDialogTitle>
|
||||
<AlertDialogDescription asChild>
|
||||
<div className='text-sm leading-6'>{desc}</div>
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
{children}
|
||||
<AlertDialogFooter className='gap-2 sm:justify-start'>
|
||||
<AlertDialogCancel className='rounded-xl' disabled={isLoading}>
|
||||
{cancelBtnText ?? 'İptal'}
|
||||
</AlertDialogCancel>
|
||||
<Button
|
||||
className='rounded-xl'
|
||||
variant={destructive ? 'destructive' : 'default'}
|
||||
onClick={handleConfirm}
|
||||
disabled={disabled || isLoading}
|
||||
>
|
||||
{isLoading ? <Loader2 className='animate-spin' /> : null}
|
||||
{confirmText ?? 'Sil'}
|
||||
</Button>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user