diff --git a/src/features/TakeNow/ui/ValidateTakeNowParams.tsx b/src/features/TakeNow/ui/ValidateTakeNowParams.tsx index 5858ff023..e41d1f5ff 100644 --- a/src/features/TakeNow/ui/ValidateTakeNowParams.tsx +++ b/src/features/TakeNow/ui/ValidateTakeNowParams.tsx @@ -14,7 +14,8 @@ function ValidateTakeNowParams({ respondentId, }: TakeNowParams) { const { showErrorNotification } = useNotification(); - const { initiateTakeNow, isInMultiInformantFlow } = appletModel.hooks.useMultiInformantState(); + const { initiateTakeNow, isInMultiInformantFlow, getMultiInformantState } = + appletModel.hooks.useMultiInformantState(); const { isError, isLoading, isSuccess, error, data } = useTakeNowValidation({ appletId, @@ -27,7 +28,12 @@ function ValidateTakeNowParams({ if (isSuccess && data) { const { sourceSubjectId, targetSubjectId } = data; - if (!isInMultiInformantFlow()) { + const multiInformantState = getMultiInformantState(); + if ( + !isInMultiInformantFlow() || + sourceSubjectId !== multiInformantState.sourceSubjectId || + targetSubjectId !== multiInformantState.targetSubjectId + ) { initiateTakeNow({ sourceSubjectId, targetSubjectId }); } } diff --git a/src/shared/api/types/activity.ts b/src/shared/api/types/activity.ts index bdd166d28..f1ac7db7b 100644 --- a/src/shared/api/types/activity.ts +++ b/src/shared/api/types/activity.ts @@ -92,6 +92,8 @@ export type AnswerPayload = { localEndDate: string; localEndTime: string; }; + sourceSubjectId?: ID | null; + targetSubjectId?: ID | null; }; export type AlertDTO = { diff --git a/src/widgets/ActivityDetails/model/hooks/useAnswers.ts b/src/widgets/ActivityDetails/model/hooks/useAnswers.ts index 05a3e13f4..0ea38fae8 100644 --- a/src/widgets/ActivityDetails/model/hooks/useAnswers.ts +++ b/src/widgets/ActivityDetails/model/hooks/useAnswers.ts @@ -14,6 +14,7 @@ import { appletModel } from '~/entities/applet'; import { userModel } from '~/entities/user'; import { AnswerPayload, AppletDetailsDTO, AppletEventsResponse } from '~/shared/api'; import { formatToDtoDate, formatToDtoTime, useEncryption } from '~/shared/utils'; +import { useLaunchDarkly } from '~/shared/utils/hooks/useLaunchDarkly'; type Props = { applet: AppletDetailsDTO; @@ -36,6 +37,9 @@ export const useAnswer = (props: Props) => { const { encryptPayload } = useEncryptPayload(); const { getGroupProgress } = appletModel.hooks.useGroupProgressState(); + const { getMultiInformantState, isInMultiInformantFlow } = + appletModel.hooks.useMultiInformantState(); + const { flags: featureFlags } = useLaunchDarkly(); const getSubmitId = (groupInProgress: GroupProgress): string => { const isFlow = groupInProgress.type === ActivityPipelineType.Flow; @@ -135,6 +139,14 @@ export const useAnswer = (props: Props) => { }, }; + if (featureFlags.enableMultiInformant) { + const multiInformantState = getMultiInformantState(); + if (isInMultiInformantFlow()) { + answer.sourceSubjectId = multiInformantState.sourceSubjectId; + answer.targetSubjectId = multiInformantState.targetSubjectId; + } + } + const scheduledTime = getScheduledTimeFromEvents(props.eventsRawData, props.activityId); if (scheduledTime) { answer.answer.scheduledTime = scheduledTime; @@ -154,6 +166,7 @@ export const useAnswer = (props: Props) => { props.eventId, props.eventsRawData, props.flowId, + getMultiInformantState, ], );