@salesforce/webapp-template-feature-react-authentication-experimental 1.43.1 → 1.45.0

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.
Files changed (41) hide show
  1. package/dist/CHANGELOG.md +16 -0
  2. package/dist/force-app/main/default/webapplications/feature-react-authentication/package-lock.json +1306 -534
  3. package/dist/force-app/main/default/webapplications/feature-react-authentication/package.json +1 -3
  4. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/app.tsx +2 -5
  5. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/auth/authHelpers.ts +73 -0
  6. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/{utils → components/auth}/authenticationConfig.ts +9 -0
  7. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/auth/{authentication-route.tsx → authenticationRouteLayout.tsx} +1 -1
  8. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/auth/{private-route.tsx → privateRouteLayout.tsx} +1 -1
  9. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/auth/sessionTimeout/SessionTimeoutValidator.tsx +616 -0
  10. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/auth/sessionTimeout/sessionTimeService.ts +161 -0
  11. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/auth/sessionTimeout/sessionTimeoutConfig.ts +77 -0
  12. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/alert.tsx +17 -13
  13. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/button.tsx +35 -22
  14. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/card.tsx +27 -12
  15. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/dialog.tsx +143 -0
  16. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/field.tsx +157 -46
  17. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/index.ts +1 -0
  18. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/input.tsx +3 -3
  19. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/label.tsx +2 -2
  20. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/pagination.tsx +87 -74
  21. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/select.tsx +156 -124
  22. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/separator.tsx +26 -0
  23. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/skeleton.tsx +1 -0
  24. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/spinner.tsx +5 -16
  25. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/table.tsx +68 -95
  26. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/components/ui/tabs.tsx +47 -84
  27. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/context/AuthContext.tsx +12 -0
  28. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/hooks/form.tsx +1 -1
  29. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/hooks/useCountdownTimer.ts +266 -0
  30. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/hooks/useRetryWithBackoff.ts +109 -0
  31. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/layouts/AuthAppLayout.tsx +12 -0
  32. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/ChangePassword.tsx +3 -2
  33. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/ForgotPassword.tsx +1 -1
  34. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/Login.tsx +3 -3
  35. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/Profile.tsx +3 -2
  36. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/Register.tsx +4 -5
  37. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/pages/ResetPassword.tsx +3 -2
  38. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/routes.tsx +5 -5
  39. package/dist/force-app/main/default/webapplications/feature-react-authentication/src/utils/helpers.ts +0 -74
  40. package/dist/package.json +1 -1
  41. package/package.json +3 -3
@@ -1,115 +1,78 @@
1
1
  import * as React from "react";
