feat(auth/contact/sms): sync contact submissions in admin, refine SMS error logs, trigger Auth Modal on 401 [TASK-13.1, TASK-14.1, TASK-15.1]
This commit is contained in:
1 parent
89c836d7b6
commit
d52d1e57f2
4 files changed
+34
-33
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import axios from 'axios';
|
||||
import toast from 'react-hot-toast';
|
||||
import api from '../services/api';
|
||||
|
||||
interface ContactSubmission {
|
||||
id: string;
|
||||
@@ -31,73 +31,56 @@ export default function ContactSubmissions() {
|
||||
const [adminNotes, setAdminNotes] = useState('');
|
||||
const [status, setStatus] = useState('PENDING');
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL || '';
|
||||
|
||||
const fetchSubmissionsData = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('adminToken');
|
||||
const res = await axios.get(`${API_URL}/api/contact/submissions`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
const res = await api.get('/contact/submissions');
|
||||
setSubmissions(res.data.items || []);
|
||||
} catch {
|
||||
toast.error('خطا در دریافت پیامهای تماس با ما');
|
||||
// Handled by api interceptor
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let isSubscribed = true;
|
||||
const token = localStorage.getItem('adminToken');
|
||||
|
||||
axios.get(`${API_URL}/api/contact/submissions`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
}).then(res => {
|
||||
setLoading(true);
|
||||
|
||||
api.get('/contact/submissions').then(res => {
|
||||
if (isSubscribed) setSubmissions(res.data.items || []);
|
||||
}).catch(() => {
|
||||
toast.error('خطا در دریافت پیامهای تماس با ما');
|
||||
// Handled by api interceptor
|
||||
}).finally(() => {
|
||||
if (isSubscribed) setLoading(false);
|
||||
});
|
||||
|
||||
axios.get(`${API_URL}/api/contact/info`).then(res => {
|
||||
api.get('/contact/info').then(res => {
|
||||
if (isSubscribed) setInfoItems(res.data || []);
|
||||
}).catch(() => {
|
||||
toast.error('خطا در دریافت اطلاعات نمایندگی');
|
||||
// Handled by api interceptor
|
||||
});
|
||||
|
||||
return () => {
|
||||
isSubscribed = false;
|
||||
};
|
||||
}, [API_URL]);
|
||||
}, []);
|
||||
|
||||
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}` } },
|
||||
);
|
||||
await api.put(`/contact/submissions/${selectedSub.id}`, { status, adminNotes });
|
||||
toast.success('وضعیت پیام با موفقیت بهروزرسانی شد');
|
||||
setSelectedSub(null);
|
||||
fetchSubmissionsData();
|
||||
} catch {
|
||||
toast.error('خطا در ثبت تغییرات');
|
||||
// Handled by api interceptor
|
||||
}
|
||||
};
|
||||
|
||||
const handleSaveContactInfo = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('adminToken');
|
||||
await axios.put(
|
||||
`${API_URL}/api/contact/info`,
|
||||
{ items: infoItems },
|
||||
{ headers: { Authorization: `Bearer ${token}` } },
|
||||
);
|
||||
await api.put('/contact/info', { items: infoItems });
|
||||
toast.success('اطلاعات نمایندگی و دفتر مرکزی با موفقیت ذخیره شد');
|
||||
} catch {
|
||||
toast.error('خطا در بروزرسانی اطلاعات نمایندگی');
|
||||
// Handled by api interceptor
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user