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

Release/v2.5.1 [main] #555

Merged
merged 8 commits into from
Nov 21, 2024
1 change: 1 addition & 0 deletions src/abstract/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export const phrasalTemplateCompatibleResponseTypes = [
'multiSelectRows',
'singleSelectRows',
'sliderRows',
'paragraphText',
];
11 changes: 10 additions & 1 deletion src/entities/activity/ui/items/ActionPlan/ResponseSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const isAnswersSkipped = (answers: string[]): boolean => {
type FieldValueTransformer = (value: string) => string;
const identity: FieldValueTransformer = (value) => value;

type FieldValuesJoiner = (values: string[]) => string;
type FieldValuesJoiner = (values: string[]) => string | JSX.Element[];
const joinWithComma: FieldValuesJoiner = (values) => values.join(', ');

type ResponseSegmentProps = {
Expand Down Expand Up @@ -58,13 +58,22 @@ export const ResponseSegment = ({ phrasalData, field, isAtStart }: ResponseSegme
};
} else if (fieldPhrasalData.context.itemResponseType === 'timeRange') {
joinSentenceWords = (values) => values.join(' - ');
} else if (fieldPhrasalData.context.itemResponseType === 'paragraphText') {
joinSentenceWords = (values) =>
values.map((item, index) => <div key={index}>{item || ' '}</div>);
}

let words: string[];
if (fieldPhrasalDataType === 'array') {
words = isAnswersSkipped(fieldPhrasalData.values)
? [t('questionSkipped')]
: fieldPhrasalData.values.map(transformValue);
} else if (fieldPhrasalDataType === 'paragraph') {
words = isAnswersSkipped(fieldPhrasalData.values)
? [t('questionSkipped')]
: fieldPhrasalData.values
.flatMap((value) => value.split(/\r?\n/)) // Split each paragraph by newlines
.map(transformValue);
} else if (fieldPhrasalDataType === 'indexed-array') {
const indexedAnswers = fieldPhrasalData.values[field.itemIndex] || [];
words = isAnswersSkipped(indexedAnswers)
Expand Down
13 changes: 12 additions & 1 deletion src/entities/activity/ui/items/ActionPlan/phrasalData.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prettier/prettier */
import { phrasalTemplateCompatibleResponseTypes } from '~/abstract/lib/constants';
import { ActivityItemType } from '~/entities/activity/lib';
import { ItemRecord } from '~/entities/applet/model';
Expand All @@ -23,6 +24,8 @@ type ActivityPhrasalBaseData<

type ActivityPhrasalArrayFieldData = ActivityPhrasalBaseData<'array', string[]>;

type ActivityPhrasalParagraphFieldData = ActivityPhrasalBaseData<'paragraph', string[]>;

type ActivityPhrasalItemizedArrayValue = Record<number, string[]>;

type ActivityPhrasalIndexedArrayFieldData = ActivityPhrasalBaseData<
Expand All @@ -45,7 +48,8 @@ type ActivityPhrasalMatrixFieldData = ActivityPhrasalBaseData<'matrix', Activity
type ActivityPhrasalData =
| ActivityPhrasalArrayFieldData
| ActivityPhrasalIndexedArrayFieldData
| ActivityPhrasalMatrixFieldData;
| ActivityPhrasalMatrixFieldData
| ActivityPhrasalParagraphFieldData;

export type ActivitiesPhrasalData = Record<string, ActivityPhrasalData>;

Expand Down Expand Up @@ -92,6 +96,13 @@ export const extractActivitiesPhrasalData = (items: ItemRecord[]): ActivitiesPhr
context: fieldDataContext,
};
fieldData = dateFieldData;
} else if (item.responseType === 'paragraphText') {
const dateFieldData: ActivityPhrasalParagraphFieldData = {
type: 'paragraph',
values: item.answer.map((value) => value || ''),
context: fieldDataContext,
};
fieldData = dateFieldData;
} else if (item.responseType === 'singleSelect' || item.responseType === 'multiSelect') {
const dateFieldData: ActivityPhrasalArrayFieldData = {
type: 'array',
Expand Down
2 changes: 1 addition & 1 deletion src/entities/user/model/hooks/useOnLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const useOnLogin = (params: Params) => {
secureTokensStorage.setTokens(tokens);

if (params.backRedirectPath !== undefined) {
navigate(params.backRedirectPath);
navigate(params.backRedirectPath, { replace: true });
} else {
Mixpanel.track({ action: MixpanelEventType.LoginSuccessful });
Mixpanel.login(user.id);
Expand Down
17 changes: 15 additions & 2 deletions src/features/Logout/lib/useLogout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useCallback } from 'react';

import { useLocation } from 'react-router-dom';

import { appletModel } from '~/entities/applet';
import { useLogoutMutation, userModel } from '~/entities/user';
import { AutoCompletionModel } from '~/features/AutoCompletion';
Expand All @@ -19,6 +21,7 @@ type UseLogoutReturn = {

export const useLogout = (): UseLogoutReturn => {
const navigator = useCustomNavigation();
const location = useLocation();

const { clearUser } = userModel.hooks.useUserState();
const { clearStore } = appletModel.hooks.useClearStore();
Expand All @@ -42,8 +45,18 @@ export const useLogout = (): UseLogoutReturn => {
Mixpanel.track({ action: MixpanelEventType.Logout });
Mixpanel.logout();
FeatureFlags.logout();
return navigator.navigate(ROUTES.login.path);
}, [clearUser, clearStore, clearAutoCompletionState, navigator, logoutMutation]);

const backRedirectPath = `${location.pathname}${location.search}`;
return navigator.navigate(ROUTES.login.path, { state: { backRedirectPath } });
}, [
clearUser,
clearStore,
clearAutoCompletionState,
location.pathname,
location.search,
navigator,
logoutMutation,
]);

return {
logout,
Expand Down
4 changes: 3 additions & 1 deletion src/features/PassSurvey/ui/EntityTimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getMsFromHours,
getMsFromMinutes,
useAppSelector,
useCustomTranslation,
useTimer,
} from '~/shared/utils';

Expand All @@ -20,6 +21,7 @@ type Props = {
};

export const EntityTimer = ({ entityTimerSettings }: Props) => {
const { t } = useCustomTranslation();
const context = useContext(SurveyContext);

const [varForDeps, forceUpdate] = useState({});
Expand Down Expand Up @@ -64,7 +66,7 @@ export const EntityTimer = ({ entityTimerSettings }: Props) => {
return '00:00';
}

return `${formatTimerTime(timeToLeft)} remaining`;
return t('timeRemaining', { time: formatTimerTime(timeToLeft) });
};

const checkLessThan10Mins = (): boolean => {
Expand Down
7 changes: 4 additions & 3 deletions src/features/PassSurvey/ui/ItemTimerBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Theme } from '~/shared/constants';
import Box from '~/shared/ui/Box';
import Text from '~/shared/ui/Text';
import { convertMillisecondsToMinSec } from '~/shared/utils';
import { convertMillisecondsToMinSec, useCustomTranslation } from '~/shared/utils';

type Props = {
duration: number; // seconds
Expand All @@ -10,6 +10,7 @@ type Props = {
};

export const ItemTimerBar = ({ time, progress, duration }: Props) => {
const { t } = useCustomTranslation();
const getProgressBarShift = (progress: number) => {
return progress - 100;
};
Expand Down Expand Up @@ -70,15 +71,15 @@ export const ItemTimerBar = ({ time, progress, duration }: Props) => {
},
}}
>
{`${convertMillisecondsToMinSec(timeMS)} remaining `}
{t('timeRemaining', { time: convertMillisecondsToMinSec(timeMS) })}
<Box
component="span"
sx={{
opacity: isPassedMoreThan(5000) ? '0' : '1',
transition: '0.6s',
}}
>
for this item
{` ${t('forItem')}`}
</Box>
</Text>
</Box>
Expand Down
4 changes: 2 additions & 2 deletions src/features/Signup/ui/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ export const SignupForm = ({ locationState }: SignupFormProps) => {
<Box display="flex" justifyContent="center">
<CheckboxWithLabel id="terms" onChange={() => setTerms((prev) => !prev)}>
<Text variant="body1">
I agree to the{' '}
{`${t('iAgreeTo')} `}
<a href={TERMS_URL} target="_blank" rel="noreferrer">
Terms of Service
{t('termsOfService')}
</a>
</Text>
</CheckboxWithLabel>
Expand Down
4 changes: 2 additions & 2 deletions src/features/TakeNow/ui/TakeNowSuccessModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useContext } from 'react';

import { TakeNowSuccessModalProps } from '../lib/types';

import { SurveyContext } from '~/features/PassSurvey';
import { MuiModal } from '~/shared/ui';
import {
addFeatureToEvent,
Expand All @@ -13,6 +12,7 @@ import {
ReturnToAdminAppEvent,
useCustomTranslation,
} from '~/shared/utils';
import { AppletDetailsContext } from '~/widgets/ActivityGroups/lib';

export const TakeNowSuccessModal = ({
isOpen,
Expand All @@ -23,7 +23,7 @@ export const TakeNowSuccessModal = ({
submitId,
}: TakeNowSuccessModalProps) => {
const { t } = useCustomTranslation();
const { applet } = useContext(SurveyContext);
const { applet } = useContext(AppletDetailsContext);

const handleReturnToAdminAppClick = () => {
const event: ReturnToAdminAppEvent = {
Expand Down
13 changes: 10 additions & 3 deletions src/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@
"logIn": "Log In",
"success": "Registration completed successfully",
"or": "Or",
"pleaseAgreeTerms": "*Please agree to the Terms of Service."
},
"pleaseAgreeTerms": "*Please agree to the Terms of Service.",
"iAgreeTo": "I agree to the",
"termsOfService": "Terms of Service"
},
"ForgotPassword": {
"title": "Reset Password",
"formTitle": "Enter the email associated with your account",
Expand Down Expand Up @@ -329,6 +331,11 @@
"support": "Support",
"privacy": "Privacy",
"termsOfService": "Terms"
}
},
"activity": "Activity",
"networkError": "Network Error",
"timeRemaining": "{{time}} remaining",
"forItem": "for this item",
"noApplets": "No applets"
}
}
11 changes: 9 additions & 2 deletions src/i18n/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@
"account": "Vous avez déjà un compte?",
"logIn": "Connexion",
"success": "Inscription terminée avec succès",
"pleaseAgreeTerms": "*Please agree to the Terms of Service."
"pleaseAgreeTerms": "*Please agree to the Terms of Service.",
"iAgreeTo": "J'accepte les",
"termsOfService": "Conditions d'Utilisation"
},
"ForgotPassword": {
"title": "réinitialiser le mot de passe",
Expand Down Expand Up @@ -348,6 +350,11 @@
"support": "Soutien",
"privacy": "Confidentialité",
"termsOfService": "Conditions"
}
},
"activity": "Activité",
"networkError": "Erreur réseau",
"timeRemaining": "{{time}} restantes",
"forItem": "pour cet objet",
"noApplets": "Pas d'applets"
}
}
5 changes: 3 additions & 2 deletions src/pages/AuthorizedRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Navigate, Route, Routes } from 'react-router-dom';
import AppletDetailsPage from './AppletDetailsPage';
import AppletListPage from './AppletListPage';
import AutoCompletion from './AutoCompletion';
import LoginPage from './Login';
import ProfilePage from './Profile';
import PublicAutoCompletion from './PublicAutoCompletion';
import SettingsPage from './Settings';
Expand Down Expand Up @@ -48,10 +49,10 @@ function AuthorizedRoutes({ refreshToken }: Props) {
<Route path={ROUTES.privateJoin.path} element={<PrivateJoinPage />} />
<Route path={ROUTES.publicJoin.path} element={<PublicAppletDetailsPage />} />
<Route path={ROUTES.transferOwnership.path} element={<TransferOwnershipPage />} />

<Route path="*" element={<Navigate to={ROUTES.appletList.path} />} />
</Route>
</Route>
<Route path={ROUTES.login.path} element={<LoginPage />} />
<Route path="*" element={<Navigate to={ROUTES.appletList.path} />} />
</Routes>
</LogoutTracker>
);
Expand Down
12 changes: 5 additions & 7 deletions src/shared/utils/hooks/useSessionBanners/useSessionBanners.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef } from 'react';
import { useRef } from 'react';

