Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M2-6044: Submit Take Now Params #441

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/features/TakeNow/ui/ValidateTakeNowParams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
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,
Expand All @@ -27,11 +28,16 @@
if (isSuccess && data) {
const { sourceSubjectId, targetSubjectId } = data;

if (!isInMultiInformantFlow()) {
const multiInformantState = getMultiInformantState();
if (
!isInMultiInformantFlow() ||
sourceSubjectId !== multiInformantState.sourceSubjectId ||
targetSubjectId !== multiInformantState.targetSubjectId
) {
initiateTakeNow({ sourceSubjectId, targetSubjectId });
}
}
}, [data, initiateTakeNow, isInMultiInformantFlow, isSuccess]);

Check warning on line 40 in src/features/TakeNow/ui/ValidateTakeNowParams.tsx

View workflow job for this annotation

GitHub Actions / ESLint

src/features/TakeNow/ui/ValidateTakeNowParams.tsx#L40

React Hook useEffect has a missing dependency: 'getMultiInformantState'. Either include it or remove the dependency array (react-hooks/exhaustive-deps)

useEffect(() => {
if (error) {
Expand Down
2 changes: 2 additions & 0 deletions src/shared/api/types/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export type AnswerPayload = {
localEndDate: string;
localEndTime: string;
};
sourceSubjectId?: ID | null;
targetSubjectId?: ID | null;
};

export type AlertDTO = {
Expand Down
13 changes: 13 additions & 0 deletions src/widgets/ActivityDetails/model/hooks/useAnswers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand All @@ -36,6 +37,9 @@
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;
Expand Down Expand Up @@ -135,6 +139,14 @@
},
};

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;
Expand All @@ -142,7 +154,7 @@

return answer;
},
[

Check warning on line 157 in src/widgets/ActivityDetails/model/hooks/useAnswers.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/widgets/ActivityDetails/model/hooks/useAnswers.ts#L157

React Hook useCallback has missing dependencies: 'featureFlags.enableMultiInformant' and 'isInMultiInformantFlow'. Either include them or remove the dependency array (react-hooks/exhaustive-deps)
encryptPayload,
generateUserPrivateKey,
getGroupProgress,
Expand All @@ -154,6 +166,7 @@
props.eventId,
props.eventsRawData,
props.flowId,
getMultiInformantState,
],
);

Expand Down
Loading