-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c60ef2d
commit 4814f27
Showing
2 changed files
with
147 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,163 +1,130 @@ | ||
import {useCallback, useEffect, useState} from "react"; | ||
import {useAPI} from "../../providers/APIProvider/APIProvider.jsx"; | ||
import {useConfig} from "../../providers/config-provider/ConfigProvider.jsx"; | ||
|
||
export default function useMyAccount() { | ||
const talks = [ | ||
{ | ||
id: 1, | ||
name: 'Discriminative Feature Learning and Face Recognition', | ||
desc: 'پیشنیازهای کارگاه: \r\nKeras, Tensorflow, Convnet', | ||
year: 2021, | ||
level: 'NOT_ASSIGNED', | ||
start_date: '2021-08-27T06:00:00Z', | ||
end_date: '2021-08-31T18:00:00Z', | ||
presenters: [], | ||
cost: 50000, | ||
hasProject: true, | ||
prerequisites: 'Basic knowledge of machine learning', | ||
syllabus: 'GANs in different type of problems - Various types of GANs - Coding', | ||
capacity: 30, | ||
isFull: false, | ||
addToCalendarLink: 'https://google.com', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'A tutorial on evaluating generative models', | ||
desc: 'A tutorial on evaluating generative models', | ||
year: 2021, | ||
level: 'Elementary', | ||
start_date: '2021-08-27T06:00:00Z', | ||
end_date: '2021-08-31T18:00:00Z', | ||
presenters: [10], | ||
cost: 50000, | ||
hasProject: false, | ||
prerequisites: 'Basic knowledge of machine learning', | ||
syllabus: 'GANs in different type of problems - Various types of GANs - Coding', | ||
capacity: 50, | ||
isFull: false, | ||
addToCalendarLink: 'https://google.com', | ||
}, | ||
{ | ||
id: 3, | ||
name: 'on the privacy Risks of algorithmic fairness', | ||
desc: 'on the privacy Risks of algorithmic fairness', | ||
year: 2021, | ||
level: 'NOT_ASSIGNED', | ||
start_date: '2021-08-27T06:00:00Z', | ||
end_date: '2021-08-30T18:00:00Z', | ||
presenters: [11], | ||
cost: 12000, | ||
hasProject: true, | ||
prerequisites: 'Basic knowledge of machine learning', | ||
syllabus: 'GANs in different type of problems - Various types of GANs - Coding', | ||
capacity: 20, | ||
isFull: true, | ||
addToCalendarLink: 'https://google.com', | ||
}, | ||
]; | ||
|
||
const workshops = [ | ||
{ | ||
id: 4, | ||
name: 'Foundations of Data Augmentation', | ||
desc: 'Foundations of Data Augmentation', | ||
year: 2021, | ||
level: 'NOT_ASSIGNED', | ||
start_date: '2021-08-27T06:00:00Z', | ||
end_date: '2021-08-30T18:00:00Z', | ||
presenters: [13], | ||
cost: 50000, | ||
hasProject: true, | ||
prerequisites: 'Basic knowledge of machine learning', | ||
syllabus: 'GANs in different type of problems - Various types of GANs - Coding', | ||
capacity: 50, | ||
isFull: true, | ||
addToCalendarLink: 'https://google.com', | ||
}, | ||
{ | ||
id: 5, | ||
name: 'Representation Learning Without Labels', | ||
desc: 'Representation Learning Without Labels', | ||
year: 2021, | ||
level: 'NOT_ASSIGNED', | ||
start_date: '2021-08-27T06:00:00Z', | ||
end_date: '2021-08-30T18:00:00Z', | ||
presenters: [16], | ||
cost: 20000, | ||
hasProject: true, | ||
prerequisites: 'Basic knowledge of machine learning', | ||
syllabus: 'GANs in different type of problems - Various types of GANs - Coding', | ||
capacity: 20, | ||
isFull: false, | ||
addToCalendarLink: 'https://google.com', | ||
}, | ||
{ | ||
id: 6, | ||
name: '3D CNNs with Adaptive Temporal Feature Resolutions', | ||
desc: '3D CNNs with Adaptive Temporal Feature Resolutions', | ||
year: 2021, | ||
level: 'NOT_ASSIGNED', | ||
start_date: '2021-08-27T06:00:00Z', | ||
end_date: '2021-08-30T18:00:00Z', | ||
presenters: [14], | ||
cost: 50000, | ||
hasProject: true, | ||
prerequisites: 'Basic knowledge of machine learning', | ||
syllabus: 'GANs in different type of problems - Various types of GANs - Coding', | ||
capacity: 50, | ||
isFull: false, | ||
addToCalendarLink: 'https://google.com', | ||
}, | ||
{ | ||
id: 7, | ||
name: 'Learning Representations on Graphs', | ||
desc: 'Learning Representations on Graphs', | ||
year: 2021, | ||
level: 'NOT_ASSIGNED', | ||
start_date: '2021-08-27T06:00:00Z', | ||
end_date: '2021-08-30T18:00:00Z', | ||
presenters: [17], | ||
cost: 50000, | ||
hasProject: true, | ||
prerequisites: 'Basic knowledge of machine learning', | ||
syllabus: 'GANs in different type of problems - Various types of GANs - Coding', | ||
capacity: 50, | ||
isFull: false, | ||
addToCalendarLink: 'https://google.com', | ||
}, | ||
{ | ||
id: 8, | ||
name: 'An Introduction to Autonomous Vehicles', | ||
desc: 'An Introduction to Autonomous Vehicles', | ||
year: 2021, | ||
level: 'NOT_ASSIGNED', | ||
start_date: '2021-08-27T06:00:00Z', | ||
end_date: '2021-08-30T18:00:00Z', | ||
presenters: [18], | ||
cost: 50000, | ||
hasProject: true, | ||
prerequisites: 'Basic knowledge of machine learning', | ||
syllabus: 'GANs in different type of problems - Various types of GANs - Coding', | ||
capacity: 50, | ||
isFull: false, | ||
addToCalendarLink: 'https://google.com', | ||
}, | ||
]; | ||
const { | ||
getUserWorkshops, | ||
getUserPresentations, | ||
userPresentationsData, | ||
userWorkshopsData, | ||
getWorkshopsData, | ||
getPresentationsData, | ||
workshopsData, | ||
presentationsData, | ||
removeFromUserCart, | ||
removeFromCartResponse, | ||
setRemoveFromCartResponse, | ||
setWorkshopsData, | ||
setPresentationsData, | ||
} = useAPI() | ||
|
||
const { | ||
accessToken | ||
} = useConfig() | ||
|
||
const [talks, setTalks] = useState() | ||
const [workshops, setWorkshops] = useState() | ||
const [cart, setCart] = useState() | ||
const [openToast, setOpenToast] = useState() | ||
const [toastData, setToastData] = useState() | ||
|
||
const removeFromCartHandler = useCallback(({id, type}) => { | ||
removeFromUserCart({ | ||
id: id, | ||
type: type, | ||
}) | ||
}, [removeFromUserCart]) | ||
|
||
useEffect(() => { | ||
if (removeFromCartResponse == null) | ||
return | ||
|
||
const toastDataTemp = {} | ||
switch (removeFromCartResponse.status) { | ||
case "200": | ||
toastDataTemp.message = "Item Removed Successfully" | ||
toastDataTemp.alertType = "success" | ||
break; | ||
case "400": | ||
toastDataTemp.message = "Failed to Remove Item" | ||
toastDataTemp.alertType = "error" | ||
break; | ||
default: | ||
toastDataTemp.message = "Unknown Error. Please Try Again Later" | ||
toastDataTemp.alertType = "error" | ||
break; | ||
} | ||
|
||
setRemoveFromCartResponse(null) | ||
setToastData(toastDataTemp) | ||
setOpenToast(true) | ||
setWorkshopsData(null) | ||
setPresentationsData(null) | ||
getUserWorkshops() | ||
getUserPresentations() | ||
}, [removeFromCartResponse]) | ||
|
||
useEffect(() => { | ||
if (!accessToken) | ||
return | ||
|
||
getWorkshopsData() | ||
getPresentationsData() | ||
getUserWorkshops() | ||
getUserPresentations() | ||
}, [accessToken, getUserPresentations, getUserWorkshops]) | ||
|
||
useEffect(() => { | ||
if (!userPresentationsData | ||
|| !userWorkshopsData | ||
|| !workshopsData | ||
|| !presentationsData) | ||
return | ||
|
||
console.log("thing") | ||
|
||
const userTempPresentations = [] | ||
const userTempWorkshops = [] | ||
const userTempCart = [] | ||
for (const presentation of presentationsData) { | ||
for (const userPresentation of userPresentationsData.data) { | ||
if (presentation.id === userPresentation.id) { | ||
presentation.type = "presentation" | ||
if (userPresentation.status !== "AWAITING_PAYMENT") { | ||
userTempPresentations.push(presentation) | ||
} else { | ||
userTempCart.push(presentation) | ||
} | ||
} | ||
} | ||
} | ||
for (const workshop of workshopsData) { | ||
for (const userWorkshop of userWorkshopsData.data) { | ||
if (workshop.id === userWorkshop.id) { | ||
workshop.type = "workshop" | ||
if (userWorkshop.status !== "AWAITING_PAYMENT") { | ||
userTempWorkshops.push(workshop) | ||
} else { | ||
userTempCart.push(workshop) | ||
} | ||
} | ||
} | ||
} | ||
|
||
const cart = [ | ||
{ | ||
id: 4, | ||
name: 'Foundations of Data Augmentation', | ||
desc: 'Foundations of Data Augmentation', | ||
year: 2021, | ||
level: 'NOT_ASSIGNED', | ||
start_date: '2021-08-27T06:00:00Z', | ||
end_date: '2021-08-30T18:00:00Z', | ||
presenters: [13], | ||
cost: 120000, | ||
}, | ||
]; | ||
setTalks(userTempPresentations) | ||
setWorkshops(userTempWorkshops) | ||
setCart(userTempCart) | ||
}, [userPresentationsData, workshopsData, presentationsData, userWorkshopsData]) | ||
|
||
return { | ||
talks, | ||
workshops, | ||
cart, | ||
}; | ||
return { | ||
talks, | ||
workshops, | ||
removeFromCartHandler, | ||
cart, | ||
toastData, | ||
openToast, | ||
setOpenToast | ||
}; | ||
} |