|
|
@ -317,6 +317,7 @@ export function QuestionAnswersProvider({ |
|
|
const storageKeyRef = useRef(storageKey); |
|
|
const storageKeyRef = useRef(storageKey); |
|
|
const slugRef = useRef(slug); |
|
|
const slugRef = useRef(slug); |
|
|
const backendFieldsRef = useRef<MarriageField[]>([]); |
|
|
const backendFieldsRef = useRef<MarriageField[]>([]); |
|
|
|
|
|
const versionRef = useRef<number | undefined>(undefined); |
|
|
const dirtyKeysRef = useRef(new Set<string>()); |
|
|
const dirtyKeysRef = useRef(new Set<string>()); |
|
|
|
|
|
|
|
|
const { data: profile } = useMarriageProfileQuery(); |
|
|
const { data: profile } = useMarriageProfileQuery(); |
|
|
@ -331,12 +332,14 @@ export function QuestionAnswersProvider({ |
|
|
slugRef.current = slug; |
|
|
slugRef.current = slug; |
|
|
questionsRef.current = questions; |
|
|
questionsRef.current = questions; |
|
|
backendFieldsRef.current = serverSectionData?.data || []; |
|
|
backendFieldsRef.current = serverSectionData?.data || []; |
|
|
|
|
|
versionRef.current = serverSectionData?.version; |
|
|
}, [ |
|
|
}, [ |
|
|
answers, |
|
|
answers, |
|
|
hasPendingSync, |
|
|
hasPendingSync, |
|
|
slug, |
|
|
slug, |
|
|
questions, |
|
|
questions, |
|
|
serverSectionData?.data, |
|
|
serverSectionData?.data, |
|
|
|
|
|
serverSectionData?.version, |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
@ -491,6 +494,7 @@ export function QuestionAnswersProvider({ |
|
|
fields: nextDirtyKey |
|
|
fields: nextDirtyKey |
|
|
? fullPayload.fields.filter((field) => field.key === nextDirtyKey) |
|
|
? fullPayload.fields.filter((field) => field.key === nextDirtyKey) |
|
|
: [], |
|
|
: [], |
|
|
|
|
|
version: versionRef.current, |
|
|
}; |
|
|
}; |
|
|
const revision = answersRevisionRef.current; |
|
|
const revision = answersRevisionRef.current; |
|
|
|
|
|
|
|
|
@ -591,7 +595,7 @@ export function QuestionAnswersProvider({ |
|
|
const pendingFields = fullPayload.fields.filter((field) => |
|
|
const pendingFields = fullPayload.fields.filter((field) => |
|
|
dirtyKeysRef.current.has(field.key), |
|
|
dirtyKeysRef.current.has(field.key), |
|
|
); |
|
|
); |
|
|
const payload = { ...fullPayload, fields: pendingFields }; |
|
|
|
|
|
|
|
|
const payload = { ...fullPayload, fields: pendingFields, version: versionRef.current }; |
|
|
const revision = answersRevisionRef.current; |
|
|
const revision = answersRevisionRef.current; |
|
|
|
|
|
|
|
|
if (payload.fields.length === 0) { |
|
|
if (payload.fields.length === 0) { |
|
|
@ -616,6 +620,7 @@ export function QuestionAnswersProvider({ |
|
|
fetch(getKeepalivePatchUrl(slugRef.current), { |
|
|
fetch(getKeepalivePatchUrl(slugRef.current), { |
|
|
body: JSON.stringify({ |
|
|
body: JSON.stringify({ |
|
|
answers: answersPayload, |
|
|
answers: answersPayload, |
|
|
|
|
|
version: payload.version, |
|
|
}), |
|
|
}), |
|
|
credentials: "include", |
|
|
credentials: "include", |
|
|
headers, |
|
|
headers, |
|
|
|