Skip to content

Commit 5034015

Browse files
Merge pull request #11 from EvolutionAPI/fixes
Fixes
2 parents 54ba0bf + 1b8bd11 commit 5034015

File tree

9 files changed

+86
-32
lines changed

9 files changed

+86
-32
lines changed

src/components/footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { Button } from "./ui/button";
99
function Footer() {
1010
const { t } = useTranslation();
1111

12-
const clientName = getToken(TOKEN_ID.CLIENT_NAME);
1312
const url = getToken(TOKEN_ID.API_URL);
1413
const { data: serverInfo } = useVerifyServer({ url });
1514

15+
const clientName = useMemo(() => serverInfo?.clientName, [serverInfo]);
1616
const version = useMemo(() => serverInfo?.version, [serverInfo]);
1717

1818
const links = [

src/lib/queries/webhook/manageWebhook.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface IParams {
99
data: Webhook;
1010
}
1111

12-
const createWebhook = async ({ instanceName, token, ...data }: IParams) => {
12+
const createWebhook = async ({ instanceName, token, data }: IParams) => {
1313
const response = await api.post(
1414
`/webhook/set/${instanceName}`,
1515
{ webhook: data },

src/lib/queries/webhook/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { Webhook } from "@/types/evolution.types";
22

33
/* eslint-disable @typescript-eslint/no-explicit-any */
4-
export type FetchWebhookResponse = Webhook;
4+
export type FetchWebhookResponse = Omit<Webhook, "base64" | "byEvents"> & {
5+
webhookBase64: boolean;
6+
webhookByEvents: boolean;
7+
};

src/pages/instance/Chatwoot/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ function Chatwoot() {
8282
}
8383
});
8484

85-
const onSubmit = async () => {
85+
const onSubmit = async (data: FormSchema) => {
8686
if (!instance) return;
8787

88-
const data = form.getValues();
89-
9088
setLoading(true);
9189
const chatwootData: ChatwootType = {
9290
enabled: data.enabled,
@@ -136,7 +134,10 @@ function Chatwoot() {
136134
return (
137135
<>
138136
<Form {...form}>
139-
<form className="w-full space-y-6">
137+
<form
138+
onSubmit={form.handleSubmit(onSubmit)}
139+
className="w-full space-y-6"
140+
>
140141
<div>
141142
<h3 className="mb-1 text-lg font-medium">{t("chatwoot.title")}</h3>
142143
<Separator className="my-4" />
@@ -231,9 +232,7 @@ function Chatwoot() {
231232
</div>
232233
</div>
233234
<div className="mx-4 flex justify-end">
234-
<Button type="submit" onClick={onSubmit}>
235-
{t("chatwoot.button.save")}
236-
</Button>
235+
<Button type="submit">{t("chatwoot.button.save")}</Button>
237236
</div>
238237
</form>
239238
</Form>

src/pages/instance/Proxy/index.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { zodResolver } from "@hookform/resolvers/zod";
33
import { Separator } from "@radix-ui/react-dropdown-menu";
4-
import { useState } from "react";
4+
import { useEffect, useState } from "react";
55
import { useForm } from "react-hook-form";
66
import { useTranslation } from "react-i18next";
77
import { toast } from "react-toastify";
@@ -42,15 +42,28 @@ function Proxy() {
4242
const form = useForm<FormSchemaType>({
4343
resolver: zodResolver(formSchema),
4444
defaultValues: {
45-
enabled: proxy?.enabled ?? false,
46-
host: proxy?.host ?? "",
47-
port: proxy?.port ?? "",
48-
protocol: proxy?.protocol ?? "http",
49-
username: proxy?.username ?? "",
50-
password: proxy?.password ?? "",
45+
enabled: false,
46+
host: "",
47+
port: "",
48+
protocol: "http",
49+
username: "",
50+
password: "",
5151
},
5252
});
5353

54+
useEffect(() => {
55+
if (proxy) {
56+
form.reset({
57+
enabled: proxy.enabled,
58+
host: proxy.host,
59+
port: proxy.port,
60+
protocol: proxy.protocol,
61+
username: proxy.username,
62+
password: proxy.password,
63+
});
64+
}
65+
}, [proxy]); // eslint-disable-line react-hooks/exhaustive-deps
66+
5467
const onSubmit = async (data: FormSchemaType) => {
5568
if (!instance) return;
5669

src/pages/instance/Rabbitmq/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { zodResolver } from "@hookform/resolvers/zod";
33
import { Separator } from "@radix-ui/react-dropdown-menu";
4-
import { useState } from "react";
4+
import { useEffect, useState } from "react";
55
import { useForm } from "react-hook-form";
66
import { useTranslation } from "react-i18next";
77
import { toast } from "react-toastify";
@@ -47,11 +47,20 @@ function Rabbitmq() {
4747
const form = useForm<FormSchemaType>({
4848
resolver: zodResolver(formSchema),
4949
defaultValues: {
50-
enabled: rabbitmq?.enabled ?? false,
51-
events: rabbitmq?.events ?? [],
50+
enabled: false,
51+
events: [],
5252
},
5353
});
5454

55+
useEffect(() => {
56+
if (rabbitmq) {
57+
form.reset({
58+
enabled: rabbitmq.enabled,
59+
events: rabbitmq.events,
60+
});
61+
}
62+
}, [rabbitmq]); // eslint-disable-line react-hooks/exhaustive-deps
63+
5564
const onSubmit = async (data: FormSchemaType) => {
5665
if (!instance) return;
5766

src/pages/instance/Sqs/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { zodResolver } from "@hookform/resolvers/zod";
33
import { Separator } from "@radix-ui/react-dropdown-menu";
4-
import { useState } from "react";
4+
import { useEffect, useState } from "react";
55
import { useForm } from "react-hook-form";
66
import { useTranslation } from "react-i18next";
77
import { toast } from "react-toastify";
@@ -47,11 +47,20 @@ function Sqs() {
4747
const form = useForm<FormSchemaType>({
4848
resolver: zodResolver(FormSchema),
4949
defaultValues: {
50-
enabled: sqs?.enabled ?? false,
51-
events: sqs?.events ?? [],
50+
enabled: false,
51+
events: [],
5252
},
5353
});
5454

55+
useEffect(() => {
56+
if (sqs) {
57+
form.reset({
58+
enabled: sqs.enabled,
59+
events: sqs.events,
60+
});
61+
}
62+
}, [sqs]); // eslint-disable-line react-hooks/exhaustive-deps
63+
5564
const onSubmit = async (data: FormSchemaType) => {
5665
if (!instance) return;
5766
setLoading(true);

src/pages/instance/Webhook/index.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { zodResolver } from "@hookform/resolvers/zod";
33
import { Separator } from "@radix-ui/react-dropdown-menu";
4-
import { useState } from "react";
4+
import { useEffect, useState } from "react";
55
import { useForm } from "react-hook-form";
66
import { useTranslation } from "react-i18next";
77
import { toast } from "react-toastify";
@@ -52,14 +52,26 @@ function Webhook() {
5252
const form = useForm<FormSchemaType>({
5353
resolver: zodResolver(FormSchema),
5454
defaultValues: {
55-
enabled: webhook?.enabled ?? false,
56-
url: webhook?.url ?? "",
57-
events: webhook?.events ?? [],
58-
base64: webhook?.base64 ?? false,
59-
byEvents: webhook?.byEvents ?? false,
55+
enabled: false,
56+
url: "",
57+
events: [],
58+
base64: false,
59+
byEvents: false,
6060
},
6161
});
6262

63+
useEffect(() => {
64+
if (webhook) {
65+
form.reset({
66+
enabled: webhook.enabled,
67+
url: webhook.url,
68+
events: webhook.events,
69+
base64: webhook.webhookBase64,
70+
byEvents: webhook.webhookByEvents,
71+
});
72+
}
73+
}, [webhook]); // eslint-disable-line react-hooks/exhaustive-deps
74+
6375
const onSubmit = async (data: FormSchemaType) => {
6476
if (!instance) return;
6577
setLoading(true);

src/pages/instance/Websocket/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { zodResolver } from "@hookform/resolvers/zod";
33
import { Separator } from "@radix-ui/react-dropdown-menu";
4-
import { useState } from "react";
4+
import { useEffect, useState } from "react";
55
import { useForm } from "react-hook-form";
66
import { useTranslation } from "react-i18next";
77
import { toast } from "react-toastify";
@@ -47,11 +47,20 @@ function Websocket() {
4747
const form = useForm<FormSchemaType>({
4848
resolver: zodResolver(FormSchema),
4949
defaultValues: {
50-
enabled: websocket?.enabled ?? false,
51-
events: websocket?.events ?? [],
50+
enabled: false,
51+
events: [],
5252
},
5353
});
5454

55+
useEffect(() => {
56+
if (websocket) {
57+
form.reset({
58+
enabled: websocket.enabled,
59+
events: websocket.events,
60+
});
61+
}
62+
}, [websocket]); // eslint-disable-line react-hooks/exhaustive-deps
63+
5564
const onSubmit = async (data: FormSchemaType) => {
5665
if (!instance) return;
5766

0 commit comments

Comments
 (0)