@greatapps/greatagents-ui 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -218,49 +218,64 @@ export function IntegrationWizard({
|
|
|
218
218
|
// OAuth start
|
|
219
219
|
// -----------------------------------------------------------------------
|
|
220
220
|
|
|
221
|
-
function startOAuth() {
|
|
222
|
-
const { language = "pt-br", idWl = 1, accountId } = config;
|
|
223
|
-
|
|
224
|
-
// Build OAuth authorize URL -- the backend already handles the full flow
|
|
225
|
-
const redirectUri = `${window.location.origin}/oauth/callback`;
|
|
226
|
-
const url = new URL(
|
|
227
|
-
`${gagentsApiUrl}/v1/${language}/${idWl}/accounts/${accountId}/oauth/authorize/${integration.slug}`,
|
|
228
|
-
);
|
|
229
|
-
url.searchParams.set("redirect_uri", redirectUri);
|
|
221
|
+
async function startOAuth() {
|
|
222
|
+
const { language = "pt-br", idWl = 1, accountId, token } = config;
|
|
230
223
|
|
|
231
224
|
setOauthStatus("waiting");
|
|
232
225
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
226
|
+
try {
|
|
227
|
+
// 1. Get auth URL from backend
|
|
228
|
+
const response = await fetch(
|
|
229
|
+
`${gagentsApiUrl}/v1/${language}/${idWl}/accounts/${accountId}/oauth/authorize/${integration.slug}`,
|
|
230
|
+
{ headers: { Authorization: `Bearer ${token}` } },
|
|
231
|
+
);
|
|
232
|
+
const result = await response.json();
|
|
233
|
+
|
|
234
|
+
if (result.status !== 1 || !result.data?.auth_url) {
|
|
235
|
+
setOauthStatus("error");
|
|
236
|
+
setOauthResult({
|
|
237
|
+
success: false,
|
|
238
|
+
error: result.message || "Erro ao obter URL de autorização",
|
|
239
|
+
});
|
|
240
|
+
return;
|
|
246
241
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
: prev,
|
|
261
|
-
);
|
|
242
|
+
|
|
243
|
+
// 2. Open auth URL in popup
|
|
244
|
+
const popup = window.open(
|
|
245
|
+
result.data.auth_url,
|
|
246
|
+
"oauth-popup",
|
|
247
|
+
"width=500,height=600,scrollbars=yes,resizable=yes",
|
|
248
|
+
);
|
|
249
|
+
popupRef.current = popup;
|
|
250
|
+
|
|
251
|
+
// Poll for popup closed without completing
|
|
252
|
+
if (popup) {
|
|
253
|
+
if (popupPollRef.current) {
|
|
254
|
+
clearInterval(popupPollRef.current);
|
|
262
255
|
}
|
|
263
|
-
|
|
256
|
+
popupPollRef.current = setInterval(() => {
|
|
257
|
+
if (popup.closed) {
|
|
258
|
+
if (popupPollRef.current) {
|
|
259
|
+
clearInterval(popupPollRef.current);
|
|
260
|
+
popupPollRef.current = null;
|
|
261
|
+
}
|
|
262
|
+
setOauthStatus((prev) =>
|
|
263
|
+
prev === "waiting" ? "error" : prev,
|
|
264
|
+
);
|
|
265
|
+
setOauthResult((prev) =>
|
|
266
|
+
prev === null
|
|
267
|
+
? { success: false, error: "Janela fechada antes de concluir" }
|
|
268
|
+
: prev,
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
}, 500);
|
|
272
|
+
}
|
|
273
|
+
} catch (err) {
|
|
274
|
+
setOauthStatus("error");
|
|
275
|
+
setOauthResult({
|
|
276
|
+
success: false,
|
|
277
|
+
error: "Erro de rede ao obter URL de autorização",
|
|
278
|
+
});
|
|
264
279
|
}
|
|
265
280
|
}
|
|
266
281
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { CheckCircle2, Loader2, AlertCircle, Shield
|
|
4
|
-
import { Button, Input, Label
|
|
3
|
+
import { CheckCircle2, Loader2, AlertCircle, Shield } from "lucide-react";
|
|
4
|
+
import { Button, Input, Label } from "@greatapps/greatauth-ui/ui";
|
|
5
5
|
import type { IntegrationDefinition } from "../../../data/integrations-registry";
|
|
6
6
|
import type { WizardIntegrationMeta, OAuthStatus, OAuthResult } from "../types";
|
|
7
7
|
|
|
@@ -14,8 +14,6 @@ interface CredentialsStepProps {
|
|
|
14
14
|
onApiKeyChange: (value: string) => void;
|
|
15
15
|
onStartOAuth: () => void;
|
|
16
16
|
isReconnect?: boolean;
|
|
17
|
-
/** When true, the OAuth authorize endpoint is available on the backend. */
|
|
18
|
-
oauthConfigured?: boolean;
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
export function CredentialsStep({
|
|
@@ -27,7 +25,6 @@ export function CredentialsStep({
|
|
|
27
25
|
onApiKeyChange,
|
|
28
26
|
onStartOAuth,
|
|
29
27
|
isReconnect = false,
|
|
30
|
-
oauthConfigured = false,
|
|
31
28
|
}: CredentialsStepProps) {
|
|
32
29
|
if (integration.authType === "oauth2") {
|
|
33
30
|
return (
|
|
@@ -38,7 +35,6 @@ export function CredentialsStep({
|
|
|
38
35
|
oauthResult={oauthResult}
|
|
39
36
|
onStartOAuth={onStartOAuth}
|
|
40
37
|
isReconnect={isReconnect}
|
|
41
|
-
oauthConfigured={oauthConfigured}
|
|
42
38
|
/>
|
|
43
39
|
);
|
|
44
40
|
}
|
|
@@ -57,7 +53,6 @@ function OAuthCredentials({
|
|
|
57
53
|
oauthResult,
|
|
58
54
|
onStartOAuth,
|
|
59
55
|
isReconnect,
|
|
60
|
-
oauthConfigured,
|
|
61
56
|
}: {
|
|
62
57
|
integration: IntegrationDefinition;
|
|
63
58
|
meta: WizardIntegrationMeta;
|
|
@@ -65,7 +60,6 @@ function OAuthCredentials({
|
|
|
65
60
|
oauthResult: OAuthResult | null;
|
|
66
61
|
onStartOAuth: () => void;
|
|
67
62
|
isReconnect: boolean;
|
|
68
|
-
oauthConfigured: boolean;
|
|
69
63
|
}) {
|
|
70
64
|
const providerLabel = meta.providerLabel || integration.name;
|
|
71
65
|
|
|
@@ -80,51 +74,19 @@ function OAuthCredentials({
|
|
|
80
74
|
</p>
|
|
81
75
|
</div>
|
|
82
76
|
|
|
83
|
-
{/* OAuth not configured notice */}
|
|
84
|
-
{!oauthConfigured && oauthStatus === "idle" && (
|
|
85
|
-
<div className="flex items-start gap-3 rounded-lg border border-amber-200 bg-amber-50 p-4 dark:border-amber-900 dark:bg-amber-950/30">
|
|
86
|
-
<Info
|
|
87
|
-
aria-hidden="true"
|
|
88
|
-
className="mt-0.5 h-5 w-5 shrink-0 text-amber-600 dark:text-amber-400"
|
|
89
|
-
/>
|
|
90
|
-
<div className="space-y-1">
|
|
91
|
-
<p className="text-sm font-medium text-amber-800 dark:text-amber-200">
|
|
92
|
-
Configuração necessária
|
|
93
|
-
</p>
|
|
94
|
-
<p className="text-xs text-amber-700 dark:text-amber-300">
|
|
95
|
-
A integração com {providerLabel} requer configuração pelo
|
|
96
|
-
administrador do sistema. Entre em contato com o suporte para
|
|
97
|
-
ativar esta funcionalidade.
|
|
98
|
-
</p>
|
|
99
|
-
</div>
|
|
100
|
-
</div>
|
|
101
|
-
)}
|
|
102
|
-
|
|
103
77
|
{/* OAuth status area */}
|
|
104
78
|
<div className="flex flex-col items-center gap-4 rounded-lg border p-6">
|
|
105
79
|
{oauthStatus === "idle" && (
|
|
106
|
-
<
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
{isReconnect
|
|
117
|
-
? `Reconectar com ${providerLabel}`
|
|
118
|
-
: `Conectar com ${providerLabel}`}
|
|
119
|
-
</Button>
|
|
120
|
-
</span>
|
|
121
|
-
</TooltipTrigger>
|
|
122
|
-
{!oauthConfigured && (
|
|
123
|
-
<TooltipContent>
|
|
124
|
-
Integração OAuth ainda não configurada no servidor
|
|
125
|
-
</TooltipContent>
|
|
126
|
-
)}
|
|
127
|
-
</Tooltip>
|
|
80
|
+
<Button
|
|
81
|
+
onClick={onStartOAuth}
|
|
82
|
+
size="lg"
|
|
83
|
+
className="gap-2"
|
|
84
|
+
>
|
|
85
|
+
{meta.icon}
|
|
86
|
+
{isReconnect
|
|
87
|
+
? `Reconectar com ${providerLabel}`
|
|
88
|
+
: `Conectar com ${providerLabel}`}
|
|
89
|
+
</Button>
|
|
128
90
|
)}
|
|
129
91
|
|
|
130
92
|
{oauthStatus === "waiting" && (
|