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