edit: response.message

This commit is contained in:
Missez 2026-02-02 09:31:22 +07:00
parent d7f824f353
commit 7de5457170
21 changed files with 227 additions and 127 deletions

View file

@ -430,7 +430,7 @@ const saveLesson = async () => {
navigateTo(`/instructor/courses/${courseId}/structure`);
} catch (error) {
console.error('Failed to save lesson:', error);
$q.notify({ type: 'negative', message: 'ไม่สามารถบันทึกได้', position: 'top' });
$q.notify({ type: 'negative', message: (error as any).data?.error?.message || (error as any).data?.message || 'ไม่สามารถบันทึกได้', position: 'top' });
} finally {
saving.value = false;
}

View file

@ -62,6 +62,20 @@
autogrow
rows="3"
/>
<q-card-section class="flex justify-end gap-2">
<q-btn
flat
label="ยกเลิก"
@click="navigateTo(`/instructor/courses/${courseId}/structure`)"
/>
<q-btn
color="primary"
label="บันทึก"
icon="save"
:loading="saving"
@click="saveLesson"
/>
</q-card-section>
</div>
</q-card-section>
@ -182,20 +196,7 @@
<!-- Actions -->
<q-separator />
<q-card-section class="flex justify-end gap-2">
<q-btn
flat
label="ยกเลิก"
@click="navigateTo(`/instructor/courses/${courseId}/structure`)"
/>
<q-btn
color="primary"
label="บันทึก"
icon="save"
:loading="saving"
@click="saveLesson"
/>
</q-card-section>
</q-card>
</div>

View file

@ -58,7 +58,8 @@
<!-- Status Badges -->
<div class="flex gap-2">
<q-badge v-if="course.is_free" color="purple">เผยแพร่</q-badge>
<q-badge v-if="course.is_free" color="purple">ฟรี</q-badge>
<q-badge v-else color="purple">เสยเง</q-badge>
<q-badge :color="getStatusColor(course.status)">
{{ getStatusLabel(course.status) }}
</q-badge>

View file

@ -204,6 +204,7 @@
:rules="[val => !!val || 'กรุณากรอกชื่อบทเรียน']"
lazy-rules="ondemand"
hide-bottom-space
class="mb-4"
/>
<q-input
v-model="lessonForm.title.en"

View file

