fix(contact): use database settings everywhere
Deploy Canina / deploy (push) Successful in 3m36s

This commit is contained in:
devops committed 2026-10-15 20:13:57 +00:00
1 parent 66cbf4c68d
commit d9ff4aef58
15 files changed
+64 -138

No files matched your search

+17 -17
View File
@@ -13,9 +13,8 @@ describe("ContactService", () => {
count: jest.fn(),
update: jest.fn(),
},
contactInfo: {
setting: {
findMany: jest.fn(),
upsert: jest.fn(),
},
};
@@ -82,26 +81,27 @@ describe("ContactService", () => {
});
describe("getContactInfo", () => {
it("should return contact items if they already exist", async () => {
const items = [
{ id: "1", key: "branch_info", title: "تلفن", value: "021" },
];
mockPrisma.contactInfo.findMany.mockResolvedValue(items);
it("should return contact items from canonical settings", async () => {
mockPrisma.setting.findMany.mockResolvedValue([
{ key: "CONTACT_PHONE", value: "021-12345678" },
{ key: "CONTACT_EMAIL", value: "support@example.test" },
{ key: "CONTACT_ADDRESS", value: "آدرس تنظیم‌شده" },
]);
const result = await service.getContactInfo();
expect(result).toEqual(items);
expect(mockPrisma.contactInfo.upsert).not.toHaveBeenCalled();
expect(result).toEqual([
{ key: "phone", title: "تلفن‌های تماس", value: "021-12345678", icon: "phone", order: 1 },
{ key: "email", title: "پست الکترونیک", value: "support@example.test", icon: "mail", order: 2 },
{ key: "address", title: "نشانی دفتر مرکزی", value: "آدرس تنظیم‌شده", icon: "map-pin", order: 3 },
]);
expect(mockPrisma.setting.findMany).toHaveBeenCalled();
});
it("should seed default items if empty", async () => {
mockPrisma.contactInfo.findMany
.mockResolvedValueOnce([])
.mockResolvedValueOnce([{ key: "branch_info" }]);
const result = await service.getContactInfo();
expect(mockPrisma.contactInfo.upsert).toHaveBeenCalledTimes(3);
expect(result).toHaveLength(1);
it("does not return hardcoded contact values when settings are empty", async () => {
mockPrisma.setting.findMany.mockResolvedValue([]);
expect(await service.getContactInfo()).toEqual([]);
});
});
describe("getAllSubmissions", () => {
+13 -44
View File
@@ -65,51 +65,20 @@ export class ContactService {
}
async getContactInfo() {
let items = await this.prisma.contactInfo.findMany({
orderBy: { order: "asc" },
const settings = await this.prisma.setting.findMany({
where: { key: { in: ["CONTACT_PHONE", "contact_phone", "CONTACT_EMAIL", "contact_email", "CONTACT_ADDRESS", "contact_address"] } },
select: { key: true, value: true },
});
if (items.length === 0) {
// Seed default items if empty
const defaultItems = [
{
key: "branch_info",
title: "اطلاعات نمایندگی",
value:
"تلفن‌های تماس\n۰۲۱-۸۸۸۸ ۴۴۴۴\n\nشنبه تا چهارشنبه ۹:۰۰ الی ۱۸:۰۰",
icon: "phone",
order: 1,
},
{
key: "email_info",
title: "پست الکترونیک",
value: "info@canina.ir\n\nپاسخگویی در کمتر از ۲۴ ساعت کاری",
icon: "mail",
order: 2,
},
{
key: "address_info",
title: "نشانی دفتر مرکزی",
value: "تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹",
icon: "map-pin",
order: 3,
},
];
for (const item of defaultItems) {
await this.prisma.contactInfo.upsert({
where: { key: item.key },
update: {},
create: item,
});
}
items = await this.prisma.contactInfo.findMany({
orderBy: { order: "asc" },
});
}
return items;
const values = new Map(settings.map((item) => [item.key, String(item.value ?? "")]));
const read = (...keys: string[]) => keys.map((key) => values.get(key)).find((value) => value?.trim()) || "";
const phone = read("CONTACT_PHONE", "contact_phone");
const email = read("CONTACT_EMAIL", "contact_email");
const address = read("CONTACT_ADDRESS", "contact_address");
return [
{ key: "phone", title: "تلفن‌های تماس", value: phone, icon: "phone", order: 1 },
{ key: "email", title: "پست الکترونیک", value: email, icon: "mail", order: 2 },
{ key: "address", title: "نشانی دفتر مرکزی", value: address, icon: "map-pin", order: 3 },
].filter((item) => item.value.trim());
}
async getAllSubmissions(page = 1, limit = 20, status?: string) {
+4 -3
View File
@@ -1,6 +1,6 @@
import type { Metadata } from "next";
import ContactFormClient from "@/components/ContactFormClient";
import { getPageMetadata } from "@/lib/seo";
import { getPageMetadata, getSeoConfig } from "@/lib/seo";
export async function generateMetadata(): Promise<Metadata> {
return getPageMetadata('contact', {
@@ -12,13 +12,14 @@ export async function generateMetadata(): Promise<Metadata> {
import { generateLocalBusinessSchema, generateBreadcrumbSchema, safeJsonLd } from "@/lib/schema";
export default function ContactPage() {
export default async function ContactPage() {
const config = await getSeoConfig();
const localBusinessSchema = generateLocalBusinessSchema({
name: 'کنینا ایران',
url: 'https://canina.ir',
telephone: '+989211231517',
address: {
streetAddress: 'تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹',
streetAddress: config.texts.CONTACT_ADDRESS || config.texts.contact_address || undefined,
addressLocality: 'تهران',
addressRegion: 'تهران',
postalCode: '1967812345',
+2 -2
View File
@@ -116,9 +116,9 @@ export default async function RootLayout({
logo: 'https://canina.ir/assets/images/logo.png',
description: 'فروشگاه تخصصی و نماینده انحصاری مکمل‌های دارویی و تقویتی سگ و گربه کنینا آلمان با فرمولاسیون دارویی و تاییدیه بالینی سازمان دامپزشکی کشور.',
telephone: '+989211231517',
email: 'caninairan@gmail.com',
email: config.texts.CONTACT_EMAIL || config.texts.contact_email || undefined,
address: {
streetAddress: 'تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹',
streetAddress: config.texts.CONTACT_ADDRESS || config.texts.contact_address || undefined,
addressLocality: 'تهران',
addressRegion: 'تهران',
postalCode: '1967812345',
@@ -730,10 +730,10 @@ export default function ArchivePage({
<h4 className="text-lg font-black italic mb-4 relative z-10 underline decoration-canina-blue underline-offset-8">{getText('shop_promo_card_title', 'مشاوره رایگان')}</h4>
<p className="text-xs text-white/60 leading-relaxed mb-6 relative z-10">{getText('shop_promo_card_desc', 'اگر نمی‌دانید کدام ترکیب برای پت شما مناسب است، همین حالا با دامپزشکان ما تماس بگیرید.')}</p>
<a
href={getText('contact_phone_link', `tel:${getText('contact_phone', '02188884444').replace(/[^0-9+]/g, '')}`)}
href={getText('contact_phone_link', `tel:${getText('contact_phone', '').replace(/[^0-9+]/g, '')}`)}
className="w-full bg-white text-medical-gray-900 py-3 rounded-xl text-xs font-black hover:scale-105 transition-transform relative z-10 flex items-center justify-center font-vazir"
>
شماره تماس: {getText('contact_phone', '۰۲۱-۸۸۸۸۴۴۴۴')}
شماره تماس: {getText('contact_phone', '')}
</a>
</div>
</aside>
@@ -28,7 +28,7 @@ export default function B2BLandingClient() {
const [openFaq, setOpenFaq] = useState<number | null>(null);
const getText = useSettingsStore((s) => s.getText);
const phone = getText('contact_phone', '۰۹۲۱۱۲۳۱۵۱۷');
const phone = getText('contact_phone', '');
const wholesaleDiscount = getText('B2B_DISCOUNT_PERCENT', '۳۰');
const [formData, setFormData] = useState({
@@ -333,10 +333,10 @@ export default function CartDrawer({ isOpen, onClose, onCheckout, onShopNavigate
</div>
</div>
<a
href={useSettingsStore.getState().getText('contact_phone_link', `tel:${useSettingsStore.getState().getText('contact_phone', '02188884444').replace(/[^0-9+]/g, '')}`)}
href={useSettingsStore.getState().getText('contact_phone_link', `tel:${useSettingsStore.getState().getText('contact_phone', '').replace(/[^0-9+]/g, '')}`)}
className="px-3 py-1.5 bg-amber-600 text-white rounded-xl text-[10px] font-black hover:bg-amber-700 transition-colors whitespace-nowrap shadow-xs font-vazir"
>
تماس فوری ({useSettingsStore.getState().getText('contact_phone', '۰۲۱-۸۸۸۸۴۴۴۴')})
تماس فوری ({useSettingsStore.getState().getText('contact_phone', '')})
</a>
</div>
@@ -321,11 +321,11 @@ export default function CheckoutPage() {
</p>
<div className="flex flex-col sm:flex-row gap-3 pt-2">
<a
href={getText('contact_phone_link', `tel:${getText('contact_phone', '02188884444').replace(/[^0-9+]/g, '')}`)}
href={getText('contact_phone_link', `tel:${getText('contact_phone', '').replace(/[^0-9+]/g, '')}`)}
className="flex-1 px-4 py-3 bg-canina-blue hover:bg-canina-dark text-white rounded-xl text-xs font-black transition-all shadow-md flex items-center justify-center gap-2"
>
<Phone className="w-4 h-4" />
<span>تماس با پشتیبانی ({getText('contact_phone', '۰۲۱-۸۸۸۸۴۴۴۴')})</span>
<span>تماس با پشتیبانی ({getText('contact_phone', '')})</span>
</a>
<button
onClick={() => router.push('/shop')}
@@ -110,53 +110,9 @@ export default function ContactFormClient() {
</div>
))
) : (
<>
<div className="flex gap-4 p-6 bg-white border border-medical-gray-200 rounded-[2rem] shadow-sm">
<div className="w-12 h-12 bg-canina-blue/5 text-canina-blue rounded-2xl flex items-center justify-center shrink-0">
<Phone className="w-6 h-6" />
</div>
<div>
<h4 className="text-xs font-black text-medical-gray-400 uppercase tracking-wider mb-1">
تلفن‌های تماس
</h4>
<p className="text-lg font-black text-medical-gray-900 tracking-wider">
۰۲۱-۸۸۸۸ ۴۴۴۴
</p>
<p className="text-sm text-medical-gray-500 font-bold">
شنبه تا چهارشنبه ۹:۰۰ الی ۱۸:۰۰
</p>
</div>
</div>
<div className="flex gap-4 p-6 bg-white border border-medical-gray-200 rounded-[2rem] shadow-sm">
<div className="w-12 h-12 bg-canina-blue/5 text-canina-blue rounded-2xl flex items-center justify-center shrink-0">
<Mail className="w-6 h-6" />
</div>
<div>
<h4 className="text-xs font-black text-medical-gray-400 uppercase tracking-wider mb-1">
پست الکترونیک
</h4>
<p className="text-sm font-black text-medical-gray-900">info@canina.ir</p>
<p className="text-xs text-medical-gray-500 font-bold">
پاسخگویی در کمتر از ۲۴ ساعت کاری
</p>
</div>
</div>
<div className="flex gap-4 p-6 bg-white border border-medical-gray-200 rounded-[2rem] shadow-sm">
<div className="w-12 h-12 bg-canina-blue/5 text-canina-blue rounded-2xl flex items-center justify-center shrink-0">
<MapPin className="w-6 h-6" />
</div>
<div>
<h4 className="text-xs font-black text-medical-gray-400 uppercase tracking-wider mb-1">
نشانی دفتر مرکزی
</h4>
<p className="text-sm font-bold text-medical-gray-900 leading-relaxed">
تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹
</p>
</div>
</div>
</>
<div className="p-6 rounded-2xl border border-amber-200 bg-amber-50 text-amber-900 font-bold">
اطلاعات تماس از تنظیمات سایت در دسترس نیست.
</div>
)}
</div>
</div>
+5 -5
View File
@@ -208,22 +208,22 @@ export default function Footer({
<h3 className="text-base sm:text-xl font-bold text-white border-b-2 border-canina-blue pb-1.5 sm:pb-2 max-w-max font-lalezar">{getText('footer_contact_title', "اطلاعات تماس نمایندگی")}</h3>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-8">
<div className="flex flex-col sm:space-y-6 gap-2.5 sm:gap-0">
<a href={getText('contact_phone_link', `tel:${getText('contact_phone', '02188884444').replace(/[^0-9+]/g, '')}`)} className="flex items-center sm:items-start gap-2.5 sm:gap-4 group hover:opacity-90 transition-opacity bg-white/[0.04] sm:bg-transparent p-3 sm:p-0 rounded-xl sm:rounded-none border border-white/5 sm:border-0">
<a href={getText('contact_phone_link', `tel:${getText('contact_phone', '').replace(/[^0-9+]/g, '')}`)} className="flex items-center sm:items-start gap-2.5 sm:gap-4 group hover:opacity-90 transition-opacity bg-white/[0.04] sm:bg-transparent p-3 sm:p-0 rounded-xl sm:rounded-none border border-white/5 sm:border-0">
<div className="w-9 h-9 sm:w-12 sm:h-12 bg-white/5 rounded-xl sm:rounded-2xl flex items-center justify-center text-blue-400 group-hover:scale-110 transition-transform flex-shrink-0">
<Phone className="w-4 h-4 sm:w-6 sm:h-6" />
</div>
<div className="min-w-0">
<p className="text-[10px] sm:text-[11px] text-slate-400 font-extrabold uppercase mb-0.5">{getText('footer_phone_label', "خط ویژه فروش")}</p>
<p className="text-xs sm:text-lg font-extrabold tracking-wider sm:tracking-widest text-left text-slate-200" dir="ltr">{getText('contact_phone', "۰۲۱-۸۸۸۸۴۴۴۴")}</p>
<p className="text-xs sm:text-lg font-extrabold tracking-wider sm:tracking-widest text-left text-slate-200" dir="ltr">{getText('contact_phone', '')}</p>
</div>
</a>
<a href={`mailto:${getText('contact_email', 'info@canina.ir')}`} className="flex items-center sm:items-start gap-2.5 sm:gap-4 group hover:opacity-90 transition-opacity bg-white/[0.04] sm:bg-transparent p-3 sm:p-0 rounded-xl sm:rounded-none border border-white/5 sm:border-0">
<a href={`mailto:${getText('contact_email', '')}`} className="flex items-center sm:items-start gap-2.5 sm:gap-4 group hover:opacity-90 transition-opacity bg-white/[0.04] sm:bg-transparent p-3 sm:p-0 rounded-xl sm:rounded-none border border-white/5 sm:border-0">
<div className="w-9 h-9 sm:w-12 sm:h-12 bg-white/5 rounded-xl sm:rounded-2xl flex items-center justify-center text-blue-400 group-hover:scale-110 transition-transform flex-shrink-0">
<Mail className="w-4 h-4 sm:w-6 sm:h-6" />
</div>
<div className="min-w-0">
<p className="text-[10px] sm:text-[11px] text-slate-400 font-extrabold uppercase mb-0.5">{getText('footer_email_label', "مکاتبات رسمی")}</p>
<p className="text-xs sm:text-sm font-bold text-slate-300 truncate">{getText('contact_email', "info@canina.ir")}</p>
<p className="text-xs sm:text-sm font-bold text-slate-300 truncate">{getText('contact_email', '')}</p>
</div>
</a>
</div>
@@ -234,7 +234,7 @@ export default function Footer({
</div>
<div className="min-w-0">
<p className="text-[10px] sm:text-[11px] text-slate-400 font-extrabold uppercase mb-0.5">{getText('footer_address_label', "دفتر مرکزی")}</p>
<p className="text-xs sm:text-sm font-bold leading-relaxed text-slate-300">{getText('contact_address', "تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹")}</p>
<p className="text-xs sm:text-sm font-bold leading-relaxed text-slate-300">{getText('contact_address', '')}</p>
</div>
</div>
</div>
@@ -14,8 +14,8 @@ export default function MaintenancePage() {
);
const badge = getText("maintenance_badge", "سامانه در حال به‌روزرسانی و ارتقا");
const eta = getText("maintenance_eta", "زمان تقریبی بازگشایی: کمتر از ۲ ساعت آینده");
const phone = getText("contact_phone", getText("maintenance_contact_phone", "۰۲۱-۸۸۸۸۴۴۴۴"));
const phoneLink = getText("contact_phone_link", getText("maintenance_contact_phone_link", `tel:${phone.replace(/[^0-9+]/g, "") || "02188884444"}`));
const phone = getText("contact_phone", "");
const phoneLink = getText("contact_phone_link", "");
return (
<div className="min-h-screen bg-medical-gray-900 text-white flex flex-col items-center justify-center p-6 text-center font-vazir relative overflow-hidden" dir="rtl">
@@ -225,7 +225,7 @@ export default function OrderDetailsModal({
</div>
<div class="footer">
داروخانه تخصصی مکمل‌های کنینا ایران • تلفن پشتیبانی: ۰۲۱-۸۸۸۸۸۸۸۸ • وب‌سایت: www.canina.ir
داروخانه تخصصی مکمل‌های کنینا ایران • تلفن پشتیبانی: {useSettingsStore.getState().getText('contact_phone', '')} • وب‌سایت: www.canina.ir
</div>
</div>
<script>
@@ -1379,11 +1379,11 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
) : (
<div className="space-y-3">
<a
href={getText('contact_phone_link', `tel:${getText('contact_phone', '02188884444').replace(/[^0-9+]/g, '')}`)}
href={getText('contact_phone_link', `tel:${getText('contact_phone', '').replace(/[^0-9+]/g, '')}`)}
className="w-full flex items-center justify-center gap-2 px-4 bg-canina-blue text-white rounded-2xl h-16 font-black text-sm hover:bg-canina-dark transition-all shadow-xl shadow-canina-blue/20 font-vazir"
>
<Phone className="w-5 h-5" />
<span>مشاوره تخصصی با کارشناسان ({getText('contact_phone', '۰۲۱-۸۸۸۸۴۴۴۴')})</span>
<span>مشاوره تخصصی با کارشناسان ({getText('contact_phone', '')})</span>
</a>
</div>
)
@@ -1620,7 +1620,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
</button>
) : (
<a
href={getText('contact_phone_link', `tel:${getText('contact_phone', '02188884444').replace(/[^0-9+]/g, '')}`)}
href={getText('contact_phone_link', `tel:${getText('contact_phone', '').replace(/[^0-9+]/g, '')}`)}
className="flex-1 bg-canina-blue text-white py-2.5 px-3 rounded-xl font-black text-xs hover:bg-canina-dark transition-all flex items-center justify-center gap-1.5 shadow-md shadow-canina-blue/20 whitespace-nowrap"
>
<Phone className="w-4 h-4" />
+5 -5
View File
@@ -43,13 +43,13 @@ export function generateOrganizationSchema(options: OrganizationSchemaOptions =
options.description ||
'نماینده رسمی و انحصاری مکمل‌های دارویی و درمانی Canina pharma GmbH آلمان در ایران.',
telephone: options.telephone || '+989211231517',
email: options.email || 'caninairan@gmail.com',
email: options.email || undefined,
address: {
'@type': 'PostalAddress',
streetAddress: options.address?.streetAddress || 'جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵',
streetAddress: options.address?.streetAddress || undefined,
addressLocality: options.address?.addressLocality || 'تهران',
addressRegion: options.address?.addressRegion || 'تهران',
postalCode: options.address?.postalCode || '1967812345',
postalCode: options.address?.postalCode || undefined,
addressCountry: options.address?.addressCountry || 'IR',
},
sameAs: options.sameAs || [
@@ -85,10 +85,10 @@ export function generateLocalBusinessSchema(options: OrganizationSchemaOptions =
priceRange: '$$',
address: {
'@type': 'PostalAddress',
streetAddress: options.address?.streetAddress || 'تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹',
streetAddress: options.address?.streetAddress || undefined,
addressLocality: options.address?.addressLocality || 'تهران',
addressRegion: options.address?.addressRegion || 'تهران',
postalCode: options.address?.postalCode || '1967812345',
postalCode: options.address?.postalCode || undefined,
addressCountry: 'IR',
},
geo: {
@@ -62,8 +62,8 @@ export const useSettingsStore = create<SettingsStore>()((set, get) => ({
texts[key.toUpperCase()];
if (value === undefined || value === null || value === '') {
// Special aliases
if (key === 'contact_phone') return texts['CONTACT_PHONE'] || texts['footer_phone'] || texts['maintenance_contact_phone'] || fallback;
if (key === 'contact_phone_link') return texts['CONTACT_PHONE_LINK'] || texts['maintenance_contact_phone_link'] || (texts['contact_phone'] ? `tel:${texts['contact_phone'].replace(/[^0-9+]/g, '')}` : fallback);
if (key === 'contact_phone') return texts['CONTACT_PHONE'] || fallback;
if (key === 'contact_phone_link') return texts['CONTACT_PHONE_LINK'] || fallback;
if (key === 'site_logo') return texts['BRAND_LOGO_URL'] || texts['brand_logo_url'] || fallback;
if (key === 'site_logo_text_en') return texts['BRAND_LOGO_TEXT_EN'] || fallback;
if (key === 'site_logo_text_fa') return texts['BRAND_LOGO_TEXT_FA'] || texts['brand_name_fa'] || fallback;