From d9ff4aef58ca4a81a64e719fcc28c3a96ebaa570 Mon Sep 17 00:00:00 2001
From: devops
Date: Thu, 15 Oct 2026 20:13:57 +0000
Subject: [PATCH] fix(contact): use database settings everywhere
---
backend/src/contact/contact.service.spec.ts | 34 +++++------
backend/src/contact/contact.service.ts | 57 +++++--------------
frontend/application/app/contact/page.tsx | 7 ++-
frontend/application/app/layout.tsx | 4 +-
.../application/components/ArchivePage.tsx | 4 +-
.../components/B2BLandingClient.tsx | 2 +-
.../application/components/CartDrawer.tsx | 4 +-
.../application/components/CheckoutPage.tsx | 4 +-
.../components/ContactFormClient.tsx | 50 +---------------
frontend/application/components/Footer.tsx | 10 ++--
.../components/MaintenancePage.tsx | 4 +-
.../components/OrderDetailsModal.tsx | 2 +-
.../application/components/ProductPage.tsx | 6 +-
frontend/application/lib/schema.ts | 10 ++--
.../application/lib/store/settingsStore.ts | 4 +-
15 files changed, 64 insertions(+), 138 deletions(-)
diff --git a/backend/src/contact/contact.service.spec.ts b/backend/src/contact/contact.service.spec.ts
index 8bb2c859..0ad0a8c6 100644
--- a/backend/src/contact/contact.service.spec.ts
+++ b/backend/src/contact/contact.service.spec.ts
@@ -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", () => {
diff --git a/backend/src/contact/contact.service.ts b/backend/src/contact/contact.service.ts
index fb69a3de..785c952e 100644
--- a/backend/src/contact/contact.service.ts
+++ b/backend/src/contact/contact.service.ts
@@ -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) {
diff --git a/frontend/application/app/contact/page.tsx b/frontend/application/app/contact/page.tsx
index b26c7273..b9e24e93 100644
--- a/frontend/application/app/contact/page.tsx
+++ b/frontend/application/app/contact/page.tsx
@@ -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 {
return getPageMetadata('contact', {
@@ -12,13 +12,14 @@ export async function generateMetadata(): Promise {
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',
diff --git a/frontend/application/app/layout.tsx b/frontend/application/app/layout.tsx
index 00fbe7a0..cce23feb 100644
--- a/frontend/application/app/layout.tsx
+++ b/frontend/application/app/layout.tsx
@@ -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',
diff --git a/frontend/application/components/ArchivePage.tsx b/frontend/application/components/ArchivePage.tsx
index 631baf83..374af28e 100644
--- a/frontend/application/components/ArchivePage.tsx
+++ b/frontend/application/components/ArchivePage.tsx
@@ -730,10 +730,10 @@ export default function ArchivePage({
{getText('shop_promo_card_title', 'مشاوره رایگان')}
{getText('shop_promo_card_desc', 'اگر نمیدانید کدام ترکیب برای پت شما مناسب است، همین حالا با دامپزشکان ما تماس بگیرید.')}
- شماره تماس: {getText('contact_phone', '۰۲۱-۸۸۸۸۴۴۴۴')}
+ شماره تماس: {getText('contact_phone', '')}
diff --git a/frontend/application/components/B2BLandingClient.tsx b/frontend/application/components/B2BLandingClient.tsx
index 130c83d9..ffccae62 100644
--- a/frontend/application/components/B2BLandingClient.tsx
+++ b/frontend/application/components/B2BLandingClient.tsx
@@ -28,7 +28,7 @@ export default function B2BLandingClient() {
const [openFaq, setOpenFaq] = useState(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({
diff --git a/frontend/application/components/CartDrawer.tsx b/frontend/application/components/CartDrawer.tsx
index e9f9767e..137d8d79 100644
--- a/frontend/application/components/CartDrawer.tsx
+++ b/frontend/application/components/CartDrawer.tsx
@@ -333,10 +333,10 @@ export default function CartDrawer({ isOpen, onClose, onCheckout, onShopNavigate
- تماس فوری ({useSettingsStore.getState().getText('contact_phone', '۰۲۱-۸۸۸۸۴۴۴۴')})
+ تماس فوری ({useSettingsStore.getState().getText('contact_phone', '')})
diff --git a/frontend/application/components/CheckoutPage.tsx b/frontend/application/components/CheckoutPage.tsx
index 12b0b510..81f79bb3 100644
--- a/frontend/application/components/CheckoutPage.tsx
+++ b/frontend/application/components/CheckoutPage.tsx
@@ -321,11 +321,11 @@ export default function CheckoutPage() {
))
) : (
- <>
-
-
-
-
- تلفنهای تماس
-
-
- ۰۲۱-۸۸۸۸ ۴۴۴۴
-
-
- شنبه تا چهارشنبه ۹:۰۰ الی ۱۸:۰۰
-
-
-
-
-
-
-
-
-
-
- پست الکترونیک
-
-
info@canina.ir
-
- پاسخگویی در کمتر از ۲۴ ساعت کاری
-
-
-
-
-
-
-
-
-
-
- نشانی دفتر مرکزی
-
-
- تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹
-
-
-
- >
+
+ اطلاعات تماس از تنظیمات سایت در دسترس نیست.
+
)}
diff --git a/frontend/application/components/Footer.tsx b/frontend/application/components/Footer.tsx
index 530e312f..f591504d 100644
--- a/frontend/application/components/Footer.tsx
+++ b/frontend/application/components/Footer.tsx
@@ -208,22 +208,22 @@ export default function Footer({
{getText('footer_contact_title', "اطلاعات تماس نمایندگی")}
@@ -234,7 +234,7 @@ export default function Footer({
{getText('footer_address_label', "دفتر مرکزی")}
-
{getText('contact_address', "تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹")}
+
{getText('contact_address', '')}
diff --git a/frontend/application/components/MaintenancePage.tsx b/frontend/application/components/MaintenancePage.tsx
index 5c6acf40..56768b57 100644
--- a/frontend/application/components/MaintenancePage.tsx
+++ b/frontend/application/components/MaintenancePage.tsx
@@ -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 (
diff --git a/frontend/application/components/OrderDetailsModal.tsx b/frontend/application/components/OrderDetailsModal.tsx
index 82586164..0ab5041d 100644
--- a/frontend/application/components/OrderDetailsModal.tsx
+++ b/frontend/application/components/OrderDetailsModal.tsx
@@ -225,7 +225,7 @@ export default function OrderDetailsModal({