Compare commits
16 Commits
feature/pl
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
52fec13377 | ||
|
1d4b796a39 | ||
|
142067e9ce | ||
3c291baa0e | |||
|
3cdc47b91b | ||
|
901d8d78a1 | ||
|
7736592830 | ||
|
8d447c9461 | ||
6506b89dc7 | |||
89d432b360 | |||
f6cc2efb86 | |||
|
0ec9e146b9 | ||
|
1669f01879 | ||
658e23d4e3 | |||
ed8ae95436 | |||
a00aaff29d |
9
__mocks__/react-i18next.ts
Normal file
9
__mocks__/react-i18next.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import localeRu from '../locales/ru.json';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
useTranslation: (_, { keyPrefix }) => {
|
||||||
|
return {
|
||||||
|
t: (key: string) => localeRu[`${keyPrefix}.${key}`],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
@ -9,9 +9,11 @@ module.exports = {
|
|||||||
clearMocks: true,
|
clearMocks: true,
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'\\.(svg|webp)$': '<rootDir>/__mocks__/file',
|
'\\.(svg|webp)$': '<rootDir>/__mocks__/file',
|
||||||
|
'react-i18next': '<rootDir>/__mocks__/react-i18next',
|
||||||
},
|
},
|
||||||
testEnvironmentOptions: {
|
testEnvironmentOptions: {
|
||||||
customExportConditions: [''],
|
customExportConditions: [''],
|
||||||
},
|
},
|
||||||
testEnvironment: 'jest-fixed-jsdom',
|
testEnvironment: 'jest-fixed-jsdom',
|
||||||
|
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/e2e'],
|
||||||
};
|
};
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
"dry-wash.order-create.car-body-select.options.sports-car" : "Sports-car",
|
"dry-wash.order-create.car-body-select.options.sports-car" : "Sports-car",
|
||||||
"dry-wash.order-create.car-body-select.options.other": "Other",
|
"dry-wash.order-create.car-body-select.options.other": "Other",
|
||||||
"dry-wash.order-create.form.submit-button.label": "Submit",
|
"dry-wash.order-create.form.submit-button.label": "Submit",
|
||||||
|
"dry-wash.order-create.order-creation-title": "Creating order ...",
|
||||||
"dry-wash.order-create.create-order-query.success.title": "The order is successfully created",
|
"dry-wash.order-create.create-order-query.success.title": "The order is successfully created",
|
||||||
"dry-wash.order-create.create-order-query.error.title": "Failed to create an order",
|
"dry-wash.order-create.create-order-query.error.title": "Failed to create an order",
|
||||||
"dry-wash.order-view.title": "Your order",
|
"dry-wash.order-view.title": "Your order",
|
||||||
|
@ -25,10 +25,16 @@
|
|||||||
"dry-wash.arm.master.table.header.phone": "Телефон",
|
"dry-wash.arm.master.table.header.phone": "Телефон",
|
||||||
"dry-wash.arm.master.table.header.actions": "Действия",
|
"dry-wash.arm.master.table.header.actions": "Действия",
|
||||||
"dry-wash.arm.master.table.actionsMenu.delete": "Удалить мастера",
|
"dry-wash.arm.master.table.actionsMenu.delete": "Удалить мастера",
|
||||||
|
"dry-wash.arm.master.table.actionsMenu.toast.success": "Мастер удалён",
|
||||||
|
"dry-wash.arm.master.table.actionsMenu.toast.error.title": "Ошибка!",
|
||||||
|
"dry-wash.arm.master.table.actionsMenu.toast.error.description": "Не удалось удалить мастера. Попробуйте ещё раз.",
|
||||||
"dry-wash.arm.master.schedule.empty": "Свободен",
|
"dry-wash.arm.master.schedule.empty": "Свободен",
|
||||||
"dry-wash.arm.master.editable.aria.cancel": "Отменить изменения",
|
"dry-wash.arm.master.editable.aria.cancel": "Отменить изменения",
|
||||||
"dry-wash.arm.master.editable.aria.save": "Сохранить изменения",
|
"dry-wash.arm.master.editable.aria.save": "Сохранить изменения",
|
||||||
"dry-wash.arm.master.editable.aria.edit": "Редактировать",
|
"dry-wash.arm.master.editable.aria.edit": "Редактировать",
|
||||||
|
"dry-wash.arm.master.editable.toast.success": "Успешно!",
|
||||||
|
"dry-wash.arm.master.editable.toast.error.description": "Не удалось обновить данные",
|
||||||
|
"dry-wash.arm.master.editable.toast.error.title": "Ошибка!",
|
||||||
"dry-wash.arm.master.drawer.title": "Добавить нового мастера",
|
"dry-wash.arm.master.drawer.title": "Добавить нового мастера",
|
||||||
"dry-wash.arm.master.drawer.inputName.label": "ФИО",
|
"dry-wash.arm.master.drawer.inputName.label": "ФИО",
|
||||||
"dry-wash.arm.master.drawer.inputName.placeholder": "Введите ФИО",
|
"dry-wash.arm.master.drawer.inputName.placeholder": "Введите ФИО",
|
||||||
@ -88,6 +94,7 @@
|
|||||||
"dry-wash.order-create.car-body-select.options.sports-car": "Спорткар",
|
"dry-wash.order-create.car-body-select.options.sports-car": "Спорткар",
|
||||||
"dry-wash.order-create.car-body-select.options.other": "Другой",
|
"dry-wash.order-create.car-body-select.options.other": "Другой",
|
||||||
"dry-wash.order-create.form.submit-button.label": "Отправить",
|
"dry-wash.order-create.form.submit-button.label": "Отправить",
|
||||||
|
"dry-wash.order-create.order-creation-title": "Создаем заказ ...",
|
||||||
"dry-wash.order-create.create-order-query.success.title": "Заказ успешно создан",
|
"dry-wash.order-create.create-order-query.success.title": "Заказ успешно создан",
|
||||||
"dry-wash.order-create.create-order-query.error.title": "Не удалось создать заказ",
|
"dry-wash.order-create.create-order-query.error.title": "Не удалось создать заказ",
|
||||||
"dry-wash.order-view.title": "Ваш заказ",
|
"dry-wash.order-view.title": "Ваш заказ",
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "dry-wash",
|
"name": "dry-wash",
|
||||||
"version": "0.5.0",
|
"version": "0.7.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "dry-wash",
|
"name": "dry-wash",
|
||||||
"version": "0.5.0",
|
"version": "0.7.2",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.26.7",
|
"@babel/core": "^7.26.7",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dry-wash",
|
"name": "dry-wash",
|
||||||
"version": "0.5.0",
|
"version": "0.7.2",
|
||||||
"description": "<a id=\"readme-top\"></a>",
|
"description": "<a id=\"readme-top\"></a>",
|
||||||
"main": "./src/index.tsx",
|
"main": "./src/index.tsx",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,20 +1,53 @@
|
|||||||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
||||||
import { getConfigValue } from '@brojs/cli';
|
import { getConfigValue } from '@brojs/cli';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { Master } from '../../models/api/master';
|
import { Master, OrderArm } from '../../models/api';
|
||||||
|
|
||||||
import { extractBodyFromResponse } from './utils';
|
import { extractBodyFromResponse } from './utils';
|
||||||
|
|
||||||
|
export type UpdateMasterPayload = Required<Pick<Master, 'id'>> &
|
||||||
|
Partial<Omit<Master, 'id'>>;
|
||||||
|
|
||||||
|
type UpdateOrderProps = Required<Pick<OrderArm, 'id'>> &
|
||||||
|
Partial<Pick<OrderArm, 'status' | 'notes'>> & {
|
||||||
|
master?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export const api = createApi({
|
export const api = createApi({
|
||||||
reducerPath: 'api',
|
reducerPath: 'api',
|
||||||
baseQuery: fetchBaseQuery({ baseUrl: getConfigValue('dry-wash.api') }),
|
baseQuery: fetchBaseQuery({
|
||||||
tagTypes: ['Masters'],
|
baseUrl: new URL(getConfigValue('dry-wash.api'), location.origin).href,
|
||||||
|
}),
|
||||||
|
tagTypes: ['Masters', 'Orders'],
|
||||||
endpoints: (builder) => ({
|
endpoints: (builder) => ({
|
||||||
getMasters: builder.query<Master[], void>({
|
getMasters: builder.query<Master[], void>({
|
||||||
query: () => ({ url: '/arm/masters' }),
|
query: () => ({ url: '/arm/masters' }),
|
||||||
transformResponse: extractBodyFromResponse<Master[]>,
|
transformResponse: extractBodyFromResponse<Master[]>,
|
||||||
providesTags: ['Masters'],
|
providesTags: ['Masters'],
|
||||||
}),
|
}),
|
||||||
|
updateOrders: builder.mutation<void, UpdateOrderProps>({
|
||||||
|
query: ({ id, status, notes, master }) => ({
|
||||||
|
url: `/order/${id}`,
|
||||||
|
method: 'PATCH',
|
||||||
|
body: { status, notes, master },
|
||||||
|
}),
|
||||||
|
invalidatesTags: ['Orders'],
|
||||||
|
}),
|
||||||
|
getOrders: builder.query<OrderArm[], { date: Date }>({
|
||||||
|
query: ({ date }) => {
|
||||||
|
const startDate = dayjs(date).startOf('day').toISOString();
|
||||||
|
const endDate = dayjs(date).endOf('day').toISOString();
|
||||||
|
return {
|
||||||
|
url: '/arm/orders',
|
||||||
|
method: 'POST',
|
||||||
|
body: { startDate, endDate },
|
||||||
|
};
|
||||||
|
},
|
||||||
|
transformResponse: extractBodyFromResponse<OrderArm[]>,
|
||||||
|
providesTags: ['Orders'],
|
||||||
|
}),
|
||||||
|
|
||||||
addMaster: builder.mutation<void, Pick<Master, 'name' | 'phone'>>({
|
addMaster: builder.mutation<void, Pick<Master, 'name' | 'phone'>>({
|
||||||
query: (master) => ({
|
query: (master) => ({
|
||||||
url: '/arm/masters',
|
url: '/arm/masters',
|
||||||
@ -23,5 +56,29 @@ export const api = createApi({
|
|||||||
}),
|
}),
|
||||||
invalidatesTags: ['Masters'],
|
invalidatesTags: ['Masters'],
|
||||||
}),
|
}),
|
||||||
|
deleteMaster: builder.mutation<void, { id: string }>({
|
||||||
|
query: ({ id }) => ({
|
||||||
|
url: `/arm/masters/${id}`,
|
||||||
|
method: 'DELETE',
|
||||||
|
}),
|
||||||
|
invalidatesTags: ['Masters'],
|
||||||
|
}),
|
||||||
|
updateMaster: builder.mutation<void, UpdateMasterPayload>({
|
||||||
|
query: ({ id, name, phone }) => ({
|
||||||
|
url: `/arm/masters/${id}`,
|
||||||
|
method: 'PATCH',
|
||||||
|
body: { name, phone },
|
||||||
|
}),
|
||||||
|
invalidatesTags: ['Masters'],
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const {
|
||||||
|
useGetMastersQuery,
|
||||||
|
useAddMasterMutation,
|
||||||
|
useDeleteMasterMutation,
|
||||||
|
useUpdateMasterMutation,
|
||||||
|
useGetOrdersQuery,
|
||||||
|
useUpdateOrdersMutation,
|
||||||
|
} = api;
|
||||||
|
@ -1,14 +1,23 @@
|
|||||||
import { GetOrder } from "../../models/api";
|
import { GetOrder, CreateOrder } from "../../models/api";
|
||||||
|
|
||||||
import { api } from "./api";
|
import { api } from "./api";
|
||||||
import { extractBodyFromResponse, extractErrorMessageFromResponse } from "./utils";
|
import { extractBodyFromResponse, extractErrorMessageFromResponse } from "./utils";
|
||||||
|
|
||||||
export const landingApi = api.injectEndpoints({
|
export const landingApi = api.injectEndpoints({
|
||||||
endpoints: ({ query }) => ({
|
endpoints: ({ mutation, query }) => ({
|
||||||
getOrder: query<GetOrder.Response, GetOrder.Params>({
|
getOrder: query<GetOrder.Response, GetOrder.Params>({
|
||||||
query: ({ orderId }) => `/order/${orderId}`,
|
query: ({ orderId }) => `/order/${orderId}`,
|
||||||
transformResponse: extractBodyFromResponse<GetOrder.Response>,
|
transformResponse: extractBodyFromResponse<GetOrder.Response>,
|
||||||
transformErrorResponse: extractErrorMessageFromResponse,
|
transformErrorResponse: extractErrorMessageFromResponse,
|
||||||
})
|
}),
|
||||||
|
createOrder: mutation<CreateOrder.Response, CreateOrder.Params>({
|
||||||
|
query: ({ body }) => ({
|
||||||
|
url: `/order/create`,
|
||||||
|
body,
|
||||||
|
method: 'POST'
|
||||||
|
}),
|
||||||
|
transformResponse: extractBodyFromResponse<CreateOrder.Response>,
|
||||||
|
transformErrorResponse: extractErrorMessageFromResponse,
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -12,4 +12,4 @@ export const extractErrorMessageFromResponse = ({ data }: FetchBaseQueryError) =
|
|||||||
if (typeof data === 'object' && 'message' in data && typeof data.message === 'string') {
|
if (typeof data === 'object' && 'message' in data && typeof data.message === 'string') {
|
||||||
return data.message;
|
return data.message;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
139
src/api/arm.ts
139
src/api/arm.ts
@ -1,139 +0,0 @@
|
|||||||
import { getConfigValue } from '@brojs/cli';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
|
|
||||||
enum ArmEndpoints {
|
|
||||||
ORDERS = '/arm/orders',
|
|
||||||
MASTERS = '/arm/masters',
|
|
||||||
}
|
|
||||||
|
|
||||||
const armService = () => {
|
|
||||||
const endpoint = getConfigValue('dry-wash.api');
|
|
||||||
|
|
||||||
const fetchOrders = async ({ date }: { date: Date }) => {
|
|
||||||
const startDate = dayjs(date).startOf('day').toISOString();
|
|
||||||
const endDate = dayjs(date).endOf('day').toISOString();
|
|
||||||
|
|
||||||
const response = await fetch(`${endpoint}${ArmEndpoints.ORDERS}`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ startDate, endDate }),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to fetch orders: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json();
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchMasters = async () => {
|
|
||||||
const response = await fetch(`${endpoint}${ArmEndpoints.MASTERS}`);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to fetch masters: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json();
|
|
||||||
};
|
|
||||||
|
|
||||||
const addMaster = async ({
|
|
||||||
name,
|
|
||||||
phone,
|
|
||||||
}: {
|
|
||||||
name: string;
|
|
||||||
phone: string;
|
|
||||||
}) => {
|
|
||||||
const response = await fetch(`${endpoint}${ArmEndpoints.MASTERS}`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ name, phone }),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to fetch masters: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json();
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteMaster = async ({ id }: { id: string }) => {
|
|
||||||
const response = await fetch(`${endpoint}${ArmEndpoints.MASTERS}/${id}`, {
|
|
||||||
method: 'DELETE',
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to fetch masters: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json();
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateOrders = async ({
|
|
||||||
id,
|
|
||||||
status,
|
|
||||||
notes,
|
|
||||||
masterId,
|
|
||||||
}: {
|
|
||||||
id: string;
|
|
||||||
status?: string;
|
|
||||||
notes?: string;
|
|
||||||
masterId?: string;
|
|
||||||
}) => {
|
|
||||||
const body = JSON.stringify({ status, notes, masterId });
|
|
||||||
|
|
||||||
const response = await fetch(`${endpoint}/order/${id}`, {
|
|
||||||
method: 'PATCH',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to fetch update masters: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json();
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateMaster = async ({
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
phone,
|
|
||||||
}: {
|
|
||||||
id: string;
|
|
||||||
name?: string;
|
|
||||||
phone?: string;
|
|
||||||
}) => {
|
|
||||||
const body = JSON.stringify({ name, phone });
|
|
||||||
|
|
||||||
const response = await fetch(`${endpoint}${ArmEndpoints.MASTERS}/${id}`, {
|
|
||||||
method: 'PATCH',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to fetch update masters: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json();
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
fetchOrders,
|
|
||||||
fetchMasters,
|
|
||||||
addMaster,
|
|
||||||
deleteMaster,
|
|
||||||
updateMaster,
|
|
||||||
updateOrders,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export { armService, ArmEndpoints };
|
|
@ -1 +0,0 @@
|
|||||||
export * from './landing';
|
|
@ -1,65 +0,0 @@
|
|||||||
import { getConfigValue } from '@brojs/cli';
|
|
||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
import { CreateOrder } from '../models/api';
|
|
||||||
|
|
||||||
import { QueryState, Trigger } from './types';
|
|
||||||
|
|
||||||
enum LandingEndpoints {
|
|
||||||
ORDER_CREATE = '/order/create',
|
|
||||||
}
|
|
||||||
|
|
||||||
const endpoint = getConfigValue('dry-wash.api');
|
|
||||||
|
|
||||||
const useCreateOrderMutation = <D extends CreateOrder.Response>(): [
|
|
||||||
Trigger<CreateOrder.Params, QueryState<D>['data']>,
|
|
||||||
QueryState<D>,
|
|
||||||
] => {
|
|
||||||
const [isLoading, setIsLoading] = useState<QueryState<D>['isLoading']>(false);
|
|
||||||
const [isSuccess, setIsSuccess] = useState<QueryState<D>['isSuccess']>();
|
|
||||||
const [data, setData] = useState<QueryState<D>['data']>();
|
|
||||||
const [isError, setIsError] = useState<QueryState<D>['isError']>();
|
|
||||||
const [error, setError] = useState<QueryState<D>['error']>();
|
|
||||||
|
|
||||||
const createOrder = async ({ body }: CreateOrder.Params) => {
|
|
||||||
setIsLoading(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(
|
|
||||||
`${endpoint}${LandingEndpoints.ORDER_CREATE}`,
|
|
||||||
{
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(body),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorResponseObject =
|
|
||||||
(await response.json()) as QueryState<D>['error'];
|
|
||||||
setIsError(true);
|
|
||||||
setError(errorResponseObject);
|
|
||||||
throw errorResponseObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dataResponseObject =
|
|
||||||
(await response.json()) as QueryState<D>['data'];
|
|
||||||
setIsSuccess(true);
|
|
||||||
setData(dataResponseObject);
|
|
||||||
|
|
||||||
return dataResponseObject;
|
|
||||||
} catch (error) {
|
|
||||||
setIsError(true);
|
|
||||||
setError(error);
|
|
||||||
throw error;
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return [createOrder, { isLoading, isSuccess, data, isError, error }];
|
|
||||||
};
|
|
||||||
|
|
||||||
export { useCreateOrderMutation };
|
|
@ -1,22 +0,0 @@
|
|||||||
export type QueryData<D> = {
|
|
||||||
success: true;
|
|
||||||
body: D;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type QueryErrorData = {
|
|
||||||
success: false;
|
|
||||||
error: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type QueryState<D> = {
|
|
||||||
isLoading: boolean;
|
|
||||||
isSuccess: boolean;
|
|
||||||
data: QueryData<D>;
|
|
||||||
isError: boolean;
|
|
||||||
error: {
|
|
||||||
status: number;
|
|
||||||
data: QueryErrorData;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Trigger<P, D> = (params: P) => Promise<D>;
|
|
1
src/assets/animation/index.ts
Normal file
1
src/assets/animation/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { default as OrderCreationAnimation } from './order-creation.json';
|
1
src/assets/animation/order-creation.json
Normal file
1
src/assets/animation/order-creation.json
Normal file
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Editable,
|
Editable,
|
||||||
EditableInput,
|
EditableInput,
|
||||||
@ -9,63 +9,51 @@ import {
|
|||||||
useEditableControls,
|
useEditableControls,
|
||||||
ButtonGroup,
|
ButtonGroup,
|
||||||
Stack,
|
Stack,
|
||||||
useToast,
|
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { CheckIcon, CloseIcon, EditIcon } from '@chakra-ui/icons';
|
import { CheckIcon, CloseIcon, EditIcon } from '@chakra-ui/icons';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import { useUpdateMasterMutation } from '../../__data__/service/api';
|
||||||
|
import useShowToast from '../../hooks/useShowToast';
|
||||||
|
|
||||||
interface EditableWrapperProps {
|
interface EditableWrapperProps {
|
||||||
value: string;
|
value: string;
|
||||||
onSubmit: ({
|
fieldName: 'phone' | 'name';
|
||||||
id,
|
|
||||||
name,
|
|
||||||
phone,
|
|
||||||
}: {
|
|
||||||
id: string;
|
|
||||||
name?: string;
|
|
||||||
phone?: string;
|
|
||||||
}) => Promise<unknown>;
|
|
||||||
as: 'phone' | 'name';
|
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EditableWrapper = ({ value, onSubmit, as, id }: EditableWrapperProps) => {
|
const EditableWrapper = ({ value, fieldName, id }: EditableWrapperProps) => {
|
||||||
|
const [updateMaster, { isError, isSuccess, error }] =
|
||||||
|
useUpdateMasterMutation();
|
||||||
|
|
||||||
const { t } = useTranslation('~', {
|
const { t } = useTranslation('~', {
|
||||||
keyPrefix: 'dry-wash.arm.master.editable',
|
keyPrefix: 'dry-wash.arm.master.editable',
|
||||||
});
|
});
|
||||||
|
|
||||||
const toast = useToast();
|
const showToast = useShowToast();
|
||||||
const [currentValue, setCurrentValue] = useState<string>(value);
|
const [currentValue, setCurrentValue] = useState<string>(value);
|
||||||
|
|
||||||
const handleSubmit = async (newValue: string) => {
|
const handleSubmit = async (newValue: string) => {
|
||||||
if (currentValue === newValue) return;
|
if (currentValue === newValue) return;
|
||||||
|
|
||||||
try {
|
await updateMaster({ id, [fieldName]: newValue });
|
||||||
await onSubmit({ id, [as]: newValue });
|
|
||||||
|
|
||||||
setCurrentValue(newValue);
|
setCurrentValue(newValue);
|
||||||
|
|
||||||
toast({
|
|
||||||
title: 'Успешно!',
|
|
||||||
description: 'Данные обновлены.',
|
|
||||||
status: 'success',
|
|
||||||
duration: 2000,
|
|
||||||
isClosable: true,
|
|
||||||
position: 'top-right',
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
toast({
|
|
||||||
title: 'Ошибка!',
|
|
||||||
description: 'Не удалось обновить данные.',
|
|
||||||
status: 'error',
|
|
||||||
duration: 2000,
|
|
||||||
isClosable: true,
|
|
||||||
position: 'top-right',
|
|
||||||
});
|
|
||||||
console.error('Ошибка при обновлении данных:', error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isSuccess) {
|
||||||
|
showToast(t('toast.success'), 'success');
|
||||||
|
}
|
||||||
|
}, [isSuccess]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isError) {
|
||||||
|
showToast(t('toast.error.title'), 'error', t('toast.error.description'));
|
||||||
|
console.error(t('toast.error.description'), error);
|
||||||
|
}
|
||||||
|
}, [isError, error]);
|
||||||
|
|
||||||
function EditableControls() {
|
function EditableControls() {
|
||||||
const {
|
const {
|
||||||
isEditing,
|
isEditing,
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
Menu,
|
Menu,
|
||||||
MenuButton,
|
MenuButton,
|
||||||
MenuList,
|
MenuList,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
IconButton,
|
IconButton,
|
||||||
useToast,
|
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { EditIcon } from '@chakra-ui/icons';
|
import { EditIcon } from '@chakra-ui/icons';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { armService } from '../../api/arm';
|
import { useDeleteMasterMutation } from '../../__data__/service/api';
|
||||||
|
import useShowToast from '../../hooks/useShowToast';
|
||||||
|
|
||||||
interface MasterActionsMenu {
|
interface MasterActionsMenu {
|
||||||
id: string;
|
id: string;
|
||||||
@ -21,38 +21,35 @@ const MasterActionsMenu = ({ id }: MasterActionsMenu) => {
|
|||||||
keyPrefix: 'dry-wash.arm.master.table.actionsMenu',
|
keyPrefix: 'dry-wash.arm.master.table.actionsMenu',
|
||||||
});
|
});
|
||||||
|
|
||||||
const { deleteMaster } = armService();
|
const [deleteMaster, { isSuccess, isError, error, isLoading }] =
|
||||||
const toast = useToast();
|
useDeleteMasterMutation();
|
||||||
|
|
||||||
|
const showToast = useShowToast();
|
||||||
|
|
||||||
const handleClickDelete = async () => {
|
const handleClickDelete = async () => {
|
||||||
try {
|
await deleteMaster({ id });
|
||||||
await deleteMaster({ id });
|
};
|
||||||
toast({
|
|
||||||
title: 'Мастер удалён.',
|
useEffect(() => {
|
||||||
description: `Мастер с ID "${id}" успешно удалён.`,
|
if (isSuccess) {
|
||||||
status: 'success',
|
showToast(t('toast.success'), 'success');
|
||||||
duration: 5000,
|
}
|
||||||
isClosable: true,
|
}, [isSuccess]);
|
||||||
position: 'top-right',
|
|
||||||
});
|
useEffect(() => {
|
||||||
} catch (error) {
|
if (isError) {
|
||||||
toast({
|
showToast(t('toast.error.title'), 'error', t('toast.error.description'));
|
||||||
title: 'Ошибка удаления мастера.',
|
|
||||||
description: 'Не удалось удалить мастера. Попробуйте ещё раз.',
|
|
||||||
status: 'error',
|
|
||||||
duration: 5000,
|
|
||||||
isClosable: true,
|
|
||||||
position: 'top-right',
|
|
||||||
});
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
};
|
}, [isError]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuButton icon={<EditIcon />} as={IconButton} variant='outline' />
|
<MenuButton icon={<EditIcon />} as={IconButton} variant='outline' />
|
||||||
<MenuList>
|
<MenuList>
|
||||||
<MenuItem onClick={handleClickDelete}>{t('delete')}</MenuItem>
|
<MenuItem onClick={handleClickDelete} isDisabled={isLoading}>
|
||||||
|
{t('delete')}
|
||||||
|
</MenuItem>
|
||||||
</MenuList>
|
</MenuList>
|
||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
|
@ -12,7 +12,6 @@ import {
|
|||||||
DrawerFooter,
|
DrawerFooter,
|
||||||
DrawerHeader,
|
DrawerHeader,
|
||||||
DrawerOverlay,
|
DrawerOverlay,
|
||||||
useToast,
|
|
||||||
InputGroup,
|
InputGroup,
|
||||||
InputLeftElement,
|
InputLeftElement,
|
||||||
FormErrorMessage,
|
FormErrorMessage,
|
||||||
@ -20,9 +19,9 @@ import {
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { PhoneIcon } from '@chakra-ui/icons';
|
import { PhoneIcon } from '@chakra-ui/icons';
|
||||||
|
|
||||||
import { api } from '../../__data__/service/api';
|
import { useAddMasterMutation } from '../../__data__/service/api';
|
||||||
import showToast from '../../helpers/showToast';
|
|
||||||
import { DrawerInputs } from '../../models/arm/form';
|
import { DrawerInputs } from '../../models/arm/form';
|
||||||
|
import useShowToast from '../../hooks/useShowToast';
|
||||||
|
|
||||||
interface MasterDrawerProps {
|
interface MasterDrawerProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@ -50,28 +49,19 @@ const MasterDrawer = ({ isOpen, onClose }: MasterDrawerProps) => {
|
|||||||
const isEmptyFields = trimMaster.name === '' || trimMaster.phone === '';
|
const isEmptyFields = trimMaster.name === '' || trimMaster.phone === '';
|
||||||
|
|
||||||
if (isEmptyFields) {
|
if (isEmptyFields) {
|
||||||
showToast({
|
showToast(t('toast.error.base'), 'error', t('toast.error.empty-fields'));
|
||||||
toast,
|
|
||||||
title: t('toast.error.base'),
|
|
||||||
description: t('toast.error.empty-fields'),
|
|
||||||
status: 'error',
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await addMaster(trimMaster);
|
await addMaster(trimMaster);
|
||||||
};
|
};
|
||||||
|
|
||||||
const [addMaster, { error, isSuccess }] = api.useAddMasterMutation();
|
const [addMaster, { error, isSuccess }] = useAddMasterMutation();
|
||||||
const toast = useToast();
|
const showToast = useShowToast();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
showToast({
|
showToast(t('toast.create-master'), 'success');
|
||||||
toast,
|
|
||||||
title: t('toast.create-master'),
|
|
||||||
status: 'success',
|
|
||||||
});
|
|
||||||
reset();
|
reset();
|
||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
@ -79,12 +69,11 @@ const MasterDrawer = ({ isOpen, onClose }: MasterDrawerProps) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (error) {
|
if (error) {
|
||||||
showToast({
|
showToast(
|
||||||
toast,
|
t('toast.error.create-master'),
|
||||||
title: t('toast.error.create-master'),
|
'error',
|
||||||
description: t('toast.error.create-master-details'),
|
t('toast.error.create-master-details'),
|
||||||
status: 'error',
|
);
|
||||||
});
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
}, [error]);
|
}, [error]);
|
||||||
|
@ -5,10 +5,8 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import MasterActionsMenu from '../MasterActionsMenu';
|
import MasterActionsMenu from '../MasterActionsMenu';
|
||||||
import { getTimeSlot } from '../../lib';
|
import { getTimeSlot } from '../../lib';
|
||||||
import EditableWrapper from '../Editable/Editable';
|
import EditableWrapper from '../Editable/Editable';
|
||||||
import { armService } from '../../api/arm';
|
|
||||||
|
|
||||||
const MasterItem = ({ name, phone, id, schedule }) => {
|
const MasterItem = ({ name, phone, id, schedule }) => {
|
||||||
const { updateMaster } = armService();
|
|
||||||
const { t } = useTranslation('~', {
|
const { t } = useTranslation('~', {
|
||||||
keyPrefix: 'dry-wash.arm.master',
|
keyPrefix: 'dry-wash.arm.master',
|
||||||
});
|
});
|
||||||
@ -16,12 +14,7 @@ const MasterItem = ({ name, phone, id, schedule }) => {
|
|||||||
return (
|
return (
|
||||||
<Tr>
|
<Tr>
|
||||||
<Td>
|
<Td>
|
||||||
<EditableWrapper
|
<EditableWrapper id={id} fieldName={'name'} value={name} />
|
||||||
id={id}
|
|
||||||
as={'name'}
|
|
||||||
value={name}
|
|
||||||
onSubmit={updateMaster}
|
|
||||||
/>
|
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
{schedule?.length > 0 ? (
|
{schedule?.length > 0 ? (
|
||||||
@ -37,12 +30,7 @@ const MasterItem = ({ name, phone, id, schedule }) => {
|
|||||||
)}
|
)}
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<EditableWrapper
|
<EditableWrapper id={id} fieldName={'phone'} value={phone} />
|
||||||
id={id}
|
|
||||||
as={'phone'}
|
|
||||||
value={phone}
|
|
||||||
onSubmit={updateMaster}
|
|
||||||
/>
|
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<MasterActionsMenu id={id} />
|
<MasterActionsMenu id={id} />
|
||||||
|
@ -10,7 +10,6 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
useDisclosure,
|
useDisclosure,
|
||||||
Flex,
|
Flex,
|
||||||
useToast,
|
|
||||||
Td,
|
Td,
|
||||||
Text,
|
Text,
|
||||||
Spinner,
|
Spinner,
|
||||||
@ -19,7 +18,8 @@ import { useTranslation } from 'react-i18next';
|
|||||||
|
|
||||||
import MasterItem from '../MasterItem';
|
import MasterItem from '../MasterItem';
|
||||||
import MasterDrawer from '../MasterDrawer';
|
import MasterDrawer from '../MasterDrawer';
|
||||||
import { api } from '../../__data__/service/api';
|
import { useGetMastersQuery } from '../../__data__/service/api';
|
||||||
|
import useShowToast from '../../hooks/useShowToast';
|
||||||
|
|
||||||
const TABLE_HEADERS = [
|
const TABLE_HEADERS = [
|
||||||
'name' as const,
|
'name' as const,
|
||||||
@ -30,26 +30,17 @@ const TABLE_HEADERS = [
|
|||||||
|
|
||||||
const Masters = () => {
|
const Masters = () => {
|
||||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||||
const toast = useToast();
|
const showToast = useShowToast();
|
||||||
|
|
||||||
const { t } = useTranslation('~', {
|
const { t } = useTranslation('~', {
|
||||||
keyPrefix: 'dry-wash.arm.master',
|
keyPrefix: 'dry-wash.arm.master',
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const { data: masters, error, isLoading, isSuccess } = useGetMastersQuery();
|
||||||
data: masters,
|
|
||||||
error,
|
|
||||||
isLoading,
|
|
||||||
isSuccess,
|
|
||||||
} = api.useGetMastersQuery();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (error) {
|
if (error) {
|
||||||
toast({
|
showToast(t('error.title'), 'error');
|
||||||
title: t('error.title'),
|
|
||||||
status: 'error',
|
|
||||||
isClosable: true,
|
|
||||||
position: 'bottom-right',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, [error]);
|
}, [error]);
|
||||||
|
|
||||||
|
@ -4,35 +4,8 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { getTimeSlot } from '../../lib';
|
import { getTimeSlot } from '../../lib';
|
||||||
import { Master } from '../../models/api/master';
|
import { useUpdateOrdersMutation } from '../../__data__/service/api';
|
||||||
import { armService } from '../../api/arm';
|
import { OrderArm, Status, statuses } from '../../models/api';
|
||||||
|
|
||||||
const statuses = [
|
|
||||||
'pending' as const,
|
|
||||||
'progress' as const,
|
|
||||||
'working' as const,
|
|
||||||
'canceled' as const,
|
|
||||||
'complete' as const,
|
|
||||||
];
|
|
||||||
|
|
||||||
type GetArrItemType<ArrType> =
|
|
||||||
ArrType extends Array<infer ItemType> ? ItemType : never;
|
|
||||||
|
|
||||||
export type OrderProps = {
|
|
||||||
carNumber?: string;
|
|
||||||
startWashTime?: string;
|
|
||||||
endWashTime?: string;
|
|
||||||
orderDate?: string;
|
|
||||||
status?: GetArrItemType<typeof statuses>;
|
|
||||||
phone?: string;
|
|
||||||
location?: string;
|
|
||||||
master: Master;
|
|
||||||
notes: '';
|
|
||||||
allMasters: Master[];
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type Status = (typeof statuses)[number];
|
|
||||||
|
|
||||||
const statusColors: Record<Status, string> = {
|
const statusColors: Record<Status, string> = {
|
||||||
pending: 'yellow.100',
|
pending: 'yellow.100',
|
||||||
@ -53,9 +26,8 @@ const OrderItem = ({
|
|||||||
master,
|
master,
|
||||||
allMasters,
|
allMasters,
|
||||||
id,
|
id,
|
||||||
}: OrderProps) => {
|
}: OrderArm) => {
|
||||||
const { updateOrders } = armService();
|
const [updateOrders] = useUpdateOrdersMutation();
|
||||||
|
|
||||||
const { t } = useTranslation('~', {
|
const { t } = useTranslation('~', {
|
||||||
keyPrefix: 'dry-wash.arm.order',
|
keyPrefix: 'dry-wash.arm.order',
|
||||||
});
|
});
|
||||||
@ -72,16 +44,16 @@ const OrderItem = ({
|
|||||||
|
|
||||||
if (selectedMaster) {
|
if (selectedMaster) {
|
||||||
setMaster(masterName);
|
setMaster(masterName);
|
||||||
updateOrders({ id, masterId: selectedMaster.id });
|
updateOrders({ id, master: selectedMaster.id });
|
||||||
} else {
|
} else {
|
||||||
console.error('Master not found');
|
console.error('Master not found');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handeChangeStatus = (e: ChangeEvent<HTMLSelectElement>) => {
|
const handeChangeStatus = (e: ChangeEvent<HTMLSelectElement>) => {
|
||||||
const status = e.target.value;
|
const status = e.target.value as OrderArm['status'];
|
||||||
updateOrders({ id, status });
|
updateOrders({ id, status });
|
||||||
setStatus(e.target.value as OrderProps['status']);
|
setStatus(status);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -10,16 +10,18 @@ import {
|
|||||||
Spinner,
|
Spinner,
|
||||||
Text,
|
Text,
|
||||||
Td,
|
Td,
|
||||||
useToast,
|
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import OrderItem from '../OrderItem';
|
import OrderItem from '../OrderItem';
|
||||||
import { OrderProps } from '../OrderItem/OrderItem';
|
import { OrderProps } from '../OrderItem/OrderItem';
|
||||||
import { armService } from '../../api/arm';
|
|
||||||
import DateNavigator from '../DateNavigator';
|
import DateNavigator from '../DateNavigator';
|
||||||
import { Master } from '../../models/api/master';
|
import {
|
||||||
|
useGetMastersQuery,
|
||||||
|
useGetOrdersQuery,
|
||||||
|
} from '../../__data__/service/api';
|
||||||
|
import useShowToast from '../../hooks/useShowToast';
|
||||||
|
|
||||||
const TABLE_HEADERS = [
|
const TABLE_HEADERS = [
|
||||||
'carNumber' as const,
|
'carNumber' as const,
|
||||||
@ -34,47 +36,34 @@ const Orders = () => {
|
|||||||
const { t } = useTranslation('~', {
|
const { t } = useTranslation('~', {
|
||||||
keyPrefix: 'dry-wash.arm.order',
|
keyPrefix: 'dry-wash.arm.order',
|
||||||
});
|
});
|
||||||
|
const showToast = useShowToast();
|
||||||
|
|
||||||
const { fetchOrders } = armService();
|
|
||||||
const { fetchMasters } = armService();
|
|
||||||
|
|
||||||
const toast = useToast();
|
|
||||||
|
|
||||||
const [orders, setOrders] = useState<OrderProps[]>([]);
|
|
||||||
const [allMasters, setAllMasters] = useState<Master[]>([]);
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const [currentDate, setCurrentDate] = useState(new Date());
|
const [currentDate, setCurrentDate] = useState(new Date());
|
||||||
|
const {
|
||||||
|
data: orders,
|
||||||
|
isLoading: isOrdersLoading,
|
||||||
|
isSuccess: isOrdersSuccess,
|
||||||
|
isError: isOrdersError,
|
||||||
|
error: ordersError,
|
||||||
|
} = useGetOrdersQuery({ date: currentDate });
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: masters,
|
||||||
|
isLoading: isMastersLoading,
|
||||||
|
isSuccess: isMastersSuccess,
|
||||||
|
isError: isMastersError,
|
||||||
|
error: mastersError,
|
||||||
|
} = useGetMastersQuery();
|
||||||
|
|
||||||
|
const isLoading = isOrdersLoading || isMastersLoading;
|
||||||
|
const isSuccess = isOrdersSuccess && isMastersSuccess;
|
||||||
|
const isError = isOrdersError || isMastersError;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadData = async () => {
|
if (isError) {
|
||||||
setLoading(true);
|
showToast(t('error.title'), 'error');
|
||||||
setError(null);
|
}
|
||||||
|
}, [isError, ordersError, mastersError, t]);
|
||||||
try {
|
|
||||||
const [ordersData, mastersData] = await Promise.all([
|
|
||||||
fetchOrders({ date: currentDate }),
|
|
||||||
fetchMasters(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
setOrders(ordersData.body);
|
|
||||||
setAllMasters(mastersData.body);
|
|
||||||
} catch (err) {
|
|
||||||
setError(err.message);
|
|
||||||
toast({
|
|
||||||
title: t('error.title'),
|
|
||||||
status: 'error',
|
|
||||||
duration: 5000,
|
|
||||||
isClosable: true,
|
|
||||||
position: 'bottom-right',
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
loadData();
|
|
||||||
}, [currentDate, toast, t]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box p='8'>
|
<Box p='8'>
|
||||||
@ -103,25 +92,24 @@ const Orders = () => {
|
|||||||
</Tr>
|
</Tr>
|
||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
{loading && (
|
{isLoading && (
|
||||||
<Tr>
|
<Tr>
|
||||||
<Td colSpan={TABLE_HEADERS.length} textAlign='center' py='8'>
|
<Td colSpan={TABLE_HEADERS.length} textAlign='center' py='8'>
|
||||||
<Spinner size='lg' />
|
<Spinner size='lg' />
|
||||||
</Td>
|
</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
)}
|
)}
|
||||||
{!loading && orders.length === 0 && !error && (
|
{isSuccess && orders.length === 0 && (
|
||||||
<Tr>
|
<Tr>
|
||||||
<Td colSpan={TABLE_HEADERS.length}>
|
<Td colSpan={TABLE_HEADERS.length}>
|
||||||
<Text>{t('table.empty')}</Text>
|
<Text>{t('table.empty')}</Text>
|
||||||
</Td>
|
</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
)}
|
)}
|
||||||
{!loading &&
|
{isSuccess &&
|
||||||
!error &&
|
|
||||||
orders.map((order, index) => (
|
orders.map((order, index) => (
|
||||||
<OrderItem
|
<OrderItem
|
||||||
allMasters={allMasters}
|
allMasters={masters}
|
||||||
key={index}
|
key={index}
|
||||||
{...order}
|
{...order}
|
||||||
status={order.status as OrderProps['status']}
|
status={order.status as OrderProps['status']}
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
import { UseToastOptions } from '@chakra-ui/react';
|
|
||||||
|
|
||||||
interface ShowToast {
|
|
||||||
toast: (options: UseToastOptions) => void;
|
|
||||||
title: string;
|
|
||||||
description?: string;
|
|
||||||
status: 'info' | 'warning' | 'success' | 'error';
|
|
||||||
}
|
|
||||||
|
|
||||||
const showToast = ({ toast, title, description, status }: ShowToast) => {
|
|
||||||
toast({
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
status,
|
|
||||||
duration: 5000,
|
|
||||||
isClosable: true,
|
|
||||||
position: 'top-right',
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export default showToast;
|
|
28
src/hooks/useShowToast.ts
Normal file
28
src/hooks/useShowToast.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { useToast } from '@chakra-ui/react';
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
const useShowToast = () => {
|
||||||
|
const toast = useToast();
|
||||||
|
|
||||||
|
const showToast = useCallback(
|
||||||
|
(
|
||||||
|
title: string,
|
||||||
|
status: 'info' | 'warning' | 'success' | 'error',
|
||||||
|
description?: string,
|
||||||
|
) => {
|
||||||
|
toast({
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
status,
|
||||||
|
duration: 5000,
|
||||||
|
isClosable: true,
|
||||||
|
position: 'top-right',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[toast],
|
||||||
|
);
|
||||||
|
|
||||||
|
return showToast;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useShowToast;
|
@ -5,9 +5,11 @@ type SuccessResponse<Body> = {
|
|||||||
|
|
||||||
export type ErrorMessage = string;
|
export type ErrorMessage = string;
|
||||||
|
|
||||||
|
export const isErrorMessage = (error: unknown): error is ErrorMessage => typeof error === 'string';
|
||||||
|
|
||||||
type ErrorResponse = {
|
type ErrorResponse = {
|
||||||
success: false;
|
success: false;
|
||||||
message: ErrorMessage;
|
message: ErrorMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BaseResponse<Body> = SuccessResponse<Body> | ErrorResponse;
|
export type BaseResponse<Body> = SuccessResponse<Body> | ErrorResponse;
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export * from './common';
|
export * from './common';
|
||||||
export * from './order';
|
export * from './order';
|
||||||
|
export * from './master';
|
||||||
|
@ -1,21 +1,49 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-namespace */
|
/* eslint-disable @typescript-eslint/no-namespace */
|
||||||
import { Order } from "../landing";
|
import { Order } from '../landing';
|
||||||
|
|
||||||
import { ErrorMessage } from "./common";
|
import { ErrorMessage } from './common';
|
||||||
|
import { Master } from './master';
|
||||||
|
|
||||||
export namespace GetOrder {
|
export namespace GetOrder {
|
||||||
export type Response = Order.View;
|
export type Response = Order.View;
|
||||||
export type Params = {
|
export type Params = {
|
||||||
orderId: Order.Id
|
orderId: Order.Id;
|
||||||
};
|
};
|
||||||
export type Error = ErrorMessage;
|
export type Error = ErrorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace CreateOrder {
|
export namespace CreateOrder {
|
||||||
export type Response = {
|
export type Response = {
|
||||||
id: Order.Id
|
id: Order.Id;
|
||||||
};
|
};
|
||||||
export type Params = {
|
export type Params = {
|
||||||
body: Order.Create
|
body: Order.Create;
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
|
type GetArrItemType<ArrType> =
|
||||||
|
ArrType extends Array<infer ItemType> ? ItemType : never;
|
||||||
|
|
||||||
|
export const statuses = [
|
||||||
|
'pending' as const,
|
||||||
|
'progress' as const,
|
||||||
|
'working' as const,
|
||||||
|
'canceled' as const,
|
||||||
|
'complete' as const,
|
||||||
|
];
|
||||||
|
|
||||||
|
export type Status = (typeof statuses)[number];
|
||||||
|
|
||||||
|
export type OrderArm = {
|
||||||
|
carNumber?: string;
|
||||||
|
startWashTime?: string;
|
||||||
|
endWashTime?: string;
|
||||||
|
orderDate?: string;
|
||||||
|
status?: GetArrItemType<typeof statuses>;
|
||||||
|
phone?: string;
|
||||||
|
location?: string;
|
||||||
|
master: Master;
|
||||||
|
notes: '';
|
||||||
|
allMasters: Master[];
|
||||||
|
id: string;
|
||||||
|
};
|
||||||
|
@ -6,58 +6,58 @@ exports[`Arm Page render 1`] = `
|
|||||||
class="css-1yeiifd"
|
class="css-1yeiifd"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="css-1fp6kaj"
|
class="css-13owfwq"
|
||||||
>
|
>
|
||||||
<h2
|
<h2
|
||||||
class="chakra-heading css-9q1d0h"
|
class="chakra-heading css-173d1bl"
|
||||||
>
|
>
|
||||||
title
|
Сухой мастер
|
||||||
</h2>
|
</h2>
|
||||||
<div
|
<div
|
||||||
class="chakra-stack css-1oen434"
|
class="chakra-stack css-1cggwyz"
|
||||||
>
|
>
|
||||||
<hr
|
<hr
|
||||||
aria-orientation="horizontal"
|
aria-orientation="horizontal"
|
||||||
class="chakra-divider css-1upb9tn"
|
class="chakra-divider css-svjswr"
|
||||||
/>
|
/>
|
||||||
<a
|
<a
|
||||||
class="chakra-button css-uxt1e8"
|
class="chakra-button css-1kg18wp"
|
||||||
href="/auth/login"
|
href="/auth/login"
|
||||||
>
|
>
|
||||||
orders
|
Заказы
|
||||||
</a>
|
</a>
|
||||||
<hr
|
<hr
|
||||||
aria-orientation="horizontal"
|
aria-orientation="horizontal"
|
||||||
class="chakra-divider css-1upb9tn"
|
class="chakra-divider css-svjswr"
|
||||||
/>
|
/>
|
||||||
<a
|
<a
|
||||||
class="chakra-button css-uxt1e8"
|
class="chakra-button css-1kg18wp"
|
||||||
href="/auth/login"
|
href="/auth/login"
|
||||||
>
|
>
|
||||||
master
|
Мастера
|
||||||
</a>
|
</a>
|
||||||
<hr
|
<hr
|
||||||
aria-orientation="horizontal"
|
aria-orientation="horizontal"
|
||||||
class="chakra-divider css-1upb9tn"
|
class="chakra-divider css-svjswr"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="css-sy55x5"
|
class="css-jiwy8d"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="css-hpgf8j"
|
class="css-1glkkdp"
|
||||||
>
|
>
|
||||||
<h2
|
<h2
|
||||||
class="chakra-heading css-r7q7qr"
|
class="chakra-heading css-1xer3cv"
|
||||||
>
|
>
|
||||||
title
|
Заказы
|
||||||
</h2>
|
</h2>
|
||||||
<div
|
<div
|
||||||
class="css-1me9tx"
|
class="css-1u3smh"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="chakra-button css-4xx2wk"
|
class="chakra-button css-ez23ye"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
@ -72,12 +72,12 @@ exports[`Arm Page render 1`] = `
|
|||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<p
|
<p
|
||||||
class="chakra-text css-1bntq7d"
|
class="chakra-text css-52ukzg"
|
||||||
>
|
>
|
||||||
2/2/2025
|
09.02.2025
|
||||||
</p>
|
</p>
|
||||||
<button
|
<button
|
||||||
class="chakra-button css-4xx2wk"
|
class="chakra-button css-ez23ye"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
@ -93,7 +93,7 @@ exports[`Arm Page render 1`] = `
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<table
|
<table
|
||||||
class="chakra-table css-0"
|
class="chakra-table css-5605sr"
|
||||||
>
|
>
|
||||||
<thead
|
<thead
|
||||||
class="css-0"
|
class="css-0"
|
||||||
@ -102,34 +102,34 @@ exports[`Arm Page render 1`] = `
|
|||||||
class="css-0"
|
class="css-0"
|
||||||
>
|
>
|
||||||
<th
|
<th
|
||||||
class="css-0"
|
class="css-1szkfps"
|
||||||
>
|
>
|
||||||
table.header.carNumber
|
Номер машины
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
class="css-0"
|
class="css-1szkfps"
|
||||||
>
|
>
|
||||||
table.header.orderDate
|
Дата заказа
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
class="css-0"
|
class="css-1szkfps"
|
||||||
>
|
>
|
||||||
table.header.status
|
Статус
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
class="css-0"
|
class="css-1szkfps"
|
||||||
>
|
>
|
||||||
table.header.masters
|
Мастер
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
class="css-0"
|
class="css-1szkfps"
|
||||||
>
|
>
|
||||||
table.header.telephone
|
Телефон
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
class="css-0"
|
class="css-1szkfps"
|
||||||
>
|
>
|
||||||
table.header.location
|
Расположение
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -140,11 +140,11 @@ exports[`Arm Page render 1`] = `
|
|||||||
class="css-0"
|
class="css-0"
|
||||||
>
|
>
|
||||||
<td
|
<td
|
||||||
class="css-12rlgei"
|
class="css-1v9gmks"
|
||||||
colspan="6"
|
colspan="6"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="chakra-spinner css-1y7joxr"
|
class="chakra-spinner css-1j92705"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
class="css-8b45rq"
|
class="css-8b45rq"
|
||||||
@ -159,6 +159,10 @@ exports[`Arm Page render 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<span
|
||||||
|
hidden=""
|
||||||
|
id="__chakra_env"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -168,58 +172,58 @@ exports[`Arm Page render 2`] = `
|
|||||||
class="css-1yeiifd"
|
class="css-1yeiifd"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="css-1fp6kaj"
|
class="css-13owfwq"
|
||||||
>
|
>
|
||||||
<h2
|
<h2
|
||||||
class="chakra-heading css-9q1d0h"
|
class="chakra-heading css-173d1bl"
|
||||||
>
|
>
|
||||||
title
|
Сухой мастер
|
||||||
</h2>
|
</h2>
|
||||||
<div
|
<div
|
||||||
class="chakra-stack css-1oen434"
|
class="chakra-stack css-1cggwyz"
|
||||||
>
|
>
|
||||||
<hr
|
<hr
|
||||||
aria-orientation="horizontal"
|
aria-orientation="horizontal"
|
||||||
class="chakra-divider css-1upb9tn"
|
class="chakra-divider css-svjswr"
|
||||||
/>
|
/>
|
||||||
<a
|
<a
|
||||||
class="chakra-button css-uxt1e8"
|
class="chakra-button css-1kg18wp"
|
||||||
href="/auth/login"
|
href="/auth/login"
|
||||||
>
|
>
|
||||||
orders
|
Заказы
|
||||||
</a>
|
</a>
|
||||||
<hr
|
<hr
|
||||||
aria-orientation="horizontal"
|
aria-orientation="horizontal"
|
||||||
class="chakra-divider css-1upb9tn"
|
class="chakra-divider css-svjswr"
|
||||||
/>
|
/>
|
||||||
<a
|
<a
|
||||||
class="chakra-button css-uxt1e8"
|
class="chakra-button css-1kg18wp"
|
||||||
href="/auth/login"
|
href="/auth/login"
|
||||||
>
|
>
|
||||||
master
|
Мастера
|
||||||
</a>
|
</a>
|
||||||
<hr
|
<hr
|
||||||
aria-orientation="horizontal"
|
aria-orientation="horizontal"
|
||||||
class="chakra-divider css-1upb9tn"
|
class="chakra-divider css-svjswr"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="css-sy55x5"
|
class="css-jiwy8d"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="css-hpgf8j"
|
class="css-1glkkdp"
|
||||||
>
|
>
|
||||||
<h2
|
<h2
|
||||||
class="chakra-heading css-r7q7qr"
|
class="chakra-heading css-1xer3cv"
|
||||||
>
|
>
|
||||||
title
|
Заказы
|
||||||
</h2>
|
</h2>
|
||||||
<div
|
<div
|
||||||
class="css-1me9tx"
|
class="css-1u3smh"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="chakra-button css-4xx2wk"
|
class="chakra-button css-ez23ye"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
@ -234,12 +238,12 @@ exports[`Arm Page render 2`] = `
|
|||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<p
|
<p
|
||||||
class="chakra-text css-1bntq7d"
|
class="chakra-text css-52ukzg"
|
||||||
>
|
>
|
||||||
2/2/2025
|
09.02.2025
|
||||||
</p>
|
</p>
|
||||||
<button
|
<button
|
||||||
class="chakra-button css-4xx2wk"
|
class="chakra-button css-ez23ye"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
@ -255,7 +259,7 @@ exports[`Arm Page render 2`] = `
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<table
|
<table
|
||||||
class="chakra-table css-0"
|
class="chakra-table css-5605sr"
|
||||||
>
|
>
|
||||||
<thead
|
<thead
|
||||||
class="css-0"
|
class="css-0"
|
||||||
@ -264,34 +268,34 @@ exports[`Arm Page render 2`] = `
|
|||||||
class="css-0"
|
class="css-0"
|
||||||
>
|
>
|
||||||
<th
|
<th
|
||||||
class="css-0"
|
class="css-1szkfps"
|
||||||
>
|
>
|
||||||
table.header.carNumber
|
Номер машины
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
class="css-0"
|
class="css-1szkfps"
|
||||||
>
|
>
|
||||||
table.header.orderDate
|
Дата заказа
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
class="css-0"
|
class="css-1szkfps"
|
||||||
>
|
>
|
||||||
table.header.status
|
Статус
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
class="css-0"
|
class="css-1szkfps"
|
||||||
>
|
>
|
||||||
table.header.masters
|
Мастер
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
class="css-0"
|
class="css-1szkfps"
|
||||||
>
|
>
|
||||||
table.header.telephone
|
Телефон
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
class="css-0"
|
class="css-1szkfps"
|
||||||
>
|
>
|
||||||
table.header.location
|
Расположение
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -302,24 +306,288 @@ exports[`Arm Page render 2`] = `
|
|||||||
class="css-0"
|
class="css-0"
|
||||||
>
|
>
|
||||||
<td
|
<td
|
||||||
class="css-12rlgei"
|
class="css-zgoslk"
|
||||||
colspan="6"
|
>
|
||||||
|
A123BC
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="css-zgoslk"
|
||||||
|
>
|
||||||
|
24.11.2024
|
||||||
|
|
||||||
|
<br />
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="css-zgoslk"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="chakra-spinner css-1y7joxr"
|
class="chakra-select__wrapper css-42b2qy"
|
||||||
>
|
>
|
||||||
<span
|
<select
|
||||||
class="css-8b45rq"
|
class="chakra-select css-11j19cx"
|
||||||
>
|
>
|
||||||
Loading...
|
<option
|
||||||
</span>
|
value=""
|
||||||
|
>
|
||||||
|
Выберите статус
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="pending"
|
||||||
|
>
|
||||||
|
В ожидании
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="progress"
|
||||||
|
>
|
||||||
|
Выполняется
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="working"
|
||||||
|
>
|
||||||
|
В работе
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="canceled"
|
||||||
|
>
|
||||||
|
Отменено
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="complete"
|
||||||
|
>
|
||||||
|
Завершено
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<div
|
||||||
|
class="chakra-select__icon-wrapper css-iohxn1"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
class="chakra-select__icon"
|
||||||
|
focusable="false"
|
||||||
|
role="presentation"
|
||||||
|
style="width: 1em; height: 1em; color: currentColor;"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
<td
|
||||||
|
class="css-zgoslk"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="chakra-select__wrapper css-42b2qy"
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
class="chakra-select css-161pkch"
|
||||||
|
>
|
||||||
|
<option
|
||||||
|
value=""
|
||||||
|
>
|
||||||
|
Выберите мастера
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="Иван Иванов"
|
||||||
|
>
|
||||||
|
Иван Иванов
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="Олег Макаров"
|
||||||
|
>
|
||||||
|
Олег Макаров
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="Иван Галкин"
|
||||||
|
>
|
||||||
|
Иван Галкин
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<div
|
||||||
|
class="chakra-select__icon-wrapper css-iohxn1"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
class="chakra-select__icon"
|
||||||
|
focusable="false"
|
||||||
|
role="presentation"
|
||||||
|
style="width: 1em; height: 1em; color: currentColor;"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="css-zgoslk"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
class="chakra-link css-spn4bz"
|
||||||
|
href="tel:"
|
||||||
|
>
|
||||||
|
79001234563
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="css-zgoslk"
|
||||||
|
>
|
||||||
|
Казань, ул. Баумана, 1
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr
|
||||||
|
class="css-0"
|
||||||
|
>
|
||||||
|
<td
|
||||||
|
class="css-zgoslk"
|
||||||
|
>
|
||||||
|
A245BC
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="css-zgoslk"
|
||||||
|
>
|
||||||
|
24.11.2024
|
||||||
|
|
||||||
|
<br />
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="css-zgoslk"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="chakra-select__wrapper css-42b2qy"
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
class="chakra-select css-lvra4l"
|
||||||
|
>
|
||||||
|
<option
|
||||||
|
value=""
|
||||||
|
>
|
||||||
|
Выберите статус
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="pending"
|
||||||
|
>
|
||||||
|
В ожидании
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="progress"
|
||||||
|
>
|
||||||
|
Выполняется
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="working"
|
||||||
|
>
|
||||||
|
В работе
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="canceled"
|
||||||
|
>
|
||||||
|
Отменено
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="complete"
|
||||||
|
>
|
||||||
|
Завершено
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<div
|
||||||
|
class="chakra-select__icon-wrapper css-iohxn1"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
class="chakra-select__icon"
|
||||||
|
focusable="false"
|
||||||
|
role="presentation"
|
||||||
|
style="width: 1em; height: 1em; color: currentColor;"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="css-zgoslk"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="chakra-select__wrapper css-42b2qy"
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
class="chakra-select css-161pkch"
|
||||||
|
>
|
||||||
|
<option
|
||||||
|
value=""
|
||||||
|
>
|
||||||
|
Выберите мастера
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="Иван Иванов"
|
||||||
|
>
|
||||||
|
Иван Иванов
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="Олег Макаров"
|
||||||
|
>
|
||||||
|
Олег Макаров
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="Иван Галкин"
|
||||||
|
>
|
||||||
|
Иван Галкин
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<div
|
||||||
|
class="chakra-select__icon-wrapper css-iohxn1"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
class="chakra-select__icon"
|
||||||
|
focusable="false"
|
||||||
|
role="presentation"
|
||||||
|
style="width: 1em; height: 1em; color: currentColor;"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="css-zgoslk"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
class="chakra-link css-spn4bz"
|
||||||
|
href="tel:"
|
||||||
|
>
|
||||||
|
79001234567
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="css-zgoslk"
|
||||||
|
>
|
||||||
|
Казань, ул. Баумана, 43
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<span
|
||||||
|
hidden=""
|
||||||
|
id="__chakra_env"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -12,7 +12,11 @@ import { render, screen, waitFor } from '@testing-library/react';
|
|||||||
import { http, HttpResponse } from 'msw';
|
import { http, HttpResponse } from 'msw';
|
||||||
import { setupServer } from 'msw/node';
|
import { setupServer } from 'msw/node';
|
||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
|
import { ChakraProvider, theme as chakraTheme } from '@chakra-ui/react';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
|
||||||
|
import ErrorBoundary from '../../components/ErrorBoundary';
|
||||||
|
import { store } from '../../__data__/store';
|
||||||
import Page from '../arm';
|
import Page from '../arm';
|
||||||
|
|
||||||
const server = setupServer(
|
const server = setupServer(
|
||||||
@ -87,17 +91,6 @@ const server = setupServer(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
jest.mock('react-i18next', () => {
|
|
||||||
return {
|
|
||||||
useTranslation: () => {
|
|
||||||
return {
|
|
||||||
t: (key: never) => `${key}`,
|
|
||||||
i18n: {},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
jest.mock('@brojs/cli', () => {
|
jest.mock('@brojs/cli', () => {
|
||||||
return {
|
return {
|
||||||
getNavigationValue: () => '/auth/login',
|
getNavigationValue: () => '/auth/login',
|
||||||
@ -116,9 +109,15 @@ describe('Arm Page', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<BrowserRouter>
|
<Provider store={store}>
|
||||||
<Page mockUser={{ name: 'ilnaz' }} />
|
<ChakraProvider theme={chakraTheme}>
|
||||||
</BrowserRouter>,
|
<ErrorBoundary>
|
||||||
|
<BrowserRouter>
|
||||||
|
<Page mockUser={{ name: 'ilnaz' }} />
|
||||||
|
</BrowserRouter>
|
||||||
|
</ErrorBoundary>
|
||||||
|
</ChakraProvider>
|
||||||
|
</Provider>,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(container).toMatchSnapshot();
|
expect(container).toMatchSnapshot();
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
import { useToast } from "@chakra-ui/react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import { Order } from "../../models/landing";
|
import { Order } from "../../models/landing";
|
||||||
import { OrderFormValues } from "../../components/order-form";
|
import { OrderFormValues } from "../../components/order-form";
|
||||||
|
import { isErrorMessage } from "../../models/api";
|
||||||
|
import { URLs } from '../../__data__/urls';
|
||||||
|
|
||||||
const removeAllSpaces = (str: string) => str.replace(/\s+/g, '');
|
const removeAllSpaces = (str: string) => str.replace(/\s+/g, '');
|
||||||
|
|
||||||
@ -26,4 +32,40 @@ export const formatFormValues = ({ phone, carNumber, carBody, carColor, carLocat
|
|||||||
end: dayjs(availableDatetimeEnd).toISOString(),
|
end: dayjs(availableDatetimeEnd).toISOString(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useHandleCreateOrderMutationResponse = (query: {
|
||||||
|
isSuccess: boolean;
|
||||||
|
data?: {
|
||||||
|
id: Parameters<typeof URLs.orderView.getUrl>[0];
|
||||||
|
};
|
||||||
|
isError: boolean;
|
||||||
|
error?: unknown;
|
||||||
|
}) => {
|
||||||
|
const toast = useToast();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { t } = useTranslation('~', {
|
||||||
|
keyPrefix: 'dry-wash.order-create.create-order-query',
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (query.isError) {
|
||||||
|
toast({
|
||||||
|
status: 'error',
|
||||||
|
title: t('error.title'),
|
||||||
|
description: isErrorMessage(query.error) ? query.error : undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [query.isError]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (query.isSuccess) {
|
||||||
|
const orderId = query.data.id;
|
||||||
|
navigate({ pathname: URLs.orderView.getUrl(orderId) });
|
||||||
|
toast({
|
||||||
|
status: 'success',
|
||||||
|
title: t('success.title'),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [query.isSuccess]);
|
||||||
|
};
|
||||||
|
@ -1,41 +1,29 @@
|
|||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Container, Heading, useToast, VStack } from '@chakra-ui/react';
|
import { Container, Heading, VStack } from '@chakra-ui/react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { Player as LottiePlayer } from '@lottiefiles/react-lottie-player';
|
||||||
|
|
||||||
import { withLandingThemeProvider } from '../../containers';
|
import { withLandingThemeProvider } from '../../containers';
|
||||||
import { OrderForm, OrderFormProps } from '../../components/order-form';
|
import { OrderForm, OrderFormProps } from '../../components/order-form';
|
||||||
import { useCreateOrderMutation } from '../../api';
|
import { landingApi } from '../../__data__/service/landing.api';
|
||||||
import { URLs } from '../../__data__/urls';
|
import { OrderCreationAnimation } from '../../assets/animation';
|
||||||
|
|
||||||
import { formatFormValues } from './helper';
|
import {
|
||||||
|
formatFormValues,
|
||||||
|
useHandleCreateOrderMutationResponse,
|
||||||
|
} from './helper';
|
||||||
|
|
||||||
const Page: FC = () => {
|
const Page: FC = () => {
|
||||||
const { t } = useTranslation('~', {
|
const { t } = useTranslation('~', {
|
||||||
keyPrefix: 'dry-wash.order-create',
|
keyPrefix: 'dry-wash.order-create',
|
||||||
});
|
});
|
||||||
|
|
||||||
const [createOrder, createOrderMutation] = useCreateOrderMutation();
|
const [createOrder, createOrderMutation] =
|
||||||
|
landingApi.useCreateOrderMutation();
|
||||||
const toast = useToast();
|
useHandleCreateOrderMutationResponse(createOrderMutation);
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
const onOrderFormSubmit: OrderFormProps['onSubmit'] = (values) => {
|
const onOrderFormSubmit: OrderFormProps['onSubmit'] = (values) => {
|
||||||
createOrder({ body: formatFormValues(values) })
|
createOrder({ body: formatFormValues(values) });
|
||||||
.then(({ body: { id: orderId } }) => {
|
|
||||||
navigate({ pathname: URLs.orderView.getUrl(orderId) });
|
|
||||||
toast({
|
|
||||||
status: 'success',
|
|
||||||
title: t('create-order-query.success.title'),
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(({ error: errorMessage }) => {
|
|
||||||
toast({
|
|
||||||
status: 'error',
|
|
||||||
title: t('create-order-query.error.title'),
|
|
||||||
description: errorMessage,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -48,13 +36,24 @@ const Page: FC = () => {
|
|||||||
centerContent
|
centerContent
|
||||||
>
|
>
|
||||||
<VStack w='full' h='full' alignItems='stretch' flexGrow={1}>
|
<VStack w='full' h='full' alignItems='stretch' flexGrow={1}>
|
||||||
<Heading textAlign='center' mt={4}>
|
{createOrderMutation.isUninitialized ? (
|
||||||
{t('title')}
|
<>
|
||||||
</Heading>
|
<Heading textAlign='center' mt={4}>
|
||||||
<OrderForm
|
{t('title')}
|
||||||
onSubmit={onOrderFormSubmit}
|
</Heading>
|
||||||
loading={createOrderMutation.isLoading}
|
<OrderForm
|
||||||
/>
|
onSubmit={onOrderFormSubmit}
|
||||||
|
loading={createOrderMutation.isLoading}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<LottiePlayer autoplay loop src={OrderCreationAnimation} />
|
||||||
|
<Heading textAlign='center' mt={4}>
|
||||||
|
{t('order-creation-title')}
|
||||||
|
</Heading>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</VStack>
|
</VStack>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
|
@ -19,7 +19,7 @@ import {
|
|||||||
import { OrderDetails } from '../../components/order-view';
|
import { OrderDetails } from '../../components/order-view';
|
||||||
import { Order } from '../../models/landing';
|
import { Order } from '../../models/landing';
|
||||||
import { landingApi } from '../../__data__/service/landing.api';
|
import { landingApi } from '../../__data__/service/landing.api';
|
||||||
import { ErrorMessage } from '../../models/api';
|
import { isErrorMessage } from '../../models/api';
|
||||||
import { FEATURE } from '../../__data__/features';
|
import { FEATURE } from '../../__data__/features';
|
||||||
|
|
||||||
const Page: FC = () => {
|
const Page: FC = () => {
|
||||||
@ -45,7 +45,7 @@ const Page: FC = () => {
|
|||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
);
|
);
|
||||||
const errorMessage = error as ErrorMessage;
|
const errorMessage = isErrorMessage(error) ? error : undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LandingThemeProvider>
|
<LandingThemeProvider>
|
||||||
@ -91,7 +91,9 @@ const Page: FC = () => {
|
|||||||
<AlertTitle>
|
<AlertTitle>
|
||||||
{t('get-order-query.error.title')}
|
{t('get-order-query.error.title')}
|
||||||
</AlertTitle>
|
</AlertTitle>
|
||||||
<AlertDescription>{errorMessage}</AlertDescription>
|
{errorMessage && (
|
||||||
|
<AlertDescription>{errorMessage}</AlertDescription>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
||||||
const router = require('express').Router();
|
const router = require('express').Router();
|
||||||
|
|
||||||
const STUBS = { masters: 'success', orders: 'success', orderView: 'success-pending' };
|
const STUBS = { masters: 'success', orders: 'success', orderCreate: 'success', orderView: 'success-pending' };
|
||||||
|
|
||||||
router.get('/set/:name/:value', (req, res) => {
|
router.get('/set/:name/:value', (req, res) => {
|
||||||
const { name, value } = req.params;
|
const { name, value } = req.params;
|
||||||
@ -14,19 +14,24 @@ router.get('/set/:name/:value', (req, res) => {
|
|||||||
|
|
||||||
router.get('/', (req, res) => {
|
router.get('/', (req, res) => {
|
||||||
res.send(`<div>
|
res.send(`<div>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Мастера</legend>
|
<legend>Мастера</legend>
|
||||||
${generateRadioInput('masters', 'success')}
|
${generateRadioInput('masters', 'success')}
|
||||||
${generateRadioInput('masters', 'error')}
|
${generateRadioInput('masters', 'error')}
|
||||||
${generateRadioInput('masters', 'empty')}
|
${generateRadioInput('masters', 'empty')}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Заказы</legend>
|
<legend>Заказы</legend>
|
||||||
${generateRadioInput('orders', 'success')}
|
${generateRadioInput('orders', 'success')}
|
||||||
${generateRadioInput('orders', 'error')}
|
${generateRadioInput('orders', 'error')}
|
||||||
${generateRadioInput('orders', 'empty')}
|
${generateRadioInput('orders', 'empty')}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
<legend>Лендинг - Сделать заказ</legend>
|
||||||
|
${generateRadioInput('orderCreate', 'success')}
|
||||||
|
${generateRadioInput('orderCreate', 'error')}
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
<legend>Лендинг - Детали заказа</legend>
|
<legend>Лендинг - Детали заказа</legend>
|
||||||
${generateRadioInput('orderView', 'success-pending')}
|
${generateRadioInput('orderView', 'success-pending')}
|
||||||
${generateRadioInput('orderView', 'success-working')}
|
${generateRadioInput('orderView', 'success-working')}
|
||||||
|
@ -53,7 +53,7 @@ router.delete('/arm/masters/:id', (req, res) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch('/orders/:id', (req, res) => {
|
router.patch('/order/:id', (req, res) => {
|
||||||
res
|
res
|
||||||
.status(/error/.test(STUBS.orders) ? 500 : 200)
|
.status(/error/.test(STUBS.orders) ? 500 : 200)
|
||||||
.send(
|
.send(
|
||||||
@ -87,7 +87,15 @@ router.get('/order/:orderId', ({ params }, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.post('/order/create', (req, res) => {
|
router.post('/order/create', (req, res) => {
|
||||||
res.status(200).send({ success: true, body: { ok: true } });
|
const stubName = STUBS.orderCreate;
|
||||||
|
|
||||||
|
res
|
||||||
|
.status(/error/.test(stubName) ? 500 : 200)
|
||||||
|
.send(
|
||||||
|
/^error$/.test(stubName)
|
||||||
|
? commonError
|
||||||
|
: require(`../json/landing-order-create/${stubName}.json`),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.use('/admin', require('./admin'));
|
router.use('/admin', require('./admin'));
|
||||||
|
4
stubs/json/landing-order-create/error.json
Normal file
4
stubs/json/landing-order-create/error.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "Не удалось создать заказ"
|
||||||
|
}
|
6
stubs/json/landing-order-create/success.json
Normal file
6
stubs/json/landing-order-create/success.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"body": {
|
||||||
|
"id": "id1"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user