From 24461ffc6a6bccc25ca3cec9347a7d83f8d0f852 Mon Sep 17 00:00:00 2001 From: baslani Date: Tue, 18 Nov 2025 14:36:38 +0330 Subject: [PATCH] implemented ComputePaymentForm modal --- .../RowActions/Forms/ComputePaymentForm.jsx | 130 +++++++++++++++++- 1 file changed, 128 insertions(+), 2 deletions(-) diff --git a/src/components/dashboard/inquiryPrivacy/privacy-office/RowActions/Forms/ComputePaymentForm.jsx b/src/components/dashboard/inquiryPrivacy/privacy-office/RowActions/Forms/ComputePaymentForm.jsx index d40f0a3..b49c61a 100644 --- a/src/components/dashboard/inquiryPrivacy/privacy-office/RowActions/Forms/ComputePaymentForm.jsx +++ b/src/components/dashboard/inquiryPrivacy/privacy-office/RowActions/Forms/ComputePaymentForm.jsx @@ -1,3 +1,129 @@ -export default function ComputePaymentForm({ mutate }) { - return
ComputePaymentForm
; +import { Box, Button, DialogActions, FormControl, InputLabel, MenuItem, Select, TextField } from "@mui/material"; +import { useEffect, useState } from "react"; +import { Controller, useForm, useWatch } from "react-hook-form"; + +export default function ComputePaymentForm({ mutate, onClose }) { + const [isSubmitting, setIsSubmitting] = useState(false); + + const price_fee = 1; // TODO: Replace with value from .env + + const { control, handleSubmit, setValue } = useForm({ + defaultValues: { + expert_description: "", + traffic: "", + road_type: "", + position: "", + final_area_space: "", + payment_amount: "", + }, + }); + + // Watch dependent fields for recalculation + const { traffic, road_type, position, final_area_space } = useWatch({ + control, + }); + + useEffect(() => { + const t = parseFloat(traffic || ""); + const r = parseFloat(road_type || ""); + const p = parseFloat(position || ""); + const area = parseFloat(final_area_space || ""); + + if (t && r && p && area) { + const result = t * r * p * area * price_fee; + setValue("payment_amount", result.toString()); + } else { + setValue("payment_amount", ""); + } + }, [traffic, road_type, position, final_area_space, price_fee, setValue]); + + const onSubmit = (data) => { + console.log(data); + setIsSubmitting(true); + mutate(); + onClose(); + }; + + return ( + + + ( + + ترافیک + + + )} + /> + + ( + + نوع راه + + + )} + /> + + + + ( + + موقعیت اقتصادی + + + )} + /> + + ( + + )} + /> + + + ( + + )} + /> + + } + /> + + + + + + + ); }