refactor: add hideDelete prop to various components and update delete button visibility logic
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 6s

This commit is contained in:
puriphatt 2025-07-07 10:40:35 +07:00
parent f646b3c9ba
commit a5791a1b54
7 changed files with 40 additions and 57 deletions

View file

@ -89,15 +89,7 @@ defineProps<{
</div> </div>
</div> </div>
</div> </div>
<div <q-separator />
style="
display: block;
width: 100%;
height: 1px;
background: hsla(0 0% 0% / 0.1);
margin-bottom: var(--size-2);
"
/>
<slot name="data"></slot> <slot name="data"></slot>
<template v-if="!$slots.data"> <template v-if="!$slots.data">
<div <div

View file

@ -23,6 +23,7 @@ const prop = withDefaults(
addButton?: boolean; addButton?: boolean;
prefixId?: string; prefixId?: string;
hideAction?: boolean; hideAction?: boolean;
hideDelete?: boolean;
}>(), }>(),
{ {
gridView: false, gridView: false,
@ -269,6 +270,7 @@ defineEmits<{
v-if="!inTable && !hideAction" v-if="!inTable && !hideAction"
:id-name="props.row.firstName" :id-name="props.row.firstName"
:status="props.row.status" :status="props.row.status"
:hide-delete="hideDelete"
@view="$emit('view', props.row)" @view="$emit('view', props.row)"
@edit="$emit('edit', props.row)" @edit="$emit('edit', props.row)"
@delete="$emit('delete', props.row)" @delete="$emit('delete', props.row)"
@ -282,6 +284,7 @@ defineEmits<{
<div class="col-12 col-md-3 col-sm-6"> <div class="col-12 col-md-3 col-sm-6">
<PersonCard <PersonCard
history history
:hide-delete="hideDelete"
:hide-action="hideAction" :hide-action="hideAction"
:id="`card-${props.row.firstNameEN}`" :id="`card-${props.row.firstNameEN}`"
:field-selected="fieldSelected" :field-selected="fieldSelected"

View file

@ -24,6 +24,7 @@ defineProps<{
prefixId?: string; prefixId?: string;
separateEnter?: boolean; separateEnter?: boolean;
hideAction?: boolean; hideAction?: boolean;
hideDelete?: boolean;
}>(); }>();
defineEmits<{ defineEmits<{
@ -80,6 +81,7 @@ defineEmits<{
v-if="!hideAction" v-if="!hideAction"
:id-name="prefixId" :id-name="prefixId"
:status="disabled ? 'INACTIVE' : 'ACTIVE'" :status="disabled ? 'INACTIVE' : 'ACTIVE'"
:hide-delete="hideDelete"
@view=" @view="
separateEnter separateEnter
? $emit('viewCard', 'INFO') ? $emit('viewCard', 'INFO')

View file

@ -751,7 +751,7 @@ watch(
}) })
" "
> >
<template #before v-if="canAccess('customer', 'edit')"> <template #before>
<EditButton <EditButton
icon-only icon-only
v-if="customerBranchFormState.dialogType === 'info'" v-if="customerBranchFormState.dialogType === 'info'"
@ -759,7 +759,10 @@ watch(
/> />
<DeleteButton <DeleteButton
icon-only icon-only
v-if="customerBranchFormState.dialogType === 'info'" v-if="
customerBranchFormState.dialogType === 'info' &&
canAccess('customer', 'edit')
"
@click=" @click="
() => { () => {
deleteBranchById(customerBranchFormData.id || ''); deleteBranchById(customerBranchFormData.id || '');

View file

@ -1391,7 +1391,7 @@ const emptyCreateDialog = ref(false);
/> />
<KebabAction <KebabAction
v-if="canAccess('customer', 'edit')" :hide-delete="!canAccess('customer', 'edit')"
:id-name=" :id-name="
props.row.branch[0].customerName || props.row.branch[0].customerName ||
props.row.branch[0].firstName props.row.branch[0].firstName
@ -1649,7 +1649,7 @@ const emptyCreateDialog = ref(false);
@click.stop="editCustomerForm(props.row.id)" @click.stop="editCustomerForm(props.row.id)"
/> />
<KebabAction <KebabAction
v-if="canAccess('customer', 'edit')" :hide-delete="!canAccess('customer', 'edit')"
:status="props.row.status" :status="props.row.status"
:id-name="props.row.name" :id-name="props.row.name"
@view=" @view="
@ -1783,7 +1783,7 @@ const emptyCreateDialog = ref(false);
" "
> >
<TableEmpoloyee <TableEmpoloyee
:hide-action="!canAccess('customer', 'edit')" :hide-delete="!canAccess('customer', 'edit')"
v-model:page-size="pageSize" v-model:page-size="pageSize"
v-model:current-page="currentPageEmployee" v-model:current-page="currentPageEmployee"
:grid-view="gridView" :grid-view="gridView"
@ -3880,7 +3880,6 @@ const emptyCreateDialog = ref(false);
:on-create="customerFormState.dialogModal" :on-create="customerFormState.dialogModal"
:default-url="customerFormState.defaultCustomerImageUrl" :default-url="customerFormState.defaultCustomerImageUrl"
:hidden-footer="!customerFormState.isImageEdit" :hidden-footer="!customerFormState.isImageEdit"
:change-disabled="!canAccess('customer', 'edit')"
@add-image=" @add-image="
async (v) => { async (v) => {
if (!v) return; if (!v) return;
@ -3990,7 +3989,6 @@ const emptyCreateDialog = ref(false);
v-model:on-create-data-list="onCreateImageList" v-model:on-create-data-list="onCreateImageList"
:on-create="employeeFormState.dialogModal" :on-create="employeeFormState.dialogModal"
:hidden-footer="!employeeFormState.isImageEdit" :hidden-footer="!employeeFormState.isImageEdit"
:change-disabled="!canAccess('customer', 'edit')"
@add-image=" @add-image="
async (v) => { async (v) => {
if (!v) return; if (!v) return;
@ -4132,7 +4130,6 @@ const emptyCreateDialog = ref(false);
> >
<ProfileBanner <ProfileBanner
v-if="customerFormData.customerBranch !== undefined" v-if="customerFormData.customerBranch !== undefined"
:readonly="!canAccess('customer', 'edit')"
:prefix="customerFormData.registeredBranchId" :prefix="customerFormData.registeredBranchId"
:active="customerFormData.status !== 'INACTIVE'" :active="customerFormData.status !== 'INACTIVE'"
hide-fade hide-fade
@ -4246,8 +4243,7 @@ const emptyCreateDialog = ref(false);
v-if=" v-if="
customerFormState.branchIndex === -1 && customerFormState.branchIndex === -1 &&
!!customerFormState.editCustomerId && !!customerFormState.editCustomerId &&
customerFormState.dialogType !== 'create' && customerFormState.dialogType !== 'create'
canAccess('customer', 'edit')
" "
:disabled="!customerFormState.readonly" :disabled="!customerFormState.readonly"
/> />
@ -4431,10 +4427,7 @@ const emptyCreateDialog = ref(false);
prefix-id="info" prefix-id="info"
v-if="!!customerFormState.editCustomerId" v-if="!!customerFormState.editCustomerId"
:index="idx" :index="idx"
:hide-action=" :hide-action="customerFormData.status === 'INACTIVE'"
customerFormData.status === 'INACTIVE' ||
!canAccess('customer', 'edit')
"
v-model:customer="customerFormData" v-model:customer="customerFormData"
v-model:customer-branch=" v-model:customer-branch="
customerFormData.customerBranch[idx] customerFormData.customerBranch[idx]
@ -4445,6 +4438,7 @@ const emptyCreateDialog = ref(false);
(customerFormState.branchIndex !== -1 && (customerFormState.branchIndex !== -1 &&
customerFormState.branchIndex !== idx) customerFormState.branchIndex !== idx)
" "
:hide-delete="!canAccess('customer', 'edit')"
:readonly="customerFormState.branchIndex !== idx" :readonly="customerFormState.branchIndex !== idx"
@edit="() => (customerFormState.branchIndex = idx)" @edit="() => (customerFormState.branchIndex = idx)"
@cancel="() => customerFormUndo(false)" @cancel="() => customerFormUndo(false)"
@ -4569,7 +4563,6 @@ const emptyCreateDialog = ref(false);
> >
<ProfileBanner <ProfileBanner
:prefix="employeeFormState.currentEmployee.firstName" :prefix="employeeFormState.currentEmployee.firstName"
:readonly="!canAccess('customer', 'edit')"
hideFade hideFade
@update:current-tab=" @update:current-tab="
() => { () => {
@ -4807,10 +4800,7 @@ const emptyCreateDialog = ref(false);
}" }"
scroll-element="#drawer-employee-form-content" scroll-element="#drawer-employee-form-content"
> >
<template <template v-slot:btn-drawer-passport>
v-if="canAccess('customer', 'edit')"
v-slot:btn-drawer-passport
>
<q-btn <q-btn
id="form-add-passport" id="form-add-passport"
dense dense
@ -4824,10 +4814,7 @@ const emptyCreateDialog = ref(false);
/> />
</template> </template>
<template <template v-slot:btn-drawer-visa>
v-if="canAccess('customer', 'edit')"
v-slot:btn-drawer-visa
>
<q-btn <q-btn
id="form-add-visa" id="form-add-visa"
dense dense
@ -4840,10 +4827,7 @@ const emptyCreateDialog = ref(false);
/> />
</template> </template>
<template <template v-slot:btn-drawer-employee-checkup>
v-if="canAccess('customer', 'edit')"
v-slot:btn-drawer-employee-checkup
>
<q-btn <q-btn
id="form-add-checkup" id="form-add-checkup"
dense dense
@ -4856,10 +4840,7 @@ const emptyCreateDialog = ref(false);
/> />
</template> </template>
<template <template v-slot:btn-drawer-employee-work-history>
v-if="canAccess('customer', 'edit')"
v-slot:btn-drawer-employee-work-history
>
<q-btn <q-btn
id="form-add-work-history" id="form-add-work-history"
dense dense
@ -4887,10 +4868,7 @@ const emptyCreateDialog = ref(false);
<div <div
class="rounded row q-py-sm q-mx-lg q-px-md" class="rounded row q-py-sm q-mx-lg q-px-md"
style="position: absolute; z-index: 999; right: 0; top: 0" style="position: absolute; z-index: 999; right: 0; top: 0"
v-if=" v-if="currentFromDataEmployee.status !== 'INACTIVE'"
currentFromDataEmployee.status !== 'INACTIVE' &&
canAccess('customer', 'edit')
"
> >
<div class="surface-1 row rounded"> <div class="surface-1 row rounded">
<UndoButton <UndoButton
@ -4925,7 +4903,10 @@ const emptyCreateDialog = ref(false);
type="button" type="button"
/> />
<DeleteButton <DeleteButton
v-if="!employeeFormState.isEmployeeEdit" v-if="
!employeeFormState.isEmployeeEdit &&
canAccess('customer', 'edit')
"
id="btn-info-basic-delete" id="btn-info-basic-delete"
icon-only icon-only
@click=" @click="
@ -5408,7 +5389,7 @@ const emptyCreateDialog = ref(false);
/> />
{{ $t('customerEmployee.form.group.passport') }} {{ $t('customerEmployee.form.group.passport') }}
<AddButton <AddButton
v-if="$q.screen.lt.md && canAccess('customer', 'edit')" v-if="$q.screen.lt.md"
id="btn-add-work" id="btn-add-work"
icon-only icon-only
class="q-ml-sm" class="q-ml-sm"
@ -5492,7 +5473,6 @@ const emptyCreateDialog = ref(false);
<template v-slot:button> <template v-slot:button>
<div <div
v-if="canAccess('customer', 'edit')"
class="surface-1 row rounded" class="surface-1 row rounded"
style="min-height: 35px" style="min-height: 35px"
> >
@ -5626,7 +5606,7 @@ const emptyCreateDialog = ref(false);
/> />
{{ $t('customerEmployee.form.group.visa') }} {{ $t('customerEmployee.form.group.visa') }}
<AddButton <AddButton
v-if="$q.screen.lt.md && canAccess('customer', 'edit')" v-if="$q.screen.lt.md"
id="btn-add-work" id="btn-add-work"
icon-only icon-only
class="q-ml-sm" class="q-ml-sm"
@ -5691,7 +5671,6 @@ const emptyCreateDialog = ref(false);
<template v-slot:button> <template v-slot:button>
<div <div
v-if="canAccess('customer', 'edit')"
class="surface-1 row rounded" class="surface-1 row rounded"
style="min-height: 35px" style="min-height: 35px"
> >
@ -5809,7 +5788,7 @@ const emptyCreateDialog = ref(false);
{{ $t(`customerEmployee.formHealthCheck.title`) }} {{ $t(`customerEmployee.formHealthCheck.title`) }}
<AddButton <AddButton
v-if="$q.screen.lt.md && canAccess('customer', 'edit')" v-if="$q.screen.lt.md"
id="btn-add-work" id="btn-add-work"
icon-only icon-only
class="q-ml-sm" class="q-ml-sm"
@ -5937,7 +5916,7 @@ const emptyCreateDialog = ref(false);
/> />
{{ $t(`customerEmployee.form.group.workHistory`) }} {{ $t(`customerEmployee.form.group.workHistory`) }}
<AddButton <AddButton
v-if="$q.screen.lt.md && canAccess('customer', 'edit')" v-if="$q.screen.lt.md"
id="btn-add-work" id="btn-add-work"
icon-only icon-only
class="q-ml-sm" class="q-ml-sm"
@ -6042,10 +6021,7 @@ const emptyCreateDialog = ref(false);
</template> </template>
<template v-if="employeeFormState.currentTab === 'other'"> <template v-if="employeeFormState.currentTab === 'other'">
<FormEmployeeOther <FormEmployeeOther
:hide-action=" :hide-action="currentFromDataEmployee.status === 'INACTIVE'"
currentFromDataEmployee.status === 'INACTIVE' ||
!canAccess('customer', 'edit')
"
v-if="employeeFormState.currentTab === 'other'" v-if="employeeFormState.currentTab === 'other'"
id="drawer-other" id="drawer-other"
prefix-id="drawer-employee" prefix-id="drawer-employee"

View file

@ -102,7 +102,13 @@ const telephoneNo = defineModel<string>('telephoneNo', { default: '' });
class="col-md-6" class="col-md-6"
:readonly :readonly
:disabled=" :disabled="
!isRoleInclude(['admin', 'system', 'head_of_admin']) && !readonly !isRoleInclude([
'admin',
'system',
'head_of_admin',
'executive',
'accountant',
]) && !readonly
" "
:label="$t('customer.form.registeredBranch')" :label="$t('customer.form.registeredBranch')"
select-first-value select-first-value

View file

@ -51,6 +51,7 @@ withDefaults(
actionDisabled?: boolean; actionDisabled?: boolean;
customerType?: 'CORP' | 'PERS'; customerType?: 'CORP' | 'PERS';
hideAction?: boolean; hideAction?: boolean;
hideDelete?: boolean;
}>(), }>(),
{ {
hideAction: false, hideAction: false,
@ -81,7 +82,7 @@ withDefaults(
/> />
<DeleteButton <DeleteButton
icon-only icon-only
v-if="readonly" v-if="readonly && !hideDelete"
@click="$emit('delete')" @click="$emit('delete')"
type="button" type="button"
:disabled="actionDisabled" :disabled="actionDisabled"