@replicated/portal-components 0.0.28 → 0.0.29

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.
@@ -15,11 +15,12 @@ interface VerifyActionResult {
15
15
  message?: string;
16
16
  isExpired?: boolean;
17
17
  }
18
- type VerifyAction = (code: string) => Promise<VerifyActionResult>;
18
+ type VerifyAction = (code: string, isPreview?: boolean) => Promise<VerifyActionResult>;
19
19
  interface UseVerifyMagicLinkOptions {
20
20
  verifyAction: VerifyAction;
21
21
  onSuccess?: () => void;
22
22
  redirectUrl?: string;
23
+ isPreview?: boolean;
23
24
  }
24
25
  /**
25
26
  * Shared hook for magic link and trial signup verification.
@@ -29,6 +30,6 @@ interface UseVerifyMagicLinkOptions {
29
30
  * Note: The verifyAction should be selected based on the verification type
30
31
  * (regular magic link vs trial signup) before calling this hook.
31
32
  */
32
- declare function useVerifyMagicLink({ verifyAction, onSuccess, redirectUrl }: UseVerifyMagicLinkOptions): VerifyState;
33
+ declare function useVerifyMagicLink({ verifyAction, onSuccess, redirectUrl, isPreview }: UseVerifyMagicLinkOptions): VerifyState;
33
34
 
34
35
  export { type UseVerifyMagicLinkOptions, type VerifyAction, type VerifyActionResult, type VerifyState, useVerifyMagicLink };
@@ -15,11 +15,12 @@ interface VerifyActionResult {
15
15
  message?: string;
16
16
  isExpired?: boolean;
17
17
  }
18
- type VerifyAction = (code: string) => Promise<VerifyActionResult>;
18
+ type VerifyAction = (code: string, isPreview?: boolean) => Promise<VerifyActionResult>;
19
19
  interface UseVerifyMagicLinkOptions {
20
20
  verifyAction: VerifyAction;
21
21
  onSuccess?: () => void;
22
22
  redirectUrl?: string;
23
+ isPreview?: boolean;
23
24
  }
24
25
  /**
25
26
  * Shared hook for magic link and trial signup verification.
@@ -29,6 +30,6 @@ interface UseVerifyMagicLinkOptions {
29
30
  * Note: The verifyAction should be selected based on the verification type
30
31
  * (regular magic link vs trial signup) before calling this hook.
31
32
  */
32
- declare function useVerifyMagicLink({ verifyAction, onSuccess, redirectUrl }: UseVerifyMagicLinkOptions): VerifyState;
33
+ declare function useVerifyMagicLink({ verifyAction, onSuccess, redirectUrl, isPreview }: UseVerifyMagicLinkOptions): VerifyState;
33
34
 
34
35
  export { type UseVerifyMagicLinkOptions, type VerifyAction, type VerifyActionResult, type VerifyState, useVerifyMagicLink };
