From e809912ae37e08b922913d45dc880f8b2efc635f Mon Sep 17 00:00:00 2001 From: Markus Thielker Date: Sun, 17 Mar 2024 19:54:56 +0100 Subject: [PATCH] N-FIN-47: add optional confirmation dialog to new component --- src/components/form/serverActionTrigger.tsx | 52 +++++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/src/components/form/serverActionTrigger.tsx b/src/components/form/serverActionTrigger.tsx index ce5b431..252b70f 100644 --- a/src/components/form/serverActionTrigger.tsx +++ b/src/components/form/serverActionTrigger.tsx @@ -9,11 +9,29 @@ import { toast } from 'sonner'; import { sonnerContent } from '@/components/ui/sonner'; import type { VariantProps } from 'class-variance-authority'; import { ActionResponse } from '@/lib/types/actionResponse'; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from '@/components/ui/alert-dialog'; + +export interface ConfirmationDialogProps { + title: string; + description?: string; + actionText?: string; +} export interface ButtonWithActionProps extends React.ButtonHTMLAttributes, VariantProps { asChild?: boolean; + dialog?: ConfirmationDialogProps; action: () => Promise>; callback?: (data: T) => void; } @@ -36,14 +54,40 @@ const ServerActionTrigger = React.forwardRef + + + + + + {props.dialog.title} + {props.dialog?.description && ( + + {props.dialog.description} + + )} + + + + Cancel + + + {props.dialog.actionText || 'Confirm'} + + + + + ) : ( ); },