Compare commits
No commits in common. "20017cad3c86b8e2773ad6a61770ecd943066884" and "c9c17340c6ec06cfb080ab5398b83bc80e7bcb17" have entirely different histories.
20017cad3c
...
c9c17340c6
@ -50,12 +50,6 @@
|
|||||||
"dry-wash.order-view.details.location": "Where",
|
"dry-wash.order-view.details.location": "Where",
|
||||||
"dry-wash.order-view.details.datetime-range": "When",
|
"dry-wash.order-view.details.datetime-range": "When",
|
||||||
"dry-wash.order-view.details.alert": "The operator will contact you about the payment at the specified phone number",
|
"dry-wash.order-view.details.alert": "The operator will contact you about the payment at the specified phone number",
|
||||||
"dry-wash.order-view.upload-car-image.field.label": "Upload a photo of your car, and our service will quickly calculate the pre-order price!",
|
|
||||||
"dry-wash.order-view.upload-car-image.field.help": "Allowed formats: .jpg, .png. Maximum size: 5MB",
|
|
||||||
"dry-wash.order-view.upload-car-image.file-input.placeholder": "Upload a file",
|
|
||||||
"dry-wash.order-view.upload-car-image.file-input.button": "Upload",
|
|
||||||
"dry-wash.order-view.upload-car-image-query.success.title": "The car image is successfully uploaded",
|
|
||||||
"dry-wash.order-view.upload-car-image-query.error.title": "Failed to upload the car image",
|
|
||||||
"dry-wash.arm.master.add": "Add",
|
"dry-wash.arm.master.add": "Add",
|
||||||
"dry-wash.arm.order.title": "Orders",
|
"dry-wash.arm.order.title": "Orders",
|
||||||
"dry-wash.arm.order.table.empty": "Table empty",
|
"dry-wash.arm.order.table.empty": "Table empty",
|
||||||
|
@ -105,12 +105,6 @@
|
|||||||
"dry-wash.order-view.details.location": "Где",
|
"dry-wash.order-view.details.location": "Где",
|
||||||
"dry-wash.order-view.details.datetime-range": "Когда",
|
"dry-wash.order-view.details.datetime-range": "Когда",
|
||||||
"dry-wash.order-view.details.alert": "С вами свяжется оператор насчет оплаты по указанному номеру телефона",
|
"dry-wash.order-view.details.alert": "С вами свяжется оператор насчет оплаты по указанному номеру телефона",
|
||||||
"dry-wash.order-view.upload-car-image.field.label": "Загрузите фото вашего автомобиля, и наш сервис быстро рассчитает предварительную стоимость заказа!",
|
|
||||||
"dry-wash.order-view.upload-car-image.field.help": "Допустимые форматы: .jpg, .png. Максимальный размер: 5МБ",
|
|
||||||
"dry-wash.order-view.upload-car-image.file-input.placeholder": "Загрузите файл",
|
|
||||||
"dry-wash.order-view.upload-car-image.file-input.button": "Загрузить",
|
|
||||||
"dry-wash.order-view.upload-car-image-query.success.title": "Изображение автомобиля успешно загружено",
|
|
||||||
"dry-wash.order-view.upload-car-image-query.error.title": "Не удалось загрузить изображение автомобиля",
|
|
||||||
"dry-wash.notFound.title": "Страница не найдена",
|
"dry-wash.notFound.title": "Страница не найдена",
|
||||||
"dry-wash.notFound.description": "К сожалению, запрашиваемая вами страница не существует.",
|
"dry-wash.notFound.description": "К сожалению, запрашиваемая вами страница не существует.",
|
||||||
"dry-wash.notFound.button.back": "Вернуться на главную",
|
"dry-wash.notFound.button.back": "Вернуться на главную",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { GetOrder, CreateOrder, UploadCarImage } from "../../models/api";
|
import { GetOrder, CreateOrder } from "../../models/api";
|
||||||
|
|
||||||
import { api } from "./api";
|
import { api } from "./api";
|
||||||
import { extractBodyFromResponse, extractErrorMessageFromResponse } from "./utils";
|
import { extractBodyFromResponse, extractErrorMessageFromResponse } from "./utils";
|
||||||
@ -19,13 +19,5 @@ export const landingApi = api.injectEndpoints({
|
|||||||
transformResponse: extractBodyFromResponse<CreateOrder.Response>,
|
transformResponse: extractBodyFromResponse<CreateOrder.Response>,
|
||||||
transformErrorResponse: extractErrorMessageFromResponse,
|
transformErrorResponse: extractErrorMessageFromResponse,
|
||||||
}),
|
}),
|
||||||
uploadCarImage: mutation<UploadCarImage.Response, UploadCarImage.Params>({
|
|
||||||
query: ({ orderId, body }) => ({
|
|
||||||
url: `/order/${orderId}/upload-car-img`,
|
|
||||||
body,
|
|
||||||
method: 'POST'
|
|
||||||
}),
|
|
||||||
transformErrorResponse: extractErrorMessageFromResponse,
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -13,9 +13,9 @@ export const extractErrorMessageFromResponse = ({
|
|||||||
}: FetchBaseQueryError) => {
|
}: FetchBaseQueryError) => {
|
||||||
if (
|
if (
|
||||||
typeof data === 'object' &&
|
typeof data === 'object' &&
|
||||||
'error' in data &&
|
'message' in data &&
|
||||||
typeof data.error === 'string'
|
typeof data.message === 'string'
|
||||||
) {
|
) {
|
||||||
return data.error;
|
return data.message;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,102 +0,0 @@
|
|||||||
import React, { FC, memo, useRef } from 'react';
|
|
||||||
import { Controller, useForm } from 'react-hook-form';
|
|
||||||
import {
|
|
||||||
Button,
|
|
||||||
FormControl,
|
|
||||||
FormErrorMessage,
|
|
||||||
FormHelperText,
|
|
||||||
FormLabel,
|
|
||||||
HStack,
|
|
||||||
Input,
|
|
||||||
} from '@chakra-ui/react';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
|
|
||||||
import { landingApi } from '../../../__data__/service/landing.api';
|
|
||||||
import { UploadCarImage } from '../../../models/api';
|
|
||||||
|
|
||||||
import { useHandleUploadCarImageResponse } from './helper';
|
|
||||||
|
|
||||||
type FormValues = {
|
|
||||||
carImg: File & {
|
|
||||||
fileName: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
type CarImageFormProps = {
|
|
||||||
orderId: UploadCarImage.Params['orderId'];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const CarImageForm: FC<CarImageFormProps> = memo(function CarImageForm({
|
|
||||||
orderId,
|
|
||||||
}) {
|
|
||||||
const {
|
|
||||||
handleSubmit,
|
|
||||||
control,
|
|
||||||
formState: { errors, isSubmitting },
|
|
||||||
} = useForm<FormValues>({ shouldFocusError: true });
|
|
||||||
|
|
||||||
const [uploadCarImage, uploadCarImageMutation] =
|
|
||||||
landingApi.useUploadCarImageMutation();
|
|
||||||
useHandleUploadCarImageResponse(uploadCarImageMutation);
|
|
||||||
|
|
||||||
const onSubmit = (formData: FormValues) => {
|
|
||||||
const body = new FormData();
|
|
||||||
body.append('file', formData.carImg);
|
|
||||||
uploadCarImage({ orderId, body });
|
|
||||||
};
|
|
||||||
|
|
||||||
const fileInputRef = useRef(null);
|
|
||||||
|
|
||||||
const { t } = useTranslation('~', {
|
|
||||||
keyPrefix: 'dry-wash.order-view.upload-car-image',
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<form>
|
|
||||||
<FormControl>
|
|
||||||
<FormLabel htmlFor='carImg'>{t('field.label')}</FormLabel>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name='carImg'
|
|
||||||
render={({ field: { value, onChange, ...field } }) => {
|
|
||||||
return (
|
|
||||||
<HStack gap={0}>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
ref={fileInputRef}
|
|
||||||
accept='.jpg,.png'
|
|
||||||
value={value?.fileName}
|
|
||||||
onChange={(event) => {
|
|
||||||
onChange(event.target.files[0]);
|
|
||||||
handleSubmit(onSubmit)();
|
|
||||||
}}
|
|
||||||
type='file'
|
|
||||||
hidden
|
|
||||||
/>
|
|
||||||
<Input
|
|
||||||
placeholder={t('file-input.placeholder')}
|
|
||||||
value={value?.name || ''}
|
|
||||||
readOnly
|
|
||||||
borderRightRadius={0}
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
onClick={() => {
|
|
||||||
fileInputRef.current.click();
|
|
||||||
}}
|
|
||||||
isLoading={isSubmitting || uploadCarImageMutation.isLoading}
|
|
||||||
colorScheme='primary'
|
|
||||||
paddingInline={8}
|
|
||||||
borderLeftRadius={0}
|
|
||||||
>
|
|
||||||
{t('file-input.button')}
|
|
||||||
</Button>
|
|
||||||
</HStack>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<FormErrorMessage>{errors.carImg?.message}</FormErrorMessage>
|
|
||||||
<FormHelperText>{t('field.help')}</FormHelperText>
|
|
||||||
</FormControl>
|
|
||||||
</form>
|
|
||||||
);
|
|
||||||
});
|
|
@ -1,35 +0,0 @@
|
|||||||
import { useEffect } from "react";
|
|
||||||
import { useToast } from "@chakra-ui/react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
import { isErrorMessage } from "../../../models/api";
|
|
||||||
|
|
||||||
export const useHandleUploadCarImageResponse = (query: {
|
|
||||||
isSuccess: boolean;
|
|
||||||
isError: boolean;
|
|
||||||
error?: unknown;
|
|
||||||
}) => {
|
|
||||||
const toast = useToast();
|
|
||||||
const { t } = useTranslation('~', {
|
|
||||||
keyPrefix: 'dry-wash.order-create.upload-car-image-query',
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (query.isError) {
|
|
||||||
toast({
|
|
||||||
status: 'error',
|
|
||||||
title: t('error.title'),
|
|
||||||
description: isErrorMessage(query.error) ? query.error : undefined,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [query.isError]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (query.isSuccess) {
|
|
||||||
toast({
|
|
||||||
status: 'success',
|
|
||||||
title: t('success.title'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [query.isSuccess]);
|
|
||||||
};
|
|
@ -1 +0,0 @@
|
|||||||
export { CarImageForm } from './car-img-form';
|
|
@ -5,13 +5,11 @@ import {
|
|||||||
Heading,
|
Heading,
|
||||||
HStack,
|
HStack,
|
||||||
UnorderedList,
|
UnorderedList,
|
||||||
|
VStack,
|
||||||
ListItem,
|
ListItem,
|
||||||
Text,
|
Text,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import dayjs from 'dayjs';
|
|
||||||
import localizedFormat from "dayjs/plugin/localizedFormat";
|
|
||||||
dayjs.extend(localizedFormat);
|
|
||||||
|
|
||||||
import { Order } from '../../../models/landing';
|
import { Order } from '../../../models/landing';
|
||||||
import { formatDatetime } from '../../../lib';
|
import { formatDatetime } from '../../../lib';
|
||||||
@ -43,7 +41,7 @@ export const OrderDetails: FC<OrderDetailsProps> = ({
|
|||||||
location,
|
location,
|
||||||
startWashTime,
|
startWashTime,
|
||||||
endWashTime,
|
endWashTime,
|
||||||
created
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation('~', {
|
const { t } = useTranslation('~', {
|
||||||
keyPrefix: 'dry-wash.order-view.details',
|
keyPrefix: 'dry-wash.order-view.details',
|
||||||
@ -53,7 +51,7 @@ export const OrderDetails: FC<OrderDetailsProps> = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<VStack p={4} alignItems='flex-start' gap={4} {...props}>
|
||||||
<HStack
|
<HStack
|
||||||
width='full'
|
width='full'
|
||||||
flexWrap='wrap'
|
flexWrap='wrap'
|
||||||
@ -61,7 +59,7 @@ export const OrderDetails: FC<OrderDetailsProps> = ({
|
|||||||
gap={2}
|
gap={2}
|
||||||
>
|
>
|
||||||
<Heading as='h2' size='lg'>
|
<Heading as='h2' size='lg'>
|
||||||
{t('title', { number: orderNumber })} ({dayjs(created).format('LLLL')})
|
{t('title', { number: orderNumber })}
|
||||||
</Heading>
|
</Heading>
|
||||||
<OrderStatus value={status} />
|
<OrderStatus value={status} />
|
||||||
</HStack>
|
</HStack>
|
||||||
@ -107,7 +105,7 @@ export const OrderDetails: FC<OrderDetailsProps> = ({
|
|||||||
<AlertIcon />
|
<AlertIcon />
|
||||||
{t('alert')}
|
{t('alert')}
|
||||||
</Alert>
|
</Alert>
|
||||||
</>
|
</VStack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ export const isErrorMessage = (error: unknown): error is ErrorMessage => typeof
|
|||||||
|
|
||||||
type ErrorResponse = {
|
type ErrorResponse = {
|
||||||
success: false;
|
success: false;
|
||||||
error: ErrorMessage;
|
message: ErrorMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BaseResponse<Body> = SuccessResponse<Body> | ErrorResponse;
|
export type BaseResponse<Body> = SuccessResponse<Body> | ErrorResponse;
|
||||||
|
@ -21,17 +21,6 @@ export namespace CreateOrder {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace UploadCarImage {
|
|
||||||
export type Response = void;
|
|
||||||
export type Params = {
|
|
||||||
orderId: Order.Id;
|
|
||||||
/**
|
|
||||||
* @example { file: File }
|
|
||||||
*/
|
|
||||||
body: FormData;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetArrItemType<ArrType> =
|
type GetArrItemType<ArrType> =
|
||||||
ArrType extends Array<infer ItemType> ? ItemType : never;
|
ArrType extends Array<infer ItemType> ? ItemType : never;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import { Order } from '../../models/landing';
|
|||||||
import { landingApi } from '../../__data__/service/landing.api';
|
import { landingApi } from '../../__data__/service/landing.api';
|
||||||
import { isErrorMessage } from '../../models/api';
|
import { isErrorMessage } from '../../models/api';
|
||||||
import { FEATURE } from '../../__data__/features';
|
import { FEATURE } from '../../__data__/features';
|
||||||
import { CarImageForm } from '../../components/order-view/car-img';
|
|
||||||
|
|
||||||
const Page: FC = () => {
|
const Page: FC = () => {
|
||||||
const { t } = useTranslation('~', {
|
const { t } = useTranslation('~', {
|
||||||
@ -70,31 +69,24 @@ const Page: FC = () => {
|
|||||||
<>
|
<>
|
||||||
<>
|
<>
|
||||||
{isSuccess && (
|
{isSuccess && (
|
||||||
<VStack p={4} alignItems='flex-start' gap={4}>
|
<OrderDetails
|
||||||
<OrderDetails
|
orderNumber={order.orderNumber}
|
||||||
orderNumber={order.orderNumber}
|
status={order.status}
|
||||||
status={order.status}
|
phone={order.phone}
|
||||||
phone={order.phone}
|
carNumber={order.carNumber}
|
||||||
carNumber={order.carNumber}
|
carBody={order.carBody}
|
||||||
carBody={order.carBody}
|
carColor={order.carColor}
|
||||||
carColor={order.carColor}
|
location={order.location}
|
||||||
location={order.location}
|
startWashTime={order.startWashTime}
|
||||||
startWashTime={order.startWashTime}
|
endWashTime={order.endWashTime}
|
||||||
endWashTime={order.endWashTime}
|
created={order.created}
|
||||||
created={order.created}
|
data-testid='order-details'
|
||||||
data-testid='order-details'
|
/>
|
||||||
/>
|
|
||||||
<CarImageForm orderId={orderId} />
|
|
||||||
</VStack>
|
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
<>
|
<>
|
||||||
{isError && (
|
{isError && (
|
||||||
<Alert
|
<Alert status='error' alignItems='flex-start' data-testid='error'>
|
||||||
status='error'
|
|
||||||
alignItems='flex-start'
|
|
||||||
data-testid='error'
|
|
||||||
>
|
|
||||||
<AlertIcon />
|
<AlertIcon />
|
||||||
<Box>
|
<Box>
|
||||||
<AlertTitle>
|
<AlertTitle>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
||||||
const router = require('express').Router();
|
const router = require('express').Router();
|
||||||
|
|
||||||
const STUBS = { masters: 'success', orders: 'success', orderCreate: 'success', orderView: 'success-pending', orderCarImg: 'success' };
|
const STUBS = { masters: 'success', orders: 'success', orderCreate: 'success', orderView: 'success-pending' };
|
||||||
|
|
||||||
router.get('/set/:name/:value', (req, res) => {
|
router.get('/set/:name/:value', (req, res) => {
|
||||||
const { name, value } = req.params;
|
const { name, value } = req.params;
|
||||||
@ -15,34 +15,28 @@ router.get('/set/:name/:value', (req, res) => {
|
|||||||
router.get('/', (req, res) => {
|
router.get('/', (req, res) => {
|
||||||
res.send(`<div>
|
res.send(`<div>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Мастера</legend>
|
<legend>Мастера</legend>
|
||||||
${generateRadioInput('masters', 'success')}
|
${generateRadioInput('masters', 'success')}
|
||||||
${generateRadioInput('masters', 'error')}
|
${generateRadioInput('masters', 'error')}
|
||||||
${generateRadioInput('masters', 'empty')}
|
${generateRadioInput('masters', 'empty')}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Заказы</legend>
|
<legend>Заказы</legend>
|
||||||
${generateRadioInput('orders', 'success')}
|
${generateRadioInput('orders', 'success')}
|
||||||
${generateRadioInput('orders', 'error')}
|
${generateRadioInput('orders', 'error')}
|
||||||
${generateRadioInput('orders', 'empty')}
|
${generateRadioInput('orders', 'empty')}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Лендинг - Сделать заказ</legend>
|
<legend>Лендинг - Сделать заказ</legend>
|
||||||
${generateRadioInput('orderCreate', 'success')}
|
${generateRadioInput('orderCreate', 'success')}
|
||||||
${generateRadioInput('orderCreate', 'error')}
|
${generateRadioInput('orderCreate', 'error')}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Лендинг - Детали заказа</legend>
|
<legend>Лендинг - Детали заказа</legend>
|
||||||
${generateRadioInput('orderView', 'success-pending')}
|
${generateRadioInput('orderView', 'success-pending')}
|
||||||
${generateRadioInput('orderView', 'success-working')}
|
${generateRadioInput('orderView', 'success-working')}
|
||||||
${generateRadioInput('orderView', 'error')}
|
${generateRadioInput('orderView', 'error')}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
|
||||||
<legend>Лендинг - Детали заказа, фото машины</legend>
|
|
||||||
${generateRadioInput('orderCarImg', 'success')}
|
|
||||||
${generateRadioInput('orderCarImg', 'error-file-type')}
|
|
||||||
${generateRadioInput('orderCarImg', 'error-file-size')}
|
|
||||||
</fieldset>
|
|
||||||
</div>`);
|
</div>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -98,22 +98,6 @@ router.post('/order/create', (req, res) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/order/:orderId/upload-car-img', (req, res) => {
|
|
||||||
const { orderId } = req.params;
|
|
||||||
const stubName = `${orderId}-${STUBS.orderCarImg}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
res
|
|
||||||
.status(/error/.test(stubName) ? 500 : 200)
|
|
||||||
.send(require(`../json/landing-order-car-image-upload/${stubName}.json`));
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
res
|
|
||||||
.status(500)
|
|
||||||
.send(commonError);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
router.use('/admin', require('./admin'));
|
router.use('/admin', require('./admin'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"success": false,
|
|
||||||
"error": "Invalid car image file size. Limit is 5MB"
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"success": false,
|
|
||||||
"error": "Invalid car image file type. Allowed types: jpg, png"
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"success": true
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"success": false,
|
"success": false,
|
||||||
"error": "Не удалось создать заказ"
|
"message": "Не удалось создать заказ"
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"success": false,
|
"success": false,
|
||||||
"error": "Не удалось загрузить детали заказа"
|
"message": "Не удалось загрузить детали заказа"
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user