@oondemand/oon-core-front 0.3.4 → 0.3.5

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/dist/index.js CHANGED
@@ -2306,6 +2306,12 @@ function LoginPage({ app }) {
2306
2306
  import { useEffect as useEffect5, useState as useState9 } from "react";
2307
2307
  import { Box as Box12, Button as Button9, Heading as Heading8, Input as Input5, Text as Text13, VStack as VStack3 } from "@chakra-ui/react";
2308
2308
  import { Fragment as Fragment2, jsx as jsx20, jsxs as jsxs13 } from "react/jsx-runtime";
2309
+ function encodeBasicCredentials2(email, password) {
2310
+ const bytes = new TextEncoder().encode(`${email}:${password}`);
2311
+ let binary = "";
2312
+ for (const byte of bytes) binary += String.fromCharCode(byte);
2313
+ return window.btoa(binary);
2314
+ }
2309
2315
  function ActivationPage() {
2310
2316
  const { http } = useOonApi();
2311
2317
  const activation = useActivation();
@@ -2317,6 +2323,11 @@ function ActivationPage() {
2317
2323
  const [app, setApp] = useState9({});
2318
2324
  const [rootEmail, setRootEmail] = useState9("");
2319
2325
  const [rootPassword, setRootPassword] = useState9("");
2326
+ const [devName, setDevName] = useState9("");
2327
+ const [devEmail, setDevEmail] = useState9("");
2328
+ const [devPassword, setDevPassword] = useState9("");
2329
+ const [showCodeFlow, setShowCodeFlow] = useState9(false);
2330
+ const [devResult, setDevResult] = useState9(null);
2320
2331
  const [error, setError] = useState9(null);
2321
2332
  const [submitting, setSubmitting] = useState9(false);
2322
2333
  useEffect5(() => {
@@ -2353,6 +2364,43 @@ function ActivationPage() {
2353
2364
  setSubmitting(false);
2354
2365
  }
2355
2366
  }
2367
+ async function activateDevLocal() {
2368
+ setSubmitting(true);
2369
+ setError(null);
2370
+ try {
2371
+ const response = await http.post(
2372
+ "/ativacao/ativar-dev-local",
2373
+ {
2374
+ nomeUsuario: devName.trim() || void 0,
2375
+ nomeCentral: global.nomeInstancia || config?.defaults?.nomeInstancia,
2376
+ appName: config?.defaults?.nomeInstancia || config?.technical?.appCode,
2377
+ urlPublica: global.urlPublica
2378
+ },
2379
+ {
2380
+ headers: {
2381
+ Authorization: `Basic ${encodeBasicCredentials2(
2382
+ devEmail.trim().toLowerCase(),
2383
+ devPassword
2384
+ )}`
2385
+ }
2386
+ }
2387
+ );
2388
+ setDevPassword("");
2389
+ setDevResult(response.data);
2390
+ setStep(6);
2391
+ const token = response.data.token;
2392
+ window.setTimeout(() => {
2393
+ window.location.replace(token ? `/?code=${encodeURIComponent(token)}` : "/login");
2394
+ }, 900);
2395
+ } catch (caught) {
2396
+ setDevPassword("");
2397
+ setError(
2398
+ caught.message || "N\xE3o foi poss\xEDvel ativar a Central em desenvolvimento."
2399
+ );
2400
+ } finally {
2401
+ setSubmitting(false);
2402
+ }
2403
+ }
2356
2404
  async function validateCode() {
2357
2405
  setSubmitting(true);
2358
2406
  setError(null);
@@ -2411,7 +2459,71 @@ function ActivationPage() {
2411
2459
  field.helpText ? /* @__PURE__ */ jsx20(Text13, { fontSize: "sm", color: "gray.500", children: field.helpText }) : null
2412
2460
  ] }, field.name);
2413
2461
  }
2462
+ function renderDevLocalActivation() {
2463
+ return /* @__PURE__ */ jsxs13(Fragment2, { children: [
2464
+ /* @__PURE__ */ jsx20(Text13, { color: "gray.700", children: "Entre com seu e-mail e senha para ativar esta Central em ambiente de desenvolvimento. Se o e-mail ainda n\xE3o existir na Central de Ativa\xE7\xF5es, o usu\xE1rio ser\xE1 criado automaticamente com perfil de desenvolvedor." }),
2465
+ /* @__PURE__ */ jsxs13(Box12, { w: "100%", children: [
2466
+ /* @__PURE__ */ jsx20(Text13, { fontWeight: "medium", children: "Nome do usu\xE1rio" }),
2467
+ /* @__PURE__ */ jsx20(
2468
+ Input5,
2469
+ {
2470
+ value: devName,
2471
+ onChange: (event) => setDevName(event.target.value),
2472
+ placeholder: "Seu nome",
2473
+ autoComplete: "name"
2474
+ }
2475
+ )
2476
+ ] }),
2477
+ /* @__PURE__ */ jsxs13(Box12, { w: "100%", children: [
2478
+ /* @__PURE__ */ jsx20(Text13, { fontWeight: "medium", children: "E-mail *" }),
2479
+ /* @__PURE__ */ jsx20(
2480
+ Input5,
2481
+ {
2482
+ type: "email",
2483
+ value: devEmail,
2484
+ onChange: (event) => setDevEmail(event.target.value),
2485
+ placeholder: "dev@empresa.com.br",
2486
+ autoComplete: "email"
2487
+ }
2488
+ )
2489
+ ] }),
2490
+ /* @__PURE__ */ jsxs13(Box12, { w: "100%", children: [
2491
+ /* @__PURE__ */ jsx20(Text13, { fontWeight: "medium", children: "Senha *" }),
2492
+ /* @__PURE__ */ jsx20(
2493
+ Input5,
2494
+ {
2495
+ type: "password",
2496
+ value: devPassword,
2497
+ onChange: (event) => setDevPassword(event.target.value),
2498
+ placeholder: "M\xEDnimo de 8 caracteres",
2499
+ minLength: 8,
2500
+ autoComplete: "current-password"
2501
+ }
2502
+ )
2503
+ ] }),
2504
+ /* @__PURE__ */ jsx20(
2505
+ Button9,
2506
+ {
2507
+ colorPalette: "blue",
2508
+ onClick: activateDevLocal,
2509
+ loading: submitting,
2510
+ disabled: submitting || !devEmail.trim() || devPassword.length < 8 || !activation.details?.podeAtivar,
2511
+ children: "Ativar ambiente de desenvolvimento"
2512
+ }
2513
+ ),
2514
+ /* @__PURE__ */ jsx20(
2515
+ Button9,
2516
+ {
2517
+ variant: "outline",
2518
+ onClick: () => setShowCodeFlow(true),
2519
+ disabled: submitting,
2520
+ children: "Usar c\xF3digo de ativa\xE7\xE3o manual"
2521
+ }
2522
+ )
2523
+ ] });
2524
+ }
2414
2525
  const rootMode = config?.mode === "root-bootstrap" || activation.details?.role === "root";
2526
+ const isDevelopmentMember = !rootMode && config?.technical?.ambiente === "desenvolvimento";
2415
2527
  if (activation.status === "loading" || !config) {
2416
2528
  return /* @__PURE__ */ jsx20(Box12, { minH: "100vh", bg: "gray.50", p: 8, children: /* @__PURE__ */ jsxs13(
2417
2529
  VStack3,
@@ -2518,10 +2630,11 @@ function ActivationPage() {
2518
2630
  config.technical.ambiente,
2519
2631
  " \xB7 Central:",
2520
2632
  " ",
2521
- config.technical.centralAtivacaoHost
2633
+ config.technical.centralAtivacaoUrl || config.technical.centralAtivacaoHost
2522
2634
  ] }),
2523
2635
  error ? /* @__PURE__ */ jsx20(Text13, { color: "red.600", children: error }) : null,
2524
- step === 1 && /* @__PURE__ */ jsxs13(Fragment2, { children: [
2636
+ step === 1 && isDevelopmentMember && !showCodeFlow ? renderDevLocalActivation() : null,
2637
+ step === 1 && (!isDevelopmentMember || showCodeFlow) && /* @__PURE__ */ jsxs13(Fragment2, { children: [
2525
2638
  /* @__PURE__ */ jsx20(Text13, { children: "Informe o c\xF3digo de ativa\xE7\xE3o para validar tenant, aplicativo e licen\xE7a antes de consumir o c\xF3digo." }),
2526
2639
  /* @__PURE__ */ jsx20(
2527
2640
  Input5,
@@ -2540,7 +2653,16 @@ function ActivationPage() {
2540
2653
  disabled: !code || submitting,
2541
2654
  children: "Validar c\xF3digo"
2542
2655
  }
2543
- )
2656
+ ),
2657
+ isDevelopmentMember ? /* @__PURE__ */ jsx20(
2658
+ Button9,
2659
+ {
2660
+ variant: "outline",
2661
+ onClick: () => setShowCodeFlow(false),
2662
+ disabled: submitting,
2663
+ children: "Voltar para ativa\xE7\xE3o com usu\xE1rio"
2664
+ }
2665
+ ) : null
2544
2666
  ] }),
2545
2667
  step === 2 && /* @__PURE__ */ jsxs13(Fragment2, { children: [
2546
2668
  /* @__PURE__ */ jsx20(Heading8, { size: "md", children: "Confirma\xE7\xE3o" }),
@@ -2572,7 +2694,12 @@ function ActivationPage() {
2572
2694
  ] }),
2573
2695
  step === 6 && /* @__PURE__ */ jsxs13(Fragment2, { children: [
2574
2696
  /* @__PURE__ */ jsx20(Heading8, { size: "md", children: "Ativa\xE7\xE3o conclu\xEDda" }),
2575
- /* @__PURE__ */ jsx20(Text13, { children: "Redirecionando para o login..." })
2697
+ devResult?.appCode ? /* @__PURE__ */ jsxs13(Text13, { children: [
2698
+ "C\xF3digo do app: ",
2699
+ devResult.appCode,
2700
+ ". Redirecionando para a Central em desenvolvimento..."
2701
+ ] }) : /* @__PURE__ */ jsx20(Text13, { children: "Redirecionando para o login..." }),
2702
+ devResult?.instrucoes?.env ? /* @__PURE__ */ jsx20(Text13, { fontSize: "sm", color: "gray.500", children: devResult.instrucoes.env }) : null
2576
2703
  ] })
2577
2704
  ]
2578
2705
  }