Feature/amiriis azmayesh
This commit is contained in:
@@ -47,7 +47,7 @@ const validationSchema = object({
|
|||||||
|
|
||||||
const CandUAzmayesh = ({ setOpen, mutate, updateInfo, rowId }) => {
|
const CandUAzmayesh = ({ setOpen, mutate, updateInfo, rowId }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const requestServer = useRequest({ auth: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
||||||
const [tabState, setTabState] = useState(0);
|
const [tabState, setTabState] = useState(0);
|
||||||
const [mapBoxData, setMapBoxData] = useState(updateInfo ? { lat: updateInfo.lat, lng: updateInfo.lng } : null);
|
const [mapBoxData, setMapBoxData] = useState(updateInfo ? { lat: updateInfo.lat, lng: updateInfo.lng } : null);
|
||||||
@@ -90,7 +90,7 @@ const CandUAzmayesh = ({ setOpen, mutate, updateInfo, rowId }) => {
|
|||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
setValue,
|
setValue,
|
||||||
formState: { isSubmitting, errors, touchedFields },
|
formState: { isSubmitting, errors },
|
||||||
} = useForm({ defaultValues, resolver: yupResolver(validationSchema), mode: "onBlur" });
|
} = useForm({ defaultValues, resolver: yupResolver(validationSchema), mode: "onBlur" });
|
||||||
|
|
||||||
const onSubmit = async (data) => {
|
const onSubmit = async (data) => {
|
||||||
@@ -113,8 +113,7 @@ const CandUAzmayesh = ({ setOpen, mutate, updateInfo, rowId }) => {
|
|||||||
formData.append("report_date", moment(new Date(data.report_date)).format("YYYY-MM-DD"));
|
formData.append("report_date", moment(new Date(data.report_date)).format("YYYY-MM-DD"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const url = updateInfo ? `${UPDATE_AZMAYESH}/${rowId}` : CREATE_AZMAYESH;
|
await requestServer(updateInfo ? `${UPDATE_AZMAYESH}/${rowId}` : CREATE_AZMAYESH, "post", {
|
||||||
await requestServer(url, "post", {
|
|
||||||
data: formData,
|
data: formData,
|
||||||
});
|
});
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { GET_AZMAYESH_LIST } from "@/core/utils/routes";
|
|||||||
import CandUAzmayesh from "@/components/dashboard/azmayesh/Forms/CandUAzmayesh";
|
import CandUAzmayesh from "@/components/dashboard/azmayesh/Forms/CandUAzmayesh";
|
||||||
|
|
||||||
const AzmayeshUpdate = ({ rowId, mutate }) => {
|
const AzmayeshUpdate = ({ rowId, mutate }) => {
|
||||||
const requestServer = useRequest({ auth: true });
|
const requestServer = useRequest();
|
||||||
const [openUpdateDialog, setOpenUpdateDialog] = useState(false);
|
const [openUpdateDialog, setOpenUpdateDialog] = useState(false);
|
||||||
const [updateInfo, setUpdateInfo] = useState(null);
|
const [updateInfo, setUpdateInfo] = useState(null);
|
||||||
const [loadingOpen, setLoadingOpen] = useState(false);
|
const [loadingOpen, setLoadingOpen] = useState(false);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import DeleteIcon from "@mui/icons-material/Delete";
|
|||||||
import { DELETE_AZMAYESH } from "@/core/utils/routes";
|
import { DELETE_AZMAYESH } from "@/core/utils/routes";
|
||||||
|
|
||||||
const DeleteAzmayesh = ({ rowId, mutate }) => {
|
const DeleteAzmayesh = ({ rowId, mutate }) => {
|
||||||
const requestServer = useRequest({ auth: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
|
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { useTheme } from "@emotion/react";
|
|||||||
import CandUSampleOfAzmayesh from "@/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Forms/CandUSampleOfAzmayesh";
|
import CandUSampleOfAzmayesh from "@/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Forms/CandUSampleOfAzmayesh";
|
||||||
|
|
||||||
const AddSampleToAzmayesh = ({ azmayeshTypeId, mutate, rowId }) => {
|
const AddSampleToAzmayesh = ({ azmayeshTypeId, mutate, rowId }) => {
|
||||||
const requestServer = useRequest({ auth: true });
|
const requestServer = useRequest();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
||||||
const [sampleInfo, setSampleInfo] = useState(null);
|
const [sampleInfo, setSampleInfo] = useState(null);
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ const CandUSampleOfAzmayesh = ({
|
|||||||
isUpdate,
|
isUpdate,
|
||||||
azmayesh_id,
|
azmayesh_id,
|
||||||
}) => {
|
}) => {
|
||||||
const requestServer = useRequest({ auth: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = async () => {
|
||||||
const data = {};
|
const data = {};
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
@@ -27,17 +27,20 @@ const CandUSampleOfAzmayesh = ({
|
|||||||
data[key] = value;
|
data[key] = value;
|
||||||
});
|
});
|
||||||
formData.append("data", JSON.stringify(data));
|
formData.append("data", JSON.stringify(data));
|
||||||
requestServer(isUpdate ? `${UPDATE_SAMPLE_OF_AZMAYESH}/${rowId}` : `${ADD_SAMPLE_TO_AZMAYESH}`, "post", {
|
try {
|
||||||
data: formData,
|
await requestServer(
|
||||||
})
|
isUpdate ? `${UPDATE_SAMPLE_OF_AZMAYESH}/${rowId}` : `${ADD_SAMPLE_TO_AZMAYESH}`,
|
||||||
.then(() => {
|
"post",
|
||||||
mutate();
|
{
|
||||||
})
|
data: formData,
|
||||||
.catch(() => {})
|
}
|
||||||
.finally(() => {
|
);
|
||||||
setOpenSampleDialog(false);
|
mutate();
|
||||||
setIsSubmitting(false);
|
setOpenSampleDialog(false);
|
||||||
});
|
setIsSubmitting(false);
|
||||||
|
} catch (error) {
|
||||||
|
setIsSubmitting(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const CandUSampleOfAzmayesh = ({
|
|||||||
isUpdate,
|
isUpdate,
|
||||||
azmayesh_id,
|
azmayesh_id,
|
||||||
}) => {
|
}) => {
|
||||||
const requestServer = useRequest({ auth: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import DeleteIcon from "@mui/icons-material/Delete";
|
|||||||
import { DELETE_SAMPLE_LIST } from "@/core/utils/routes";
|
import { DELETE_SAMPLE_LIST } from "@/core/utils/routes";
|
||||||
|
|
||||||
const DeleteSample = ({ rowId, mutate }) => {
|
const DeleteSample = ({ rowId, mutate }) => {
|
||||||
const requestServer = useRequest({ auth: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
|
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import CandUSampleOfAzmayesh from "@/components/dashboard/azmayesh/RowActions/Sh
|
|||||||
import EditIcon from "@mui/icons-material/Edit";
|
import EditIcon from "@mui/icons-material/Edit";
|
||||||
|
|
||||||
const UpdateSample = ({ azmayeshTypeId, mutate, rowId, azmayesh_id }) => {
|
const UpdateSample = ({ azmayeshTypeId, mutate, rowId, azmayesh_id }) => {
|
||||||
const requestServer = useRequest({ auth: true });
|
const requestServer = useRequest();
|
||||||
const [sampleInfo, setSampleInfo] = useState(null);
|
const [sampleInfo, setSampleInfo] = useState(null);
|
||||||
const [openUpdateSampleDialog, setOpenUpdateSampleDialog] = useState(false);
|
const [openUpdateSampleDialog, setOpenUpdateSampleDialog] = useState(false);
|
||||||
const [defaultValues, setDefaultValues] = useState({});
|
const [defaultValues, setDefaultValues] = useState({});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { GET_AZMAYESH_SAMPLE_FIELDS } from "@/core/utils/routes";
|
|||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
|
|
||||||
const ShowSampleOfAzmayesh = ({ rowData }) => {
|
const ShowSampleOfAzmayesh = ({ rowData }) => {
|
||||||
const requestServer = useRequest({ auth: true });
|
const requestServer = useRequest();
|
||||||
const [openShowSampleDialog, setOpenShowSampleDialog] = useState(false);
|
const [openShowSampleDialog, setOpenShowSampleDialog] = useState(false);
|
||||||
const [sampleInfo, setSampleInfo] = useState(null);
|
const [sampleInfo, setSampleInfo] = useState(null);
|
||||||
const handleGetSampleFields = () => {
|
const handleGetSampleFields = () => {
|
||||||
|
|||||||
@@ -42,9 +42,8 @@ const validationSchema = object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const FormAndRequest = ({ setOpen, mutate, rowId, updateInfo }) => {
|
const FormAndRequest = ({ setOpen, mutate, rowId, updateInfo }) => {
|
||||||
const requestServer = useRequest({ auth: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const [selectedListItem, setSelectedListItem] = useState(null);
|
const [selectedListItem, setSelectedListItem] = useState(null);
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
@@ -68,7 +67,7 @@ const FormAndRequest = ({ setOpen, mutate, rowId, updateInfo }) => {
|
|||||||
handleSubmit,
|
handleSubmit,
|
||||||
setValue,
|
setValue,
|
||||||
watch,
|
watch,
|
||||||
formState: { errors },
|
formState: { errors, isSubmitting },
|
||||||
} = useForm({ defaultValues, resolver: yupResolver(validationSchema), mode: "onBlur" });
|
} = useForm({ defaultValues, resolver: yupResolver(validationSchema), mode: "onBlur" });
|
||||||
|
|
||||||
const { fields, append, remove } = useFieldArray({
|
const { fields, append, remove } = useFieldArray({
|
||||||
@@ -90,25 +89,22 @@ const FormAndRequest = ({ setOpen, mutate, rowId, updateInfo }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = async (data) => {
|
const onSubmit = async (data) => {
|
||||||
setIsSubmitting(true);
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("name", data.name);
|
formData.append("name", data.name);
|
||||||
data.fields.map((field, index) => {
|
data.fields.map((field, index) => {
|
||||||
formData.append(`fields[${index}][name]`, field.name);
|
formData.append(`fields[${index}][name]`, field.name);
|
||||||
formData.append(`fields[${index}][unit]`, field.unit);
|
if (field.unit !== "") formData.append(`fields[${index}][unit]`, field.unit);
|
||||||
formData.append(`fields[${index}][type]`, field.type);
|
formData.append(`fields[${index}][type]`, field.type);
|
||||||
if (field.options.length !== 0) formData.append(`fields[${index}][option]`, JSON.stringify(field.options));
|
if (field.options.length !== 0) formData.append(`fields[${index}][option]`, JSON.stringify(field.options));
|
||||||
});
|
});
|
||||||
|
|
||||||
requestServer(updateInfo ? `${UPDATE_AZMAYESH_TYPE}/${rowId}` : ADD_AZMAYESH_TYPE, "post", {
|
try {
|
||||||
data: formData,
|
await requestServer(updateInfo ? `${UPDATE_AZMAYESH_TYPE}/${rowId}` : ADD_AZMAYESH_TYPE, "post", {
|
||||||
})
|
data: formData,
|
||||||
.then(() => {
|
});
|
||||||
mutate();
|
mutate();
|
||||||
handleClose();
|
handleClose();
|
||||||
})
|
} catch (error) {}
|
||||||
.catch(() => {})
|
|
||||||
.finally(() => setIsSubmitting(false));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { useState } from "react";
|
|||||||
import { DELETE_AZMAYESH_TYPE_LIST } from "@/core/utils/routes";
|
import { DELETE_AZMAYESH_TYPE_LIST } from "@/core/utils/routes";
|
||||||
|
|
||||||
const DeleteAzmayeshType = ({ rowId, mutate }) => {
|
const DeleteAzmayeshType = ({ rowId, mutate }) => {
|
||||||
const requestServer = useRequest({ auth: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
|
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import useRequest from "@/lib/hooks/useRequest";
|
|||||||
import CandUAzmayeshType from "@/components/dashboard/azmayeshType/Forms/CandUAzmayeshType";
|
import CandUAzmayeshType from "@/components/dashboard/azmayeshType/Forms/CandUAzmayeshType";
|
||||||
|
|
||||||
const UpdateAzmayeshType = ({ rowId, mutate }) => {
|
const UpdateAzmayeshType = ({ rowId, mutate }) => {
|
||||||
const requestServer = useRequest({ auth: true });
|
const requestServer = useRequest();
|
||||||
const [openUpdateDialog, setOpenUpdateDialog] = useState(false);
|
const [openUpdateDialog, setOpenUpdateDialog] = useState(false);
|
||||||
const [updateInfo, setUpdateInfo] = useState(null);
|
const [updateInfo, setUpdateInfo] = useState(null);
|
||||||
const [loadingOpen, setLoadingOpen] = useState(false);
|
const [loadingOpen, setLoadingOpen] = useState(false);
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ const InputType = ({ itemInfo, defaultValues, setDefaultValues }) => {
|
|||||||
[itemInfo.id]: value,
|
[itemInfo.id]: value,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
console.log(itemInfo);
|
|
||||||
|
|
||||||
const label = itemInfo.unit ? `${itemInfo.name} (${itemInfo.unit})` : itemInfo.name;
|
const label = itemInfo.unit ? `${itemInfo.name} (${itemInfo.unit})` : itemInfo.name;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user