mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-27 06:13:06 +00:00
Merge pull request #234 from fsolla/cursor/pass5-p1a-activity-hybrid-171a
P5-P1a — activity hybrid: hide unsavable fields, clear relations
This commit is contained in:
commit
caec1237ff
2 changed files with 66 additions and 27 deletions
|
|
@ -90,6 +90,8 @@ export type ActivityFormFieldsProps = {
|
|||
submittedTitle?: string
|
||||
searchContacts: (query: string) => Promise<ContactComboboxOption[]>
|
||||
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
|
||||
|
|
@ -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 = ({
|
|||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Tarefas</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ActivityTaskFields
|
||||
initialTasks={activity?.tasks ?? []}
|
||||
searchContacts={searchContacts}
|
||||
error={errorFor('tasksJson')}
|
||||
/>
|
||||
</CardContent>
|
||||
</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>
|
||||
<CardHeader>
|
||||
<CardTitle>Tarefas</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ActivityTaskFields
|
||||
initialTasks={activity?.tasks ?? []}
|
||||
searchContacts={searchContacts}
|
||||
error={errorFor('tasksJson')}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Demandas</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ActivityDemandFields error={errorFor('demandsJson')} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Demandas</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ActivityDemandFields error={errorFor('demandsJson')} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</>
|
||||
)}
|
||||
</FieldGroup>
|
||||
)
|
||||
}
|
||||
|
|
@ -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}
|
||||
/>
|
||||
<div className="flex flex-col-reverse gap-3 sm:flex-row sm:justify-end">
|
||||
<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