refactor: handle name trim

This commit is contained in:
Thanaphon Frappet 2024-11-29 13:33:07 +07:00
parent 5c39f9756a
commit 9fa735c529
5 changed files with 114 additions and 25 deletions

View file

@ -107,7 +107,13 @@ const employeeOther = defineModel<EmployeeOtherCreate>('employeeOther');
hide-bottom-space hide-bottom-space
class="col-md-3 col-6" class="col-md-3 col-6"
:label="$t('form.firstName')" :label="$t('form.firstName')"
v-model="employeeOther.fatherFirstName" :model-value="employeeOther.fatherFirstName"
@update:model-value="
(v) =>
typeof v === 'string' && employeeOther
? (employeeOther.fatherFirstName = v.trim())
: ''
"
/> />
<q-input <q-input
:for="`${prefixId}-input-father-last-name`" :for="`${prefixId}-input-father-last-name`"
@ -117,7 +123,13 @@ const employeeOther = defineModel<EmployeeOtherCreate>('employeeOther');
hide-bottom-space hide-bottom-space
class="col-md-3 col-6" class="col-md-3 col-6"
:label="$t('form.lastName')" :label="$t('form.lastName')"
v-model="employeeOther.fatherLastName" :model-value="employeeOther.fatherLastName"
@update:model-value="
(v) =>
typeof v === 'string' && employeeOther
? (employeeOther.fatherLastName = v.trim())
: ''
"
/> />
<q-input <q-input
:for="`${prefixId}-input-father-first-name-en`" :for="`${prefixId}-input-father-first-name-en`"
@ -127,7 +139,13 @@ const employeeOther = defineModel<EmployeeOtherCreate>('employeeOther');
hide-bottom-space hide-bottom-space
class="col-md-3 col-6" class="col-md-3 col-6"
:label="$t('form.firstNameEN')" :label="$t('form.firstNameEN')"
v-model="employeeOther.fatherFirstNameEN" :model-value="employeeOther.fatherFirstNameEN"
@update:model-value="
(v) =>
typeof v === 'string' && employeeOther
? (employeeOther.fatherFirstNameEN = v.trim())
: ''
"
/> />
<q-input <q-input
:for="`${prefixId}-input-father-last-name-en`" :for="`${prefixId}-input-father-last-name-en`"
@ -137,7 +155,13 @@ const employeeOther = defineModel<EmployeeOtherCreate>('employeeOther');
hide-bottom-space hide-bottom-space
class="col-md-3 col-6" class="col-md-3 col-6"
:label="$t('form.lastNameEN')" :label="$t('form.lastNameEN')"
v-model="employeeOther.fatherLastNameEN" :model-value="employeeOther.fatherLastNameEN"
@update:model-value="
(v) =>
typeof v === 'string' && employeeOther
? (employeeOther.fatherLastNameEN = v.trim())
: ''
"
/> />
</div> </div>
@ -154,7 +178,13 @@ const employeeOther = defineModel<EmployeeOtherCreate>('employeeOther');
hide-bottom-space hide-bottom-space
class="col-md-3 col-6" class="col-md-3 col-6"
:label="$t('form.firstName')" :label="$t('form.firstName')"
v-model="employeeOther.motherFirstName" :model-value="employeeOther.motherFirstName"
@update:model-value="
(v) =>
typeof v === 'string' && employeeOther
? (employeeOther.motherFirstName = v.trim())
: ''
"
/> />
<q-input <q-input
:for="`${prefixId}-input-mother-last-name`" :for="`${prefixId}-input-mother-last-name`"
@ -164,7 +194,13 @@ const employeeOther = defineModel<EmployeeOtherCreate>('employeeOther');
hide-bottom-space hide-bottom-space
class="col-md-3 col-6" class="col-md-3 col-6"
:label="$t('form.lastName')" :label="$t('form.lastName')"
v-model="employeeOther.motherLastName" :model-value="employeeOther.motherLastName"
@update:model-value="
(v) =>
typeof v === 'string' && employeeOther
? (employeeOther.motherLastName = v.trim())
: ''
"
/> />
<q-input <q-input
:for="`${prefixId}-input-mother-first-name-en`" :for="`${prefixId}-input-mother-first-name-en`"
@ -174,7 +210,13 @@ const employeeOther = defineModel<EmployeeOtherCreate>('employeeOther');
hide-bottom-space hide-bottom-space
class="col-md-3 col-6" class="col-md-3 col-6"
:label="$t('form.firstNameEN')" :label="$t('form.firstNameEN')"
v-model="employeeOther.motherFirstNameEN" :model-value="employeeOther.motherFirstNameEN"
@update:model-value="
(v) =>
typeof v === 'string' && employeeOther
? (employeeOther.motherFirstNameEN = v.trim())
: ''
"
/> />
<q-input <q-input
:for="`${prefixId}-input-mother-last-name-en`" :for="`${prefixId}-input-mother-last-name-en`"
@ -184,7 +226,13 @@ const employeeOther = defineModel<EmployeeOtherCreate>('employeeOther');
hide-bottom-space hide-bottom-space
class="col-md-3 col-6" class="col-md-3 col-6"
:label="$t('form.lastNameEN')" :label="$t('form.lastNameEN')"
v-model="employeeOther.motherLastNameEN" :model-value="employeeOther.motherLastNameEN"
@update:model-value="
(v) =>
typeof v === 'string' && employeeOther
? (employeeOther.motherLastNameEN = v.trim())
: ''
"
/> />
</div> </div>
</div> </div>

