feat: big major update
This commit is contained in:
@@ -36,7 +36,7 @@ export const NAVIGATION_ITEMS: {
|
||||
primary: [
|
||||
{
|
||||
id: "snapshots",
|
||||
label: "Снапшоты",
|
||||
label: "Экспорт",
|
||||
icon: GitBranch,
|
||||
path: "/snapshot",
|
||||
for_admin: true,
|
||||
@@ -124,6 +124,16 @@ export const NAVIGATION_ITEMS: {
|
||||
};
|
||||
|
||||
export const VEHICLE_TYPES = [
|
||||
{ label: "Трамвай", value: 1 },
|
||||
{ label: "Автобус", value: 3 },
|
||||
{ label: "Троллейбус", value: 2 },
|
||||
{ label: "Трамвай", value: 1 },
|
||||
{ label: "Электробус", value: 4 },
|
||||
{ label: "Электричка", value: 5 },
|
||||
{ label: "Вагон метро", value: 6 },
|
||||
{ label: "Вагон ЖД", value: 7 },
|
||||
];
|
||||
|
||||
export const VEHICLE_MODELS = [
|
||||
{ label: "71-431P «Довлатов»", value: "71-431P «Довлатов»" },
|
||||
{ label: "71-638M-02 «Альтаир»", value: "71-638M-02 «Альтаир»" },
|
||||
] as const;
|
||||
|
||||
@@ -33,3 +33,12 @@ export const generateDefaultMediaName = (
|
||||
|
||||
return `${objectName || "Название"}_${fileNameWithoutExtension}_Медиа`;
|
||||
};
|
||||
|
||||
/** Медиа-id считается пустым, если строка пустая или состоит только из нулей (с дефисами или без). */
|
||||
export const isMediaIdEmpty = (
|
||||
id: string | null | undefined
|
||||
): boolean => {
|
||||
if (id == null || id === "") return true;
|
||||
const digits = id.replace(/-/g, "");
|
||||
return digits === "" || /^0+$/.test(digits);
|
||||
};
|
||||
|
||||
@@ -51,7 +51,9 @@ interface UploadMediaDialogProps {
|
||||
| "carrier"
|
||||
| "country"
|
||||
| "vehicle"
|
||||
| "station";
|
||||
| "station"
|
||||
| "route"
|
||||
| "user";
|
||||
isArticle?: boolean;
|
||||
articleName?: string;
|
||||
initialFile?: File;
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
import { authInstance, languageInstance, languageStore } from "@shared";
|
||||
import {
|
||||
authInstance,
|
||||
languageInstance,
|
||||
languageStore,
|
||||
isMediaIdEmpty,
|
||||
} from "@shared";
|
||||
|
||||
export type Route = {
|
||||
route_name: string;
|
||||
@@ -9,6 +14,7 @@ export type Route = {
|
||||
center_longitude: number;
|
||||
governor_appeal: number;
|
||||
id: number;
|
||||
icon: string;
|
||||
path: number[][];
|
||||
rotate: number;
|
||||
route_direction: boolean;
|
||||
@@ -137,6 +143,7 @@ class RouteStore {
|
||||
center_longitude: "",
|
||||
governor_appeal: 0,
|
||||
id: 0,
|
||||
icon: "",
|
||||
path: [] as number[][],
|
||||
rotate: 0,
|
||||
route_direction: false,
|
||||
@@ -152,9 +159,15 @@ class RouteStore {
|
||||
};
|
||||
|
||||
editRoute = async (id: number) => {
|
||||
if (!this.editRouteData.video_preview) {
|
||||
if (
|
||||
!this.editRouteData.video_preview ||
|
||||
isMediaIdEmpty(this.editRouteData.video_preview)
|
||||
) {
|
||||
delete this.editRouteData.video_preview;
|
||||
}
|
||||
if (!this.editRouteData.icon || isMediaIdEmpty(this.editRouteData.icon)) {
|
||||
delete (this.editRouteData as any).icon;
|
||||
}
|
||||
const dataToSend: any = {
|
||||
...this.editRouteData,
|
||||
center_latitude: parseFloat(this.editRouteData.center_latitude),
|
||||
|
||||
@@ -7,6 +7,7 @@ export type User = {
|
||||
is_admin: boolean;
|
||||
name: string;
|
||||
password?: string;
|
||||
icon?: string;
|
||||
};
|
||||
|
||||
class UserStore {
|
||||
@@ -57,15 +58,23 @@ class UserStore {
|
||||
email: "",
|
||||
password: "",
|
||||
is_admin: false,
|
||||
icon: "",
|
||||
};
|
||||
|
||||
setCreateUserData = (
|
||||
name: string,
|
||||
email: string,
|
||||
password: string,
|
||||
is_admin: boolean
|
||||
is_admin: boolean,
|
||||
icon?: string
|
||||
) => {
|
||||
this.createUserData = { name, email, password, is_admin };
|
||||
this.createUserData = {
|
||||
name,
|
||||
email,
|
||||
password,
|
||||
is_admin,
|
||||
icon: icon ?? "",
|
||||
};
|
||||
};
|
||||
|
||||
createUser = async () => {
|
||||
@@ -73,7 +82,9 @@ class UserStore {
|
||||
if (this.users.data.length > 0) {
|
||||
id = this.users.data[this.users.data.length - 1].id + 1;
|
||||
}
|
||||
const response = await authInstance.post("/user", this.createUserData);
|
||||
const payload = { ...this.createUserData };
|
||||
if (!payload.icon) delete payload.icon;
|
||||
const response = await authInstance.post("/user", payload);
|
||||
|
||||
runInAction(() => {
|
||||
this.users.data.push({
|
||||
@@ -88,19 +99,29 @@ class UserStore {
|
||||
email: "",
|
||||
password: "",
|
||||
is_admin: false,
|
||||
icon: "",
|
||||
};
|
||||
|
||||
setEditUserData = (
|
||||
name: string,
|
||||
email: string,
|
||||
password: string,
|
||||
is_admin: boolean
|
||||
is_admin: boolean,
|
||||
icon?: string
|
||||
) => {
|
||||
this.editUserData = { name, email, password, is_admin };
|
||||
this.editUserData = {
|
||||
name,
|
||||
email,
|
||||
password,
|
||||
is_admin,
|
||||
icon: icon ?? "",
|
||||
};
|
||||
};
|
||||
|
||||
editUser = async (id: number) => {
|
||||
const response = await authInstance.patch(`/user/${id}`, this.editUserData);
|
||||
const payload = { ...this.editUserData };
|
||||
if (!payload.icon) delete payload.icon;
|
||||
const response = await authInstance.patch(`/user/${id}`, payload);
|
||||
|
||||
runInAction(() => {
|
||||
this.users.data = this.users.data.map((user) =>
|
||||
|
||||
@@ -9,6 +9,9 @@ export type Vehicle = {
|
||||
carrier_id: number;
|
||||
carrier: string;
|
||||
uuid?: string;
|
||||
model?: string;
|
||||
current_snapshot_uuid?: string;
|
||||
snapshot_update_blocked?: boolean;
|
||||
};
|
||||
device_status?: {
|
||||
device_uuid: string;
|
||||
@@ -65,14 +68,18 @@ class VehicleStore {
|
||||
tailNumber: string,
|
||||
type: number,
|
||||
carrier: string,
|
||||
carrierId: number
|
||||
carrierId: number,
|
||||
model?: string
|
||||
) => {
|
||||
const response = await languageInstance("ru").post("/vehicle", {
|
||||
const payload: Record<string, unknown> = {
|
||||
tail_number: tailNumber,
|
||||
type,
|
||||
carrier,
|
||||
carrier_id: carrierId,
|
||||
});
|
||||
};
|
||||
// TODO: когда будет бекенд — добавить model в payload и в ответ
|
||||
if (model != null && model !== "") payload.model = model;
|
||||
const response = await languageInstance("ru").post("/vehicle", payload);
|
||||
|
||||
runInAction(() => {
|
||||
this.vehicles.data.push({
|
||||
@@ -83,6 +90,7 @@ class VehicleStore {
|
||||
carrier_id: response.data.carrier_id,
|
||||
carrier: response.data.carrier,
|
||||
uuid: response.data.uuid,
|
||||
model: response.data.model ?? model,
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -93,11 +101,15 @@ class VehicleStore {
|
||||
type: number;
|
||||
carrier: string;
|
||||
carrier_id: number;
|
||||
model: string;
|
||||
snapshot_update_blocked: boolean;
|
||||
} = {
|
||||
tail_number: "",
|
||||
type: 0,
|
||||
carrier: "",
|
||||
carrier_id: 0,
|
||||
model: "",
|
||||
snapshot_update_blocked: false,
|
||||
};
|
||||
|
||||
setEditVehicleData = (data: {
|
||||
@@ -105,6 +117,8 @@ class VehicleStore {
|
||||
type: number;
|
||||
carrier: string;
|
||||
carrier_id: number;
|
||||
model?: string;
|
||||
snapshot_update_blocked?: boolean;
|
||||
}) => {
|
||||
this.editVehicleData = {
|
||||
...this.editVehicleData,
|
||||
@@ -119,27 +133,45 @@ class VehicleStore {
|
||||
type: number;
|
||||
carrier: string;
|
||||
carrier_id: number;
|
||||
model?: string;
|
||||
snapshot_update_blocked?: boolean;
|
||||
}
|
||||
) => {
|
||||
const response = await languageInstance("ru").patch(`/vehicle/${id}`, {
|
||||
const payload: Record<string, unknown> = {
|
||||
tail_number: data.tail_number,
|
||||
type: data.type,
|
||||
carrier: data.carrier,
|
||||
carrier_id: data.carrier_id,
|
||||
});
|
||||
};
|
||||
if (data.model != null && data.model !== "") payload.model = data.model;
|
||||
if (data.snapshot_update_blocked != null)
|
||||
payload.snapshot_update_blocked = data.snapshot_update_blocked;
|
||||
const response = await languageInstance("ru").patch(
|
||||
`/vehicle/${id}`,
|
||||
payload
|
||||
);
|
||||
|
||||
runInAction(() => {
|
||||
const updated = {
|
||||
...response.data,
|
||||
model: response.data.model ?? data.model,
|
||||
snapshot_update_blocked:
|
||||
response.data.snapshot_update_blocked ?? data.snapshot_update_blocked,
|
||||
};
|
||||
this.vehicle[id] = {
|
||||
vehicle: {
|
||||
...this.vehicle[id].vehicle,
|
||||
...response.data,
|
||||
...updated,
|
||||
},
|
||||
};
|
||||
this.vehicles.data = this.vehicles.data.map((vehicle) =>
|
||||
vehicle.vehicle.id === id
|
||||
? {
|
||||
...vehicle,
|
||||
...response.data,
|
||||
vehicle: {
|
||||
...vehicle.vehicle,
|
||||
...updated,
|
||||
},
|
||||
}
|
||||
: vehicle
|
||||
);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Modal as MuiModal, Typography, Box } from "@mui/material";
|
||||
import { Modal as MuiModal, Typography, Box, SxProps, Theme } from "@mui/material";
|
||||
|
||||
interface ModalProps {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
children: React.ReactNode;
|
||||
title?: string;
|
||||
sx?: SxProps<Theme>;
|
||||
}
|
||||
|
||||
const style = {
|
||||
@@ -19,7 +20,7 @@ const style = {
|
||||
borderRadius: 2,
|
||||
};
|
||||
|
||||
export const Modal = ({ open, onClose, children, title }: ModalProps) => {
|
||||
export const Modal = ({ open, onClose, children, title, sx }: ModalProps) => {
|
||||
return (
|
||||
<MuiModal
|
||||
open={open}
|
||||
@@ -27,7 +28,7 @@ export const Modal = ({ open, onClose, children, title }: ModalProps) => {
|
||||
aria-labelledby="modal-modal-title"
|
||||
aria-describedby="modal-modal-description"
|
||||
>
|
||||
<Box sx={style}>
|
||||
<Box sx={{ ...style, ...sx }}>
|
||||
{title && (
|
||||
<Typography
|
||||
id="modal-modal-title"
|
||||
|
||||
Reference in New Issue
Block a user