fear: change requests to RTK query #78

Merged
primakov merged 3 commits from feature/rtk-query-arm into main 2025-02-09 10:10:41 +03:00
5 changed files with 45 additions and 44 deletions
Showing only changes of commit 658e23d4e3 - Show all commits

View File

@ -2,16 +2,15 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { getConfigValue } from '@brojs/cli';
import dayjs from 'dayjs';
import { Master } from '../../models/api/master';
import { OrderProps } from '../../components/OrderItem/OrderItem';
import { Master, OrderArm } from '../../models/api';
import { extractBodyFromResponse } from './utils';
export type UpdateMasterPayload = Required<Pick<Master, 'id'>> &
Partial<Omit<Master, 'id'>>;
type UpdateOrderProps = Required<Pick<OrderProps, 'id'>> &
Partial<Pick<OrderProps, 'status' | 'notes'>> & {
type UpdateOrderProps = Required<Pick<OrderArm, 'id'>> &
Partial<Pick<OrderArm, 'status' | 'notes'>> & {
master?: string;
};
@ -33,7 +32,7 @@ export const api = createApi({
}),
invalidatesTags: ['Orders'],
}),
getOrders: builder.query<OrderProps[], { date: Date }>({
getOrders: builder.query<OrderArm[], { date: Date }>({
query: ({ date }) => {
const startDate = dayjs(date).startOf('day').toISOString();
const endDate = dayjs(date).endOf('day').toISOString();
@ -43,7 +42,7 @@ export const api = createApi({
body: { startDate, endDate },
};
},
transformResponse: extractBodyFromResponse<OrderProps[]>,
transformResponse: extractBodyFromResponse<OrderArm[]>,
providesTags: ['Orders'],
}),

View File

@ -19,7 +19,7 @@ import {
import { useTranslation } from 'react-i18next';
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 useShowToast from '../../hooks/useShowToast';
@ -56,7 +56,7 @@ const MasterDrawer = ({ isOpen, onClose }: MasterDrawerProps) => {
await addMaster(trimMaster);
};
const [addMaster, { error, isSuccess }] = api.useAddMasterMutation();
const [addMaster, { error, isSuccess }] = useAddMasterMutation();
const showToast = useShowToast();
useEffect(() => {

View File

@ -4,35 +4,8 @@ import { useTranslation } from 'react-i18next';
import dayjs from 'dayjs';
import { getTimeSlot } from '../../lib';
import { Master } from '../../models/api/master';
import { useUpdateOrdersMutation } from '../../__data__/service/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];
import { OrderArm, Status, statuses } from '../../models/api';
const statusColors: Record<Status, string> = {
pending: 'yellow.100',
@ -53,7 +26,7 @@ const OrderItem = ({
master,
allMasters,
id,
}: OrderProps) => {
}: OrderArm) => {
const [updateOrders] = useUpdateOrdersMutation();
const { t } = useTranslation('~', {
keyPrefix: 'dry-wash.arm.order',
@ -78,7 +51,7 @@ const OrderItem = ({
};
const handeChangeStatus = (e: ChangeEvent<HTMLSelectElement>) => {
const status = e.target.value as OrderProps['status'];
const status = e.target.value as OrderArm['status'];
updateOrders({ id, status });
setStatus(status);
};

View File

@ -1,2 +1,3 @@
export * from './common';
export * from './order';
export * from './master';

View File

@ -1,21 +1,49 @@
/* 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 type Response = Order.View;
export type Params = {
orderId: Order.Id
orderId: Order.Id;
};
export type Error = ErrorMessage;
}
export namespace CreateOrder {
export type Response = {
id: Order.Id
id: Order.Id;
};
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;
};