build and format
This commit is contained in:
@@ -1,93 +1,93 @@
|
||||
"use client";
|
||||
import { GET_RAHDARANS_LIST_SEARCH } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
import { Autocomplete, CircularProgress, TextField } from "@mui/material";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
const RahdarNameOrCode = ({ title = "راهدار", rahdarsName, setRahdarsName, error, multiple = true }) => {
|
||||
const [inputValue, setInputValue] = useState(""); // مدیریت مقدار تایپشده
|
||||
const [options, setOptions] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const requestServer = useRequest();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchRahdarNames = (inputValue, controller) => {
|
||||
if ((inputValue || "").length < 3) {
|
||||
setOptions([]);
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
requestServer(`${GET_RAHDARANS_LIST_SEARCH}?search=${inputValue}`, "get", {
|
||||
requestOptions: { signal: controller.signal },
|
||||
})
|
||||
.then((response) => {
|
||||
const combinedArray = rahdarsName
|
||||
? [...rahdarsName, ...response.data.data]
|
||||
: [...response.data.data];
|
||||
const uniqueArray = Array.from(new Map(combinedArray.map((item) => [item.id, item])).values());
|
||||
setOptions(uniqueArray || []);
|
||||
})
|
||||
.catch(() => {
|
||||
setOptions([]);
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
const controller = new AbortController();
|
||||
fetchRahdarNames(inputValue, controller);
|
||||
return () => controller.abort();
|
||||
}, [inputValue]);
|
||||
|
||||
return (
|
||||
<Autocomplete
|
||||
multiple={multiple} // قابلیت انتخاب چندگانه داینامیک
|
||||
value={rahdarsName} // آرایه موارد انتخابشده
|
||||
size="small"
|
||||
onChange={(event, newValue) => {
|
||||
setRahdarsName(multiple ? newValue || [] : newValue || null); // مدیریت حالت چندگانه و تکگانه
|
||||
}}
|
||||
inputValue={inputValue} // مقدار تایپشده
|
||||
onInputChange={(event, newInputValue) => {
|
||||
setInputValue(newInputValue || ""); // بهروزرسانی مقدار تایپشده
|
||||
}}
|
||||
options={options} // گزینههای موجود
|
||||
getOptionLabel={(option) => (typeof option === "string" ? option : `${option.code} - ${option.name}`)}
|
||||
isOptionEqualToValue={(option, value) => {
|
||||
if (!value) return false;
|
||||
if (value === "") return option.code === "";
|
||||
return option.code === (value?.code || value);
|
||||
}}
|
||||
loading={loading}
|
||||
loadingText={`درحال جستجوی ${title}`}
|
||||
noOptionsText={(inputValue || "").length < 3 ? `حداقل سه کاراکتر وارد کنید` : `${title}ی یافت نشد`}
|
||||
fullWidth
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
{...params}
|
||||
label={multiple ? `${title}ان` : `${title}`}
|
||||
fullWidth
|
||||
placeholder={
|
||||
multiple ? `نام یا کدملی ${title}ان را وارد کنید` : `نام یا کدملی ${title} را وارد کنید`
|
||||
}
|
||||
error={!!error}
|
||||
helperText={error?.message}
|
||||
InputLabelProps={{
|
||||
shrink: true,
|
||||
}}
|
||||
InputProps={{
|
||||
...params.InputProps,
|
||||
endAdornment: (
|
||||
<>
|
||||
{loading ? <CircularProgress size="25px" color="inherit" /> : null}
|
||||
{params.InputProps.endAdornment}
|
||||
</>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
export default RahdarNameOrCode;
|
||||
"use client";
|
||||
import { GET_RAHDARANS_LIST_SEARCH } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
import { Autocomplete, CircularProgress, TextField } from "@mui/material";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
const RahdarNameOrCode = ({ title = "راهدار", rahdarsName, setRahdarsName, error, multiple = true }) => {
|
||||
const [inputValue, setInputValue] = useState(""); // مدیریت مقدار تایپشده
|
||||
const [options, setOptions] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const requestServer = useRequest();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchRahdarNames = (inputValue, controller) => {
|
||||
if ((inputValue || "").length < 3) {
|
||||
setOptions([]);
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
requestServer(`${GET_RAHDARANS_LIST_SEARCH}?search=${inputValue}`, "get", {
|
||||
requestOptions: { signal: controller.signal },
|
||||
})
|
||||
.then((response) => {
|
||||
const combinedArray = rahdarsName
|
||||
? [...rahdarsName, ...response.data.data]
|
||||
: [...response.data.data];
|
||||
const uniqueArray = Array.from(new Map(combinedArray.map((item) => [item.id, item])).values());
|
||||
setOptions(uniqueArray || []);
|
||||
})
|
||||
.catch(() => {
|
||||
setOptions([]);
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
const controller = new AbortController();
|
||||
fetchRahdarNames(inputValue, controller);
|
||||
return () => controller.abort();
|
||||
}, [inputValue]);
|
||||
|
||||
return (
|
||||
<Autocomplete
|
||||
multiple={multiple} // قابلیت انتخاب چندگانه داینامیک
|
||||
value={rahdarsName} // آرایه موارد انتخابشده
|
||||
size="small"
|
||||
onChange={(event, newValue) => {
|
||||
setRahdarsName(multiple ? newValue || [] : newValue || null); // مدیریت حالت چندگانه و تکگانه
|
||||
}}
|
||||
inputValue={inputValue} // مقدار تایپشده
|
||||
onInputChange={(event, newInputValue) => {
|
||||
setInputValue(newInputValue || ""); // بهروزرسانی مقدار تایپشده
|
||||
}}
|
||||
options={options} // گزینههای موجود
|
||||
getOptionLabel={(option) => (typeof option === "string" ? option : `${option.code} - ${option.name}`)}
|
||||
isOptionEqualToValue={(option, value) => {
|
||||
if (!value) return false;
|
||||
if (value === "") return option.code === "";
|
||||
return option.code === (value?.code || value);
|
||||
}}
|
||||
loading={loading}
|
||||
loadingText={`درحال جستجوی ${title}`}
|
||||
noOptionsText={(inputValue || "").length < 3 ? `حداقل سه کاراکتر وارد کنید` : `${title}ی یافت نشد`}
|
||||
fullWidth
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
{...params}
|
||||
label={multiple ? `${title}ان` : `${title}`}
|
||||
fullWidth
|
||||
placeholder={
|
||||
multiple ? `نام یا کدملی ${title}ان را وارد کنید` : `نام یا کدملی ${title} را وارد کنید`
|
||||
}
|
||||
error={!!error}
|
||||
helperText={error?.message}
|
||||
InputLabelProps={{
|
||||
shrink: true,
|
||||
}}
|
||||
InputProps={{
|
||||
...params.InputProps,
|
||||
endAdornment: (
|
||||
<>
|
||||
{loading ? <CircularProgress size="25px" color="inherit" /> : null}
|
||||
{params.InputProps.endAdornment}
|
||||
</>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
export default RahdarNameOrCode;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Box } from "@mui/material";
|
||||
|
||||
const TabPanel = (props) => {
|
||||
const { children, value, index } = props;
|
||||
return (
|
||||
<div role="tabpanel" hidden={value !== index}>
|
||||
{value === index && <Box>{children}</Box>}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
export default TabPanel;
|
||||
import { Box } from "@mui/material";
|
||||
|
||||
const TabPanel = (props) => {
|
||||
const { children, value, index } = props;
|
||||
return (
|
||||
<div role="tabpanel" hidden={value !== index}>
|
||||
{value === index && <Box>{children}</Box>}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
export default TabPanel;
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
import * as turf from "@turf/turf";
|
||||
|
||||
export const calculatePolygonMetrics = (coordinates, isLatLngOrder = true) => {
|
||||
if (!coordinates || coordinates.length < 3) {
|
||||
return { area: 0, sides: [], coordinates: [] };
|
||||
}
|
||||
|
||||
const geoCoords = isLatLngOrder
|
||||
? coordinates.map(([lat, lng]) => [lng, lat])
|
||||
: coordinates.map(([lng, lat]) => [lng, lat]);
|
||||
|
||||
if (
|
||||
geoCoords[0][0] !== geoCoords[geoCoords.length - 1][0] ||
|
||||
geoCoords[0][1] !== geoCoords[geoCoords.length - 1][1]
|
||||
) {
|
||||
geoCoords.push(geoCoords[0]);
|
||||
}
|
||||
|
||||
const polygon = turf.polygon([geoCoords]);
|
||||
|
||||
const area = turf.area(polygon);
|
||||
|
||||
const sides = [];
|
||||
for (let i = 0; i < geoCoords.length - 1; i++) {
|
||||
const line = turf.lineString([geoCoords[i], geoCoords[i + 1]]);
|
||||
const length = turf.length(line, { units: "meters" });
|
||||
sides.push(length);
|
||||
}
|
||||
|
||||
return {
|
||||
area,
|
||||
sides,
|
||||
coordinates: geoCoords,
|
||||
};
|
||||
};
|
||||
import * as turf from "@turf/turf";
|
||||
|
||||
export const calculatePolygonMetrics = (coordinates, isLatLngOrder = true) => {
|
||||
if (!coordinates || coordinates.length < 3) {
|
||||
return { area: 0, sides: [], coordinates: [] };
|
||||
}
|
||||
|
||||
const geoCoords = isLatLngOrder
|
||||
? coordinates.map(([lat, lng]) => [lng, lat])
|
||||
: coordinates.map(([lng, lat]) => [lng, lat]);
|
||||
|
||||
if (
|
||||
geoCoords[0][0] !== geoCoords[geoCoords.length - 1][0] ||
|
||||
geoCoords[0][1] !== geoCoords[geoCoords.length - 1][1]
|
||||
) {
|
||||
geoCoords.push(geoCoords[0]);
|
||||
}
|
||||
|
||||
const polygon = turf.polygon([geoCoords]);
|
||||
|
||||
const area = turf.area(polygon);
|
||||
|
||||
const sides = [];
|
||||
for (let i = 0; i < geoCoords.length - 1; i++) {
|
||||
const line = turf.lineString([geoCoords[i], geoCoords[i + 1]]);
|
||||
const length = turf.length(line, { units: "meters" });
|
||||
sides.push(length);
|
||||
}
|
||||
|
||||
return {
|
||||
area,
|
||||
sides,
|
||||
coordinates: geoCoords,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
export default function groupByEdareAxisStep(data) {
|
||||
return data.reduce((acc, item) => {
|
||||
const { edare_id, axis_type_id } = item;
|
||||
|
||||
if (!acc[edare_id]) acc[edare_id] = {};
|
||||
if (!acc[edare_id][axis_type_id]) acc[edare_id][axis_type_id] = {};
|
||||
|
||||
acc[edare_id][axis_type_id] = { ...item };
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
export default function groupByEdareAxisStep(data) {
|
||||
return data.reduce((acc, item) => {
|
||||
const { edare_id, axis_type_id } = item;
|
||||
|
||||
if (!acc[edare_id]) acc[edare_id] = {};
|
||||
if (!acc[edare_id][axis_type_id]) acc[edare_id][axis_type_id] = {};
|
||||
|
||||
acc[edare_id][axis_type_id] = { ...item };
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
export default function groupByProvinceAxisStep(data) {
|
||||
return data.reduce((acc, item) => {
|
||||
const { province_id, axis_type_id } = item;
|
||||
|
||||
if (!acc[province_id]) acc[province_id] = {};
|
||||
if (!acc[province_id][axis_type_id]) acc[province_id][axis_type_id] = {};
|
||||
|
||||
acc[province_id][axis_type_id] = { ...item };
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
export default function groupByProvinceAxisStep(data) {
|
||||
return data.reduce((acc, item) => {
|
||||
const { province_id, axis_type_id } = item;
|
||||
|
||||
if (!acc[province_id]) acc[province_id] = {};
|
||||
if (!acc[province_id][axis_type_id]) acc[province_id][axis_type_id] = {};
|
||||
|
||||
acc[province_id][axis_type_id] = { ...item };
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export const makeDateTime = (date, time) => {
|
||||
if (!date) return null;
|
||||
const d = new Date(date);
|
||||
if (time) {
|
||||
const t = new Date(time);
|
||||
d.setHours(t.getHours(), t.getMinutes(), 0, 0);
|
||||
}
|
||||
return d;
|
||||
};
|
||||
export const makeDateTime = (date, time) => {
|
||||
if (!date) return null;
|
||||
const d = new Date(date);
|
||||
if (time) {
|
||||
const t = new Date(time);
|
||||
d.setHours(t.getHours(), t.getMinutes(), 0, 0);
|
||||
}
|
||||
return d;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export const missionCategoryTypes = [
|
||||
{ id: 1, name_fa: "فعالیت روزانه" },
|
||||
{ id: 2, name_fa: "گشت راهداری" },
|
||||
// { id: 3, name_fa: "واکنش سریع" },
|
||||
];
|
||||
export const missionCategoryTypes = [
|
||||
{ id: 1, name_fa: "فعالیت روزانه" },
|
||||
{ id: 2, name_fa: "گشت راهداری" },
|
||||
// { id: 3, name_fa: "واکنش سریع" },
|
||||
];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export const missionRegions = [
|
||||
{ id: 1, name_fa: "داخل شهر" },
|
||||
{ id: 2, name_fa: "بیرون شهر - داخل محدوده" },
|
||||
{ id: 3, name_fa: "بیرون شهر - خارج محدوده" },
|
||||
];
|
||||
export const missionRegions = [
|
||||
{ id: 1, name_fa: "داخل شهر" },
|
||||
{ id: 2, name_fa: "بیرون شهر - داخل محدوده" },
|
||||
{ id: 3, name_fa: "بیرون شهر - خارج محدوده" },
|
||||
];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export const missionTypes = [
|
||||
{ id: 1, name_fa: "ساعتی" },
|
||||
{ id: 2, name_fa: "روزانه" },
|
||||
];
|
||||
export const missionTypes = [
|
||||
{ id: 1, name_fa: "ساعتی" },
|
||||
{ id: 2, name_fa: "روزانه" },
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user