import { useBanners } from '~/entities/banner/model';
import { userModel } from '~/entities/user';
Expand All @@ -9,11 +9,9 @@ export const useSessionBanners = () => {

const prevIsAuthorized = useRef(isAuthorized);

useEffect(() => {
if (prevIsAuthorized.current !== isAuthorized && !isAuthorized) {
removeAllBanners();
}
if (prevIsAuthorized.current !== isAuthorized && !isAuthorized) {
removeAllBanners();
}

prevIsAuthorized.current = isAuthorized;
}, [isAuthorized, removeAllBanners]);
prevIsAuthorized.current = isAuthorized;
};
4 changes: 3 additions & 1 deletion src/widgets/AppletList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { userModel } from '~/entities/user';
import { Box } from '~/shared/ui';
import { Text } from '~/shared/ui';
import Loader from '~/shared/ui/Loader';
import { useCustomTranslation } from '~/shared/utils';

export const AppletListWidget = () => {
const { t } = useCustomTranslation();
const { user } = userModel.hooks.useUserState();

const {
Expand Down Expand Up @@ -36,7 +38,7 @@ export const AppletListWidget = () => {
if (isAppletsEmpty) {
return (
<Box display="flex" flex={1} alignItems="center" justifyContent="center">
<Text variant="body1">No applets</Text>
<Text variant="body1">{t('noApplets')}</Text>
</Box>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/Survey/ui/ActivityMetaData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ActivityMetaData = ({ activityLength, isFlow, activityOrderInFlow }
variant="body1"
component="span"
testid="metadata-activity-serial-number"
>{`Activity ${activityOrderInFlow} `}</Text>
>{`${t('activity')} ${activityOrderInFlow} `}</Text>
&bull;
<Text
variant="body1"
Expand Down
Loading