refactor: split toggleTarget into separate handlers for create and edit forms

Replace conditional setter pattern with explicit if/else branches for editing and creating modes. Handle editForm state updates separately from form state updates to improve code clarity and maintainability.
This commit is contained in:
2026-03-17 21:44:54 +01:00
parent b16564ac5c
commit 1b684aecbb

View File

@@ -140,8 +140,17 @@ export function PoliciesPage() {
}
function toggleTarget(id: string, editing = false) {
const setter = editing ? setEditForm : setForm;
setter((value) => ({
if (editing) {
setEditForm((value) => ({
...value,
targetIds: value.targetIds.includes(id)
? value.targetIds.filter((item) => item !== id)
: [...value.targetIds, id]
}));
return;
}
setForm((value) => ({
...value,
targetIds: value.targetIds.includes(id)
? value.targetIds.filter((item) => item !== id)