diff --git a/frontend/src/pages/workshops/useWorkshopsPage.js b/frontend/src/pages/workshops/useWorkshopsPage.js index baaa077..5a4375a 100644 --- a/frontend/src/pages/workshops/useWorkshopsPage.js +++ b/frontend/src/pages/workshops/useWorkshopsPage.js @@ -9,6 +9,10 @@ export default function useWorkshopsPage() { presentationsData, addToCartResponse, addItemToCart, + teachersData, + getTeachersData, + presenterData, + getPresenterData, setAddToCartResponse, } = useAPI() @@ -50,27 +54,45 @@ export default function useWorkshopsPage() { useEffect(() => { getWorkshopsData() getPresentationsData() + getTeachersData() + getPresenterData() }, [getPresentationsData, getWorkshopsData]) useEffect(() => { - if (workshopsData == null || presentationsData == null) return - - const parsedData = workshopsData.concat(presentationsData).map(e => { - if ("is_full" in e && !("id" in e)) return null + if (workshopsData == null + || presentationsData == null + || teachersData == null + || presenterData == null) return + const parsedData = workshopsData.concat(presentationsData).map(workshop => { + if ("is_full" in workshop && !("id" in workshop)) return null + if (workshop.year < 2023) + return const item = {} - item["id"] = e.id - item["name"] = e.name - item["start_date"] = e.start_date - item["end_date"] = e.end_date - item["level"] = e.level - item.presenters = e.presenters ?? e.teachers - item["desc"] = e.desc - item["isWorkshop"] = !("presenters" in e) + + const presenters = [] + if (workshop.teachers) { + workshop.teachers.forEach(item => { + presenters.push(teachersData.filter(el => el.id === item)[0].name); + }) + } else { + workshop.presenters.forEach(item => { + presenters.push(presenterData.filter(el => el.id === item)[0].name); + }) + } + item.presenters = presenters + + item["id"] = workshop.id + item["name"] = workshop.name + item["start_date"] = workshop.start_date + item["end_date"] = workshop.end_date + item["level"] = workshop.level + item["desc"] = workshop.desc + item["isWorkshop"] = !("presenters" in workshop) return item }).filter(e => e != null) setParsedItemsList(parsedData) - }, [workshopsData, presentationsData]) + }, [workshopsData, presentationsData, presenterData, teachersData]) const addToCart = useCallback(({ id, diff --git a/frontend/src/providers/APIProvider/APIProvider.jsx b/frontend/src/providers/APIProvider/APIProvider.jsx index e387a83..5230c84 100644 --- a/frontend/src/providers/APIProvider/APIProvider.jsx +++ b/frontend/src/providers/APIProvider/APIProvider.jsx @@ -296,8 +296,9 @@ export function APIProvider({children}) { }) }, [currentYear, service]) - const getTeachersData = useCallback(async () => { - await service.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.teacher}`) + const getTeachersData = useCallback(async (id) => { + if (id != null) id = id + "/" + await service.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.teacher}${id ?? ""}`) .then(response => setTeachersData(response.data)) }, [currentYear, service])