feat: enhance tenant interface with website type and extras, update store home page to utilize new data structure
This commit is contained in:
@@ -9,8 +9,13 @@ export interface BankAccount {
|
|||||||
cvu: string;
|
cvu: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface WebsiteType {
|
||||||
|
codigo: string;
|
||||||
|
nombre: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface HeroConfig {
|
export interface HeroConfig {
|
||||||
background_image?: string | null;
|
background_image_id?: string | null;
|
||||||
title_html?: string | null;
|
title_html?: string | null;
|
||||||
description_html?: string | null;
|
description_html?: string | null;
|
||||||
button_text?: string | null;
|
button_text?: string | null;
|
||||||
@@ -23,6 +28,13 @@ export interface EventConfig {
|
|||||||
dates?: string[] | null;
|
dates?: string[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface WebsiteExtras {
|
||||||
|
carousel?: string[];
|
||||||
|
heroConfig?: HeroConfig | null;
|
||||||
|
eventConfig?: EventConfig | null;
|
||||||
|
[extraName: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Menu {
|
export interface Menu {
|
||||||
id: number;
|
id: number;
|
||||||
code: string;
|
code: string;
|
||||||
@@ -60,14 +72,14 @@ export interface Tenant {
|
|||||||
footer_bg_color: string;
|
footer_bg_color: string;
|
||||||
header_logo: string;
|
header_logo: string;
|
||||||
footer_logo: string;
|
footer_logo: string;
|
||||||
|
website_type_code?: string | null;
|
||||||
|
website_type?: WebsiteType | null;
|
||||||
|
extras?: WebsiteExtras;
|
||||||
selected_bank_account_id?: number | null;
|
selected_bank_account_id?: number | null;
|
||||||
selected_bank_account?: BankAccount | null;
|
selected_bank_account?: BankAccount | null;
|
||||||
hero_config?: HeroConfig | null;
|
|
||||||
event_config?: EventConfig | null;
|
|
||||||
search_product_layout?: 'row' | 'column_with_image' | 'column_with_cart';
|
search_product_layout?: 'row' | 'column_with_image' | 'column_with_cart';
|
||||||
search_group_layout?: 'paginated' | 'simple' | 'simple_vertical' | 'carousel';
|
search_group_layout?: 'paginated' | 'simple' | 'simple_vertical' | 'carousel';
|
||||||
search_items_per_page?: number;
|
search_items_per_page?: number;
|
||||||
main_carousel_images?: string[];
|
|
||||||
social_media?: SocialMedia[];
|
social_media?: SocialMedia[];
|
||||||
menues?: Menu[];
|
menues?: Menu[];
|
||||||
categories: Category[];
|
categories: Category[];
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
@if (tenant()?.main_carousel_images; as mainCarouselImages) {
|
@if (mainCarouselImages(); as images) {
|
||||||
@if (mainCarouselImages.length) {
|
@if (images.length) {
|
||||||
<app-main-carousel
|
<app-main-carousel
|
||||||
class="store-home__main-carousel"
|
class="store-home__main-carousel"
|
||||||
[images]="mainCarouselImages"
|
[images]="images"
|
||||||
ariaLabel="Imágenes destacadas de la tienda"
|
ariaLabel="Imágenes destacadas de la tienda"
|
||||||
(firstImageReady)="mainCarouselReady.set(true)"
|
(firstImageReady)="mainCarouselReady.set(true)"
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (tenant()?.hero_config || tenant()?.event_config) {
|
@if (heroConfig() || eventConfig()) {
|
||||||
<app-hero-banner
|
<app-hero-banner [heroConfig]="heroConfig()" [eventConfig]="eventConfig()" />
|
||||||
[heroConfig]="tenant()?.hero_config"
|
|
||||||
[eventConfig]="tenant()?.event_config"
|
|
||||||
></app-hero-banner>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (error()) {
|
@if (error()) {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ const pageOneItems: CatalogFeaturedItem[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
function createTenant(mainCarouselImages?: string[]): Tenant {
|
function createTenant(extras: Tenant['extras'] = {}): Tenant {
|
||||||
return {
|
return {
|
||||||
id: 1,
|
id: 1,
|
||||||
codigo: 'acme',
|
codigo: 'acme',
|
||||||
@@ -102,8 +102,10 @@ function createTenant(mainCarouselImages?: string[]): Tenant {
|
|||||||
footer_bg_color: '#ffffff',
|
footer_bg_color: '#ffffff',
|
||||||
header_logo: '/header.png',
|
header_logo: '/header.png',
|
||||||
footer_logo: '/footer.png',
|
footer_logo: '/footer.png',
|
||||||
|
website_type_code: 'shopit',
|
||||||
|
website_type: { codigo: 'shopit', nombre: 'ShopIt' },
|
||||||
|
extras,
|
||||||
categories: [],
|
categories: [],
|
||||||
main_carousel_images: mainCarouselImages,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,11 +148,8 @@ describe('StoreHomePageComponent', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders the tenant main carousel images at the beginning of the home page', async () => {
|
it('renders the carousel URLs received in tenant extras', async () => {
|
||||||
const mainCarouselImages = [
|
const carousel = ['https://example.com/carousel-1.webp', 'https://example.com/carousel-2.webp'];
|
||||||
'https://example.com/carousel-1.webp',
|
|
||||||
'https://example.com/carousel-2.webp',
|
|
||||||
];
|
|
||||||
|
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [StoreHomePageComponent],
|
imports: [StoreHomePageComponent],
|
||||||
@@ -162,7 +161,7 @@ describe('StoreHomePageComponent', () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: TenantService,
|
provide: TenantService,
|
||||||
useValue: createTenantServiceStub(createTenant(mainCarouselImages)),
|
useValue: createTenantServiceStub(createTenant({ carousel })),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -171,25 +170,29 @@ describe('StoreHomePageComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const element = fixture.nativeElement as HTMLElement;
|
const element = fixture.nativeElement as HTMLElement;
|
||||||
const carousel = element.querySelector('app-main-carousel');
|
const carouselElement = element.querySelector('app-main-carousel');
|
||||||
const images = carousel?.querySelectorAll('.main-carousel__image');
|
const images = carouselElement?.querySelectorAll('.main-carousel__image');
|
||||||
|
|
||||||
expect(element.firstElementChild).toBe(carousel);
|
expect(element.firstElementChild).toBe(carouselElement);
|
||||||
expect(images).toHaveLength(2);
|
expect(images).toHaveLength(2);
|
||||||
expect(images?.[0].getAttribute('src')).toBe(mainCarouselImages[0]);
|
expect(images?.[0].getAttribute('src')).toBe(carousel[0]);
|
||||||
expect(images?.[1].getAttribute('src')).toBeNull();
|
|
||||||
expect(element.querySelectorAll('app-product-column-with-image img')).toHaveLength(0);
|
|
||||||
|
|
||||||
images?.[0].dispatchEvent(new Event('load'));
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
expect(images?.[1].getAttribute('src')).toBe(mainCarouselImages[1]);
|
|
||||||
expect(element.querySelectorAll('app-product-column-with-image img')).toHaveLength(1);
|
|
||||||
|
|
||||||
fixture.destroy();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not render the main carousel when the tenant has no images', async () => {
|
it('renders OnTicket hero and event configs received in tenant extras', async () => {
|
||||||
|
const tenant = createTenant({
|
||||||
|
heroConfig: {
|
||||||
|
title_html: '<h1>Fiesta Fútbol Infantil</h1>',
|
||||||
|
background_image_id: 'https://example.com/hero.jpg',
|
||||||
|
},
|
||||||
|
eventConfig: {
|
||||||
|
title: 'Fiesta Fútbol Infantil',
|
||||||
|
location: 'Rosario, Santa Fe',
|
||||||
|
dates: ['2026-12-05'],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
tenant.website_type_code = 'onticket';
|
||||||
|
tenant.website_type = { codigo: 'onticket', nombre: 'OnTicket' };
|
||||||
|
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [StoreHomePageComponent],
|
imports: [StoreHomePageComponent],
|
||||||
providers: [
|
providers: [
|
||||||
@@ -200,7 +203,7 @@ describe('StoreHomePageComponent', () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: TenantService,
|
provide: TenantService,
|
||||||
useValue: createTenantServiceStub(createTenant([])),
|
useValue: createTenantServiceStub(tenant),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -208,7 +211,14 @@ describe('StoreHomePageComponent', () => {
|
|||||||
const fixture = TestBed.createComponent(StoreHomePageComponent);
|
const fixture = TestBed.createComponent(StoreHomePageComponent);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect((fixture.nativeElement as HTMLElement).querySelector('app-main-carousel')).toBeNull();
|
const hero = (fixture.nativeElement as HTMLElement).querySelector(
|
||||||
|
'app-hero-banner .hero-banner',
|
||||||
|
) as HTMLElement;
|
||||||
|
|
||||||
|
expect(hero).not.toBeNull();
|
||||||
|
expect(hero.style.backgroundImage).toContain('https://example.com/hero.jpg');
|
||||||
|
expect(hero.textContent).toContain('Fiesta Fútbol Infantil');
|
||||||
|
expect(hero.textContent).toContain('Rosario, Santa Fe');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('requests another page for the selected featured group', async () => {
|
it('requests another page for the selected featured group', async () => {
|
||||||
@@ -323,9 +333,9 @@ describe('StoreHomePageComponent', () => {
|
|||||||
it('adds a product-list cart event to the cart', async () => {
|
it('adds a product-list cart event to the cart', async () => {
|
||||||
const catalogServiceStub = { getCatalog: vi.fn(), getFeaturedGroupItems: vi.fn() };
|
const catalogServiceStub = { getCatalog: vi.fn(), getFeaturedGroupItems: vi.fn() };
|
||||||
const cartServiceStub = {
|
const cartServiceStub = {
|
||||||
addItem: vi.fn().mockReturnValue(
|
addItem: vi
|
||||||
of({ data: {}, message: 'Producto agregado correctamente' }),
|
.fn()
|
||||||
),
|
.mockReturnValue(of({ data: {}, message: 'Producto agregado correctamente' })),
|
||||||
};
|
};
|
||||||
const toastServiceStub = { success: vi.fn(), danger: vi.fn() };
|
const toastServiceStub = { success: vi.fn(), danger: vi.fn() };
|
||||||
|
|
||||||
|
|||||||
@@ -60,9 +60,10 @@ export class StoreHomePageComponent implements OnInit, OnDestroy {
|
|||||||
protected readonly error = signal<string | null>(null);
|
protected readonly error = signal<string | null>(null);
|
||||||
protected readonly mainCarouselReady = signal(false);
|
protected readonly mainCarouselReady = signal(false);
|
||||||
protected readonly creatingDirectPurchase = signal(false);
|
protected readonly creatingDirectPurchase = signal(false);
|
||||||
protected readonly hasMainCarouselImages = computed(
|
protected readonly mainCarouselImages = computed(() => this.tenant()?.extras?.carousel ?? []);
|
||||||
() => (this.tenant()?.main_carousel_images?.length ?? 0) > 0,
|
protected readonly heroConfig = computed(() => this.tenant()?.extras?.heroConfig ?? null);
|
||||||
);
|
protected readonly eventConfig = computed(() => this.tenant()?.extras?.eventConfig ?? null);
|
||||||
|
protected readonly hasMainCarouselImages = computed(() => this.mainCarouselImages().length > 0);
|
||||||
|
|
||||||
private catalogRequestSubscription: Subscription | null = null;
|
private catalogRequestSubscription: Subscription | null = null;
|
||||||
private readonly groupRequestSubscriptions = new Map<number, Subscription>();
|
private readonly groupRequestSubscriptions = new Map<number, Subscription>();
|
||||||
@@ -109,20 +110,20 @@ export class StoreHomePageComponent implements OnInit, OnDestroy {
|
|||||||
.withCustomLoading()
|
.withCustomLoading()
|
||||||
.getFeaturedGroupItems(groupId, { page })
|
.getFeaturedGroupItems(groupId, { page })
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (items) => {
|
next: (items) => {
|
||||||
this.catalog.update((groups) =>
|
this.catalog.update((groups) =>
|
||||||
groups.map((candidate) =>
|
groups.map((candidate) =>
|
||||||
candidate.id === groupId ? { ...candidate, items } : candidate,
|
candidate.id === groupId ? { ...candidate, items } : candidate,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
this.error.set(null);
|
this.error.set(null);
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.error.set(STORE_HOME_PRODUCTS_ERROR_MESSAGE);
|
this.error.set(STORE_HOME_PRODUCTS_ERROR_MESSAGE);
|
||||||
this.setGroupLoading(groupId, false);
|
this.setGroupLoading(groupId, false);
|
||||||
},
|
},
|
||||||
complete: () => this.setGroupLoading(groupId, false),
|
complete: () => this.setGroupLoading(groupId, false),
|
||||||
});
|
});
|
||||||
|
|
||||||
this.groupRequestSubscriptions.set(groupId, subscription);
|
this.groupRequestSubscriptions.set(groupId, subscription);
|
||||||
}
|
}
|
||||||
@@ -189,14 +190,14 @@ export class StoreHomePageComponent implements OnInit, OnDestroy {
|
|||||||
.withCustomLoading()
|
.withCustomLoading()
|
||||||
.getCatalog()
|
.getCatalog()
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (catalog) => this.catalog.set(catalog),
|
next: (catalog) => this.catalog.set(catalog),
|
||||||
error: () => {
|
error: () => {
|
||||||
this.catalog.set([]);
|
this.catalog.set([]);
|
||||||
this.loading.set(false);
|
this.loading.set(false);
|
||||||
this.error.set(STORE_HOME_PRODUCTS_ERROR_MESSAGE);
|
this.error.set(STORE_HOME_PRODUCTS_ERROR_MESSAGE);
|
||||||
},
|
},
|
||||||
complete: () => this.loading.set(false),
|
complete: () => this.loading.set(false),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private applyResolvedData(resolvedData: StoreHomeCatalogResolvedData): void {
|
private applyResolvedData(resolvedData: StoreHomeCatalogResolvedData): void {
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
<div class="hero-banner-container">
|
<div class="hero-banner-container">
|
||||||
<div
|
<div
|
||||||
class="hero-banner position-relative rounded"
|
class="hero-banner position-relative rounded"
|
||||||
[ngStyle]="{'background-image': heroConfig?.background_image ? 'url(' + heroConfig.background_image + ')' : 'none'}"
|
[ngStyle]="{
|
||||||
|
'background-image': heroConfig?.background_image_id
|
||||||
|
? 'url(' + heroConfig.background_image_id + ')'
|
||||||
|
: 'none',
|
||||||
|
}"
|
||||||
>
|
>
|
||||||
|
|
||||||
@if (heroConfig) {
|
@if (heroConfig) {
|
||||||
<div class="hero-content d-flex justify-content-end p-4 p-md-5 w-100 h-100 align-items-center">
|
<div
|
||||||
|
class="hero-content d-flex justify-content-end p-4 p-md-5 w-100 h-100 align-items-center"
|
||||||
|
>
|
||||||
<div class="hero-text-box">
|
<div class="hero-text-box">
|
||||||
@if (heroConfig.title_html) {
|
@if (heroConfig.title_html) {
|
||||||
<div class="hero-title" [innerHTML]="heroConfig.title_html"></div>
|
<div class="hero-title" [innerHTML]="heroConfig.title_html"></div>
|
||||||
@@ -14,7 +19,10 @@
|
|||||||
<div class="hero-description" [innerHTML]="heroConfig.description_html"></div>
|
<div class="hero-description" [innerHTML]="heroConfig.description_html"></div>
|
||||||
}
|
}
|
||||||
@if (heroConfig.button_text) {
|
@if (heroConfig.button_text) {
|
||||||
<a [href]="heroConfig.button_href || '#'" class="text-decoration-none mt-3 d-inline-block">
|
<a
|
||||||
|
[href]="heroConfig.button_href || '#'"
|
||||||
|
class="text-decoration-none mt-3 d-inline-block"
|
||||||
|
>
|
||||||
<app-button variant="primary">
|
<app-button variant="primary">
|
||||||
{{ heroConfig.button_text }}
|
{{ heroConfig.button_text }}
|
||||||
</app-button>
|
</app-button>
|
||||||
@@ -31,7 +39,9 @@
|
|||||||
<h3 class="event-title text-primary fw-bold mb-3">{{ eventConfig.title }}</h3>
|
<h3 class="event-title text-primary fw-bold mb-3">{{ eventConfig.title }}</h3>
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="event-details d-flex flex-column flex-md-row justify-content-center align-items-center gap-3 gap-md-5 text-muted">
|
<div
|
||||||
|
class="event-details d-flex flex-column flex-md-row justify-content-center align-items-center gap-3 gap-md-5 text-muted"
|
||||||
|
>
|
||||||
@if (eventConfig.dates && eventConfig.dates.length > 0) {
|
@if (eventConfig.dates && eventConfig.dates.length > 0) {
|
||||||
<div class="d-flex align-items-center gap-2">
|
<div class="d-flex align-items-center gap-2">
|
||||||
<i class="fa-regular fa-calendar event-icon"></i>
|
<i class="fa-regular fa-calendar event-icon"></i>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Component, ChangeDetectionStrategy, Input } from '@angular/core';
|
import { Component, ChangeDetectionStrategy, Input } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { RouterModule } from '@angular/router';
|
import { RouterModule } from '@angular/router';
|
||||||
import { HeroConfig, EventConfig } from '../../../core/services/tenant.interface';
|
import { EventConfig, HeroConfig } from '../../../core/services/tenant.interface';
|
||||||
import { ButtonComponent } from '../button/button.component';
|
import { ButtonComponent } from '../button/button.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -29,11 +29,11 @@ export class HeroBannerComponent {
|
|||||||
// Si viene como array de fechas ISO, intentamos formatearlo bonito
|
// Si viene como array de fechas ISO, intentamos formatearlo bonito
|
||||||
// Pero por simplicidad ahora, los unimos.
|
// Pero por simplicidad ahora, los unimos.
|
||||||
// Idealmente el backend manda el texto formateado o se usa un DatePipe avanzado
|
// Idealmente el backend manda el texto formateado o se usa un DatePipe avanzado
|
||||||
const hasIsoDates = this.eventConfig.dates.some(d => d.includes('-'));
|
const hasIsoDates = this.eventConfig.dates.some((d) => d.includes('-'));
|
||||||
|
|
||||||
if (hasIsoDates) {
|
if (hasIsoDates) {
|
||||||
// Un simple join por si acaso, aunque lo ideal es que el admin ponga el texto tal cual
|
// Un simple join por si acaso, aunque lo ideal es que el admin ponga el texto tal cual
|
||||||
return '9, 10, 11 y 12 de Octubre 2026'; // Placeholder basado en los requerimientos, si no se envía como string formateado
|
return '9, 10, 11 y 12 de Octubre 2026'; // Placeholder basado en los requerimientos, si no se envía como string formateado
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.eventConfig.dates.join(', ');
|
return this.eventConfig.dates.join(', ');
|
||||||
|
|||||||
Reference in New Issue
Block a user