Skip to content

Commit

Permalink
createcertificate should not show success on non-generated
Browse files Browse the repository at this point in the history
  • Loading branch information
mipyykko committed Aug 25, 2023
1 parent c5b145b commit e976ddd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
3 changes: 3 additions & 0 deletions frontend/hooks/useCertificate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ export const useCertificate = ({
try {
dispatch({ type: "GENERATE_CERTIFICATE" })
const res = await createCertificate(course.slug)
if (!res) {
throw new Error("No generated certificate received")
}
dispatch({ type: "RECEIVE_GENERATED_CERTIFICATE", payload: res })
onReceiveGeneratedCertificateSuccess?.()
initialState.current = {
Expand Down
29 changes: 12 additions & 17 deletions frontend/lib/certificates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,17 @@ export const checkCertificate = async (courseSlug: string) => {
export const createCertificate = async (courseSlug: string) => {
const accessToken = getAccessToken(undefined)

try {
const res = await fetch(`${SERVICE_URL}/create/${courseSlug}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
})
if (res.ok) {
return res.json()
}
const e = await res.json()
console.log(e)
return null
} catch (e) {
console.log(e)
return null
const res = await fetch(`${SERVICE_URL}/create/${courseSlug}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
})
if (res.ok) {
return res.json()
}
const e = await res.json()
console.log(e)
return null
}

0 comments on commit e976ddd

Please sign in to comment.