feat: Add useCourse composable for course data management and a new discovery page.
This commit is contained in:
parent
327f6ec7b5
commit
8f38f795e6
2 changed files with 13 additions and 6 deletions
|
|
@ -138,6 +138,19 @@ export const useCourse = () => {
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error('Enroll course failed:', err)
|
console.error('Enroll course failed:', err)
|
||||||
|
|
||||||
|
// Check for 409 Conflict (Already Enrolled)
|
||||||
|
// ofetch/h3 error properties might vary, check common ones
|
||||||
|
const status = err.statusCode || err.status || err.response?.status
|
||||||
|
|
||||||
|
if (status === 409) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: 'ท่านได้ลงทะเบียนไปแล้ว',
|
||||||
|
code: 409
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: err.data?.message || err.message || 'Error enrolling in course',
|
error: err.data?.message || err.message || 'Error enrolling in course',
|
||||||
|
|
|
||||||
|
|
@ -86,12 +86,6 @@ const handleEnroll = async (id: number) => {
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
// Navigate to my-courses where the success modal will be shown
|
// Navigate to my-courses where the success modal will be shown
|
||||||
return navigateTo('/dashboard/my-courses?enrolled=true');
|
return navigateTo('/dashboard/my-courses?enrolled=true');
|
||||||
} else if (res.code === 409) {
|
|
||||||
// Already enrolled, maybe redirect to course learning page or my-courses?
|
|
||||||
// For now, let's redirect to my-courses as well, maybe with a different param or just same.
|
|
||||||
// User requirement didn't specify distinct behavior for 409 in UI terms,
|
|
||||||
// but 'Already enrolled' implies they should go see it.
|
|
||||||
return navigateTo('/dashboard/my-courses');
|
|
||||||
} else {
|
} else {
|
||||||
alert(res.error || 'Failed to enroll');
|
alert(res.error || 'Failed to enroll');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue