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:
@@ -2,7 +2,7 @@ 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';
|
||||
import { formatRial, rialToToman, tomanToRial } from '../lib/utils';
|
||||
|
||||
interface Pricing { free_visit_price_rials: number }
|
||||
|
||||
@@ -17,11 +17,11 @@ export default function FreeVisitPrice() {
|
||||
const pricing = (data as any)?.data as Pricing | undefined;
|
||||
|
||||
useEffect(() => {
|
||||
if (pricing) setValue(String(pricing.free_visit_price_rials ?? 0));
|
||||
if (pricing) setValue(String(rialToToman(pricing.free_visit_price_rials ?? 0)));
|
||||
}, [pricing]);
|
||||
|
||||
const saveMut = useMutation({
|
||||
mutationFn: () => api.put('/api/v1/insurance-pricing', { free_visit_price_rials: Number(value) || 0 }),
|
||||
mutationFn: () => api.put('/api/v1/insurance-pricing', { free_visit_price_rials: tomanToRial(Number(value) || 0) }),
|
||||
onSuccess: () => {
|
||||
toast.success('قیمت ویزیت ذخیره شد');
|
||||
qc.invalidateQueries({ queryKey: ['insurance-pricing'] });
|
||||
@@ -37,7 +37,7 @@ export default function FreeVisitPrice() {
|
||||
</p>
|
||||
<div style={{ display: 'flex', alignItems: 'flex-end', gap: 10 }}>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||
<label style={{ fontSize: 11.5, fontWeight: 600 }}>قیمت (ریال)</label>
|
||||
<label style={{ fontSize: 11.5, fontWeight: 600 }}>قیمت (تومان)</label>
|
||||
<input
|
||||
type="number" min={0} dir="ltr" className="input" style={{ width: 200 }}
|
||||
value={value} onChange={(e) => setValue(e.target.value)}
|
||||
@@ -47,7 +47,7 @@ export default function FreeVisitPrice() {
|
||||
{saveMut.isPending ? '...' : 'ذخیره'}
|
||||
</button>
|
||||
{value !== '' && (
|
||||
<span style={{ fontSize: 12, color: 'var(--text-3)', marginBottom: 8 }}>{formatRial(Number(value) || 0)}</span>
|
||||
<span style={{ fontSize: 12, color: 'var(--text-3)', marginBottom: 8 }}>{formatRial(tomanToRial(Number(value) || 0))}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user