From d776c73a03dec6c899ed3d2b7309db7a5e8fcc90 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Mon, 2 Feb 2026 14:32:40 +0700 Subject: [PATCH] refactor(FE): Add onClose handler and improve button behavior --- .../modal/ConfirmationModalWithNotes.tsx | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/components/modal/ConfirmationModalWithNotes.tsx b/src/components/modal/ConfirmationModalWithNotes.tsx index a5551571..e862dffc 100644 --- a/src/components/modal/ConfirmationModalWithNotes.tsx +++ b/src/components/modal/ConfirmationModalWithNotes.tsx @@ -13,6 +13,7 @@ interface ConfirmationModalWithNotesProps extends Omit { rows?: number; placeholder?: string; + onClose?: () => void; primaryButton?: { text?: string; @@ -32,6 +33,7 @@ const ConfirmationModalWithNotes: React.FC = ({ className, rows = 3, placeholder = 'Catatan...', + onClose, ...props }) => { const randomId = useId(); @@ -41,6 +43,11 @@ const ConfirmationModalWithNotes: React.FC = ({ setNotes(e.target.value); }; + const closeModalHandler = () => { + onClose?.(); + ref.current?.close(); + }; + return ( = ({ closeOnBackdrop={closeOnBackdrop} primaryButton={{ ...primaryButton, - onClick: () => { - primaryButton?.onClick?.(notes); + onClick: (e) => { + if (primaryButton && primaryButton?.onClick) { + primaryButton?.onClick?.(notes); + } else { + closeModalHandler(); + } + setNotes(''); }, }} - secondaryButton={secondaryButton} + secondaryButton={ + secondaryButton + ? { + text: secondaryButton?.text ?? 'Tidak', + onClick: (e) => { + if (secondaryButton && secondaryButton?.onClick) { + secondaryButton.onClick?.(e); + } else { + closeModalHandler(); + } + + setNotes(''); + }, + } + : undefined + } className={className} {...props} >