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-6109: [FE] [Web App] Header - Update to Include Subject and Respondent #442

Merged
merged 6 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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/abstract/lib/types/multiInformant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export type MultiInformantSubject = {
id: string;
secretId: string | null;
nickname: string | null;
};

export type MultiInformantState = {
sourceSubjectId?: string;
targetSubjectId?: string;
sourceSubject?: MultiInformantSubject;
targetSubject?: MultiInformantSubject;
};
2 changes: 1 addition & 1 deletion src/entities/applet/model/hooks/useMultiInformantState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const useMultiInformantState = (): Return => {
const getMultiInformantState = useCallback(() => multiInformantState, [multiInformantState]);

const isInMultiInformantFlow = useCallback(() => {
return !!multiInformantState.sourceSubjectId && !!multiInformantState.targetSubjectId;
return !!multiInformantState.sourceSubject?.id && !!multiInformantState.targetSubject?.id;
}, [multiInformantState]);

const initiateTakeNow = useCallback(
Expand Down
6 changes: 2 additions & 4 deletions src/entities/applet/model/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GroupProgress } from '~/abstract/lib';
import { MultiInformantState } from '~/abstract/lib/types/multiInformant';
import {
Answer,
AudioPlayerItem,
Expand Down Expand Up @@ -174,7 +175,4 @@ export type InProgressFlow = {
pipelineActivityOrder: number;
};

export type MultiInformantPayload = {
sourceSubjectId: string;
targetSubjectId: string;
};
export type MultiInformantPayload = Required<MultiInformantState>;
21 changes: 18 additions & 3 deletions src/features/TakeNow/lib/useTakeNowValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ export const useTakeNowValidation = ({
return errorState(t('takeNow.invalidSubject'));
}

const { nickname: targetSubjectNickname, secretUserId: targetSecretUserId } =
subjectData.data.result;

if (isActivityError) {
return errorState(t('takeNow.invalidActivity'));
}
Expand Down Expand Up @@ -161,15 +164,27 @@ export const useTakeNowValidation = ({
return errorState(null);
}

const { subjectId: sourceSubjectId } = respondentData.data.result;
const {
subjectId: sourceSubjectId,
nickname: sourceSubjectNickname,
secretUserId: sourceSecretUserId,
} = respondentData.data.result;

return {
isLoading: false,
isError: false,
isSuccess: true,
data: {
sourceSubjectId,
targetSubjectId,
sourceSubject: {
id: sourceSubjectId,
nickname: sourceSubjectNickname,
secretId: sourceSecretUserId,
},
targetSubject: {
id: targetSubjectId,
nickname: targetSubjectNickname,
secretId: targetSecretUserId,
},
},
};
};
36 changes: 36 additions & 0 deletions src/features/TakeNow/ui/MultiInformantBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useMultiInformantState } from '~/entities/applet/model/hooks';
import { MultiInformantBadgeTile } from '~/features/TakeNow/ui/MultiInformantBadgeTile';
import { Theme } from '~/shared/constants';
import { Box } from '~/shared/ui';
import { useLaunchDarkly } from '~/shared/utils/hooks/useLaunchDarkly';

export const MultiInformantBadge = () => {
const { getMultiInformantState, isInMultiInformantFlow } = useMultiInformantState();
const { flags: featureFlags } = useLaunchDarkly();

if (!isInMultiInformantFlow() || !featureFlags.enableMultiInformant) {
return null;
}

const { sourceSubject, targetSubject } = getMultiInformantState();

if (!sourceSubject || !targetSubject) {
return null;
}

return (
<Box
display="flex"
padding="4px"
sultanofcardio marked this conversation as resolved.
Show resolved Hide resolved
alignItems="center"
gap="4px"
width="192px"
height="40px"
sultanofcardio marked this conversation as resolved.
Show resolved Hide resolved
borderRadius="8px"
border={`1px solid ${Theme.colors.light.surfaceVariant}`}
>
<MultiInformantBadgeTile type="Respondent" subject={sourceSubject} />
<MultiInformantBadgeTile type="Subject" subject={targetSubject} />
</Box>
);
};
55 changes: 55 additions & 0 deletions src/features/TakeNow/ui/MultiInformantBadgeTile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Tooltip from '@mui/material/Tooltip';

import { MultiInformantSubject } from '~/abstract/lib/types/multiInformant';
import { Theme } from '~/shared/constants';
import { Box } from '~/shared/ui';

type MultiInformantBadgeTileProps = {
type: 'Subject' | 'Respondent';
subject: MultiInformantSubject;
};

export const MultiInformantBadgeTile = ({ subject, type }: MultiInformantBadgeTileProps) => {
const { id, secretId, nickname } = subject;
let text = secretId ?? id;
if (nickname) {
text += `, ${nickname}`;
}

const tooltipText = `${type}: ${text}`;

const backgroundColor = type === 'Subject' ? Theme.colors.light.inverseOnSurface : 'transparent';

return (
<Box
display="flex"
padding="8px"
alignItems="center"
gap="8px"
flex="1 0 0"
borderRadius="4px"
width="78px"
height="100%"
sx={{ backgroundColor, cursor: 'default' }}
>
<Tooltip title={tooltipText}>
<p
style={{
overflow: 'hidden',
color: Theme.colors.light.onSurface,
textOverflow: 'ellipsis',

fontSize: '16px',
fontStyle: 'normal',
fontWeight: 400,
lineHeight: '24px',
letterSpacing: '0.5px',
whiteSpace: 'nowrap',
}}
>
{text}
</p>
</Tooltip>
</Box>
);
};
8 changes: 4 additions & 4 deletions src/features/TakeNow/ui/ValidateTakeNowParams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@

useEffect(() => {
if (isSuccess && data) {
const { sourceSubjectId, targetSubjectId } = data;
const { sourceSubject, targetSubject } = data;

const multiInformantState = getMultiInformantState();
if (
!isInMultiInformantFlow() ||
sourceSubjectId !== multiInformantState.sourceSubjectId ||
targetSubjectId !== multiInformantState.targetSubjectId
sourceSubject.id !== multiInformantState.sourceSubject?.id ||
targetSubject.id !== multiInformantState.targetSubject?.id
) {
initiateTakeNow({ sourceSubjectId, targetSubjectId });
initiateTakeNow({ sourceSubject, targetSubject });
}
}
}, [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/features/TakeNow/ui/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './ValidateTakeNowParams';
export * from './MultiInformantBadge';
export * from './MultiInformantBadgeTile';
4 changes: 2 additions & 2 deletions src/widgets/ActivityDetails/model/hooks/useAnswers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@
if (featureFlags.enableMultiInformant) {
const multiInformantState = getMultiInformantState();
if (isInMultiInformantFlow()) {
answer.sourceSubjectId = multiInformantState.sourceSubjectId;
answer.targetSubjectId = multiInformantState.targetSubjectId;
answer.sourceSubjectId = multiInformantState.sourceSubject?.id;
answer.targetSubjectId = multiInformantState.targetSubject?.id;
}
}

Expand All @@ -154,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 Down
7 changes: 5 additions & 2 deletions src/widgets/ActivityDetails/ui/AssessmentLayoutHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SaveAndExitButton } from '~/features/SaveAssessmentAndExit';
import { MultiInformantBadge } from '~/features/TakeNow';
import { ROUTES, Theme } from '~/shared/constants';
import { Box } from '~/shared/ui';
import { BaseProgressBar, Text } from '~/shared/ui';
import { BaseProgressBar, Box, Text } from '~/shared/ui';
import { useCustomMediaQuery, useCustomNavigation } from '~/shared/utils';

type Props = {
Expand Down Expand Up @@ -40,12 +40,15 @@ export const AssessmentLayoutHeader = (props: Props) => {
justifyContent="center"
gridTemplateColumns="1fr minmax(300px, 900px) 1fr"
padding={greaterThanSM ? '19px 24px' : '15px 16px'}
height={87}
gap={1.5}
sx={{
backgroundColor: Theme.colors.light.surface,
borderBottom: `1px solid ${Theme.colors.light.surfaceVariant}`,
}}
>
<MultiInformantBadge />

<Box sx={{ gridColumn: '2 / 3' }}>
<Box
display="flex"
Expand Down
Loading