Skip to content

Commit 54ba0bf

Browse files
Merge pull request #10 from EvolutionAPI/requests-improvement
Requests improvement
2 parents 8ef9bac + f0346da commit 54ba0bf

File tree

131 files changed

+3685
-2794
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+3685
-2794
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@radix-ui/react-slot": "^1.1.0",
2424
"@radix-ui/react-switch": "^1.1.0",
2525
"@radix-ui/react-tabs": "^1.1.0",
26+
"@tanstack/react-query": "^5.52.1",
2627
"@tanstack/react-table": "^8.20.1",
2728
"axios": "^1.7.2",
2829
"class-variance-authority": "^0.7.0",

src/components/footer.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
import { useEffect, useState } from "react";
1+
import { useMemo } from "react";
22
import { useTranslation } from "react-i18next";
33

4-
import { verifyServer } from "@/services/auth.service";
4+
import { useVerifyServer } from "@/lib/queries/auth/verifyServer";
5+
import { getToken, TOKEN_ID } from "@/lib/queries/token";
56

67
import { Button } from "./ui/button";
78

89
function Footer() {
910
const { t } = useTranslation();
1011

11-
const [version, setVersion] = useState<string | null>(null);
12-
const clientName = localStorage.getItem("clientName");
12+
const clientName = getToken(TOKEN_ID.CLIENT_NAME);
13+
const url = getToken(TOKEN_ID.API_URL);
14+
const { data: serverInfo } = useVerifyServer({ url });
1315

14-
useEffect(() => {
15-
const url = localStorage.getItem("apiUrl");
16-
17-
if (!url) return;
18-
19-
verifyServer(url).then((data) => setVersion(data.version));
20-
}, []);
16+
const version = useMemo(() => serverInfo?.version, [serverInfo]);
2117

2218
const links = [
2319
{

src/components/header.tsx

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { DoorOpen } from "lucide-react";
2-
import { useEffect, useState } from "react";
2+
import { useState } from "react";
33
import { Link, useNavigate } from "react-router-dom";
44

5-
import { logout } from "@/services/auth.service";
6-
import { fetchInstance } from "@/services/instances.service";
7-
8-
import { Instance } from "@/types/evolution.types";
5+
import { useFetchInstance } from "@/lib/queries/instance/fetchInstance";
6+
import { logout } from "@/lib/queries/token";
97

8+
import { LanguageToggle } from "./language-toggle";
109
import { ModeToggle } from "./mode-toggle";
1110
import { Avatar, AvatarImage } from "./ui/avatar";
1211
import { Button } from "./ui/button";
@@ -17,7 +16,6 @@ import {
1716
DialogFooter,
1817
DialogHeader,
1918
} from "./ui/dialog";
20-
import { LanguageToggle } from "./language-toggle";
2119

2220
function Header({ instanceId }: { instanceId?: string }) {
2321
const [logoutConfirmation, setLogoutConfirmation] = useState(false);
@@ -32,22 +30,7 @@ function Header({ instanceId }: { instanceId?: string }) {
3230
navigate("/manager/");
3331
};
3432

35-
const [instance, setInstance] = useState<Instance | null>(null);
36-
37-
useEffect(() => {
38-
if (instanceId) {
39-
const fetchData = async (instanceId: string) => {
40-
try {
41-
const data = await fetchInstance(instanceId);
42-
setInstance(data[0] || null);
43-
} catch (error) {
44-
console.error("Erro ao buscar dados:", error);
45-
}
46-
};
47-
48-
fetchData(instanceId);
49-
}
50-
}, [instanceId]);
33+
const { data: instance } = useFetchInstance({ instanceId });
5134

5235
return (
5336
<header className="flex items-center justify-between px-4 py-2">

src/components/instance-token.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function InstanceToken({
2424
)}
2525
>
2626
<pre className="block truncate text-xs">
27-
{visible ? token : token.replace(/\w/g, "*")}
27+
{visible ? token : token?.replace(/\w/g, "*")}
2828
</pre>
2929
<Button
3030
variant="ghost"

src/components/providers/protected-route.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import React from "react";
22
import { Navigate } from "react-router-dom";
33

4+
import { getToken, TOKEN_ID } from "@/lib/queries/token";
5+
46
type ProtectedRouteProps = {
57
children: React.ReactNode;
68
};
79

810
const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
9-
const apiUrl = localStorage.getItem("apiUrl");
10-
const token = localStorage.getItem("token");
11-
const version = localStorage.getItem("version");
11+
const apiUrl = getToken(TOKEN_ID.API_URL);
12+
const token = getToken(TOKEN_ID.TOKEN);
13+
const version = getToken(TOKEN_ID.VERSION);
1214

1315
if (!apiUrl || !token || !version) {
1416
return <Navigate to="/manager/login" />;

src/components/providers/public-route.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import React from "react";
22
import { Navigate } from "react-router-dom";
33

4+
import { getToken, TOKEN_ID } from "@/lib/queries/token";
5+
46
type PublicRouteProps = {
57
children: React.ReactNode;
68
};
79

810
const PublicRoute = ({ children }: PublicRouteProps) => {
9-
const apiUrl = localStorage.getItem("apiUrl");
10-
const token = localStorage.getItem("token");
11-
const version = localStorage.getItem("version");
11+
const apiUrl = getToken(TOKEN_ID.API_URL);
12+
const token = getToken(TOKEN_ID.TOKEN);
13+
const version = getToken(TOKEN_ID.VERSION);
1214

1315
if (apiUrl && token && version) {
1416
return <Navigate to="/" />;

src/components/sidebar.tsx

Lines changed: 118 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -28,118 +28,121 @@ import {
2828
function Sidebar() {
2929
const { t } = useTranslation();
3030

31-
const Menus = [
32-
{
33-
id: "dashboard",
34-
title: t("sidebar.dashboard"),
35-
icon: LayoutDashboard,
36-
path: "dashboard",
37-
},
38-
{
39-
navLabel: true,
40-
title: t("sidebar.configurations"),
41-
icon: Cog,
42-
children: [
43-
{
44-
id: "settings",
45-
title: t("sidebar.settings"),
46-
path: "settings",
47-
},
48-
{
49-
id: "proxy",
50-
title: t("sidebar.proxy"),
51-
path: "proxy",
52-
},
53-
],
54-
},
55-
{
56-
title: t("sidebar.events"),
57-
icon: IterationCcw,
58-
children: [
59-
{
60-
id: "webhook",
61-
title: t("sidebar.webhook"),
62-
path: "webhook",
63-
},
64-
{
65-
id: "websocket",
66-
title: t("sidebar.websocket"),
67-
path: "websocket",
68-
},
69-
{
70-
id: "rabbitmq",
71-
title: t("sidebar.rabbitmq"),
72-
path: "rabbitmq",
73-
},
74-
{
75-
id: "sqs",
76-
title: t("sidebar.sqs"),
77-
path: "sqs",
78-
},
79-
],
80-
},
81-
{
82-
title: t("sidebar.integrations"),
83-
icon: Zap,
84-
children: [
85-
{
86-
id: "evolutionBot",
87-
title: t("sidebar.evolutionBot"),
88-
path: "evolutionBot",
89-
},
90-
{
91-
id: "chatwoot",
92-
title: t("sidebar.chatwoot"),
93-
path: "chatwoot",
94-
},
95-
{
96-
id: "typebot",
97-
title: t("sidebar.typebot"),
98-
path: "typebot",
99-
},
100-
{
101-
id: "openai",
102-
title: t("sidebar.openai"),
103-
path: "openai",
104-
},
105-
{
106-
id: "dify",
107-
title: t("sidebar.dify"),
108-
path: "dify",
109-
},
110-
{
111-
id: "flowise",
112-
title: t("sidebar.flowise"),
113-
path: "flowise",
114-
},
115-
],
116-
},
117-
{
118-
id: "documentation",
119-
title: t("sidebar.documentation"),
120-
icon: FileQuestion,
121-
link: "https://doc.evolution-api.com",
122-
divider: true,
123-
},
124-
{
125-
id: "postman",
126-
title: t("sidebar.postman"),
127-
icon: CircleHelp,
128-
link: "https://evolution-api.com/postman",
129-
},
130-
{
131-
id: "discord",
132-
title: t("sidebar.discord"),
133-
icon: MessageCircle,
134-
link: "https://evolution-api.com/discord",
135-
},
136-
{
137-
id: "support-premium",
138-
title: t("sidebar.supportPremium"),
139-
icon: LifeBuoy,
140-
link: "https://evolution-api.com/suporte-pro",
141-
},
142-
] as const;
31+
const Menus = useMemo(
32+
() => [
33+
{
34+
id: "dashboard",
35+
title: t("sidebar.dashboard"),
36+
icon: LayoutDashboard,
37+
path: "dashboard",
38+
},
39+
{
40+
navLabel: true,
41+
title: t("sidebar.configurations"),
42+
icon: Cog,
43+
children: [
44+
{
45+
id: "settings",
46+
title: t("sidebar.settings"),
47+
path: "settings",
48+
},
49+
{
50+
id: "proxy",
51+
title: t("sidebar.proxy"),
52+
path: "proxy",
53+
},
54+
],
55+
},
56+
{
57+
title: t("sidebar.events"),
58+
icon: IterationCcw,
59+
children: [
60+
{
61+
id: "webhook",
62+
title: t("sidebar.webhook"),
63+
path: "webhook",
64+
},
65+
{
66+
id: "websocket",
67+
title: t("sidebar.websocket"),
68+
path: "websocket",
69+
},
70+
{
71+
id: "rabbitmq",
72+
title: t("sidebar.rabbitmq"),
73+
path: "rabbitmq",
74+
},
75+
{
76+
id: "sqs",
77+
title: t("sidebar.sqs"),
78+
path: "sqs",
79+
},
80+
],
81+
},
82+
{
83+
title: t("sidebar.integrations"),
84+
icon: Zap,
85+
children: [
86+
{
87+
id: "evolutionBot",
88+
title: t("sidebar.evolutionBot"),
89+
path: "evolutionBot",
90+
},
91+
{
92+
id: "chatwoot",
93+
title: t("sidebar.chatwoot"),
94+
path: "chatwoot",
95+
},
96+
{
97+
id: "typebot",
98+
title: t("sidebar.typebot"),
99+
path: "typebot",
100+
},
101+
{
102+
id: "openai",
103+
title: t("sidebar.openai"),
104+
path: "openai",
105+
},
106+
{
107+
id: "dify",
108+
title: t("sidebar.dify"),
109+
path: "dify",
110+
},
111+
{
112+
id: "flowise",
113+
title: t("sidebar.flowise"),
114+
path: "flowise",
115+
},
116+
],
117+
},
118+
{
119+
id: "documentation",
120+
title: t("sidebar.documentation"),
121+
icon: FileQuestion,
122+
link: "https://doc.evolution-api.com",
123+
divider: true,
124+
},
125+
{
126+
id: "postman",
127+
title: t("sidebar.postman"),
128+
icon: CircleHelp,
129+
link: "https://evolution-api.com/postman",
130+
},
131+
{
132+
id: "discord",
133+
title: t("sidebar.discord"),
134+
icon: MessageCircle,
135+
link: "https://evolution-api.com/discord",
136+
},
137+
{
138+
id: "support-premium",
139+
title: t("sidebar.supportPremium"),
140+
icon: LifeBuoy,
141+
link: "https://evolution-api.com/suporte-pro",
142+
},
143+
],
144+
[t],
145+
);
143146

144147
const navigate = useNavigate();
145148
const { pathname } = useLocation();
@@ -165,15 +168,16 @@ function Sidebar() {
165168
"path" in child ? pathname.includes(child.path) : false,
166169
}))
167170
: undefined,
168-
isActive: "path" in menu ? pathname.includes(menu.path) : false,
171+
isActive:
172+
"path" in menu && menu.path ? pathname.includes(menu.path) : false,
169173
})).map((menu) => ({
170174
...menu,
171175
isActive:
172176
menu.isActive ||
173177
("children" in menu &&
174178
menu.children?.some((child) => child.isActive)),
175179
})),
176-
[pathname],
180+
[Menus, pathname],
177181
);
178182

179183
return (

0 commit comments

Comments
 (0)