mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-27 06:13:06 +00:00
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.
This commit is contained in:
parent
5fd0f47651
commit
1011eaafd2
2 changed files with 66 additions and 27 deletions
|
|
@ -90,6 +90,8 @@ export type ActivityFormFieldsProps = {
|
||||||
submittedTitle?: string
|
submittedTitle?: string
|
||||||
searchContacts: (query: string) => Promise<ContactComboboxOption[]>
|
searchContacts: (query: string) => Promise<ContactComboboxOption[]>
|
||||||
searchLeaderships: (query: string) => Promise<ActivityLeadershipOption[]>
|
searchLeaderships: (query: string) => Promise<ActivityLeadershipOption[]>
|
||||||
|
/** When true (hybrid/offline edit), hide tasks/demands — outbox cannot persist them. */
|
||||||
|
deferOfflineUnsupportedFields?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const editableStatuses = ['rascunho', 'planejado'] as const
|
const editableStatuses = ['rascunho', 'planejado'] as const
|
||||||
|
|
@ -104,6 +106,7 @@ const ActivityFormFields = ({
|
||||||
submittedTitle,
|
submittedTitle,
|
||||||
searchContacts,
|
searchContacts,
|
||||||
searchLeaderships,
|
searchLeaderships,
|
||||||
|
deferOfflineUnsupportedFields = false,
|
||||||
}: ActivityFormFieldsProps) => {
|
}: ActivityFormFieldsProps) => {
|
||||||
const errorFor = (name: string) => fieldError(fieldErrors, name)
|
const errorFor = (name: string) => fieldError(fieldErrors, name)
|
||||||
const statusIsEditable =
|
const statusIsEditable =
|
||||||
|
|
@ -457,6 +460,16 @@ const ActivityFormFields = ({
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
{deferOfflineUnsupportedFields ? (
|
||||||
|
<Alert>
|
||||||
|
<AlertTitle>Tarefas e demandas</AlertTitle>
|
||||||
|
<AlertDescription>
|
||||||
|
Edição offline grava só os campos principais. Para alterar tarefas ou criar demandas,
|
||||||
|
use a atividade com conexão.
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Tarefas</CardTitle>
|
<CardTitle>Tarefas</CardTitle>
|
||||||
|
|
@ -478,6 +491,8 @@ const ActivityFormFields = ({
|
||||||
<ActivityDemandFields error={errorFor('demandsJson')} />
|
<ActivityDemandFields error={errorFor('demandsJson')} />
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</FieldGroup>
|
</FieldGroup>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -580,12 +595,12 @@ export const ActivityForm = ({
|
||||||
const responsible =
|
const responsible =
|
||||||
typeof responsibleRaw === 'string' && Number.isInteger(Number(responsibleRaw))
|
typeof responsibleRaw === 'string' && Number.isInteger(Number(responsibleRaw))
|
||||||
? Number(responsibleRaw)
|
? Number(responsibleRaw)
|
||||||
: undefined
|
: null
|
||||||
const leadershipRaw = data.get('leadership')
|
const leadershipRaw = data.get('leadership')
|
||||||
const leadershipId =
|
const leadershipId =
|
||||||
typeof leadershipRaw === 'string' && Number.isInteger(Number(leadershipRaw))
|
typeof leadershipRaw === 'string' && Number.isInteger(Number(leadershipRaw))
|
||||||
? Number(leadershipRaw)
|
? Number(leadershipRaw)
|
||||||
: undefined
|
: null
|
||||||
const startAtRaw = readOptionalFormText(data, 'startAt')
|
const startAtRaw = readOptionalFormText(data, 'startAt')
|
||||||
const endAtRaw = readOptionalFormText(data, 'endAt')
|
const endAtRaw = readOptionalFormText(data, 'endAt')
|
||||||
const deadlineRaw = readOptionalFormText(data, 'deadline')
|
const deadlineRaw = readOptionalFormText(data, 'deadline')
|
||||||
|
|
@ -611,16 +626,14 @@ export const ActivityForm = ({
|
||||||
startAt,
|
startAt,
|
||||||
endAt,
|
endAt,
|
||||||
deadline,
|
deadline,
|
||||||
...(responsible !== undefined ? { responsible } : {}),
|
responsible,
|
||||||
...(leadershipId !== undefined ? { leadership: leadershipId } : {}),
|
leadership: leadershipId,
|
||||||
},
|
},
|
||||||
baseUpdatedAt: mirrorUpdatedAt ?? activity.updatedAt,
|
baseUpdatedAt: mirrorUpdatedAt ?? activity.updatedAt,
|
||||||
}).then(
|
}).then(
|
||||||
() => {
|
() => {
|
||||||
setHybridPending(false)
|
setHybridPending(false)
|
||||||
setHybridMessage(
|
setHybridMessage('Alterações enfileiradas.')
|
||||||
'Alterações enfileiradas (campos principais). Tarefas e novas demandas exigem conexão.',
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
(error: unknown) => {
|
(error: unknown) => {
|
||||||
setHybridPending(false)
|
setHybridPending(false)
|
||||||
|
|
@ -672,6 +685,7 @@ export const ActivityForm = ({
|
||||||
submittedTitle={state.submittedTitle}
|
submittedTitle={state.submittedTitle}
|
||||||
searchContacts={searchContacts}
|
searchContacts={searchContacts}
|
||||||
searchLeaderships={searchLeaderships}
|
searchLeaderships={searchLeaderships}
|
||||||
|
deferOfflineUnsupportedFields={hybridUpdate}
|
||||||
/>
|
/>
|
||||||
<div className="flex flex-col-reverse gap-3 sm:flex-row sm:justify-end">
|
<div className="flex flex-col-reverse gap-3 sm:flex-row sm:justify-end">
|
||||||
<Button asChild variant="outline" className="min-h-11">
|
<Button asChild variant="outline" className="min-h-11">
|
||||||
|
|
|
||||||
25
tests/unit/activityHybridUpdatePayload.unit.spec.ts
Normal file
25
tests/unit/activityHybridUpdatePayload.unit.spec.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
|
import { activityUpdateSchema } from '@/lib/schemas/activity'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pass 5 P1a — hybrid activity updates must be able to clear relations with
|
||||||
|
* explicit null (omitting the key leaves the previous server value).
|
||||||
|
*/
|
||||||
|
describe('activity hybrid update payload (Pass 5 P1a)', () => {
|
||||||
|
it('accepts null responsible and leadership on patch', () => {
|
||||||
|
const parsed = activityUpdateSchema.parse({
|
||||||
|
id: 1,
|
||||||
|
responsible: null,
|
||||||
|
leadership: null,
|
||||||
|
description: null,
|
||||||
|
locality: null,
|
||||||
|
})
|
||||||
|
expect(parsed.responsible).toBeNull()
|
||||||
|
expect(parsed.leadership).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('rejects omitting id', () => {
|
||||||
|
expect(() => activityUpdateSchema.parse({ responsible: null })).toThrow()
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
Reference in a new issue