@@ -12,7 +12,8 @@ var navigation = require('next/navigation');
12
12
  function useVerifyMagicLink({
13
13
  verifyAction,
14
14
  onSuccess,
15
- redirectUrl = "/"
15
+ redirectUrl = "/",
16
+ isPreview
16
17
  }) {
17
18
  const router = navigation.useRouter();
18
19
  const [state, setState] = react.useState({ status: "verifying" });
@@ -37,7 +38,7 @@ function useVerifyMagicLink({
37
38
  }
38
39
  if (verifyingRef.current) return;
39
40
  verifyingRef.current = true;
40
- verifyAction(code).then((result) => {
41
+ verifyAction(code, isPreview).then((result) => {
41
42
  if (result.success) {
42
43
  setState({
43
44
  status: "success",
@@ -67,7 +68,7 @@ function useVerifyMagicLink({
67
68
  message: "An unexpected error occurred. Please try again."
68
69
  });
69
70
  });
70
- }, [verifyAction, router, redirectUrl, onSuccess]);
71
+ }, [verifyAction, router, redirectUrl, onSuccess, isPreview]);
71
72
  return state;
72
73
  }
73
74
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/use-verify-magic-link.ts"],"names":["useRouter","useState","useRef","useEffect"],"mappings":";;;;;;;;;;AAiCO,SAAS,kBAAA,CAAmB;AAAA,EACjC,YAAA;AAAA,EACA,SAAA;AAAA,EACA,WAAA,GAAc;AAChB,CAAA,EAA8B;AAC5B,EAAA,MAAM,SAASA,oBAAA,EAAU;AACzB,EAAA,MAAM,CAAC,OAAO,QAAQ,CAAA,GAAIC,eAAsB,EAAE,MAAA,EAAQ,aAAa,CAAA;AACvE,EAAA,MAAM,YAAA,GAAeC,aAAO,KAAK,CAAA;AAEjC,EAAAC,eAAA,CAAU,MAAM;AAEd,IAAA,IAAI,OAAO,WAAW,WAAA,E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AAAA,UACR,OAAA,EAAS,OAAO,OAAA,IAAW;AAAA,SAC5B,CAAA;AAAA,MACH;AAAA,IACF,CAAC,CAAA,CACA,KAAA,CAAM,CAAC,GAAA,KAAQ;AACd,MAAA,OAAA,CAAQ,KAAA,CAAM,6CAA6C,GAAG,CAAA;AAC9D,MAAA,QAAA,CAAS;AAAA,QACP,MAAA,EAAQ,OAAA;AAAA,QACR,OAAA,EAAS;AAAA,OACV,CAAA;AAAA,IACH,CAAC,CAAA;AAAA,EACL,GAAG,CAAC,YAAA,EAAc,MAAA,EAAQ,WAAA,EAAa,SAAS,CAAC,CAAA;AAEjD,EAAA,OAAO,KAAA;AACT","file":"use-verify-magic-link.js","sourcesContent":["\"use client\";\n\nimport { useEffect, useState, useRef } from \"react\";\nimport { useRouter } from \"next/navigation\";\n\nexport type VerifyState = \n | { status: \"verifying\" }\n | { status: \"success\"; message: string }\n | { status: \"expired\"; message: string }\n | { status: \"error\"; message: string };\n\nexport interface VerifyActionResult {\n success: boolean;\n message?: string;\n isExpired?: boolean;\n}\n\nexport type VerifyAction = (code: string) => Promise<VerifyActionResult>;\n\nexport interface UseVerifyMagicLinkOptions {\n verifyAction: VerifyAction;\n onSuccess?: () => void;\n redirectUrl?: string;\n}\n\n/**\n * Shared hook for magic link and trial signup verification.\n * Extracts the code from URL hash, calls the verification action,\n * handles all error states, and redirects on success.\n * \n * Note: The verifyAction should be selected based on the verification type\n * (regular magic link vs trial signup) before calling this hook.\n */\nexport function useVerifyMagicLink({\n verifyAction,\n onSuccess,\n redirectUrl = \"/\"\n}: UseVerifyMagicLinkOptions) {\n const router = useRouter();\n const [state, setState] = useState<VerifyState>({ status: \"verifying\" });\n const verifyingRef = useRef(false);\n\n useEffect(() => {\n // Extract code from URL hash\n if (typeof window === \"undefined\") return;\n\n const hash = window.location.hash;\n \n if (!hash || hash.length <= 1) {\n setState({ \n status: \"error\", \n message: \"No verification code found. Please use the link from your email.\" \n });\n return;\n }\n\n // Remove the # and any trailing path segments, trim whitespace\n const code = hash.substring(1).split(\"/\")[0]?.trim() || \"\";\n \n if (!code) {\n setState({ \n status: \"error\", \n message: \"Invalid verification code. Please use the link from your email.\" \n });\n return;\n }\n\n // Prevent duplicate verification attempts\n if (verifyingRef.current) return;\n verifyingRef.current = true;\n\n // Auto-verify on mount\n verifyAction(code)\n .then((result) => {\n if (result.success) {\n setState({ \n status: \"success\", \n message: \"Verified! Redirecting to the portal...\" \n });\n \n // Call success callback if provided\n if (onSuccess) {\n onSuccess();\n }\n \n // Redirect to dashboard after a short delay\n setTimeout(() => {\n router.push(redirectUrl);\n }, 1500);\n } else if (result.isExpired) {\n setState({ \n status: \"expired\", \n message: result.message || \"Magic link has expired. A new link has been sent to your email.\" \n });\n } else {\n setState({ \n status: \"error\", \n message: result.message || \"Failed to verify. Please try again.\" \n });\n }\n })\n .catch((err) => {\n console.error(\"[use-verify-magic-link] Unexpected error:\", err);\n setState({ \n status: \"error\", \n message: \"An unexpected error occurred. Please try again.\" \n });\n });\n }, [verifyAction, router, redirectUrl, onSuccess]);\n\n return state;\n}\n"]}
1
+ {"version":3,"sources":["../src/hooks/use-verify-magic-link.ts"],"names":["useRouter","useState","useRef","useEffect"],"mappings":";;;;;;;;;;AAkCO,SAAS,kBAAA,CAAmB;AAAA,EACjC,YAAA;AAAA,EACA,SAAA;AAAA,EACA,WAAA,GAAc,GAAA;AAAA,EACd;AACF,CAAA,EAA8B;AAC5B,EAAA,MAAM,SAASA,oBAAA,EAAU;AACzB,EAAA,MAAM,CAAC,OAAO,QAAQ,CAAA,GAAIC,eAAsB,EAAE,MAAA,EAAQ,aAAa,CAAA;AACvE,EAAA,MAAM,YAAA,GAAeC,aAAO,KAAK,CAAA;AAEjC,EAAAC,eAAA,CAAU,MAAM;AAEd,IAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AAEnC,IAAA,MAAM,IAAA,GAAO,OAAO,QAAA,CAAS,IAAA;AAE7B,IAAA,IAAI,CAAC,IAAA,IAAQ,IAAA,CA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CACA,KAAA,CAAM,CAAC,GAAA,KAAQ;AACd,MAAA,OAAA,CAAQ,KAAA,CAAM,6CAA6C,GAAG,CAAA;AAC9D,MAAA,QAAA,CAAS;AAAA,QACP,MAAA,EAAQ,OAAA;AAAA,QACR,OAAA,EAAS;AAAA,OACV,CAAA;AAAA,IACH,CAAC,CAAA;AAAA,EACL,GAAG,CAAC,YAAA,EAAc,QAAQ,WAAA,EAAa,SAAA,EAAW,SAAS,CAAC,CAAA;AAE5D,EAAA,OAAO,KAAA;AACT","file":"use-verify-magic-link.js","sourcesContent":["\"use client\";\n\nimport { useEffect, useState, useRef } from \"react\";\nimport { useRouter } from \"next/navigation\";\n\nexport type VerifyState = \n | { status: \"verifying\" }\n | { status: \"success\"; message: string }\n | { status: \"expired\"; message: string }\n | { status: \"error\"; message: string };\n\nexport interface VerifyActionResult {\n success: boolean;\n message?: string;\n isExpired?: boolean;\n}\n\nexport type VerifyAction = (code: string, isPreview?: boolean) => Promise<VerifyActionResult>;\n\nexport interface UseVerifyMagicLinkOptions {\n verifyAction: VerifyAction;\n onSuccess?: () => void;\n redirectUrl?: string;\n isPreview?: boolean;\n}\n\n/**\n * Shared hook for magic link and trial signup verification.\n * Extracts the code from URL hash, calls the verification action,\n * handles all error states, and redirects on success.\n * \n * Note: The verifyAction should be selected based on the verification type\n * (regular magic link vs trial signup) before calling this hook.\n */\nexport function useVerifyMagicLink({\n verifyAction,\n onSuccess,\n redirectUrl = \"/\",\n isPreview\n}: UseVerifyMagicLinkOptions) {\n const router = useRouter();\n const [state, setState] = useState<VerifyState>({ status: \"verifying\" });\n const verifyingRef = useRef(false);\n\n useEffect(() => {\n // Extract code from URL hash\n if (typeof window === \"undefined\") return;\n\n const hash = window.location.hash;\n \n if (!hash || hash.length <= 1) {\n setState({ \n status: \"error\", \n message: \"No verification code found. Please use the link from your email.\" \n });\n return;\n }\n\n // Remove the # and any trailing path segments, trim whitespace\n const code = hash.substring(1).split(\"/\")[0]?.trim() || \"\";\n \n if (!code) {\n setState({ \n status: \"error\", \n message: \"Invalid verification code. Please use the link from your email.\" \n });\n return;\n }\n\n // Prevent duplicate verification attempts\n if (verifyingRef.current) return;\n verifyingRef.current = true;\n\n // Auto-verify on mount\n verifyAction(code, isPreview)\n .then((result) => {\n if (result.success) {\n setState({ \n status: \"success\", \n message: \"Verified! Redirecting to the portal...\" \n });\n \n // Call success callback if provided\n if (onSuccess) {\n onSuccess();\n }\n \n // Redirect to dashboard after a short delay\n setTimeout(() => {\n router.push(redirectUrl);\n }, 1500);\n } else if (result.isExpired) {\n setState({ \n status: \"expired\", \n message: result.message || \"Magic link has expired. A new link has been sent to your email.\" \n });\n } else {\n setState({ \n status: \"error\", \n message: result.message || \"Failed to verify. Please try again.\" \n });\n }\n })\n .catch((err) => {\n console.error(\"[use-verify-magic-link] Unexpected error:\", err);\n setState({ \n status: \"error\", \n message: \"An unexpected error occurred. Please try again.\" \n });\n });\n }, [verifyAction, router, redirectUrl, onSuccess, isPreview]);\n\n return state;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replicated/portal-components",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "description": "Opinionated component library for Replicated enterprise portals",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {