Skip to content

Commit

Permalink
refactor: guidance list now uses plan template locale
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminfaure committed Nov 28, 2024
1 parent 5f3ceb0 commit 0c7ca6e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/components/WritePlan/GuidanceChoice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function GuidanceChoice({ planId, currentOrgId, currentOrgName, isClassic }) {
const orgName = currentOrgName || currentOrg.name;

setLoading(true);
guidances.getGuidanceGroups(planId, locale)
guidances.getGuidanceGroups(planId)
.then((res) => {
let guidance_groups = [];
const { data } = res.data;
Expand All @@ -63,7 +63,7 @@ function GuidanceChoice({ planId, currentOrgId, currentOrgName, isClassic }) {
})
.catch((error) => setError(error))
.finally(() => setLoading(false));
}, [planId, locale]);
}, [planId]);

const sortGuidances = (guidances) => guidances.sort((a, b) => a.name.localeCompare(b.name));

Expand Down Expand Up @@ -138,7 +138,7 @@ function GuidanceChoice({ planId, currentOrgId, currentOrgName, isClassic }) {

let response;
try {
response = await guidances.postGuidanceGroups({ guidance_group_ids: selectedGuidancesIds, ro_id: displayedResearchOutput?.id }, planId, locale);
response = await guidances.postGuidanceGroups({ guidance_group_ids: selectedGuidancesIds, ro_id: displayedResearchOutput?.id }, planId);
} catch (error) {
console.log(error);
return toast.error(t("An error occurred while saving the selected guidances"));
Expand Down
11 changes: 2 additions & 9 deletions src/services/guidances.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@ import createHeaders from '../utils/HeaderBuilder';
const getGuidances = async (planId, questionId) =>
axios.get(`/plans/${planId}/guidances?question=${questionId}`);

const getGuidanceGroups = async (planId, locale = 'fr-FR') => {
const locales = {
en: 'en-GB',
fr: 'fr-FR',
};
const getGuidanceGroups = async (planId) => axios.get(`/plans/${planId}/guidance_groups`);

return axios.get(`/plans/${planId}/guidance_groups?locale=${(locales?.[locale] || locale).replace('_', '-')}`);
};

const postGuidanceGroups = async (jsonObject, planId, locale = 'fr-FR') => axios.post(`/plans/${planId}/guidance_groups?locale=${locale.replace('_', '-')}`, jsonObject, { headers: createHeaders({}, true) });
const postGuidanceGroups = async (jsonObject, planId) => axios.post(`/plans/${planId}/guidance_groups`, jsonObject, { headers: createHeaders({}, true) });

// eslint-disable-next-line import/no-anonymous-default-export
export default {
Expand Down

0 comments on commit 0c7ca6e

Please sign in to comment.