From c14d7ca779c69868c1181978bd94935edadbd8d8 Mon Sep 17 00:00:00 2001 From: gustavomm19 Date: Wed, 16 Aug 2023 23:32:38 +0000 Subject: [PATCH 1/3] add academy aliases to session --- src/components/UpcomingDates/index.js | 7 ++++--- src/templates/calendar.js | 3 ++- src/templates/outcomes.js | 1 - src/worker.js | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/components/UpcomingDates/index.js b/src/components/UpcomingDates/index.js index cb8567f42..6268a5cac 100644 --- a/src/components/UpcomingDates/index.js +++ b/src/components/UpcomingDates/index.js @@ -139,7 +139,8 @@ const UpcomingDates = ({ useEffect(() => { const getData = async () => { - const cohorts = await getCohorts({ academy: location }); + const academySlug = session.academyAliasDictionary[location] ? session.academyAliasDictionary[location] : location; + const cohorts = await getCohorts({ academy: academySlug }); console.log("cohorts upcoming", cohorts); let syllabus = []; for (let i in cohorts) { @@ -166,8 +167,8 @@ const UpcomingDates = ({ }, })); }; - getData(); - }, []); + if (session?.academyAliasDictionary) getData(); + }, [session]); const formIsValid = (formData = null) => { if (!formData) return null; diff --git a/src/templates/calendar.js b/src/templates/calendar.js index dbaf11f79..c025c137b 100644 --- a/src/templates/calendar.js +++ b/src/templates/calendar.js @@ -370,11 +370,12 @@ const Calendar = (props) => { value={academy} onChange={(opt) => { setAcademy(opt); + const academySlug = session.academyAliasDictionary[opt.value] || opt.value let filtered = opt.label !== "All Locations" ? datas[filterType.value].all.filter( - (elm) => elm.academy.slug === opt.value + (elm) => elm.academy.slug === academySlug ) : datas[filterType.value].all; // if no cohorts on location, try to include online diff --git a/src/templates/outcomes.js b/src/templates/outcomes.js index f9c14202c..fb3d5c919 100644 --- a/src/templates/outcomes.js +++ b/src/templates/outcomes.js @@ -157,7 +157,6 @@ const Outcomes = ({ data, pageContext, yml }) => {
{ } if (!language) language = location.defaultLanguage; + + //construct the academy alias dictionary + let academyAlias = await fetch( + `${process.env.GATSBY_BREATHECODE_HOST}/marketing/alias?academy=2,4,5,6,7,8,9,10,11`, + { + method: "GET", + } + ); + academyAlias = await academyAlias.json(); + + const academyAliasDictionary = {} + academyAlias.map((alias) => { + const key = alias.slug; + academyAliasDictionary[key] = alias.academy.slug + }); + const _session = { ...defaultSession, ...storedSession, @@ -266,6 +282,7 @@ const initSession = async (locationsArray, storedSession, seed = {}) => { language, latitude, longitude, + academyAliasDictionary, pathsDictionary, // marketing utm info From a05005cf512d14d2fd72b743866c38d798eb47bd Mon Sep 17 00:00:00 2001 From: gustavomm19 Date: Wed, 16 Aug 2023 23:32:52 +0000 Subject: [PATCH 2/3] add academy aliases to session --- src/components/UpcomingDates/index.js | 4 +++- src/templates/calendar.js | 3 ++- src/worker.js | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/UpcomingDates/index.js b/src/components/UpcomingDates/index.js index 6268a5cac..3d67a86ea 100644 --- a/src/components/UpcomingDates/index.js +++ b/src/components/UpcomingDates/index.js @@ -139,7 +139,9 @@ const UpcomingDates = ({ useEffect(() => { const getData = async () => { - const academySlug = session.academyAliasDictionary[location] ? session.academyAliasDictionary[location] : location; + const academySlug = session.academyAliasDictionary[location] + ? session.academyAliasDictionary[location] + : location; const cohorts = await getCohorts({ academy: academySlug }); console.log("cohorts upcoming", cohorts); let syllabus = []; diff --git a/src/templates/calendar.js b/src/templates/calendar.js index c025c137b..2fb9553c7 100644 --- a/src/templates/calendar.js +++ b/src/templates/calendar.js @@ -370,7 +370,8 @@ const Calendar = (props) => { value={academy} onChange={(opt) => { setAcademy(opt); - const academySlug = session.academyAliasDictionary[opt.value] || opt.value + const academySlug = + session.academyAliasDictionary[opt.value] || opt.value; let filtered = opt.label !== "All Locations" diff --git a/src/worker.js b/src/worker.js index b3ef84dc8..b27665ff3 100644 --- a/src/worker.js +++ b/src/worker.js @@ -265,10 +265,10 @@ const initSession = async (locationsArray, storedSession, seed = {}) => { ); academyAlias = await academyAlias.json(); - const academyAliasDictionary = {} + const academyAliasDictionary = {}; academyAlias.map((alias) => { const key = alias.slug; - academyAliasDictionary[key] = alias.academy.slug + academyAliasDictionary[key] = alias.academy.slug; }); const _session = { From 17ec57ffa7893cab57706c06a2d803d7aad9ed81 Mon Sep 17 00:00:00 2001 From: gustavomm19 Date: Mon, 21 Aug 2023 19:51:25 +0000 Subject: [PATCH 3/3] remove comment --- src/templates/calendar.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/templates/calendar.js b/src/templates/calendar.js index 2fb9553c7..f500b2867 100644 --- a/src/templates/calendar.js +++ b/src/templates/calendar.js @@ -753,9 +753,6 @@ export const query = graphql` width: 400 placeholder: NONE # --> NONE || DOMINANT_COLOR || BLURRED | TRACED_SVG ) - # fluid(maxWidth: 400) { - # ...GatsbyImageSharpFluid_withWebp - # } } } }