Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class="flex w-fit cursor-pointer items-center gap-2 text-brandColor"
@lang("admin::app.common.custom-attributes.add-more")
</span>
</script>

<script src="https://unpkg.com/libphonenumber-js/bundle/libphonenumber-max.js"></script>
<script type="module">
app.component('v-phone-component', {
template: '#v-phone-component-template',
Expand All @@ -98,7 +98,12 @@ class="flex w-fit cursor-pointer items-center gap-2 text-brandColor"
watch: {
value(newValue, oldValue) {
if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
this.contactNumbers = newValue || [{'value': '', 'label': 'work'}];
this.contactNumbers = (newValue || [{'value': '', 'label': 'work'}])
.map(contactNumber => ({
...contactNumber,
value: this.cleanPhone(contactNumber.value),
label: (contactNumber.label || 'work').toLowerCase()
}));
}
},
},
Expand All @@ -122,6 +127,7 @@ class="flex w-fit cursor-pointer items-center gap-2 text-brandColor"
'label': 'work'
}];
}

},

methods: {
Expand All @@ -135,6 +141,14 @@ class="flex w-fit cursor-pointer items-center gap-2 text-brandColor"
remove(contactNumber) {
this.contactNumbers = this.contactNumbers.filter(number => number !== contactNumber);
},
cleanPhone(value) {
if (!value) return value;
const phone = libphonenumber.parsePhoneNumberFromString(value);
if (phone) {
return phone.nationalNumber;
}
return value.replace(/\D/g, '');
},

extendValidations() {
defineRule('unique_contact_number', async (value, contactNumbers) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test("should be able to assign a company to person", async ({ adminPage }) => {
*/
await adminPage.goto("admin/contacts/persons");
await createPerson(adminPage);
await expect(adminPage.locator("span.icon-edit")).toBeVisible();
await adminPage.locator("span.icon-edit").first().click();
await adminPage
.locator("div")
Expand Down
Loading