Skip to content

Commit

Permalink
feat: added fallback logic for consulting types to be able to overwri…
Browse files Browse the repository at this point in the history
…te all
  • Loading branch information
web-mi committed Jan 31, 2024
1 parent 1962e14 commit 751cae3
Show file tree
Hide file tree
Showing 39 changed files with 2,799 additions and 2,783 deletions.
3 changes: 3 additions & 0 deletions src/api/apiAgencySelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export const apiAgencySelection = async (
postcode: string;
consultingType: number | undefined;
topicId?: number;
age?: number;
gender?: string;
counsellingRelation?: string;
},
signal?: AbortSignal
): Promise<Array<AgencyDataInterface> | null> => {
Expand Down
3 changes: 2 additions & 1 deletion src/api/apiGetUserDataBySessionId.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { endpoints } from '../resources/scripts/endpoints';
import { fetchData, FETCH_METHODS } from './fetchData';
import { ConsultingSessionDataInterface } from '../globalState';

export const apiGetUserDataBySessionId = async (
sessionId: number
): Promise<any> => {
): Promise<ConsultingSessionDataInterface> => {
return fetchData({
url: endpoints.userDataBySessionId(sessionId),
rcValidation: true,
Expand Down
55 changes: 36 additions & 19 deletions src/components/agencySelection/AgencySelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface AgencySelectionProps {
initialPostcode?: string;
hideExternalAgencies?: boolean;
onKeyDown?: Function;
age?: number;
gender?: string;
}

export const AgencySelection = (props: AgencySelectionProps) => {
Expand Down Expand Up @@ -86,7 +88,9 @@ export const AgencySelection = (props: AgencySelectionProps) => {
const response = await apiAgencySelection({
postcode: DEFAULT_POSTCODE,
consultingType: props.consultingType.id,
topicId: props?.mainTopicId
topicId: props?.mainTopicId,
age: props?.age,
gender: props?.gender
});

const defaultAgency = response[0];
Expand All @@ -101,7 +105,14 @@ export const AgencySelection = (props: AgencySelectionProps) => {
}
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [autoSelectAgency, props.consultingType.id, props?.mainTopicId, locale]);
}, [
autoSelectAgency,
props.consultingType.id,
props?.mainTopicId,
props?.age,
props?.gender,
locale
]);

useEffect(() => {
if (isSelectedAgencyValidated()) {
Expand Down Expand Up @@ -150,7 +161,9 @@ export const AgencySelection = (props: AgencySelectionProps) => {
await apiAgencySelection({
postcode: selectedPostcode,
consultingType: props.consultingType.id,
topicId: props?.mainTopicId
topicId: props?.mainTopicId,
age: props?.age,
gender: props?.gender
}).finally(() => setIsLoading(false))
).filter(
(agency) =>
Expand All @@ -163,23 +176,21 @@ export const AgencySelection = (props: AgencySelectionProps) => {
setProposedAgencies(null);
}
} catch (err: any) {
if (
err.message === FETCH_ERRORS.EMPTY &&
props.consultingType.id !== null
) {
if (err.message === FETCH_ERRORS.EMPTY) {
setProposedAgencies(null);
setPostcodeFallbackLink(
parsePlaceholderString(
settings.postcodeFallbackUrl,
{
url: props.consultingType.urls
.registrationPostcodeFallbackUrl,
postcode: selectedPostcode
}
)
);
if (props.consultingType.id !== null) {
setPostcodeFallbackLink(
parsePlaceholderString(
settings.postcodeFallbackUrl,
{
url: props.consultingType.urls
.registrationPostcodeFallbackUrl,
postcode: selectedPostcode
}
)
);
}
}
return;
}
})();
} else if (
Expand All @@ -194,7 +205,13 @@ export const AgencySelection = (props: AgencySelectionProps) => {
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedPostcode, props.consultingType.id, props?.mainTopicId]);
}, [
selectedPostcode,
props.consultingType.id,
props?.mainTopicId,
props?.age,
props?.gender
]);

const postcodeInputItem: InputFieldItem = {
name: 'postcode',
Expand Down
6 changes: 2 additions & 4 deletions src/components/askerInfo/AskerInfoData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export const AskerInfoData = () => {

const consultingType = useConsultingType(activeSession.item.consultingType);

const userSessionData = getContact(
activeSession,
translate('sessionList.user.consultantUnknown')
).sessionData;
const userSessionData = getContact(activeSession).sessionData;
const preparedUserSessionData =
convertUserDataObjectToArray(userSessionData);

Expand All @@ -35,6 +32,7 @@ export const AskerInfoData = () => {
? translate(
[
`consultingType.${consultingType.id}.titles.default`,
`consultingType.fallback.titles.default`,
consultingType.titles.default
],
{ ns: 'consultingTypes' }
Expand Down
2 changes: 1 addition & 1 deletion src/components/askerInfo/AskerInfoTools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useTranslation } from 'react-i18next';
export const AskerInfoTools = () => {
const { t: translate } = useTranslation();
const { activeSession } = useContext(ActiveSessionContext);
const [askerId, setAskerId] = useState();
const [askerId, setAskerId] = useState<string>();

const openToolsLink = () => {
refreshKeycloakAccessToken().then((resp) => {
Expand Down
4 changes: 3 additions & 1 deletion src/components/box/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { ReactNode } from 'react';
import './box.styles';

type BoxProps = {
title?: string;
children: ReactNode;
};

export const Box = ({ children }: BoxProps) => {
export const Box = ({ children, title }: BoxProps) => {
return (
<div className="box">
{title && <div className="box__title">{title}</div>}
<div className="box__content">{children}</div>
</div>
);
Expand Down
9 changes: 9 additions & 0 deletions src/components/box/box.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@
padding: $grid-base-three;
margin-bottom: $grid-base-two;
}

&__title {
font-style: normal;
font-weight: 700;
font-size: 16px;
line-height: 24px;
color: rgba(0, 0, 0, 0.87);
margin-bottom: 16px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const ConsultingTypeAgencySelection = ({
label: translate(
[
`consultingType.${consultingType.id}.titles.long`,
`consultingType.fallback.titles.long`,
consultingType.titles.long
],
{ ns: 'consultingTypes' }
Expand Down
1 change: 1 addition & 0 deletions src/components/formAccordion/FormAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export const FormAccordion = ({
label: translate(
[
`consultingType.${consultingType.id}.requiredComponents.age.${option.value}`,
`consultingType.fallback.requiredComponents.age.${option.value}`,
option.label
],
{ ns: 'consultingTypes' }
Expand Down
8 changes: 7 additions & 1 deletion src/components/groupChat/JoinGroupChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,13 @@ export const JoinGroupChatView = ({
consultingType?.id ?? 'noConsultingType'
}.groupChatRules`;
const translatedRules: { [key: string]: string } =
i18n.getResource(i18n.language, 'consultingTypes', transKey) || {};
i18n.getResource(i18n.language, 'consultingTypes', transKey) ||
i18n.getResource(
i18n.language,
'consultingTypes',
`consultingType.fallback.groupChatRules`
) ||
{};
if (Object.keys(translatedRules).length > 0) {
groupChatRules = Object.values(translatedRules);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import { useHistory } from 'react-router-dom';
import { SendMessageButton } from './SendMessageButton';
import { SESSION_LIST_TYPES } from '../session/sessionHelpers';
import { Checkbox, CheckboxItem } from '../checkbox/Checkbox';
import {
AUTHORITIES,
getContact,
hasUserAuthority
} from '../../globalState/helpers/stateHelpers';
import { AUTHORITIES, getContact, hasUserAuthority } from '../../globalState';
import {
AnonymousConversationFinishedContext,
E2EEContext,
Expand Down Expand Up @@ -856,17 +852,13 @@ export const MessageSubmitInterfaceComponent = ({
const getMessageSubmitInfo = useCallback((): MessageSubmitInfoInterface => {
let infoData;
if (activeInfo === INFO_TYPES.ABSENT) {
const contact = getContact(activeSession);
infoData = {
isInfo: true,
infoHeadline: `${
getContact(
activeSession,
translate('sessionList.user.consultantUnknown')
).displayName ||
getContact(
activeSession,
translate('sessionList.user.consultantUnknown')
).username
contact?.displayName ||
contact?.username ||
translate('sessionList.user.consultantUnknown')
} ${translate('consultant.absent.message')} `,
infoMessage: activeSession.consultant.absenceMessage
};
Expand Down
1 change: 1 addition & 0 deletions src/components/profile/AskerConsultingTypeData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const AskerConsultingTypeData = () => {
text={translate(
[
`consultingType.${resort.agency.consultingType}.titles.default`,
`consultingType.fallback.titles.default`,
consultingTypes.find(
(cur) =>
cur.id ===
Expand Down
1 change: 1 addition & 0 deletions src/components/profile/AskerRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const AskerRegistration: React.FC = () => {
label: translate(
[
`consultingType.${option.id}.titles.registrationDropdown`,
`consultingType.fallback.titles.registrationDropdown`,
option.label
],
{ ns: 'consultingTypes' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const AskerRegistrationExternalAgencyOverlay = ({
translate(
[
`consultingType.${consultingType.id}.titles.default`,
`consultingType.fallback.titles.default`,
consultingType.titles.default
],
{ ns: 'consultingTypes' }
Expand Down
4 changes: 4 additions & 0 deletions src/components/registration/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const Registration = ({
)} ${translate(
[
`consultingType.${consultant.agencies[0].consultingTypeRel.id}.titles.long`,
`consultingType.fallback.titles.long`,
consultant.agencies[0].consultingTypeRel.titles.long
],
{ ns: 'consultingTypes' }
Expand Down Expand Up @@ -131,6 +132,7 @@ export const Registration = ({
)} ${translate(
[
`consultingType.${consultingType.id}.titles.long`,
`consultingType.fallback.titles.long`,
consultingType.titles.long
],
{ ns: 'consultingTypes' }
Expand Down Expand Up @@ -171,6 +173,7 @@ export const Registration = ({
? translate(
[
`consultingType.${consultingType?.id}.titles.welcome`,
`consultingType.fallback.titles.welcome`,
consultingType?.titles.welcome
],
{ ns: 'consultingTypes' }
Expand All @@ -188,6 +191,7 @@ export const Registration = ({
? translate(
[
`consultingType.${consultingType?.id}.titles.long`,
`consultingType.fallback.titles.long`,
consultingType?.titles.long
],
{ ns: 'consultingTypes' }
Expand Down
1 change: 1 addition & 0 deletions src/components/registration/RegistrationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export const RegistrationForm = () => {
? translate(
[
`consultingType.${consultingType.id}.titles.long`,
`consultingType.fallback.titles.long`,
consultingType.titles.long
],
{ ns: 'consultingTypes' }
Expand Down
2 changes: 2 additions & 0 deletions src/components/serviceExplanation/ServiceExplanation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const ServiceExplanation = ({
title: translate(
[
`consultingType.${consultingTypeId}.welcomeScreen.anonymous.title`,
`consultingType.fallback.welcomeScreen.anonymous.title`,
welcomeScreenConfig?.anonymous.title ??
'registration.welcomeScreen.info4.title'
],
Expand All @@ -52,6 +53,7 @@ export const ServiceExplanation = ({
text: translate(
[
`consultingType.${consultingTypeId}.welcomeScreen.anonymous.text`,
`consultingType.fallback.welcomeScreen.anonymous.text`,
welcomeScreenConfig?.anonymous.text ??
'registration.welcomeScreen.info4.text'
],
Expand Down
6 changes: 2 additions & 4 deletions src/components/session/AcceptLiveChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ export const AcceptLiveChatView = ({
text={`${translate(
'enquiry.anonymous.infoLabel.start'
)}${
getContact(
activeSession,
translate('sessionList.user.consultantUnknown')
).username
getContact(activeSession)?.username ||
translate('sessionList.user.consultantUnknown')
}${translate('enquiry.anonymous.infoLabel.end')}`}
/>
</div>
Expand Down
10 changes: 4 additions & 6 deletions src/components/session/SessionItemComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,10 @@ export const SessionItemComponent = (props: SessionItemProps) => {
<React.Fragment key={`${message._id}-${index}`}>
<MessageItemComponent
clientName={
getContact(
activeSession,
translate(
'sessionList.user.consultantUnknown'
)
).username
getContact(activeSession)?.username ||
translate(
'sessionList.user.consultantUnknown'
)
}
askerRcId={activeSession.item.askerRcId}
isOnlyEnquiry={isOnlyEnquiry}
Expand Down
2 changes: 1 addition & 1 deletion src/components/session/sessionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
STATUS_ARCHIVED,
STATUS_EMPTY,
STATUS_ENQUIRY
} from '../../globalState/interfaces/SessionsDataInterface';
} from '../../globalState';

import { MessageItem } from '../message/MessageItemComponent';
import {
Expand Down
5 changes: 1 addition & 4 deletions src/components/sessionHeader/GroupChatHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ export const GroupChatHeader = ({
rcUserId: getValueFromCookie('rc_uid')
});

const userSessionData = getContact(
activeSession,
t('sessionList.user.consultantUnknown')
).sessionData;
const userSessionData = getContact(activeSession)?.sessionData || {};
const isAskerInfoAvailable = () =>
!hasUserAuthority(AUTHORITIES.ASKER_DEFAULT, userData) &&
consultingType?.showAskerProfile &&
Expand Down
Loading

0 comments on commit 751cae3

Please sign in to comment.