feat(contact): implement contact form submission, admin management and dynamic contact info
This commit is contained in:
1 parent
49049a7f78
commit
2aea3bded4
11 files changed
+961
-77
No files matched your search
@@ -19,6 +19,7 @@ import Media from './pages/Media';
|
||||
import CMS from './pages/CMS';
|
||||
import WholesaleApplications from './pages/WholesaleApplications';
|
||||
import Videos from './pages/Videos';
|
||||
import ContactSubmissions from './pages/ContactSubmissions';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
@@ -44,6 +45,7 @@ function App() {
|
||||
<Route path="media" element={<Media />} />
|
||||
<Route path="cms" element={<CMS />} />
|
||||
<Route path="wholesale" element={<WholesaleApplications />} />
|
||||
<Route path="contact" element={<ContactSubmissions />} />
|
||||
</Route>
|
||||
</Route>
|
||||
</Routes>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Link, useLocation, useNavigate } from 'react-router-dom';
|
||||
import { Users, ShoppingCart, Tag, Settings, LogOut, TrendingUp, FolderTree, FileText, BookOpen, Heart, Package, LayoutDashboard, Languages, Image, Video } from 'lucide-react';
|
||||
import { Users, ShoppingCart, Tag, Settings, LogOut, TrendingUp, FolderTree, FileText, BookOpen, Heart, Package, LayoutDashboard, Languages, Image, Video, PhoneCall } from 'lucide-react';
|
||||
import api from '../services/api';
|
||||
|
||||
const menuGroups = [
|
||||
@@ -26,6 +26,7 @@ const menuGroups = [
|
||||
{ icon: Users, label: 'کاربران', path: '/users' },
|
||||
{ icon: Heart, label: 'حیوانات (Pets)', path: '/pets' },
|
||||
{ icon: Package, label: 'درخواستهای B2B', path: '/wholesale' },
|
||||
{ icon: PhoneCall, label: 'تماس با ما & اطلاعات', path: '/contact' },
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import axios from 'axios';
|
||||
import toast from 'react-hot-toast';
|
||||
|
||||
interface ContactSubmission {
|
||||
id: string;
|
||||
name: string;
|
||||
phone: string;
|
||||
email?: string;
|
||||
subject?: string;
|
||||
message: string;
|
||||
status: string;
|
||||
adminNotes?: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
interface ContactInfoItem {
|
||||
key: string;
|
||||
title: string;
|
||||
value: string;
|
||||
icon?: string;
|
||||
order?: number;
|
||||
}
|
||||
|
||||
export default function ContactSubmissions() {
|
||||
const [activeTab, setActiveTab] = useState<'submissions' | 'info'>('submissions');
|
||||
const [submissions, setSubmissions] = useState<ContactSubmission[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [infoItems, setInfoItems] = useState<ContactInfoItem[]>([]);
|
||||
const [selectedSub, setSelectedSub] = useState<ContactSubmission | null>(null);
|
||||
const [adminNotes, setAdminNotes] = useState('');
|
||||
const [status, setStatus] = useState('PENDING');
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL || '';
|
||||
|
||||
const fetchSubmissions = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const token = localStorage.getItem('adminToken');
|
||||
const res = await axios.get(`${API_URL}/api/contact/submissions`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
setSubmissions(res.data.items || []);
|
||||
} catch (err: any) {
|
||||
toast.error('خطا در دریافت پیامهای تماس با ما');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchContactInfo = async () => {
|
||||
try {
|
||||
const res = await axios.get(`${API_URL}/api/contact/info`);
|
||||
setInfoItems(res.data || []);
|
||||
} catch (err: any) {
|
||||
toast.error('خطا در دریافت اطلاعات نمایندگی');
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchSubmissions();
|
||||
fetchContactInfo();
|
||||
}, []);
|
||||
|
||||
const handleUpdateStatus = async () => {
|
||||
if (!selectedSub) return;
|
||||
try {
|
||||
const token = localStorage.getItem('adminToken');
|
||||
await axios.put(
|
||||
`${API_URL}/api/contact/submissions/${selectedSub.id}`,
|
||||
{ status, adminNotes },
|
||||
{ headers: { Authorization: `Bearer ${token}` } },
|
||||
);
|
||||
toast.success('وضعیت پیام با موفقیت بهروزرسانی شد');
|
||||
setSelectedSub(null);
|
||||
fetchSubmissions();
|
||||
} catch (err: any) {
|
||||
toast.error('خطا در ثبت تغییرات');
|
||||
}
|
||||
};
|
||||
|
||||
const handleSaveContactInfo = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('adminToken');
|
||||
await axios.put(
|
||||
`${API_URL}/api/contact/info`,
|
||||
{ items: infoItems },
|
||||
{ headers: { Authorization: `Bearer ${token}` } },
|
||||
);
|
||||
toast.success('اطلاعات نمایندگی و دفتر مرکزی با موفقیت ذخیره شد');
|
||||
} catch (err: any) {
|
||||
toast.error('خطا در بروزرسانی اطلاعات نمایندگی');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="p-6 dir-rtl">
|
||||
<div className="flex justify-between items-center mb-6">
|
||||
<h1 className="text-2xl font-bold text-gray-800">مدیریت تماس با ما & اطلاعات نمایندگی</h1>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
onClick={() => setActiveTab('submissions')}
|
||||
className={`px-4 py-2 rounded-lg font-medium transition ${
|
||||
activeTab === 'submissions' ? 'bg-amber-600 text-white' : 'bg-gray-100 text-gray-700'
|
||||
}`}
|
||||
>
|
||||
پیامهای دریافت شده
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab('info')}
|
||||
className={`px-4 py-2 rounded-lg font-medium transition ${
|
||||
activeTab === 'info' ? 'bg-amber-600 text-white' : 'bg-gray-100 text-gray-700'
|
||||
}`}
|
||||
>
|
||||
اطلاعات نمایندگی & آدرسها
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{activeTab === 'submissions' ? (
|
||||
<div className="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
|
||||
{loading ? (
|
||||
<div className="p-8 text-center text-gray-500">در حال بارگذاری...</div>
|
||||
) : submissions.length === 0 ? (
|
||||
<div className="p-8 text-center text-gray-500">هیچ پیامی ثبت نشده است.</div>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-right border-collapse">
|
||||
<thead>
|
||||
<tr className="bg-gray-50 text-gray-600 text-sm font-semibold border-b">
|
||||
<th className="p-4">نام فرستنده</th>
|
||||
<th className="p-4">شماره تماس</th>
|
||||
<th className="p-4">موضوع</th>
|
||||
<th className="p-4">تاریخ ثبت</th>
|
||||
<th className="p-4">وضعیت</th>
|
||||
<th className="p-4">عملیات</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100 text-sm">
|
||||
{submissions.map((sub) => (
|
||||
<tr key={sub.id} className="hover:bg-gray-50/50">
|
||||
<td className="p-4 font-medium text-gray-900">{sub.name}</td>
|
||||
<td className="p-4 dir-ltr text-right">{sub.phone}</td>
|
||||
<td className="p-4">{sub.subject || 'بدون موضوع'}</td>
|
||||
<td className="p-4">
|
||||
{new Date(sub.createdAt).toLocaleDateString('fa-IR')}
|
||||
</td>
|
||||
<td className="p-4">
|
||||
<span
|
||||
className={`px-2.5 py-1 rounded-full text-xs font-medium ${
|
||||
sub.status === 'RESOLVED'
|
||||
? 'bg-emerald-100 text-emerald-700'
|
||||
: sub.status === 'IN_PROGRESS'
|
||||
? 'bg-amber-100 text-amber-700'
|
||||
: 'bg-rose-100 text-rose-700'
|
||||
}`}
|
||||
>
|
||||
{sub.status === 'RESOLVED'
|
||||
? 'پاسخ داده شده'
|
||||
: sub.status === 'IN_PROGRESS'
|
||||
? 'در حال پیگیری'
|
||||
: 'جدید (نیازمند بررسی)'}
|
||||
</span>
|
||||
</td>
|
||||
<td className="p-4">
|
||||
<button
|
||||
onClick={() => {
|
||||
setSelectedSub(sub);
|
||||
setStatus(sub.status);
|
||||
setAdminNotes(sub.adminNotes || '');
|
||||
}}
|
||||
className="px-3 py-1.5 bg-gray-100 hover:bg-gray-200 text-gray-800 rounded-lg text-xs font-medium transition"
|
||||
>
|
||||
مشاهده & تغییر وضعیت
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="bg-white rounded-xl shadow-sm border border-gray-100 p-6 max-w-4xl">
|
||||
<h2 className="text-lg font-bold text-gray-800 mb-4">ویرایش داینامیک اطلاعات دفتر مرکزی & نمایندگیها</h2>
|
||||
<div className="space-y-6">
|
||||
{infoItems.map((item, idx) => (
|
||||
<div key={item.key} className="p-4 bg-gray-50 rounded-xl border border-gray-200 space-y-3">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-700 mb-1">عنوان بخش</label>
|
||||
<input
|
||||
type="text"
|
||||
value={item.title}
|
||||
onChange={(e) => {
|
||||
const newItems = [...infoItems];
|
||||
newItems[idx].title = e.target.value;
|
||||
setInfoItems(newItems);
|
||||
}}
|
||||
className="w-full px-3 py-2 border rounded-lg text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-700 mb-1">آیکون (نام آیکون یا کلید)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={item.icon || ''}
|
||||
onChange={(e) => {
|
||||
const newItems = [...infoItems];
|
||||
newItems[idx].icon = e.target.value;
|
||||
setInfoItems(newItems);
|
||||
}}
|
||||
className="w-full px-3 py-2 border rounded-lg text-sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-700 mb-1">مقدار / متون اطلاعات</label>
|
||||
<textarea
|
||||
rows={3}
|
||||
value={item.value}
|
||||
onChange={(e) => {
|
||||
const newItems = [...infoItems];
|
||||
newItems[idx].value = e.target.value;
|
||||
setInfoItems(newItems);
|
||||
}}
|
||||
className="w-full px-3 py-2 border rounded-lg text-sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<button
|
||||
onClick={handleSaveContactInfo}
|
||||
className="px-6 py-2.5 bg-amber-600 hover:bg-amber-700 text-white rounded-lg font-medium transition shadow-sm"
|
||||
>
|
||||
ذخیره تغییرات اطلاعات نمایندگی
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Modal for Submission Detail & Status Update */}
|
||||
{selectedSub && (
|
||||
<div className="fixed inset-0 bg-black/40 backdrop-blur-sm flex items-center justify-center p-4 z-50">
|
||||
<div className="bg-white rounded-2xl p-6 max-w-lg w-full shadow-xl">
|
||||
<h3 className="text-lg font-bold text-gray-900 mb-4">جزئیات پیام {selectedSub.name}</h3>
|
||||
<div className="space-y-3 text-sm text-gray-700 mb-6 bg-gray-50 p-4 rounded-xl">
|
||||
<div><span className="font-semibold text-gray-900">تلفن:</span> {selectedSub.phone}</div>
|
||||
{selectedSub.email && <div><span className="font-semibold text-gray-900">ایمیل:</span> {selectedSub.email}</div>}
|
||||
<div><span className="font-semibold text-gray-900">موضوع:</span> {selectedSub.subject || 'ندارد'}</div>
|
||||
<div>
|
||||
<span className="font-semibold text-gray-900 block mb-1">متن پیام:</span>
|
||||
<p className="bg-white p-3 rounded-lg border text-gray-800 leading-relaxed whitespace-pre-wrap">{selectedSub.message}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-xs font-semibold text-gray-700 mb-1">تغییر وضعیت پیگیری</label>
|
||||
<select
|
||||
value={status}
|
||||
onChange={(e) => setStatus(e.target.value)}
|
||||
className="w-full px-3 py-2 border rounded-lg text-sm bg-white"
|
||||
>
|
||||
<option value="PENDING">جدید (نیازمند بررسی)</option>
|
||||
<option value="IN_PROGRESS">در حال پیگیری توسط ادمین</option>
|
||||
<option value="RESOLVED">پاسخ داده شد / تکمیل پیگیری</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-semibold text-gray-700 mb-1">یادداشت مدیر (اختیاری)</label>
|
||||
<textarea
|
||||
rows={3}
|
||||
value={adminNotes}
|
||||
onChange={(e) => setAdminNotes(e.target.value)}
|
||||
placeholder="یادداشتهای داخلی جهت پیگیری کارشناسان..."
|
||||
className="w-full px-3 py-2 border rounded-lg text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2 pt-2">
|
||||
<button
|
||||
onClick={() => setSelectedSub(null)}
|
||||
className="px-4 py-2 bg-gray-100 hover:bg-gray-200 text-gray-700 rounded-lg text-sm"
|
||||
>
|
||||
انصراف
|
||||
</button>
|
||||
<button
|
||||
onClick={handleUpdateStatus}
|
||||
className="px-4 py-2 bg-amber-600 hover:bg-amber-700 text-white rounded-lg text-sm font-medium"
|
||||
>
|
||||
ثبت تغییرات
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user