Skip to content

Commit 78c3484

Browse files
committed
Add n8n and Evoai integration components, including API queries and UI forms. Update sidebar to include new sections for n8n and Evoai. Enhance localization support for new features.
1 parent 9bde4fb commit 78c3484

31 files changed

+4076
-0
lines changed

src/components/sidebar.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ function Sidebar() {
113113
title: t("sidebar.flowise"),
114114
path: "flowise",
115115
},
116+
{
117+
id: "n8n",
118+
title: t("sidebar.n8n"),
119+
path: "n8n",
120+
},
121+
{
122+
id: "evoai",
123+
title: t("sidebar.evoai"),
124+
path: "evoai",
125+
},
116126
],
117127
},
118128
{
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
3+
import { api } from "../api";
4+
import { UseQueryParams } from "../types";
5+
import { FetchEvoaiRsponse } from "./types";
6+
7+
interface IParams {
8+
instanceName: string;
9+
token?: string;
10+
}
11+
12+
const queryKey = (params: Partial<IParams>) => [
13+
"evoai",
14+
"fetchEvoai",
15+
JSON.stringify(params),
16+
];
17+
18+
export const fetchEvoai = async ({ instanceName, token }: IParams) => {
19+
const response = await api.get(`/evoai/find/${instanceName}`, {
20+
headers: { apikey: token },
21+
});
22+
return response.data;
23+
};
24+
25+
export const useFetchEvoai = (
26+
props: UseQueryParams<FetchEvoaiRsponse> & Partial<IParams>,
27+
) => {
28+
const { instanceName, token, ...rest } = props;
29+
return useQuery<FetchEvoaiRsponse>({
30+
...rest,
31+
queryKey: queryKey({ instanceName, token }),
32+
queryFn: () => fetchEvoai({ instanceName: instanceName!, token: token! }),
33+
enabled: !!instanceName && (props.enabled ?? true),
34+
});
35+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
3+
import { api } from "../api";
4+
import { UseQueryParams } from "../types";
5+
import { FetchSessionsEvoaiResponse } from "./types";
6+
7+
interface IParams {
8+
evoaiId: string;
9+
instanceName: string;
10+
}
11+
12+
const queryKey = (params: Partial<IParams>) => [
13+
"evoai",
14+
"fetchSessions",
15+
JSON.stringify(params),
16+
];
17+
18+
export const fetchSessionsEvoai = async ({ evoaiId, instanceName }: IParams) => {
19+
const response = await api.get(
20+
`/evoai/fetchSessions/${evoaiId}/${instanceName}`,
21+
);
22+
return response.data;
23+
};
24+
25+
export const useFetchSessionsEvoai = (
26+
props: UseQueryParams<FetchSessionsEvoaiResponse> & Partial<IParams>,
27+
) => {
28+
const { evoaiId, instanceName, ...rest } = props;
29+
return useQuery<FetchSessionsEvoaiResponse>({
30+
...rest,
31+
queryKey: queryKey({ evoaiId, instanceName }),
32+
queryFn: () =>
33+
fetchSessionsEvoai({ evoaiId: evoaiId!, instanceName: instanceName! }),
34+
enabled: !!instanceName && !!evoaiId && (props.enabled ?? true),
35+
staleTime: 1000 * 10, // 10 seconds
36+
});
37+
};

src/lib/queries/evoai/getEvoai.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
3+
import { api } from "../api";
4+
import { UseQueryParams } from "../types";
5+
import { GetEvoaiResponse } from "./types";
6+
7+
interface IParams {
8+
evoaiId: string;
9+
instanceName: string;
10+
}
11+
12+
const queryKey = (params: Partial<IParams>) => [
13+
"evoai",
14+
"getEvoai",
15+
JSON.stringify(params),
16+
];
17+
18+
export const getEvoai = async ({ evoaiId, instanceName }: IParams) => {
19+
const response = await api.get(`/evoai/fetch/${evoaiId}/${instanceName}`);
20+
return response.data;
21+
};
22+
23+
export const useGetEvoai = (
24+
props: UseQueryParams<GetEvoaiResponse> & Partial<IParams>,
25+
) => {
26+
const { evoaiId, instanceName, ...rest } = props;
27+
return useQuery<GetEvoaiResponse>({
28+
...rest,
29+
queryKey: queryKey({ evoaiId, instanceName }),
30+
queryFn: () => getEvoai({ evoaiId: evoaiId!, instanceName: instanceName! }),
31+
enabled: !!instanceName && !!evoaiId && (props.enabled ?? true),
32+
});
33+
};
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { Evoai, EvoaiSettings } from "@/types/evolution.types";
2+
3+
import { api } from "../api";
4+
import { useManageMutation } from "../mutateQuery";
5+
6+
interface CreateEvoaiParams {
7+
instanceName: string;
8+
token: string;
9+
data: Evoai;
10+
}
11+
12+
const createEvoai = async ({ instanceName, token, data }: CreateEvoaiParams) => {
13+
const response = await api.post(`/evoai/create/${instanceName}`, data, {
14+
headers: { apikey: token },
15+
});
16+
return response.data;
17+
};
18+
19+
interface UpdateEvoaiParams {
20+
instanceName: string;
21+
evoaiId: string;
22+
data: Evoai;
23+
}
24+
const updateEvoai = async ({ instanceName, evoaiId, data }: UpdateEvoaiParams) => {
25+
const response = await api.put(
26+
`/evoai/update/${evoaiId}/${instanceName}`,
27+
data,
28+
);
29+
return response.data;
30+
};
31+
32+
interface DeleteEvoaiParams {
33+
instanceName: string;
34+
evoaiId: string;
35+
}
36+
const deleteEvoai = async ({ instanceName, evoaiId }: DeleteEvoaiParams) => {
37+
const response = await api.delete(`/evoai/delete/${evoaiId}/${instanceName}`);
38+
return response.data;
39+
};
40+
41+
interface SetDefaultSettingsEvoaiParams {
42+
instanceName: string;
43+
token: string;
44+
data: EvoaiSettings;
45+
}
46+
const setDefaultSettingsEvoai = async ({
47+
instanceName,
48+
token,
49+
data,
50+
}: SetDefaultSettingsEvoaiParams) => {
51+
const response = await api.post(`/evoai/settings/${instanceName}`, data, {
52+
headers: { apikey: token },
53+
});
54+
return response.data;
55+
};
56+
57+
interface ChangeStatusEvoaiParams {
58+
instanceName: string;
59+
token: string;
60+
remoteJid: string;
61+
status: string;
62+
}
63+
const changeStatusEvoai = async ({
64+
instanceName,
65+
token,
66+
remoteJid,
67+
status,
68+
}: ChangeStatusEvoaiParams) => {
69+
const response = await api.post(
70+
`/evoai/changeStatus/${instanceName}`,
71+
{ remoteJid, status },
72+
{ headers: { apikey: token } },
73+
);
74+
return response.data;
75+
};
76+
77+
export function useManageEvoai() {
78+
const setDefaultSettingsEvoaiMutation = useManageMutation(
79+
setDefaultSettingsEvoai,
80+
{ invalidateKeys: [["evoai", "fetchDefaultSettings"]] },
81+
);
82+
const changeStatusEvoaiMutation = useManageMutation(changeStatusEvoai, {
83+
invalidateKeys: [
84+
["evoai", "getEvoai"],
85+
["evoai", "fetchSessions"],
86+
],
87+
});
88+
const deleteEvoaiMutation = useManageMutation(deleteEvoai, {
89+
invalidateKeys: [
90+
["evoai", "getEvoai"],
91+
["evoai", "fetchEvoai"],
92+
["evoai", "fetchSessions"],
93+
],
94+
});
95+
const updateEvoaiMutation = useManageMutation(updateEvoai, {
96+
invalidateKeys: [
97+
["evoai", "getEvoai"],
98+
["evoai", "fetchEvoai"],
99+
["evoai", "fetchSessions"],
100+
],
101+
});
102+
const createEvoaiMutation = useManageMutation(createEvoai, {
103+
invalidateKeys: [["evoai", "fetchEvoai"]],
104+
});
105+
106+
return {
107+
setDefaultSettingsEvoai: setDefaultSettingsEvoaiMutation,
108+
changeStatusEvoai: changeStatusEvoaiMutation,
109+
deleteEvoai: deleteEvoaiMutation,
110+
updateEvoai: updateEvoaiMutation,
111+
createEvoai: createEvoaiMutation,
112+
};
113+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
3+
import { api } from "../api";
4+
import { UseQueryParams } from "../types";
5+
import { FetchEvoaiSettingsResponse } from "./types";
6+
7+
interface IParams {
8+
instanceName: string | null;
9+
token: string;
10+
}
11+
12+
const queryKey = (params: Partial<IParams>) => [
13+
"evoai",
14+
"fetchDefaultSettings",
15+
JSON.stringify(params),
16+
];
17+
18+
export const fetchDefaultSettings = async ({
19+
instanceName,
20+
token,
21+
}: IParams) => {
22+
const response = await api.get(`/evoai/fetchSettings/${instanceName}`, {
23+
headers: { apikey: token },
24+
});
25+
return response.data;
26+
};
27+
28+
export const useFetchDefaultSettings = (
29+
props: UseQueryParams<FetchEvoaiSettingsResponse> & Partial<IParams>,
30+
) => {
31+
const { instanceName, token, ...rest } = props;
32+
return useQuery<FetchEvoaiSettingsResponse>({
33+
...rest,
34+
queryKey: queryKey({ instanceName, token }),
35+
queryFn: () =>
36+
fetchDefaultSettings({ instanceName: instanceName!, token: token! }),
37+
enabled: !!instanceName,
38+
});
39+
};

src/lib/queries/evoai/types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {
2+
IntegrationSession,
3+
Evoai,
4+
EvoaiSettings,
5+
} from "@/types/evolution.types";
6+
7+
export type FetchEvoaiRsponse = Evoai[];
8+
9+
export type GetEvoaiResponse = Evoai;
10+
11+
export type FetchEvoaiSettingsResponse = EvoaiSettings;
12+
13+
export type FetchSessionsEvoaiResponse = IntegrationSession[];

src/lib/queries/n8n/fetchN8n.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
3+
import { api } from "../api";
4+
import { UseQueryParams } from "../types";
5+
import { FetchN8nRsponse } from "./types";
6+
7+
interface IParams {
8+
instanceName: string;
9+
token?: string;
10+
}
11+
12+
const queryKey = (params: Partial<IParams>) => [
13+
"n8n",
14+
"fetchN8n",
15+
JSON.stringify(params),
16+
];
17+
18+
export const fetchN8n = async ({ instanceName, token }: IParams) => {
19+
const response = await api.get(`/n8n/find/${instanceName}`, {
20+
headers: { apikey: token },
21+
});
22+
return response.data;
23+
};
24+
25+
export const useFetchN8n = (
26+
props: UseQueryParams<FetchN8nRsponse> & Partial<IParams>,
27+
) => {
28+
const { instanceName, token, ...rest } = props;
29+
return useQuery<FetchN8nRsponse>({
30+
...rest,
31+
queryKey: queryKey({ instanceName, token }),
32+
queryFn: () => fetchN8n({ instanceName: instanceName!, token: token! }),
33+
enabled: !!instanceName && (props.enabled ?? true),
34+
});
35+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
3+
import { api } from "../api";
4+
import { UseQueryParams } from "../types";
5+
import { FetchSessionsN8nResponse } from "./types";
6+
7+
interface IParams {
8+
n8nId: string;
9+
instanceName: string;
10+
}
11+
12+
const queryKey = (params: Partial<IParams>) => [
13+
"n8n",
14+
"fetchSessions",
15+
JSON.stringify(params),
16+
];
17+
18+
export const fetchSessionsN8n = async ({ n8nId, instanceName }: IParams) => {
19+
const response = await api.get(
20+
`/n8n/fetchSessions/${n8nId}/${instanceName}`,
21+
);
22+
return response.data;
23+
};
24+
25+
export const useFetchSessionsN8n = (
26+
props: UseQueryParams<FetchSessionsN8nResponse> & Partial<IParams>,
27+
) => {
28+
const { n8nId, instanceName, ...rest } = props;
29+
return useQuery<FetchSessionsN8nResponse>({
30+
...rest,
31+
queryKey: queryKey({ n8nId, instanceName }),
32+
queryFn: () =>
33+
fetchSessionsN8n({ n8nId: n8nId!, instanceName: instanceName! }),
34+
enabled: !!instanceName && !!n8nId && (props.enabled ?? true),
35+
staleTime: 1000 * 10, // 10 seconds
36+
});
37+
};

0 commit comments

Comments
 (0)