@opexa/portal-components 0.0.433 → 0.0.435
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.
|
@@ -16,66 +16,56 @@ export function useIdleLogout(timer = DEFAULT_IDLE_TIMER) {
|
|
|
16
16
|
onSuccess: () => {
|
|
17
17
|
router.refresh();
|
|
18
18
|
localStorage.removeItem(IDLE_TIMESTAMP_KEY);
|
|
19
|
+
logoutInitiated.current = false;
|
|
20
|
+
isLoggingOut.current = false;
|
|
19
21
|
},
|
|
20
22
|
onError: () => {
|
|
21
23
|
isLoggingOut.current = false;
|
|
24
|
+
logoutInitiated.current = false;
|
|
22
25
|
},
|
|
23
26
|
});
|
|
24
27
|
const isIdle = useIdle(timer);
|
|
25
|
-
const sessionStatusRef = useRef(sessionQuery.data?.status);
|
|
26
|
-
sessionStatusRef.current = sessionQuery.data?.status;
|
|
27
28
|
useEffect(() => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
if (sessionQuery.data?.status === 'authenticated') {
|
|
34
|
-
const lastActivityTimestamp = localStorage.getItem(IDLE_TIMESTAMP_KEY);
|
|
35
|
-
if (lastActivityTimestamp) {
|
|
36
|
-
localStorage.removeItem(IDLE_TIMESTAMP_KEY);
|
|
37
|
-
const timeElapsed = Date.now() - parseInt(lastActivityTimestamp, 10);
|
|
38
|
-
if (timeElapsed > timer) {
|
|
39
|
-
if (!logoutInitiated.current) {
|
|
40
|
-
logoutInitiated.current = true;
|
|
41
|
-
setTimeout(() => {
|
|
42
|
-
toaster.warning({
|
|
43
|
-
title: 'You have been away for a while.',
|
|
44
|
-
description: 'You have been logged out for inactivity.',
|
|
45
|
-
});
|
|
46
|
-
isLoggingOut.current = true;
|
|
47
|
-
signOutMutation.mutate();
|
|
48
|
-
}, 0);
|
|
49
|
-
}
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
window.addEventListener('beforeunload', handleUnload);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
29
|
+
if (sessionQuery.data?.status === 'unauthenticated') {
|
|
30
|
+
logoutInitiated.current = false;
|
|
31
|
+
isLoggingOut.current = false;
|
|
56
32
|
localStorage.removeItem(IDLE_TIMESTAMP_KEY);
|
|
57
33
|
}
|
|
58
|
-
|
|
59
|
-
window.removeEventListener('beforeunload', handleUnload);
|
|
60
|
-
};
|
|
61
|
-
}, [sessionQuery.data?.status, signOutMutation, timer]);
|
|
34
|
+
}, [sessionQuery.data?.status]);
|
|
62
35
|
useEffect(() => {
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
logoutInitiated.current = true;
|
|
68
|
-
setTimeout(() => {
|
|
69
|
-
toaster.warning({
|
|
70
|
-
title: 'You have been idle for a while.',
|
|
71
|
-
description: 'You will be logged out for inactivity.',
|
|
72
|
-
});
|
|
73
|
-
isLoggingOut.current = true;
|
|
74
|
-
signOutMutation.mutate();
|
|
75
|
-
}, 0);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
logoutInitiated.current = false;
|
|
36
|
+
if (sessionQuery.data?.status === 'unauthenticated' || !isIdle || logoutInitiated.current || isLoggingOut.current) {
|
|
37
|
+
return;
|
|
79
38
|
}
|
|
39
|
+
const handleIdleLogout = async () => {
|
|
40
|
+
logoutInitiated.current = true;
|
|
41
|
+
isLoggingOut.current = true;
|
|
42
|
+
const timestamp = Date.now().toString();
|
|
43
|
+
localStorage.setItem(IDLE_TIMESTAMP_KEY, timestamp);
|
|
44
|
+
toaster.warning({ description: 'You have been logged out due to inactivity.' });
|
|
45
|
+
try {
|
|
46
|
+
await signOutMutation.mutateAsync();
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
logoutInitiated.current = false;
|
|
50
|
+
isLoggingOut.current = false;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
handleIdleLogout();
|
|
80
54
|
}, [isIdle, sessionQuery.data?.status, signOutMutation]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const handleStorageChange = (e) => {
|
|
57
|
+
if (e.key === IDLE_TIMESTAMP_KEY && e.newValue && sessionQuery.data?.status === 'authenticated') {
|
|
58
|
+
if (!logoutInitiated.current) {
|
|
59
|
+
logoutInitiated.current = true;
|
|
60
|
+
router.refresh();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
window.addEventListener('storage', handleStorageChange);
|
|
65
|
+
return () => window.removeEventListener('storage', handleStorageChange);
|
|
66
|
+
}, [router, sessionQuery.data?.status]);
|
|
67
|
+
return {
|
|
68
|
+
isIdle,
|
|
69
|
+
isLoggingOut: isLoggingOut.current,
|
|
70
|
+
};
|
|
81
71
|
}
|
|
@@ -72,7 +72,7 @@ export function BetRecords__client(props) {
|
|
|
72
72
|
}),
|
|
73
73
|
...(state.status && {
|
|
74
74
|
status: {
|
|
75
|
-
|
|
75
|
+
equal: state.status,
|
|
76
76
|
},
|
|
77
77
|
}),
|
|
78
78
|
...(state.timestamp && {
|
|
@@ -139,9 +139,7 @@ export function BetRecords__client(props) {
|
|
|
139
139
|
}, children: [_jsxs(Select.Trigger, { className: "w-full lg:w-[14rem]", children: [_jsx(Select.ValueText, { placeholder: props.placeholder?.gameProvider ?? 'Game Vendor' }), _jsx(Select.Context, { children: (api) => (_jsx(_Fragment, { children: api.value.length ? (_jsx(Select.ClearTrigger, { asChild: true, children: _jsx("span", { onClick: (e) => {
|
|
140
140
|
e.stopPropagation();
|
|
141
141
|
}, children: "Clear" }) })) : (_jsx(Select.Indicator, { asChild: true, children: _jsx(ChevronDownIcon, {}) })) })) })] }), _jsx(Portal, { children: _jsx(Select.Positioner, { children: _jsx(Select.Content, { children: _jsx(Select.ItemGroup, { children: providerCollection.items.map((provider) => (_jsxs(Select.Item, { item: provider, children: [_jsx(Select.ItemText, { children: provider.name }), _jsx(Select.ItemIndicator, { asChild: true, children: _jsx(CheckIcon, {}) })] }, provider.id))) }) }) }) })] }), _jsxs(Select.Root, { collection: statusCollection, value: state.status ? [state.status] : [], onValueChange: (details) => {
|
|
142
|
-
const value = z
|
|
143
|
-
.enum(STATUSES)
|
|
144
|
-
.safeParse(details.value.at(0)).data;
|
|
142
|
+
const value = z.enum(STATUSES).safeParse(details.value.at(0)).data;
|
|
145
143
|
firstPage();
|
|
146
144
|
setState({
|
|
147
145
|
status: value ?? null,
|
|
@@ -185,7 +183,7 @@ export function BetRecords__client(props) {
|
|
|
185
183
|
delimiter: capitalize.delimiters.UNDERSCORE,
|
|
186
184
|
}) }) }) }), _jsx(Table.Cell, { className: "!py-1", children: data.game.name }), _jsx(Table.Cell, { className: "!py-1", children: data.vendorRoundId })] }, data.id))) })] }) }), _jsxs("div", { className: "flex items-center justify-between gap-lg px-4 py-3", children: [_jsx(IconButton, { size: "xs", variant: "outline", colorScheme: "gray", disabled: !hasPrevPage || loading, onClick: () => prev(), children: _jsx(ChevronLeftIcon, { className: "size-5" }) }), _jsxs("p", { className: "font-medium text-sm text-text-secondary-700", children: ["Page ", page, " of ", totalPages] }), _jsx(IconButton, { size: "xs", variant: "outline", colorScheme: "gray", disabled: !hasNextPage || loading, onClick: () => next(), children: _jsx(ChevronRightIcon, { className: "size-5" }) })] })] }))] }));
|
|
187
185
|
}
|
|
188
|
-
const STATUSES = ['
|
|
186
|
+
const STATUSES = ['STARTED', 'SETTLED', 'CANCELLED'];
|
|
189
187
|
const statusCollection = createListCollection({
|
|
190
188
|
items: STATUSES,
|
|
191
189
|
itemToValue: (item) => item,
|
|
@@ -83,7 +83,7 @@ export function SignUpDefaultForm() {
|
|
|
83
83
|
}),
|
|
84
84
|
firstName: z
|
|
85
85
|
.string()
|
|
86
|
-
.regex(/^[a-
|
|
86
|
+
.regex(/^[a-z ]+$/gi, 'First name must contain only letters')
|
|
87
87
|
.transform((val) => val.trim())
|
|
88
88
|
.refine((val) => val.length >= 2, {
|
|
89
89
|
message: 'First name must be 2 or more characters',
|
|
@@ -93,7 +93,7 @@ export function SignUpDefaultForm() {
|
|
|
93
93
|
}),
|
|
94
94
|
lastName: z
|
|
95
95
|
.string()
|
|
96
|
-
.regex(/^[a-
|
|
96
|
+
.regex(/^[a-z ]+$/gi, 'Last name must contain only letters')
|
|
97
97
|
.transform((val) => val.trim())
|
|
98
98
|
.refine((val) => val.length >= 2, {
|
|
99
99
|
message: 'Last name must be 2 or more characters',
|