From 6d6f573760f5e3e4892c7d74c7b33abd5762700c Mon Sep 17 00:00:00 2001 From: LN Date: Tue, 28 Nov 2023 02:08:52 +0100 Subject: [PATCH] Reinforce security when deleting a form --- components/cards/card-form.tsx | 39 ---------------------------------- components/form/settings.tsx | 27 ++++++++++++++++++++--- 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/components/cards/card-form.tsx b/components/cards/card-form.tsx index 4bb520f..3b33800 100644 --- a/components/cards/card-form.tsx +++ b/components/cards/card-form.tsx @@ -256,45 +256,6 @@ export default function CardForm({ - {" "} - - - - - - - - Are you sure you want to delete this form ? - - - This action is irreversible, please reflect beforehand. - - - - Cancel - - - diff --git a/components/form/settings.tsx b/components/form/settings.tsx index 9e868d9..7f34ac5 100644 --- a/components/form/settings.tsx +++ b/components/form/settings.tsx @@ -197,6 +197,7 @@ export default function SettingsForms({ dataForm }: { dataForm: any }) { const { deleteDocument, isLoading: isLoadingDelete }: any = useDeleteDocument("forms") + const [confirmFormName, setConfirmFormName] = useState("") const handleDeleteDocument = () => { deleteDocument(id) index.deleteObject(id) @@ -448,8 +449,26 @@ export default function SettingsForms({ dataForm }: { dataForm: any }) { Are you sure you want to delete this form ? - - This action is irreversible, please reflect beforehand. + +
+ This action is irreversible, please reflect beforehand. +
+
+

+ Enter the form name{" "} + {dataForm.name} to + continue: +

+ { + setConfirmFormName(e.target.value) + }} + className="" + /> +
@@ -458,7 +477,9 @@ export default function SettingsForms({ dataForm }: { dataForm: any }) { className={cn( "inline-flex h-10 items-center justify-center rounded-md bg-red-500 px-4 py-2 text-sm font-semibold text-white transition-colors hover:bg-slate-900 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-red-600 dark:hover:bg-slate-200 dark:hover:text-slate-900 dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900" )} - disabled={isLoadingDelete} + disabled={ + isLoadingDelete || confirmFormName !== dataForm.name + } onClick={ !isLoadingDelete ? handleDeleteDocument : undefined }