main
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
||||
TextField,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useFormik } from "formik";
|
||||
import { DatePicker } from "@mui/x-date-pickers";
|
||||
import moment from "moment";
|
||||
@@ -36,7 +36,6 @@ import PersianDate from "persian-date";
|
||||
import axios from "axios";
|
||||
import { LabelField } from "../../../components/label-field/LabelField";
|
||||
import { SPACING } from "../../../data/spacing";
|
||||
import { checkPathStartsWith } from "../../../utils/checkPathStartsWith";
|
||||
|
||||
export const StewardAllocationToGuild = ({
|
||||
item,
|
||||
@@ -80,9 +79,6 @@ export const StewardAllocationToGuild = ({
|
||||
const [selectedDate1, setSelectedDate1] = useState(
|
||||
moment(new Date()).format("YYYY-MM-DD")
|
||||
);
|
||||
const selectedSubUser = useSelector(
|
||||
(state) => state.userSlice.selectedSubUser
|
||||
);
|
||||
|
||||
const handleChange = (event) => {
|
||||
setValue(event.target.value);
|
||||
@@ -164,10 +160,13 @@ export const StewardAllocationToGuild = ({
|
||||
return transformedData;
|
||||
}, []);
|
||||
|
||||
const updateCalendarData = useCallback((dataArray) => {
|
||||
const transformed = transformCalendarData(dataArray);
|
||||
setCalendarDayData(transformed);
|
||||
}, []);
|
||||
const updateCalendarData = useCallback(
|
||||
(dataArray) => {
|
||||
const transformed = transformCalendarData(dataArray);
|
||||
setCalendarDayData(transformed);
|
||||
},
|
||||
[transformCalendarData]
|
||||
);
|
||||
|
||||
const fetchCalendarData = useCallback(
|
||||
async (dateParam = selectedDate1) => {
|
||||
@@ -175,9 +174,6 @@ export const StewardAllocationToGuild = ({
|
||||
const response = await axios.get("/steward-remain-weight/", {
|
||||
params: {
|
||||
date: dateParam,
|
||||
role_key: checkPathStartsWith("steward")
|
||||
? selectedSubUser?.key
|
||||
: "",
|
||||
},
|
||||
});
|
||||
if (response.data) {
|
||||
@@ -195,7 +191,7 @@ export const StewardAllocationToGuild = ({
|
||||
console.error("Error fetching calendar data:", error);
|
||||
}
|
||||
},
|
||||
[selectedInventory, updateCalendarData, selectedDate1, selectedSubUser]
|
||||
[selectedInventory, updateCalendarData, selectedDate1]
|
||||
);
|
||||
|
||||
const [buyerData, setBuyerData] = useState({
|
||||
@@ -213,7 +209,7 @@ export const StewardAllocationToGuild = ({
|
||||
|
||||
useEffect(() => {
|
||||
fetchCalendarData(selectedDate1);
|
||||
}, [selectedDate1]);
|
||||
}, [fetchCalendarData, selectedDate1]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
@@ -229,41 +225,30 @@ export const StewardAllocationToGuild = ({
|
||||
setProductionDate(null);
|
||||
setSelectedDateAmount(null);
|
||||
}
|
||||
}, [selectedInventory, calendarRawData]);
|
||||
}, [selectedInventory, calendarRawData, updateCalendarData]);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(
|
||||
provincePolicyGetUploadImageService({
|
||||
role_key: checkPathStartsWith("steward") ? selectedSubUser?.key : "",
|
||||
})
|
||||
).then((r) => {
|
||||
dispatch(provincePolicyGetUploadImageService()).then((r) => {
|
||||
if (r.payload?.data) {
|
||||
setImageUploadLimit(r.payload.data.killHouseAllocation);
|
||||
}
|
||||
});
|
||||
|
||||
if (!editData) {
|
||||
dispatch(
|
||||
slaughterGetProductsService({
|
||||
role_key: checkPathStartsWith("steward") ? selectedSubUser?.key : "",
|
||||
})
|
||||
).then((r) => {
|
||||
dispatch(slaughterGetProductsService()).then((r) => {
|
||||
setProductData(r.payload.data);
|
||||
});
|
||||
if (!item) {
|
||||
dispatch(
|
||||
slaughterGetGuildsForAllocateService({
|
||||
free: value === "free" ? true : false,
|
||||
role_key: checkPathStartsWith("steward")
|
||||
? selectedSubUser?.key
|
||||
: "",
|
||||
})
|
||||
).then((r) => {
|
||||
setGuildsData(r.payload.data);
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [value, selectedSubUser?.key]);
|
||||
}, [dispatch, value]);
|
||||
|
||||
const validationSchema = Yup.object({
|
||||
mobile: Yup.string().when([], {
|
||||
@@ -350,11 +335,14 @@ export const StewardAllocationToGuild = ({
|
||||
}, [formik.values.price, formik.values.weight]);
|
||||
|
||||
const successSubmit = () => {
|
||||
dispatch(
|
||||
fetchSlaughterBroadcastAndProducts({
|
||||
role_key: checkPathStartsWith("steward") ? selectedSubUser?.key : "",
|
||||
})
|
||||
);
|
||||
dispatch(CLOSE_MODAL());
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(fetchSlaughterBroadcastAndProducts());
|
||||
dispatch(
|
||||
DRAWER({
|
||||
right: false,
|
||||
@@ -366,13 +354,6 @@ export const StewardAllocationToGuild = ({
|
||||
fetchApiData && fetchApiData(1);
|
||||
updateTable && updateTable();
|
||||
fetchData && fetchData(1);
|
||||
dispatch(CLOSE_MODAL());
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
};
|
||||
|
||||
const [dateRangeError, setDateRangeError] = useState(null);
|
||||
@@ -472,9 +453,13 @@ export const StewardAllocationToGuild = ({
|
||||
<FormControlLabel
|
||||
value="own"
|
||||
control={<Radio />}
|
||||
label="اختصاصی"
|
||||
label="صنوف اختصاصی"
|
||||
/>
|
||||
<FormControlLabel
|
||||
value="free"
|
||||
control={<Radio />}
|
||||
label="صنوف آزاد"
|
||||
/>
|
||||
<FormControlLabel value="free" control={<Radio />} label="آزاد" />
|
||||
</RadioGroup>
|
||||
</FormControl>
|
||||
</LabelField>
|
||||
@@ -492,7 +477,9 @@ export const StewardAllocationToGuild = ({
|
||||
? guildsData.map((i) => {
|
||||
return {
|
||||
data: i,
|
||||
label: `${i?.guildsName} ${i?.user?.fullname} (${i?.user?.mobile})`,
|
||||
label: `${i?.steward ? "مباشر" : "صنف"} ${
|
||||
i?.guildsName
|
||||
} ${i?.user?.fullname} (${i?.user?.mobile})`,
|
||||
};
|
||||
})
|
||||
: []
|
||||
@@ -501,8 +488,10 @@ export const StewardAllocationToGuild = ({
|
||||
setBuyerData({
|
||||
item: value?.data,
|
||||
key: value?.data?.key,
|
||||
allocationType: "steward_guild",
|
||||
buyerType: "Guild",
|
||||
allocationType: value?.data?.steward
|
||||
? "steward_steward"
|
||||
: "steward_guild",
|
||||
buyerType: value?.data?.steward ? "Steward" : "Guild",
|
||||
});
|
||||
formik.setFieldValue("mobile", value?.data?.user?.mobile);
|
||||
formik.setFieldTouched("mobile", true, false);
|
||||
@@ -513,7 +502,7 @@ export const StewardAllocationToGuild = ({
|
||||
}
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField fullWidth {...params} label="انتخاب صنف" />
|
||||
<TextField fullWidth {...params} label="انتخاب مباشر / صنف" />
|
||||
)}
|
||||
/>
|
||||
</Grid>
|
||||
@@ -538,7 +527,7 @@ export const StewardAllocationToGuild = ({
|
||||
checked={changeMobile}
|
||||
onChange={() => setChangeMobile(!changeMobile)}
|
||||
/>
|
||||
از این قسمت میتوانید تلفن صنف را ویرایش کنید.
|
||||
از این قسمت میتوانید تلفن مباشر/صنف را ویرایش کنید.
|
||||
</Typography>
|
||||
|
||||
{buyerData?.key && changeMobile && (
|
||||
@@ -786,21 +775,31 @@ export const StewardAllocationToGuild = ({
|
||||
weight_of_carcasses: formik.values.weight,
|
||||
amount: formik.values.price,
|
||||
total_amount: formik.values.wholePrice,
|
||||
role_key: checkPathStartsWith("steward")
|
||||
? selectedSubUser?.key || ""
|
||||
: "",
|
||||
distribution_type: "web",
|
||||
...(imageChanged && { image: formik.values.image }),
|
||||
};
|
||||
} else if (!editData) {
|
||||
req = {
|
||||
seller_type: sellerType,
|
||||
buyer_type: "Guild",
|
||||
guild_key: buyerData?.item?.key,
|
||||
buyer_type: buyerData?.buyerType,
|
||||
guild_key:
|
||||
buyerData?.buyerType === "Guild"
|
||||
? buyerData?.item?.key
|
||||
: null,
|
||||
steward_key:
|
||||
buyerData?.buyerType === "Steward"
|
||||
? buyerData?.item?.key
|
||||
: null,
|
||||
kill_house_key:
|
||||
buyerData?.buyerType === "KillHouse"
|
||||
? buyerData?.item?.key
|
||||
: null,
|
||||
cold_house_key: coldHouseKey || null,
|
||||
product_key: coldHouseKey ? null : productKey.key,
|
||||
type: "manual",
|
||||
allocation_type: coldHouseKey ? "ColdHouse" : "steward_guild",
|
||||
allocation_type: coldHouseKey
|
||||
? "ColdHouse"
|
||||
: buyerData?.allocationType,
|
||||
number_of_carcasses: 0,
|
||||
weight_of_carcasses: formik.values.weight,
|
||||
sell_type: sellType,
|
||||
@@ -811,9 +810,6 @@ export const StewardAllocationToGuild = ({
|
||||
quota: selectedInventory,
|
||||
date: selectedDate1,
|
||||
production_date: productionDate,
|
||||
role_key: checkPathStartsWith("steward")
|
||||
? selectedSubUser?.key || ""
|
||||
: "",
|
||||
distribution_type: "web",
|
||||
...(buyerData?.item?.user?.mobile !== formik.values.mobile
|
||||
? { interface_number: formik.values.mobile }
|
||||
@@ -831,9 +827,6 @@ export const StewardAllocationToGuild = ({
|
||||
number_of_carcasses: 0,
|
||||
weight_of_carcasses: formik.values.weight,
|
||||
amount: formik.values.price,
|
||||
role_key: checkPathStartsWith("steward")
|
||||
? selectedSubUser?.key || ""
|
||||
: "",
|
||||
total_amount: formik.values.wholePrice,
|
||||
distribution_type: "web",
|
||||
...(imageChanged && { image: formik.values.image }),
|
||||
|
||||
Reference in New Issue
Block a user