feat(products): remove mock static fallbacks and add dynamic specialist recommendation management in database and admin panel
This commit is contained in:
1 parent
1ca06d5740
commit
00839017ff
7 files changed
+216
-66
No files matched your search
@@ -232,7 +232,7 @@ export default function Products() {
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
const [previewImage, setPreviewImage] = useState<{ url: string; title: string; subtitle?: string; artNo?: string } | null>(null);
|
||||
const [isMediaSelectorOpen, setIsMediaSelectorOpen] = useState(false);
|
||||
const [mediaTargetField, setMediaTargetField] = useState<'imageUrl' | 'ogImage' | 'podcastUrl' | 'podcastCover' | 'videoUrl' | 'videoCover' | 'pdfUrl' | 'pdfCover' | 'gallery'>('imageUrl');
|
||||
const [mediaTargetField, setMediaTargetField] = useState<'imageUrl' | 'ogImage' | 'podcastUrl' | 'podcastCover' | 'videoUrl' | 'videoCover' | 'pdfUrl' | 'pdfCover' | 'specialistImage' | 'gallery'>('imageUrl');
|
||||
const [editingProduct, setEditingProduct] = useState<Product | null>(null);
|
||||
const [deleteTargetId, setDeleteTargetId] = useState<string | null>(null);
|
||||
const [activeTab, setActiveTab] = useState('general');
|
||||
@@ -297,6 +297,12 @@ export default function Products() {
|
||||
preorderDeposit: '' as number | string,
|
||||
roundingStep: '' as number | string,
|
||||
roundingMode: '' as string,
|
||||
specialist: {
|
||||
name: '',
|
||||
title: '',
|
||||
image: '',
|
||||
message: '',
|
||||
},
|
||||
});
|
||||
|
||||
// Smart Pricing & Rounding state
|
||||
@@ -482,6 +488,14 @@ export default function Products() {
|
||||
? (Array.isArray((product as unknown as { contraindications?: any }).contraindications) ? (product as unknown as { contraindications?: any }).contraindications.join('\n') : String((product as unknown as { contraindications?: any }).contraindications))
|
||||
: '');
|
||||
|
||||
const rawSpecialist = dosageConfig.specialist || (product as unknown as { specialist?: any }).specialist;
|
||||
const initialSpecialist = rawSpecialist && typeof rawSpecialist === 'object' ? {
|
||||
name: rawSpecialist.name || '',
|
||||
title: rawSpecialist.title || '',
|
||||
image: rawSpecialist.image || '',
|
||||
message: rawSpecialist.message || '',
|
||||
} : { name: '', title: '', image: '', message: '' };
|
||||
|
||||
setFormData({
|
||||
artNo: product.artNo || '',
|
||||
nameFa: product.nameFa || '',
|
||||
@@ -542,6 +556,7 @@ export default function Products() {
|
||||
preorderDeposit: product.preorderDeposit !== undefined && product.preorderDeposit !== null ? product.preorderDeposit : '',
|
||||
roundingStep: product.roundingStep !== undefined && product.roundingStep !== null ? product.roundingStep : '',
|
||||
roundingMode: product.roundingMode || '',
|
||||
specialist: initialSpecialist,
|
||||
});
|
||||
} else {
|
||||
setEditingProduct(null);
|
||||
@@ -574,7 +589,8 @@ export default function Products() {
|
||||
podcastUrl: '', podcastTitle: '', podcastDescription: '', podcastCover: '',
|
||||
videoUrl: '', videoTitle: '', videoDescription: '', videoCover: '',
|
||||
pdfUrl: '', pdfTitle: '', pdfDescription: '', pdfCover: '',
|
||||
symptoms: [], isPreorder: false, preorderDeposit: ''
|
||||
symptoms: [], isPreorder: false, preorderDeposit: '',
|
||||
specialist: { name: '', title: '', image: '', message: '' }
|
||||
});
|
||||
}
|
||||
setIsModalOpen(true);
|
||||
@@ -916,7 +932,15 @@ export default function Products() {
|
||||
slug: derivedSlug,
|
||||
symptoms: formData.symptoms || [],
|
||||
isPreorder: Boolean(formData.isPreorder),
|
||||
preorderDeposit: formData.preorderDeposit ? String(formData.preorderDeposit) : undefined
|
||||
preorderDeposit: formData.preorderDeposit ? String(formData.preorderDeposit) : undefined,
|
||||
specialist: formData.specialist && (formData.specialist.name?.trim() || formData.specialist.message?.trim())
|
||||
? {
|
||||
name: (formData.specialist.name || '').trim(),
|
||||
title: (formData.specialist.title || '').trim(),
|
||||
image: (formData.specialist.image || '').trim(),
|
||||
message: (formData.specialist.message || '').trim(),
|
||||
}
|
||||
: null,
|
||||
};
|
||||
|
||||
if (editingProduct) {
|
||||
@@ -1822,6 +1846,103 @@ export default function Products() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Specialist Endorsement Card */}
|
||||
<div className="bg-white p-5 rounded-2xl border border-gray-200 shadow-sm space-y-4">
|
||||
<div className="flex items-center justify-between border-b pb-2">
|
||||
<h4 className="text-sm font-black text-gray-800 flex items-center gap-2">
|
||||
<Activity className="w-4 h-4 text-canina-blue" />
|
||||
<span>توصیه و نظر پزشک متخصص (Specialist Endorsement)</span>
|
||||
</h4>
|
||||
{formData.specialist?.name && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setFormData({
|
||||
...formData,
|
||||
specialist: { name: '', title: '', image: '', message: '' }
|
||||
})}
|
||||
className="text-xs text-red-600 hover:underline font-bold"
|
||||
>
|
||||
پاک کردن نظر پزشک ✕
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-[11px] text-gray-500 font-medium">
|
||||
در صورت تکمیل این بخش، کادر نظر و توصیه بالینی پزشک در کاتالوگ و صفحه محصول نمایش داده میشود. در صورت خالی ماندن، هیچ کادری نمایش داده نخواهد شد.
|
||||
</p>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div className="space-y-1">
|
||||
<label className="text-xs font-bold text-gray-700 block">نام پزشک / متخصص</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.specialist?.name || ''}
|
||||
onChange={(e) => setFormData({
|
||||
...formData,
|
||||
specialist: { ...(formData.specialist || { name: '', title: '', image: '', message: '' }), name: e.target.value }
|
||||
})}
|
||||
placeholder="مثال: دکتر علیرضا رضایی یا Dr. Klaus Henning"
|
||||
className="w-full px-3 py-2 rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-xs font-bold font-vazir"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<label className="text-xs font-bold text-gray-700 block">عنوان / تخصص پزشک</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.specialist?.title || ''}
|
||||
onChange={(e) => setFormData({
|
||||
...formData,
|
||||
specialist: { ...(formData.specialist || { name: '', title: '', image: '', message: '' }), title: e.target.value }
|
||||
})}
|
||||
placeholder="مثال: متخصص جراحی استخوان و مفاصل دامپزشکی"
|
||||
className="w-full px-3 py-2 rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-xs font-bold font-vazir"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<label className="text-xs font-bold text-gray-700 block">تصویر پزشک (اختیاری)</label>
|
||||
<div className="flex gap-2 items-center">
|
||||
<input
|
||||
type="text"
|
||||
value={formData.specialist?.image || ''}
|
||||
onChange={(e) => setFormData({
|
||||
...formData,
|
||||
specialist: { ...(formData.specialist || { name: '', title: '', image: '', message: '' }), image: e.target.value }
|
||||
})}
|
||||
placeholder="آدرس تصویر یا انتخاب از رسانهها (/uploads/doctor.jpg)"
|
||||
className="flex-1 px-3 py-2 rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-xs font-mono"
|
||||
dir="ltr"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMediaTargetField('specialistImage');
|
||||
setIsMediaSelectorOpen(true);
|
||||
}}
|
||||
className="px-3 py-2 bg-purple-600 hover:bg-purple-700 text-white rounded-xl text-xs font-bold whitespace-nowrap cursor-pointer flex items-center gap-1"
|
||||
>
|
||||
<ImageIcon className="w-3.5 h-3.5" />
|
||||
انتخاب تصویر
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<label className="text-xs font-bold text-gray-700 block">متن توصیه / نظر بالینی پزشک</label>
|
||||
<textarea
|
||||
rows={3}
|
||||
value={formData.specialist?.message || ''}
|
||||
onChange={(e) => setFormData({
|
||||
...formData,
|
||||
specialist: { ...(formData.specialist || { name: '', title: '', image: '', message: '' }), message: e.target.value }
|
||||
})}
|
||||
placeholder="متن نظر پزشک درباره اثربخشی، کیفیت مواد اولیه یا پروتکل درمانی مکمل..."
|
||||
className="w-full px-3 py-2 rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-xs leading-relaxed font-vazir resize-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Benefits & Analysis Tab */}
|
||||
@@ -4030,6 +4151,14 @@ export default function Products() {
|
||||
if (!formData.images.includes(url)) {
|
||||
setFormData({ ...formData, images: [...formData.images, url] });
|
||||
}
|
||||
} else if (mediaTargetField === 'specialistImage') {
|
||||
setFormData({
|
||||
...formData,
|
||||
specialist: {
|
||||
...(formData.specialist || { name: '', title: '', image: '', message: '' }),
|
||||
image: url,
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setFormData({ ...formData, [mediaTargetField]: url });
|
||||
if (mediaTargetField === 'imageUrl') setMediaImageError(false);
|
||||
@@ -4038,9 +4167,11 @@ export default function Products() {
|
||||
selectedUrl={
|
||||
(mediaTargetField as string) === 'gallery'
|
||||
? undefined
|
||||
: formData[mediaTargetField]?.startsWith('http')
|
||||
? formData[mediaTargetField]
|
||||
: formData[mediaTargetField]
|
||||
: mediaTargetField === 'specialistImage'
|
||||
? (formData.specialist?.image?.startsWith('http') ? formData.specialist?.image : formData.specialist?.image ? `${BASE_DOMAIN}${formData.specialist?.image}` : undefined)
|
||||
: (formData[mediaTargetField] as string)?.startsWith('http')
|
||||
? (formData[mediaTargetField] as string)
|
||||
: (formData[mediaTargetField] as string)
|
||||
? `${BASE_DOMAIN}${formData[mediaTargetField]}`
|
||||
: undefined
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user