feat: warehouse place number editing
This commit is contained in:
@@ -232,6 +232,7 @@ export type { EditMessageResponse } from './models/EditMessageResponse';
|
|||||||
export type { EditMessageSchema } from './models/EditMessageSchema';
|
export type { EditMessageSchema } from './models/EditMessageSchema';
|
||||||
export type { EditPlaceRequest } from './models/EditPlaceRequest';
|
export type { EditPlaceRequest } from './models/EditPlaceRequest';
|
||||||
export type { EditPlaceResponse } from './models/EditPlaceResponse';
|
export type { EditPlaceResponse } from './models/EditPlaceResponse';
|
||||||
|
export type { EditPlaceSchema } from './models/EditPlaceSchema';
|
||||||
export type { EditPlaceTypeRequest } from './models/EditPlaceTypeRequest';
|
export type { EditPlaceTypeRequest } from './models/EditPlaceTypeRequest';
|
||||||
export type { EditPlaceTypeResponse } from './models/EditPlaceTypeResponse';
|
export type { EditPlaceTypeResponse } from './models/EditPlaceTypeResponse';
|
||||||
export type { FinishPauseByShiftIdResponse } from './models/FinishPauseByShiftIdResponse';
|
export type { FinishPauseByShiftIdResponse } from './models/FinishPauseByShiftIdResponse';
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
/* istanbul ignore file */
|
/* istanbul ignore file */
|
||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import type { PlaceSchema } from './PlaceSchema';
|
import type { EditPlaceSchema } from './EditPlaceSchema';
|
||||||
export type EditPlaceRequest = {
|
export type EditPlaceRequest = {
|
||||||
place: PlaceSchema;
|
place: EditPlaceSchema;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
11
src/client/models/EditPlaceSchema.ts
Normal file
11
src/client/models/EditPlaceSchema.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/* generated using openapi-typescript-codegen -- do not edit */
|
||||||
|
/* istanbul ignore file */
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
export type EditPlaceSchema = {
|
||||||
|
parentId: (number | null);
|
||||||
|
placeTypeId: number;
|
||||||
|
id: number;
|
||||||
|
number: number;
|
||||||
|
};
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { PlaceSchema } from "../../../../../../client";
|
import { PlaceSchema } from "../../../../../../client";
|
||||||
import { IconPlaylistAdd, IconQrcode, IconTrash } from "@tabler/icons-react";
|
import { IconEdit, IconPlaylistAdd, IconQrcode, IconTrash } from "@tabler/icons-react";
|
||||||
import { ActionIcon, Flex, Tooltip } from "@mantine/core";
|
import { ActionIcon, Flex, Tooltip } from "@mantine/core";
|
||||||
import React, { ReactNode } from "react";
|
import React, { ReactNode } from "react";
|
||||||
import { useWarehouseManagementTabContext } from "../../placeType/contexts/WarehouseManagementTabContext.tsx";
|
import { useWarehouseManagementTabContext } from "../../placeType/contexts/WarehouseManagementTabContext.tsx";
|
||||||
@@ -10,7 +10,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const PlaceActions = ({ place }: Props) => {
|
const PlaceActions = ({ place }: Props) => {
|
||||||
const { placeCrud, onCreatePlace, generateQrCode } = useWarehouseManagementTabContext();
|
const { placeCrud, onCreatePlace, onEditPlace, generateQrCode } = useWarehouseManagementTabContext();
|
||||||
|
|
||||||
const getAction = (
|
const getAction = (
|
||||||
label: string,
|
label: string,
|
||||||
@@ -46,6 +46,11 @@ const PlaceActions = ({ place }: Props) => {
|
|||||||
<IconPlaylistAdd />,
|
<IconPlaylistAdd />,
|
||||||
place.placeType.childCount === 0,
|
place.placeType.childCount === 0,
|
||||||
),
|
),
|
||||||
|
getAction(
|
||||||
|
"Редактировать",
|
||||||
|
() => onEditPlace(place),
|
||||||
|
<IconEdit />,
|
||||||
|
),
|
||||||
getAction(
|
getAction(
|
||||||
"Удалить",
|
"Удалить",
|
||||||
() => placeCrud.onDelete && placeCrud.onDelete(place),
|
() => placeCrud.onDelete && placeCrud.onDelete(place),
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { FlatPlaceTypeSchema } from "../../../../../../client";
|
import { FlatPlaceTypeSchema, PlaceTypeSchema } from "../../../../../../client";
|
||||||
import ObjectSelect, { ObjectSelectProps } from "../../../../../../components/ObjectSelect/ObjectSelect.tsx";
|
import ObjectSelect, { ObjectSelectProps } from "../../../../../../components/ObjectSelect/ObjectSelect.tsx";
|
||||||
|
|
||||||
type Props = Omit<
|
type Props = Omit<
|
||||||
ObjectSelectProps<FlatPlaceTypeSchema | null>,
|
ObjectSelectProps<FlatPlaceTypeSchema | PlaceTypeSchema | null>,
|
||||||
"getValueFn" | "getLabelFn"
|
"getValueFn" | "getLabelFn"
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { useCRUD } from "../../../../../../hooks/useCRUD.tsx";
|
import { useCRUD } from "../../../../../../hooks/useCRUD.tsx";
|
||||||
import { BasePlaceSchema, PlaceSchema, WmsService } from "../../../../../../client";
|
import { BasePlaceSchema, EditPlaceSchema, PlaceSchema, WmsService } from "../../../../../../client";
|
||||||
import { notifications } from "../../../../../../shared/lib/notifications.ts";
|
import { notifications } from "../../../../../../shared/lib/notifications.ts";
|
||||||
|
|
||||||
|
|
||||||
export type PlaceCrud = {
|
export type PlaceCrud = {
|
||||||
onCreate: (element: BasePlaceSchema) => void,
|
onCreate: (element: BasePlaceSchema) => void,
|
||||||
onDelete: (element: PlaceSchema) => void,
|
onDelete: (element: PlaceSchema) => void,
|
||||||
onChange: (element: PlaceSchema) => void
|
onChange: (element: EditPlaceSchema) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -14,8 +14,8 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const usePlacesCrud = ({ fetchPlaces }: Props): PlaceCrud => {
|
const usePlacesCrud = ({ fetchPlaces }: Props): PlaceCrud => {
|
||||||
return useCRUD<PlaceSchema, BasePlaceSchema>({
|
return useCRUD<EditPlaceSchema, BasePlaceSchema>({
|
||||||
onChange: (place: PlaceSchema) => {
|
onChange: (place: EditPlaceSchema) => {
|
||||||
WmsService.editPlace({
|
WmsService.editPlace({
|
||||||
requestBody: { place },
|
requestBody: { place },
|
||||||
})
|
})
|
||||||
@@ -26,7 +26,7 @@ const usePlacesCrud = ({ fetchPlaces }: Props): PlaceCrud => {
|
|||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
},
|
},
|
||||||
onDelete: (place: PlaceSchema) => {
|
onDelete: (place: EditPlaceSchema) => {
|
||||||
WmsService.deletePlace({
|
WmsService.deletePlace({
|
||||||
placeId: place.id,
|
placeId: place.id,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ContextModalProps } from "@mantine/modals";
|
import { ContextModalProps } from "@mantine/modals";
|
||||||
import { FlatPlaceTypeSchema, PlaceSchema } from "../../../../../../client";
|
import { EditPlaceSchema, FlatPlaceTypeSchema, PlaceSchema, PlaceTypeSchema } from "../../../../../../client";
|
||||||
import { Button, Stack } from "@mantine/core";
|
import { Button, NumberInput, Stack } from "@mantine/core";
|
||||||
import { useForm } from "@mantine/form";
|
import { useForm } from "@mantine/form";
|
||||||
import { PlaceCrud } from "../hooks/usePlacesCrud.tsx";
|
import { PlaceCrud } from "../hooks/usePlacesCrud.tsx";
|
||||||
import PlaceTypeSelect from "../components/PlaceTypeSelect.tsx";
|
import PlaceTypeSelect from "../components/PlaceTypeSelect.tsx";
|
||||||
@@ -8,11 +8,13 @@ import PlaceTypeSelect from "../components/PlaceTypeSelect.tsx";
|
|||||||
type Props = {
|
type Props = {
|
||||||
placeCrud: PlaceCrud;
|
placeCrud: PlaceCrud;
|
||||||
parent?: PlaceSchema;
|
parent?: PlaceSchema;
|
||||||
placeTypes: FlatPlaceTypeSchema[];
|
placeTypes?: FlatPlaceTypeSchema[];
|
||||||
|
element?: EditPlaceSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
type PlaceModalForm = {
|
type PlaceModalForm = {
|
||||||
placeType: PlaceSchema | null;
|
placeType: PlaceTypeSchema | null;
|
||||||
|
placeNumber: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PlaceModal = ({
|
const PlaceModal = ({
|
||||||
@@ -20,6 +22,7 @@ const PlaceModal = ({
|
|||||||
id,
|
id,
|
||||||
innerProps,
|
innerProps,
|
||||||
}: ContextModalProps<Props>) => {
|
}: ContextModalProps<Props>) => {
|
||||||
|
const isEditing = "element" in innerProps;
|
||||||
const { parent, placeCrud, placeTypes } = innerProps;
|
const { parent, placeCrud, placeTypes } = innerProps;
|
||||||
|
|
||||||
const closeModal = () => {
|
const closeModal = () => {
|
||||||
@@ -28,31 +31,54 @@ const PlaceModal = ({
|
|||||||
|
|
||||||
const initialValues: PlaceModalForm = {
|
const initialValues: PlaceModalForm = {
|
||||||
placeType: null,
|
placeType: null,
|
||||||
|
placeNumber: innerProps.element?.number ?? null,
|
||||||
};
|
};
|
||||||
const form = useForm<PlaceModalForm>({
|
const form = useForm<PlaceModalForm>({
|
||||||
initialValues,
|
initialValues,
|
||||||
validate: {
|
validate: {
|
||||||
placeType: placeType => !placeType && "Необходимо указать тип",
|
placeType: placeType => !isEditing && !placeType && "Необходимо указать тип",
|
||||||
|
placeNumber: placeNumber => isEditing && !placeNumber && "Необходимо ввести номер",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit = (values: PlaceModalForm) => {
|
const onSubmit = (values: PlaceModalForm) => {
|
||||||
if (!values.placeType) return;
|
if (isEditing) {
|
||||||
placeCrud.onCreate({
|
const place = innerProps.element!;
|
||||||
placeTypeId: values.placeType.id,
|
placeCrud.onChange({
|
||||||
parentId: parent?.id || null,
|
id: place.id,
|
||||||
});
|
placeTypeId: place.placeTypeId,
|
||||||
|
number: values.placeNumber!,
|
||||||
|
parentId: place.parentId,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (!values.placeType) return;
|
||||||
|
placeCrud.onCreate({
|
||||||
|
placeTypeId: values.placeType.id,
|
||||||
|
parentId: parent?.id || null,
|
||||||
|
});
|
||||||
|
}
|
||||||
closeModal();
|
closeModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={form.onSubmit(values => onSubmit(values))}>
|
<form onSubmit={form.onSubmit(values => onSubmit(values))}>
|
||||||
<Stack>
|
<Stack>
|
||||||
<PlaceTypeSelect
|
{!isEditing && (
|
||||||
label={"Тип места на складе"}
|
<PlaceTypeSelect
|
||||||
{...form.getInputProps("placeType")}
|
label={"Тип места на складе"}
|
||||||
data={placeTypes}
|
{...form.getInputProps("placeType")}
|
||||||
/>
|
data={placeTypes ?? []}
|
||||||
|
defaultValue={(form.getValues().placeType ?? "") as FlatPlaceTypeSchema & string}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isEditing && (
|
||||||
|
<NumberInput
|
||||||
|
label={"Номер места на складе"}
|
||||||
|
{...form.getInputProps("placeNumber")}
|
||||||
|
defaultValue={form.getValues().placeNumber ?? ""}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<Button variant={"default"} type={"submit"}>
|
<Button variant={"default"} type={"submit"}>
|
||||||
Сохранить
|
Сохранить
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { createContext, FC, useContext } from "react";
|
import React, { createContext, FC, useContext } from "react";
|
||||||
import { PlaceSchema, PlaceTypeSchema, WmsService } from "../../../../../../client";
|
import { EditPlaceSchema, PlaceSchema, PlaceTypeSchema, WmsService } from "../../../../../../client";
|
||||||
import usePlaceTypesList from "../hooks/usePlaceTypesList.tsx";
|
import usePlaceTypesList from "../hooks/usePlaceTypesList.tsx";
|
||||||
import usePlaceTypesCrud, { PlaceTypeCrud } from "../hooks/usePlaceTypesCrud.tsx";
|
import usePlaceTypesCrud, { PlaceTypeCrud } from "../hooks/usePlaceTypesCrud.tsx";
|
||||||
import usePlacesList from "../../place/hooks/usePlacesList.tsx";
|
import usePlacesList from "../../place/hooks/usePlacesList.tsx";
|
||||||
@@ -14,6 +14,7 @@ type WarehouseManagementTabContextState = {
|
|||||||
placeCrud: PlaceCrud;
|
placeCrud: PlaceCrud;
|
||||||
places: PlaceSchema[];
|
places: PlaceSchema[];
|
||||||
onCreatePlace: (place?: PlaceSchema) => void;
|
onCreatePlace: (place?: PlaceSchema) => void;
|
||||||
|
onEditPlace: (place?: EditPlaceSchema) => void;
|
||||||
generateQrCode: (place: PlaceSchema) => void;
|
generateQrCode: (place: PlaceSchema) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -59,6 +60,18 @@ const useWarehouseManagementTabContextState = () => {
|
|||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onEditPlace = (place?: EditPlaceSchema) => {
|
||||||
|
modals.openContextModal({
|
||||||
|
modal: "placeModal",
|
||||||
|
withCloseButton: false,
|
||||||
|
title: "Редактирование",
|
||||||
|
innerProps: {
|
||||||
|
placeCrud,
|
||||||
|
element: place,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const generateQrCode = (place: PlaceSchema) => {
|
const generateQrCode = (place: PlaceSchema) => {
|
||||||
modals.openContextModal({
|
modals.openContextModal({
|
||||||
modal: "selectPlaceQrType",
|
modal: "selectPlaceQrType",
|
||||||
@@ -78,6 +91,7 @@ const useWarehouseManagementTabContextState = () => {
|
|||||||
placeCrud,
|
placeCrud,
|
||||||
refetchPlaces,
|
refetchPlaces,
|
||||||
onCreatePlace,
|
onCreatePlace,
|
||||||
|
onEditPlace,
|
||||||
generateQrCode,
|
generateQrCode,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user