diff --git a/src/__data__/service/api.ts b/src/__data__/service/api.ts index 86adbfa..115a0e8 100644 --- a/src/__data__/service/api.ts +++ b/src/__data__/service/api.ts @@ -21,8 +21,16 @@ export const api = createApi({ }), tagTypes: ['Masters', 'Orders'], endpoints: (builder) => ({ - getMasters: builder.query({ - query: () => ({ url: '/arm/masters' }), + getMasters: builder.query({ + query: ({ date }) => { + const startDate = dayjs(date).startOf('day').toISOString(); + const endDate = dayjs(date).endOf('day').toISOString(); + return { + url: '/arm/masters/list', + method: 'POST', + body: { startDate, endDate }, + }; + }, transformResponse: extractBodyFromResponse, providesTags: ['Masters'], }), @@ -32,7 +40,7 @@ export const api = createApi({ method: 'PATCH', body: { status, notes, master }, }), - invalidatesTags: ['Orders'], + invalidatesTags: ['Orders', 'Masters'], }), getOrders: builder.query({ query: ({ date }) => { @@ -54,14 +62,14 @@ export const api = createApi({ method: 'POST', body: master, }), - invalidatesTags: ['Masters'], + invalidatesTags: ['Masters', 'Orders'], }), deleteMaster: builder.mutation({ query: ({ id }) => ({ url: `/arm/masters/${id}`, method: 'DELETE', }), - invalidatesTags: ['Masters'], + invalidatesTags: ['Masters', 'Orders'], }), updateMaster: builder.mutation({ query: ({ id, name, phone }) => ({ @@ -69,7 +77,7 @@ export const api = createApi({ method: 'PATCH', body: { name, phone }, }), - invalidatesTags: ['Masters'], + invalidatesTags: ['Masters', 'Orders'], }), }), }); diff --git a/src/__data__/service/utils.ts b/src/__data__/service/utils.ts index c03db86..f55bb9c 100644 --- a/src/__data__/service/utils.ts +++ b/src/__data__/service/utils.ts @@ -3,7 +3,6 @@ import { FetchBaseQueryError } from '@reduxjs/toolkit/query'; import { BaseResponse } from '../../models/api'; export const extractBodyFromResponse = (response: BaseResponse) => { - console.log('response', response); if (response.success) { return response.body; } diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 7371ea4..8a5e122 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -1,4 +1,4 @@ -import { Box, Button, Heading, HStack, Divider, Flex } from '@chakra-ui/react'; +import { Box, Button, Heading, HStack, Flex } from '@chakra-ui/react'; import React from 'react'; import { useLocation, Link } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; @@ -30,7 +30,6 @@ const Header = () => { {t('orders')} )} - {URLs.armMaster.isOn && ( + + setCurrentDate((prevDate) => + dayjs(prevDate).subtract(1, 'day').toDate(), + ) + } + onNextDate={() => + setCurrentDate((prevDate) => dayjs(prevDate).add(1, 'day').toDate()) + } + /> diff --git a/src/components/Orders/Orders.tsx b/src/components/Orders/Orders.tsx index 81d3f22..16e5035 100644 --- a/src/components/Orders/Orders.tsx +++ b/src/components/Orders/Orders.tsx @@ -53,7 +53,7 @@ const Orders = () => { isSuccess: isMastersSuccess, isError: isMastersError, error: mastersError, - } = useGetMastersQuery(); + } = useGetMastersQuery({ date: currentDate }); const isLoading = isOrdersLoading || isMastersLoading; const isSuccess = isOrdersSuccess && isMastersSuccess; diff --git a/src/pages/__tests__/__snapshots__/masters.test.tsx.snap b/src/pages/__tests__/__snapshots__/masters.test.tsx.snap index 95d72e4..409d6d2 100644 --- a/src/pages/__tests__/__snapshots__/masters.test.tsx.snap +++ b/src/pages/__tests__/__snapshots__/masters.test.tsx.snap @@ -25,10 +25,6 @@ exports[`Master Page should display master list and show details when master but > Заказы -
Мастера + + Карта заказов + @@ -46,7 +48,7 @@ exports[`Master Page should display master list and show details when master but class="css-1glkkdp" >

+
+ +

+ 17.03.2025 +

+ +
@@ -216,11 +257,11 @@ exports[`Master Page should display master list and show details when master but class="css-zgoslk" > - + - - + diff --git a/src/pages/__tests__/masters.test.tsx b/src/pages/__tests__/masters.test.tsx index 9fef217..7aa3c45 100644 --- a/src/pages/__tests__/masters.test.tsx +++ b/src/pages/__tests__/masters.test.tsx @@ -20,7 +20,7 @@ import { store } from '../../__data__/store'; import Page from '../arm'; const server = setupServer( - http.get('/api/arm/masters', () => { + http.post('/api/arm/masters/list', () => { return HttpResponse.json({ success: true, body: [ diff --git a/src/pages/__tests__/ordersEmpty.test.tsx b/src/pages/__tests__/ordersEmpty.test.tsx index 3c65469..9c120d4 100644 --- a/src/pages/__tests__/ordersEmpty.test.tsx +++ b/src/pages/__tests__/ordersEmpty.test.tsx @@ -25,7 +25,7 @@ const server = setupServer( body: [], }); }), - http.get('/api/arm/masters', () => { + http.post('/api/arm/masters/list', () => { return HttpResponse.json({ success: true, body: [], diff --git a/src/pages/__tests__/ordersError.test.tsx b/src/pages/__tests__/ordersError.test.tsx index ab71a50..640f84e 100644 --- a/src/pages/__tests__/ordersError.test.tsx +++ b/src/pages/__tests__/ordersError.test.tsx @@ -24,7 +24,7 @@ const server = setupServer( http.post('/api/arm/orders', () => { return HttpResponse.json({}, { status: 500 }); }), - http.get('/api/arm/masters', () => { + http.post('/api/arm/masters/list', () => { return HttpResponse.json({ success: true, body: [ diff --git a/src/pages/__tests__/ordersList.test.tsx b/src/pages/__tests__/ordersList.test.tsx index 2288331..95d89a6 100644 --- a/src/pages/__tests__/ordersList.test.tsx +++ b/src/pages/__tests__/ordersList.test.tsx @@ -55,7 +55,7 @@ const server = setupServer( ], }); }), - http.get('/api/arm/masters', () => { + http.post('/api/arm/masters/list', () => { return HttpResponse.json({ success: true, body: [ diff --git a/stubs/api/index.js b/stubs/api/index.js index d1e0a3c..bba2cfb 100644 --- a/stubs/api/index.js +++ b/stubs/api/index.js @@ -8,12 +8,12 @@ const commonError = { success: false, message: 'Что-то пошло не та const sleep = (duration = 1000) => - (req, res, next) => - setTimeout(next, duration); + (req, res, next) => + setTimeout(next, duration); router.use(sleep()); -router.get('/arm/masters', (req, res) => { +router.post('/arm/masters/list', (req, res) => { res .status(/error/.test(STUBS.masters) ? 500 : 200) .send( @@ -108,9 +108,7 @@ router.post('/order/:orderId/upload-car-img', (req, res) => { .send(require(`../json/landing-order-car-image-upload/${stubName}.json`)); } catch (e) { console.error(e); - res - .status(500) - .send(commonError); + res.status(500).send(commonError); } });