@ -197,6 +197,7 @@ const handleSubmit = async () => {
const response = await instructorService.createCourse(form.value);
$q.notify({
type: 'positive',
message: response.message,
@ -206,9 +207,9 @@ const handleSubmit = async () => {
// Redirect to course edit page
// Note: Assuming response.data contains the created course with ID
if (response.data && response.data.id) {
router.push(`/instructor/courses/${response.data.id}/edit`);
await navigateTo(`/instructor/courses/${response.data.id}`);
} else {
navigateTo('/instructor/courses');
await navigateTo('/instructor/courses');
}
} catch (error: any) {
$q.notify({

View file

@ -100,9 +100,9 @@
<div class="flex justify-between items-start mb-2">
<h3 class="font-semibold text-gray-900 line-clamp-2">{{ course.title.th }}</h3>
<q-badge :color="getStatusColor(course.status)" class="ml-2">
{{ getStatusLabel(course.status) }}
</q-badge>
</div>
{{ getStatusLabel(course.status) }}
</q-badge>
</div>
<p class="text-sm text-gray-500 line-clamp-2 mb-3">
{{ course.description.th }}
@ -277,18 +277,18 @@ const confirmDelete = (course: CourseResponse) => {
persistent: true
}).onOk(async () => {
try {
await instructorService.deleteCourse(course.id);
const response = await instructorService.deleteCourse(course.id);
$q.notify({
type: 'positive',
message: 'ลบหลักสูตรสำเร็จ',
message: response.message || 'ลบหลักสูตรสำเร็จ',
position: 'top'
});
// Refresh list
fetchCourses();
} catch (error) {
} catch (error: any) {
$q.notify({
type: 'negative',
message: 'ไม่สามารถลบหลักสูตรได้',
message: error.data?.message || 'ไม่สามารถลบหลักสูตรได้',
position: 'top'
});
}

View file

@ -125,7 +125,7 @@
:alt="course.title"
class="w-full h-full object-cover"
/>
<span v-else class="text-3xl">{{ course.icon }}</span>
<q-icon v-else :name="course.icon" class="text-3xl" />
</div>
<div class="flex-1">
<div class="font-semibold text-gray-900">{{ course.title }}</div>

View file

@ -350,12 +350,19 @@ const getRoleLabel = (role: string) => {
return labels[role] || role;
};
const formatDate = (date: string) => {
return new Date(date).toLocaleDateString('th-TH', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
const formatDate = (date: string, includeTime = true) => {
const options: Intl.DateTimeFormatOptions = {
day: 'numeric',
month: 'short',
year: '2-digit'
};
if (includeTime) {
options.hour = '2-digit';
options.minute = '2-digit';
}
return new Date(date).toLocaleDateString('th-TH', options);
};
// Avatar upload
@ -398,21 +405,21 @@ const handleAvatarUpload = async (event: Event) => {
uploadingAvatar.value = true;
try {
await userService.uploadAvatar(file);
const response = await userService.uploadAvatar(file);
// Re-fetch profile to get presigned URL from backend
await fetchProfile();
$q.notify({
type: 'positive',
message: 'อัพโหลดรูปโปรไฟล์สำเร็จ',
message: response.message || 'อัพโหลดรูปโปรไฟล์สำเร็จ',
position: 'top'
});
} catch (error) {
} catch (error: any) {
console.error('Failed to upload avatar:', error);
$q.notify({
type: 'negative',
message: 'เกิดข้อผิดพลาดในการอัพโหลดรูป',
message: error.data?.message || 'เกิดข้อผิดพลาดในการอัพโหลดรูป',
position: 'top'
});
} finally {
@ -426,7 +433,7 @@ const handleUpdateProfile = async () => {
try {
// Call real API to update profile
await userService.updateProfile({
const response = await userService.updateProfile({
first_name: editForm.value.firstName,
last_name: editForm.value.lastName,
phone: editForm.value.phone || null
@ -437,7 +444,7 @@ const handleUpdateProfile = async () => {
$q.notify({
type: 'positive',
message: 'อัพเดทโปรไฟล์สำเร็จ',
message: response.message || 'อัพเดทโปรไฟล์สำเร็จ',
position: 'top'
});
@ -445,7 +452,7 @@ const handleUpdateProfile = async () => {
} catch (error: any) {
$q.notify({
type: 'negative',
message: 'เกิดข้อผิดพลาด กรุณาลองใหม่อีกครั้ง',
message: error.data?.message || 'เกิดข้อผิดพลาด กรุณาลองใหม่อีกครั้ง',
position: 'top'
});
} finally {
@ -458,14 +465,14 @@ const handleChangePassword = async () => {
try {
// Call real API to change password
await userService.changePassword(
const response = await userService.changePassword(
passwordForm.value.currentPassword,
passwordForm.value.newPassword
);
$q.notify({
type: 'positive',
message: 'เปลี่ยนรหัสผ่านสำเร็จ',
message: response.message || 'เปลี่ยนรหัสผ่านสำเร็จ',
position: 'top'
});
@ -478,9 +485,9 @@ const handleChangePassword = async () => {
} catch (error: any) {
$q.notify({
type: 'negative',
message: error.response?.status === 401
message: error.data?.message || (error.response?.status === 401
? 'รหัสผ่านปัจจุบันไม่ถูกต้อง'
: 'เกิดข้อผิดพลาดในการเปลี่ยนรหัสผ่าน',
: 'เกิดข้อผิดพลาดในการเปลี่ยนรหัสผ่าน'),
position: 'top'
});
} finally {