Skip to content

Commit

Permalink
fix: registration consulting types
Browse files Browse the repository at this point in the history
  • Loading branch information
web-mi committed Feb 20, 2024
1 parent bbcee3e commit 949d61a
Show file tree
Hide file tree
Showing 22 changed files with 610 additions and 332 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ REACT_APP_DISABLE_2FA_DUTY=0

### Registration
# Enable fallback loader for direct link registration where slug could not be matched (0/1)
FRONTEND_REGISTRATION_DIRECTLINK_FALLBACKLOADER_ENABLED=
FRONTEND_REGISTRATION_USE_CONSULTINGTYPE_SLUG=

### Weblate
# Weblate host
Expand Down
12 changes: 3 additions & 9 deletions proxy/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ module.exports = {
}
},
registration: {
directlink: {
fallbackLoader: {
enabled: !!parseInt(
process.env
.FRONTEND_REGISTRATION_DIRECTLINK_FALLBACKLOADER_ENABLED ||
'1'
)
}
}
useConsultingTypeSlug: !!parseInt(
process.env.FRONTEND_REGISTRATION_USE_CONSULTINGTYPE_SLUG || '0'
)
}
};
49 changes: 35 additions & 14 deletions src/api/apiAgencySelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import { endpoints } from '../resources/scripts/endpoints';
import { fetchData, FETCH_METHODS, FETCH_ERRORS } from './fetchData';
import { VALID_POSTCODE_LENGTH } from '../components/agencySelection/agencySelectionHelpers';
import { AgencyDataInterface } from '../globalState';
import { loadConsultingTypeForAgency } from '../utils/loadConsultingTypeForAgency';

export const apiAgencySelection = async (
params: {
{
fetchConsultingTypeDetails,
...params
}: {
postcode: string;
consultingType: number | undefined;
topicId?: number;
age?: number;
gender?: string;
counsellingRelation?: string;
fetchConsultingTypeDetails?: boolean;
},
signal?: AbortSignal
): Promise<Array<AgencyDataInterface> | null> => {
Expand All @@ -24,22 +32,35 @@ export const apiAgencySelection = async (
skipAuth: true,
responseHandling: [FETCH_ERRORS.EMPTY],
...(signal && { signal: signal })
}).then((result) => {
if (result) {
// External agencies should only be returned
// if there are no internal ones.
const internalAgencies = result.filter(
(agency) => !agency.external
);
if (internalAgencies.length > 0) {
return internalAgencies;
})
.then((result) => {
if (result) {
// External agencies should only be returned
// if there are no internal ones.
const internalAgencies = result.filter(
(agency) => !agency.external
);
if (internalAgencies.length > 0) {
return internalAgencies;
} else {
return result;
}
} else {
return result;
}
} else {
return result;
}
});
})
.then((agencies) => {
if (!fetchConsultingTypeDetails) {
return agencies;
}

return Promise.all(
agencies.map(
async (agency) =>
await loadConsultingTypeForAgency(agency)
)
);
});
} else {
return null;
}
Expand Down
14 changes: 12 additions & 2 deletions src/api/apiGetAgencyId.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { endpoints } from '../resources/scripts/endpoints';
import { fetchData, FETCH_METHODS, FETCH_ERRORS } from './fetchData';
import { AgencyDataInterface } from '../globalState';
import { loadConsultingTypeForAgency } from '../utils/loadConsultingTypeForAgency';

export const apiGetAgencyById = async (
agencyId: any
agencyId: any,
fetchConsultingTypeDetails?: boolean
): Promise<AgencyDataInterface> => {
const url = endpoints.agencyServiceBase + '/' + agencyId;

Expand All @@ -12,5 +14,13 @@ export const apiGetAgencyById = async (
method: FETCH_METHODS.GET,
skipAuth: true,
responseHandling: [FETCH_ERRORS.EMPTY, FETCH_ERRORS.NO_MATCH]
}).then((response) => response[0]);
})
.then((response) => response[0])
.then(async (agency) => {
if (!fetchConsultingTypeDetails) {
return agency;
}

return await loadConsultingTypeForAgency(agency);
});
};
52 changes: 13 additions & 39 deletions src/api/apiGetConsultant.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { endpoints } from '../resources/scripts/endpoints';
import { fetchData, FETCH_METHODS, FETCH_ERRORS } from './fetchData';
import { ConsultantDataInterface } from '../globalState';
import { apiGetConsultingType } from './apiGetConsultingType';
import { apiGetConsultingTypes } from './apiGetConsultingTypes';
import { loadConsultingTypeForAgency } from '../utils/loadConsultingTypeForAgency';

export const apiGetConsultant = async (
consultantId: any,
fetchConsultingTypes?: boolean,
consultingTypeDetail: 'full' | 'basic' = 'full'
fetchConsultingTypeDetails?: boolean
): Promise<ConsultantDataInterface> => {
const url = endpoints.agencyConsultants + '/' + consultantId;

Expand All @@ -17,43 +15,19 @@ export const apiGetConsultant = async (
skipAuth: true,
responseHandling: [FETCH_ERRORS.EMPTY, FETCH_ERRORS.NO_MATCH]
}).then((user) => {
if (!fetchConsultingTypes) {
if (!fetchConsultingTypeDetails) {
return user;
}

if (consultingTypeDetail === 'full') {
return Promise.all(
user.agencies.map(async (agency) => ({
...agency,
consultingTypeRel: await apiGetConsultingType({
consultingTypeId: agency?.consultingType
})
}))
).then((agencies): ConsultantDataInterface => {
return {
...user,
agencies
};
});
}

if (consultingTypeDetail === 'basic') {
return apiGetConsultingTypes().then((consultingTypes) => {
const mappedUserAgencies = user.agencies.map((agency) => {
const consultingTypeRel = consultingTypes.filter(
(type) => type.id === agency.consultingType
)[0];
return {
...agency,
consultingTypeRel: { ...consultingTypeRel }
};
});

return {
...user,
agencies: mappedUserAgencies
};
});
}
return Promise.all(
user.agencies.map(
async (agency) => await loadConsultingTypeForAgency(agency)
)
).then(
(agencies): ConsultantDataInterface => ({
...user,
agencies
})
);
});
};
6 changes: 4 additions & 2 deletions src/api/apiRegistrationNewConsultingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ export const apiRegistrationNewConsultingTypes = async (
consultingType: number,
agencyId: number,
postcode: string,
consultantId?: string
consultantId?: string,
topicIds?: number[]
): Promise<registrationResponse> => {
const url = endpoints.registerAskerNewConsultingType;
const data = JSON.stringify({
postcode,
agencyId,
consultingType,
consultantId
consultantId,
...(topicIds ? { topicIds: topicIds } : {})
});

return fetchData({
Expand Down
Loading

0 comments on commit 949d61a

Please sign in to comment.