feat(currency): update currency display to toman in admin panel; implement conversion functions for rial to toman and vice versa
This commit is contained in:
@@ -11,7 +11,7 @@ import { toast } from 'sonner';
|
||||
import { api } from '../lib/api';
|
||||
import type { ApiResponse } from '../lib/api';
|
||||
import type { ServiceSection, ServiceItem, ClinicStaff } from '../types';
|
||||
import { formatRial } from '../lib/utils';
|
||||
import { formatRial, rialToToman, tomanToRial } from '../lib/utils';
|
||||
import Modal from '../components/ui/Modal';
|
||||
import PriceInput from '../components/ui/PriceInput';
|
||||
import ConfirmDialog from '../components/ui/ConfirmDialog';
|
||||
@@ -124,14 +124,22 @@ function ClinicServicesPageInner() {
|
||||
});
|
||||
|
||||
const createItem = useMutation({
|
||||
mutationFn: (body: ItemForm & { section_uuid: string }) => api.post('/api/v1/service-item', body),
|
||||
mutationFn: (body: ItemForm & { section_uuid: string }) => api.post('/api/v1/service-item', {
|
||||
...body,
|
||||
price_rials: tomanToRial(body.price_rials),
|
||||
insurance_price_rials: tomanToRial(body.insurance_price_rials ?? 0),
|
||||
}),
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['service-items', selectedSection?.uuid] }); setItemModal(null); itemForm.reset(); toast.success('سرویس ایجاد شد'); },
|
||||
onError: (e: any) => toast.error(e.message),
|
||||
});
|
||||
|
||||
const editItem = useMutation({
|
||||
mutationFn: ({ uuid, body }: { uuid: string; body: ItemForm }) =>
|
||||
api.patch(`/api/v1/service-item/${uuid}`, body),
|
||||
api.patch(`/api/v1/service-item/${uuid}`, {
|
||||
...body,
|
||||
price_rials: tomanToRial(body.price_rials),
|
||||
insurance_price_rials: tomanToRial(body.insurance_price_rials ?? 0),
|
||||
}),
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['service-items', selectedSection?.uuid] }); setItemModal(null); toast.success('سرویس ویرایش شد'); },
|
||||
onError: (e: any) => toast.error(e.message),
|
||||
});
|
||||
@@ -155,10 +163,10 @@ function ClinicServicesPageInner() {
|
||||
const openEditItem = (item: ServiceItem) => {
|
||||
itemForm.reset({
|
||||
name: item.name,
|
||||
price_rials: item.price_rials,
|
||||
price_rials: rialToToman(item.price_rials),
|
||||
staff_uuid: item.staff?.uuid ?? '',
|
||||
insurance_covered: item.insurance_covered ?? false,
|
||||
insurance_price_rials: item.insurance_price_rials ?? 0,
|
||||
insurance_price_rials: rialToToman(item.insurance_price_rials ?? 0),
|
||||
});
|
||||
setItemModal(item);
|
||||
};
|
||||
@@ -434,7 +442,7 @@ function ClinicServicesPageInner() {
|
||||
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
|
||||
<div>
|
||||
<label className="field-label">قیمت پایه (ریال) *</label>
|
||||
<label className="field-label">قیمت پایه (تومان) *</label>
|
||||
<div className="field">
|
||||
<PriceInput
|
||||
value={itemForm.watch('price_rials') ?? 0}
|
||||
@@ -488,7 +496,7 @@ function ClinicServicesPageInner() {
|
||||
|
||||
{itemForm.watch('insurance_covered') && (
|
||||
<div style={{ padding: '0 16px 16px', borderTop: '1px solid var(--border)', paddingTop: 14 }}>
|
||||
<label className="field-label">قیمت تقریبی با بیمه (ریال)</label>
|
||||
<label className="field-label">قیمت تقریبی با بیمه (تومان)</label>
|
||||
<div className="field" style={{ background: 'var(--surface)' }}>
|
||||
<PriceInput
|
||||
value={itemForm.watch('insurance_price_rials') ?? 0}
|
||||
|
||||
Reference in New Issue
Block a user