feat: Implement course detail viewing and enrollment functionality with a new useCourse composable.
This commit is contained in:
parent
a65ded02f9
commit
23d9e44cc9
4 changed files with 65 additions and 27 deletions
|
|
@ -31,6 +31,23 @@ const isEnrolling = ref(false)
|
|||
const handleEnroll = async () => {
|
||||
if (!course.value) return
|
||||
if (isEnrolling.value) return
|
||||
|
||||
// กรณีเคยกดลงทะเบียนไปแล้ว (Check จากสถานะคอร์ส)
|
||||
if (course.value.enrolled) {
|
||||
$q.dialog({
|
||||
message: `<div class="text-slate-800 text-base leading-relaxed">ท่านเคยลงทะเบียนคอร์ส <b class="text-blue-600">"${getLocalizedText(course.value.title)}"</b> นี้ไปเรียบร้อยแล้ว</div>`,
|
||||
html: true,
|
||||
ok: {
|
||||
label: 'ตกลง',
|
||||
color: 'primary',
|
||||
rounded: true,
|
||||
unelevated: true,
|
||||
padding: '8px 32px'
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
isEnrolling.value = true
|
||||
|
||||
// เรียก API ลงทะเบียนเรียน
|
||||
|
|
@ -38,7 +55,6 @@ const handleEnroll = async () => {
|
|||
|
||||
if (res.success) {
|
||||
// ถ้าสำเร็จ ให้เปลี่ยนหน้าไปที่ "คอร์สของฉัน" พร้อม params enrolled=true
|
||||
// Use object syntax for robust query param handling
|
||||
const targetId = route.params.id || course.value?.id
|
||||
return navigateTo({
|
||||
path: '/dashboard/my-courses',
|
||||
|
|
@ -47,14 +63,30 @@ const handleEnroll = async () => {
|
|||
course_id: String(targetId)
|
||||
}
|
||||
})
|
||||
// กรณี error แสดง Toast notification แทน alert
|
||||
$q.notify({
|
||||
type: 'negative',
|
||||
message: res.error || 'Failed to enroll',
|
||||
position: 'top',
|
||||
timeout: 3000,
|
||||
actions: [{ icon: 'close', color: 'white' }]
|
||||
})
|
||||
} else {
|
||||
// กรณี API แจ้งว่าเคยลงทะเบียนไปแล้ว (Code 409)
|
||||
if (res.code === 409) {
|
||||
$q.dialog({
|
||||
message: `<div class="text-slate-800 text-base leading-relaxed">ท่านเคยลงทะเบียนคอร์ส <b class="text-blue-600">"${getLocalizedText(course.value.title)}"</b> นี้ไปเรียบร้อยแล้ว</div>`,
|
||||
html: true,
|
||||
ok: {
|
||||
label: 'ตกลง',
|
||||
color: 'primary',
|
||||
rounded: true,
|
||||
unelevated: true,
|
||||
padding: '8px 32px'
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// กรณี error ทั่วไป แสดง Toast notification
|
||||
$q.notify({
|
||||
type: 'negative',
|
||||
message: res.error || 'Failed to enroll',
|
||||
position: 'top',
|
||||
timeout: 3000,
|
||||
actions: [{ icon: 'close', color: 'white' }]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
isEnrolling.value = false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue