diff --git a/assets/admin/components/FreeVisitPrice.tsx b/assets/admin/components/FreeVisitPrice.tsx new file mode 100644 index 00000000..4256c9a8 --- /dev/null +++ b/assets/admin/components/FreeVisitPrice.tsx @@ -0,0 +1,55 @@ +import { useEffect, useState } from 'react'; +import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; +import { toast } from 'sonner'; +import { api } from '../lib/api'; +import { formatRial } from '../lib/utils'; + +interface Pricing { free_visit_price_rials: number } + +export default function FreeVisitPrice() { + const qc = useQueryClient(); + const [value, setValue] = useState(''); + + const { data } = useQuery<{ data: Pricing }>({ + queryKey: ['insurance-pricing'], + queryFn: () => api.get('/api/v1/insurance-pricing'), + }); + const pricing = (data as any)?.data as Pricing | undefined; + + useEffect(() => { + if (pricing) setValue(String(pricing.free_visit_price_rials ?? 0)); + }, [pricing]); + + const saveMut = useMutation({ + mutationFn: () => api.put('/api/v1/insurance-pricing', { free_visit_price_rials: Number(value) || 0 }), + onSuccess: () => { + toast.success('قیمت ویزیت ذخیره شد'); + qc.invalidateQueries({ queryKey: ['insurance-pricing'] }); + }, + onError: (e: Error) => toast.error(e.message), + }); + + return ( +
+

قیمت ویزیت آزاد

+

+ مبلغ ویزیت بدون بیمه. در ثبت مراجعه، انتخاب بیمه درصد پوشش قرارداد را روی همین مبلغ اعمال می‌کند. +

+
+
+ + setValue(e.target.value)} + /> +
+ + {value !== '' && ( + {formatRial(Number(value) || 0)} + )} +
+
+ ); +} diff --git a/assets/admin/pages/InsurancePricingPage.tsx b/assets/admin/pages/InsurancePricingPage.tsx index 781dd643..2a97e665 100644 --- a/assets/admin/pages/InsurancePricingPage.tsx +++ b/assets/admin/pages/InsurancePricingPage.tsx @@ -1,13 +1,15 @@ import PageHeader from '../components/ui/PageHeader'; import TenantInsuranceContracts from '../components/TenantInsuranceContracts'; +import FreeVisitPrice from '../components/FreeVisitPrice'; export default function InsurancePricingPage() { return (
+
);