From d339f41cedbb913f0ddc0fdcab2fc2b04fbff2e4 Mon Sep 17 00:00:00 2001 From: bagas Date: Sun, 1 Mar 2026 20:54:34 +0700 Subject: [PATCH] feat: add modal for editing and deleting form --- app/routes/form.tsx | 143 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 122 insertions(+), 21 deletions(-) diff --git a/app/routes/form.tsx b/app/routes/form.tsx index 94baa62..46e14b3 100644 --- a/app/routes/form.tsx +++ b/app/routes/form.tsx @@ -1,6 +1,7 @@ import { useState, useEffect } from "react" import { Link, useParams, useNavigate } from "react-router" import { + AlertTriangle, ArrowLeft, BarChart3, Calendar, @@ -27,6 +28,10 @@ export default function FormPreviewPage() { const [error, setError] = useState(null) const [showDeleteConfirm, setShowDeleteConfirm] = useState(false) const [deleting, setDeleting] = useState(false) + const [confirmText, setConfirmText] = useState("") + const [showEditWarning, setShowEditWarning] = useState(false) + + const CONFIRM_PHRASE = "Aku suka femboy jadi hapus form ini" useEffect(() => { if (!id) return @@ -149,17 +154,32 @@ export default function FormPreviewPage() { Responses - - + {form.response_count > 0 ? ( + setShowEditWarning(true)} + > Edit - + ) : ( + + + + Edit + + + )} setShowDeleteConfirm(true)} + onClick={() => { + setConfirmText("") + setShowDeleteConfirm(true) + }} className="text-destructive hover:bg-destructive/10 hover:text-destructive" > @@ -206,29 +226,110 @@ export default function FormPreviewPage() { {showDeleteConfirm && (
-

Delete Form

-

- Are you sure you want to delete this form? This action cannot be - undone. + {form.response_count > 0 ? ( + <> +

+ +
+

Delete Form with Responses

+

+ This form has {form.response_count} response{form.response_count > 1 ? "s" : ""}. Deleting it will permanently remove all responses. This action cannot be undone. +

+

+ To confirm, type {CONFIRM_PHRASE} below: +

+ setConfirmText(e.target.value)} + placeholder="Type the phrase above" + className="mt-2 w-full rounded-lg border border-input bg-background px-3.5 py-2.5 text-sm text-foreground placeholder:text-muted-foreground outline-none transition-colors focus:border-primary focus:ring-2 focus:ring-primary/20" + autoFocus + /> +
+ setShowDeleteConfirm(false)} + disabled={deleting} + > + Cancel + + + {deleting ? "Deleting..." : "Delete Forever"} + +
+ + ) : ( + <> +

Delete Form

+

+ Are you sure you want to delete this form? This action cannot be + undone. +

+
+ setShowDeleteConfirm(false)} + disabled={deleting} + > + Cancel + + + {deleting ? "Deleting..." : "Delete"} + +
+ + )} +
+
+ )} + + {showEditWarning && ( +
+
+
+ +
+

Cannot Edit Form

+

+ This form already has {form.response_count} response{form.response_count > 1 ? "s" : ""}. Editing a form with existing responses is not allowed to preserve data integrity.

-
+
+ + + + View Responses + + setShowDeleteConfirm(false)} - disabled={deleting} + className="w-full" + onClick={() => setShowEditWarning(false)} > - Cancel - - - {deleting ? "Deleting..." : "Delete"} + Close