From 1011eaafd2db242bdf29f7ad49221c93bc5c62ef Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 2 Aug 2026 06:39:58 +0000 Subject: [PATCH] fix(activity): hybrid edit hides unsavable fields and clears relations Offline/hybrid activity updates no longer render tasks/demands editors (outbox cannot persist them) and always send null when responsible or leadership is cleared. --- .../campaign/activity/ActivityForm.tsx | 68 +++++++++++-------- .../activityHybridUpdatePayload.unit.spec.ts | 25 +++++++ 2 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 tests/unit/activityHybridUpdatePayload.unit.spec.ts diff --git a/src/components/campaign/activity/ActivityForm.tsx b/src/components/campaign/activity/ActivityForm.tsx index bae58c56..d69e1d10 100644 --- a/src/components/campaign/activity/ActivityForm.tsx +++ b/src/components/campaign/activity/ActivityForm.tsx @@ -90,6 +90,8 @@ export type ActivityFormFieldsProps = { submittedTitle?: string searchContacts: (query: string) => Promise searchLeaderships: (query: string) => Promise + /** When true (hybrid/offline edit), hide tasks/demands — outbox cannot persist them. */ + deferOfflineUnsupportedFields?: boolean } const editableStatuses = ['rascunho', 'planejado'] as const @@ -104,6 +106,7 @@ const ActivityFormFields = ({ submittedTitle, searchContacts, searchLeaderships, + deferOfflineUnsupportedFields = false, }: ActivityFormFieldsProps) => { const errorFor = (name: string) => fieldError(fieldErrors, name) const statusIsEditable = @@ -457,27 +460,39 @@ const ActivityFormFields = ({ - - - Tarefas - - - - - + {deferOfflineUnsupportedFields ? ( + + Tarefas e demandas + + Edição offline grava só os campos principais. Para alterar tarefas ou criar demandas, + use a atividade com conexão. + + + ) : ( + <> + + + Tarefas + + + + + - - - Demandas - - - - - + + + Demandas + + + + + + + )} ) } @@ -580,12 +595,12 @@ export const ActivityForm = ({ const responsible = typeof responsibleRaw === 'string' && Number.isInteger(Number(responsibleRaw)) ? Number(responsibleRaw) - : undefined + : null const leadershipRaw = data.get('leadership') const leadershipId = typeof leadershipRaw === 'string' && Number.isInteger(Number(leadershipRaw)) ? Number(leadershipRaw) - : undefined + : null const startAtRaw = readOptionalFormText(data, 'startAt') const endAtRaw = readOptionalFormText(data, 'endAt') const deadlineRaw = readOptionalFormText(data, 'deadline') @@ -611,16 +626,14 @@ export const ActivityForm = ({ startAt, endAt, deadline, - ...(responsible !== undefined ? { responsible } : {}), - ...(leadershipId !== undefined ? { leadership: leadershipId } : {}), + responsible, + leadership: leadershipId, }, baseUpdatedAt: mirrorUpdatedAt ?? activity.updatedAt, }).then( () => { setHybridPending(false) - setHybridMessage( - 'Alterações enfileiradas (campos principais). Tarefas e novas demandas exigem conexão.', - ) + setHybridMessage('Alterações enfileiradas.') }, (error: unknown) => { setHybridPending(false) @@ -672,6 +685,7 @@ export const ActivityForm = ({ submittedTitle={state.submittedTitle} searchContacts={searchContacts} searchLeaderships={searchLeaderships} + deferOfflineUnsupportedFields={hybridUpdate} />