feat(contact): update phone handling to support multiple phone numbers

This commit is contained in:
2026-09-30 11:53:09 -03:00
parent d9bf729a96
commit b6ab36437b
7 changed files with 53 additions and 12 deletions

View File

@@ -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>

View File

@@ -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');

View 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;
}

View File

@@ -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;

View File

@@ -13,10 +13,10 @@
</a> </a>
} }
@if (contact().phone; as phone) { @for (phone of contact().phones; track phone.id) {
<a class="contact-page__contact-link" [href]="phoneUrl(phone)"> <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 +35,7 @@
</article> </article>
} }
@if (!contact().whatsappUrl && !contact().phone && contact().locations.length === 0) { @if (!contact().whatsappUrl && 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>

View File

@@ -19,6 +19,10 @@ const tenant: Tenant = {
header_logo: '', header_logo: '',
footer_logo: '', footer_logo: '',
categories: [], categories: [],
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: 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: 2, label: 'Telepagos', address_text: 'Rioja 1150, piso 12, dpto. 3, Rosario', latitude: -32.94682, longitude: -60.63932, is_main: false },
@@ -145,6 +149,17 @@ 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({ ...tenant, addresses: [
{ id: 10, label: 'Principal', address_text: 'Nueva sede 123', latitude: 0, longitude: 0, is_main: true }, { id: 10, label: 'Principal', address_text: 'Nueva sede 123', latitude: 0, longitude: 0, is_main: true },

View File

@@ -2,6 +2,7 @@ import { Component, computed, inject } from '@angular/core';
import { findMenu } from '../../../../../../core/services/menu.utils'; 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 { 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,
@@ -24,7 +25,7 @@ type ContactAddress = {
type ContactContent = { type ContactContent = {
whatsappUrl: string | null; whatsappUrl: string | null;
whatsappLabel: string | null; whatsappLabel: string | null;
phone: string | null; phones: TenantPhoneNumber[];
locations: ContactLocation[]; locations: ContactLocation[];
mapLocations: MapLocation[]; mapLocations: MapLocation[];
}; };
@@ -48,11 +49,6 @@ export class ContactPage {
), ),
); );
protected phoneUrl(phone: string): string {
const normalizedPhone = phone.replace(/[^\d+]/g, '');
return `tel:${normalizedPhone}`;
}
private parseContactContent(value: unknown): ContactContent { private parseContactContent(value: unknown): ContactContent {
const content = this.isRecord(value) ? value : {}; const content = this.isRecord(value) ? value : {};
const whatsapp = this.isRecord(content['whatsapp']) ? content['whatsapp'] : null; const whatsapp = this.isRecord(content['whatsapp']) ? content['whatsapp'] : null;
@@ -72,7 +68,8 @@ export class ContactPage {
return { return {
whatsappUrl: whatsapp ? this.stringValue(whatsapp['whatsapp_url']) : null, whatsappUrl: whatsapp ? this.stringValue(whatsapp['whatsapp_url']) : null,
whatsappLabel: whatsapp ? this.stringValue(whatsapp['whatsapp_label']) : null, whatsappLabel: whatsapp ? this.stringValue(whatsapp['whatsapp_label']) : null,
phone: this.stringValue(content['phone']) ?? this.tenantService.tenant()?.phone ?? null, phones: [...(this.tenantService.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(