From d778ed345c76807fd2796c34e0649ff0cbba50f4 Mon Sep 17 00:00:00 2001 From: Jandl-hostacny Date: Thu, 22 Oct 2026 10:46:42 +0200 Subject: [PATCH] fix: jednotkova cena v tvare 'jednotkova cena 7,75 EUR/kg' aj v existujucich produktoch - normalizeUnitPrice prevedie stare zapisy '1kg = 7,75 EUR' pri nacitani newslettera, v CSV importe a v predvolenych produktoch - jednotkova cena pod nazvom sa neopakuje, ked ju ma priamo cenovka (vernostna karta, appkaci) Co-Authored-By: Claude Opus 5.5 --- src/app/page.tsx | 17 +++++++++---- src/components/editor/BadgeEditorModal.tsx | 2 +- src/components/editor/ProductImportModal.tsx | 5 ++-- src/lib/defaultCampaign.ts | 18 +++++++------- src/lib/productCard.ts | 10 +++----- src/lib/unitPrice.ts | 25 ++++++++++++++++++++ 6 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 src/lib/unitPrice.ts diff --git a/src/app/page.tsx b/src/app/page.tsx index 444efec..cb2dd41 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,7 +1,7 @@ 'use client'; import React, { useState, useEffect, useRef } from 'react'; -import { NewsletterCampaign, NewsletterModule, ProductItem, BadgeTemplate } from '@/types/newsletter'; +import { NewsletterCampaign, NewsletterModule, ProductItem, BadgeTemplate, CardProduct } from '@/types/newsletter'; import { DEFAULT_CAMPAIGN, SUPABASE_ASSETS_BASE, ensureValidityBar } from '@/lib/defaultCampaign'; import { renderEmailHtml, renderSingleModuleHtml, getCampaignValidity } from '@/lib/emailRenderer'; import { supabase } from '@/lib/supabase'; @@ -15,6 +15,7 @@ import { SavedCampaignsModal } from '@/components/editor/SavedCampaignsModal'; import { NameDialog } from '@/components/editor/NameDialog'; import JSZip from 'jszip'; import { prepareCardImages } from '@/lib/cardImages'; +import { normalizeUnitPrice } from '@/lib/unitPrice'; import { useCampaignReview } from '@/components/review/useCampaignReview'; import { ReviewModal } from '@/components/review/ReviewModal'; import { AnnotationLayer, useModuleLayout } from '@/components/review/AnnotationLayer'; @@ -88,7 +89,15 @@ export default function Home() { useEffect(() => { if (!availableBadges.length) return; const byId = new Map(availableBadges.map((b) => [b.id, b])); - const update = (p: ProductItem, def: BadgeTemplate | undefined): ProductItem => { + const UNIT_KEYS = ['unitPrice', 'cardUnitPrice', 'noCardUnitPrice', 'appUnitPrice'] as const; + const update = (input: ProductItem, def: BadgeTemplate | undefined): ProductItem => { + // jednotkové ceny v jednotnom tvare „jednotková cena 7,75 EUR/kg“ (staršie produkty mali „1kg = 7,75 €“) + let p = input; + for (const k of UNIT_KEYS) { + const cur = (p as CardProduct)[k]; + const next = cur ? normalizeUnitPrice(cur) : cur; + if (next !== cur) p = { ...p, [k]: next }; + } if (p.customBadgePngUrl) return p; if (!p.badgeCustomTemplate) return def ? { ...p, badgeCustomTemplate: def, badgeId: def.id, badgeWidth: def.width } : p; const fresh = byId.get(p.badgeCustomTemplate.id); @@ -346,7 +355,7 @@ export default function Home() { imageUrl: `${SUPABASE_ASSETS_BASE}produkt_5.png`, priceMain: '2', priceSub: '49', - unitPrice: '1kg = 9,90 €', + unitPrice: 'jednotková cena 9,90 EUR/kg', discountText: '15%', badgeText: 'zľava', cardBgColor: '#feeaea', @@ -1050,7 +1059,7 @@ export default function Home() { currentDiscount={targetProduct?.discountText || targetProduct?.cardDiscount || '25%'} currentPriceMain={targetProduct?.priceMain || targetProduct?.cardPriceMain || '1'} currentPriceSub={targetProduct?.priceSub || targetProduct?.cardPriceSub || '99'} - currentUnitPrice={targetProduct?.unitPrice || targetProduct?.cardUnitPrice || '1kg = 4,91 €'} + currentUnitPrice={targetProduct?.unitPrice || targetProduct?.cardUnitPrice || 'jednotková cena 4,91 EUR/kg'} currentCardPriceMain={targetProduct?.cardPriceMain || undefined} currentCardPriceSub={targetProduct?.cardPriceSub || undefined} currentCardDiscount={targetProduct?.cardDiscount || undefined} diff --git a/src/components/editor/BadgeEditorModal.tsx b/src/components/editor/BadgeEditorModal.tsx index bf53494..b6388d9 100644 --- a/src/components/editor/BadgeEditorModal.tsx +++ b/src/components/editor/BadgeEditorModal.tsx @@ -315,7 +315,7 @@ export const BadgeEditorModal: React.FC = ({ currentDiscount = '25%', currentPriceMain = '1', currentPriceSub = '99', - currentUnitPrice = '1kg = 4,91 €', + currentUnitPrice = 'jednotková cena 4,91 EUR/kg', currentCardPriceMain = '1', currentCardPriceSub = '49', currentCardDiscount = '30%', diff --git a/src/components/editor/ProductImportModal.tsx b/src/components/editor/ProductImportModal.tsx index 88cfdb0..2785014 100644 --- a/src/components/editor/ProductImportModal.tsx +++ b/src/components/editor/ProductImportModal.tsx @@ -9,6 +9,7 @@ import { Upload, Check, AlertCircle, FileText, X } from 'lucide-react'; import { supabase } from '@/lib/supabase'; import { PodkladyProduct, pickLoyaltyBadge, podkladyToLoyaltyItem, podkladyToProductItem, readPodkladyZip, splitPrice } from '@/lib/podkladyZip'; import { CARD_BG_BY_BADGE_COLOR } from '@/lib/productCard'; +import { normalizeUnitPrice } from '@/lib/unitPrice'; import { shrinkImage, uploadFile } from '@/lib/upload'; interface ImportModalProps { @@ -222,7 +223,7 @@ export const ProductImportModal: React.FC = ({ imageUrl: row[mapping.imageUrl] || 'https://dqexxfspkylqttrtxsww.supabase.co/storage/v1/object/public/newsletter-assets/produkt_1.png', priceMain: pMain, priceSub: pSub, - unitPrice: row[mapping.unitPrice] || '', + unitPrice: normalizeUnitPrice(String(row[mapping.unitPrice] || '')), discountText: row[mapping.discountText] ? `${row[mapping.discountText]}%` : '', badgeText: 'zľava', cardBgColor: '#feeaea', @@ -416,7 +417,7 @@ export const ProductImportModal: React.FC = ({
- +