2
- import { cn } from "../../lib/utils";
3
-
4
- interface TabsContextValue {
5
- value: string;
6
- onValueChange: (value: string) => void;
7
- }
8
-
9
- const TabsContext = React.createContext<TabsContextValue | undefined>(undefined);
10
-
11
- interface TabsProps extends React.ComponentProps<"div"> {
12
- value?: string;
13
- defaultValue?: string;
14
- onValueChange?: (value: string) => void;
15
- }
16
-
17
- function Tabs({ value, defaultValue, onValueChange, className, children, ...props }: TabsProps) {
18
- const [internalValue, setInternalValue] = React.useState(defaultValue || "");
19
- const controlled = value !== undefined;
20
- const currentValue = controlled ? value : internalValue;
2
+ import { cva, type VariantProps } from "class-variance-authority";
3
+ import { Tabs as TabsPrimitive } from "radix-ui";
21
4
 
22
- const handleValueChange = React.useCallback(
23
- (newValue: string) => {
24
- if (!controlled) {
25
- setInternalValue(newValue);
26
- }
27
- onValueChange?.(newValue);
28
- },
29
- [controlled, onValueChange],
30
- );
5
+ import { cn } from "../../lib/utils";
31
6
 
7
+ function Tabs({
8
+ className,
9
+ orientation = "horizontal",
10
+ ...props
11
+ }: React.ComponentProps<typeof TabsPrimitive.Root>) {
32
12
  return (
33
- <TabsContext.Provider value={{ value: currentValue, onValueChange: handleValueChange }}>
34
- <div data-slot="tabs" className={cn("w-full", className)} {...props}>
35
- {children}
36
- </div>
37
- </TabsContext.Provider>
13
+ <TabsPrimitive.Root
14
+ data-slot="tabs"
15
+ data-orientation={orientation}
16
+ className={cn("gap-2 group/tabs flex data-horizontal:flex-col", className)}
17
+ {...props}
18
+ />
38
19
  );
39
20
  }
40
21
 
41
- function useTabsContext() {
42
- const context = React.useContext(TabsContext);
43
- if (!context) {
44
- throw new Error("Tabs components must be used within a Tabs component");
45
- }
46
- return context;
47
- }
22
+ const tabsListVariants = cva(
23
+ "rounded-lg p-[3px] group-data-horizontal/tabs:h-8 data-[variant=line]:rounded-none group/tabs-list text-muted-foreground inline-flex w-fit items-center justify-center group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col",
24
+ {
25
+ variants: {
26
+ variant: {
27
+ default: "bg-muted",
28
+ line: "gap-1 bg-transparent",
29
+ },
30
+ },
31
+ defaultVariants: {
32
+ variant: "default",
33
+ },
34
+ },
35
+ );
48
36
 
49
- function TabsList({ className, ...props }: React.ComponentProps<"div">) {
37
+ function TabsList({
38
+ className,
39
+ variant = "default",
40
+ ...props
41
+ }: React.ComponentProps<typeof TabsPrimitive.List> & VariantProps<typeof tabsListVariants>) {
50
42
  return (
51
- <div
43
+ <TabsPrimitive.List
52
44
  data-slot="tabs-list"
53
- className={cn(
54
- "inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",
55
- className,
56
- )}
45
+ data-variant={variant}
46
+ className={cn(tabsListVariants({ variant }), className)}
57
47
  {...props}
58
48
  />
59
49
  );
60
50
  }
61
51
 
62
- interface TabsTriggerProps extends React.ComponentProps<"button"> {
63
- value: string;
64
- }
65
-
66
- function TabsTrigger({ className, value, ...props }: TabsTriggerProps) {
67
- const { value: selectedValue, onValueChange } = useTabsContext();
68
- const isSelected = selectedValue === value;
69
-
52
+ function TabsTrigger({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
70
53
  return (
71
- <button
54
+ <TabsPrimitive.Trigger
72
55
  data-slot="tabs-trigger"
73
- data-selected={isSelected}
74
- type="button"
75
- role="tab"
76
- aria-selected={isSelected}
77
56
  className={cn(
78
- "inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
79
- isSelected
80
- ? "bg-background text-foreground shadow-sm"
81
- : "text-muted-foreground hover:bg-background/50",
57
+ "gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg:not([class*='size-'])]:size-4 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring text-foreground/60 hover:text-foreground dark:text-muted-foreground dark:hover:text-foreground relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
58
+ "group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent",
59
+ "data-active:bg-background dark:data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 data-active:text-foreground",
60
+ "after:bg-foreground after:absolute after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100",
82
61
  className,
83
62
  )}
84
- onClick={() => onValueChange(value)}
85
63
  {...props}
86
64
  />
87
65
  );
88
66
  }
89
67
 
90
- interface TabsContentProps extends React.ComponentProps<"div"> {
91
- value: string;
92
- }
93
-
94
- function TabsContent({ className, value, children, ...props }: TabsContentProps) {
95
- const { value: selectedValue } = useTabsContext();
96
- if (selectedValue !== value) {
97
- return null;
98
- }
99
-
68
+ function TabsContent({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Content>) {
100
69
  return (
101
- <div
70
+ <TabsPrimitive.Content
102
71
  data-slot="tabs-content"
103
- role="tabpanel"
104
- className={cn(
105
- "mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
106
- className,
107
- )}
72
+ className={cn("text-sm flex-1 outline-none", className)}
108
73
  {...props}
109
- >
110
- {children}
111
- </div>
74
+ />
112
75
  );
113
76
  }
114
77
 
115
- export { Tabs, TabsList, TabsTrigger, TabsContent };
78
+ export { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants };
@@ -1,5 +1,6 @@
1
1
  import { createContext, useContext, useState, useEffect, useCallback, type ReactNode } from "react";
2
2
  import { getCurrentUser } from "@salesforce/webapp-experimental/api";
3
+ import { API_ROUTES } from "../components/auth/authenticationConfig";
3
4
 
4
5
  interface User {
5
6
  readonly id: string;
@@ -12,6 +13,7 @@ interface AuthContextType {
12
13
  loading: boolean;
13
14
  error: string | null;
14
15
  checkAuth: () => Promise<void>;
16
+ logout: (startURL?: string) => void;
15
17
  }
16
18
 
17
19
  const AuthContext = createContext<AuthContextType | undefined>(undefined);
@@ -41,6 +43,15 @@ export function AuthProvider({ children }: AuthProviderProps) {
41
43
  }
42
44
  }, []);
43
45
 
46
+ const logout = useCallback((startURL?: string) => {
47
+ // Navigate to logout URL (server-side endpoint)
48
+ // Use replace to prevent back button from returning to authenticated session
49
+ const finalLogoutUrl = startURL
50
+ ? `${API_ROUTES.LOGOUT}?startURL=${encodeURIComponent(startURL)}`
51
+ : API_ROUTES.LOGOUT;
52
+ window.location.replace(finalLogoutUrl);
53
+ }, []);
54
+
44
55
  useEffect(() => {
45
56
  checkAuth();
46
57
  }, [checkAuth]);
@@ -51,6 +62,7 @@ export function AuthProvider({ children }: AuthProviderProps) {
51
62
  loading,
52
63
  error,
53
64
  checkAuth,
65
+ logout,
54
66
  };
55
67
 
56
68
  return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
@@ -3,7 +3,7 @@ import { createFormHookContexts, createFormHook } from "@tanstack/react-form";
3
3
  import { Field, FieldDescription, FieldError, FieldLabel } from "../components/ui/field";
4
4
  import { Input } from "../components/ui/input";
5
5
  import { cn } from "../lib/utils";
6
- import { AUTH_PLACEHOLDERS } from "../utils/authenticationConfig";
6
+ import { AUTH_PLACEHOLDERS } from "../components/auth/authenticationConfig";
7
7
 
8
8
  // Create form hook contexts
9
9
  export const { fieldContext, formContext, useFieldContext, useFormContext } =
@@ -0,0 +1,266 @@
1
+ /**
2
+ * Custom hook for countdown timer with accessibility features
3
+ */
4
+
5
+ import { useState, useEffect, useRef, useCallback } from "react";
6
+
7
+ /**
8
+ * Accessibility configuration for countdown timer
9
+ */
10
+ export interface CountdownTimerA11yConfig {
11
+ /** Announce time remaining at these specific second marks */
12
+ ANNOUNCE_AT_SECONDS: readonly number[];
13
+ /** Announce every N seconds (after initial period) */
14
+ ANNOUNCE_INTERVAL_SECONDS: number;
15
+ /** Minimum elapsed time before starting interval announcements */
16
+ MIN_ELAPSED_FOR_INTERVAL: number;
17
+ }
18
+
19
+ /**
20
+ * Return value from useCountdownTimer hook
21
+ */
22
+ export interface CountdownTimerResult {
23
+ /** Current time remaining in seconds */
24
+ displayTime: number;
25
+ /** Formatted time string (MM:SS) */
26
+ formattedTime: string;
27
+ /** ISO 8601 duration string (e.g., PT2M15S) */
28
+ isoTime: string;
29
+ /** Accessibility announcement text for screen readers */
30
+ accessibilityAnnouncement: string;
31
+ /** Start the countdown timer */
32
+ start: () => void;
33
+ /** Stop the countdown timer */
34
+ stop: () => void;
35
+ /** Reset the countdown timer to initial time */
36
+ reset: () => void;
37
+ }
38
+
39
+ /**
40
+ * Configuration for countdown timer hook
41
+ */
42
+ export interface CountdownTimerConfig {
43
+ /** Initial time in seconds */
44
+ initialTime: number;
45
+ /** Callback when countdown reaches 0 */
46
+ onExpire: () => void;
47
+ /** Optional accessibility configuration */
48
+ a11yConfig?: CountdownTimerA11yConfig;
49
+ }
50
+
51
+ /**
52
+ * Default accessibility configuration
53
+ */
54
+ const DEFAULT_A11Y_CONFIG: CountdownTimerA11yConfig = {
55
+ ANNOUNCE_AT_SECONDS: [5, 1],
56
+ ANNOUNCE_INTERVAL_SECONDS: 10,
57
+ MIN_ELAPSED_FOR_INTERVAL: 10,
58
+ };
59
+
60
+ /**
61
+ * Format time remaining as MM:SS string
62
+ * Uses Intl.NumberFormat for zero-padding and internationalization
63
+ *
64
+ * @param seconds - Total seconds remaining
65
+ * @returns Formatted time string (e.g., "05:23")
66
+ */
67
+ function formatTimeRemaining(seconds: number): string {
68
+ const minutes = Math.floor(seconds / 60);
69
+ const secs = seconds % 60;
70
+
71
+ // Use Intl.NumberFormat for zero-padding with internationalization
72
+ const formatter = new Intl.NumberFormat(navigator.language, {
73
+ minimumIntegerDigits: 2,
74
+ useGrouping: false,
75
+ });
76
+
77
+ return `${formatter.format(minutes)}:${formatter.format(secs)}`;
78
+ }
79
+
80
+ /**
81
+ * Format time remaining as ISO 8601 duration for ARIA
82
+ * Used in datetime attribute of <time> element
83
+ *
84
+ * @param seconds - Total seconds remaining
85
+ * @returns ISO 8601 duration string (e.g., "PT2M15S")
86
+ */
87
+ function formatISODuration(seconds: number): string {
88
+ const minutes = Math.floor(seconds / 60);
89
+ const secs = seconds % 60;
90
+ return `PT${minutes}M${secs}S`;
91
+ }
92
+
93
+ /**
94
+ * Format time remaining for screen reader announcement
95
+ * Uses Intl.DurationFormat if available, falls back to manual formatting
96
+ *
97
+ * @param seconds - Total seconds remaining
98
+ * @returns Formatted announcement text (e.g., "2 minutes 15 seconds")
99
+ */
100
+ function formatAccessibilityAnnouncement(seconds: number): string {
101
+ const minutes = Math.floor(seconds / 60);
102
+ const secs = seconds % 60;
103
+
104
+ // Try using Intl.DurationFormat (newer API, may not be available in all browsers)
105
+ if (typeof Intl !== "undefined" && "DurationFormat" in Intl) {
106
+ try {
107
+ // @ts-expect-error - DurationFormat is not yet in TypeScript lib
108
+ const formatter = new Intl.DurationFormat(navigator.language, { style: "long" });
109
+ return formatter.format({ minutes, seconds: secs });
110
+ } catch (e) {
111
+ // Fallback to manual formatting
112
+ }
113
+ }
114
+
115
+ // Manual fallback
116
+ const parts: string[] = [];
117
+ if (minutes > 0) {
118
+ parts.push(`${minutes} ${minutes === 1 ? "minute" : "minutes"}`);
119
+ }
120
+ if (secs > 0 || minutes === 0) {
121
+ parts.push(`${secs} ${secs === 1 ? "second" : "seconds"}`);
122
+ }
123
+ return parts.join(" ");
124
+ }
125
+
126
+ /**
127
+ * Determine if an accessibility announcement should be made at this time
128
+ *
129
+ * @param currentTime - Current countdown time in seconds
130
+ * @param initialTime - Initial countdown time in seconds
131
+ * @param config - Accessibility configuration
132
+ * @returns True if announcement should be made
133
+ */
134
+ function shouldAnnounce(
135
+ currentTime: number,
136
+ initialTime: number,
137
+ config: CountdownTimerA11yConfig,
138
+ ): boolean {
139
+ // Announce at specific second marks (5s, 1s)
140
+ if (config.ANNOUNCE_AT_SECONDS.includes(currentTime)) {
141
+ return true;
142
+ }
143
+
144
+ // Calculate elapsed time
145
+ const elapsed = initialTime - currentTime;
146
+
147
+ // Announce every N seconds after minimum elapsed time
148
+ if (elapsed >= config.MIN_ELAPSED_FOR_INTERVAL) {
149
+ return currentTime % config.ANNOUNCE_INTERVAL_SECONDS === 0;
150
+ }
151
+
152
+ return false;
153
+ }
154
+
155
+ /**
156
+ * Custom hook for countdown timer with accessibility
157
+ * Decrements from initial time to 0, provides formatted output for display and ARIA
158
+ *
159
+ * @param config - Timer configuration
160
+ * @returns Timer state and control functions
161
+ *
162
+ * @example
163
+ * const timer = useCountdownTimer({
164
+ * initialTime: 300, // 5 minutes
165
+ * onExpire: () => handleLogout()
166
+ * });
167
+ *
168
+ * timer.start(); // Begin countdown
169
+ *
170
+ * <time dateTime={timer.isoTime} role="timer">
171
+ * {timer.formattedTime}
172
+ * </time>
173
+ * <div role="status" aria-live="polite" className="sr-only">
174
+ * {timer.accessibilityAnnouncement}
175
+ * </div>
176
+ */
177
+ export function useCountdownTimer({
178
+ initialTime,
179
+ onExpire,
180
+ a11yConfig = DEFAULT_A11Y_CONFIG,
181
+ }: CountdownTimerConfig): CountdownTimerResult {
182
+ const [displayTime, setDisplayTime] = useState(initialTime);
183
+ const [accessibilityAnnouncement, setAccessibilityAnnouncement] = useState("");
184
+ const [isActive, setIsActive] = useState(false);
185
+
186
+ // Use refs to avoid stale closure issues
187
+ const initialTimeRef = useRef(initialTime);
188
+ const onExpireRef = useRef(onExpire);
189
+ const a11yConfigRef = useRef(a11yConfig);
190
+ const endTimeRef = useRef<number>(0);
191
+ const previousTimeRef = useRef<number>(initialTime);
192
+
193
+ // Update refs when props change
194
+ useEffect(() => {
195
+ initialTimeRef.current = initialTime;
196
+ }, [initialTime]);
197
+
198
+ useEffect(() => {
199
+ onExpireRef.current = onExpire;
200
+ }, [onExpire]);
201
+
202
+ useEffect(() => {
203
+ a11yConfigRef.current = a11yConfig;
204
+ }, [a11yConfig]);
205
+
206
+ // Countdown effect using Date.now() for accuracy
207
+ useEffect(() => {
208
+ if (!isActive) return;
209
+
210
+ // Set the target end time when timer starts
211
+ endTimeRef.current = Date.now() + initialTimeRef.current * 1000;
212
+ previousTimeRef.current = initialTimeRef.current;
213
+
214
+ const intervalId = setInterval(() => {
215
+ const now = Date.now();
216
+ const remainingMs = endTimeRef.current - now;
217
+ const newTime = Math.max(0, Math.ceil(remainingMs / 1000));
218
+
219
+ setDisplayTime(newTime);
220
+
221
+ // Check if we should make an accessibility announcement
222
+ // Only announce when the second value changes
223
+ if (
224
+ newTime !== previousTimeRef.current &&
225
+ shouldAnnounce(newTime, initialTimeRef.current, a11yConfigRef.current)
226
+ ) {
227
+ setAccessibilityAnnouncement(formatAccessibilityAnnouncement(newTime));
228
+ }
229
+ previousTimeRef.current = newTime;
230
+
231
+ // Check if countdown expired
232
+ if (newTime <= 0) {
233
+ clearInterval(intervalId);
234
+ setIsActive(false);
235
+ onExpireRef.current();
236
+ }
237
+ }, 100); // Check more frequently for smoother updates
238
+
239
+ return () => clearInterval(intervalId);
240
+ }, [isActive]);
241
+
242
+ // Control functions
243
+ const start = useCallback(() => {
244
+ setIsActive(true);
245
+ }, []);
246
+
247
+ const stop = useCallback(() => {
248
+ setIsActive(false);
249
+ }, []);
250
+
251
+ const reset = useCallback(() => {
252
+ setDisplayTime(initialTimeRef.current);
253
+ setIsActive(false);
254
+ setAccessibilityAnnouncement("");
255
+ }, []);
256
+
257
+ return {
258
+ displayTime,
259
+ formattedTime: formatTimeRemaining(displayTime),
260
+ isoTime: formatISODuration(displayTime),
261
+ accessibilityAnnouncement,
262
+ start,
263
+ stop,
264
+ reset,
265
+ };
266
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Custom hook for retry logic with exponential backoff
3
+ */
4
+
5
+ import { useState, useCallback } from "react";
6
+
7
+ export interface UseRetryWithBackoffOptions {
8
+ /** Initial delay in milliseconds */
9
+ initialDelay: number;
10
+ /** Maximum number of retry attempts */
11
+ maxAttempts: number;
12
+ /** Maximum delay in milliseconds */
13
+ maxDelay: number;
14
+ }
15
+
16
+ export interface UseRetryWithBackoffResult {
17
+ /** Current number of retry attempts */
18
+ retryAttempts: number;
19
+ /** Current retry delay in milliseconds */
20
+ currentRetryDelay: number;
21
+ /** Whether max retry attempts have been reached */
22
+ maxRetriesReached: boolean;
23
+ /** Schedule a retry with exponential backoff, returns timeout ID for cancellation */
24
+ scheduleRetry: (callback: () => void) => ReturnType<typeof setTimeout> | undefined;
25
+ /** Reset retry state after successful operation */
26
+ resetRetry: () => void;
27
+ }
28
+
29
+ /**
30
+ * Hook for managing retry logic with exponential backoff
31
+ *
32
+ * @param options - Configuration for retry behavior
33
+ * @returns Retry state and control functions
34
+ *
35
+ * @example
36
+ * const retry = useRetryWithBackoff({
37
+ * initialDelay: 2000,
38
+ * maxAttempts: 10,
39
+ * maxDelay: 1800000
40
+ * });
41
+ *
42
+ * async function fetchData() {
43
+ * try {
44
+ * const data = await apiCall();
45
+ * retry.resetRetry();
46
+ * return data;
47
+ * } catch (error) {
48
+ * if (retry.maxRetriesReached) {
49
+ * console.error('Max retries reached');
50
+ * return;
51
+ * }
52
+ * retry.scheduleRetry(() => fetchData());
53
+ * }
54
+ * }
55
+ */
56
+ export function useRetryWithBackoff(
57
+ options: UseRetryWithBackoffOptions,
58
+ ): UseRetryWithBackoffResult {
59
+ const { initialDelay, maxAttempts, maxDelay } = options;
60
+
61
+ const [retryAttempts, setRetryAttempts] = useState<number>(0);
62
+ const [currentRetryDelay, setCurrentRetryDelay] = useState<number>(initialDelay);
63
+
64
+ const maxRetriesReached = retryAttempts >= maxAttempts;
65
+
66
+ /**
67
+ * Reset retry state after successful operation
68
+ */
69
+ const resetRetry = useCallback(() => {
70
+ setRetryAttempts(0);
71
+ setCurrentRetryDelay(initialDelay);
72
+ }, [initialDelay]);
73
+
74
+ /**
75
+ * Schedule a retry with exponential backoff
76
+ * Returns the timeout ID which can be used to cancel the retry if needed
77
+ */
78
+ const scheduleRetry = useCallback(
79
+ (callback: () => void) => {
80
+ if (retryAttempts >= maxAttempts) {
81
+ console.error("[useRetryWithBackoff] Max retry attempts reached");
82
+ return undefined;
83
+ }
84
+
85
+ console.warn(
86
+ `[useRetryWithBackoff] Retry attempt ${retryAttempts + 1}/${maxAttempts} in ${currentRetryDelay}ms`,
87
+ );
88
+
89
+ const timeoutId = setTimeout(() => {
90
+ callback();
91
+ }, currentRetryDelay);
92
+
93
+ setRetryAttempts((prev) => prev + 1);
94
+ // Double the delay for next retry, capped at maxDelay
95
+ setCurrentRetryDelay((prev) => Math.min(prev * 2, maxDelay));
96
+
97
+ return timeoutId;
98
+ },
99
+ [retryAttempts, currentRetryDelay, maxAttempts, maxDelay],
100
+ );
101
+
102
+ return {
103
+ retryAttempts,
104
+ currentRetryDelay,
105
+ maxRetriesReached,
106
+ scheduleRetry,
107
+ resetRetry,
108
+ };
109
+ }
@@ -0,0 +1,12 @@
1
+ import SessionTimeoutValidator from "../components/auth/sessionTimeout/SessionTimeoutValidator";
2
+ import { AuthProvider } from "../context/AuthContext";
3
+ import AppLayout from "../appLayout";
4
+
5
+ export default function AuthAppLayout() {
6
+ return (
7
+ <AuthProvider>
8
+ <SessionTimeoutValidator basePath="" />
9
+ <AppLayout />
10
+ </AuthProvider>
11
+ );
12
+ }
@@ -5,8 +5,9 @@ import { uiApiClient } from "@salesforce/webapp-experimental/api";
5
5
  import { CenteredPageLayout } from "../components/layout/centered-page-layout";
6
6
  import { AuthForm } from "../components/forms/auth-form";
7
7
  import { useAppForm } from "../hooks/form";
8
- import { ROUTES, AUTH_PLACEHOLDERS } from "../utils/authenticationConfig";
9
- import { newPasswordSchema, handleApiResponse, getErrorMessage } from "../utils/helpers";
8
+ import { ROUTES, AUTH_PLACEHOLDERS } from "../components/auth/authenticationConfig";
9
+ import { newPasswordSchema } from "../components/auth/authHelpers";
10
+ import { handleApiResponse, getErrorMessage } from "../utils/helpers";
10
11
 
11
12
  const changePasswordSchema = z
12
13
  .object({
@@ -4,7 +4,7 @@ import { uiApiClient } from "@salesforce/webapp-experimental/api";
4
4
  import { CenteredPageLayout } from "../components/layout/centered-page-layout";
5
5
  import { AuthForm } from "../components/forms/auth-form";
6
6
  import { useAppForm } from "../hooks/form";
7
- import { ROUTES, AUTH_PLACEHOLDERS } from "../utils/authenticationConfig";
7
+ import { ROUTES, AUTH_PLACEHOLDERS } from "../components/auth/authenticationConfig";
8
8
  import { handleApiResponse, getErrorMessage } from "../utils/helpers";
9
9
 
10
10
  const forgotPasswordSchema = z.object({
@@ -5,9 +5,9 @@ import { uiApiClient } from "@salesforce/webapp-experimental/api";
5
5
  import { CenteredPageLayout } from "../components/layout/centered-page-layout";
6
6
  import { AuthForm } from "../components/forms/auth-form";
7
7
  import { useAppForm } from "../hooks/form";
8
- import { ROUTES } from "../utils/authenticationConfig";
9
- import { emailSchema, getStartUrl, handleApiResponse, getErrorMessage } from "../utils/helpers";
10
- import type { AuthResponse } from "../utils/helpers";
8
+ import { ROUTES } from "../components/auth/authenticationConfig";
9
+ import { emailSchema, getStartUrl, type AuthResponse } from "../components/auth/authHelpers";
10
+ import { handleApiResponse, getErrorMessage } from "../utils/helpers";
11
11
 
12
12
  const loginSchema = z.object({
13
13
  email: emailSchema,
@@ -7,8 +7,9 @@ import { CenteredPageLayout } from "../components/layout/centered-page-layout";
7
7
  import { CardSkeleton } from "../components/layout/card-skeleton";
8
8
  import { AuthForm } from "../components/forms/auth-form";
9
9
  import { useAppForm } from "../hooks/form";
10
- import { ROUTES } from "../utils/authenticationConfig";
11
- import { emailSchema, flattenGraphQLRecord, getErrorMessage } from "../utils/helpers";
10
+ import { ROUTES } from "../components/auth/authenticationConfig";
11
+ import { emailSchema } from "../components/auth/authHelpers";
12
+ import { flattenGraphQLRecord, getErrorMessage } from "../utils/helpers";
12
13
  import { getUser } from "../context/AuthContext";
13
14
 
14
15
  const GRAPHQL_USER_PROFILE_FIELDS = `
@@ -5,15 +5,14 @@ import { uiApiClient } from "@salesforce/webapp-experimental/api";
5
5
  import { CenteredPageLayout } from "../components/layout/centered-page-layout";
6
6
  import { AuthForm } from "../components/forms/auth-form";
7
7
  import { useAppForm } from "../hooks/form";
8
- import { ROUTES, AUTH_PLACEHOLDERS } from "../utils/authenticationConfig";
8
+ import { ROUTES, AUTH_PLACEHOLDERS } from "../components/auth/authenticationConfig";
9
9
  import {
10
10
  emailSchema,
11
11
  passwordSchema,
12
12
  getStartUrl,
13
- handleApiResponse,
14
- getErrorMessage,
15
- } from "../utils/helpers";
16
- import type { AuthResponse } from "../utils/helpers";
13
+ type AuthResponse,
14
+ } from "../components/auth/authHelpers";
15
+ import { handleApiResponse, getErrorMessage } from "../utils/helpers";
17
16
 
18
17
  const registerSchema = z
19
18
  .object({