Skip to content

Commit 5cfa694

Browse files
committed
Incluindo modal de detalhes
1 parent e9414ed commit 5cfa694

File tree

12 files changed

+169
-29
lines changed

12 files changed

+169
-29
lines changed

backend/src/services/order/DetailOrderService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface OrderRequest {
66

77
class DetailOrderService {
88
async execute({ order_id }: OrderRequest) {
9-
const orders = await prismaClient.orderItem.findMany({
9+
const orders = await prismaClient.orderItem.findFirst({
1010
where: {
1111
order_id: order_id,
1212
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type StateDashboard = {
2+
orderId?: string
3+
}
4+
5+
const initialStateDashboard: StateDashboard = {
6+
orderId: undefined
7+
}
8+
9+
export { initialStateDashboard }
10+
export type { StateDashboard }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { createSelector } from "@reduxjs/toolkit";
2+
import { State } from "../../types";
3+
4+
const dashboard = (state: State) => state.dashboard;
5+
6+
const selectOrderId = createSelector(
7+
dashboard,
8+
(feature) => feature.orderId
9+
);
10+
11+
export { selectOrderId };
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { httpToken } from "../../infra/axios";
2-
import { Orders } from "../orders/orders.schema";
2+
import { Order, OrderDetail } from "../orders/orders.schema";
33

4-
const obterOrdersServices = async (): Promise<Orders[]> => {
4+
const obterOrdersServices = async (): Promise<Order[]> => {
55
try {
66
const response = await httpToken.get("orders")
77
return response.data
@@ -10,4 +10,15 @@ const obterOrdersServices = async (): Promise<Orders[]> => {
1010
}
1111
}
1212

13-
export { obterOrdersServices }
13+
const obterOrderDetailServices = async (order_id: string): Promise<OrderDetail> => {
14+
try {
15+
const response = await httpToken.get("order/details", { params: { order_id } })
16+
console.log(response);
17+
18+
return response.data
19+
} catch (error) {
20+
throw new Error("Não foi possivel concluir a operacao");
21+
}
22+
}
23+
24+
export { obterOrdersServices, obterOrderDetailServices }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
2+
import { initialStateDashboard } from "./dashboard.schema";
3+
4+
const dashboard = createSlice({
5+
name: "auth",
6+
initialState: initialStateDashboard,
7+
reducers: {
8+
setOrderId(state, action: PayloadAction<string | undefined>) {
9+
state.orderId = action.payload;
10+
}
11+
}
12+
})
13+
14+
export const { actions: dashboardAction, reducer: dashboardReducer } = dashboard

front-end/src/features/dashboard/index.tsx

+36-21
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,50 @@ import { useMutation } from "@tanstack/react-query";
66
import { obterOrdersServices } from "./dashboard.service";
77
import { useEffect } from "react";
88
import { Article, Section } from "../../shared/components/Article";
9+
import { useDispatch } from "react-redux";
10+
import { dashboardAction } from "./dashboard.state";
11+
import ModalDetalhes from "./modalDetails";
912

1013
const Dashboard = () => {
1114
const obterOrders = useMutation({ mutationFn: () => obterOrdersServices() });
15+
const dispatch = useDispatch();
16+
1217
useEffect(() => {
1318
obterOrders.mutate();
1419
}, []);
1520

21+
const handleSelectOrderId = (orderId: string) =>
22+
dispatch(dashboardAction.setOrderId(orderId));
1623
return (
17-
<Main>
18-
<TitleStyled>Painel</TitleStyled>
19-
<SubTitle>
20-
Últimos pedidos{" "}
21-
<Tooltip title="Recarregar">
22-
<Button
23-
onClick={() => obterOrders.mutate()}
24-
type="text"
25-
icon={<IconReloadOutlined />}
26-
/>
27-
</Tooltip>
28-
</SubTitle>
29-
<Spin spinning={obterOrders.isPending}>
30-
<Article>
31-
{obterOrders.data &&
32-
obterOrders.data.map((item) => (
33-
<Section key={item.id}>Mesa: {item.table}</Section>
34-
))}
35-
</Article>
36-
</Spin>
37-
</Main>
24+
<>
25+
<Main>
26+
<TitleStyled>Painel</TitleStyled>
27+
<SubTitle>
28+
Últimos pedidos{" "}
29+
<Tooltip title="Recarregar">
30+
<Button
31+
onClick={() => obterOrders.mutate()}
32+
type="text"
33+
icon={<IconReloadOutlined />}
34+
/>
35+
</Tooltip>
36+
</SubTitle>
37+
<Spin spinning={obterOrders.isPending}>
38+
<Article>
39+
{obterOrders.data &&
40+
obterOrders.data.map((item) => (
41+
<Section
42+
onClick={() => handleSelectOrderId(item.id)}
43+
key={item.id}
44+
>
45+
Mesa: {item.table}
46+
</Section>
47+
))}
48+
</Article>
49+
</Spin>
50+
</Main>
51+
<ModalDetalhes />
52+
</>
3853
);
3954
};
4055

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Modal, ModalProps, Spin } from "antd";
2+
import { useDispatch, useSelector } from "react-redux";
3+
import { selectOrderId } from "../dashboard.selector";
4+
import { dashboardAction } from "../dashboard.state";
5+
import { useMutation } from "@tanstack/react-query";
6+
import { obterOrderDetailServices } from "../dashboard.service";
7+
import { useEffect } from "react";
8+
9+
interface Props extends ModalProps {}
10+
11+
const ModalDetalhes: React.FC<Props> = ({ ...props }) => {
12+
const orderIdStore = useSelector(selectOrderId);
13+
14+
const dispatch = useDispatch();
15+
const handleCancelDetails = () =>
16+
dispatch(dashboardAction.setOrderId(undefined));
17+
18+
const obterOrderDetails = useMutation({
19+
mutationFn: (orderId: string) => obterOrderDetailServices(orderId),
20+
});
21+
22+
useEffect(() => {
23+
if (orderIdStore) {
24+
obterOrderDetails.mutate(orderIdStore);
25+
}
26+
}, []);
27+
28+
return (
29+
<>
30+
{orderIdStore && (
31+
<Modal
32+
onCancel={handleCancelDetails}
33+
open={orderIdStore != undefined}
34+
title="Detalhes"
35+
{...props}
36+
>
37+
<Spin spinning={obterOrderDetails.isPending}>
38+
{obterOrderDetails.data && <></>}
39+
</Spin>
40+
</Modal>
41+
)}
42+
</>
43+
);
44+
};
45+
46+
export default ModalDetalhes;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
interface Orders{
1+
interface Order {
22
id: string,
33
name: string,
44
table: number,
55
status: boolean
6+
draft?: boolean,
7+
create_at?: Date
8+
update_at?: Date
69
}
10+
interface OrderDetail {
11+
id: string;
12+
amount: number;
13+
create_at: Date;
14+
update_at: Date;
15+
order_id: string;
16+
product_id: string;
17+
order: Order;
18+
product: Product
19+
}
20+
721

8-
export type{Orders}
22+
export type { Order, OrderDetail }

front-end/src/features/product/product.schema.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,18 @@ interface NewProduct {
55
banner: string;
66
category_id: string;
77
file: any;
8-
}
8+
}
9+
10+
11+
12+
13+
interface Product {
14+
id: string;
15+
name: string
16+
price: string
17+
description: string
18+
banner: string
19+
create_at: Date
20+
update_at: Date
21+
category_id: string
22+
}

front-end/src/features/reducers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { combineReducers } from "redux";
22
import { authPersisted } from "../infra/config-redux/redux-persist";
3+
import { dashboardReducer } from "./dashboard/dashboard.state";
34

45
export default combineReducers({
5-
auth: authPersisted
6+
auth: authPersisted,
7+
dashboard: dashboardReducer
68
})

front-end/src/shared/components/Article/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const Section = styled.section`
1212
background-color: ${x => x.theme.colors.dark900};
1313
border-radius: .3rem;
1414
border-left: 7px solid ${x => x.theme.colors.green900};
15+
cursor: pointer;
1516
`;
1617

1718
export { Section, Article }

front-end/src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { StateAuth } from "./features/auth/auth.schema";
2+
import { StateDashboard } from "./features/dashboard/dashboard.schema";
23

34
export interface State {
45
auth: StateAuth;
6+
dashboard: StateDashboard;
57
}

0 commit comments

Comments
 (0)