Skip to content

Commit

Permalink
fix: displaying presenters/teachers name on my account page
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirezaYousefpourM committed Nov 28, 2023
1 parent 8f19020 commit 7947495
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion frontend/src/pages/my-account/MyAccount.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
73 changes: 69 additions & 4 deletions frontend/src/pages/my-account/useMyAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export default function useMyAccount() {
setPresentationsData,
postPaymentData,
paymentData,
getTeachersData,
teachersData,
getPresenterData,
presenterData,
} = useAPI()

const {
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit 7947495

Please sign in to comment.