Skip to content

Commit

Permalink
Reinforce security when deleting a form
Browse files Browse the repository at this point in the history
  • Loading branch information
ln-dev7 committed Nov 28, 2023
1 parent 2e75a0f commit 6d6f573
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 42 deletions.
39 changes: 0 additions & 39 deletions components/cards/card-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,45 +256,6 @@ export default function CardForm({
</button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>{" "}
<AlertDialog>
<AlertDialogTrigger asChild>
<Button
variant="destructive"
className="h-10 w-10 rounded-full p-0"
>
<Trash className="h-4 w-4" />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
Are you sure you want to delete this form ?
</AlertDialogTitle>
<AlertDialogDescription>
This action is irreversible, please reflect beforehand.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<button
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}
onClick={
!isLoadingDelete ? handleDeleteDocument : undefined
}
>
{isLoadingDelete ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : (
<Trash className="mr-2 h-4 w-4" />
)}
Delete
</button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</PopoverContent>
Expand Down
27 changes: 24 additions & 3 deletions components/form/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -448,8 +449,26 @@ export default function SettingsForms({ dataForm }: { dataForm: any }) {
<AlertDialogTitle>
Are you sure you want to delete this form ?
</AlertDialogTitle>
<AlertDialogDescription>
This action is irreversible, please reflect beforehand.
<AlertDialogDescription className="space-y-3">
<div
className="rounded-lg bg-red-50 p-4 text-sm text-red-800 dark:bg-gray-800 dark:text-red-400 font-semibold"
role="alert"
>
This action is irreversible, please reflect beforehand.
</div>
<div className="space-y-2">
<p>
Enter the form name{" "}
<span className="font-bold">{dataForm.name}</span> to
continue:
</p>
<Input
onChange={(e) => {
setConfirmFormName(e.target.value)
}}
className=""
/>
</div>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
Expand All @@ -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
}
Expand Down

1 comment on commit 6d6f573

@vercel
Copy link

@vercel vercel bot commented on 6d6f573 Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sharuco – ./

shruco.vercel.app
sharuco-ln-dev7.vercel.app
sharuco-git-master-ln-dev7.vercel.app
sharuco.lndev.me

Please sign in to comment.