refactor: kebab action

This commit is contained in:
puriphatt 2024-08-27 11:46:26 +07:00
parent 5ec6d1c9d5
commit bc578d569c
11 changed files with 518 additions and 1357 deletions

View file

@ -36,6 +36,7 @@ import ImageUploadDialog from 'components/ImageUploadDialog.vue';
import FormBank from 'components/01_branch-management/FormBank.vue';
import ToggleButton from 'src/components/button/ToggleButton.vue';
import FormBranchAdmin from 'src/components/01_branch-management/FormBranchAdmin.vue';
import KebabAction from 'src/components/shared/KebabAction.vue';
import { User } from 'src/stores/user/types';
import {
EditButton,
@ -479,10 +480,10 @@ function triggerDelete(id: string) {
dialog({
color: 'negative',
icon: 'mdi-alert',
title: t('deleteConfirmTitle'),
actionText: t('agree'),
title: t('dialog.title.confirmDelete'),
actionText: t('general.delete'),
persistent: true,
message: t('deleteConfirmMessage'),
message: t('dialog.message.confirmDelete'),
action: async () => {
await branchStore.deleteById(id);
await branchStore.fetchList({ pageSize: 99999 });
@ -1189,155 +1190,56 @@ watch(currentHq, () => {
}}
</q-td>
<q-td>
<q-btn
icon="mdi-dots-vertical"
:id="`btn-dots-${props.row.code}`"
size="sm"
dense
round
flat
@click.stop
>
<q-menu class="bordered">
<q-list v-close-popup>
<q-item
:id="`view-detail-btn-${props.row.name}-view`"
@click.stop="
if (props.row.isHeadOffice) {
triggerEdit(
'drawer',
props.row.id,
'headOffice',
props.row.code,
);
} else {
triggerEdit(
'drawer',
props.row.id,
'subBranch',
);
}
"
v-close-popup
clickable
dense
class="row q-py-sm"
style="white-space: nowrap"
>
<q-icon
name="mdi-eye-outline"
class="col-3"
size="xs"
style="color: hsl(var(--green-6-hsl))"
/>
<span class="col-9 q-px-md flex items-center">
{{ $t('general.viewDetail') }}
</span>
</q-item>
<KebabAction
:status="props.row.status"
:idName="props.row.code"
@view="
if (props.row.isHeadOffice) {
triggerEdit(
'drawer',
props.row.id,
'headOffice',
props.row.code,
);
} else {
triggerEdit(
'drawer',
props.row.id,
'subBranch',
);
}
"
@edit="
async () => {
if (props.row.isHeadOffice) {
await triggerEdit(
'drawer',
props.row.id,
'headOffice',
props.row.code,
);
} else {
await triggerEdit(
'drawer',
props.row.id,
'subBranch',
);
}
formType = 'edit';
}
"
@delete="triggerDelete(props.row.id)"
@changeStatus="
async () => {
const res = await triggerChangeStatus(
props.row.id,
props.row.status,
);
<q-item
:id="`view-detail-btn-${props.row.name}-edit`"
v-close-popup
clickable
dense
class="row q-py-sm"
style="white-space: nowrap"
@click="
async () => {
if (props.row.isHeadOffice) {
await triggerEdit(
'drawer',
props.row.id,
'headOffice',
props.row.code,
);
} else {
await triggerEdit(
'drawer',
props.row.id,
'subBranch',
);
}
formType = 'edit';
}
"
>
<q-icon
name="mdi-pencil-outline"
class="col-3"
size="xs"
style="color: hsl(var(--cyan-6-hsl))"
/>
<span class="col-9 q-px-md flex items-center">
{{ $t('general.edit') }}
</span>
</q-item>
<q-item
:id="`view-detail-btn-${props.row.name}-delete`"
dense
v-close-popup
:clickable="props.row.status === 'CREATED'"
class="row"
:class="{
'surface-3': props.row.status !== 'CREATED',
'app-text-muted':
props.row.status !== 'CREATED',
}"
style="white-space: nowrap"
@click="triggerDelete(props.row.id)"
>
<q-icon
name="mdi-trash-can-outline"
size="xs"
class="col-3"
:class="{
'app-text-negative':
props.row.status === 'CREATED',
}"
/>
<span class="col-9 q-px-md flex items-center">
{{ $t('general.delete') }}
</span>
</q-item>
<q-item dense>
<q-item-section class="q-py-sm">
<div
class="q-pa-sm surface-2 rounded flex items-center"
>
<ToggleButton
two-way
:id="`view-detail-btn-${props.row.name}-status`"
@click="
async () => {
const res =
await triggerChangeStatus(
props.row.id,
props.row.status,
);
if (res)
props.row.status = res.status;
}
"
:model-value="
props.row.status === 'CREATED' ||
props.row.status === 'ACTIVE'
"
/>
<span class="q-pl-md">
{{
props.row.status !== 'INACTIVE'
? $t('general.open')
: $t('general.close')
}}
</span>
</div>
</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
if (res) props.row.status = res.status;
}
"
/>
</q-td>
</q-tr>
</template>
@ -1409,145 +1311,56 @@ watch(currentHq, () => {
"
>
<template v-slot:action>
<q-menu class="bordered">
<q-list>
<q-item
:id="`view-detail-btn-${props.row.name}-view`"
@click.stop="
if (props.row.isHeadOffice) {
triggerEdit(
'drawer',
props.row.id,
'headOffice',
props.row.code,
);
} else {
triggerEdit(
'drawer',
props.row.id,
'subBranch',
);
}
"
v-close-popup
clickable
dense
class="row q-py-sm"
style="white-space: nowrap"
>
<q-icon
name="mdi-eye-outline"
class="col-3"
size="xs"
style="color: hsl(var(--green-6-hsl))"
/>
<span class="col-9 q-px-md flex items-center">
{{ $t('general.viewDetail') }}
</span>
</q-item>
<KebabAction
:status="props.row.status"
:idName="props.row.code"
@view="
if (props.row.isHeadOffice) {
triggerEdit(
'drawer',
props.row.id,
'headOffice',
props.row.code,
);
} else {
triggerEdit(
'drawer',
props.row.id,
'subBranch',
);
}
"
@edit="
async () => {
if (props.row.isHeadOffice) {
await triggerEdit(
'drawer',
props.row.id,
'headOffice',
props.row.code,
);
} else {
await triggerEdit(
'drawer',
props.row.id,
'subBranch',
);
}
formType = 'edit';
}
"
@delete="triggerDelete(props.row.id)"
@change-status="
async () => {
const res = await triggerChangeStatus(
props.row.id,
props.row.status,
);
<q-item
:id="`view-detail-btn-${props.row.name}-edit`"
v-close-popup
clickable
dense
class="row q-py-sm"
style="white-space: nowrap"
@click="
async () => {
if (props.row.isHeadOffice) {
await triggerEdit(
'drawer',
props.row.id,
'headOffice',
props.row.code,
);
} else {
await triggerEdit(
'drawer',
props.row.id,
'subBranch',
);
}
formType = 'edit';
}
"
>
<q-icon
name="mdi-pencil-outline"
class="col-3"
size="xs"
style="color: hsl(var(--cyan-6-hsl))"
/>
<span class="col-9 q-px-md flex items-center">
{{ $t('general.edit') }}
</span>
</q-item>
<q-item
:id="`view-detail-btn-${props.row.name}-delete`"
dense
v-close-popup
:clickable="props.row.status === 'CREATED'"
class="row"
:class="{
'surface-3': props.row.status !== 'CREATED',
'app-text-muted':
props.row.status !== 'CREATED',
}"
style="white-space: nowrap"
@click="triggerDelete(props.row.id)"
>
<q-icon
name="mdi-trash-can-outline"
size="xs"
class="col-3"
:class="{
'app-text-negative':
props.row.status === 'CREATED',
}"
/>
<span class="col-9 q-px-md flex items-center">
{{ $t('generaldelete') }}
</span>
</q-item>
<q-item dense>
<q-item-section class="q-py-sm">
<div
class="q-pa-sm surface-2 rounded flex items-center"
>
<ToggleButton
:id="`view-detail-btn-${props.row.name}-status`"
two-way
:model-value="
props.row.status === 'CREATED' ||
props.row.status === 'ACTIVE'
"
@click="
async () => {
const res =
await triggerChangeStatus(
props.row.id,
props.row.status,
);
if (res)
props.row.status = res.status;
}
"
/>
<span class="q-pl-md">
{{
props.row.status !== 'INACTIVE'
? $t('general.open')
: $t('general.close')
}}
</span>
</div>
</q-item-section>
</q-item>
</q-list>
</q-menu>
if (res) props.row.status = res.status;
}
"
/>
</template>
</BranchCard>
</div>
@ -1622,7 +1435,7 @@ watch(currentHq, () => {
class="col surface-1 q-ma-lg rounded bordered scroll row"
id="branch-form"
>
<div class="col">
<div class="col" v-if="$q.screen.gt.sm">
<div style="position: sticky; top: 0" class="q-pa-sm">
<SideMenu
:menu="[
@ -1661,7 +1474,7 @@ watch(currentHq, () => {
</div>
</div>
<div class="col-10 q-pa-md q-gutter-y-xl">
<div class="col-md-10 col-12 q-pa-md q-gutter-y-xl">
<FormBranchInformation
id="form-information"
v-model:abbreviation="formData.code"
@ -1842,6 +1655,7 @@ watch(currentHq, () => {
</div>
</div>
<div
v-if="$q.screen.gt.sm"
class="col full-height rounded scroll row q-py-md q-pl-md q-pr-sm"
>
<SideMenu
@ -1880,7 +1694,8 @@ watch(currentHq, () => {
/>
</div>
<div
class="col-12 col-md-10 q-py-md q-pr-md q-pl-sm full-height"
class="col-12 col-md-10 q-py-md q-pr-md full-height"
:class="$q.screen.xs ? 'q-pl-md' : 'q-pl-sm'"
id="branch-info"
style="overflow-y: auto"
>
@ -1952,6 +1767,7 @@ watch(currentHq, () => {
inputFile.click();
}
"
class="q-mb-xl"
/>
<FormBank
id="info-bank"