refactor: simplify confirm dialog with dialog actions and icon tile
This commit is contained in:
parent
cbd23f2902
commit
b3f7504459
@ -1,83 +1,30 @@
|
||||
import * as React from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
} from '~/components/ui/dialog';
|
||||
import { Button } from '~/components/ui/button';
|
||||
import { AlertTriangle, RefreshCw } from 'lucide-react';
|
||||
import { AlertTriangle } from 'lucide-react';
|
||||
import { Dialog, DialogBody, DialogContent, DialogDescription, DialogTitle } from '~/components/ui/dialog';
|
||||
import { DialogActions } from '~/components/ui/dialog-actions';
|
||||
import { IconTile } from '~/components/ui/icon-tile';
|
||||
|
||||
interface ConfirmDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
title: string;
|
||||
description: string;
|
||||
confirmText?: string;
|
||||
cancelText?: string;
|
||||
variant?: 'destructive' | 'default';
|
||||
loading?: boolean;
|
||||
confirmLabel?: string;
|
||||
pending?: boolean;
|
||||
onConfirm: () => void;
|
||||
}
|
||||
|
||||
export function ConfirmDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
title,
|
||||
description,
|
||||
confirmText = 'Confirm',
|
||||
cancelText = 'Cancel',
|
||||
variant = 'destructive',
|
||||
loading = false,
|
||||
onConfirm,
|
||||
}: ConfirmDialogProps) {
|
||||
export function ConfirmDialog({ open, onOpenChange, title, description, confirmLabel = 'Confirm', pending, onConfirm }: ConfirmDialogProps) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-md bg-[#121212] border-neutral-850 p-6">
|
||||
<DialogHeader className="space-y-2">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 rounded-xl bg-red-500/10 border border-red-500/20 flex items-center justify-center text-red-500 shrink-0">
|
||||
<AlertTriangle size={20} />
|
||||
</div>
|
||||
<div>
|
||||
<DialogTitle className="text-base font-bold text-white uppercase tracking-wider">
|
||||
{title}
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-xs text-neutral-400 mt-1">
|
||||
{description}
|
||||
</DialogDescription>
|
||||
</div>
|
||||
<DialogContent className='max-w-md'>
|
||||
<DialogBody className='flex-row items-start gap-4 pr-16'>
|
||||
<IconTile icon={AlertTriangle} tone='danger' />
|
||||
<div className='space-y-1.5'>
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
<DialogDescription>{description}</DialogDescription>
|
||||
</div>
|
||||
</DialogHeader>
|
||||
|
||||
<DialogFooter className="mt-6 flex flex-row items-center justify-end gap-3">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={loading}
|
||||
onClick={() => onOpenChange(false)}
|
||||
className="h-9"
|
||||
>
|
||||
{cancelText}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={variant}
|
||||
size="sm"
|
||||
disabled={loading}
|
||||
onClick={onConfirm}
|
||||
className="h-9"
|
||||
>
|
||||
{loading ? (
|
||||
<RefreshCw size={14} className="animate-spin" />
|
||||
) : (
|
||||
confirmText
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogBody>
|
||||
<DialogActions confirmLabel={confirmLabel} variant='destructive' pending={pending} onConfirm={onConfirm} />
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user