feat: create order api

This commit is contained in:
RustamRu 2025-01-19 10:55:44 +03:00
parent 3ea501161c
commit a9a9b3cadd
2 changed files with 22 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { getConfigValue } from '@brojs/cli';
import { InputProps, SelectProps } from "@chakra-ui/react"; import { InputProps, SelectProps } from "@chakra-ui/react";
import { Order } from "../../../models/landing"; import { Order } from "../../../models/landing";
@ -56,11 +57,22 @@ export const formatFormValues = ({ phone, carNumber, carBody, carColor, carLocat
}; };
}; };
export const onSubmit = (values: OrderFormValues) => { const endpoint = getConfigValue('dry-wash.api');
return new Promise((resolve) => {
console.log(formatFormValues(values)); export const onSubmit = async (values: OrderFormValues) => {
resolve(formatFormValues(values)); const response = await fetch(`${endpoint}/order/create`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formatFormValues(values)),
}); });
if (!response.ok) {
throw new Error(`Failed to create order: ${response.status}`);
}
return await response.json();
}; };
export const inputCommonStyles: Partial<InputProps & SelectProps> = { export const inputCommonStyles: Partial<InputProps & SelectProps> = {

View File

@ -76,6 +76,12 @@ router.get('/order/:orderId', ({ params }, res) => {
); );
}); });
router.post('/order/create', (req, res) => {
res
.status(200)
.send({ success: true, body: { ok: true } });
});
router.use('/admin', require('./admin')); router.use('/admin', require('./admin'));
module.exports = router; module.exports = router;