diff --git a/frontend/src/pages/my-account/MyAccount.jsx b/frontend/src/pages/my-account/MyAccount.jsx index e7f0753..9fc7d49 100644 --- a/frontend/src/pages/my-account/MyAccount.jsx +++ b/frontend/src/pages/my-account/MyAccount.jsx @@ -71,7 +71,7 @@ const MyAccount = () => { level={item.level} startDate={item.start_date} endDate={item.end_date} - presenterName={item.presenters?.[0]} + presenterName={item.presenters?.join(", ") ?? item.teachers?.join(", ")} cost={item.cost} hasProject={item.hasProject} prerequisites={item.prerequisites} diff --git a/frontend/src/pages/my-account/useMyAccount.js b/frontend/src/pages/my-account/useMyAccount.js index 7a82ee8..777822f 100644 --- a/frontend/src/pages/my-account/useMyAccount.js +++ b/frontend/src/pages/my-account/useMyAccount.js @@ -21,6 +21,10 @@ export default function useMyAccount() { setPresentationsData, postPaymentData, paymentData, + getTeachersData, + teachersData, + getPresenterData, + presenterData, } = useAPI() const { @@ -100,19 +104,23 @@ export default function useMyAccount() { getPresentationsData() getUserWorkshops() getUserPresentations() + getTeachersData() + getPresenterData() }, [accessToken, getUserPresentations, getUserWorkshops]) useEffect(() => { if (!userPresentationsData || !userWorkshopsData || !workshopsData + || !presenterData + || !teachersData || !presentationsData) return - const userTempPresentations = [] - const userTempWorkshops = [] - const userTempCart = [] + let userTempPresentations = [] + let userTempWorkshops = [] + let userTempCart = [] for (const presentation of presentationsData) { for (const userPresentation of userPresentationsData.data) { if (presentation.id === userPresentation.id) { @@ -138,10 +146,67 @@ export default function useMyAccount() { } } + for (const presenterOrTeacher of teachersData.concat(presenterData)) { + userTempWorkshops = userTempWorkshops.map(workshop => { + const newTeachers = [] + for (const id of workshop.teachers) { + if (id === presenterOrTeacher.id) { + newTeachers.push(presenterOrTeacher.name) + } else { + newTeachers.push(id) + } + } + workshop.teachers = newTeachers + return workshop + }) + userTempPresentations = userTempPresentations.map(presentation => { + const newPresenters = [] + for (const id of presentation.presenters) { + if (id === presenterOrTeacher.id) { + newPresenters.push(presenterOrTeacher.name) + } else { + newPresenters.push(id) + } + } + presentation.presenters = newPresenters + return presentation + }) + userTempCart = userTempCart.map(cartItem => { + const newPresenters = [] + for (const id of cartItem.presenters ?? []) { + if (id === presenterOrTeacher.id) { + newPresenters.push(presenterOrTeacher.name) + } else { + newPresenters.push(id) + } + } + for (const id of cartItem.teachers ?? []) { + if (id === presenterOrTeacher.id) { + newPresenters.push(presenterOrTeacher.name) + } else { + newPresenters.push(id) + } + } + if (cartItem.teachers) { + cartItem.teachers = newPresenters + } else { + cartItem.presenters = newPresenters + } + return cartItem + }) + } + + console.log(userTempCart) + setTalks(userTempPresentations) setWorkshops(userTempWorkshops) setCart(userTempCart) - }, [userPresentationsData, workshopsData, presentationsData, userWorkshopsData]) + }, [userPresentationsData, + workshopsData, + presentationsData, + teachersData, + presenterData, + userWorkshopsData]) return { talks,