feat: create user
This commit is contained in:
@@ -43,6 +43,8 @@ export type { CreatePayRateRequest } from './models/CreatePayRateRequest';
|
|||||||
export type { CreatePayRateResponse } from './models/CreatePayRateResponse';
|
export type { CreatePayRateResponse } from './models/CreatePayRateResponse';
|
||||||
export type { CreatePositionRequest } from './models/CreatePositionRequest';
|
export type { CreatePositionRequest } from './models/CreatePositionRequest';
|
||||||
export type { CreatePositionResponse } from './models/CreatePositionResponse';
|
export type { CreatePositionResponse } from './models/CreatePositionResponse';
|
||||||
|
export type { CreateUserRequest } from './models/CreateUserRequest';
|
||||||
|
export type { CreateUserResponse } from './models/CreateUserResponse';
|
||||||
export type { DealAddProductRequest } from './models/DealAddProductRequest';
|
export type { DealAddProductRequest } from './models/DealAddProductRequest';
|
||||||
export type { DealAddProductResponse } from './models/DealAddProductResponse';
|
export type { DealAddProductResponse } from './models/DealAddProductResponse';
|
||||||
export type { DealAddServiceRequest } from './models/DealAddServiceRequest';
|
export type { DealAddServiceRequest } from './models/DealAddServiceRequest';
|
||||||
@@ -156,6 +158,7 @@ export type { UpdateTimeTrackingRecordRequest } from './models/UpdateTimeTrackin
|
|||||||
export type { UpdateTimeTrackingRecordResponse } from './models/UpdateTimeTrackingRecordResponse';
|
export type { UpdateTimeTrackingRecordResponse } from './models/UpdateTimeTrackingRecordResponse';
|
||||||
export type { UpdateUserRequest } from './models/UpdateUserRequest';
|
export type { UpdateUserRequest } from './models/UpdateUserRequest';
|
||||||
export type { UpdateUserResponse } from './models/UpdateUserResponse';
|
export type { UpdateUserResponse } from './models/UpdateUserResponse';
|
||||||
|
export type { UserCreate } from './models/UserCreate';
|
||||||
export type { UserSchema } from './models/UserSchema';
|
export type { UserSchema } from './models/UserSchema';
|
||||||
export type { UserUpdate } from './models/UserUpdate';
|
export type { UserUpdate } from './models/UserUpdate';
|
||||||
export type { ValidationError } from './models/ValidationError';
|
export type { ValidationError } from './models/ValidationError';
|
||||||
|
|||||||
9
src/client/models/CreateUserRequest.ts
Normal file
9
src/client/models/CreateUserRequest.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/* generated using openapi-typescript-codegen -- do not edit */
|
||||||
|
/* istanbul ignore file */
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
import type { UserCreate } from './UserCreate';
|
||||||
|
export type CreateUserRequest = {
|
||||||
|
data: UserCreate;
|
||||||
|
};
|
||||||
|
|
||||||
9
src/client/models/CreateUserResponse.ts
Normal file
9
src/client/models/CreateUserResponse.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/* generated using openapi-typescript-codegen -- do not edit */
|
||||||
|
/* istanbul ignore file */
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
export type CreateUserResponse = {
|
||||||
|
ok: boolean;
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
|
||||||
19
src/client/models/UserCreate.ts
Normal file
19
src/client/models/UserCreate.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/* generated using openapi-typescript-codegen -- do not edit */
|
||||||
|
/* istanbul ignore file */
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
import type { PayRateSchema } from './PayRateSchema';
|
||||||
|
export type UserCreate = {
|
||||||
|
telegramId: number;
|
||||||
|
phoneNumber?: (string | null);
|
||||||
|
firstName: string;
|
||||||
|
secondName: string;
|
||||||
|
comment: string;
|
||||||
|
isAdmin: boolean;
|
||||||
|
isBlocked: boolean;
|
||||||
|
isDeleted: boolean;
|
||||||
|
roleKey: string;
|
||||||
|
payRate?: (PayRateSchema | null);
|
||||||
|
positionKey?: (string | null);
|
||||||
|
};
|
||||||
|
|
||||||
@@ -6,7 +6,6 @@ import type { PayRateSchema } from './PayRateSchema';
|
|||||||
import type { PositionSchema } from './PositionSchema';
|
import type { PositionSchema } from './PositionSchema';
|
||||||
import type { RoleSchema } from './RoleSchema';
|
import type { RoleSchema } from './RoleSchema';
|
||||||
export type UserSchema = {
|
export type UserSchema = {
|
||||||
id: number;
|
|
||||||
telegramId: number;
|
telegramId: number;
|
||||||
phoneNumber?: (string | null);
|
phoneNumber?: (string | null);
|
||||||
firstName: string;
|
firstName: string;
|
||||||
@@ -17,6 +16,7 @@ export type UserSchema = {
|
|||||||
isDeleted: boolean;
|
isDeleted: boolean;
|
||||||
roleKey: string;
|
roleKey: string;
|
||||||
payRate?: (PayRateSchema | null);
|
payRate?: (PayRateSchema | null);
|
||||||
|
id: number;
|
||||||
role: RoleSchema;
|
role: RoleSchema;
|
||||||
position?: (PositionSchema | null);
|
position?: (PositionSchema | null);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import type { PayRateSchema } from './PayRateSchema';
|
import type { PayRateSchema } from './PayRateSchema';
|
||||||
export type UserUpdate = {
|
export type UserUpdate = {
|
||||||
id: number;
|
|
||||||
telegramId: number;
|
telegramId: number;
|
||||||
phoneNumber?: (string | null);
|
phoneNumber?: (string | null);
|
||||||
firstName: string;
|
firstName: string;
|
||||||
@@ -15,6 +14,7 @@ export type UserUpdate = {
|
|||||||
isDeleted: boolean;
|
isDeleted: boolean;
|
||||||
roleKey: string;
|
roleKey: string;
|
||||||
payRate?: (PayRateSchema | null);
|
payRate?: (PayRateSchema | null);
|
||||||
|
id: number;
|
||||||
positionKey?: (string | null);
|
positionKey?: (string | null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
/* istanbul ignore file */
|
/* istanbul ignore file */
|
||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
import type { CreateUserRequest } from '../models/CreateUserRequest';
|
||||||
|
import type { CreateUserResponse } from '../models/CreateUserResponse';
|
||||||
import type { GetAllUsersResponse } from '../models/GetAllUsersResponse';
|
import type { GetAllUsersResponse } from '../models/GetAllUsersResponse';
|
||||||
import type { UpdateUserRequest } from '../models/UpdateUserRequest';
|
import type { UpdateUserRequest } from '../models/UpdateUserRequest';
|
||||||
import type { UpdateUserResponse } from '../models/UpdateUserResponse';
|
import type { UpdateUserResponse } from '../models/UpdateUserResponse';
|
||||||
@@ -40,4 +42,24 @@ export class UserService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Create
|
||||||
|
* @returns CreateUserResponse Successful Response
|
||||||
|
* @throws ApiError
|
||||||
|
*/
|
||||||
|
public static createUser({
|
||||||
|
requestBody,
|
||||||
|
}: {
|
||||||
|
requestBody: CreateUserRequest,
|
||||||
|
}): CancelablePromise<CreateUserResponse> {
|
||||||
|
return __request(OpenAPI, {
|
||||||
|
method: 'POST',
|
||||||
|
url: '/user/create',
|
||||||
|
body: requestBody,
|
||||||
|
mediaType: 'application/json',
|
||||||
|
errors: {
|
||||||
|
422: `Validation Error`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {CRUDTableProps} from "../../../../types/CRUDTable.tsx";
|
|||||||
import {UserSchema} from "../../../../client";
|
import {UserSchema} from "../../../../client";
|
||||||
import {BaseTable} from "../../../../components/BaseTable/BaseTable.tsx";
|
import {BaseTable} from "../../../../components/BaseTable/BaseTable.tsx";
|
||||||
import {FC} from "react";
|
import {FC} from "react";
|
||||||
import {ActionIcon, Flex, Text, Tooltip} from "@mantine/core";
|
import {ActionIcon, Button, Flex, rem, Text, Tooltip} from "@mantine/core";
|
||||||
import {useUsersTableColumns} from "./columns.tsx";
|
import {useUsersTableColumns} from "./columns.tsx";
|
||||||
import {IconEdit, IconTrash} from "@tabler/icons-react";
|
import {IconEdit, IconTrash} from "@tabler/icons-react";
|
||||||
import {modals} from "@mantine/modals";
|
import {modals} from "@mantine/modals";
|
||||||
@@ -10,7 +10,7 @@ import {MRT_TableOptions} from "mantine-react-table";
|
|||||||
|
|
||||||
type Props = CRUDTableProps<UserSchema>;
|
type Props = CRUDTableProps<UserSchema>;
|
||||||
|
|
||||||
const UsersTable: FC<Props> = ({items, onChange, onDelete}) => {
|
const UsersTable: FC<Props> = ({items, onChange, onDelete, onCreate}) => {
|
||||||
const columns = useUsersTableColumns();
|
const columns = useUsersTableColumns();
|
||||||
const onEditClick = (user: UserSchema) => {
|
const onEditClick = (user: UserSchema) => {
|
||||||
if (!onChange) return;
|
if (!onChange) return;
|
||||||
@@ -40,19 +40,39 @@ const UsersTable: FC<Props> = ({items, onChange, onDelete}) => {
|
|||||||
onConfirm: () => onDelete(user)
|
onConfirm: () => onDelete(user)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const onCreateClick = () => {
|
||||||
|
if (!onCreate) return;
|
||||||
|
modals.openContextModal({
|
||||||
|
modal: "userFormModal",
|
||||||
|
title: 'Редактирование пользователя',
|
||||||
|
withCloseButton: false,
|
||||||
|
innerProps: {
|
||||||
|
onCreate: onCreate
|
||||||
|
},
|
||||||
|
size: "md"
|
||||||
|
})
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<BaseTable
|
<BaseTable
|
||||||
data={items}
|
data={items}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
restProps={{
|
restProps={{
|
||||||
enableTopToolbar: false,
|
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
enableColumnActions: false,
|
enableColumnActions: false,
|
||||||
|
enableTopToolbar: true,
|
||||||
|
renderTopToolbar: (
|
||||||
|
<Flex p={rem(10)}>
|
||||||
|
<Button
|
||||||
|
variant={"default"}
|
||||||
|
onClick={() => onCreateClick()}
|
||||||
|
>
|
||||||
|
Создать пользователя
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
),
|
||||||
enableRowActions: true,
|
enableRowActions: true,
|
||||||
renderRowActions: ({row}) => (
|
renderRowActions: ({row}) => (
|
||||||
<Flex gap="md">
|
<Flex gap="md">
|
||||||
|
|
||||||
<Tooltip
|
<Tooltip
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onEditClick(row.original)
|
onEditClick(row.original)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {ContextModalProps} from "@mantine/modals";
|
import {ContextModalProps} from "@mantine/modals";
|
||||||
import BaseFormModal, {EditProps} from "../../../ClientsPage/modals/BaseFormModal/BaseFormModal.tsx";
|
import BaseFormModal, {CreateEditFormProps} from "../../../ClientsPage/modals/BaseFormModal/BaseFormModal.tsx";
|
||||||
import {UserSchema} from "../../../../client";
|
import {UserSchema} from "../../../../client";
|
||||||
import {useForm} from "@mantine/form";
|
import {useForm} from "@mantine/form";
|
||||||
import {Checkbox, Fieldset, Input, Stack, Textarea, TextInput} from "@mantine/core";
|
import {Checkbox, Fieldset, Input, Stack, Textarea, TextInput} from "@mantine/core";
|
||||||
@@ -11,16 +11,23 @@ import {IMaskInput} from "react-imask";
|
|||||||
import phone from "phone";
|
import phone from "phone";
|
||||||
import PayRateSelect from "../../../../components/Selects/PayRateSelect/PayRateSelect.tsx";
|
import PayRateSelect from "../../../../components/Selects/PayRateSelect/PayRateSelect.tsx";
|
||||||
|
|
||||||
type Props = EditProps<UserSchema>;
|
type Props = CreateEditFormProps<UserSchema>;
|
||||||
const UserFormModal = ({context, id, innerProps}: ContextModalProps<Props>) => {
|
const UserFormModal = ({context, id, innerProps}: ContextModalProps<Props>) => {
|
||||||
const initialValues = innerProps.element;
|
const isEditing = 'element' in innerProps;
|
||||||
|
const initialValues = isEditing ? innerProps.element : {
|
||||||
|
isAdmin: false,
|
||||||
|
isBlocked: false,
|
||||||
|
isDeleted: false,
|
||||||
|
comment: "",
|
||||||
|
roleKey: UserRoleEnum.USER
|
||||||
|
};
|
||||||
|
|
||||||
const form = useForm<UserSchema>({
|
const form = useForm<Partial<UserSchema>>({
|
||||||
initialValues: initialValues,
|
initialValues: initialValues,
|
||||||
validate: {
|
validate: {
|
||||||
firstName: value => !value.trim() && "Укажите имя пользователя",
|
firstName: value => !value?.trim() && "Укажите имя пользователя",
|
||||||
secondName: value => !value.trim() && "Укажите фамилию",
|
secondName: value => !value?.trim() && "Укажите фамилию",
|
||||||
position: (value, values) => ((values.role.key === UserRoleEnum.EMPLOYEE) && (!value)) && 'Необходимо указать должность сотрудника',
|
position: (value, values) => ((values.role?.key === UserRoleEnum.EMPLOYEE) && (!value)) && 'Необходимо указать должность сотрудника',
|
||||||
phoneNumber: value => !phone(value || '', {
|
phoneNumber: value => !phone(value || '', {
|
||||||
country: "",
|
country: "",
|
||||||
strictDetection: false,
|
strictDetection: false,
|
||||||
@@ -71,7 +78,7 @@ const UserFormModal = ({context, id, innerProps}: ContextModalProps<Props>) => {
|
|||||||
placeholder={"Выберите роль пользователя"}
|
placeholder={"Выберите роль пользователя"}
|
||||||
{...form.getInputProps('role')}
|
{...form.getInputProps('role')}
|
||||||
/>
|
/>
|
||||||
{form.values.role.key === UserRoleEnum.EMPLOYEE &&
|
{form.values.role?.key === UserRoleEnum.EMPLOYEE &&
|
||||||
<>
|
<>
|
||||||
<PositionSelect
|
<PositionSelect
|
||||||
label={"Должность сотрудника"}
|
label={"Должность сотрудника"}
|
||||||
|
|||||||
@@ -24,11 +24,26 @@ const UsersTab = () => {
|
|||||||
const onDelete = async (user: UserSchema) => {
|
const onDelete = async (user: UserSchema) => {
|
||||||
onChange({...user, isDeleted: true});
|
onChange({...user, isDeleted: true});
|
||||||
}
|
}
|
||||||
|
const onCreate = (user: UserSchema) => {
|
||||||
|
UserService.createUser({
|
||||||
|
requestBody: {
|
||||||
|
data: {
|
||||||
|
...user,
|
||||||
|
telegramId: -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).then(async ({ok, message}) => {
|
||||||
|
notifications.guess(ok, {message});
|
||||||
|
if (!ok) return;
|
||||||
|
await refetch();
|
||||||
|
})
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<UsersTable
|
<UsersTable
|
||||||
items={users}
|
items={users}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
|
onCreate={onCreate}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user