(channel, formattedValues)
| 146 | // provider values. Matching fields become null (clear); diverging |
| 147 | // fields carry the form value. |
| 148 | export const buildOverridePayload = (channel, formattedValues) => { |
| 149 | if (!channel) return undefined; |
| 150 | const payload = {}; |
| 151 | let anyOverride = false; |
| 152 | |
| 153 | for (const field of OVERRIDABLE_FIELDS) { |
| 154 | const formValue = normalizeFieldValue(field, formattedValues[field]); |
| 155 | const providerValue = normalizeFieldValue(field, channel[field]); |
| 156 | if (formValue === null && providerValue === null) continue; |
| 157 | if (formValue !== providerValue) { |
| 158 | payload[field] = formValue; |
| 159 | if (formValue !== null) anyOverride = true; |
| 160 | } else { |
| 161 | payload[field] = null; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | if (!anyOverride) { |
| 166 | // Every field matches provider; explicit null deletes the row. |
| 167 | return null; |
| 168 | } |
| 169 | return payload; |
| 170 | }; |
| 171 | |
| 172 | // Prefer the backend-resolved effective_* so the form loads with the |
| 173 | // overridden value; fall back to the raw field otherwise. |
no test coverage detected