Compare commits
1 Commits
feature/rt
...
feature/pl
| Author | SHA1 | Date | |
|---|---|---|---|
| 859fa4f2e1 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -131,3 +131,9 @@ dist
|
|||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
|
# Playwright
|
||||||
|
/test-results/
|
||||||
|
/playwright-report/
|
||||||
|
/blob-report/
|
||||||
|
/playwright/.cache/
|
||||||
|
|||||||
@@ -25,16 +25,10 @@
|
|||||||
"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": "Введите ФИО",
|
||||||
|
|||||||
77
package-lock.json
generated
77
package-lock.json
generated
@@ -48,7 +48,9 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.14.0",
|
"@eslint/js": "^9.14.0",
|
||||||
|
"@playwright/test": "^1.50.1",
|
||||||
"@stylistic/eslint-plugin": "^2.10.1",
|
"@stylistic/eslint-plugin": "^2.10.1",
|
||||||
|
"@types/node": "^22.13.1",
|
||||||
"@types/react-dom": "^18.3.1",
|
"@types/react-dom": "^18.3.1",
|
||||||
"eslint": "^9.14.0",
|
"eslint": "^9.14.0",
|
||||||
"eslint-plugin-import": "^2.31.0",
|
"eslint-plugin-import": "^2.31.0",
|
||||||
@@ -3619,6 +3621,21 @@
|
|||||||
"node": ">=14"
|
"node": ">=14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@playwright/test": {
|
||||||
|
"version": "1.50.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.50.1.tgz",
|
||||||
|
"integrity": "sha512-Jii3aBg+CEDpgnuDxEp/h7BimHcUTDlpEtce89xEumlJ5ef2hqepZ+PWp1DDpYC/VO9fmWVI1IlEaoI5fK9FXQ==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"playwright": "1.50.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"playwright": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@popperjs/core": {
|
"node_modules/@popperjs/core": {
|
||||||
"version": "2.11.8",
|
"version": "2.11.8",
|
||||||
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
|
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
|
||||||
@@ -4003,12 +4020,11 @@
|
|||||||
"integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA=="
|
"integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA=="
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "22.9.0",
|
"version": "22.13.1",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.1.tgz",
|
||||||
"integrity": "sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==",
|
"integrity": "sha512-jK8uzQlrvXqEU91UxiK5J7pKHyzgnI1Qnl0QDHIgVGuolJhRb9EEl28Cj9b3rGR8B2lhFCtvIm5os8lFnO/1Ew==",
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~6.19.8"
|
"undici-types": "~6.20.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/parse-json": {
|
"node_modules/@types/parse-json": {
|
||||||
@@ -12110,6 +12126,50 @@
|
|||||||
"node": ">=4"
|
"node": ">=4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/playwright": {
|
||||||
|
"version": "1.50.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.50.1.tgz",
|
||||||
|
"integrity": "sha512-G8rwsOQJ63XG6BbKj2w5rHeavFjy5zynBA9zsJMMtBoe/Uf757oG12NXz6e6OirF7RCrTVAKFXbLmn1RbL7Qaw==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"playwright-core": "1.50.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"playwright": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"fsevents": "2.3.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/playwright-core": {
|
||||||
|
"version": "1.50.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.50.1.tgz",
|
||||||
|
"integrity": "sha512-ra9fsNWayuYumt+NiM069M6OkcRb1FZSK8bgi66AtpFoWkg2+y0bJSNmkFrWhMbEBbVKC/EruAHH3g0zmtwGmQ==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"playwright-core": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/playwright/node_modules/fsevents": {
|
||||||
|
"version": "2.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||||
|
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||||
|
"dev": true,
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/popmotion": {
|
"node_modules/popmotion": {
|
||||||
"version": "11.0.3",
|
"version": "11.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/popmotion/-/popmotion-11.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/popmotion/-/popmotion-11.0.3.tgz",
|
||||||
@@ -14382,10 +14442,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/undici-types": {
|
"node_modules/undici-types": {
|
||||||
"version": "6.19.8",
|
"version": "6.20.0",
|
||||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
|
||||||
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
|
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="
|
||||||
"license": "MIT"
|
|
||||||
},
|
},
|
||||||
"node_modules/unicode-canonical-property-names-ecmascript": {
|
"node_modules/unicode-canonical-property-names-ecmascript": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
|
|||||||
@@ -17,11 +17,11 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@brojs/cli": "^1.8.4",
|
|
||||||
"@babel/core": "^7.26.7",
|
"@babel/core": "^7.26.7",
|
||||||
"@babel/preset-env": "^7.26.7",
|
"@babel/preset-env": "^7.26.7",
|
||||||
"@babel/preset-react": "^7.26.3",
|
"@babel/preset-react": "^7.26.3",
|
||||||
"@babel/preset-typescript": "^7.26.0",
|
"@babel/preset-typescript": "^7.26.0",
|
||||||
|
"@brojs/cli": "^1.8.4",
|
||||||
"@chakra-ui/icons": "^2.2.4",
|
"@chakra-ui/icons": "^2.2.4",
|
||||||
"@chakra-ui/react": "^2.10.5",
|
"@chakra-ui/react": "^2.10.5",
|
||||||
"@emotion/react": "^11.4.1",
|
"@emotion/react": "^11.4.1",
|
||||||
@@ -56,7 +56,9 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.14.0",
|
"@eslint/js": "^9.14.0",
|
||||||
|
"@playwright/test": "^1.50.1",
|
||||||
"@stylistic/eslint-plugin": "^2.10.1",
|
"@stylistic/eslint-plugin": "^2.10.1",
|
||||||
|
"@types/node": "^22.13.1",
|
||||||
"@types/react-dom": "^18.3.1",
|
"@types/react-dom": "^18.3.1",
|
||||||
"eslint": "^9.14.0",
|
"eslint": "^9.14.0",
|
||||||
"eslint-plugin-import": "^2.31.0",
|
"eslint-plugin-import": "^2.31.0",
|
||||||
|
|||||||
79
playwright.config.ts
Normal file
79
playwright.config.ts
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import { defineConfig, devices } from '@playwright/test';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read environment variables from file.
|
||||||
|
* https://github.com/motdotla/dotenv
|
||||||
|
*/
|
||||||
|
// import dotenv from 'dotenv';
|
||||||
|
// import path from 'path';
|
||||||
|
// dotenv.config({ path: path.resolve(__dirname, '.env') });
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See https://playwright.dev/docs/test-configuration.
|
||||||
|
*/
|
||||||
|
export default defineConfig({
|
||||||
|
testDir: './tests',
|
||||||
|
/* Run tests in files in parallel */
|
||||||
|
fullyParallel: true,
|
||||||
|
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||||
|
forbidOnly: !!process.env.CI,
|
||||||
|
/* Retry on CI only */
|
||||||
|
retries: process.env.CI ? 2 : 0,
|
||||||
|
/* Opt out of parallel tests on CI. */
|
||||||
|
workers: process.env.CI ? 1 : undefined,
|
||||||
|
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||||
|
reporter: 'html',
|
||||||
|
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||||
|
use: {
|
||||||
|
/* Base URL to use in actions like `await page.goto('/')`. */
|
||||||
|
// baseURL: 'http://127.0.0.1:3000',
|
||||||
|
|
||||||
|
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||||
|
trace: 'on-first-retry',
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Configure projects for major browsers */
|
||||||
|
projects: [
|
||||||
|
{
|
||||||
|
name: 'chromium',
|
||||||
|
use: { ...devices['Desktop Chrome'] },
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'firefox',
|
||||||
|
use: { ...devices['Desktop Firefox'] },
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'webkit',
|
||||||
|
use: { ...devices['Desktop Safari'] },
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Test against mobile viewports. */
|
||||||
|
// {
|
||||||
|
// name: 'Mobile Chrome',
|
||||||
|
// use: { ...devices['Pixel 5'] },
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// name: 'Mobile Safari',
|
||||||
|
// use: { ...devices['iPhone 12'] },
|
||||||
|
// },
|
||||||
|
|
||||||
|
/* Test against branded browsers. */
|
||||||
|
// {
|
||||||
|
// name: 'Microsoft Edge',
|
||||||
|
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// name: 'Google Chrome',
|
||||||
|
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
|
||||||
|
// },
|
||||||
|
],
|
||||||
|
|
||||||
|
/* Run your local dev server before starting the tests */
|
||||||
|
// webServer: {
|
||||||
|
// command: 'npm run start',
|
||||||
|
// url: 'http://127.0.0.1:3000',
|
||||||
|
// reuseExistingServer: !process.env.CI,
|
||||||
|
// },
|
||||||
|
});
|
||||||
@@ -1,51 +1,20 @@
|
|||||||
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, OrderArm } from '../../models/api';
|
import { Master } from '../../models/api/master';
|
||||||
|
|
||||||
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({ baseUrl: getConfigValue('dry-wash.api') }),
|
||||||
tagTypes: ['Masters', 'Orders'],
|
tagTypes: ['Masters'],
|
||||||
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',
|
||||||
@@ -54,29 +23,5 @@ 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;
|
|
||||||
|
|||||||
139
src/api/arm.ts
Normal file
139
src/api/arm.ts
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
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,4 +1,4 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Editable,
|
Editable,
|
||||||
EditableInput,
|
EditableInput,
|
||||||
@@ -9,51 +9,63 @@ 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;
|
||||||
fieldName: 'phone' | 'name';
|
onSubmit: ({
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
phone,
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
name?: string;
|
||||||
|
phone?: string;
|
||||||
|
}) => Promise<unknown>;
|
||||||
|
as: 'phone' | 'name';
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EditableWrapper = ({ value, fieldName, id }: EditableWrapperProps) => {
|
const EditableWrapper = ({ value, onSubmit, as, 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 showToast = useShowToast();
|
const toast = useToast();
|
||||||
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;
|
||||||
|
|
||||||
await updateMaster({ id, [fieldName]: newValue });
|
try {
|
||||||
|
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, { useEffect } from 'react';
|
import React 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 { useDeleteMasterMutation } from '../../__data__/service/api';
|
import { armService } from '../../api/arm';
|
||||||
import useShowToast from '../../hooks/useShowToast';
|
|
||||||
|
|
||||||
interface MasterActionsMenu {
|
interface MasterActionsMenu {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -21,35 +21,38 @@ const MasterActionsMenu = ({ id }: MasterActionsMenu) => {
|
|||||||
keyPrefix: 'dry-wash.arm.master.table.actionsMenu',
|
keyPrefix: 'dry-wash.arm.master.table.actionsMenu',
|
||||||
});
|
});
|
||||||
|
|
||||||
const [deleteMaster, { isSuccess, isError, error, isLoading }] =
|
const { deleteMaster } = armService();
|
||||||
useDeleteMasterMutation();
|
const toast = useToast();
|
||||||
|
|
||||||
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} isDisabled={isLoading}>
|
<MenuItem onClick={handleClickDelete}>{t('delete')}</MenuItem>
|
||||||
{t('delete')}
|
|
||||||
</MenuItem>
|
|
||||||
</MenuList>
|
</MenuList>
|
||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
DrawerFooter,
|
DrawerFooter,
|
||||||
DrawerHeader,
|
DrawerHeader,
|
||||||
DrawerOverlay,
|
DrawerOverlay,
|
||||||
|
useToast,
|
||||||
InputGroup,
|
InputGroup,
|
||||||
InputLeftElement,
|
InputLeftElement,
|
||||||
FormErrorMessage,
|
FormErrorMessage,
|
||||||
@@ -19,9 +20,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 { useAddMasterMutation } from '../../__data__/service/api';
|
import { api } 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;
|
||||||
@@ -49,19 +50,28 @@ const MasterDrawer = ({ isOpen, onClose }: MasterDrawerProps) => {
|
|||||||
const isEmptyFields = trimMaster.name === '' || trimMaster.phone === '';
|
const isEmptyFields = trimMaster.name === '' || trimMaster.phone === '';
|
||||||
|
|
||||||
if (isEmptyFields) {
|
if (isEmptyFields) {
|
||||||
showToast(t('toast.error.base'), 'error', t('toast.error.empty-fields'));
|
showToast({
|
||||||
|
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 }] = useAddMasterMutation();
|
const [addMaster, { error, isSuccess }] = api.useAddMasterMutation();
|
||||||
const showToast = useShowToast();
|
const toast = useToast();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
showToast(t('toast.create-master'), 'success');
|
showToast({
|
||||||
|
toast,
|
||||||
|
title: t('toast.create-master'),
|
||||||
|
status: 'success',
|
||||||
|
});
|
||||||
reset();
|
reset();
|
||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
@@ -69,11 +79,12 @@ const MasterDrawer = ({ isOpen, onClose }: MasterDrawerProps) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (error) {
|
if (error) {
|
||||||
showToast(
|
showToast({
|
||||||
t('toast.error.create-master'),
|
toast,
|
||||||
'error',
|
title: t('toast.error.create-master'),
|
||||||
t('toast.error.create-master-details'),
|
description: t('toast.error.create-master-details'),
|
||||||
);
|
status: 'error',
|
||||||
|
});
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
}, [error]);
|
}, [error]);
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ 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',
|
||||||
});
|
});
|
||||||
@@ -14,7 +16,12 @@ const MasterItem = ({ name, phone, id, schedule }) => {
|
|||||||
return (
|
return (
|
||||||
<Tr>
|
<Tr>
|
||||||
<Td>
|
<Td>
|
||||||
<EditableWrapper id={id} fieldName={'name'} value={name} />
|
<EditableWrapper
|
||||||
|
id={id}
|
||||||
|
as={'name'}
|
||||||
|
value={name}
|
||||||
|
onSubmit={updateMaster}
|
||||||
|
/>
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
{schedule?.length > 0 ? (
|
{schedule?.length > 0 ? (
|
||||||
@@ -30,7 +37,12 @@ const MasterItem = ({ name, phone, id, schedule }) => {
|
|||||||
)}
|
)}
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<EditableWrapper id={id} fieldName={'phone'} value={phone} />
|
<EditableWrapper
|
||||||
|
id={id}
|
||||||
|
as={'phone'}
|
||||||
|
value={phone}
|
||||||
|
onSubmit={updateMaster}
|
||||||
|
/>
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<MasterActionsMenu id={id} />
|
<MasterActionsMenu id={id} />
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
useDisclosure,
|
useDisclosure,
|
||||||
Flex,
|
Flex,
|
||||||
|
useToast,
|
||||||
Td,
|
Td,
|
||||||
Text,
|
Text,
|
||||||
Spinner,
|
Spinner,
|
||||||
@@ -18,8 +19,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
|
|
||||||
import MasterItem from '../MasterItem';
|
import MasterItem from '../MasterItem';
|
||||||
import MasterDrawer from '../MasterDrawer';
|
import MasterDrawer from '../MasterDrawer';
|
||||||
import { useGetMastersQuery } from '../../__data__/service/api';
|
import { api } from '../../__data__/service/api';
|
||||||
import useShowToast from '../../hooks/useShowToast';
|
|
||||||
|
|
||||||
const TABLE_HEADERS = [
|
const TABLE_HEADERS = [
|
||||||
'name' as const,
|
'name' as const,
|
||||||
@@ -30,17 +30,26 @@ const TABLE_HEADERS = [
|
|||||||
|
|
||||||
const Masters = () => {
|
const Masters = () => {
|
||||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||||
const showToast = useShowToast();
|
const toast = useToast();
|
||||||
|
|
||||||
const { t } = useTranslation('~', {
|
const { t } = useTranslation('~', {
|
||||||
keyPrefix: 'dry-wash.arm.master',
|
keyPrefix: 'dry-wash.arm.master',
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: masters, error, isLoading, isSuccess } = useGetMastersQuery();
|
const {
|
||||||
|
data: masters,
|
||||||
|
error,
|
||||||
|
isLoading,
|
||||||
|
isSuccess,
|
||||||
|
} = api.useGetMastersQuery();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (error) {
|
if (error) {
|
||||||
showToast(t('error.title'), 'error');
|
toast({
|
||||||
|
title: t('error.title'),
|
||||||
|
status: 'error',
|
||||||
|
isClosable: true,
|
||||||
|
position: 'bottom-right',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [error]);
|
}, [error]);
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,35 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { getTimeSlot } from '../../lib';
|
import { getTimeSlot } from '../../lib';
|
||||||
import { useUpdateOrdersMutation } from '../../__data__/service/api';
|
import { Master } from '../../models/api/master';
|
||||||
import { OrderArm, Status, statuses } from '../../models/api';
|
import { armService } from '../../api/arm';
|
||||||
|
|
||||||
|
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',
|
||||||
@@ -26,8 +53,9 @@ const OrderItem = ({
|
|||||||
master,
|
master,
|
||||||
allMasters,
|
allMasters,
|
||||||
id,
|
id,
|
||||||
}: OrderArm) => {
|
}: OrderProps) => {
|
||||||
const [updateOrders] = useUpdateOrdersMutation();
|
const { updateOrders } = armService();
|
||||||
|
|
||||||
const { t } = useTranslation('~', {
|
const { t } = useTranslation('~', {
|
||||||
keyPrefix: 'dry-wash.arm.order',
|
keyPrefix: 'dry-wash.arm.order',
|
||||||
});
|
});
|
||||||
@@ -44,16 +72,16 @@ const OrderItem = ({
|
|||||||
|
|
||||||
if (selectedMaster) {
|
if (selectedMaster) {
|
||||||
setMaster(masterName);
|
setMaster(masterName);
|
||||||
updateOrders({ id, master: selectedMaster.id });
|
updateOrders({ id, masterId: 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 as OrderArm['status'];
|
const status = e.target.value;
|
||||||
updateOrders({ id, status });
|
updateOrders({ id, status });
|
||||||
setStatus(status);
|
setStatus(e.target.value as OrderProps['status']);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -10,18 +10,16 @@ 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 {
|
import { Master } from '../../models/api/master';
|
||||||
useGetMastersQuery,
|
|
||||||
useGetOrdersQuery,
|
|
||||||
} from '../../__data__/service/api';
|
|
||||||
import useShowToast from '../../hooks/useShowToast';
|
|
||||||
|
|
||||||
const TABLE_HEADERS = [
|
const TABLE_HEADERS = [
|
||||||
'carNumber' as const,
|
'carNumber' as const,
|
||||||
@@ -36,34 +34,47 @@ 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(() => {
|
||||||
if (isError) {
|
const loadData = async () => {
|
||||||
showToast(t('error.title'), 'error');
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}, [isError, ordersError, mastersError, t]);
|
};
|
||||||
|
|
||||||
|
loadData();
|
||||||
|
}, [currentDate, toast, t]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box p='8'>
|
<Box p='8'>
|
||||||
@@ -92,24 +103,25 @@ const Orders = () => {
|
|||||||
</Tr>
|
</Tr>
|
||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
{isLoading && (
|
{loading && (
|
||||||
<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>
|
||||||
)}
|
)}
|
||||||
{isSuccess && orders.length === 0 && (
|
{!loading && orders.length === 0 && !error && (
|
||||||
<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>
|
||||||
)}
|
)}
|
||||||
{isSuccess &&
|
{!loading &&
|
||||||
|
!error &&
|
||||||
orders.map((order, index) => (
|
orders.map((order, index) => (
|
||||||
<OrderItem
|
<OrderItem
|
||||||
allMasters={masters}
|
allMasters={allMasters}
|
||||||
key={index}
|
key={index}
|
||||||
{...order}
|
{...order}
|
||||||
status={order.status as OrderProps['status']}
|
status={order.status as OrderProps['status']}
|
||||||
|
|||||||
21
src/helpers/showToast.ts
Normal file
21
src/helpers/showToast.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
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;
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
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;
|
|
||||||
@@ -1,3 +1,2 @@
|
|||||||
export * from './common';
|
export * from './common';
|
||||||
export * from './order';
|
export * from './order';
|
||||||
export * from './master';
|
|
||||||
|
|||||||
@@ -1,49 +1,21 @@
|
|||||||
/* 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;
|
|
||||||
};
|
};
|
||||||
@@ -53,7 +53,7 @@ router.delete('/arm/masters/:id', (req, res) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch('/order/:id', (req, res) => {
|
router.patch('/orders/:id', (req, res) => {
|
||||||
res
|
res
|
||||||
.status(/error/.test(STUBS.orders) ? 500 : 200)
|
.status(/error/.test(STUBS.orders) ? 500 : 200)
|
||||||
.send(
|
.send(
|
||||||
|
|||||||
26
tests/example.spec.ts
Normal file
26
tests/example.spec.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
test.beforeEach('check server is up', async ({ page }) => {
|
||||||
|
try {
|
||||||
|
await page.goto('http://localhost:8099/dry-wash');
|
||||||
|
const makeOrderText = page.getByText('Сделать заказ', { exact: true });
|
||||||
|
await expect(makeOrderText).toBeVisible();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('server not up');
|
||||||
|
test.skip();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('login', async ({ page }) => {
|
||||||
|
await page.goto('http://localhost:8099/dry-wash/arm');
|
||||||
|
await page.getByRole('textbox', { name: 'Username or email' }).click();
|
||||||
|
await page
|
||||||
|
.getByRole('textbox', { name: 'Username or email' })
|
||||||
|
.fill('237x237');
|
||||||
|
await page.getByRole('textbox', { name: 'Password' }).click();
|
||||||
|
await page.getByRole('textbox', { name: 'Password' }).fill('');
|
||||||
|
await page.getByRole('button', { name: 'Sign In' }).click();
|
||||||
|
await page.getByRole('heading', { name: 'Заказы' }).click();
|
||||||
|
await page.getByRole('link', { name: 'Мастера' }).click();
|
||||||
|
await page.getByRole('link', { name: 'Заказы' }).click();
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user