refactor(FE): Add onClose handler and improve button behavior

This commit is contained in:
rstubryan
2026-02-02 14:32:40 +07:00
parent dc26da7404
commit d776c73a03
@@ -13,6 +13,7 @@ interface ConfirmationModalWithNotesProps
extends Omit<ConfirmationModalProps, 'children' | 'primaryButton'> { extends Omit<ConfirmationModalProps, 'children' | 'primaryButton'> {
rows?: number; rows?: number;
placeholder?: string; placeholder?: string;
onClose?: () => void;
primaryButton?: { primaryButton?: {
text?: string; text?: string;
@@ -32,6 +33,7 @@ const ConfirmationModalWithNotes: React.FC<ConfirmationModalWithNotesProps> = ({
className, className,
rows = 3, rows = 3,
placeholder = 'Catatan...', placeholder = 'Catatan...',
onClose,
...props ...props
}) => { }) => {
const randomId = useId(); const randomId = useId();
@@ -41,6 +43,11 @@ const ConfirmationModalWithNotes: React.FC<ConfirmationModalWithNotesProps> = ({
setNotes(e.target.value); setNotes(e.target.value);
}; };
const closeModalHandler = () => {
onClose?.();
ref.current?.close();
};
return ( return (
<ConfirmationModal <ConfirmationModal
ref={ref} ref={ref}
@@ -49,12 +56,32 @@ const ConfirmationModalWithNotes: React.FC<ConfirmationModalWithNotesProps> = ({
closeOnBackdrop={closeOnBackdrop} closeOnBackdrop={closeOnBackdrop}
primaryButton={{ primaryButton={{
...primaryButton, ...primaryButton,
onClick: () => { onClick: (e) => {
primaryButton?.onClick?.(notes); if (primaryButton && primaryButton?.onClick) {
primaryButton?.onClick?.(notes);
} else {
closeModalHandler();
}
setNotes(''); setNotes('');
}, },
}} }}
secondaryButton={secondaryButton} secondaryButton={
secondaryButton
? {
text: secondaryButton?.text ?? 'Tidak',
onClick: (e) => {
if (secondaryButton && secondaryButton?.onClick) {
secondaryButton.onClick?.(e);
} else {
closeModalHandler();
}
setNotes('');
},
}
: undefined
}
className={className} className={className}
{...props} {...props}
> >