fix: place orders in the model
Some checks are pending
it-academy/dry-wash-pl/pipeline/pr-main Build started...
Some checks are pending
it-academy/dry-wash-pl/pipeline/pr-main Build started...
This commit is contained in:
parent
ed8ae95436
commit
658e23d4e3
@ -2,16 +2,15 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
|||||||
import { getConfigValue } from '@brojs/cli';
|
import { getConfigValue } from '@brojs/cli';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { Master } from '../../models/api/master';
|
import { Master, OrderArm } from '../../models/api';
|
||||||
import { OrderProps } from '../../components/OrderItem/OrderItem';
|
|
||||||
|
|
||||||
import { extractBodyFromResponse } from './utils';
|
import { extractBodyFromResponse } from './utils';
|
||||||
|
|
||||||
export type UpdateMasterPayload = Required<Pick<Master, 'id'>> &
|
export type UpdateMasterPayload = Required<Pick<Master, 'id'>> &
|
||||||
Partial<Omit<Master, 'id'>>;
|
Partial<Omit<Master, 'id'>>;
|
||||||
|
|
||||||
type UpdateOrderProps = Required<Pick<OrderProps, 'id'>> &
|
type UpdateOrderProps = Required<Pick<OrderArm, 'id'>> &
|
||||||
Partial<Pick<OrderProps, 'status' | 'notes'>> & {
|
Partial<Pick<OrderArm, 'status' | 'notes'>> & {
|
||||||
master?: string;
|
master?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ export const api = createApi({
|
|||||||
}),
|
}),
|
||||||
invalidatesTags: ['Orders'],
|
invalidatesTags: ['Orders'],
|
||||||
}),
|
}),
|
||||||
getOrders: builder.query<OrderProps[], { date: Date }>({
|
getOrders: builder.query<OrderArm[], { date: Date }>({
|
||||||
query: ({ date }) => {
|
query: ({ date }) => {
|
||||||
const startDate = dayjs(date).startOf('day').toISOString();
|
const startDate = dayjs(date).startOf('day').toISOString();
|
||||||
const endDate = dayjs(date).endOf('day').toISOString();
|
const endDate = dayjs(date).endOf('day').toISOString();
|
||||||
@ -43,7 +42,7 @@ export const api = createApi({
|
|||||||
body: { startDate, endDate },
|
body: { startDate, endDate },
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
transformResponse: extractBodyFromResponse<OrderProps[]>,
|
transformResponse: extractBodyFromResponse<OrderArm[]>,
|
||||||
providesTags: ['Orders'],
|
providesTags: ['Orders'],
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import {
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { PhoneIcon } from '@chakra-ui/icons';
|
import { PhoneIcon } from '@chakra-ui/icons';
|
||||||
|
|
||||||
import { api } from '../../__data__/service/api';
|
import { useAddMasterMutation } from '../../__data__/service/api';
|
||||||
import { DrawerInputs } from '../../models/arm/form';
|
import { DrawerInputs } from '../../models/arm/form';
|
||||||
import useShowToast from '../../hooks/useShowToast';
|
import useShowToast from '../../hooks/useShowToast';
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ const MasterDrawer = ({ isOpen, onClose }: MasterDrawerProps) => {
|
|||||||
await addMaster(trimMaster);
|
await addMaster(trimMaster);
|
||||||
};
|
};
|
||||||
|
|
||||||
const [addMaster, { error, isSuccess }] = api.useAddMasterMutation();
|
const [addMaster, { error, isSuccess }] = useAddMasterMutation();
|
||||||
const showToast = useShowToast();
|
const showToast = useShowToast();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -4,35 +4,8 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { getTimeSlot } from '../../lib';
|
import { getTimeSlot } from '../../lib';
|
||||||
import { Master } from '../../models/api/master';
|
|
||||||
import { useUpdateOrdersMutation } from '../../__data__/service/api';
|
import { useUpdateOrdersMutation } from '../../__data__/service/api';
|
||||||
|
import { OrderArm, Status, statuses } from '../../models/api';
|
||||||
const statuses = [
|
|
||||||
'pending' as const,
|
|
||||||
'progress' as const,
|
|
||||||
'working' as const,
|
|
||||||
'canceled' as const,
|
|
||||||
'complete' as const,
|
|
||||||
];
|
|
||||||
|
|
||||||
type GetArrItemType<ArrType> =
|
|
||||||
ArrType extends Array<infer ItemType> ? ItemType : never;
|
|
||||||
|
|
||||||
export type OrderProps = {
|
|
||||||
carNumber?: string;
|
|
||||||
startWashTime?: string;
|
|
||||||
endWashTime?: string;
|
|
||||||
orderDate?: string;
|
|
||||||
status?: GetArrItemType<typeof statuses>;
|
|
||||||
phone?: string;
|
|
||||||
location?: string;
|
|
||||||
master: Master;
|
|
||||||
notes: '';
|
|
||||||
allMasters: Master[];
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type Status = (typeof statuses)[number];
|
|
||||||
|
|
||||||
const statusColors: Record<Status, string> = {
|
const statusColors: Record<Status, string> = {
|
||||||
pending: 'yellow.100',
|
pending: 'yellow.100',
|
||||||
@ -53,7 +26,7 @@ const OrderItem = ({
|
|||||||
master,
|
master,
|
||||||
allMasters,
|
allMasters,
|
||||||
id,
|
id,
|
||||||
}: OrderProps) => {
|
}: OrderArm) => {
|
||||||
const [updateOrders] = useUpdateOrdersMutation();
|
const [updateOrders] = useUpdateOrdersMutation();
|
||||||
const { t } = useTranslation('~', {
|
const { t } = useTranslation('~', {
|
||||||
keyPrefix: 'dry-wash.arm.order',
|
keyPrefix: 'dry-wash.arm.order',
|
||||||
@ -78,7 +51,7 @@ const OrderItem = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handeChangeStatus = (e: ChangeEvent<HTMLSelectElement>) => {
|
const handeChangeStatus = (e: ChangeEvent<HTMLSelectElement>) => {
|
||||||
const status = e.target.value as OrderProps['status'];
|
const status = e.target.value as OrderArm['status'];
|
||||||
updateOrders({ id, status });
|
updateOrders({ id, status });
|
||||||
setStatus(status);
|
setStatus(status);
|
||||||
};
|
};
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export * from './common';
|
export * from './common';
|
||||||
export * from './order';
|
export * from './order';
|
||||||
|
export * from './master';
|
||||||
|
@ -1,21 +1,49 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-namespace */
|
/* eslint-disable @typescript-eslint/no-namespace */
|
||||||
import { Order } from "../landing";
|
import { Order } from '../landing';
|
||||||
|
|
||||||
import { ErrorMessage } from "./common";
|
import { ErrorMessage } from './common';
|
||||||
|
import { Master } from './master';
|
||||||
|
|
||||||
export namespace GetOrder {
|
export namespace GetOrder {
|
||||||
export type Response = Order.View;
|
export type Response = Order.View;
|
||||||
export type Params = {
|
export type Params = {
|
||||||
orderId: Order.Id
|
orderId: Order.Id;
|
||||||
};
|
};
|
||||||
export type Error = ErrorMessage;
|
export type Error = ErrorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace CreateOrder {
|
export namespace CreateOrder {
|
||||||
export type Response = {
|
export type Response = {
|
||||||
id: Order.Id
|
id: Order.Id;
|
||||||
};
|
};
|
||||||
export type Params = {
|
export type Params = {
|
||||||
body: Order.Create
|
body: Order.Create;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetArrItemType<ArrType> =
|
||||||
|
ArrType extends Array<infer ItemType> ? ItemType : never;
|
||||||
|
|
||||||
|
export const statuses = [
|
||||||
|
'pending' as const,
|
||||||
|
'progress' as const,
|
||||||
|
'working' as const,
|
||||||
|
'canceled' as const,
|
||||||
|
'complete' as const,
|
||||||
|
];
|
||||||
|
|
||||||
|
export type Status = (typeof statuses)[number];
|
||||||
|
|
||||||
|
export type OrderArm = {
|
||||||
|
carNumber?: string;
|
||||||
|
startWashTime?: string;
|
||||||
|
endWashTime?: string;
|
||||||
|
orderDate?: string;
|
||||||
|
status?: GetArrItemType<typeof statuses>;
|
||||||
|
phone?: string;
|
||||||
|
location?: string;
|
||||||
|
master: Master;
|
||||||
|
notes: '';
|
||||||
|
allMasters: Master[];
|
||||||
|
id: string;
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user