feat: enhance staff management and payment gateway features
- Fix national code handling in staff creation and updates to support Persian digits. - Update ClinicStaff entity to allow longer national codes (up to 15 characters). - Implement support for clinic secretaries in SecretaryController, allowing creation without a doctor UUID. - Add a new endpoint to retrieve doctors associated with a clinic for secretary management. - Improve appointment management by ensuring doctors are selectable even when no appointments exist. - Extend PatientController to allow secretaries to create patient records if they have the appropriate permissions. - Introduce a PriceInput component for better price formatting in forms, supporting Persian digits. - Add a MockGateway for testing payment processes without real transactions. - Enhance SMS settings management with an approval flow for post-visit text messages, including new fields for pending text and status. - Update migrations to reflect changes in database schema for national codes and SMS settings.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
interface PriceInputProps {
|
||||
value: number | '';
|
||||
onChange: (value: number) => void;
|
||||
placeholder?: string;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
disabled?: boolean;
|
||||
min?: number;
|
||||
}
|
||||
|
||||
const PERSIAN_TO_LATIN: Record<string, string> = {
|
||||
'۰': '0', '۱': '1', '۲': '2', '۳': '3', '۴': '4',
|
||||
'۵': '5', '۶': '6', '۷': '7', '۸': '8', '۹': '9',
|
||||
'٠': '0', '١': '1', '٢': '2', '٣': '3', '٤': '4',
|
||||
'٥': '5', '٦': '6', '٧': '7', '٨': '8', '٩': '9',
|
||||
};
|
||||
|
||||
function toLatinDigits(str: string): string {
|
||||
return str.replace(/[۰-۹٠-٩]/g, (ch) => PERSIAN_TO_LATIN[ch] ?? ch);
|
||||
}
|
||||
|
||||
function formatDisplay(num: number): string {
|
||||
if (num === 0) return '';
|
||||
return new Intl.NumberFormat('fa-IR').format(num);
|
||||
}
|
||||
|
||||
export default function PriceInput({
|
||||
value,
|
||||
onChange,
|
||||
placeholder = '0',
|
||||
className,
|
||||
style,
|
||||
disabled,
|
||||
min = 0,
|
||||
}: PriceInputProps) {
|
||||
const [display, setDisplay] = useState(() => (value !== '' && value > 0 ? formatDisplay(value) : ''));
|
||||
|
||||
useEffect(() => {
|
||||
setDisplay(value !== '' && Number(value) > 0 ? formatDisplay(Number(value)) : '');
|
||||
}, [value]);
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const raw = toLatinDigits(e.target.value).replace(/[^0-9]/g, '');
|
||||
const num = raw === '' ? 0 : Math.max(min, parseInt(raw, 10));
|
||||
onChange(num);
|
||||
setDisplay(num > 0 ? formatDisplay(num) : '');
|
||||
};
|
||||
|
||||
return (
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
value={display}
|
||||
onChange={handleChange}
|
||||
placeholder={placeholder}
|
||||
className={className}
|
||||
style={{ textAlign: 'left', direction: 'ltr', ...style }}
|
||||
disabled={disabled}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -551,14 +551,27 @@ export default function AppointmentsPage() {
|
||||
});
|
||||
const appointments: Appointment[] = apptQuery.data?.data ?? EMPTY_ARR;
|
||||
|
||||
// ── Unique doctors from results (for clinic tabs)
|
||||
// ── Clinic: load doctors from clinic profile (not derived from appointments)
|
||||
const clinicDoctorsQuery = useQuery<ApiResponse<{ data: { uuid: string; name: string }[] }>>({
|
||||
queryKey: ['clinic-doctors', dbUuid],
|
||||
queryFn: () => api.get(`/api/v1/clinic/doctor-list/${dbUuid}`),
|
||||
enabled: isClinic && !!dbUuid,
|
||||
});
|
||||
const clinicDoctorsList = clinicDoctorsQuery.data?.data?.data ?? [];
|
||||
|
||||
// ── Unique doctors from results (for clinic tabs) + merge with clinic list
|
||||
const doctors = React.useMemo(() => {
|
||||
const map = new Map<string, string>();
|
||||
// first from clinic API (authoritative list)
|
||||
clinicDoctorsList.forEach(d => map.set(d.uuid, d.name));
|
||||
// then supplement with appointment data (for admin view)
|
||||
appointments.forEach(a => {
|
||||
if (a.doctor_uuid && a.doctor_name) map.set(a.doctor_uuid, a.doctor_name);
|
||||
if (a.doctor_uuid && a.doctor_name && !map.has(a.doctor_uuid)) {
|
||||
map.set(a.doctor_uuid, a.doctor_name);
|
||||
}
|
||||
});
|
||||
return Array.from(map.entries()).map(([uuid, name]) => ({ uuid, name }));
|
||||
}, [appointments]);
|
||||
}, [appointments, clinicDoctorsList]);
|
||||
|
||||
const showDoctorTabs = isClinic && doctors.length >= 2;
|
||||
const showDoctorCol = isAdmin || (isClinic && !selectedDoctorUuid);
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { ApiResponse } from '../lib/api';
|
||||
import type { ServiceSection, ServiceItem, ClinicStaff } from '../types';
|
||||
import { formatRial } from '../lib/utils';
|
||||
import Modal from '../components/ui/Modal';
|
||||
import PriceInput from '../components/ui/PriceInput';
|
||||
import ConfirmDialog from '../components/ui/ConfirmDialog';
|
||||
import PageHeader from '../components/ui/PageHeader';
|
||||
import SearchableSelect from '../components/ui/SearchableSelect';
|
||||
@@ -359,7 +360,12 @@ export default function ClinicServicesPage() {
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>قیمت (ریال) *</label>
|
||||
<input {...itemForm.register('price_rials')} type="number" min={0} placeholder="85000" dir="ltr" />
|
||||
<PriceInput
|
||||
value={itemForm.watch('price_rials') ?? 0}
|
||||
onChange={(v) => itemForm.setValue('price_rials', v)}
|
||||
placeholder="۸۵,۰۰۰"
|
||||
min={0}
|
||||
/>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>پرسنل مسئول</label>
|
||||
|
||||
@@ -134,35 +134,64 @@ const createSchema = z.object({
|
||||
});
|
||||
type CreateForm = z.infer<typeof createSchema>;
|
||||
|
||||
interface ClinicDoctor { uuid: string; name: string; }
|
||||
|
||||
// ── Main component ─────────────────────────────────────────────────────────
|
||||
|
||||
export default function MySecretariesPage() {
|
||||
const qc = useQueryClient();
|
||||
const { doctorUuid } = useAuthStore();
|
||||
const { doctorUuid, dbUuid, primaryRole } = useAuthStore();
|
||||
|
||||
const isClinic = primaryRole === 'clinic';
|
||||
|
||||
// for clinic: selected doctor to add secretary for
|
||||
const [selectedDoctorUuid, setSelectedDoctorUuid] = useState<string>('');
|
||||
|
||||
const activeDoctorUuid = isClinic ? selectedDoctorUuid : (doctorUuid ?? '');
|
||||
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editTarget, setEditTarget] = useState<Secretary | null>(null);
|
||||
const [editPerms, setEditPerms] = useState<SecretaryPermissions>(DEFAULT_PERMISSIONS);
|
||||
const [deleteTarget, setDeleteTarget] = useState<Secretary | null>(null);
|
||||
|
||||
const { data, isLoading } = useQuery<ApiResponse<Secretary[]>>({
|
||||
queryKey: ['my-secretaries', doctorUuid],
|
||||
queryFn: () => api.get(`/api/v1/secretaries/${doctorUuid}`),
|
||||
enabled: !!doctorUuid,
|
||||
// clinic: load clinic's doctors
|
||||
const { data: clinicDoctorsData, isLoading: clinicDoctorsLoading } = useQuery<ApiResponse<{ data: ClinicDoctor[] }>>({
|
||||
queryKey: ['clinic-doctors', dbUuid],
|
||||
queryFn: () => api.get(`/api/v1/clinic/doctor-list/${dbUuid}`),
|
||||
enabled: isClinic && !!dbUuid,
|
||||
});
|
||||
const clinicDoctors: ClinicDoctor[] = clinicDoctorsData?.data?.data ?? [];
|
||||
|
||||
// clinic: load ALL secretaries across all its doctors
|
||||
const { data: clinicSecrData, isLoading: clinicSecrLoading } = useQuery<ApiResponse<Secretary[]>>({
|
||||
queryKey: ['my-secretaries-clinic', dbUuid],
|
||||
queryFn: () => api.get(`/api/v1/secretaries/clinic/${dbUuid}`),
|
||||
enabled: isClinic && !!dbUuid,
|
||||
});
|
||||
|
||||
const secretaries = data?.data ?? [];
|
||||
// doctor: load secretaries for the doctor
|
||||
const { data: doctorSecrData, isLoading: doctorSecrLoading } = useQuery<ApiResponse<Secretary[]>>({
|
||||
queryKey: ['my-secretaries', activeDoctorUuid],
|
||||
queryFn: () => api.get(`/api/v1/secretaries/${activeDoctorUuid}`),
|
||||
enabled: !isClinic && !!activeDoctorUuid,
|
||||
});
|
||||
|
||||
const secretaries = isClinic
|
||||
? (clinicSecrData?.data ?? [])
|
||||
: (doctorSecrData?.data ?? []);
|
||||
const isLoading = isClinic ? clinicSecrLoading : doctorSecrLoading;
|
||||
|
||||
const createForm = useForm<CreateForm>({ resolver: zodResolver(createSchema) });
|
||||
|
||||
const createMutation = useMutation({
|
||||
mutationFn: (body: CreateForm) =>
|
||||
api.post('/api/v1/secretary', { ...body, doctor_uuid: doctorUuid }),
|
||||
api.post('/api/v1/secretary', { ...body, doctor_uuid: activeDoctorUuid }),
|
||||
onSuccess: () => {
|
||||
toast.success('منشی اضافه شد');
|
||||
setCreateOpen(false);
|
||||
createForm.reset();
|
||||
qc.invalidateQueries({ queryKey: ['my-secretaries'] });
|
||||
qc.invalidateQueries({ queryKey: ['my-secretaries-clinic'] });
|
||||
},
|
||||
onError: (e: any) => toast.error(e.message),
|
||||
});
|
||||
@@ -174,6 +203,7 @@ export default function MySecretariesPage() {
|
||||
toast.success('دسترسیها بروزرسانی شد');
|
||||
setEditTarget(null);
|
||||
qc.invalidateQueries({ queryKey: ['my-secretaries'] });
|
||||
qc.invalidateQueries({ queryKey: ['my-secretaries-clinic'] });
|
||||
},
|
||||
onError: (e: any) => toast.error(e.message),
|
||||
});
|
||||
@@ -184,6 +214,7 @@ export default function MySecretariesPage() {
|
||||
toast.success('منشی غیرفعال شد');
|
||||
setDeleteTarget(null);
|
||||
qc.invalidateQueries({ queryKey: ['my-secretaries'] });
|
||||
qc.invalidateQueries({ queryKey: ['my-secretaries-clinic'] });
|
||||
},
|
||||
onError: (e: any) => toast.error(e.message),
|
||||
});
|
||||
@@ -193,7 +224,28 @@ export default function MySecretariesPage() {
|
||||
setEditPerms(s.permissions ?? DEFAULT_PERMISSIONS);
|
||||
};
|
||||
|
||||
const columns: Column<Secretary>[] = [
|
||||
const handleCreateOpen = () => {
|
||||
if (isClinic && !selectedDoctorUuid) {
|
||||
toast.error('ابتدا یک پزشک را انتخاب کنید');
|
||||
return;
|
||||
}
|
||||
setCreateOpen(true);
|
||||
};
|
||||
|
||||
const selectedDoctorName = clinicDoctors.find(d => d.uuid === selectedDoctorUuid)?.name ?? '';
|
||||
|
||||
// for clinic: show doctor column in the table
|
||||
const clinicColumns: Column<Secretary>[] = isClinic ? [
|
||||
{
|
||||
key: 'doctor_name',
|
||||
header: 'پزشک',
|
||||
render: (s) => (
|
||||
<span style={{ fontSize: 13, color: 'var(--text-2)', fontWeight: 500 }}>{s.doctor_name}</span>
|
||||
),
|
||||
},
|
||||
] : [];
|
||||
|
||||
const allColumns: Column<Secretary>[] = [
|
||||
{
|
||||
key: 'user_name',
|
||||
header: 'منشی',
|
||||
@@ -212,6 +264,7 @@ export default function MySecretariesPage() {
|
||||
</div>
|
||||
),
|
||||
},
|
||||
...clinicColumns,
|
||||
{
|
||||
key: 'mobile_number',
|
||||
header: 'موبایل',
|
||||
@@ -256,14 +309,39 @@ export default function MySecretariesPage() {
|
||||
title="منشیان من"
|
||||
description="مدیریت منشیان و دسترسیهای آنها"
|
||||
action={
|
||||
<button className="btn primary sm" onClick={() => setCreateOpen(true)}>
|
||||
<button className="btn primary sm" onClick={handleCreateOpen} disabled={isClinic && !selectedDoctorUuid}>
|
||||
<PlusIcon style={{ width: 16 }} />
|
||||
افزودن منشی
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
|
||||
{!doctorUuid ? (
|
||||
{/* کلینیک: انتخاب پزشک برای افزودن منشی */}
|
||||
{isClinic && (
|
||||
<div className="card card-pad" style={{ marginBottom: 16 }}>
|
||||
<div className="field" style={{ marginBottom: 0 }}>
|
||||
<label>پزشک مورد نظر برای افزودن منشی جدید</label>
|
||||
{clinicDoctorsLoading ? (
|
||||
<p style={{ fontSize: 13, color: 'var(--text-3)' }}>در حال بارگذاری...</p>
|
||||
) : clinicDoctors.length === 0 ? (
|
||||
<p style={{ fontSize: 13, color: 'var(--text-3)' }}>هیچ پزشکی در این کلینیک تعریف نشده است. ابتدا پزشک اضافه کنید.</p>
|
||||
) : (
|
||||
<select
|
||||
value={selectedDoctorUuid}
|
||||
onChange={(e) => setSelectedDoctorUuid(e.target.value)}
|
||||
style={{ width: '100%', maxWidth: 360 }}
|
||||
>
|
||||
<option value="">— یک پزشک را انتخاب کنید —</option>
|
||||
{clinicDoctors.map((d) => (
|
||||
<option key={d.uuid} value={d.uuid}>{d.name}</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isClinic && !doctorUuid ? (
|
||||
<div className="card card-pad" style={{ textAlign: 'center', color: 'var(--text-3)' }}>
|
||||
پروفایل پزشک یافت نشد
|
||||
</div>
|
||||
@@ -274,20 +352,29 @@ export default function MySecretariesPage() {
|
||||
<IdentificationIcon style={{ width: 48, color: 'var(--text-3)', margin: '0 auto 16px', display: 'block', opacity: 0.4 }} />
|
||||
<div style={{ fontWeight: 600, fontSize: 15, marginBottom: 8, color: 'var(--text-2)' }}>هنوز منشیای اضافه نشده</div>
|
||||
<div style={{ color: 'var(--text-3)', fontSize: 13.5, marginBottom: 20 }}>
|
||||
منشی میتواند نوبتها و اطلاعات کلینیک را مدیریت کند
|
||||
{isClinic
|
||||
? 'برای افزودن منشی، ابتدا یک پزشک را از لیست بالا انتخاب کنید'
|
||||
: 'منشی میتواند نوبتها و اطلاعات کلینیک را مدیریت کند'}
|
||||
</div>
|
||||
<button className="btn primary sm" onClick={() => setCreateOpen(true)}>
|
||||
<PlusIcon style={{ width: 16 }} /> افزودن اولین منشی
|
||||
</button>
|
||||
{!isClinic && (
|
||||
<button className="btn primary sm" onClick={handleCreateOpen}>
|
||||
<PlusIcon style={{ width: 16 }} /> افزودن اولین منشی
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<DataTable columns={columns} data={secretaries} loading={isLoading} emptyMessage="منشیای ثبت نشده است" />
|
||||
<DataTable columns={allColumns} data={secretaries} loading={isLoading} emptyMessage="منشیای ثبت نشده است" />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Modal افزودن منشی */}
|
||||
<Modal open={createOpen} onClose={() => setCreateOpen(false)} title="افزودن منشی جدید">
|
||||
{isClinic && selectedDoctorName && (
|
||||
<div style={{ marginBottom: 12, padding: '8px 12px', background: 'var(--primary-subtle)', borderRadius: 8, fontSize: 13, color: 'var(--primary)' }}>
|
||||
منشی برای دکتر {selectedDoctorName} اضافه میشود
|
||||
</div>
|
||||
)}
|
||||
<form onSubmit={createForm.handleSubmit((d) => createMutation.mutate(d))}>
|
||||
<div className="field">
|
||||
<label>شماره موبایل *</label>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { z } from 'zod';
|
||||
@@ -19,6 +19,17 @@ const schema = z.object({
|
||||
}, 'درصد باید بین ۰ تا ۱۰۰ باشد'),
|
||||
max_cancel_hours_before: z.string(),
|
||||
appointment_reminder_hours: z.string(),
|
||||
// payment gateways
|
||||
payment_test_mode: z.string(),
|
||||
mellat_terminal_id: z.string(),
|
||||
mellat_username: z.string(),
|
||||
mellat_password: z.string(),
|
||||
sep_terminal_id: z.string(),
|
||||
// sms
|
||||
sms_provider: z.string(),
|
||||
kavenegar_api_key: z.string(),
|
||||
kavenegar_sender: z.string(),
|
||||
sms_price_rials: z.string(),
|
||||
});
|
||||
|
||||
type FormValues = z.infer<typeof schema>;
|
||||
@@ -30,12 +41,23 @@ interface Settings {
|
||||
commission_percent: string;
|
||||
max_cancel_hours_before: string;
|
||||
appointment_reminder_hours: string;
|
||||
payment_test_mode: string;
|
||||
mellat_terminal_id: string;
|
||||
mellat_username: string;
|
||||
mellat_password: string;
|
||||
sep_terminal_id: string;
|
||||
sms_provider: string;
|
||||
kavenegar_api_key: string;
|
||||
kavenegar_sender: string;
|
||||
sms_price_rials: string;
|
||||
}
|
||||
|
||||
// ── Component ─────────────────────────────────────────────────────────────
|
||||
|
||||
export default function SettingsPage() {
|
||||
const qc = useQueryClient();
|
||||
const [showMellatPassword, setShowMellatPassword] = useState(false);
|
||||
const [showKavenegarKey, setShowKavenegarKey] = useState(false);
|
||||
|
||||
const { data, isLoading } = useQuery({
|
||||
queryKey: ['admin-settings'],
|
||||
@@ -51,6 +73,7 @@ export default function SettingsPage() {
|
||||
handleSubmit,
|
||||
reset,
|
||||
watch,
|
||||
setValue,
|
||||
formState: { errors, isDirty },
|
||||
} = useForm<FormValues>({ resolver: zodResolver(schema) });
|
||||
|
||||
@@ -63,6 +86,15 @@ export default function SettingsPage() {
|
||||
commission_percent: settings.commission_percent ?? '0',
|
||||
max_cancel_hours_before: settings.max_cancel_hours_before ?? '24',
|
||||
appointment_reminder_hours: settings.appointment_reminder_hours ?? '2',
|
||||
payment_test_mode: settings.payment_test_mode ?? '0',
|
||||
mellat_terminal_id: settings.mellat_terminal_id ?? '',
|
||||
mellat_username: settings.mellat_username ?? '',
|
||||
mellat_password: settings.mellat_password ?? '',
|
||||
sep_terminal_id: settings.sep_terminal_id ?? '',
|
||||
sms_provider: settings.sms_provider ?? 'kavenegar',
|
||||
kavenegar_api_key: settings.kavenegar_api_key ?? '',
|
||||
kavenegar_sender: settings.kavenegar_sender ?? '',
|
||||
sms_price_rials: settings.sms_price_rials ?? '500',
|
||||
});
|
||||
}
|
||||
}, [settings, reset]);
|
||||
@@ -75,7 +107,8 @@ export default function SettingsPage() {
|
||||
},
|
||||
});
|
||||
|
||||
const commissionEnabled = watch('commission_enabled') === '1';
|
||||
const commissionEnabled = watch('commission_enabled') === '1';
|
||||
const paymentTestMode = watch('payment_test_mode') === '1';
|
||||
|
||||
const onSubmit = (values: FormValues) => {
|
||||
mutation.mutate(values);
|
||||
@@ -167,22 +200,11 @@ export default function SettingsPage() {
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
|
||||
{/* toggle فعال/غیرفعال */}
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 12, cursor: 'pointer' }}>
|
||||
<div style={{ position: 'relative', width: 44, height: 24, flexShrink: 0 }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={commissionEnabled}
|
||||
onChange={(e) => {
|
||||
const target = e.target;
|
||||
const input = document.querySelector<HTMLInputElement>('input[name="commission_enabled"]');
|
||||
if (input) {
|
||||
input.value = target.checked ? '1' : '0';
|
||||
// Trigger react-hook-form change
|
||||
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
}
|
||||
}}
|
||||
style={{ opacity: 0, width: 0, height: 0, position: 'absolute' }}
|
||||
/>
|
||||
<input type="hidden" {...register('commission_enabled')} />
|
||||
<input type="hidden" {...register('commission_enabled')} />
|
||||
<div
|
||||
style={{ position: 'relative', width: 44, height: 24, flexShrink: 0, cursor: 'pointer' }}
|
||||
onClick={() => setValue('commission_enabled', commissionEnabled ? '0' : '1', { shouldDirty: true })}
|
||||
>
|
||||
<div style={{
|
||||
width: 44, height: 24, borderRadius: 12,
|
||||
background: commissionEnabled ? 'var(--primary)' : 'var(--border)',
|
||||
@@ -281,6 +303,136 @@ export default function SettingsPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* درگاه پرداخت */}
|
||||
<div className="card card-pad">
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: '1.25rem' }}>
|
||||
<div className="ico" style={{ background: '#fef3c7', color: '#d97706', width: 36, height: 36, borderRadius: 10 }}>
|
||||
<span style={{ fontSize: 16 }}>💳</span>
|
||||
</div>
|
||||
<h3 style={{ fontSize: 15 }}>درگاه پرداخت</h3>
|
||||
</div>
|
||||
|
||||
{/* حالت تست */}
|
||||
<div style={{ marginBottom: '1.25rem', padding: '12px 16px', borderRadius: 'var(--r-sm)', background: paymentTestMode ? '#fef9c3' : 'var(--surface)', border: `1px solid ${paymentTestMode ? '#fbbf24' : 'var(--border)'}` }}>
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 12, cursor: 'pointer' }}>
|
||||
<input type="hidden" {...register('payment_test_mode')} />
|
||||
<div
|
||||
style={{ position: 'relative', width: 44, height: 24, flexShrink: 0, cursor: 'pointer' }}
|
||||
onClick={() => setValue('payment_test_mode', paymentTestMode ? '0' : '1', { shouldDirty: true })}
|
||||
>
|
||||
<div style={{ width: 44, height: 24, borderRadius: 12, background: paymentTestMode ? '#f59e0b' : 'var(--border)', transition: 'background .2s', position: 'relative' }}>
|
||||
<div style={{ position: 'absolute', top: 2, width: 20, height: 20, borderRadius: '50%', background: '#fff', transition: 'right .2s', right: paymentTestMode ? 2 : 22, boxShadow: '0 1px 3px rgba(0,0,0,.2)' }} />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ fontSize: 14, fontWeight: 600 }}>{paymentTestMode ? 'حالت تست فعال' : 'حالت تست غیرفعال'}</div>
|
||||
<div className="muted" style={{ fontSize: 12, marginTop: 2 }}>
|
||||
{paymentTestMode ? 'همه پرداختها از درگاه آزمایشی رد میشوند (پول واقعی کسر نمیشود)' : 'پرداختها از درگاه واقعی انجام میشوند'}
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{/* Mellat */}
|
||||
<div style={{ marginBottom: '1.25rem' }}>
|
||||
<div style={{ fontSize: 13.5, fontWeight: 600, marginBottom: '0.75rem', display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<span style={{ width: 8, height: 8, borderRadius: '50%', background: '#6366f1', display: 'inline-block' }} />
|
||||
درگاه ملت (Mellat)
|
||||
</div>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: '0.75rem' }}>
|
||||
<div>
|
||||
<label style={{ fontSize: 12.5, fontWeight: 500, display: 'block', marginBottom: 4 }}>شناسه پایانه</label>
|
||||
<input {...register('mellat_terminal_id')} dir="ltr" placeholder="12345678"
|
||||
style={{ width: '100%', height: 38, padding: '0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13, boxSizing: 'border-box' }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style={{ fontSize: 12.5, fontWeight: 500, display: 'block', marginBottom: 4 }}>نام کاربری</label>
|
||||
<input {...register('mellat_username')} dir="ltr" placeholder="username"
|
||||
style={{ width: '100%', height: 38, padding: '0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13, boxSizing: 'border-box' }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style={{ fontSize: 12.5, fontWeight: 500, display: 'block', marginBottom: 4 }}>رمز عبور</label>
|
||||
<div style={{ position: 'relative' }}>
|
||||
<input {...register('mellat_password')} type={showMellatPassword ? 'text' : 'password'} dir="ltr" placeholder="••••••••"
|
||||
style={{ width: '100%', height: 38, padding: '0 36px 0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13, boxSizing: 'border-box' }}
|
||||
/>
|
||||
<button type="button" onClick={() => setShowMellatPassword(p => !p)}
|
||||
style={{ position: 'absolute', left: 10, top: '50%', transform: 'translateY(-50%)', background: 'none', border: 'none', cursor: 'pointer', color: 'var(--muted)', fontSize: 12 }}>
|
||||
{showMellatPassword ? 'پنهان' : 'نمایش'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* SEP */}
|
||||
<div>
|
||||
<div style={{ fontSize: 13.5, fontWeight: 600, marginBottom: '0.75rem', display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<span style={{ width: 8, height: 8, borderRadius: '50%', background: '#10b981', display: 'inline-block' }} />
|
||||
درگاه سپ (SEP)
|
||||
</div>
|
||||
<div style={{ maxWidth: 240 }}>
|
||||
<label style={{ fontSize: 12.5, fontWeight: 500, display: 'block', marginBottom: 4 }}>شناسه پایانه</label>
|
||||
<input {...register('sep_terminal_id')} dir="ltr" placeholder="12345678"
|
||||
style={{ width: '100%', height: 38, padding: '0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13, boxSizing: 'border-box' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* تنظیمات پیامک */}
|
||||
<div className="card card-pad">
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: '1.25rem' }}>
|
||||
<div className="ico" style={{ background: '#ede9fe', color: '#7c3aed', width: 36, height: 36, borderRadius: 10 }}>
|
||||
<span style={{ fontSize: 16 }}>📱</span>
|
||||
</div>
|
||||
<h3 style={{ fontSize: 15 }}>تنظیمات پیامک (SMS)</h3>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '1rem' }}>
|
||||
<div>
|
||||
<label style={{ fontSize: 12.5, fontWeight: 500, display: 'block', marginBottom: 4 }}>سرویس پیامک</label>
|
||||
<select {...register('sms_provider')}
|
||||
style={{ width: '100%', height: 38, padding: '0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13 }}>
|
||||
<option value="kavenegar">کاوهنگار</option>
|
||||
<option value="rangineh">رنگینه</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label style={{ fontSize: 12.5, fontWeight: 500, display: 'block', marginBottom: 4 }}>قیمت هر پیامک (ریال)</label>
|
||||
<input {...register('sms_price_rials')} type="number" min={0} dir="ltr" placeholder="500"
|
||||
style={{ width: '100%', height: 38, padding: '0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13, boxSizing: 'border-box' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ marginTop: '1rem' }}>
|
||||
<div style={{ fontSize: 13, fontWeight: 600, marginBottom: '0.75rem' }}>تنظیمات کاوهنگار</div>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '0.75rem' }}>
|
||||
<div>
|
||||
<label style={{ fontSize: 12.5, fontWeight: 500, display: 'block', marginBottom: 4 }}>API Key</label>
|
||||
<div style={{ position: 'relative' }}>
|
||||
<input {...register('kavenegar_api_key')} type={showKavenegarKey ? 'text' : 'password'} dir="ltr" placeholder="••••••••••••••••"
|
||||
style={{ width: '100%', height: 38, padding: '0 36px 0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13, boxSizing: 'border-box' }}
|
||||
/>
|
||||
<button type="button" onClick={() => setShowKavenegarKey(p => !p)}
|
||||
style={{ position: 'absolute', left: 10, top: '50%', transform: 'translateY(-50%)', background: 'none', border: 'none', cursor: 'pointer', color: 'var(--muted)', fontSize: 12 }}>
|
||||
{showKavenegarKey ? 'پنهان' : 'نمایش'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label style={{ fontSize: 12.5, fontWeight: 500, display: 'block', marginBottom: 4 }}>شماره فرستنده</label>
|
||||
<input {...register('kavenegar_sender')} dir="ltr" placeholder="10008664"
|
||||
style={{ width: '100%', height: 38, padding: '0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13, boxSizing: 'border-box' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* دکمه ذخیره */}
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 10 }}>
|
||||
<button
|
||||
@@ -293,6 +445,15 @@ export default function SettingsPage() {
|
||||
commission_percent: settings.commission_percent,
|
||||
max_cancel_hours_before: settings.max_cancel_hours_before,
|
||||
appointment_reminder_hours: settings.appointment_reminder_hours,
|
||||
payment_test_mode: settings.payment_test_mode,
|
||||
mellat_terminal_id: settings.mellat_terminal_id,
|
||||
mellat_username: settings.mellat_username,
|
||||
mellat_password: settings.mellat_password,
|
||||
sep_terminal_id: settings.sep_terminal_id,
|
||||
sms_provider: settings.sms_provider,
|
||||
kavenegar_api_key: settings.kavenegar_api_key,
|
||||
kavenegar_sender: settings.kavenegar_sender,
|
||||
sms_price_rials: settings.sms_price_rials,
|
||||
})}
|
||||
disabled={!isDirty || mutation.isPending}
|
||||
>
|
||||
|
||||
@@ -21,7 +21,7 @@ const templateSchema = z.object({
|
||||
});
|
||||
type TemplateFormData = z.infer<typeof templateSchema>;
|
||||
|
||||
type Tab = 'samples' | 'pending' | 'logs';
|
||||
type Tab = 'samples' | 'pending' | 'logs' | 'post-visit-review';
|
||||
|
||||
const STATUS_LOG_META: Record<string, { label: string; cls: string }> = {
|
||||
sent: { label: 'ارسال شده', cls: 'green' },
|
||||
@@ -38,6 +38,8 @@ export default function SmsPage() {
|
||||
const [rejectReason, setRejectReason] = useState('');
|
||||
const [addOpen, setAddOpen] = useState(false);
|
||||
const [deleteTarget, setDeleteTarget] = useState<SmsTemplate | null>(null);
|
||||
const [postVisitRejectId, setPostVisitRejectId] = useState<number | null>(null);
|
||||
const [postVisitRejectReason, setPostVisitRejectReason] = useState('');
|
||||
const limit = 15;
|
||||
|
||||
const sampleTemplatesQuery = useQuery({
|
||||
@@ -114,6 +116,33 @@ 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 }> }>>({
|
||||
queryKey: ['sms-post-visit-review'],
|
||||
queryFn: () => api.get('/api/v1/admin/sms/settings/review'),
|
||||
enabled: activeTab === 'post-visit-review',
|
||||
});
|
||||
|
||||
const postVisitApproveMutation = useMutation({
|
||||
mutationFn: (id: number) => api.post(`/api/v1/admin/sms/settings/${id}/approve`, {}),
|
||||
onSuccess: () => {
|
||||
toast.success('متن پیامک تأیید شد');
|
||||
qc.invalidateQueries({ queryKey: ['sms-post-visit-review'] });
|
||||
},
|
||||
onError: (err: Error) => toast.error(err.message),
|
||||
});
|
||||
|
||||
const postVisitRejectMutation = useMutation({
|
||||
mutationFn: ({ id, reason }: { id: number; reason: string }) =>
|
||||
api.post(`/api/v1/admin/sms/settings/${id}/reject`, { reason }),
|
||||
onSuccess: () => {
|
||||
toast.success('متن پیامک رد شد');
|
||||
setPostVisitRejectId(null);
|
||||
setPostVisitRejectReason('');
|
||||
qc.invalidateQueries({ queryKey: ['sms-post-visit-review'] });
|
||||
},
|
||||
onError: (err: Error) => toast.error(err.message),
|
||||
});
|
||||
|
||||
const templateColumns: Column<SmsTemplate>[] = [
|
||||
{ key: 'name', header: 'نام', render: (t) => <b>{t.name}</b> },
|
||||
{
|
||||
@@ -153,9 +182,12 @@ export default function SmsPage() {
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const postVisitPendingCount = (postVisitReviewQuery.data?.data as any)?.data?.length ?? 0;
|
||||
|
||||
const TABS: { key: Tab; label: string; badge?: number }[] = [
|
||||
{ key: 'samples', label: 'قالبهای نمونه' },
|
||||
{ key: 'pending', label: 'در انتظار تأیید', badge: pendingCount },
|
||||
{ key: 'post-visit-review', label: 'متن پیامک ویزیت', badge: postVisitPendingCount },
|
||||
{ key: 'logs', label: 'لاگهای ارسال' },
|
||||
];
|
||||
|
||||
@@ -262,6 +294,48 @@ export default function SmsPage() {
|
||||
</>
|
||||
)}
|
||||
|
||||
{activeTab === 'post-visit-review' && (
|
||||
<div style={{ padding: '16px' }}>
|
||||
{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 }}>
|
||||
متنی برای بررسی وجود ندارد
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
|
||||
{((postVisitReviewQuery.data?.data as any)?.data ?? []).map((item: any) => (
|
||||
<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>
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<button
|
||||
className="btn primary sm"
|
||||
disabled={postVisitApproveMutation.isPending}
|
||||
onClick={() => postVisitApproveMutation.mutate(item.id)}
|
||||
>
|
||||
<CheckIcon style={{ width: 14 }} /> تأیید
|
||||
</button>
|
||||
<button
|
||||
className="btn danger sm"
|
||||
onClick={() => { setPostVisitRejectId(item.id); setPostVisitRejectReason(''); }}
|
||||
>
|
||||
<XMarkIcon style={{ width: 14 }} /> رد
|
||||
</button>
|
||||
</div>
|
||||
</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_pending}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'logs' && (
|
||||
<>
|
||||
<DataTable<SmsLog>
|
||||
@@ -328,6 +402,28 @@ export default function SmsPage() {
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
<Modal open={!!postVisitRejectId} title="رد متن پیامک ویزیت"
|
||||
onClose={() => { setPostVisitRejectId(null); setPostVisitRejectReason(''); }}
|
||||
footer={
|
||||
<>
|
||||
<button onClick={() => { setPostVisitRejectId(null); setPostVisitRejectReason(''); }} className="btn ghost sm">لغو</button>
|
||||
<button
|
||||
onClick={() => postVisitRejectId && postVisitRejectMutation.mutate({ id: postVisitRejectId, reason: postVisitRejectReason })}
|
||||
disabled={!postVisitRejectReason || postVisitRejectMutation.isPending}
|
||||
className="btn danger sm">
|
||||
رد کردن
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="form-row">
|
||||
<label>دلیل رد</label>
|
||||
<textarea value={postVisitRejectReason} onChange={(e) => setPostVisitRejectReason(e.target.value)}
|
||||
rows={4} placeholder="دلیل رد را بنویسید..."
|
||||
className="input" style={{ resize: 'none', height: 'auto' }} />
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!approveTarget}
|
||||
title="تأیید قالب پیامک"
|
||||
|
||||
@@ -218,14 +218,40 @@ export default function SmsWalletPage() {
|
||||
</div>
|
||||
|
||||
{currentSettings.post_visit_enabled && (
|
||||
<div className="field" style={{ marginBottom: 0, marginRight: 4 }}>
|
||||
<label style={{ fontSize: 13 }}>متن پیامک</label>
|
||||
<textarea
|
||||
value={currentSettings.post_visit_text ?? ''}
|
||||
onChange={(e) => setLocalSettings({ ...currentSettings, post_visit_text: e.target.value })}
|
||||
rows={3}
|
||||
placeholder="ممنون از مراجعه شما..."
|
||||
/>
|
||||
<div style={{ marginRight: 4 }}>
|
||||
<div className="field" style={{ marginBottom: 8 }}>
|
||||
<label style={{ fontSize: 13 }}>متن پیامک</label>
|
||||
<textarea
|
||||
value={currentSettings.post_visit_text_pending ?? currentSettings.post_visit_text ?? ''}
|
||||
onChange={(e) => setLocalSettings({ ...currentSettings, post_visit_text: e.target.value })}
|
||||
rows={3}
|
||||
placeholder="ممنون از مراجعه شما..."
|
||||
/>
|
||||
</div>
|
||||
{/* وضعیت تأیید */}
|
||||
{currentSettings.post_visit_text_status === 'pending' && (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '8px 12px', borderRadius: 8, background: '#fef9c3', border: '1px solid #fbbf24', fontSize: 12.5, marginBottom: 8 }}>
|
||||
<span style={{ fontSize: 14 }}>⏳</span>
|
||||
<span>متن پیامک در انتظار تأیید ادمین است</span>
|
||||
</div>
|
||||
)}
|
||||
{currentSettings.post_visit_text_status === 'approved' && (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '8px 12px', borderRadius: 8, background: '#dcfce7', border: '1px solid #86efac', fontSize: 12.5, marginBottom: 8 }}>
|
||||
<span style={{ fontSize: 14 }}>✅</span>
|
||||
<span>متن پیامک تأیید شده و فعال است</span>
|
||||
</div>
|
||||
)}
|
||||
{currentSettings.post_visit_text_status === 'rejected' && (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '8px 12px', borderRadius: 8, background: '#fee2e2', border: '1px solid #fca5a5', fontSize: 12.5, marginBottom: 8 }}>
|
||||
<span style={{ fontSize: 14 }}>❌</span>
|
||||
<div>
|
||||
<div>متن پیامک رد شد</div>
|
||||
{currentSettings.post_visit_text_reject_reason && (
|
||||
<div style={{ color: '#dc2626', marginTop: 2 }}>دلیل: {currentSettings.post_visit_text_reject_reason}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -392,6 +392,9 @@ export interface SmsSettings {
|
||||
reminder_hours_before: number;
|
||||
post_visit_enabled: boolean;
|
||||
post_visit_text: string | null;
|
||||
post_visit_text_pending?: string | null;
|
||||
post_visit_text_status?: 'none' | 'pending' | 'approved' | 'rejected';
|
||||
post_visit_text_reject_reason?: string | null;
|
||||
}
|
||||
|
||||
export interface PatientRecord {
|
||||
|
||||
Reference in New Issue
Block a user