fix: alert i18n dialog

This commit is contained in:
puriphatt 2024-06-17 04:00:22 +00:00
parent 3aa99f2ede
commit 8fdc916955
5 changed files with 17 additions and 6 deletions

View file

@ -21,10 +21,10 @@ const api = axios.create({ baseURL: import.meta.env.VITE_API_BASE_URL });
function parseError(
status: number,
body?: { status: number; message: string },
body?: { status: number; message: string; code: string },
) {
if (status === 422) return 'ข้อมูลไม่ถูกต้อง กรุณาตรวจสอบใหม่อีกครั้ง';
if (body && body.message) return body.message;
if (body && body.code) return body.code;
return 'เกิดข้อผิดพลาดทำให้ระบบไม่สามารถทำงานได้ กรุณาลองใหม่ในภายหลัง';
}
@ -43,11 +43,17 @@ api.interceptors.response.use(
(err) => {
useLoader().hide();
dialog({
color: 'negative',
color:
err.response.status >= 400 && err.response.status < 500
? 'warning'
: 'negative',
icon: 'mdi-alert',
title: 'เกิดข้อผิดพลาด',
actionText: 'ตกลง',
title:
err.response.status >= 400 && err.response.status < 500
? 'warning'
: 'errorOccurred',
persistent: true,
enablei18n: true,
message: parseError(err.response.status, err.response.data),
action: () => {},
});

View file

@ -81,7 +81,7 @@ defineProps<{
:class="{ 'full-width': !cancel }"
v-if="action"
@click="action"
:label="actionText || $t('defaultDialog')"
:label="actionText || $t('agree')"
:color="color || 'primary'"
v-close-popup
/>

View file

@ -2,6 +2,8 @@ export default {
warning: 'Warning',
warningForgetInput: 'You have incomplete information.',
errorOccurred: 'An error occurred.',
// Backend
productGroupNotFound: 'Product group cannot be found.',
productGroupInUsed: 'Product group is in used.',

View file

@ -2,6 +2,8 @@ export default {
warning: 'เตือน',
warningForgetInput: 'คุณกรอกข้อมูลไม่ครบ',
errorOccurred: 'เกิดข้อผิดพลาด.',
// Backend
productGroupNotFound: 'ไม่พบกลุ่มสินค้า',
productGroupInUsed: 'กลุ่มสินค้าที่ใช้งานอยู่',

View file

@ -10,6 +10,7 @@ export function dialog(opts: {
persistent?: boolean;
actionText?: string;
cancelText?: string;
enablei18n?: boolean;
action?: (...args: unknown[]) => unknown;
cancel?: (...args: unknown[]) => unknown;
}) {