Skip to content

Commit

Permalink
Merge pull request #71 from AAISS/certificate-download-button
Browse files Browse the repository at this point in the history
Added certificate download button to user's personal page
  • Loading branch information
AlirezaYousefpourM authored Jan 11, 2024
2 parents 1a883d9 + 3c6d505 commit efe4f90
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 27 deletions.
14 changes: 14 additions & 0 deletions frontend/src/components/item-card/item-card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const ItemCard = ({
startDate,
endDate,
presenterName,
certificateLink,
finished,
level,
cost = 50000,
Expand Down Expand Up @@ -193,6 +194,18 @@ const ItemCard = ({
</Button>
{getActionComponent()}
</CardActions>
{certificateLink &&
<Button
href={certificateLink}
style={{
backgroundColor: "#ec6803",
color: "#fff",
width: "100%",
}}
>
Download Certificate!
</Button>
}
</Card>
</>
);
Expand All @@ -216,6 +229,7 @@ ItemCard.propTypes = {
addToCalendarLink: PropTypes.string,
onClickAddToCart: PropTypes.func,
remainingCapacity: PropTypes.number,
certificateLink: PropTypes.string,
finished: PropTypes.bool,
};

Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/my-account/MyAccount.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const MyAccount = () => {
presenterName={item.presenters?.join(', ') ?? item.teachers?.join(', ')}
cost={item.cost}
hasProject={item.has_project}
certificateLink={item.certificateLink}
prerequisites={item.prerequisites}
syllabus={item.syllabus}
capacity={item.capacity}
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/pages/my-account/useMyAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ export default function useMyAccount() {
if (presentation.id === userPresentation.id) {
presentation.type = "presentation"
if (userPresentation.status !== "AWAITING_PAYMENT") {
if (userPresentation.certificate) {
presentation.certificateLink = userPresentation.certificate
}
userTempPresentations.push(presentation)
} else {
userTempCart.push(presentation)
Expand All @@ -172,6 +175,9 @@ export default function useMyAccount() {
if (workshop.id === userWorkshop.id) {
workshop.type = "workshop"
if (userWorkshop.status !== "AWAITING_PAYMENT") {
if (userWorkshop.certificate) {
workshop.certificateLink = userWorkshop.certificate
}
userTempWorkshops.push(workshop)
} else {
userTempCart.push(workshop)
Expand Down
54 changes: 27 additions & 27 deletions frontend/src/providers/APIProvider/APIProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function APIProvider({ children }) {
const { accessToken, refreshToken, setAccessTokenFromLocalStorage } = useConfig();

const service = axios;
const currentYear = new Date().getFullYear();
const year = "2023";

const [workshopsData, setWorkshopsData] = useState();
const [presentationsData, setPresentationsData] = useState();
Expand Down Expand Up @@ -200,19 +200,19 @@ export function APIProvider({ children }) {
async (id) => {
if (id != null) id = id + '/';
await service
.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.presenter}${id ?? ''}`)
.get(`${URL.baseURL}${URL.services[year]}${URL.endpoints.presenter}${id ?? ''}`)
.then((response) => {
setPresenterData(response.data);
});
},
[currentYear, service],
[year, service],
);

const getCommitteeData = useCallback(async () => {
await service.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.committee}`).then((response) => {
await service.get(`${URL.baseURL}${URL.services[year]}${URL.endpoints.committee}`).then((response) => {
setCommitteeData(response.data);
});
}, [currentYear, service]);
}, [year, service]);

const postVerifyPayment = useCallback(
async (data) => {
Expand All @@ -225,7 +225,7 @@ export function APIProvider({ children }) {
setVerifyPaymentData(error.response);
});
},
[currentYear, service],
[year, service],
);

const postPaymentData = useCallback(
Expand All @@ -243,46 +243,46 @@ export function APIProvider({ children }) {
setPaymentData(error.response);
});
},
[currentYear, service, getAccessTokenHeader],
[year, service, getAccessTokenHeader],
);

const activateUser = useCallback(async () => {
await service.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.user.activate}`).then((response) => {
await service.get(`${URL.baseURL}${URL.services[year]}${URL.endpoints.user.activate}`).then((response) => {
setActivateUserData(response.data);
});
}, [currentYear, service]);
}, [year, service]);

const deleteUser = useCallback(
async (data) => {
await service
.delete(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.user.default}`, data)
.delete(`${URL.baseURL}${URL.services[year]}${URL.endpoints.user.default}`, data)
.then((response) => {
setDeleteUserData(response.data);
});
},
[currentYear, service],
[year, service],
);

const partiallyUpdateUser = useCallback(
async (data) => {
await service
.patch(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.user.default}`, data)
.patch(`${URL.baseURL}${URL.services[year]}${URL.endpoints.user.default}`, data)
.then((response) => {
setPartiallyUpdateUserData(response.data);
});
},
[currentYear, service],
[year, service],
);

const updateUser = useCallback(
async (data) => {
await service
.put(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.user.default}`, data)
.put(`${URL.baseURL}${URL.services[year]}${URL.endpoints.user.default}`, data)
.then((response) => {
setUpdateUserData(response);
});
},
[currentYear, service],
[year, service],
);

const createUser = useCallback(
Expand All @@ -303,58 +303,58 @@ export function APIProvider({ children }) {
async (id) => {
if (id != null) id = id + '/';
await service
.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.user.default}${id ?? ''}`)
.get(`${URL.baseURL}${URL.services[year]}${URL.endpoints.user.default}${id ?? ''}`)
.then((response) => {
setUserData(response.data);
});
},
[currentYear, service],
[year, service],
);

const getMiscData = useCallback(
async (id) => {
if (id != null) id = id + '/';
await service
.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.misc}${id ?? ''}`)
.get(`${URL.baseURL}${URL.services[year]}${URL.endpoints.misc}${id ?? ''}`)
.then((response) => {
setMiscData(response.data);
});
},
[currentYear, service],
[year, service],
);

const getStaffData = useCallback(async () => {
await service.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.staff}`).then((response) => {
await service.get(`${URL.baseURL}${URL.services[year]}${URL.endpoints.staff}`).then((response) => {
setStaffData(response.data);
});
}, [currentYear, service]);
}, [year, service]);

const getWorkshopsData = useCallback(
async (id) => {
if (id != null) id = id + '/';
await service
.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.workshop}${id ?? ''}`)
.get(`${URL.baseURL}${URL.services[year]}${URL.endpoints.workshop}${id ?? ''}`)
.then((response) => {
setWorkshopsData(response.data);
});
},
[currentYear, service],
[year, service],
);

const getPresentationsData = useCallback(async () => {
await service.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.presentation}`).then((response) => {
await service.get(`${URL.baseURL}${URL.services[year]}${URL.endpoints.presentation}`).then((response) => {
setPresentationsData(response.data);
});
}, [currentYear, service]);
}, [year, service]);

const getTeachersData = useCallback(
async (id) => {
if (id != null) id = id + '/';
await service
.get(`${URL.baseURL}${URL.services[currentYear]}${URL.endpoints.teacher}${id ?? ''}`)
.get(`${URL.baseURL}${URL.services[year]}${URL.endpoints.teacher}${id ?? ''}`)
.then((response) => setTeachersData(response.data));
},
[currentYear, service],
[year, service],
);

useEffect(() => {
Expand Down

0 comments on commit efe4f90

Please sign in to comment.