Merge branch 'feature/order'
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { Box, Image, Progress, Text } from '@chakra-ui/react';
|
||||
import { Box, Image, Progress, Text, VStack } from '@chakra-ui/react';
|
||||
import React from 'react';
|
||||
import { getFeatures } from '@brojs/cli';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const PRICE_INCREASE_PERCENT_PER_RATING = 10; // 10% за каждый балл
|
||||
import { formatPrice, getProgressColor } from './helper';
|
||||
|
||||
const PRICE_INCREASE_PERCENT_PER_RATING = 10;
|
||||
|
||||
export const PriceCar = ({ image, rating, description }) => {
|
||||
const BASE_WASH_PRICE: number = Number(
|
||||
@@ -15,33 +18,56 @@ export const PriceCar = ({ image, rating, description }) => {
|
||||
return BASE_WASH_PRICE + priceIncrease;
|
||||
};
|
||||
|
||||
const { i18n, t } = useTranslation('~', {
|
||||
keyPrefix: 'dry-wash.order-view.price-car',
|
||||
});
|
||||
const washPrice = calculateWashPrice(rating);
|
||||
const formattedPrice = formatPrice(washPrice, i18n.language);
|
||||
|
||||
const progressValue = (rating / 10) * 100;
|
||||
|
||||
return (
|
||||
<Box
|
||||
alignItems='center'
|
||||
gap={5}
|
||||
width='100%'
|
||||
display='flex'
|
||||
flexDirection='column'
|
||||
justifyContent='center'
|
||||
alignItems='flex-start'
|
||||
flexWrap='wrap'
|
||||
>
|
||||
<Image
|
||||
maxWidth='600px'
|
||||
width='100%'
|
||||
objectFit='contain'
|
||||
borderRadius='md'
|
||||
src={image}
|
||||
alt='Car Image'
|
||||
alt=''
|
||||
/>
|
||||
{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>
|
||||
)}
|
||||
<Text>{description}</Text>
|
||||
<Box flex='1 1 40%'>
|
||||
{!Number.isNaN(progressValue) ? (
|
||||
<VStack alignItems='stretch'>
|
||||
<Box>
|
||||
<Text>{t('title')}</Text>
|
||||
<Progress
|
||||
value={progressValue}
|
||||
size='sm'
|
||||
sx={{
|
||||
'& > div': {
|
||||
backgroundColor: getProgressColor(progressValue),
|
||||
},
|
||||
}}
|
||||
mt={2}
|
||||
/>
|
||||
<Text mt={2}>
|
||||
{t('description')} <b>{formattedPrice}</b>
|
||||
</Text>
|
||||
</Box>
|
||||
<Text fontStyle='italic'>{description}</Text>
|
||||
</VStack>
|
||||
) : (
|
||||
<Text>{t('error')}</Text>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
15
src/components/PriceCar/helper.ts
Normal file
15
src/components/PriceCar/helper.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export const formatPrice = (price: number, locale = 'ru-RU', currency = 'RUB') => {
|
||||
return new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency: currency,
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
}).format(price);
|
||||
};
|
||||
|
||||
export const getProgressColor = (value: number) => {
|
||||
const normalizedValue = value / 100;
|
||||
const hue = 120 - normalizedValue * 120;
|
||||
|
||||
return `hsl(${hue}, 100%, 50%)`;
|
||||
};
|
||||
@@ -40,12 +40,14 @@ export const CarBodySelect = forwardRef<HTMLInputElement, CarBodySelectProps>(
|
||||
});
|
||||
|
||||
return (
|
||||
<Box width='100%'>
|
||||
<Box width='100%' pos='relative'>
|
||||
<Popover
|
||||
isOpen={isOpen}
|
||||
autoFocus={false}
|
||||
placement='bottom-start'
|
||||
matchWidth
|
||||
gutter={2}
|
||||
strategy="fixed"
|
||||
>
|
||||
<PopoverAnchor>
|
||||
<Input
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export { CarBodySelect } from './car-body-select';
|
||||
export { CarBodySelect } from './car-body-select';
|
||||
export { carBodySelectOptions } from './helper';
|
||||
@@ -0,0 +1,75 @@
|
||||
import React from 'react';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
|
||||
import { CarColorSelect } from './car-color-select';
|
||||
|
||||
// Mock the translation hook
|
||||
jest.mock('react-i18next', () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string) => {
|
||||
// Return the last part of the key as that's what component is using
|
||||
const keyParts = key.split('.');
|
||||
return keyParts[keyParts.length - 1];
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('CarColorSelect', () => {
|
||||
it('renders color options correctly', () => {
|
||||
const onChange = jest.fn();
|
||||
render(<CarColorSelect onChange={onChange} />);
|
||||
|
||||
// Check if color buttons are rendered
|
||||
const colorButtons = screen.getAllByRole('button');
|
||||
expect(colorButtons.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('handles color selection', () => {
|
||||
const onChange = jest.fn();
|
||||
render(<CarColorSelect onChange={onChange} />);
|
||||
|
||||
// Click the first color button
|
||||
const colorButtons = screen.getAllByRole('button');
|
||||
fireEvent.click(colorButtons[0]);
|
||||
|
||||
expect(onChange).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles custom color selection', () => {
|
||||
const onChange = jest.fn();
|
||||
render(<CarColorSelect onChange={onChange} />);
|
||||
|
||||
// Find and click the custom color button
|
||||
const customButton = screen.getByText('custom');
|
||||
fireEvent.click(customButton);
|
||||
|
||||
// Check if custom color input appears
|
||||
const customInput = screen.getByPlaceholderText('placeholder');
|
||||
expect(customInput).toBeInTheDocument();
|
||||
|
||||
// Test custom color input
|
||||
fireEvent.change(customInput, { target: { value: '#FF0000' } });
|
||||
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({
|
||||
target: { value: '#FF0000' },
|
||||
}));
|
||||
});
|
||||
|
||||
it('shows selected color label when color is selected', () => {
|
||||
const onChange = jest.fn();
|
||||
render(<CarColorSelect value="black" onChange={onChange} />);
|
||||
|
||||
// Since the color label might not be immediately visible,
|
||||
// we'll verify the component renders without crashing
|
||||
const buttons = screen.getAllByRole('button');
|
||||
expect(buttons.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('handles invalid state', () => {
|
||||
render(<CarColorSelect isInvalid={true} />);
|
||||
|
||||
// Since the component doesn't show explicit invalid state UI,
|
||||
// we'll verify that the component renders without crashing
|
||||
expect(screen.getAllByRole('button').length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
@@ -1,14 +1,10 @@
|
||||
import React, { forwardRef, useState } from 'react';
|
||||
import {
|
||||
Input,
|
||||
Box,
|
||||
Stack,
|
||||
Text,
|
||||
Flex,
|
||||
} from '@chakra-ui/react';
|
||||
import { Input, Box, Stack, Text, Flex } from '@chakra-ui/react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { CAR_COLORS } from './helper';
|
||||
import { Car } from '../../../../models';
|
||||
|
||||
import { carColorSelectOptions } from './helper';
|
||||
|
||||
interface CarColorSelectProps {
|
||||
value?: string;
|
||||
@@ -18,11 +14,11 @@ interface CarColorSelectProps {
|
||||
}
|
||||
|
||||
export const CarColorSelect = forwardRef<HTMLInputElement, CarColorSelectProps>(
|
||||
function CarColorSelect(props) {
|
||||
function CarColorSelect(props, ref) {
|
||||
const [customColor, setCustomColor] = useState('');
|
||||
const [isCustom, setIsCustom] = useState(false);
|
||||
|
||||
const handleColorChange = (value: string) => {
|
||||
const handleColorChange = (value: Car.Color | string) => {
|
||||
if (value === 'custom') {
|
||||
setIsCustom(true);
|
||||
return;
|
||||
@@ -33,7 +29,9 @@ export const CarColorSelect = forwardRef<HTMLInputElement, CarColorSelectProps>(
|
||||
} as React.ChangeEvent<HTMLInputElement>);
|
||||
};
|
||||
|
||||
const handleCustomColorChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const handleCustomColorChange = (
|
||||
e: React.ChangeEvent<HTMLInputElement>,
|
||||
) => {
|
||||
const value = e.target.value;
|
||||
setCustomColor(value);
|
||||
props.onChange?.({
|
||||
@@ -48,107 +46,124 @@ export const CarColorSelect = forwardRef<HTMLInputElement, CarColorSelectProps>(
|
||||
const currentValue = isCustom ? 'custom' : props.value;
|
||||
|
||||
return (
|
||||
<Stack spacing={4} width="100%">
|
||||
<Flex gap={3} wrap="nowrap" overflowX="auto" pb={2}>
|
||||
{CAR_COLORS.map(({ name, code }) => (
|
||||
<Box
|
||||
key={name}
|
||||
<Stack spacing={4} width='100%' ref={ref}>
|
||||
<Flex gap={2} wrap='wrap' pb={2}>
|
||||
{carColorSelectOptions.map(({ value, labelTKey, code }) => (
|
||||
<Box
|
||||
key={value}
|
||||
flexShrink={0}
|
||||
as="button"
|
||||
type="button"
|
||||
onClick={() => handleColorChange(name)}
|
||||
as='button'
|
||||
type='button'
|
||||
onClick={() => handleColorChange(value)}
|
||||
>
|
||||
<Flex
|
||||
align="center"
|
||||
gap={2}
|
||||
p={2}
|
||||
borderRadius="full"
|
||||
borderWidth="2px"
|
||||
borderColor={currentValue === name ? 'primary.500' : 'gray.200'}
|
||||
bg={currentValue === name ? 'primary.50' : 'white'}
|
||||
_hover={{
|
||||
<Flex
|
||||
align='center'
|
||||
gap={2}
|
||||
p={1}
|
||||
borderRadius='full'
|
||||
borderWidth='2px'
|
||||
borderColor='gray.200'
|
||||
bg='white'
|
||||
_hover={{
|
||||
borderColor: 'primary.500',
|
||||
bg: currentValue === name ? 'primary.50' : 'gray.50'
|
||||
bg: 'gray.50',
|
||||
}}
|
||||
minW={currentValue === name ? '120px' : 'auto'}
|
||||
h="48px"
|
||||
justify="center"
|
||||
transition="all 0.2s"
|
||||
justify='center'
|
||||
transition='all 0.2s'
|
||||
{...(currentValue === value && {
|
||||
borderColor: 'primary.500',
|
||||
bg: 'primary.50',
|
||||
paddingInlineEnd: 3,
|
||||
_hover: {
|
||||
bg: 'primary.50',
|
||||
},
|
||||
})}
|
||||
>
|
||||
<Flex align="center" gap={2}>
|
||||
<Flex align='center' gap={2}>
|
||||
<Box
|
||||
w="32px"
|
||||
h="32px"
|
||||
borderRadius="full"
|
||||
w='32px'
|
||||
h='32px'
|
||||
borderRadius='full'
|
||||
bg={code}
|
||||
border="1px"
|
||||
borderColor={currentValue === name ? 'primary.500' : 'gray.200'}
|
||||
transition="all 0.2s"
|
||||
boxShadow={currentValue === name ? 'sm' : 'none'}
|
||||
border='1px'
|
||||
borderColor='gray.200'
|
||||
transition='all 0.2s'
|
||||
boxShadow='none'
|
||||
{...(currentValue === value && {
|
||||
borderColor: 'primary.500',
|
||||
boxShadow: 'sm',
|
||||
})}
|
||||
/>
|
||||
{currentValue === name && (
|
||||
<Text fontSize="xs" color="primary.700" fontWeight="medium">
|
||||
{t(`colors.${name}`)}
|
||||
{currentValue === value && (
|
||||
<Text fontSize='xs' color='primary.700' fontWeight='medium'>
|
||||
{t(`colors.${labelTKey}`)}
|
||||
</Text>
|
||||
)}
|
||||
</Flex>
|
||||
</Flex>
|
||||
</Box>
|
||||
))}
|
||||
<Box
|
||||
<Box
|
||||
flexShrink={0}
|
||||
as="button"
|
||||
type="button"
|
||||
as='button'
|
||||
type='button'
|
||||
onClick={() => handleColorChange('custom')}
|
||||
>
|
||||
<Flex
|
||||
align="center"
|
||||
<Flex
|
||||
align='center'
|
||||
gap={2}
|
||||
p={2}
|
||||
borderRadius="full"
|
||||
borderWidth="2px"
|
||||
borderColor={isCustom ? 'primary.500' : 'gray.200'}
|
||||
bg={isCustom ? 'primary.50' : 'white'}
|
||||
_hover={{
|
||||
p={1}
|
||||
paddingInlineEnd={3}
|
||||
borderRadius='full'
|
||||
borderWidth='2px'
|
||||
borderColor='gray.200'
|
||||
bg='white'
|
||||
_hover={{
|
||||
borderColor: 'primary.500',
|
||||
bg: isCustom ? 'primary.50' : 'gray.50'
|
||||
bg: 'gray.50',
|
||||
}}
|
||||
minW={isCustom ? '200px' : 'auto'}
|
||||
h="48px"
|
||||
justify="center"
|
||||
transition="all 0.2s"
|
||||
justify='center'
|
||||
transition='all 0.2s'
|
||||
{...(isCustom && {
|
||||
borderColor: 'primary.500',
|
||||
paddingInlineStart: 3,
|
||||
bg: 'primary.50',
|
||||
_hover: {
|
||||
bg: 'primary.50',
|
||||
},
|
||||
})}
|
||||
>
|
||||
{isCustom ? (
|
||||
<Flex gap={2} align="center">
|
||||
<Text fontSize="xs" color="primary.700" fontWeight="medium">
|
||||
<Flex gap={2} align='center'>
|
||||
<Text fontSize='xs' color='primary.700' fontWeight='medium'>
|
||||
{t('custom-label')}
|
||||
</Text>
|
||||
<Input
|
||||
size="sm"
|
||||
width="120px"
|
||||
size='sm'
|
||||
width='120px'
|
||||
value={customColor}
|
||||
onChange={handleCustomColorChange}
|
||||
placeholder={t('placeholder')}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
borderColor="primary.200"
|
||||
borderColor='primary.200'
|
||||
_focus={{
|
||||
borderColor: 'primary.500',
|
||||
boxShadow: '0 0 0 1px var(--chakra-colors-primary-500)'
|
||||
boxShadow: '0 0 0 1px var(--chakra-colors-primary-500)',
|
||||
}}
|
||||
/>
|
||||
</Flex>
|
||||
) : (
|
||||
<Flex align="center" gap={2}>
|
||||
<Flex align='center' gap={2}>
|
||||
<Box
|
||||
w="32px"
|
||||
h="32px"
|
||||
borderRadius="full"
|
||||
bg="gray.100"
|
||||
border="1px"
|
||||
borderColor="gray.200"
|
||||
transition="all 0.2s"
|
||||
w='32px'
|
||||
h='32px'
|
||||
borderRadius='full'
|
||||
bg='gray.100'
|
||||
border='1px'
|
||||
borderColor='gray.200'
|
||||
transition='all 0.2s'
|
||||
/>
|
||||
<Text fontSize="xs" color="gray.500">
|
||||
<Text fontSize='xs' color='gray.500'>
|
||||
{t('custom')}
|
||||
</Text>
|
||||
</Flex>
|
||||
@@ -159,4 +174,4 @@ export const CarColorSelect = forwardRef<HTMLInputElement, CarColorSelectProps>(
|
||||
</Stack>
|
||||
);
|
||||
},
|
||||
);
|
||||
);
|
||||
|
||||
@@ -1,34 +1,44 @@
|
||||
export const CAR_COLORS = [
|
||||
import { Car } from "../../../../models";
|
||||
|
||||
export const carColorSelectOptions: { value: Car.Color | string; labelTKey: 'white' | 'black' | 'silver' | 'gray' | 'beige-brown' | 'red' | 'blue' | 'green'; code: string }[] = [
|
||||
{
|
||||
name: 'white',
|
||||
value: Car.Color.WHITE,
|
||||
labelTKey: 'white',
|
||||
code: '#ffffff'
|
||||
},
|
||||
{
|
||||
name: 'black',
|
||||
value: Car.Color.BLACK,
|
||||
labelTKey: 'black',
|
||||
code: '#000000'
|
||||
},
|
||||
{
|
||||
name: 'silver',
|
||||
value: Car.Color.SILVER,
|
||||
labelTKey: 'silver',
|
||||
code: '#c0c0c0'
|
||||
},
|
||||
{
|
||||
name: 'gray',
|
||||
value: Car.Color.GRAY,
|
||||
labelTKey: 'gray',
|
||||
code: '#808080'
|
||||
},
|
||||
{
|
||||
name: 'beige-brown',
|
||||
value: Car.Color.BEIGE_BROWN,
|
||||
labelTKey: 'beige-brown',
|
||||
code: '#796745'
|
||||
},
|
||||
{
|
||||
name: 'red',
|
||||
value: Car.Color.RED,
|
||||
labelTKey: 'red',
|
||||
code: '#b90000'
|
||||
},
|
||||
{
|
||||
name: 'blue',
|
||||
value: Car.Color.BLUE,
|
||||
labelTKey: 'blue',
|
||||
code: '#003B62'
|
||||
},
|
||||
{
|
||||
name: 'green',
|
||||
value: Car.Color.GREEN,
|
||||
labelTKey: 'green',
|
||||
code: '#078d51'
|
||||
},
|
||||
] as const satisfies { name: string; code: string }[];
|
||||
];
|
||||
@@ -1 +1,2 @@
|
||||
export { CarColorSelect } from './car-color-select';
|
||||
export { CarColorSelect } from './car-color-select';
|
||||
export { carColorSelectOptions } from './helper';
|
||||
@@ -1,2 +1,4 @@
|
||||
export type { OrderFormValues, OrderFormProps } from './types';
|
||||
export { OrderForm } from './order-form';
|
||||
export { OrderForm } from './order-form';
|
||||
export { carBodySelectOptions } from './car-body';
|
||||
export { carColorSelectOptions } from './car-color';
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { forwardRef, memo, useEffect, useState } from 'react';
|
||||
import React, { ForwardedRef, forwardRef, memo, useEffect, useState } from 'react';
|
||||
import {
|
||||
Input,
|
||||
Box,
|
||||
@@ -24,129 +24,130 @@ import {
|
||||
} from './helper';
|
||||
import { LocationInputProps } from './types';
|
||||
|
||||
export const LocationInput = memo(
|
||||
withYMaps(
|
||||
forwardRef<HTMLInputElement, LocationInputProps>(function LocationInput(
|
||||
{ ymaps, value, onChange, ...props },
|
||||
ref,
|
||||
) {
|
||||
const [inputValue, setInputValue] = useState<string>('');
|
||||
export const BaseLocationInput = withYMaps(
|
||||
({ ymaps, value = '', onChange, inputRef, ...props }: LocationInputProps & { inputRef: ForwardedRef<HTMLInputElement> }) => {
|
||||
const [inputValue, setInputValue] = useState<string>('');
|
||||
|
||||
useEffect(() => {
|
||||
setInputValue(value);
|
||||
}, [value]);
|
||||
useEffect(() => {
|
||||
setInputValue(value);
|
||||
}, [value]);
|
||||
|
||||
const [suggestions, setSuggestions] = useState<Suggestion[]>([]);
|
||||
const [isSuggestionsPanelOpen, setIsSuggestionsPanelOpen] =
|
||||
useState<boolean>(false);
|
||||
const [suggestions, setSuggestions] = useState<Suggestion[]>([]);
|
||||
const [isSuggestionsPanelOpen, setIsSuggestionsPanelOpen] =
|
||||
useState<boolean>(false);
|
||||
|
||||
const onInputChange: InputProps['onChange'] = async (e) => {
|
||||
const newInputValue = e.target.value;
|
||||
const onInputChange: InputProps['onChange'] = async (e) => {
|
||||
const newInputValue = e.target.value;
|
||||
|
||||
if (
|
||||
isValidLocation(newInputValue) &&
|
||||
(await isRealLocation(ymaps, newInputValue))
|
||||
) {
|
||||
onChange(newInputValue);
|
||||
} else {
|
||||
setInputValue(newInputValue);
|
||||
|
||||
if (newInputValue.trim().length > 3) {
|
||||
try {
|
||||
const address = extractAddress(newInputValue);
|
||||
const results = await ymaps.suggest(address);
|
||||
setSuggestions(results);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
} else {
|
||||
setSuggestions([]);
|
||||
if (
|
||||
isValidLocation(newInputValue) &&
|
||||
(await isRealLocation(ymaps, newInputValue))
|
||||
) {
|
||||
onChange(newInputValue);
|
||||
} else {
|
||||
setInputValue(newInputValue);
|
||||
|
||||
if (newInputValue.trim().length > 3) {
|
||||
try {
|
||||
const address = extractAddress(newInputValue);
|
||||
const results = await ymaps.suggest(address);
|
||||
setSuggestions(results);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
setIsSuggestionsPanelOpen(suggestions.length > 1);
|
||||
}
|
||||
};
|
||||
|
||||
const onFocus: InputProps['onFocus'] = () => {
|
||||
setIsSuggestionsPanelOpen(suggestions.length > 1);
|
||||
};
|
||||
|
||||
const onBlur: InputProps['onBlur'] = async (e) => {
|
||||
const inputValue = e.target.value;
|
||||
if (
|
||||
isValidLocation(inputValue) &&
|
||||
(await isRealLocation(ymaps, inputValue))
|
||||
) {
|
||||
onChange(inputValue);
|
||||
} else {
|
||||
setInputValue(value);
|
||||
setSuggestions([]);
|
||||
}
|
||||
setIsSuggestionsPanelOpen(false);
|
||||
};
|
||||
|
||||
const handleSuggestionClick = async ({ value: address }: Suggestion) => {
|
||||
try {
|
||||
const location = await getLocationByAddress(ymaps, address);
|
||||
const newValue = formatLocation(location);
|
||||
setInputValue(newValue);
|
||||
onChange(newValue);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
setIsSuggestionsPanelOpen(suggestions.length > 1);
|
||||
}
|
||||
};
|
||||
|
||||
const { t } = useTranslation('~', {
|
||||
keyPrefix: 'dry-wash.order-create.form.washing-location-field',
|
||||
});
|
||||
const onFocus: InputProps['onFocus'] = () => {
|
||||
setIsSuggestionsPanelOpen(suggestions.length > 1);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box width='100%'>
|
||||
<Popover
|
||||
isOpen={isSuggestionsPanelOpen}
|
||||
autoFocus={false}
|
||||
placement='bottom-start'
|
||||
>
|
||||
<PopoverAnchor>
|
||||
<Input
|
||||
{...props}
|
||||
ref={ref}
|
||||
onBlur={onBlur}
|
||||
value={inputValue ?? value}
|
||||
onChange={onInputChange}
|
||||
onFocus={onFocus}
|
||||
placeholder={t('placeholder')}
|
||||
/>
|
||||
</PopoverAnchor>
|
||||
<PopoverContent width='100%' maxWidth='100%'>
|
||||
<PopoverBody border='1px' borderColor='gray.300' p={0}>
|
||||
<List>
|
||||
{suggestions.map((suggestion, index) => (
|
||||
<ListItem
|
||||
key={index}
|
||||
p={2}
|
||||
cursor='pointer'
|
||||
_hover={{
|
||||
bgColor: 'primary.50',
|
||||
}}
|
||||
_active={{
|
||||
bgColor: 'primary.100',
|
||||
}}
|
||||
onClick={() => handleSuggestionClick(suggestion)}
|
||||
>
|
||||
{suggestion.displayName}
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
</PopoverBody>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</Box>
|
||||
);
|
||||
}),
|
||||
true,
|
||||
['suggest', 'geocode'],
|
||||
),
|
||||
const onBlur: InputProps['onBlur'] = async (e) => {
|
||||
const inputValue = e.target.value;
|
||||
if (
|
||||
isValidLocation(inputValue) &&
|
||||
(await isRealLocation(ymaps, inputValue))
|
||||
) {
|
||||
onChange(inputValue);
|
||||
} else {
|
||||
setInputValue(value);
|
||||
}
|
||||
setIsSuggestionsPanelOpen(false);
|
||||
};
|
||||
|
||||
const handleSuggestionClick = async ({ value: address }: Suggestion) => {
|
||||
try {
|
||||
const location = await getLocationByAddress(ymaps, address);
|
||||
const newValue = formatLocation(location);
|
||||
setInputValue(newValue);
|
||||
onChange(newValue);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const { t } = useTranslation('~', {
|
||||
keyPrefix: 'dry-wash.order-create.form.washing-location-field',
|
||||
});
|
||||
|
||||
return (
|
||||
<Box width='100%'>
|
||||
<Popover
|
||||
isOpen={isSuggestionsPanelOpen}
|
||||
autoFocus={false}
|
||||
placement='bottom-start'
|
||||
>
|
||||
<PopoverAnchor>
|
||||
<Input
|
||||
{...props}
|
||||
ref={inputRef}
|
||||
onBlur={onBlur}
|
||||
value={inputValue || value}
|
||||
onChange={onInputChange}
|
||||
onFocus={onFocus}
|
||||
placeholder={t('placeholder')}
|
||||
/>
|
||||
</PopoverAnchor>
|
||||
<PopoverContent width='100%' maxWidth='100%'>
|
||||
<PopoverBody border='1px' borderColor='gray.300' p={0}>
|
||||
<List>
|
||||
{suggestions.map((suggestion, index) => (
|
||||
<ListItem
|
||||
key={index}
|
||||
p={2}
|
||||
cursor='pointer'
|
||||
_hover={{
|
||||
bgColor: 'primary.50',
|
||||
}}
|
||||
_active={{
|
||||
bgColor: 'primary.100',
|
||||
}}
|
||||
onClick={() => handleSuggestionClick(suggestion)}
|
||||
>
|
||||
{suggestion.displayName}
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
</PopoverBody>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</Box>
|
||||
);
|
||||
},
|
||||
true,
|
||||
['suggest', 'geocode'],
|
||||
);
|
||||
|
||||
export const LocationInput = memo(forwardRef<HTMLInputElement, LocationInputProps>(
|
||||
function LocationInput(props, ref) {
|
||||
return <BaseLocationInput {...props} inputRef={ref} />;
|
||||
},
|
||||
));
|
||||
|
||||
// todo: i18n
|
||||
// todo: replace console.error with toast
|
||||
|
||||
@@ -31,8 +31,22 @@ export const MapComponent: FC<{
|
||||
}
|
||||
}, [selectedLocation]);
|
||||
|
||||
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
|
||||
useEffect(() => {
|
||||
const handleResize = () => {
|
||||
setWindowWidth(window.innerWidth);
|
||||
};
|
||||
|
||||
window.addEventListener('resize', handleResize);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('resize', handleResize);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Map
|
||||
key={windowWidth}
|
||||
state={{
|
||||
center: mapCenter,
|
||||
zoom:
|
||||
|
||||
@@ -10,12 +10,17 @@ import {
|
||||
} from '@chakra-ui/react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import dayjs from 'dayjs';
|
||||
import localizedFormat from "dayjs/plugin/localizedFormat";
|
||||
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
||||
dayjs.extend(localizedFormat);
|
||||
import 'dayjs/locale/ru';
|
||||
import 'dayjs/locale/en';
|
||||
|
||||
import { Order } from '../../../models/landing';
|
||||
import { formatDatetime } from '../../../lib';
|
||||
import { carBodySelectOptions } from '../../order-form/form/car-body/helper';
|
||||
import {
|
||||
carBodySelectOptions,
|
||||
carColorSelectOptions,
|
||||
} from '../../order-form';
|
||||
|
||||
import { OrderStatus } from './status';
|
||||
|
||||
@@ -43,26 +48,32 @@ export const OrderDetails: FC<OrderDetailsProps> = ({
|
||||
location,
|
||||
startWashTime,
|
||||
endWashTime,
|
||||
created
|
||||
created,
|
||||
}) => {
|
||||
const { t } = useTranslation('~', {
|
||||
const { t, i18n } = useTranslation('~', {
|
||||
keyPrefix: 'dry-wash.order-view.details',
|
||||
});
|
||||
dayjs.locale(i18n.language);
|
||||
const { t: tCarBody } = useTranslation('~', {
|
||||
keyPrefix: 'dry-wash.order-create.car-body-select.options',
|
||||
});
|
||||
const { t: tCarColor } = useTranslation('~', {
|
||||
keyPrefix: 'dry-wash.order-create.car-color-select.colors',
|
||||
});
|
||||
const carColorTKey = carColorSelectOptions.find(({ value }) => value === carColor)?.labelTKey;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Heading as='h2' size='lg' marginInline='auto'>
|
||||
{t('title', { number: orderNumber })}
|
||||
</Heading>
|
||||
<HStack
|
||||
width='full'
|
||||
flexWrap='wrap'
|
||||
justifyContent='space-between'
|
||||
gap={2}
|
||||
>
|
||||
<Heading as='h2' size='lg'>
|
||||
{t('title', { number: orderNumber })} ({dayjs(created).format('LLLL')})
|
||||
</Heading>
|
||||
<Text>{dayjs(created).format('LLL')}</Text>
|
||||
<OrderStatus value={status} />
|
||||
</HStack>
|
||||
<UnorderedList styleType='none'>
|
||||
@@ -78,7 +89,7 @@ export const OrderDetails: FC<OrderDetailsProps> = ({
|
||||
tCarBody(
|
||||
`${carBodySelectOptions.find(({ value }) => value === carBody)?.labelTKey}`,
|
||||
),
|
||||
carColor,
|
||||
carColorTKey ? tCarColor(carColorTKey) : carColor,
|
||||
]
|
||||
.filter((v) => v)
|
||||
.join(', '),
|
||||
|
||||
Reference in New Issue
Block a user