feat: update SMS settings review functionality

- Changed the tab name from 'post-visit-review' to 'post-visit-approved' in SmsPage.
- Introduced a new query for fetching approved post-visit texts.
- Updated the UI to display approved post-visit texts and their details.
- Enhanced the API endpoint to filter SMS settings based on status (pending/approved).
- Added entity name resolution for doctors and clinics in the SMS settings.
- Updated the SmsWalletPage to include new post-visit text variables for SMS templates.
- Improved type definitions in index.ts for better clarity and consistency.
This commit is contained in:
hamed
2026-06-22 10:30:46 +03:30
parent 8ed119e12a
commit 3c103bc51e
8 changed files with 1831 additions and 1011 deletions
File diff suppressed because it is too large Load Diff
+61 -18
View File
@@ -21,7 +21,7 @@ const templateSchema = z.object({
});
type TemplateFormData = z.infer<typeof templateSchema>;
type Tab = 'samples' | 'pending' | 'logs' | 'post-visit-review' | 'messages';
type Tab = 'samples' | 'pending' | 'logs' | 'post-visit-approved' | 'messages';
const STATUS_LOG_META: Record<string, { label: string; cls: string }> = {
sent: { label: 'ارسال شده', cls: 'green' },
@@ -167,10 +167,18 @@ export default function SmsPage() {
onError: (err: Error) => toast.error(err.message),
});
const postVisitReviewQuery = useQuery<ApiResponse<{ data: Array<{ id: number; entity_type: string; entity_id: number; post_visit_text_pending: string; post_visit_text_status: string }> }>>({
type PostVisitItem = { id: number; entity_type: string; entity_id: number; entity_name?: string | null; post_visit_text_pending: string; post_visit_text: string | null; post_visit_text_status: string };
const postVisitReviewQuery = useQuery<ApiResponse<{ data: PostVisitItem[] }>>({
queryKey: ['sms-post-visit-review'],
queryFn: () => api.get('/api/v1/admin/sms/settings/review'),
enabled: activeTab === 'post-visit-review',
queryFn: () => api.get('/api/v1/admin/sms/settings/review?status=pending'),
enabled: activeTab === 'pending',
});
const postVisitApprovedQuery = useQuery<ApiResponse<{ data: PostVisitItem[] }>>({
queryKey: ['sms-post-visit-approved'],
queryFn: () => api.get('/api/v1/admin/sms/settings/review?status=approved'),
enabled: activeTab === 'post-visit-approved',
});
const postVisitApproveMutation = useMutation({
@@ -178,6 +186,7 @@ export default function SmsPage() {
onSuccess: () => {
toast.success('متن پیامک تأیید شد');
qc.invalidateQueries({ queryKey: ['sms-post-visit-review'] });
qc.invalidateQueries({ queryKey: ['sms-post-visit-approved'] });
},
onError: (err: Error) => toast.error(err.message),
});
@@ -234,12 +243,14 @@ export default function SmsPage() {
setPage(1);
};
const postVisitPendingCount = (postVisitReviewQuery.data?.data as any)?.data?.length ?? 0;
const postVisitPending = (postVisitReviewQuery.data?.data as any)?.data ?? [];
const postVisitApproved = (postVisitApprovedQuery.data?.data as any)?.data ?? [];
const pendingBadge = pendingCount + postVisitPending.length;
const TABS: { key: Tab; label: string; badge?: number }[] = [
{ key: 'samples', label: 'قالب‌های نمونه' },
{ key: 'pending', label: 'در انتظار تأیید', badge: pendingCount },
{ key: 'post-visit-review', label: 'متن پیامک ویزیت', badge: postVisitPendingCount },
{ key: 'pending', label: 'در انتظار تأیید', badge: pendingBadge },
{ key: 'post-visit-approved', label: 'پیامک‌های تأیید شده' },
{ key: 'logs', label: 'لاگ‌های ارسال' },
{ key: 'messages', label: 'متن پیامک‌ها' },
];
@@ -330,11 +341,14 @@ export default function SmsPage() {
{activeTab === 'pending' && (
<>
{pendingCount > 0 && (
<div style={{ fontSize: 12.5, fontWeight: 600, color: 'var(--text-2)', marginBottom: 8 }}>قالبهای نمونه</div>
)}
<DataTable<SmsTemplate>
columns={pendingColumns}
data={pendingTemplatesQuery.data?.data ?? []}
loading={pendingTemplatesQuery.isLoading}
emptyMessage="هیچ قالبی در انتظار تأیید نیست"
emptyMessage="قالب نمونه‌ای در انتظار تأیید نیست"
actions={(t) => (
<>
<button onClick={() => setApproveTarget(t)} className="mini-btn" title="تأیید">
@@ -352,24 +366,24 @@ export default function SmsPage() {
limit={limit}
onPageChange={setPage}
/>
</>
)}
{activeTab === 'post-visit-review' && (
<div style={{ padding: '16px' }}>
<div style={{ fontSize: 12.5, fontWeight: 600, color: 'var(--text-2)', margin: '20px 0 8px' }}>متن پیامک ویزیت</div>
{postVisitReviewQuery.isLoading ? (
<div className="muted" style={{ fontSize: 13 }}>در حال بارگذاری...</div>
) : ((postVisitReviewQuery.data?.data as any)?.data ?? []).length === 0 ? (
<div style={{ textAlign: 'center', padding: '32px 16px', color: 'var(--text-3)', fontSize: 13 }}>
متنی برای بررسی وجود ندارد
) : postVisitPending.length === 0 ? (
<div style={{ textAlign: 'center', padding: '24px 16px', color: 'var(--text-3)', fontSize: 13 }}>
متن ویزیتی در انتظار تأیید نیست
</div>
) : (
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
{((postVisitReviewQuery.data?.data as any)?.data ?? []).map((item: any) => (
{postVisitPending.map((item: PostVisitItem) => (
<div key={item.id} className="card card-pad">
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 10 }}>
<div>
<span className="badge gray" style={{ fontSize: 11 }}>{item.entity_type} #{item.entity_id}</span>
<span className="badge gray" style={{ fontSize: 11 }}>
{item.entity_type === 'doctor' ? 'پزشک' : item.entity_type === 'clinic' ? 'کلینیک' : item.entity_type}
{item.entity_name ? `: ${item.entity_name}` : ` #${item.entity_id}`}
</span>
</div>
<div style={{ display: 'flex', gap: 8 }}>
<button
@@ -394,7 +408,36 @@ export default function SmsPage() {
))}
</div>
)}
</div>
</>
)}
{activeTab === 'post-visit-approved' && (
<>
{postVisitApprovedQuery.isLoading ? (
<div className="muted" style={{ fontSize: 13 }}>در حال بارگذاری...</div>
) : postVisitApproved.length === 0 ? (
<div style={{ textAlign: 'center', padding: '24px 16px', color: 'var(--text-3)', fontSize: 13 }}>
متن تأییدشدهای وجود ندارد
</div>
) : (
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
{postVisitApproved.map((item: PostVisitItem) => (
<div key={item.id} className="card card-pad">
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 10 }}>
<span className="badge gray" style={{ fontSize: 11 }}>
{item.entity_type === 'doctor' ? 'پزشک' : item.entity_type === 'clinic' ? 'کلینیک' : item.entity_type}
{item.entity_name ? `: ${item.entity_name}` : ` #${item.entity_id}`}
</span>
<span className="badge green" style={{ fontSize: 11 }}><span className="bdot" />تأیید شده</span>
</div>
<div style={{ fontSize: 13, lineHeight: 1.8, padding: '10px 14px', background: 'var(--surface)', borderRadius: 8, border: '1px solid var(--border)', direction: 'rtl' }}>
{item.post_visit_text}
</div>
</div>
))}
</div>
)}
</>
)}
{activeTab === 'logs' && (
+44 -7
View File
@@ -25,6 +25,15 @@ type ChargeForm = z.infer<typeof chargeSchema>;
const EMPTY_LOGS: SmsWalletLog[] = [];
const REMINDER_HOUR_OPTIONS = [1, 2, 3, 4, 6, 12, 24, 48];
const POST_VISIT_VARS: { key: string; label: string }[] = [
{ key: 'patient_name', label: 'نام بیمار' },
{ key: 'doctor', label: 'نام پزشک' },
{ key: 'clinic', label: 'نام کلینیک' },
{ key: 'date', label: 'تاریخ ویزیت' },
];
function SmsWalletPageInner() {
const qc = useQueryClient();
const [chargeOpen, setChargeOpen] = useState(false);
@@ -211,14 +220,16 @@ function SmsWalletPageInner() {
{currentSettings.reminder_enabled && (
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 12 }}>
<label style={{ fontSize: 13, color: 'var(--text-2)', whiteSpace: 'nowrap' }}>ارسال</label>
<input
type="number" min={1} max={72}
<select
className="cp-select"
value={currentSettings.reminder_hours_before}
onChange={(e) => setLocalSettings({ ...currentSettings, reminder_hours_before: +e.target.value })}
dir="ltr"
style={{ width: 72, textAlign: 'center' }}
/>
<label style={{ fontSize: 13, color: 'var(--text-2)', whiteSpace: 'nowrap' }}>ساعت قبل</label>
style={{ width: 130, height: 36 }}
>
{REMINDER_HOUR_OPTIONS.map((h) => (
<option key={h} value={h}>{h} ساعت قبل</option>
))}
</select>
</div>
)}
</div>
@@ -283,7 +294,33 @@ function SmsWalletPageInner() {
direction: 'rtl',
}}
/>
<div style={{ fontSize: 11.5, color: 'var(--text-3)', marginTop: 6 }}>
<div style={{ marginTop: 10 }}>
<div style={{ fontSize: 12, color: 'var(--text-3)', marginBottom: 6 }}>
برای افزودن، روی پارامتر کلیک کنید:
</div>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
{POST_VISIT_VARS.map(({ key, label }) => (
<button
key={key}
type="button"
onClick={() => setLocalSettings({
...currentSettings,
post_visit_text: `${currentSettings.post_visit_text_pending ?? currentSettings.post_visit_text ?? ''}{${key}}`,
})}
style={{
fontSize: 12, fontWeight: 600,
padding: '4px 10px', borderRadius: 16, cursor: 'pointer',
background: 'var(--primary-subtle)', color: 'var(--primary)',
border: '1px solid color-mix(in oklch, var(--primary) 30%, transparent)',
}}
>
{label} <span style={{ direction: 'ltr', opacity: 0.7 }}>{`{${key}}`}</span>
</button>
))}
</div>
</div>
<div style={{ fontSize: 11.5, color: 'var(--text-3)', marginTop: 8 }}>
متن پس از تغییر باید توسط ادمین تأیید شود تا فعال گردد
</div>
</div>