fix: Fix station create page
All checks were successful
release-tag / release-image (push) Successful in 2m16s

This commit is contained in:
2025-05-25 23:16:33 +03:00
parent b1a4edc136
commit db5e9d9fc4
8 changed files with 565 additions and 416 deletions

View File

@ -96,6 +96,26 @@ export const StationEdit = observer(() => {
},
});
const directions = [
{
label: "Прямой",
value: true,
},
{
label: "Обратный",
value: false,
},
];
const directionContent = watch("direction");
const [routeDirection, setRouteDirection] = useState(false);
useEffect(() => {
if (directionContent) {
setRouteDirection(directionContent);
}
}, [directionContent]);
useEffect(() => {
if (stationData[language as keyof typeof stationData]?.name) {
setValue("name", stationData[language as keyof typeof stationData]?.name);
@ -172,17 +192,6 @@ export const StationEdit = observer(() => {
},
});
useEffect(() => {
const latitude = getValues("latitude");
const longitude = getValues("longitude");
if (latitude && longitude) {
setCoordinatesPreview({
latitude: latitude,
longitude: longitude,
});
}
}, [getValues]);
return (
<Edit saveButtonProps={saveButtonProps}>
<Box
@ -217,20 +226,29 @@ export const StationEdit = observer(() => {
label={"Системное название *"}
name="system_name"
/>
<Controller
name="direction" // boolean
control={control}
defaultValue={false}
render={({ field }: { field: any }) => (
<FormControlLabel
label="Прямой маршрут?"
control={
<Checkbox
{...field}
checked={field.value}
onChange={(e) => field.onChange(e.target.checked)}
/>
}
<input
type="hidden"
{...register("direction", { value: routeDirection })}
/>
<Autocomplete
options={directions}
value={directions.find((el) => el.value == routeDirection)}
onChange={(_, element) => {
if (element) {
setValue("direction", element.value);
setRouteDirection(element.value);
}
}}
renderInput={(params) => (
<TextField
{...params}
label="Прямой/обратный маршрут"
margin="normal"
variant="outlined"
error={!!errors.direction}
helperText={(errors as any)?.direction?.message}
required
/>
)}
/>