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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user