fix: alert i18n dialog
This commit is contained in:
parent
3aa99f2ede
commit
8fdc916955
5 changed files with 17 additions and 6 deletions
|
|
@ -21,10 +21,10 @@ const api = axios.create({ baseURL: import.meta.env.VITE_API_BASE_URL });
|
||||||
|
|
||||||
function parseError(
|
function parseError(
|
||||||
status: number,
|
status: number,
|
||||||
body?: { status: number; message: string },
|
body?: { status: number; message: string; code: string },
|
||||||
) {
|
) {
|
||||||
if (status === 422) return 'ข้อมูลไม่ถูกต้อง กรุณาตรวจสอบใหม่อีกครั้ง';
|
if (status === 422) return 'ข้อมูลไม่ถูกต้อง กรุณาตรวจสอบใหม่อีกครั้ง';
|
||||||
if (body && body.message) return body.message;
|
if (body && body.code) return body.code;
|
||||||
|
|
||||||
return 'เกิดข้อผิดพลาดทำให้ระบบไม่สามารถทำงานได้ กรุณาลองใหม่ในภายหลัง';
|
return 'เกิดข้อผิดพลาดทำให้ระบบไม่สามารถทำงานได้ กรุณาลองใหม่ในภายหลัง';
|
||||||
}
|
}
|
||||||
|
|
@ -43,11 +43,17 @@ api.interceptors.response.use(
|
||||||
(err) => {
|
(err) => {
|
||||||
useLoader().hide();
|
useLoader().hide();
|
||||||
dialog({
|
dialog({
|
||||||
color: 'negative',
|
color:
|
||||||
|
err.response.status >= 400 && err.response.status < 500
|
||||||
|
? 'warning'
|
||||||
|
: 'negative',
|
||||||
icon: 'mdi-alert',
|
icon: 'mdi-alert',
|
||||||
title: 'เกิดข้อผิดพลาด',
|
title:
|
||||||
actionText: 'ตกลง',
|
err.response.status >= 400 && err.response.status < 500
|
||||||
|
? 'warning'
|
||||||
|
: 'errorOccurred',
|
||||||
persistent: true,
|
persistent: true,
|
||||||
|
enablei18n: true,
|
||||||
message: parseError(err.response.status, err.response.data),
|
message: parseError(err.response.status, err.response.data),
|
||||||
action: () => {},
|
action: () => {},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ defineProps<{
|
||||||
:class="{ 'full-width': !cancel }"
|
:class="{ 'full-width': !cancel }"
|
||||||
v-if="action"
|
v-if="action"
|
||||||
@click="action"
|
@click="action"
|
||||||
:label="actionText || $t('defaultDialog')"
|
:label="actionText || $t('agree')"
|
||||||
:color="color || 'primary'"
|
:color="color || 'primary'"
|
||||||
v-close-popup
|
v-close-popup
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ export default {
|
||||||
warning: 'Warning',
|
warning: 'Warning',
|
||||||
warningForgetInput: 'You have incomplete information.',
|
warningForgetInput: 'You have incomplete information.',
|
||||||
|
|
||||||
|
errorOccurred: 'An error occurred.',
|
||||||
|
|
||||||
// Backend
|
// Backend
|
||||||
productGroupNotFound: 'Product group cannot be found.',
|
productGroupNotFound: 'Product group cannot be found.',
|
||||||
productGroupInUsed: 'Product group is in used.',
|
productGroupInUsed: 'Product group is in used.',
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ export default {
|
||||||
warning: 'เตือน',
|
warning: 'เตือน',
|
||||||
warningForgetInput: 'คุณกรอกข้อมูลไม่ครบ',
|
warningForgetInput: 'คุณกรอกข้อมูลไม่ครบ',
|
||||||
|
|
||||||
|
errorOccurred: 'เกิดข้อผิดพลาด.',
|
||||||
|
|
||||||
// Backend
|
// Backend
|
||||||
productGroupNotFound: 'ไม่พบกลุ่มสินค้า',
|
productGroupNotFound: 'ไม่พบกลุ่มสินค้า',
|
||||||
productGroupInUsed: 'กลุ่มสินค้าที่ใช้งานอยู่',
|
productGroupInUsed: 'กลุ่มสินค้าที่ใช้งานอยู่',
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ export function dialog(opts: {
|
||||||
persistent?: boolean;
|
persistent?: boolean;
|
||||||
actionText?: string;
|
actionText?: string;
|
||||||
cancelText?: string;
|
cancelText?: string;
|
||||||
|
enablei18n?: boolean;
|
||||||
action?: (...args: unknown[]) => unknown;
|
action?: (...args: unknown[]) => unknown;
|
||||||
cancel?: (...args: unknown[]) => unknown;
|
cancel?: (...args: unknown[]) => unknown;
|
||||||
}) {
|
}) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue