Compare commits
39 Commits
20017cad3c
...
feature/ma
| Author | SHA1 | Date | |
|---|---|---|---|
| fea4a54c83 | |||
| 9349a41f84 | |||
| 8103fdcb56 | |||
| a59864a3e2 | |||
| a252301ea0 | |||
| 48cdfb92bd | |||
|
|
279da05b32 | ||
|
|
c6d906ad62 | ||
|
|
418a121418 | ||
|
|
7647958e52 | ||
|
|
9e024af568 | ||
|
|
7fe62e7d6e | ||
|
|
f2db3774c9 | ||
|
|
02e3fdffa0 | ||
|
|
965d2d0be1 | ||
|
|
9121fcaa43 | ||
|
|
290bb3f0a3 | ||
|
|
e6e73e5289 | ||
|
|
b959fcf8db | ||
|
|
5e25848e22 | ||
|
|
ecf6c60cdc | ||
|
|
91fc91230b | ||
| d312445bf2 | |||
|
|
351420bc62 | ||
|
|
61b042eee6 | ||
|
|
ac006267a2 | ||
|
|
63d9d069c0 | ||
| c83ebf02bc | |||
|
|
1968df7bb3 | ||
|
|
811e0e3f24 | ||
| a2ffd6f38f | |||
|
|
7b3889aa02 | ||
|
|
cee124fca5 | ||
|
|
b77eccc8e8 | ||
|
|
ebfaa7ea8f | ||
|
|
0027cc09b1 | ||
|
|
dd612d662c | ||
|
|
69251745fa | ||
|
|
253e3b3856 |
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"i18n-ally.localesPaths": [
|
||||
"locales"
|
||||
]
|
||||
}
|
||||
6
Jenkinsfile
vendored
6
Jenkinsfile
vendored
@@ -1,7 +1,7 @@
|
||||
pipeline {
|
||||
agent {
|
||||
docker {
|
||||
image 'node:20'
|
||||
image 'node:22'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,6 @@ pipeline {
|
||||
}
|
||||
}
|
||||
|
||||
stage('checks') {
|
||||
parallel {
|
||||
stage('eslint') {
|
||||
steps {
|
||||
sh 'npm run eslint'
|
||||
@@ -49,8 +47,6 @@ pipeline {
|
||||
sh 'npm run build'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('clean-all') {
|
||||
steps {
|
||||
|
||||
@@ -16,12 +16,27 @@ module.exports = {
|
||||
'dry-wash.order.view': '/order/:orderId',
|
||||
'dry-wash.arm.master': 'master',
|
||||
'dry-wash.arm.order': 'order',
|
||||
'dry-wash.arm.map': 'map',
|
||||
'dry-wash.arm': '/arm/*',
|
||||
},
|
||||
features: {
|
||||
'dry-wash': {
|
||||
// add your features here in the format [featureName]: { value: string }
|
||||
'order-view-status-polling': { value: '3000' }
|
||||
'order-view-status-polling': {
|
||||
on: true,
|
||||
value: '3000',
|
||||
key: 'order-view-status-polling',
|
||||
},
|
||||
'car-img-upload': {
|
||||
on: true,
|
||||
value: 'true',
|
||||
key: 'car-img-upload',
|
||||
},
|
||||
'order-cost': {
|
||||
on: true,
|
||||
value: '1000',
|
||||
key: 'order-cost',
|
||||
},
|
||||
},
|
||||
},
|
||||
config: {
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
"dry-wash.arm.order.status.complete": "Completed",
|
||||
"dry-wash.arm.order.status.pending": "Pending",
|
||||
"dry-wash.arm.order.status.working": "Working",
|
||||
"dry-wash.arm.order.status.canceled": "Canceled",
|
||||
"dry-wash.arm.order.status.cancelled": "Canceled",
|
||||
"dry-wash.arm.order.status.placeholder": "Select status",
|
||||
"dry-wash.arm.order.master.placeholder": "Select master",
|
||||
"dry-wash.arm.order.table.header.carNumber": "Car Number",
|
||||
@@ -111,5 +111,8 @@
|
||||
"dry-wash.errorBoundary.title": "Something went wrong",
|
||||
"dry-wash.errorBoundary.description": "We are already working on fixing the issue",
|
||||
"dry-wash.errorBoundary.button.reload": "Reload Page",
|
||||
"dry-wash.washTime.timeSlot": "{{start}} - {{end}}"
|
||||
"dry-wash.washTime.timeSlot": "{{start}} - {{end}}",
|
||||
"dry-wash.arm.map.title": "Map of orders",
|
||||
"dry-wash.arm.map.carNumber": "Car Number",
|
||||
"dry-wash.arm.map.status": "Status"
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"dry-wash.arm.order.status.complete": "Завершено",
|
||||
"dry-wash.arm.order.status.pending": "В ожидании",
|
||||
"dry-wash.arm.order.status.working": "В работе",
|
||||
"dry-wash.arm.order.status.canceled": "Отменено",
|
||||
"dry-wash.arm.order.status.cancelled": "Отменено",
|
||||
"dry-wash.arm.order.status.placeholder": "Выберите статус",
|
||||
"dry-wash.arm.order.master.placeholder": "Выберите мастера",
|
||||
"dry-wash.arm.order.table.header.carNumber": "Номер машины",
|
||||
@@ -117,5 +117,8 @@
|
||||
"dry-wash.errorBoundary.title": "Что-то пошло не так",
|
||||
"dry-wash.errorBoundary.description": "Мы уже работаем над исправлением проблемы",
|
||||
"dry-wash.errorBoundary.button.reload": "Перезагрузить страницу",
|
||||
"dry-wash.washTime.timeSlot": "{{start}} - {{end}}"
|
||||
"dry-wash.washTime.timeSlot": "{{start}} - {{end}}",
|
||||
"dry-wash.arm.map.title": " Карта заказов",
|
||||
"dry-wash.arm.map.carNumber": " Номер автомобиля",
|
||||
"dry-wash.arm.map.status": "Статус"
|
||||
}
|
||||
|
||||
5
package-lock.json
generated
5
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "dry-wash",
|
||||
"version": "0.8.0",
|
||||
"version": "0.9.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "dry-wash",
|
||||
"version": "0.8.0",
|
||||
"version": "0.9.2",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.26.7",
|
||||
@@ -3610,7 +3610,6 @@
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://registry.npmjs.org/@pbe/react-yandex-maps/-/react-yandex-maps-1.2.5.tgz",
|
||||
"integrity": "sha512-cBojin5e1fPx9XVCAqHQJsCnHGMeBNsP0TrNfpWCrPFfxb30ye+JgcGr2mn767Gbr1d+RufBLRiUcX2kaiAwjQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/yandex-maps": "2.1.29"
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dry-wash",
|
||||
"version": "0.8.0",
|
||||
"version": "0.9.2",
|
||||
"description": "<a id=\"readme-top\"></a>",
|
||||
"main": "./src/index.tsx",
|
||||
"scripts": {
|
||||
@@ -9,8 +9,8 @@
|
||||
"build": "npm run clean && brojs build --dev",
|
||||
"build:prod": "npm run clean && brojs build",
|
||||
"clean": "rimraf dist",
|
||||
"eslint": "npx eslint .",
|
||||
"eslint:fix": "npx eslint . --fix",
|
||||
"eslint": "npx eslint src",
|
||||
"eslint:fix": "npx eslint src --fix",
|
||||
"preversion": "npm run eslint"
|
||||
},
|
||||
"keywords": [],
|
||||
|
||||
@@ -11,5 +11,8 @@ export const FEATURE = {
|
||||
return interval;
|
||||
}
|
||||
}
|
||||
},
|
||||
carImageUpload: {
|
||||
isOn: Boolean(features?.['car-img-upload'])
|
||||
}
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import { FetchBaseQueryError } from '@reduxjs/toolkit/query';
|
||||
import { BaseResponse } from '../../models/api';
|
||||
|
||||
export const extractBodyFromResponse = <Body>(response: BaseResponse<Body>) => {
|
||||
console.log('response', response);
|
||||
if (response.success) {
|
||||
return response.body;
|
||||
}
|
||||
@@ -13,6 +14,7 @@ export const extractErrorMessageFromResponse = ({
|
||||
}: FetchBaseQueryError) => {
|
||||
if (
|
||||
typeof data === 'object' &&
|
||||
data !== null &&
|
||||
'error' in data &&
|
||||
typeof data.error === 'string'
|
||||
) {
|
||||
|
||||
@@ -7,7 +7,9 @@ export const store = configureStore({
|
||||
[api.reducerPath]: api.reducer,
|
||||
},
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware().concat(api.middleware),
|
||||
getDefaultMiddleware({
|
||||
serializableCheck: false
|
||||
}).concat(api.middleware),
|
||||
});
|
||||
|
||||
export type RootState = ReturnType<typeof store.getState>;
|
||||
|
||||
@@ -33,6 +33,18 @@ export const URLs = {
|
||||
url: getNavigationValue('dry-wash.arm.order'),
|
||||
isOn: Boolean(getNavigationValue('dry-wash.arm.order')),
|
||||
},
|
||||
armMap: {
|
||||
url: getNavigationValue('dry-wash.arm.map'),
|
||||
isOn: Boolean(getNavigationValue('dry-wash.arm.map')),
|
||||
getUrl({ lat, lon, currentDate }) {
|
||||
return (
|
||||
getFullUrls('/arm') +
|
||||
'/' +
|
||||
getNavigationValue('dry-wash.arm.map') +
|
||||
`?lat=${lat}&lon=${lon}¤tDate=${currentDate}`
|
||||
);
|
||||
},
|
||||
},
|
||||
armBase: {
|
||||
url: getFullUrls(getNavigationValue('dry-wash.arm')),
|
||||
isOn: Boolean(getNavigationValue('dry-wash.arm')),
|
||||
|
||||
@@ -28,7 +28,6 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
||||
|
||||
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
|
||||
console.error('Error caught by ErrorBoundary:', error, errorInfo);
|
||||
console.error('4545');
|
||||
this.setState({ error, errorInfo });
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@ jest.mock('@brojs/cli', () => {
|
||||
|
||||
describe('ErrorBoundary', () => {
|
||||
it('должен отобразить запасной UI при ошибке', async () => {
|
||||
// Подавляем вывод ошибки в консоль во время теста
|
||||
const consoleSpy = jest.spyOn(console, 'error');
|
||||
consoleSpy.mockImplementation(() => {});
|
||||
|
||||
const { container } = render(
|
||||
<Provider store={store}>
|
||||
<ErrorBoundary>
|
||||
@@ -39,7 +43,9 @@ describe('ErrorBoundary', () => {
|
||||
);
|
||||
|
||||
expect(button).not.toBeNull();
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
// Восстанавливаем console.error после теста
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
63
src/components/Header/Header.tsx
Normal file
63
src/components/Header/Header.tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
import { Box, Button, Heading, HStack, Divider, Flex } from '@chakra-ui/react';
|
||||
import React from 'react';
|
||||
import { useLocation, Link } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { URLs } from '../../__data__/urls';
|
||||
|
||||
const Header = () => {
|
||||
const location = useLocation();
|
||||
const isActive = (keyword: string) => location.pathname.includes(keyword);
|
||||
|
||||
const { t } = useTranslation('~', {
|
||||
keyPrefix: 'dry-wash.arm.master.sideBar',
|
||||
});
|
||||
|
||||
return (
|
||||
<Box as='header' bg='gray.50' boxShadow='md' px={6} py={4} w='100%'>
|
||||
<Flex gap={50} align='center'>
|
||||
<Heading color='green' size='lg'>
|
||||
{t('title')}
|
||||
</Heading>
|
||||
<HStack spacing={4}>
|
||||
{URLs.armOrder.isOn && (
|
||||
<Button
|
||||
as={Link}
|
||||
to={URLs.armOrder.url}
|
||||
colorScheme={isActive(URLs.armOrder.url) ? 'green' : 'blue'}
|
||||
variant={isActive(URLs.armOrder.url) ? 'outline' : 'ghost'}
|
||||
>
|
||||
{t('orders')}
|
||||
</Button>
|
||||
)}
|
||||
<Divider orientation='vertical' height='30px' />
|
||||
{URLs.armMaster.isOn && (
|
||||
<Button
|
||||
as={Link}
|
||||
to={URLs.armMaster.url}
|
||||
colorScheme={isActive(URLs.armMaster.url) ? 'green' : 'blue'}
|
||||
variant={isActive(URLs.armMaster.url) ? 'outline' : 'ghost'}
|
||||
data-testid='master-button'
|
||||
>
|
||||
{t('master')}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{URLs.armMap.isOn && (
|
||||
<Button
|
||||
as={Link}
|
||||
to={URLs.armMap.url}
|
||||
colorScheme={isActive(URLs.armMap.url) ? 'green' : 'blue'}
|
||||
variant={isActive(URLs.armMap.url) ? 'outline' : 'ghost'}
|
||||
data-testid='master-button'
|
||||
>
|
||||
Карта заказов
|
||||
</Button>
|
||||
)}
|
||||
</HStack>
|
||||
</Flex>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default Header;
|
||||
1
src/components/Header/index.ts
Normal file
1
src/components/Header/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from './Header';
|
||||
@@ -2,10 +2,11 @@ import { Box, Flex } from '@chakra-ui/react';
|
||||
import React from 'react';
|
||||
import { Navigate, Route, Routes } from 'react-router-dom';
|
||||
|
||||
import Sidebar from '../Sidebar';
|
||||
import Orders from '../Orders';
|
||||
import Masters from '../Masters';
|
||||
import { URLs } from '../../__data__/urls';
|
||||
import Header from '../Header';
|
||||
import OrdersMap from '../Map';
|
||||
|
||||
const LayoutArm = () => {
|
||||
let defaultRedirect = null;
|
||||
@@ -17,8 +18,8 @@ const LayoutArm = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<Flex h='100vh'>
|
||||
<Sidebar />
|
||||
<Flex flexDirection='column' h='100vh'>
|
||||
<Header />
|
||||
<Box flex='1' bg='gray.50'>
|
||||
<Routes>
|
||||
<Route index element={<Navigate to={defaultRedirect} replace />} />
|
||||
@@ -28,6 +29,9 @@ const LayoutArm = () => {
|
||||
{URLs.armMaster.isOn && (
|
||||
<Route path={URLs.armMaster.url} element={<Masters />} />
|
||||
)}
|
||||
{URLs.armMap.isOn && (
|
||||
<Route path={URLs.armMap.url} element={<OrdersMap />} />
|
||||
)}
|
||||
</Routes>
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
82
src/components/Map/Map.tsx
Normal file
82
src/components/Map/Map.tsx
Normal file
@@ -0,0 +1,82 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import { Box, Flex, Heading, Spinner } from '@chakra-ui/react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { YMaps, Map, Placemark } from '@pbe/react-yandex-maps';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
|
||||
import { useGetOrdersQuery } from '../../__data__/service/api';
|
||||
import getCoordinates from '../../utils/getCoordinates';
|
||||
|
||||
const OrdersMap = () => {
|
||||
const { t } = useTranslation('~', {
|
||||
keyPrefix: 'dry-wash.arm.map',
|
||||
});
|
||||
|
||||
const location = useLocation();
|
||||
const params = new URLSearchParams(location.search);
|
||||
const latFromUrl = parseFloat(params.get('lat') || 55.78);
|
||||
const lonFromUrl = parseFloat(params.get('lon') || 49.12);
|
||||
const currentDate = useMemo(
|
||||
() =>
|
||||
params.get('currentDate')
|
||||
? new Date(params.get('currentDate'))
|
||||
: new Date(),
|
||||
[],
|
||||
);
|
||||
|
||||
const {
|
||||
data: ordersData,
|
||||
isLoading,
|
||||
isSuccess,
|
||||
} = useGetOrdersQuery({ date: currentDate });
|
||||
|
||||
// Получаем координаты из location
|
||||
const orders = ordersData
|
||||
?.map((order) => {
|
||||
const coords = getCoordinates(order.location);
|
||||
return coords ? { ...order, ...coords } : null;
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
return (
|
||||
<Box p='8'>
|
||||
<Heading size='lg' mb='5'>
|
||||
{t('title')}
|
||||
</Heading>
|
||||
|
||||
{isLoading && (
|
||||
<Flex justifyContent='center' alignItems='center'>
|
||||
<Spinner size='lg' />
|
||||
</Flex>
|
||||
)}
|
||||
|
||||
{isSuccess && (
|
||||
<YMaps>
|
||||
<Map
|
||||
defaultState={{ center: [latFromUrl, lonFromUrl], zoom: 12 }}
|
||||
width='100%'
|
||||
height='70vh'
|
||||
modules={['geoObject.addon.balloon']}
|
||||
>
|
||||
{orders.map(({ id, lat, lon, carNumber, status }) => (
|
||||
<Placemark
|
||||
key={id}
|
||||
geometry={[lat, lon]}
|
||||
options={{
|
||||
preset: 'islands#blueAutoIcon',
|
||||
iconColor: 'blue',
|
||||
balloonPanelMaxMapArea: 0,
|
||||
}}
|
||||
properties={{
|
||||
balloonContent: `<strong>${t('carNumber')}</strong> ${carNumber}<br/><strong>${t('status')}</strong> ${status}`,
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</Map>
|
||||
</YMaps>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default OrdersMap;
|
||||
1
src/components/Map/index.ts
Normal file
1
src/components/Map/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from './Map';
|
||||
@@ -1,17 +1,20 @@
|
||||
import React, { ChangeEvent, useState } from 'react';
|
||||
import { Td, Tr, Link, Select } from '@chakra-ui/react';
|
||||
import { Td, Tr, Link, Select, Button } from '@chakra-ui/react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import dayjs from 'dayjs';
|
||||
import { ViewIcon } from '@chakra-ui/icons';
|
||||
import { Link as LinkRouter } from 'react-router-dom';
|
||||
|
||||
import { getTimeSlot } from '../../lib';
|
||||
import { useUpdateOrdersMutation } from '../../__data__/service/api';
|
||||
import { OrderArm, Status, statuses } from '../../models/api';
|
||||
import getCoordinates from '../../utils/getCoordinates';
|
||||
import { URLs } from '../../__data__/urls';
|
||||
|
||||
const statusColors: Record<Status, string> = {
|
||||
pending: 'yellow.100',
|
||||
progress: 'blue.100',
|
||||
working: 'orange.100',
|
||||
canceled: 'red.100',
|
||||
cancelled: 'red.100',
|
||||
complete: 'green.100',
|
||||
};
|
||||
|
||||
@@ -26,6 +29,7 @@ const OrderItem = ({
|
||||
master,
|
||||
allMasters,
|
||||
id,
|
||||
currentDate,
|
||||
}: OrderArm) => {
|
||||
const [updateOrders] = useUpdateOrdersMutation();
|
||||
const { t } = useTranslation('~', {
|
||||
@@ -34,7 +38,7 @@ const OrderItem = ({
|
||||
|
||||
const [statusSelect, setStatus] = useState(status);
|
||||
const bgColor = statusColors[statusSelect];
|
||||
const [masterSelect, setMaster] = useState(master?.name);
|
||||
const [masterSelectId, setMasterSelectId] = useState(master);
|
||||
|
||||
const handelChangeMasters = (e: ChangeEvent<HTMLSelectElement>) => {
|
||||
const masterName = e.target.value;
|
||||
@@ -43,7 +47,7 @@ const OrderItem = ({
|
||||
);
|
||||
|
||||
if (selectedMaster) {
|
||||
setMaster(masterName);
|
||||
setMasterSelectId(selectedMaster.id);
|
||||
updateOrders({ id, master: selectedMaster.id });
|
||||
} else {
|
||||
console.error('Master not found');
|
||||
@@ -56,6 +60,12 @@ const OrderItem = ({
|
||||
setStatus(status);
|
||||
};
|
||||
|
||||
const masterSelectChange = allMasters.find(
|
||||
(master) => master.id === masterSelectId,
|
||||
);
|
||||
|
||||
const { lat = 55.78, lon = 49.12 } = getCoordinates(location);
|
||||
|
||||
return (
|
||||
<Tr>
|
||||
<Td>{carNumber}</Td>
|
||||
@@ -79,7 +89,7 @@ const OrderItem = ({
|
||||
</Td>
|
||||
<Td>
|
||||
<Select
|
||||
value={masterSelect}
|
||||
value={masterSelectChange?.name}
|
||||
onChange={handelChangeMasters}
|
||||
placeholder={t(`master.placeholder`)}
|
||||
>
|
||||
@@ -93,7 +103,14 @@ const OrderItem = ({
|
||||
<Td>
|
||||
<Link href='tel:'>{phone}</Link>
|
||||
</Td>
|
||||
<Td>{location}</Td>
|
||||
<Td>
|
||||
<Button
|
||||
as={LinkRouter}
|
||||
to={URLs.armMap.getUrl({ lat, lon, currentDate })}
|
||||
>
|
||||
<ViewIcon />
|
||||
</Button>
|
||||
</Td>
|
||||
</Tr>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -112,6 +112,7 @@ const Orders = () => {
|
||||
key={index}
|
||||
{...order}
|
||||
status={order.status as OrderArm['status']}
|
||||
currentDate={currentDate}
|
||||
/>
|
||||
))}
|
||||
</Tbody>
|
||||
|
||||
35
src/components/PopoverTemplate/PopoverTemplate.tsx
Normal file
35
src/components/PopoverTemplate/PopoverTemplate.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
Button,
|
||||
Popover,
|
||||
PopoverArrow,
|
||||
PopoverBody,
|
||||
PopoverCloseButton,
|
||||
PopoverContent,
|
||||
PopoverHeader,
|
||||
PopoverTrigger,
|
||||
} from '@chakra-ui/react';
|
||||
|
||||
interface Props {
|
||||
title?: string;
|
||||
description: string;
|
||||
trigger?: React.ReactNode;
|
||||
}
|
||||
|
||||
const PopoverTemplate = ({ title, description, trigger }: Props) => {
|
||||
return (
|
||||
<Popover>
|
||||
<PopoverTrigger>
|
||||
<Button>{trigger}</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent>
|
||||
<PopoverArrow />
|
||||
<PopoverCloseButton />
|
||||
{title && <PopoverHeader>{title}!</PopoverHeader>}
|
||||
<PopoverBody mr={5}>{description}</PopoverBody>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
};
|
||||
|
||||
export default PopoverTemplate;
|
||||
1
src/components/PopoverTemplate/index.ts
Normal file
1
src/components/PopoverTemplate/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from './PopoverTemplate';
|
||||
48
src/components/PriceCar/PriceCar.tsx
Normal file
48
src/components/PriceCar/PriceCar.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Box, Image, Progress, Text } from '@chakra-ui/react';
|
||||
import React from 'react';
|
||||
import { getFeatures } from '@brojs/cli';
|
||||
|
||||
const PRICE_INCREASE_PERCENT_PER_RATING = 10; // 10% за каждый балл
|
||||
|
||||
export const PriceCar = ({ image, rating }) => {
|
||||
const BASE_WASH_PRICE: number = Number(
|
||||
getFeatures('dry-wash')['order-cost']?.value || 1000,
|
||||
);
|
||||
|
||||
const calculateWashPrice = (rating: number) => {
|
||||
const priceIncrease =
|
||||
(BASE_WASH_PRICE * PRICE_INCREASE_PERCENT_PER_RATING * rating) / 100;
|
||||
return BASE_WASH_PRICE + priceIncrease;
|
||||
};
|
||||
|
||||
const washPrice = calculateWashPrice(rating);
|
||||
const progressValue = (rating / 10) * 100;
|
||||
return (
|
||||
<Box
|
||||
alignItems='center'
|
||||
gap={5}
|
||||
width='100%'
|
||||
display='flex'
|
||||
flexDirection='column'
|
||||
>
|
||||
<Image
|
||||
maxWidth='600px'
|
||||
objectFit='contain'
|
||||
borderRadius='md'
|
||||
src={image}
|
||||
alt='Car Image'
|
||||
/>
|
||||
{rating ? (
|
||||
<Box width='100%' maxW='600px'>
|
||||
<Text>Рейтинг загрязнения машины:</Text>
|
||||
<Progress value={progressValue} size='sm' colorScheme='red' mt={2} />
|
||||
<Text mt={2}>Стоимость мойки: {washPrice.toFixed(2)} руб.</Text>
|
||||
</Box>
|
||||
) : (
|
||||
<Text>Не удалость определить уровень загрязнения машины</Text>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default PriceCar;
|
||||
1
src/components/PriceCar/index.ts
Normal file
1
src/components/PriceCar/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from './PriceCar';
|
||||
@@ -1,61 +0,0 @@
|
||||
import { Box, Button, Heading, VStack, Divider } from '@chakra-ui/react';
|
||||
import React from 'react';
|
||||
import { useLocation, Link } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { URLs } from '../../__data__/urls';
|
||||
|
||||
const Sidebar = () => {
|
||||
const location = useLocation();
|
||||
const isActive = (keyword: string) => location.pathname.includes(keyword);
|
||||
|
||||
const { t } = useTranslation('~', {
|
||||
keyPrefix: 'dry-wash.arm.master.sideBar',
|
||||
});
|
||||
|
||||
return (
|
||||
<Box
|
||||
borderRight='1px solid black'
|
||||
bg='gray.50'
|
||||
color='white'
|
||||
w='250px'
|
||||
p='5'
|
||||
pt='8'
|
||||
>
|
||||
<Heading color='green' size='lg' mb='5'>
|
||||
{t('title')}
|
||||
</Heading>
|
||||
|
||||
<VStack align='start' spacing='4'>
|
||||
<Divider />
|
||||
{URLs.armOrder.isOn && (
|
||||
<Button
|
||||
as={Link}
|
||||
to={URLs.armOrder.url}
|
||||
w='100%'
|
||||
colorScheme={isActive(URLs.armOrder.url) ? 'green' : 'blue'}
|
||||
variant={isActive(URLs.armOrder.url) ? 'solid' : 'ghost'}
|
||||
>
|
||||
{t('orders')}
|
||||
</Button>
|
||||
)}
|
||||
<Divider />
|
||||
{URLs.armMaster.isOn && (
|
||||
<Button
|
||||
as={Link}
|
||||
to={URLs.armMaster.url}
|
||||
w='100%'
|
||||
colorScheme={isActive(URLs.armMaster.url) ? 'green' : 'blue'}
|
||||
variant={isActive(URLs.armMaster.url) ? 'solid' : 'ghost'}
|
||||
data-testid='master-button'
|
||||
>
|
||||
{t('master')}
|
||||
</Button>
|
||||
)}
|
||||
<Divider />
|
||||
</VStack>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default Sidebar;
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from './Sidebar';
|
||||
@@ -64,7 +64,7 @@ export const CarImageForm: FC<CarImageFormProps> = memo(function CarImageForm({
|
||||
<Input
|
||||
{...field}
|
||||
ref={fileInputRef}
|
||||
accept='.jpg,.png'
|
||||
accept='image/png,image/jpeg'
|
||||
value={value?.fileName}
|
||||
onChange={(event) => {
|
||||
onChange(event.target.files[0]);
|
||||
|
||||
@@ -11,7 +11,7 @@ export const useHandleUploadCarImageResponse = (query: {
|
||||
}) => {
|
||||
const toast = useToast();
|
||||
const { t } = useTranslation('~', {
|
||||
keyPrefix: 'dry-wash.order-create.upload-car-image-query',
|
||||
keyPrefix: 'dry-wash.order-view.upload-car-image-query',
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -38,8 +38,7 @@ type GetArrItemType<ArrType> =
|
||||
export const statuses = [
|
||||
'pending' as const,
|
||||
'progress' as const,
|
||||
'working' as const,
|
||||
'canceled' as const,
|
||||
'cancelled' as const,
|
||||
'complete' as const,
|
||||
];
|
||||
|
||||
@@ -53,8 +52,9 @@ export type OrderArm = {
|
||||
status?: GetArrItemType<typeof statuses>;
|
||||
phone?: string;
|
||||
location?: string;
|
||||
master: Master;
|
||||
master: string | [];
|
||||
notes: '';
|
||||
allMasters: Master[];
|
||||
id: string;
|
||||
currentDate: Date;
|
||||
};
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
import { IsoDate } from "../common";
|
||||
import { IsoDate } from '../common';
|
||||
|
||||
import { Car, Customer, Washing } from ".";
|
||||
import { Car, Customer, Washing } from '.';
|
||||
|
||||
export type Id = string;
|
||||
|
||||
export type Status = 'pending' |
|
||||
'progress' |
|
||||
'working' |
|
||||
'canceled' |
|
||||
'complete';
|
||||
export type Status =
|
||||
| 'pending'
|
||||
| 'progress'
|
||||
| 'working'
|
||||
| 'canceled'
|
||||
| 'complete';
|
||||
|
||||
export type Create = {
|
||||
customer: {
|
||||
phone: Customer.PhoneNumber,
|
||||
phone: Customer.PhoneNumber;
|
||||
};
|
||||
car: {
|
||||
number: Car.RegistrationNumber,
|
||||
body: Car.BodyStyle,
|
||||
color: Car.Color,
|
||||
},
|
||||
number: Car.RegistrationNumber;
|
||||
body: Car.BodyStyle;
|
||||
color: Car.Color;
|
||||
};
|
||||
washing: {
|
||||
location: Washing.Location
|
||||
begin: Washing.AvailableBeginDateTime,
|
||||
end: Washing.AvailableEndDateTime,
|
||||
}
|
||||
location: Washing.Location;
|
||||
begin: Washing.AvailableBeginDateTime;
|
||||
end: Washing.AvailableEndDateTime;
|
||||
};
|
||||
};
|
||||
|
||||
export type Number = string;
|
||||
@@ -36,10 +37,12 @@ export type View = {
|
||||
location: Washing.Location;
|
||||
startWashTime: Washing.AvailableBeginDateTime;
|
||||
endWashTime: Washing.AvailableEndDateTime;
|
||||
orderNumber: Number,
|
||||
status: Status,
|
||||
orderNumber: Number;
|
||||
status: Status;
|
||||
notes: string;
|
||||
created: IsoDate;
|
||||
updated: IsoDate;
|
||||
id: Id;
|
||||
image?: string;
|
||||
imageRating?: string;
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Master Page render 1`] = `
|
||||
exports[`Master Page should display master list and show details when master button is clicked 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="css-1yeiifd"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Order View page, initial load shows order details 1`] = `
|
||||
exports[`Страница просмотра заказа отображает детали заказа после успешной загрузки 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="chakra-container css-3n6qh3"
|
||||
@@ -16,7 +16,6 @@ exports[`Order View page, initial load shows order details 1`] = `
|
||||
</h2>
|
||||
<div
|
||||
class="chakra-stack css-1n38vgh"
|
||||
created="2025-01-19T14:04:02.985Z"
|
||||
data-testid="order-details"
|
||||
>
|
||||
<div
|
||||
@@ -26,6 +25,9 @@ exports[`Order View page, initial load shows order details 1`] = `
|
||||
class="chakra-heading css-1jb3vzl"
|
||||
>
|
||||
Заказ №{{number}}
|
||||
(
|
||||
Sunday, January 19, 2025 5:04 PM
|
||||
)
|
||||
</h2>
|
||||
<span
|
||||
class="css-6jfsiv"
|
||||
@@ -126,7 +128,7 @@ exports[`Order View page, initial load shows order details 1`] = `
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`Order View page, initial load shows order details loading 1`] = `
|
||||
exports[`Страница просмотра заказа отображает индикатор загрузки деталей заказа 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="chakra-container css-3n6qh3"
|
||||
@@ -171,7 +173,7 @@ exports[`Order View page, initial load shows order details loading 1`] = `
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`Order View page, initial load shows order error 1`] = `
|
||||
exports[`Страница просмотра заказа отображает ошибку при некорректном ID заказа 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="chakra-container css-3n6qh3"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`order page получение списка заказов 1`] = `
|
||||
exports[`Страница заказов должна корректно отображать список заказов после загрузки данных 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="css-1yeiifd"
|
||||
@@ -75,7 +75,7 @@ exports[`order page получение списка заказов 1`] = `
|
||||
<p
|
||||
class="chakra-text css-52ukzg"
|
||||
>
|
||||
16.02.2025
|
||||
23.02.2025
|
||||
</p>
|
||||
<button
|
||||
class="chakra-button css-ez23ye"
|
||||
|
||||
@@ -54,6 +54,41 @@ const server = setupServer(
|
||||
],
|
||||
});
|
||||
}),
|
||||
http.post('/api/arm/orders', () => {
|
||||
return HttpResponse.json({
|
||||
success: true,
|
||||
body: [
|
||||
{
|
||||
id: 'order1',
|
||||
carNumber: 'A123BC',
|
||||
startWashTime: '2024-11-24T10:30:00.000Z',
|
||||
endWashTime: '2024-11-24T16:30:00.000Z',
|
||||
orderDate: '2024-11-24T08:41:46.366Z',
|
||||
status: 'pending',
|
||||
phone: '79001234563',
|
||||
location: 'Казань, ул. Баумана, 1',
|
||||
master: {
|
||||
name: 'Олег Макаров',
|
||||
phone: '79001234567',
|
||||
id: '23423442',
|
||||
},
|
||||
notes: '',
|
||||
},
|
||||
{
|
||||
id: 'order2',
|
||||
carNumber: 'A245BC',
|
||||
startWashTime: '2024-11-24T11:30:00.000Z',
|
||||
endWashTime: '2024-11-24T17:30:00.000Z',
|
||||
orderDate: '2024-11-24T07:40:46.366Z',
|
||||
status: 'progress',
|
||||
phone: '79001234567',
|
||||
location: 'Казань, ул. Баумана, 43',
|
||||
master: [],
|
||||
notes: '',
|
||||
},
|
||||
],
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
jest.mock('@brojs/cli', () => {
|
||||
@@ -70,11 +105,7 @@ describe('Master Page', () => {
|
||||
afterEach(() => server.resetHandlers());
|
||||
afterAll(() => server.close());
|
||||
|
||||
it('render ', async () => {
|
||||
server.events.on('request:start', ({ request }) => {
|
||||
console.log('Outgoing:', request.method, request.url);
|
||||
});
|
||||
|
||||
it('should display master list and show details when master button is clicked', async () => {
|
||||
const { container } = render(
|
||||
<Provider store={store}>
|
||||
<ChakraProvider theme={chakraTheme}>
|
||||
@@ -88,10 +119,14 @@ describe('Master Page', () => {
|
||||
);
|
||||
|
||||
const button = await waitFor(() => screen.getByTestId('master-button'));
|
||||
|
||||
fireEvent.click(button);
|
||||
|
||||
await waitFor(() => screen.getByText('Иван Иванов'));
|
||||
// Проверяем отображение всех мастеров
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Иван Иванов')).toBeInTheDocument();
|
||||
expect(screen.getByText('Олег Макаров')).toBeInTheDocument();
|
||||
expect(screen.getByText('Иван Галкин')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
@@ -11,12 +11,12 @@ jest.mock('react-router-dom', () => ({
|
||||
useParams: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('Order View page, initial load', () => {
|
||||
describe('Страница просмотра заказа', () => {
|
||||
beforeAll(() => server.listen());
|
||||
afterEach(() => server.resetHandlers());
|
||||
afterAll(() => server.close());
|
||||
|
||||
test('shows order details loading', () => {
|
||||
test('отображает индикатор загрузки деталей заказа', () => {
|
||||
(useParams as jest.Mock).mockReturnValue({ orderId: 'id1' });
|
||||
|
||||
const { container } = render(
|
||||
@@ -33,7 +33,7 @@ describe('Order View page, initial load', () => {
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('shows order details', async () => {
|
||||
test('отображает детали заказа после успешной загрузки', async () => {
|
||||
(useParams as jest.Mock).mockReturnValue({ orderId: 'id1' });
|
||||
|
||||
const { container } = render(
|
||||
@@ -52,7 +52,7 @@ describe('Order View page, initial load', () => {
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('shows order error', async () => {
|
||||
test('отображает ошибку при некорректном ID заказа', async () => {
|
||||
(useParams as jest.Mock).mockReturnValue({ orderId: null });
|
||||
|
||||
const { container } = render(
|
||||
|
||||
@@ -46,10 +46,6 @@ describe('order page', () => {
|
||||
afterAll(() => server.close());
|
||||
|
||||
it('получение пустого списка', async () => {
|
||||
server.events.on('request:start', ({ request }) => {
|
||||
console.log('Outgoing:', request.method, request.url);
|
||||
});
|
||||
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<ChakraProvider theme={chakraTheme}>
|
||||
|
||||
@@ -21,9 +21,43 @@ import Page from '../arm';
|
||||
import { PageSpinner } from '../../components';
|
||||
|
||||
const server = setupServer(
|
||||
http.get('/api/arm/orders', () => {
|
||||
http.post('/api/arm/orders', () => {
|
||||
return HttpResponse.json({}, { status: 500 });
|
||||
}),
|
||||
http.get('/api/arm/masters', () => {
|
||||
return HttpResponse.json({
|
||||
success: true,
|
||||
body: [
|
||||
{
|
||||
id: '4545423234',
|
||||
name: 'Иван Иванов',
|
||||
phone: '+7 900 123 45 67',
|
||||
},
|
||||
{
|
||||
name: 'Олег Макаров',
|
||||
phone: '79001234567',
|
||||
id: '23423442',
|
||||
},
|
||||
{
|
||||
id: '345354234',
|
||||
name: 'Иван Галкин',
|
||||
schedule: [
|
||||
{
|
||||
id: 'order1',
|
||||
startWashTime: '2024-11-24T10:30:00.000Z',
|
||||
endWashTime: '2024-11-24T16:30:00.000Z',
|
||||
},
|
||||
{
|
||||
id: 'order2',
|
||||
startWashTime: '2024-11-24T11:30:00.000Z',
|
||||
endWashTime: '2024-11-24T17:30:00.000Z',
|
||||
},
|
||||
],
|
||||
phone: '+7 900 123 45 67',
|
||||
},
|
||||
],
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
jest.mock('@brojs/cli', () => {
|
||||
|
||||
@@ -98,16 +98,12 @@ jest.mock('@brojs/cli', () => {
|
||||
};
|
||||
});
|
||||
|
||||
describe('order page', () => {
|
||||
describe('Страница заказов', () => {
|
||||
beforeAll(() => server.listen());
|
||||
afterEach(() => server.resetHandlers());
|
||||
afterAll(() => server.close());
|
||||
|
||||
it('получение списка заказов ', async () => {
|
||||
server.events.on('request:start', ({ request }) => {
|
||||
console.log('Outgoing:', request.method, request.url);
|
||||
});
|
||||
|
||||
it('должна корректно отображать список заказов после загрузки данных', async () => {
|
||||
const { container } = render(
|
||||
<Provider store={store}>
|
||||
<ChakraProvider theme={chakraTheme}>
|
||||
|
||||
@@ -22,6 +22,7 @@ import { landingApi } from '../../__data__/service/landing.api';
|
||||
import { isErrorMessage } from '../../models/api';
|
||||
import { FEATURE } from '../../__data__/features';
|
||||
import { CarImageForm } from '../../components/order-view/car-img';
|
||||
import PriceCar from '../../components/PriceCar';
|
||||
|
||||
const Page: FC = () => {
|
||||
const { t } = useTranslation('~', {
|
||||
@@ -70,7 +71,12 @@ const Page: FC = () => {
|
||||
<>
|
||||
<>
|
||||
{isSuccess && (
|
||||
<VStack p={4} alignItems='flex-start' gap={4}>
|
||||
<VStack
|
||||
p={4}
|
||||
alignItems='flex-start'
|
||||
gap={4}
|
||||
data-testid='order-details'
|
||||
>
|
||||
<OrderDetails
|
||||
orderNumber={order.orderNumber}
|
||||
status={order.status}
|
||||
@@ -82,9 +88,16 @@ const Page: FC = () => {
|
||||
startWashTime={order.startWashTime}
|
||||
endWashTime={order.endWashTime}
|
||||
created={order.created}
|
||||
data-testid='order-details'
|
||||
/>
|
||||
{FEATURE.carImageUpload.isOn && (
|
||||
<CarImageForm orderId={orderId} />
|
||||
)}
|
||||
{FEATURE.carImageUpload.isOn && order.image && (
|
||||
<PriceCar
|
||||
image={order?.image}
|
||||
rating={order?.imageRating}
|
||||
/>
|
||||
)}
|
||||
</VStack>
|
||||
)}
|
||||
</>
|
||||
|
||||
13
src/utils/getCoordinates.ts
Normal file
13
src/utils/getCoordinates.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
const getCoordinates = (location: string) => {
|
||||
if (!location) return null;
|
||||
|
||||
const [lat, lon] = location
|
||||
.split(',')
|
||||
.map((coord) => parseFloat(coord.trim()));
|
||||
|
||||
if (isNaN(lat) || isNaN(lon)) return null;
|
||||
|
||||
return { lat, lon };
|
||||
};
|
||||
|
||||
export default getCoordinates;
|
||||
@@ -9,12 +9,8 @@
|
||||
"orderDate": "2024-11-24T08:41:46.366Z",
|
||||
"status": "pending",
|
||||
"phone": "79001234563",
|
||||
"location": "Казань, ул. Баумана, 1",
|
||||
"master": {
|
||||
"name": "Олег Макаров",
|
||||
"phone": "79001234567",
|
||||
"id": "23423442"
|
||||
},
|
||||
"location": "55.779905316526424,49.12446113769528 Республика Татарстан (Татарстан),н Казань, ул. Баумана, 1",
|
||||
"master": "4545423234",
|
||||
"notes": ""
|
||||
},
|
||||
{
|
||||
@@ -25,7 +21,7 @@
|
||||
"orderDate": "2024-11-24T07:40:46.366Z",
|
||||
"status": "progress",
|
||||
"phone": "79001234567",
|
||||
"location": "Казань, ул. Баумана, 43",
|
||||
"location": "55.75060416346278,48.746329576898944 Республика Татарстан (Татарстан), Верхнеуслонский район, Иннополис",
|
||||
"master": [],
|
||||
"notes": ""
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user