@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/greatagents-ui",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "Shared agents UI components for Great platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -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
- // Open popup
234
- const popup = window.open(
235
- url.toString(),
236
- "oauth-popup",
237
- "width=500,height=600,scrollbars=yes,resizable=yes",
238
- );
239
- popupRef.current = popup;
240
-
241
- // Poll for popup closed without completing
242
- if (popup) {
243
- // Clear any previous poll interval
244
- if (popupPollRef.current) {
245
- clearInterval(popupPollRef.current);
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
- popupPollRef.current = setInterval(() => {
248
- if (popup.closed) {
249
- if (popupPollRef.current) {
250
- clearInterval(popupPollRef.current);
251
- popupPollRef.current = null;
252
- }
253
- // Only set error if we're still waiting (no success message received)
254
- setOauthStatus((prev) =>
255
- prev === "waiting" ? "error" : prev,
256
- );
257
- setOauthResult((prev) =>
258
- prev === null
259
- ? { success: false, error: "Janela fechada antes de concluir" }
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
- }, 500);
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, Info } from "lucide-react";
4
- import { Button, Input, Label, Tooltip, TooltipTrigger, TooltipContent } from "@greatapps/greatauth-ui/ui";
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
- <Tooltip>
107
- <TooltipTrigger asChild>
108
- <span tabIndex={!oauthConfigured ? 0 : undefined}>
109
- <Button
110
- onClick={onStartOAuth}
111
- size="lg"
112
- className="gap-2"
113
- disabled={!oauthConfigured}
114
- >
115
- {meta.icon}
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" && (