From d1271c6c2a5020cdb191a0f75fa9bcca99838d98 Mon Sep 17 00:00:00 2001 From: sultanofcardio Date: Mon, 22 Apr 2024 15:26:50 -0500 Subject: [PATCH 1/2] M2-6044: Submit take now params --- src/shared/api/types/activity.ts | 2 ++ .../ActivityDetails/model/hooks/useAnswers.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+) 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, ], ); From 98fa17501574f497e39b2586a1781619cb068c87 Mon Sep 17 00:00:00 2001 From: sultanofcardio Date: Mon, 29 Apr 2024 15:33:47 -0500 Subject: [PATCH 2/2] M2-6044: Update the multi-informant check that initiates the take now flow We can get stuck in a weird state where the values in the state won't get updated, even if the new values from the params are different. By also comparing the values themselves, we can break out of this state --- src/features/TakeNow/ui/ValidateTakeNowParams.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 }); } }