feat: Implement course detail viewing and enrollment functionality with a new useCourse composable.

This commit is contained in:
supalerk-ar66 2026-02-11 17:06:18 +07:00
parent a65ded02f9
commit 23d9e44cc9
4 changed files with 65 additions and 27 deletions

View file

@ -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