Compare commits
2 Commits
d9bf729a96
...
feature/sh
| Author | SHA1 | Date | |
|---|---|---|---|
| 1edbd84be6 | |||
| b6ab36437b |
@@ -74,7 +74,7 @@
|
|||||||
[backgroundImageUrl]="tenant()?.footer_bg_image ?? null"
|
[backgroundImageUrl]="tenant()?.footer_bg_image ?? null"
|
||||||
[storeName]="tenant()?.nombre ?? null"
|
[storeName]="tenant()?.nombre ?? null"
|
||||||
[address]="tenant()?.main_address?.address_text ?? null"
|
[address]="tenant()?.main_address?.address_text ?? null"
|
||||||
[phone]="tenant()?.phone ?? null"
|
[phone]="tenant()?.main_phone_number?.number ?? null"
|
||||||
(logoutClick)="onLogoutClick()"
|
(logoutClick)="onLogoutClick()"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ const tenant: Tenant = {
|
|||||||
address: 'Calle Test 123, Rosario',
|
address: 'Calle Test 123, Rosario',
|
||||||
main_address: { id: 1, label: 'Principal', address_text: 'Calle Test 123, Rosario', latitude: null, longitude: null },
|
main_address: { id: 1, label: 'Principal', address_text: 'Calle Test 123, Rosario', latitude: null, longitude: null },
|
||||||
phone: '+54 341 555 1234',
|
phone: '+54 341 555 1234',
|
||||||
|
main_phone_number: { id: 1, label: 'Principal', number: '+54 341 555 1234', tel_url: 'tel:+543415551234' },
|
||||||
primary_color: '#6376F3',
|
primary_color: '#6376F3',
|
||||||
secondary_color: '#A0A0A0',
|
secondary_color: '#A0A0A0',
|
||||||
danger_color: '#FF8888',
|
danger_color: '#FF8888',
|
||||||
@@ -579,6 +580,21 @@ describe('StoreLayoutComponent', () => {
|
|||||||
expect(footer.textContent).not.toContain(tenant.address);
|
expect(footer.textContent).not.toContain(tenant.address);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('uses only the main phone number in the footer', () => {
|
||||||
|
tenantState.set({ ...tenant, main_phone_number: {
|
||||||
|
id: 10, label: 'Principal', number: '3411234567', tel_url: 'tel:3411234567',
|
||||||
|
} });
|
||||||
|
const fixture = TestBed.createComponent(StoreLayoutComponent);
|
||||||
|
fixture.detectChanges();
|
||||||
|
const footer = fixture.nativeElement.querySelector('app-store-footer') as HTMLElement;
|
||||||
|
expect(footer.textContent).toContain('3411234567');
|
||||||
|
expect(footer.textContent).not.toContain(tenant.phone);
|
||||||
|
tenantState.set({ ...tenant, main_phone_number: null });
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(footer.textContent).not.toContain('3411234567');
|
||||||
|
expect(footer.textContent).not.toContain(tenant.phone);
|
||||||
|
});
|
||||||
|
|
||||||
it('navigates to search results when the search button is clicked', () => {
|
it('navigates to search results when the search button is clicked', () => {
|
||||||
const router = TestBed.inject(Router);
|
const router = TestBed.inject(Router);
|
||||||
vi.spyOn(router, 'navigate');
|
vi.spyOn(router, 'navigate');
|
||||||
|
|||||||
10
src/app/core/services/phone-number.interface.ts
Normal file
10
src/app/core/services/phone-number.interface.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export interface PhoneNumber {
|
||||||
|
id: number;
|
||||||
|
label: string;
|
||||||
|
number: string;
|
||||||
|
tel_url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TenantPhoneNumber extends PhoneNumber {
|
||||||
|
is_main: boolean;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ApiResponse } from './api-response.interface';
|
import { ApiResponse } from './api-response.interface';
|
||||||
import { Address, TenantAddress } from './address.interface';
|
import { Address, TenantAddress } from './address.interface';
|
||||||
|
import { PhoneNumber, TenantPhoneNumber } from './phone-number.interface';
|
||||||
|
|
||||||
export type CartEditingPolicyCode = 'disabled' | 'quantity_and_remove' | 'full';
|
export type CartEditingPolicyCode = 'disabled' | 'quantity_and_remove' | 'full';
|
||||||
|
|
||||||
@@ -126,6 +127,8 @@ export interface Tenant {
|
|||||||
addresses?: TenantAddress[];
|
addresses?: TenantAddress[];
|
||||||
main_address?: Address | null;
|
main_address?: Address | null;
|
||||||
phone?: string | null;
|
phone?: string | null;
|
||||||
|
phone_numbers?: TenantPhoneNumber[];
|
||||||
|
main_phone_number?: PhoneNumber | null;
|
||||||
favicon?: string | null;
|
favicon?: string | null;
|
||||||
primary_color: string;
|
primary_color: string;
|
||||||
secondary_color: string;
|
secondary_color: string;
|
||||||
|
|||||||
@@ -1,22 +1,34 @@
|
|||||||
<app-menu-content-section menuCode="help.contact" titleId="contact-page-title">
|
<app-menu-content-section menuCode="help.contact" titleId="contact-page-title">
|
||||||
<div class="contact-page">
|
<div class="contact-page">
|
||||||
<div class="contact-page__details">
|
<div class="contact-page__details">
|
||||||
@if (contact().whatsappUrl && contact().whatsappLabel) {
|
@for (whatsapp of contact().whatsapp; track whatsapp.code) {
|
||||||
<a
|
<a
|
||||||
class="contact-page__contact-link"
|
class="contact-page__contact-link"
|
||||||
[href]="contact().whatsappUrl"
|
[href]="whatsapp.url"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
>
|
>
|
||||||
<i class="fa-brands fa-whatsapp" aria-hidden="true"></i>
|
<i [class]="whatsapp.icon" aria-hidden="true"></i>
|
||||||
<span>{{ contact().whatsappLabel }}</span>
|
<span>{{ whatsapp.name }}</span>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (contact().phone; as phone) {
|
@for (social of contact().socialMedia; track social.code) {
|
||||||
<a class="contact-page__contact-link" [href]="phoneUrl(phone)">
|
<a
|
||||||
|
class="contact-page__contact-link"
|
||||||
|
[href]="social.url"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<i [class]="social.icon" aria-hidden="true"></i>
|
||||||
|
<span>{{ social.name }}</span>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
|
||||||
|
@for (phone of contact().phones; track phone.id) {
|
||||||
|
<a class="contact-page__contact-link" [href]="phone.tel_url">
|
||||||
<i class="fa-solid fa-phone" aria-hidden="true"></i>
|
<i class="fa-solid fa-phone" aria-hidden="true"></i>
|
||||||
<span>{{ phone }}</span>
|
<span>{{ phone.label }}: {{ phone.number }}</span>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +47,12 @@
|
|||||||
</article>
|
</article>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (!contact().whatsappUrl && !contact().phone && contact().locations.length === 0) {
|
@if (
|
||||||
|
contact().whatsapp.length === 0 &&
|
||||||
|
contact().socialMedia.length === 0 &&
|
||||||
|
contact().phones.length === 0 &&
|
||||||
|
contact().locations.length === 0
|
||||||
|
) {
|
||||||
<p class="contact-page__empty">No hay datos de contacto disponibles.</p>
|
<p class="contact-page__empty">No hay datos de contacto disponibles.</p>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -19,10 +19,55 @@ const tenant: Tenant = {
|
|||||||
header_logo: '',
|
header_logo: '',
|
||||||
footer_logo: '',
|
footer_logo: '',
|
||||||
categories: [],
|
categories: [],
|
||||||
|
social_media: [
|
||||||
|
{
|
||||||
|
code: 'whatsapp',
|
||||||
|
name: 'WhatsApp',
|
||||||
|
icon: 'fa-brands fa-whatsapp',
|
||||||
|
url: 'https://wa.me/543412602222',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
code: 'instagram',
|
||||||
|
name: 'Instagram',
|
||||||
|
icon: 'fa-brands fa-instagram',
|
||||||
|
url: 'https://www.instagram.com/comercio',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
phone_numbers: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
label: 'Principal',
|
||||||
|
number: '+54 9 (0341) 6658247',
|
||||||
|
tel_url: 'tel:+54903416658247',
|
||||||
|
is_main: true,
|
||||||
|
},
|
||||||
|
{ id: 2, label: 'Ventas', number: '3411234567', tel_url: 'tel:3411234567', is_main: false },
|
||||||
|
],
|
||||||
addresses: [
|
addresses: [
|
||||||
{ id: 1, label: 'Gigante de Arroyito', address_text: 'Av. Génova 640, Rosario', latitude: -32.913997, longitude: -60.674567, is_main: true },
|
{
|
||||||
{ id: 2, label: 'Telepagos', address_text: 'Rioja 1150, piso 12, dpto. 3, Rosario', latitude: -32.94682, longitude: -60.63932, is_main: false },
|
id: 1,
|
||||||
{ id: 3, label: 'San Martín 2450', address_text: 'San Martín 2450, Santa Fe', latitude: -31.63333, longitude: -60.7, is_main: false },
|
label: 'Gigante de Arroyito',
|
||||||
|
address_text: 'Av. Génova 640, Rosario',
|
||||||
|
latitude: -32.913997,
|
||||||
|
longitude: -60.674567,
|
||||||
|
is_main: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
label: 'Telepagos',
|
||||||
|
address_text: 'Rioja 1150, piso 12, dpto. 3, Rosario',
|
||||||
|
latitude: -32.94682,
|
||||||
|
longitude: -60.63932,
|
||||||
|
is_main: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
label: 'San Martín 2450',
|
||||||
|
address_text: 'San Martín 2450, Santa Fe',
|
||||||
|
latitude: -31.63333,
|
||||||
|
longitude: -60.7,
|
||||||
|
is_main: false,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
menues: [
|
menues: [
|
||||||
{
|
{
|
||||||
@@ -38,42 +83,8 @@ const tenant: Tenant = {
|
|||||||
code: 'help.contact',
|
code: 'help.contact',
|
||||||
label: 'Contacto',
|
label: 'Contacto',
|
||||||
parent_menu_code: 'help',
|
parent_menu_code: 'help',
|
||||||
content_type: 'static',
|
content_type: 'dynamic',
|
||||||
route: '/ayuda/contacto',
|
route: '/ayuda/contacto',
|
||||||
static_content: {
|
|
||||||
whatsapp: {
|
|
||||||
whatsapp_url: 'https://wa.me/543412602222',
|
|
||||||
whatsapp_label: 'Chatea con nosotros',
|
|
||||||
},
|
|
||||||
phone: '+54 9 (0341) 6658247',
|
|
||||||
locations: {
|
|
||||||
rosario: {
|
|
||||||
label: 'Rosario',
|
|
||||||
addresses: [
|
|
||||||
{
|
|
||||||
label: 'Gigante de Arroyito',
|
|
||||||
address: 'Av. Génova 640, Rosario',
|
|
||||||
coordinates: [-32.913997, -60.674567],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Telepagos',
|
|
||||||
address: 'Rioja 1150, piso 12, dpto. 3, Rosario',
|
|
||||||
coordinates: [-32.94682, -60.63932],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
santa_fe: {
|
|
||||||
label: 'Santa Fe',
|
|
||||||
addresses: [
|
|
||||||
{
|
|
||||||
label: 'San Martín 2450',
|
|
||||||
address: 'San Martín 2450, Santa Fe',
|
|
||||||
coordinates: [-31.63333, -60.7],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
submenues: [],
|
submenues: [],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -111,7 +122,10 @@ describe('ContactPage', () => {
|
|||||||
const phone = element.querySelector<HTMLAnchorElement>('a[href="tel:+54903416658247"]');
|
const phone = element.querySelector<HTMLAnchorElement>('a[href="tel:+54903416658247"]');
|
||||||
|
|
||||||
expect(element.textContent).toContain('CONTACTO');
|
expect(element.textContent).toContain('CONTACTO');
|
||||||
expect(whatsapp?.textContent).toContain('Chatea con nosotros');
|
expect(whatsapp?.textContent).toContain('WhatsApp');
|
||||||
|
expect(
|
||||||
|
element.querySelector('a[href="https://www.instagram.com/comercio"]')?.textContent,
|
||||||
|
).toContain('Instagram');
|
||||||
expect(phone?.textContent).toContain('+54 9 (0341) 6658247');
|
expect(phone?.textContent).toContain('+54 9 (0341) 6658247');
|
||||||
expect(element.textContent).toContain('Rosario');
|
expect(element.textContent).toContain('Rosario');
|
||||||
expect(element.textContent).toContain('Gigante de Arroyito');
|
expect(element.textContent).toContain('Gigante de Arroyito');
|
||||||
@@ -119,9 +133,7 @@ describe('ContactPage', () => {
|
|||||||
expect(element.querySelector('.contact-page__addresses')?.textContent).toContain(
|
expect(element.querySelector('.contact-page__addresses')?.textContent).toContain(
|
||||||
'Av. Génova 640, Rosario',
|
'Av. Génova 640, Rosario',
|
||||||
);
|
);
|
||||||
expect(element.textContent).toContain(
|
expect(element.textContent).toContain('Rioja 1150, piso 12, dpto. 3, Rosario');
|
||||||
'Rioja 1150, piso 12, dpto. 3, Rosario',
|
|
||||||
);
|
|
||||||
expect(element.textContent).toContain('Santa Fe');
|
expect(element.textContent).toContain('Santa Fe');
|
||||||
expect(element.textContent).toContain('San Martín 2450');
|
expect(element.textContent).toContain('San Martín 2450');
|
||||||
});
|
});
|
||||||
@@ -145,12 +157,47 @@ describe('ContactPage', () => {
|
|||||||
expect(map?.textContent).toContain('San Martín 2450');
|
expect(map?.textContent).toContain('San Martín 2450');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('renders canonical numbers with the main first and never restores legacy numbers', () => {
|
||||||
|
const element = fixture.nativeElement as HTMLElement;
|
||||||
|
expect(element.querySelectorAll('a[href^="tel:"]')).toHaveLength(2);
|
||||||
|
expect(element.querySelector('a[href^="tel:"]')?.textContent).toContain('Principal');
|
||||||
|
tenantState.set({ ...tenant, phone: '999999', phone_numbers: [] });
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(element.querySelectorAll('a[href^="tel:"]')).toHaveLength(0);
|
||||||
|
expect(element.textContent).not.toContain('999999');
|
||||||
|
expect(element.textContent).not.toContain('+54 9 (0341) 6658247');
|
||||||
|
});
|
||||||
|
|
||||||
it('shows every canonical address and maps only addresses with coordinates', () => {
|
it('shows every canonical address and maps only addresses with coordinates', () => {
|
||||||
tenantState.set({ ...tenant, addresses: [
|
tenantState.set({
|
||||||
{ id: 10, label: 'Principal', address_text: 'Nueva sede 123', latitude: 0, longitude: 0, is_main: true },
|
...tenant,
|
||||||
{ id: 11, label: 'Sucursal sin mapa', address_text: 'Otra calle 456', latitude: null, longitude: null, is_main: false },
|
addresses: [
|
||||||
{ id: 12, label: 'Otra ciudad', address_text: 'Tercera 789', latitude: -31, longitude: -60, is_main: false },
|
{
|
||||||
] });
|
id: 10,
|
||||||
|
label: 'Principal',
|
||||||
|
address_text: 'Nueva sede 123',
|
||||||
|
latitude: 0,
|
||||||
|
longitude: 0,
|
||||||
|
is_main: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 11,
|
||||||
|
label: 'Sucursal sin mapa',
|
||||||
|
address_text: 'Otra calle 456',
|
||||||
|
latitude: null,
|
||||||
|
longitude: null,
|
||||||
|
is_main: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 12,
|
||||||
|
label: 'Otra ciudad',
|
||||||
|
address_text: 'Tercera 789',
|
||||||
|
latitude: -31,
|
||||||
|
longitude: -60,
|
||||||
|
is_main: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
const element = fixture.nativeElement as HTMLElement;
|
const element = fixture.nativeElement as HTMLElement;
|
||||||
expect(element.textContent).toContain('Nueva sede 123');
|
expect(element.textContent).toContain('Nueva sede 123');
|
||||||
@@ -173,4 +220,75 @@ describe('ContactPage', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.nativeElement.querySelectorAll('.contact-page__location')).toHaveLength(0);
|
expect(fixture.nativeElement.querySelectorAll('.contact-page__location')).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('updates contact when the resolved social media changes to the active event channels', () => {
|
||||||
|
tenantState.set({
|
||||||
|
...tenant,
|
||||||
|
social_media: [
|
||||||
|
{
|
||||||
|
code: 'whatsapp',
|
||||||
|
name: 'WhatsApp del evento',
|
||||||
|
icon: 'fa-brands fa-whatsapp',
|
||||||
|
url: 'https://wa.me/541111111111',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
fixture.detectChanges();
|
||||||
|
const element = fixture.nativeElement as HTMLElement;
|
||||||
|
expect(element.querySelector('a[href="https://wa.me/541111111111"]')?.textContent).toContain(
|
||||||
|
'WhatsApp del evento',
|
||||||
|
);
|
||||||
|
expect(element.querySelector('a[href="https://wa.me/543412602222"]')).toBeNull();
|
||||||
|
expect(element.textContent).not.toContain('Instagram');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows the main address first without reordering tenant data', () => {
|
||||||
|
const addresses = [...tenant.addresses!].reverse();
|
||||||
|
tenantState.set({ ...tenant, addresses });
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(
|
||||||
|
fixture.nativeElement.querySelector('.contact-page__location-title')?.textContent,
|
||||||
|
).toContain('Gigante de Arroyito');
|
||||||
|
expect(addresses[0].id).toBe(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignores legacy static content and shows the empty state when no canonical data exists', () => {
|
||||||
|
tenantState.set({
|
||||||
|
...tenant,
|
||||||
|
addresses: [],
|
||||||
|
phone_numbers: [],
|
||||||
|
social_media: [],
|
||||||
|
menues: [
|
||||||
|
{
|
||||||
|
...tenant.menues![0].submenues[0],
|
||||||
|
static_content: {
|
||||||
|
whatsapp: {
|
||||||
|
whatsapp_url: 'https://wa.me/549999999999',
|
||||||
|
whatsapp_label: 'Legacy WhatsApp',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(fixture.nativeElement.textContent).toContain('No hay datos de contacto disponibles.');
|
||||||
|
expect(fixture.nativeElement.textContent).not.toContain('Legacy WhatsApp');
|
||||||
|
expect(fixture.nativeElement.querySelector('a')).toBeNull();
|
||||||
|
expect(fixture.nativeElement.querySelector('app-location-map')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows social-only contact and ignores blank social URLs', () => {
|
||||||
|
tenantState.set({
|
||||||
|
...tenant,
|
||||||
|
addresses: [],
|
||||||
|
phone_numbers: [],
|
||||||
|
social_media: [tenant.social_media![1], { ...tenant.social_media![0], url: ' ' }],
|
||||||
|
});
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(fixture.nativeElement.textContent).toContain('Instagram');
|
||||||
|
expect(fixture.nativeElement.textContent).not.toContain(
|
||||||
|
'No hay datos de contacto disponibles.',
|
||||||
|
);
|
||||||
|
expect(fixture.nativeElement.textContent).not.toContain('WhatsApp');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { Component, computed, inject } from '@angular/core';
|
import { Component, computed, inject } from '@angular/core';
|
||||||
|
|
||||||
import { findMenu } from '../../../../../../core/services/menu.utils';
|
|
||||||
import { TenantService } from '../../../../../../core/services/tenant.service';
|
import { TenantService } from '../../../../../../core/services/tenant.service';
|
||||||
|
import { TenantPhoneNumber } from '../../../../../../core/services/phone-number.interface';
|
||||||
|
import { SocialMedia } from '../../../../../../core/services/tenant.interface';
|
||||||
import { MenuContentSectionComponent } from '../../../../components/menu-content-section/menu-content-section.component';
|
import { MenuContentSectionComponent } from '../../../../components/menu-content-section/menu-content-section.component';
|
||||||
import {
|
import {
|
||||||
LocationMapComponent,
|
LocationMapComponent,
|
||||||
@@ -22,9 +23,9 @@ type ContactAddress = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type ContactContent = {
|
type ContactContent = {
|
||||||
whatsappUrl: string | null;
|
whatsapp: SocialMedia[];
|
||||||
whatsappLabel: string | null;
|
socialMedia: SocialMedia[];
|
||||||
phone: string | null;
|
phones: TenantPhoneNumber[];
|
||||||
locations: ContactLocation[];
|
locations: ContactLocation[];
|
||||||
mapLocations: MapLocation[];
|
mapLocations: MapLocation[];
|
||||||
};
|
};
|
||||||
@@ -42,57 +43,52 @@ export class ContactPage {
|
|||||||
() => this.tenantService.tenant()?.primary_color ?? '#6376f3',
|
() => this.tenantService.tenant()?.primary_color ?? '#6376f3',
|
||||||
);
|
);
|
||||||
|
|
||||||
protected readonly contact = computed(() =>
|
protected readonly contact = computed(() => this.buildContactContent());
|
||||||
this.parseContactContent(
|
|
||||||
findMenu(this.tenantService.tenant()?.menues ?? [], 'help.contact')?.static_content,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
protected phoneUrl(phone: string): string {
|
private buildContactContent(): ContactContent {
|
||||||
const normalizedPhone = phone.replace(/[^\d+]/g, '');
|
const tenant = this.tenantService.tenant();
|
||||||
return `tel:${normalizedPhone}`;
|
const socialMedia = (tenant?.social_media ?? []).filter((social) => social.url.trim());
|
||||||
}
|
const addresses = [...(tenant?.addresses ?? [])].sort(
|
||||||
|
(a, b) => Number(b.is_main) - Number(a.is_main),
|
||||||
private parseContactContent(value: unknown): ContactContent {
|
);
|
||||||
const content = this.isRecord(value) ? value : {};
|
|
||||||
const whatsapp = this.isRecord(content['whatsapp']) ? content['whatsapp'] : null;
|
|
||||||
const addresses = this.tenantService.tenant()?.addresses ?? [];
|
|
||||||
const locations: ContactLocation[] = addresses.map((address) => ({
|
const locations: ContactLocation[] = addresses.map((address) => ({
|
||||||
|
id: String(address.id),
|
||||||
|
label: address.label,
|
||||||
|
addresses: [
|
||||||
|
{
|
||||||
id: String(address.id),
|
id: String(address.id),
|
||||||
label: address.label,
|
label: address.label,
|
||||||
addresses: [{
|
address: address.address_text,
|
||||||
id: String(address.id),
|
coordinates:
|
||||||
label: address.label,
|
address.latitude !== null && address.longitude !== null
|
||||||
address: address.address_text,
|
? [address.latitude, address.longitude]
|
||||||
coordinates: address.latitude !== null && address.longitude !== null
|
: null,
|
||||||
? [address.latitude, address.longitude] : null,
|
},
|
||||||
}],
|
],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
whatsappUrl: whatsapp ? this.stringValue(whatsapp['whatsapp_url']) : null,
|
whatsapp: socialMedia.filter((social) => social.code === 'whatsapp'),
|
||||||
whatsappLabel: whatsapp ? this.stringValue(whatsapp['whatsapp_label']) : null,
|
socialMedia: socialMedia.filter((social) => social.code !== 'whatsapp'),
|
||||||
phone: this.stringValue(content['phone']) ?? this.tenantService.tenant()?.phone ?? null,
|
phones: [...(tenant?.phone_numbers ?? [])].sort(
|
||||||
|
(a, b) => Number(b.is_main) - Number(a.is_main),
|
||||||
|
),
|
||||||
locations,
|
locations,
|
||||||
mapLocations: locations.flatMap((location) =>
|
mapLocations: locations.flatMap((location) =>
|
||||||
location.addresses.flatMap(
|
location.addresses.flatMap((address): MapLocation[] =>
|
||||||
(address): MapLocation[] => address.coordinates === null ? [] : [{
|
address.coordinates === null
|
||||||
id: address.id,
|
? []
|
||||||
label: address.label,
|
: [
|
||||||
latitude: address.coordinates[0],
|
{
|
||||||
longitude: address.coordinates[1],
|
id: address.id,
|
||||||
address: address.address,
|
label: address.label,
|
||||||
}],
|
latitude: address.coordinates[0],
|
||||||
|
longitude: address.coordinates[1],
|
||||||
|
address: address.address,
|
||||||
|
},
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private stringValue(value: unknown): string | null {
|
|
||||||
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private isRecord(value: unknown): value is Record<string, unknown> {
|
|
||||||
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user