Skip to content

Commit 9c606bf

Browse files
committed
Resolvidos conflitos após merge
2 parents ca91f43 + 4cc9370 commit 9c606bf

File tree

9 files changed

+237
-0
lines changed

9 files changed

+237
-0
lines changed

src/components/sidebar.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useNavigate } from "react-router-dom";
22
import Menus from "./constants/menus";
3+
<<<<<<< HEAD
34

45
type SidebarProps = {
56
instanceId: string;
@@ -12,6 +13,19 @@ function Sidebar({ instanceId }: SidebarProps) {
1213
if (!path) return;
1314

1415
navigate(`/instance/${instanceId}/${path}`);
16+
=======
17+
import { useInstance } from "@/contexts/InstanceContext";
18+
19+
function Sidebar() {
20+
const navigate = useNavigate();
21+
22+
const { instance } = useInstance();
23+
24+
const handleNavigate = (path?: string) => {
25+
if (!path || !instance) return;
26+
27+
navigate(`/instance/${instance.id}/${path}`);
28+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
1529
};
1630

1731
return (

src/contexts/InstanceContext.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React, {
2+
createContext,
3+
useContext,
4+
useState,
5+
useEffect,
6+
ReactNode,
7+
} from "react";
8+
import { useParams } from "react-router-dom";
9+
import { Instance } from "@/types/evolution.types";
10+
import { fetchInstance } from "@/services/instances.service";
11+
12+
interface InstanceContextProps {
13+
instance: Instance | null;
14+
}
15+
16+
export const InstanceContext = createContext<InstanceContextProps | null>(null);
17+
18+
export const useInstance = () => {
19+
const context = useContext(InstanceContext);
20+
if (!context) {
21+
throw new Error("useInstance must be used within an InstanceProvider");
22+
}
23+
return context;
24+
};
25+
26+
interface InstanceProviderProps {
27+
children: ReactNode;
28+
}
29+
30+
export const InstanceProvider: React.FC<InstanceProviderProps> = ({
31+
children,
32+
}): React.ReactNode => {
33+
const { instanceId } = useParams<{ instanceId: string }>();
34+
const [instance, setInstance] = useState<Instance | null>(null);
35+
36+
useEffect(() => {
37+
const fetchData = async (instanceId: string) => {
38+
try {
39+
const data = await fetchInstance(instanceId);
40+
setInstance(data[0] || null);
41+
} catch (error) {
42+
console.error("Erro ao buscar dados:", error);
43+
}
44+
};
45+
46+
if (instanceId) {
47+
fetchData(instanceId);
48+
}
49+
}, [instanceId]);
50+
51+
return (
52+
<InstanceContext.Provider value={{ instance }}>
53+
{children}
54+
</InstanceContext.Provider>
55+
);
56+
};

src/layout/InstanceLayout.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,62 @@
1+
<<<<<<< HEAD
12
import "./instance-layout.css";
23

34
import React from "react";
45
import { Header } from "@/components/header";
56
import { Sidebar } from "@/components/sidebar";
67
import { useParams } from "react-router-dom";
8+
=======
9+
// InstanceLayout.tsx
10+
import "./instance-layout.css";
11+
import React from "react";
12+
import { Header } from "@/components/header";
13+
import { Sidebar } from "@/components/sidebar";
14+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
715
import {
816
ResizableHandle,
917
ResizablePanel,
1018
ResizablePanelGroup,
1119
} from "@/components/ui/resizable";
20+
<<<<<<< HEAD
21+
=======
22+
import { InstanceProvider } from "@/contexts/InstanceContext";
23+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
1224

1325
interface LayoutProps {
1426
children: React.ReactNode;
1527
}
1628

1729
function InstanceLayout({ children }: LayoutProps) {
30+
<<<<<<< HEAD
1831
const { instanceId } = useParams<{ instanceId: string }>();
1932

2033
return (
2134
<>
35+
=======
36+
return (
37+
<InstanceProvider>
38+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
2239
<Header perfil={true} />
2340
<div className="layout-general">
2441
<div className="instance-layout">
2542
<ResizablePanelGroup direction="horizontal">
2643
<ResizablePanel defaultSize={15}>
44+
<<<<<<< HEAD
2745
<Sidebar instanceId={`${instanceId}`} />
46+
=======
47+
<Sidebar />
48+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
2849
</ResizablePanel>
2950
<ResizableHandle withHandle className="border border-black" />
3051
<ResizablePanel>{children}</ResizablePanel>
3152
</ResizablePanelGroup>
3253
</div>
3354
</div>
55+
<<<<<<< HEAD
3456
</>
57+
=======
58+
</InstanceProvider>
59+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
3560
);
3661
}
3762

src/pages/Dashboard/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import { useNavigate } from "react-router-dom";
1919
const fetchData = async (callback: (data: Instance[]) => void) => {
2020
try {
2121
const data = await fetchInstances();
22+
<<<<<<< HEAD
23+
=======
24+
25+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
2226
callback(data);
2327
} catch (error) {
2428
console.error("Erro ao buscar dados:", error);
@@ -35,9 +39,17 @@ function Dashboard() {
3539
setDropdownOpen(!dropdownOpen);
3640
};
3741

42+
<<<<<<< HEAD
3843
const handleInstance = (instanceName: string) => {
3944
navigate(`/instance/${instanceName}/dashboard`);
4045
};
46+
=======
47+
const handleInstance =
48+
(instanceId: string): (() => void) =>
49+
() => {
50+
navigate(`/instance/${instanceId}/dashboard`);
51+
};
52+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
4153

4254
useEffect(() => {
4355
const getData = async () => {
@@ -124,7 +136,11 @@ function Dashboard() {
124136
<span>{instance.token}</span>
125137
<Copy className="card-icon" size="15" />
126138
</div>
139+
<<<<<<< HEAD
127140
<div className="card-menu" onClick={() => handleInstance(instance.name)}>
141+
=======
142+
<div className="card-menu" onClick={handleInstance(instance.id)}>
143+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
128144
<Cog className="card-icon" size="20" />
129145
</div>
130146
</div>

src/pages/instance/DashboardInstance/index.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
import { useEffect, useState, useCallback } from "react";
23
import { Button } from "@/components/ui/button";
34
import "./style.css";
@@ -186,6 +187,66 @@ function DashboardInstance() {
186187
</Button>
187188
</div>
188189
</div>
190+
=======
191+
import { Button } from "@/components/ui/button";
192+
import "./style.css";
193+
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
194+
import { useInstance } from "@/contexts/InstanceContext";
195+
196+
function DashboardInstance() {
197+
const { instance } = useInstance();
198+
199+
const renderStatus = (status: string | undefined) => {
200+
switch (status) {
201+
case "open":
202+
return (
203+
<div className="dashboard-status">
204+
<i className="status-icon connected"></i>
205+
<span className="status-text">CONECTADO</span>
206+
</div>
207+
);
208+
case "connecting":
209+
return (
210+
<div className="dashboard-status">
211+
<i className="status-icon connecting"></i>
212+
<span className="status-text">CONECTANDO</span>
213+
</div>
214+
);
215+
case "closed":
216+
return (
217+
<div className="dashboard-status">
218+
<i className="status-icon disconnected"></i>
219+
<span className="status-text">DESCONECTADO</span>
220+
</div>
221+
);
222+
default:
223+
return (
224+
<div className="dashboard-status">
225+
<i className="status-icon disconnected"></i>
226+
<span className="status-text">DESCONECTADO</span>
227+
</div>
228+
);
229+
}
230+
};
231+
232+
return (
233+
<>
234+
<main className="dashboard-instance">
235+
<div className="dashboard-card">
236+
<div className="dashboard-info">
237+
{renderStatus(instance?.connectionStatus)}
238+
<div className="dashboard-name">{instance?.name}</div>
239+
</div>
240+
<div className="dashboard-actions">
241+
<Button className="action-button">REINICIAR</Button>
242+
<Button className="action-button disabled">DESCONECTAR</Button>
243+
</div>
244+
</div>
245+
<div className="connection-warning">
246+
<span>Telefone não conectado</span>
247+
<Button className="connect-button">CONECTAR</Button>
248+
</div>
249+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
189250
</main>
190251
<main className="instance-cards">
191252
<Card className="instance-card">
@@ -207,9 +268,12 @@ function DashboardInstance() {
207268
<CardContent>0</CardContent>
208269
</Card>
209270
</main>
271+
<<<<<<< HEAD
210272
{showQRCode && (
211273
<QRCodePopup qrCodeData={qrCodeData} onClose={closeQRCodePopup} />
212274
)}
275+
=======
276+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
213277
</>
214278
);
215279
}

src/pages/instance/DashboardInstance/style.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
margin-right: 10px;
3232
}
3333

34+
<<<<<<< HEAD
3435

36+
=======
37+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
3538
.status-icon.disconnected {
3639
background-color: red;
3740
}
@@ -85,16 +88,25 @@
8588
padding: 20px;
8689
border-radius: 8px;
8790
color: #fff;
91+
<<<<<<< HEAD
8892
margin-top: 10px;
8993
}
9094

9195

96+
=======
97+
}
98+
99+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392
92100
.connect-button {
93101
background-color: #000;
94102
color: #fff;
95103
border: none;
96104
padding: 10px 15px;
97105
border-radius: 4px;
98106
cursor: pointer;
107+
<<<<<<< HEAD
99108
margin-left: 10px;
100109
}
110+
=======
111+
}
112+
>>>>>>> 4cc9370dbfe3c7a3d271f87e6e12747f59f42392

0 commit comments

Comments
 (0)