Saved rules and client form drafts can now be edited through the rule modal. On the Rules tab, saving re-runs client setup so the firewall matches, and both add and edit ask for confirmation. Comma-separated destinations were rejected because drafts were validated before being split; validate each one after splitting instead. When editing, the first destination updates the rule and the rest are added as new rules. Pin the id in the client_rules PUT handler so a request body can't change it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { useState } from "react";
|
|
import Modal from "@/src/components/twui/elements/Modal";
|
|
import ClientRuleModalBody from "./client-rule-modal-body";
|
|
import ClientRuleModalTarget from "./client-rule-modal-target";
|
|
import type { ClientRuleDraft } from "./client-rule-draft";
|
|
|
|
/** `cancelled` keeps the modal open without showing an error. */
|
|
export type ClientRuleModalSaveResult = {
|
|
success: boolean;
|
|
msg?: string;
|
|
cancelled?: boolean;
|
|
};
|
|
|
|
export type ClientRuleModalSave = ({
|
|
rules,
|
|
}: {
|
|
rules: ClientRuleDraft[];
|
|
}) => Promise<ClientRuleModalSaveResult>;
|
|
|
|
type Props = {
|
|
/** The rule to edit. Omit to add a new one. */
|
|
rule?: ClientRuleDraft;
|
|
onSave: ClientRuleModalSave;
|
|
disabled?: boolean;
|
|
};
|
|
|
|
/**
|
|
* Validates a rule and hands it to `onSave`. Closes only on success. Commas in
|
|
* the destination yield several drafts, in both add and edit.
|
|
*/
|
|
export default function ClientRuleModal({ rule, onSave, disabled }: Props) {
|
|
const [open, setOpen] = useState(false);
|
|
|
|
return (
|
|
<Modal
|
|
open={open}
|
|
setOpen={setOpen}
|
|
className="max-w-lg p-5"
|
|
target={<ClientRuleModalTarget is_edit={Boolean(rule)} disabled={disabled} />}
|
|
>
|
|
<ClientRuleModalBody rule={rule} onSave={onSave} onClose={() => setOpen(false)} />
|
|
</Modal>
|
|
);
|
|
}
|