feat: resolve doctors query error, add FAQ, testimonials, blog preview, and full menu management
Deploy Canina / deploy (push) Successful in 1m41s
Deploy Canina / deploy (push) Successful in 1m41s
This commit is contained in:
1 parent
70d58e7086
commit
2c452215c3
31 files changed
+1987
-76
No files matched your search
@@ -0,0 +1,178 @@
|
||||
"use client";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { BookOpen, Calendar, Eye, MessageSquare, ArrowLeft } from "lucide-react";
|
||||
import { motion } from "motion/react";
|
||||
import SafeImage from "./SafeImage";
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
import api, { BASE_DOMAIN } from "../lib/services/api";
|
||||
import { toPersian } from "../lib/utils";
|
||||
|
||||
export interface BlogPost {
|
||||
id: string;
|
||||
title: string;
|
||||
slug: string;
|
||||
content: string;
|
||||
imageUrl?: string;
|
||||
viewCount: number;
|
||||
createdAt: string;
|
||||
author?: {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
};
|
||||
_count?: {
|
||||
comments: number;
|
||||
};
|
||||
}
|
||||
|
||||
export default function BlogPreviewSection() {
|
||||
const getText = useSettingsStore((state) => state.getText);
|
||||
const [blogs, setBlogs] = useState<BlogPost[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
async function loadBlogs() {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const res = await api.get("/blogs/homepage");
|
||||
const list = Array.isArray(res.data?.blogs)
|
||||
? res.data.blogs
|
||||
: Array.isArray(res.data)
|
||||
? res.data
|
||||
: [];
|
||||
setBlogs(list);
|
||||
} catch (err) {
|
||||
console.error("Failed to load homepage blogs:", err);
|
||||
setBlogs([]);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
loadBlogs();
|
||||
}, []);
|
||||
|
||||
if (!isLoading && blogs.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="py-20 bg-white font-vazir" dir="rtl">
|
||||
<div className="max-w-7xl mx-auto px-4">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col md:flex-row md:items-end justify-between mb-12 gap-4">
|
||||
<div>
|
||||
<div className="inline-flex items-center gap-2 px-3 py-1 bg-canina-blue/10 text-canina-blue rounded-full text-xs font-black uppercase tracking-widest mb-3">
|
||||
<BookOpen className="w-4 h-4" />
|
||||
<span>{getText("blog_preview_badge", "آخرین مطالب تخصصی")}</span>
|
||||
</div>
|
||||
<h2 className="text-3xl md:text-4xl font-black text-medical-gray-900 font-lalezar leading-tight">
|
||||
{getText("blog_preview_title", "مجله سلامت پت کنینا")}
|
||||
</h2>
|
||||
<p className="text-sm md:text-base text-medical-gray-500 font-medium mt-2">
|
||||
{getText(
|
||||
"blog_preview_subtitle",
|
||||
"مقالات علمی و تخصصی دامپزشکی برای مراقبت بهتر از حیوان خانگی شما"
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<Link
|
||||
href="/blog"
|
||||
className="inline-flex items-center gap-2 text-canina-blue font-bold hover:gap-3 transition-all text-sm shrink-0"
|
||||
>
|
||||
<span>{getText("blog_preview_read_more", "مشاهده همه مقالات")}</span>
|
||||
<ArrowLeft className="w-4 h-4" />
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{/* Blog Grid */}
|
||||
{isLoading ? (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
|
||||
{[1, 2, 3].map((i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="bg-medical-gray-50 rounded-3xl p-4 border border-medical-gray-100 animate-pulse space-y-4"
|
||||
>
|
||||
<div className="h-48 bg-medical-gray-200 rounded-2xl" />
|
||||
<div className="h-6 bg-medical-gray-200 rounded-md w-3/4" />
|
||||
<div className="h-4 bg-medical-gray-200 rounded-md w-1/2" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
|
||||
{blogs.map((blog, idx) => {
|
||||
const image = blog.imageUrl?.startsWith("http")
|
||||
? blog.imageUrl
|
||||
: blog.imageUrl
|
||||
? `${BASE_DOMAIN}${blog.imageUrl}`
|
||||
: "/assets/images/blog-placeholder.png";
|
||||
|
||||
const authorName = blog.author
|
||||
? `${blog.author.firstName || ""} ${blog.author.lastName || ""}`.trim()
|
||||
: "تحریریه کنینا";
|
||||
|
||||
const formattedDate = new Date(blog.createdAt).toLocaleDateString("fa-IR");
|
||||
|
||||
return (
|
||||
<motion.article
|
||||
key={blog.id || idx}
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
whileInView={{ opacity: 1, y: 0 }}
|
||||
viewport={{ once: true }}
|
||||
transition={{ delay: idx * 0.1 }}
|
||||
className="bg-medical-gray-50/60 rounded-[2rem] border border-medical-gray-100 overflow-hidden hover:shadow-lg hover:-translate-y-1 transition-all flex flex-col group"
|
||||
>
|
||||
<Link href={`/blog/${blog.slug}`} className="block relative h-52 overflow-hidden bg-medical-gray-100">
|
||||
<SafeImage
|
||||
src={image}
|
||||
alt={blog.title}
|
||||
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500"
|
||||
/>
|
||||
</Link>
|
||||
|
||||
<div className="p-6 flex-1 flex flex-col justify-between space-y-4">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-4 text-xs text-medical-gray-400 font-medium">
|
||||
<span className="flex items-center gap-1">
|
||||
<Calendar className="w-3.5 h-3.5" />
|
||||
{toPersian(formattedDate)}
|
||||
</span>
|
||||
<span className="flex items-center gap-1">
|
||||
<Eye className="w-3.5 h-3.5" />
|
||||
{toPersian(blog.viewCount || 0)} {getText("blog_preview_views", "بازدید")}
|
||||
</span>
|
||||
<span className="flex items-center gap-1">
|
||||
<MessageSquare className="w-3.5 h-3.5" />
|
||||
{toPersian(blog._count?.comments || 0)} {getText("blog_preview_comments", "نظر")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<Link href={`/blog/${blog.slug}`}>
|
||||
<h3 className="text-lg font-black text-medical-gray-900 group-hover:text-canina-blue transition-colors line-clamp-2 leading-snug">
|
||||
{blog.title}
|
||||
</h3>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="pt-4 border-t border-medical-gray-200/60 flex items-center justify-between">
|
||||
<span className="text-xs font-bold text-medical-gray-500">
|
||||
{authorName}
|
||||
</span>
|
||||
<Link
|
||||
href={`/blog/${blog.slug}`}
|
||||
className="text-xs font-black text-canina-blue group-hover:underline flex items-center gap-1"
|
||||
>
|
||||
{getText("blog_preview_read_article", "خواندن مقاله")}
|
||||
<ArrowLeft className="w-3 h-3" />
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</motion.article>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
"use client";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { HelpCircle, ChevronDown } from "lucide-react";
|
||||
import { motion, AnimatePresence } from "motion/react";
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
import api from "../lib/services/api";
|
||||
|
||||
export interface FAQItem {
|
||||
id: string;
|
||||
question: string;
|
||||
answer: string;
|
||||
order: number;
|
||||
}
|
||||
|
||||
export default function FAQSection() {
|
||||
const getText = useSettingsStore((state) => state.getText);
|
||||
const [faqs, setFaqs] = useState<FAQItem[]>([]);
|
||||
const [openIndex, setOpenIndex] = useState<number | null>(0);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
async function loadFaqs() {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const res = await api.get("/faq");
|
||||
const list = Array.isArray(res.data) ? res.data : [];
|
||||
setFaqs(list);
|
||||
} catch (err) {
|
||||
console.error("Failed to load FAQs:", err);
|
||||
setFaqs([]);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
loadFaqs();
|
||||
}, []);
|
||||
|
||||
if (!isLoading && faqs.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Schema.org FAQPage JSON-LD structure
|
||||
const faqSchema = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "FAQPage",
|
||||
"mainEntity": faqs.map((faq) => ({
|
||||
"@type": "Question",
|
||||
"name": faq.question,
|
||||
"acceptedAnswer": {
|
||||
"@type": "Answer",
|
||||
"text": faq.answer,
|
||||
},
|
||||
})),
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="py-20 bg-medical-gray-50/70 border-t border-medical-gray-100 font-vazir" dir="rtl">
|
||||
{/* Schema.org FAQPage Rich Snippet */}
|
||||
{faqs.length > 0 && (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(faqSchema) }}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="max-w-4xl mx-auto px-4">
|
||||
{/* Header */}
|
||||
<div className="text-center mb-12">
|
||||
<div className="inline-flex items-center gap-2 px-3 py-1 bg-amber-500/10 text-amber-600 rounded-full text-xs font-black uppercase tracking-widest mb-3">
|
||||
<HelpCircle className="w-4 h-4" />
|
||||
<span>{getText("faq_badge", "سوالات پرتکرار")}</span>
|
||||
</div>
|
||||
<h2 className="text-3xl md:text-4xl font-black text-medical-gray-900 font-lalezar leading-tight">
|
||||
{getText("faq_title", "سوالات متداول")}
|
||||
</h2>
|
||||
<p className="text-sm md:text-base text-medical-gray-500 font-medium mt-2">
|
||||
{getText("faq_subtitle", "پاسخ سوالاتی که اغلب از ما میپرسید")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* FAQ List */}
|
||||
{isLoading ? (
|
||||
<div className="space-y-4">
|
||||
{[1, 2, 3].map((i) => (
|
||||
<div key={i} className="h-16 bg-white rounded-2xl border border-medical-gray-100 animate-pulse" />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{faqs.map((faq, idx) => {
|
||||
const isOpen = openIndex === idx;
|
||||
return (
|
||||
<div
|
||||
key={faq.id || idx}
|
||||
className="bg-white rounded-2xl border border-medical-gray-100 overflow-hidden shadow-xs hover:border-canina-blue/30 transition-all"
|
||||
>
|
||||
<button
|
||||
onClick={() => setOpenIndex(isOpen ? null : idx)}
|
||||
className="w-full p-6 text-right flex items-center justify-between gap-4 font-bold text-medical-gray-900 hover:text-canina-blue transition-colors"
|
||||
>
|
||||
<span className="text-base font-shabnam">{faq.question}</span>
|
||||
<ChevronDown
|
||||
className={`w-5 h-5 shrink-0 text-medical-gray-400 transition-transform duration-300 ${
|
||||
isOpen ? "rotate-180 text-canina-blue" : ""
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
|
||||
<AnimatePresence initial={false}>
|
||||
{isOpen && (
|
||||
<motion.div
|
||||
initial={{ height: 0, opacity: 0 }}
|
||||
animate={{ height: "auto", opacity: 1 }}
|
||||
exit={{ height: 0, opacity: 0 }}
|
||||
transition={{ duration: 0.25 }}
|
||||
className="overflow-hidden"
|
||||
>
|
||||
<div className="px-6 pb-6 pt-0 text-sm text-medical-gray-600 leading-relaxed font-normal border-t border-medical-gray-50">
|
||||
{faq.answer}
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ export default function TestimonialsSection() {
|
||||
async function loadTestimonials() {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const res = await api.get('/testimonials');
|
||||
const res = await api.get('/testimonials/homepage');
|
||||
const raw = res.data;
|
||||
const list = Array.isArray(raw?.testimonials)
|
||||
? raw.testimonials
|
||||
@@ -46,6 +46,7 @@ export default function TestimonialsSection() {
|
||||
}
|
||||
}
|
||||
loadTestimonials();
|
||||
|
||||
}, []);
|
||||
|
||||
if (!isLoading && testimonials.length === 0) {
|
||||
|
||||
@@ -26,7 +26,7 @@ export default function UserDashboard() {
|
||||
const { pets, activePetId, setActivePet, removePet } = usePetStore();
|
||||
const isWithdrawalEnabled = useSettingsStore((s) => s.getBoolean('wallet_withdrawal_enabled', false));
|
||||
const isCatalogMode = useSettingsStore((s) => s.getBoolean('catalog_mode', false));
|
||||
const isWalletRechargeAllowed = !isCatalogMode && useSettingsStore((s) => s.getBoolean('wallet_recharge_enabled', true));
|
||||
const isWalletRechargeAllowed = useSettingsStore((s) => !s.getBoolean('catalog_mode', false) && s.getBoolean('wallet_recharge_enabled', true));
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!isLoggedIn && typeof window !== "undefined") {
|
||||
@@ -216,6 +216,15 @@ export default function UserDashboard() {
|
||||
};
|
||||
}, [profile]);
|
||||
|
||||
// Password Management State
|
||||
const [currentPassword, setCurrentPassword] = useState("");
|
||||
const [newPassword, setNewPassword] = useState("");
|
||||
const [confirmPassword, setConfirmPassword] = useState("");
|
||||
const [showCurrentPass, setShowCurrentPass] = useState(false);
|
||||
const [showNewPass, setShowNewPass] = useState(false);
|
||||
const [showConfirmPass, setShowConfirmPass] = useState(false);
|
||||
const [isSavingPassword, setIsSavingPassword] = useState(false);
|
||||
|
||||
if (!isLoggedIn) {
|
||||
return null;
|
||||
}
|
||||
@@ -240,14 +249,6 @@ export default function UserDashboard() {
|
||||
}
|
||||
};
|
||||
|
||||
// Password Management State
|
||||
const [currentPassword, setCurrentPassword] = useState("");
|
||||
const [newPassword, setNewPassword] = useState("");
|
||||
const [confirmPassword, setConfirmPassword] = useState("");
|
||||
const [showCurrentPass, setShowCurrentPass] = useState(false);
|
||||
const [showNewPass, setShowNewPass] = useState(false);
|
||||
const [showConfirmPass, setShowConfirmPass] = useState(false);
|
||||
const [isSavingPassword, setIsSavingPassword] = useState(false);
|
||||
|
||||
const handleSavePassword = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
Reference in new issue
Block a user