feat: add update status and masters (#67) #68
@ -58,7 +58,8 @@
|
|||||||
"dry-wash.arm.order.status.pending": "Pending",
|
"dry-wash.arm.order.status.pending": "Pending",
|
||||||
"dry-wash.arm.order.status.working": "Working",
|
"dry-wash.arm.order.status.working": "Working",
|
||||||
"dry-wash.arm.order.status.canceled": "Canceled",
|
"dry-wash.arm.order.status.canceled": "Canceled",
|
||||||
"dry-wash.arm.order.status.placeholder": "Select Status",
|
"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",
|
"dry-wash.arm.order.table.header.carNumber": "Car Number",
|
||||||
"dry-wash.arm.order.table.header.washingTime": "Washing Time",
|
"dry-wash.arm.order.table.header.washingTime": "Washing Time",
|
||||||
"dry-wash.arm.order.table.header.orderDate": "Order Date",
|
"dry-wash.arm.order.table.header.orderDate": "Order Date",
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"dry-wash.arm.order.status.working": "В работе",
|
"dry-wash.arm.order.status.working": "В работе",
|
||||||
"dry-wash.arm.order.status.canceled": "Отменено",
|
"dry-wash.arm.order.status.canceled": "Отменено",
|
||||||
"dry-wash.arm.order.status.placeholder": "Выберите статус",
|
"dry-wash.arm.order.status.placeholder": "Выберите статус",
|
||||||
|
"dry-wash.arm.order.master.placeholder": "Выберите мастера",
|
||||||
"dry-wash.arm.order.table.header.carNumber": "Номер машины",
|
"dry-wash.arm.order.table.header.carNumber": "Номер машины",
|
||||||
"dry-wash.arm.order.table.header.washingTime": "Время мойки",
|
"dry-wash.arm.order.table.header.washingTime": "Время мойки",
|
||||||
"dry-wash.arm.order.table.header.orderDate": "Дата заказа",
|
"dry-wash.arm.order.table.header.orderDate": "Дата заказа",
|
||||||
|
@ -72,6 +72,34 @@ const armService = () => {
|
|||||||
return await response.json();
|
return await response.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateOrders = async ({
|
||||||
|
id,
|
||||||
|
status,
|
||||||
|
notes,
|
||||||
|
masterId,
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
status?: string;
|
||||||
|
notes?: string;
|
||||||
|
masterId?: string;
|
||||||
|
}) => {
|
||||||
|
const body = JSON.stringify({ status, notes, masterId });
|
||||||
|
|
||||||
|
const response = await fetch(`${endpoint}${ArmEndpoints.MASTERS}/${id}`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to fetch update masters: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
};
|
||||||
|
|
||||||
const updateMaster = async ({
|
const updateMaster = async ({
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
@ -98,7 +126,14 @@ const armService = () => {
|
|||||||
return await response.json();
|
return await response.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
return { fetchOrders, fetchMasters, addMaster, deleteMaster, updateMaster };
|
return {
|
||||||
|
fetchOrders,
|
||||||
|
fetchMasters,
|
||||||
|
addMaster,
|
||||||
|
deleteMaster,
|
||||||
|
updateMaster,
|
||||||
|
updateOrders,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export { armService, ArmEndpoints };
|
export { armService, ArmEndpoints };
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { ChangeEvent, useState } from 'react';
|
||||||
import { Td, Tr, Link, Select } from '@chakra-ui/react';
|
import { Td, Tr, Link, Select } from '@chakra-ui/react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { MasterProps } from '../MasterItem/MasterItem';
|
import { MasterProps } from '../MasterItem/MasterItem';
|
||||||
import { getTimeSlot } from '../../lib';
|
import { getTimeSlot } from '../../lib';
|
||||||
|
import { armService } from '../../api/arm';
|
||||||
|
|
||||||
const statuses = [
|
const statuses = [
|
||||||
'pending' as const,
|
'pending' as const,
|
||||||
@ -28,6 +29,7 @@ export type OrderProps = {
|
|||||||
master: MasterProps;
|
master: MasterProps;
|
||||||
notes: '';
|
notes: '';
|
||||||
allMasters: MasterProps[];
|
allMasters: MasterProps[];
|
||||||
|
id: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Status = (typeof statuses)[number];
|
type Status = (typeof statuses)[number];
|
||||||
@ -50,7 +52,10 @@ const OrderItem = ({
|
|||||||
location,
|
location,
|
||||||
master,
|
master,
|
||||||
allMasters,
|
allMasters,
|
||||||
|
id,
|
||||||
}: OrderProps) => {
|
}: OrderProps) => {
|
||||||
|
const { updateOrders } = armService();
|
||||||
|
|
||||||
const { t } = useTranslation('~', {
|
const { t } = useTranslation('~', {
|
||||||
keyPrefix: 'dry-wash.arm.order',
|
keyPrefix: 'dry-wash.arm.order',
|
||||||
});
|
});
|
||||||
@ -59,15 +64,37 @@ const OrderItem = ({
|
|||||||
const bgColor = statusColors[statusSelect];
|
const bgColor = statusColors[statusSelect];
|
||||||
const [masterSelect, setMaster] = useState(master?.name);
|
const [masterSelect, setMaster] = useState(master?.name);
|
||||||
|
|
||||||
|
const handelChangeMasters = (e: ChangeEvent<HTMLSelectElement>) => {
|
||||||
|
const masterName = e.target.value;
|
||||||
|
const selectedMaster = allMasters.find(
|
||||||
|
(master) => master.name === masterName,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (selectedMaster) {
|
||||||
|
setMaster(masterName);
|
||||||
|
updateOrders({ id, masterId: selectedMaster.id });
|
||||||
|
} else {
|
||||||
|
console.error('Master not found');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handeChangeStatus = (e: ChangeEvent<HTMLSelectElement>) => {
|
||||||
|
const status = e.target.value;
|
||||||
|
updateOrders({ id, status });
|
||||||
|
setStatus(e.target.value as OrderProps['status']);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tr>
|
<Tr>
|
||||||
<Td>{carNumber}</Td>
|
<Td>{carNumber}</Td>
|
||||||
<Td>{getTimeSlot(startWashTime, endWashTime)}</Td>
|
<Td>
|
||||||
<Td>{dayjs(orderDate).format('DD.MM.YYYY')}</Td>
|
{dayjs(orderDate).format('DD.MM.YYYY')} <br />
|
||||||
|
{getTimeSlot(startWashTime, endWashTime)}
|
||||||
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<Select
|
<Select
|
||||||
value={statusSelect}
|
value={statusSelect}
|
||||||
onChange={(e) => setStatus(e.target.value as OrderProps['status'])}
|
onChange={handeChangeStatus}
|
||||||
placeholder={t(`status.placeholder`)}
|
placeholder={t(`status.placeholder`)}
|
||||||
bg={bgColor}
|
bg={bgColor}
|
||||||
>
|
>
|
||||||
@ -81,8 +108,8 @@ const OrderItem = ({
|
|||||||
<Td>
|
<Td>
|
||||||
<Select
|
<Select
|
||||||
value={masterSelect}
|
value={masterSelect}
|
||||||
onChange={(e) => setMaster(e.target.value as OrderProps['status'])}
|
onChange={handelChangeMasters}
|
||||||
placeholder={t(`status.placeholder`)}
|
placeholder={t(`master.placeholder`)}
|
||||||
>
|
>
|
||||||
{allMasters.map((item) => (
|
{allMasters.map((item) => (
|
||||||
<option key={item.id} value={item.name}>
|
<option key={item.id} value={item.name}>
|
||||||
|
@ -23,7 +23,6 @@ import { MasterProps } from '../MasterItem/MasterItem';
|
|||||||
|
|
||||||
const TABLE_HEADERS = [
|
const TABLE_HEADERS = [
|
||||||
'carNumber' as const,
|
'carNumber' as const,
|
||||||
'washingTime' as const,
|
|
||||||
'orderDate' as const,
|
'orderDate' as const,
|
||||||
'status' as const,
|
'status' as const,
|
||||||
'masters' as const,
|
'masters' as const,
|
||||||
|
@ -53,6 +53,16 @@ router.delete('/arm/masters/:id', (req, res) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.patch('/orders/:id', (req, res) => {
|
||||||
|
res
|
||||||
|
.status(/error/.test(STUBS.orders) ? 500 : 200)
|
||||||
|
.send(
|
||||||
|
/^error$/.test(STUBS.orders)
|
||||||
|
? commonError
|
||||||
|
: require(`../json/arm-orders/${STUBS.orders}.json`),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
router.post('/arm/orders', (req, res) => {
|
router.post('/arm/orders', (req, res) => {
|
||||||
res
|
res
|
||||||
.status(/error/.test(STUBS.orders) ? 500 : 200)
|
.status(/error/.test(STUBS.orders) ? 500 : 200)
|
||||||
@ -77,9 +87,7 @@ router.get('/order/:orderId', ({ params }, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.post('/order/create', (req, res) => {
|
router.post('/order/create', (req, res) => {
|
||||||
res
|
res.status(200).send({ success: true, body: { ok: true } });
|
||||||
.status(200)
|
|
||||||
.send({ success: true, body: { ok: true } });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.use('/admin', require('./admin'));
|
router.use('/admin', require('./admin'));
|
||||||
|
@ -6,9 +6,14 @@
|
|||||||
"name": "Иван Иванов",
|
"name": "Иван Иванов",
|
||||||
"phone": "+7 900 123 45 67"
|
"phone": "+7 900 123 45 67"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Олег Макаров",
|
||||||
|
"phone": "79001234567",
|
||||||
|
"id": "23423442"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "345354234",
|
"id": "345354234",
|
||||||
"name": "Иван Иванов",
|
"name": "Иван Галкин",
|
||||||
"schedule": [ {
|
"schedule": [ {
|
||||||
"id": "order1",
|
"id": "order1",
|
||||||
"startWashTime": "2024-11-24T10:30:00.000Z",
|
"startWashTime": "2024-11-24T10:30:00.000Z",
|
||||||
|
@ -7,10 +7,14 @@
|
|||||||
"startWashTime": "2024-11-24T10:30:00.000Z",
|
"startWashTime": "2024-11-24T10:30:00.000Z",
|
||||||
"endWashTime": "2024-11-24T16:30:00.000Z",
|
"endWashTime": "2024-11-24T16:30:00.000Z",
|
||||||
"orderDate": "2024-11-24T08:41:46.366Z",
|
"orderDate": "2024-11-24T08:41:46.366Z",
|
||||||
"status": "progress",
|
"status": "pending",
|
||||||
"phone": "79001234563",
|
"phone": "79001234563",
|
||||||
"location": "Казань, ул. Баумана, 1",
|
"location": "Казань, ул. Баумана, 1",
|
||||||
"master": [],
|
"master": {
|
||||||
|
"name": "Олег Макаров",
|
||||||
|
"phone": "79001234567",
|
||||||
|
"id": "23423442"
|
||||||
|
},
|
||||||
"notes": ""
|
"notes": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user