"use client"; /** * Controlled section editor for a communication-method chip. Used by both * the custom-rule `communication-methods` add-method modal and the * `final-review` chip edit modal — caller owns draft state and decides when * to persist or discard. */ import { memo, useCallback } from "react"; import { useMessages } from "../../../../contexts/MessagesContext"; import ModalTextAreaField from "../ModalTextAreaField"; import type { CommunicationMethodDetailEntry } from "../../types"; export interface CommunicationMethodEditFieldsProps { value: CommunicationMethodDetailEntry; onChange: (_next: CommunicationMethodDetailEntry) => void; /** When true, fields are not editable (view mode). */ readOnly?: boolean; } const FIELDS: ReadonlyArray = [ "corePrinciple", "logisticsAdmin", "codeOfConduct", ]; function CommunicationMethodEditFieldsComponent({ value, onChange, readOnly = false, }: CommunicationMethodEditFieldsProps) { const m = useMessages(); const t = m.create.customRule.communication; const patch = useCallback( ( key: K, next: CommunicationMethodDetailEntry[K], ) => { onChange({ ...value, [key]: next }); }, [value, onChange], ); return (
{FIELDS.map((field) => ( patch(field, v)} disabled={readOnly} /> ))}
); } CommunicationMethodEditFieldsComponent.displayName = "CommunicationMethodEditFields"; export default memo(CommunicationMethodEditFieldsComponent);