View file

@ -328,7 +328,7 @@ watch(
:label="$t('form.firstName')" :label="$t('form.firstName')"
:model-value="readonly ? firstName || '-' : firstName" :model-value="readonly ? firstName || '-' : firstName"
@update:model-value=" @update:model-value="
(v) => (typeof v === 'string' ? (firstName = v) : '') (v) => (typeof v === 'string' ? (firstName = v.trim()) : '')
" "
/> />
@ -342,7 +342,7 @@ watch(
:label="$t('form.middleName')" :label="$t('form.middleName')"
:model-value="readonly ? middleName || '-' : middleName" :model-value="readonly ? middleName || '-' : middleName"
@update:model-value=" @update:model-value="
(v) => (typeof v === 'string' ? (middleName = v) : '') (v) => (typeof v === 'string' ? (middleName = v.trim()) : '')
" "
/> />
@ -356,7 +356,7 @@ watch(
:label="$t('form.lastName')" :label="$t('form.lastName')"
:model-value="readonly ? lastName || '-' : lastName" :model-value="readonly ? lastName || '-' : lastName"
@update:model-value=" @update:model-value="
(v) => (typeof v === 'string' ? (lastName = v) : '') (v) => (typeof v === 'string' ? (lastName = v.trim()) : '')
" "
/> />
@ -382,7 +382,7 @@ watch(
:label="$t('form.firstNameEN')" :label="$t('form.firstNameEN')"
:model-value="readonly ? firstNameEN || '-' : firstNameEN" :model-value="readonly ? firstNameEN || '-' : firstNameEN"
@update:model-value=" @update:model-value="
(v) => (typeof v === 'string' ? (firstNameEN = v) : '') (v) => (typeof v === 'string' ? (firstNameEN = v.trim()) : '')
" "
/> />
@ -396,7 +396,7 @@ watch(
:label="$t('form.middleNameEN')" :label="$t('form.middleNameEN')"
:model-value="readonly ? middleNameEN || '-' : middleNameEN" :model-value="readonly ? middleNameEN || '-' : middleNameEN"
@update:model-value=" @update:model-value="
(v) => (typeof v === 'string' ? (middleNameEN = v) : '') (v) => (typeof v === 'string' ? (middleNameEN = v.trim()) : '')
" "
/> />
@ -410,7 +410,7 @@ watch(
:label="$t('form.lastNameEN')" :label="$t('form.lastNameEN')"
:model-value="readonly ? lastNameEN || '-' : lastNameEN" :model-value="readonly ? lastNameEN || '-' : lastNameEN"
@update:model-value=" @update:model-value="
(v) => (typeof v === 'string' ? (lastNameEN = v) : '') (v) => (typeof v === 'string' ? (lastNameEN = v.trim()) : '')
" "
/> />

View file

@ -132,7 +132,10 @@ const workplaceFilter = selectFilterOptionRefMod(
hide-bottom-space hide-bottom-space
class="col-6" class="col-6"
:label="$t('customerEmployee.formWorkHistory.employerName')" :label="$t('customerEmployee.formWorkHistory.employerName')"
v-model="work.ownerName" :model-value="work.ownerName"
@update:model-value="
(v) => (typeof v === 'string' ? (work.ownerName = v.trim()) : '')
"
/> />
<q-select <q-select

View file

@ -129,7 +129,10 @@ watch(
class="col-12 col-md-6" class="col-12 col-md-6"
:label="$t('customer.form.registerName')" :label="$t('customer.form.registerName')"
for="input-register-name" for="input-register-name"
v-model="registerName" :model-value="registerName"
@update:model-value="
(v) => (typeof v === 'string' ? (registerName = v.trim()) : '')
"
:rules="[(val: string) => !!val || $t('form.error.required')]" :rules="[(val: string) => !!val || $t('form.error.required')]"
/> />
@ -141,7 +144,10 @@ watch(
class="col-12 col-md-6" class="col-12 col-md-6"
label="Company name" label="Company name"
for="input-register-name-en" for="input-register-name-en"
v-model="registerNameEN" :model-value="registerNameEN"
@update:model-value="
(v) => (typeof v === 'string' ? (registerNameEN = v.trim()) : '')
"
:rules="[ :rules="[
(val: string) => (val: string) =>
val === '' || val === '' ||
@ -160,7 +166,10 @@ watch(
class="col-6 col-md-5" class="col-6 col-md-5"
:label="$t('customer.form.employerName')" :label="$t('customer.form.employerName')"
for="input-legal-person-no" for="input-legal-person-no"
v-model="customerName" :model-value="customerName"
@update:model-value="
(v) => (typeof v === 'string' ? (customerName = v.trim()) : '')
"
/> />
<q-input <q-input
@ -329,7 +338,6 @@ watch(
</q-item> </q-item>
</template> </template>
</q-select> </q-select>
<q-input <q-input
:for="`${prefixId}-input-first-name`" :for="`${prefixId}-input-first-name`"
dense dense
@ -338,7 +346,10 @@ watch(
hide-bottom-space hide-bottom-space
class="col" class="col"
:label="$t('personnel.form.firstName')" :label="$t('personnel.form.firstName')"
v-model="firstName" :model-value="firstName"
@update:model-value="
(v) => (typeof v === 'string' ? (firstName = v.trim()) : '')
"
:rules="[(val: string) => !!val || $t('form.error.required')]" :rules="[(val: string) => !!val || $t('form.error.required')]"
/> />
<q-input <q-input
@ -349,7 +360,10 @@ watch(
hide-bottom-space hide-bottom-space
class="col" class="col"
:label="$t('personnel.form.lastName')" :label="$t('personnel.form.lastName')"
v-model="lastName" :model-value="lastName"
@update:model-value="
(v) => (typeof v === 'string' ? (lastName = v.trim()) : '')
"
:rules="[(val: string) => !!val || $t('form.error.required')]" :rules="[(val: string) => !!val || $t('form.error.required')]"
/> />
</div> </div>
@ -383,7 +397,10 @@ watch(
hide-bottom-space hide-bottom-space
class="col" class="col"
label="Name" label="Name"
v-model="firstNameEN" :model-value="firstNameEN"
@update:model-value="
(v) => (typeof v === 'string' ? (firstNameEN = v.trim()) : '')
"
:rules="[ :rules="[
(val: string) => !!val || $t('form.error.required'), (val: string) => !!val || $t('form.error.required'),
(val: string) => (val: string) =>
@ -398,7 +415,10 @@ watch(
hide-bottom-space hide-bottom-space
class="col" class="col"
label="Surname" label="Surname"
v-model="lastNameEN" :model-value="lastNameEN"
@update:model-value="
(v) => (typeof v === 'string' ? (lastNameEN = v.trim()) : '')
"
:rules="[ :rules="[
(val: string) => !!val || $t('form.error.required'), (val: string) => !!val || $t('form.error.required'),
(val: string) => (val: string) =>

View file

@ -1,6 +1,10 @@
import { ref, toRaw, watch } from 'vue'; import { ref, toRaw, watch } from 'vue';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { CustomerBranchCreate, CustomerCreate } from 'stores/customer/types'; import {
CustomerBranchCreate,
CustomerCreate,
CustomerType,
} from 'stores/customer/types';
import { Employee, EmployeeCreate } from 'stores/employee/types'; import { Employee, EmployeeCreate } from 'stores/employee/types';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
@ -29,7 +33,7 @@ export const useCustomerForm = defineStore('form-customer', () => {
customerBranch: [], customerBranch: [],
selectedImage: '', selectedImage: '',
status: 'CREATED', status: 'CREATED',
customerType: 'CORP', customerType: CustomerType.Corporate,
registeredBranchId: branchStore.currentMyBranch?.id || '', registeredBranchId: branchStore.currentMyBranch?.id || '',
image: null, image: null,
}; };
@ -1092,6 +1096,20 @@ export const useEmployeeForm = defineStore('form-employee', () => {
selectedImage: string; selectedImage: string;
list: { url: string; imgFile: File | null; name: string }[]; list: { url: string; imgFile: File | null; name: string }[];
}) { }) {
currentFromDataEmployee.value.firstName =
currentFromDataEmployee.value.firstName.trim();
currentFromDataEmployee.value.middleName =
currentFromDataEmployee.value.middleName?.trim();
currentFromDataEmployee.value.lastName =
currentFromDataEmployee.value.lastName.trim();
currentFromDataEmployee.value.firstNameEN =
currentFromDataEmployee.value.firstNameEN.trim();
currentFromDataEmployee.value.middleNameEN =
currentFromDataEmployee.value.middleNameEN?.trim();
currentFromDataEmployee.value.lastNameEN =
currentFromDataEmployee.value.lastNameEN.trim();
if (state.value.dialogType === 'create') { if (state.value.dialogType === 'create') {
const res = await employeeStore.create( const res = await employeeStore.create(
{ {