add conditional warning for destructive delete operation

- Added React state to track toggle status and show warning only when enabled
- Implemented modern custom border warning style with left red border and subtle background
- Added responsive width constraints (max-w-[24rem]) and word wrapping for proper layout
- Warning includes ⚠️ emoji and clear messaging about irreversible operation
- Fixed JSON syntax errors in translation files (replaced HTML entities with escaped quotes)
- Enhanced translations: "Also delete" phrasing and detailed warning messages
- Warning appears dynamically when bulk deletion option is activated

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-08-11 11:24:09 +02:00
parent 131dfe793b
commit 80e30deace
3 changed files with 29 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
"use client";
import { FC, ReactNode } from "react";
import { FC, ReactNode, useState } from "react";
import { BillingLocation } from "../lib/db-types";
import { deleteLocationById } from "../lib/actions/locationActions";
import { useFormState } from "react-dom";
@@ -17,6 +17,7 @@ export const LocationDeleteForm:FC<LocationDeleteFormProps> = ({ location }) =>
const handleAction = deleteLocationById.bind(null, location._id, location.yearMonth);
const [ , dispatch ] = useFormState(handleAction, null);
const t = useTranslations("location-delete-form");
const [deleteInSubsequentMonths, setDeleteInSubsequentMonths] = useState(false);
return(
<div className="card card-compact card-bordered min-w-[20em] max-w-[90em] bg-base-100 shadow-s my-1">
@@ -34,9 +35,27 @@ export const LocationDeleteForm:FC<LocationDeleteFormProps> = ({ location }) =>
<div className="form-control">
<label className="label cursor-pointer justify-center gap-4">
<span className="label-text">{t("delete-in-subsequent-months")}</span>
<input type="checkbox" name="deleteInSubsequentMonths" className="toggle toggle-error" />
<input
type="checkbox"
name="deleteInSubsequentMonths"
className="toggle toggle-error"
checked={deleteInSubsequentMonths}
onChange={(e) => setDeleteInSubsequentMonths(e.target.checked)}
/>
</label>
</div>
{deleteInSubsequentMonths && (
<div className="border-l-4 border-error bg-error/10 p-4 mt-4 rounded-r max-w-[24rem]">
<div className="flex items-start gap-3">
<span className="text-xl flex-shrink-0"></span>
<div className="flex-1 min-w-0">
<h3 className="font-bold text-error break-words">{t("warning-title")}</h3>
<div className="text-sm text-error/80 break-words">{t("warning-message")}</div>
</div>
</div>
</div>
)}
<div className="pt-4 text-center">
<button className="btn btn-primary w-[5.5em]">{t("confirm-button")}</button>
<Link className="btn btn-neutral w-[5.5em] ml-3" href={`/location/${location._id}/edit/`}>{t("cancel-button")}</Link>