change some files
This commit is contained in:
@@ -9,16 +9,19 @@ import {
|
||||
FormHelperText,
|
||||
} from "@mui/material";
|
||||
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
|
||||
import { Form, FormikProps } from "formik";
|
||||
import { ErrorMessage, Form, FormikProps } from "formik";
|
||||
import BusinessIcon from "@mui/icons-material/Business";
|
||||
import LocationOnIcon from "@mui/icons-material/LocationOn";
|
||||
import LocalHospitalIcon from "@mui/icons-material/LocalHospital";
|
||||
import { useGetAllCenters } from "@/hooks/center.hook";
|
||||
import { useGetAllCenters, useSelectCenter } from "@/hooks/center.hook";
|
||||
import {
|
||||
RegistrationCenterFormProps,
|
||||
RegistrationCenterFormValues,
|
||||
} from "./RegistrationCenterForm";
|
||||
import { CenterItem } from "@/core/types";
|
||||
import { Warning } from "@mui/icons-material";
|
||||
import { toast } from "sonner";
|
||||
import { useEffect } from "react";
|
||||
|
||||
// تعریف اینترفیس برای تمیزی بیشتر
|
||||
interface InnerFormProps
|
||||
@@ -27,33 +30,26 @@ interface InnerFormProps
|
||||
RegistrationCenterFormProps {}
|
||||
|
||||
export default function InnerRegistrationCenterForm(props: InnerFormProps) {
|
||||
const { data } = useGetAllCenters();
|
||||
const { data,error } = useGetAllCenters();
|
||||
|
||||
const { mutateAsync, isPending } = useSelectCenter();
|
||||
const theme = useTheme();
|
||||
const isMobile = useMediaQuery(theme.breakpoints.down("md"));
|
||||
const handleBack = () => {
|
||||
props.update({ registrationCenter: props.values});
|
||||
props.update({ registrationCenter: props.values });
|
||||
props.setStep((prev) => Math.max(1, prev - 1));
|
||||
};
|
||||
|
||||
// منطق نمایش خطا
|
||||
const isSelectedCenterError =
|
||||
(props.touched.selectedCenter || props.submitCount > 0) &&
|
||||
!!props.errors.selectedCenter;
|
||||
|
||||
const handleCenterSelect = (center: CenterItem) => {
|
||||
props.setFieldValue("selectedCenter", center);
|
||||
props.setFieldTouched("selectedCenter", true, true); // فعال کردن حالت لمس شده
|
||||
};
|
||||
|
||||
const handleNext = async () => {
|
||||
// اگر مرحله اول است، فیلد را لمس کن تا اگر خالی بود خطا نشان دهد
|
||||
if (props.step === 1) {
|
||||
props.setFieldTouched("selectedCenter", true, true);
|
||||
}
|
||||
|
||||
// اعتبارسنجی دستی کل فرم
|
||||
const errors = await props.validateForm();
|
||||
|
||||
props.update({
|
||||
registrationCenter: props.values,
|
||||
});
|
||||
// اگر در گام فعلی خطایی وجود ندارد، برو مرحله بعد
|
||||
if (Object.keys(errors).length === 0) {
|
||||
if (props.step === 12) {
|
||||
@@ -62,8 +58,32 @@ export default function InnerRegistrationCenterForm(props: InnerFormProps) {
|
||||
props.setStep(props.step + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// try {
|
||||
// const applicant = await mutateAsync(props.values.selectedCenter?.id!);
|
||||
|
||||
// props.update({
|
||||
// applicantId: applicant.id,
|
||||
// registrationCenter: props.values,
|
||||
// });
|
||||
|
||||
// localStorage.setItem(
|
||||
// "applicationDraft",
|
||||
// JSON.stringify({
|
||||
// applicantId: applicant.id,
|
||||
// registrationCenter: props.values,
|
||||
// formStep: applicant.formStep,
|
||||
// }),
|
||||
// );
|
||||
|
||||
// props.setStep(2);
|
||||
// } catch (error: any) {
|
||||
// console.log(error)
|
||||
// toast.error(error?.message || "خطا در ثبت مرکز");
|
||||
// }
|
||||
};
|
||||
|
||||
|
||||
const renderCenterList = () => (
|
||||
<Box sx={{ width: "100%", gridColumn: "1 / -1" }}>
|
||||
<div className="w-full grid grid-cols-2 gap-4">
|
||||
@@ -78,7 +98,7 @@ export default function InnerRegistrationCenterForm(props: InnerFormProps) {
|
||||
borderRadius: "18px",
|
||||
border: isSelected
|
||||
? "2px solid #2563eb"
|
||||
: isSelectedCenterError
|
||||
: props.errors.selectedCenter
|
||||
? "2px solid #d32f2f"
|
||||
: "1px solid #e2e8f0",
|
||||
backgroundColor: isSelected ? "#eff6ff" : "#fff",
|
||||
@@ -106,6 +126,27 @@ export default function InnerRegistrationCenterForm(props: InnerFormProps) {
|
||||
{center.address}
|
||||
</Typography>
|
||||
</Box>
|
||||
{center.isUrgent && (
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: 1,
|
||||
mb: 1,
|
||||
}}
|
||||
>
|
||||
{/* <Warning sx={{ color: "red", fontSize: 14 }} /> */}
|
||||
<Typography
|
||||
sx={{
|
||||
fontWeight: 700,
|
||||
color: "red",
|
||||
fontSize: "14px",
|
||||
}}
|
||||
>
|
||||
استخدام فوري
|
||||
</Typography>
|
||||
</Box>
|
||||
)}
|
||||
{isSelected && <CheckCircleIcon sx={{ color: "#2563eb" }} />}
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -115,14 +156,7 @@ export default function InnerRegistrationCenterForm(props: InnerFormProps) {
|
||||
</div>
|
||||
|
||||
{/* نمایش پیام خطا به صورت تمیز زیر لیست */}
|
||||
{isSelectedCenterError && (
|
||||
<FormHelperText
|
||||
error
|
||||
sx={{ mt: 2, fontSize: "0.9rem", fontWeight: 600 }}
|
||||
>
|
||||
{props.errors.selectedCenter as string}
|
||||
</FormHelperText>
|
||||
)}
|
||||
<ErrorMessage name="selectedCenter" component={"div"} />
|
||||
</Box>
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user