Skip to content

Commit abdfa9c

Browse files
committed
chore(dashboard): add wait util function, keep delay with success messages before redirects (shortened)
1 parent e36df2a commit abdfa9c

File tree

8 files changed

+60
-17
lines changed

8 files changed

+60
-17
lines changed

packages/apps/app-dashboard/src/components/user-dashboard/connect/EditPermissionsCard.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { useJwtRedirect } from '@/hooks/user-dashboard/connect/useJwtRedirect';
1919
import { useFormatUserPermissions } from '@/hooks/user-dashboard/dashboard/useFormatUserPermissions';
2020
import { ReadAuthInfo } from '@/hooks/user-dashboard/useAuthInfo';
2121
import { litNodeClient } from '@/utils/user-dashboard/lit';
22+
import { wait } from '@/lib/utils';
2223

2324
interface EditPermissionsCardProps {
2425
connectInfoMap: ConnectInfoMap;
@@ -57,8 +58,11 @@ export function EditPermissionsCard({
5758
// Handle redirect when JWT is ready
5859
useEffect(() => {
5960
if (redirectUrl && !localSuccess) {
60-
setLocalSuccess('Success! Redirecting to app...');
61-
executeRedirect();
61+
(async () => {
62+
setLocalSuccess('Success! Redirecting to app...');
63+
await wait(1000);
64+
executeRedirect();
65+
})();
6266
}
6367
}, [redirectUrl, localSuccess, executeRedirect]);
6468

packages/apps/app-dashboard/src/components/user-dashboard/connect/RepermitConnect.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ActionButtons } from './ui/ActionButtons';
1414
import { theme } from './ui/theme';
1515
import { InfoBanner } from './ui/InfoBanner';
1616
import { App } from '@/types/developer-dashboard/appTypes';
17+
import { wait } from '@/lib/utils';
1718

1819
interface RepermitConnectProps {
1920
appData: App;
@@ -44,15 +45,20 @@ export function RepermitConnect({
4445
// Handle redirect when JWT is ready
4546
useEffect(() => {
4647
if (redirectUrl && localSuccess !== 'Success! Redirecting to app...') {
47-
setLocalSuccess('Success! Redirecting to app...');
48-
executeRedirect();
48+
(async () => {
49+
setLocalSuccess('Success! Redirecting to app...');
50+
await wait(1000);
51+
executeRedirect();
52+
})();
4953
}
5054
}, [redirectUrl, localSuccess, executeRedirect]);
5155

5256
// Generate JWT when re-permitting is successful
5357
useEffect(() => {
5458
if (localSuccess === 'App re-permitted successfully!') {
55-
generateJWT(appData, appData.activeVersion!);
59+
(async () => {
60+
await generateJWT(appData, appData.activeVersion!);
61+
})();
5662
}
5763
}, [localSuccess, generateJWT, appData]);
5864

packages/apps/app-dashboard/src/components/user-dashboard/connect/ReturningUserConnect.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useCanGoBack } from '@/hooks/user-dashboard/connect/useCanGoBack';
1212
import { useJwtRedirect } from '@/hooks/user-dashboard/connect/useJwtRedirect';
1313
import { ReadAuthInfo } from '@/hooks/user-dashboard/useAuthInfo';
1414
import { App, AppVersion } from '@/types/developer-dashboard/appTypes';
15+
import { wait } from '@/lib/utils';
1516

1617
type ReturningUserConnectProps = {
1718
appData: App;
@@ -46,8 +47,11 @@ export function ReturningUserConnect({
4647
// Handle redirect when JWT is ready
4748
useEffect(() => {
4849
if (redirectUrl && !localSuccess) {
49-
setLocalSuccess('Success! Redirecting to app...');
50-
executeRedirect();
50+
(async () => {
51+
setLocalSuccess('Success! Redirecting to app...');
52+
await wait(1000);
53+
executeRedirect();
54+
})();
5155
}
5256
}, [redirectUrl, localSuccess, executeRedirect]);
5357

packages/apps/app-dashboard/src/components/user-dashboard/connect/UpdateVersionCard.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { useConnectFormData } from '@/hooks/user-dashboard/connect/useConnectFor
2020
import { useJwtRedirect } from '@/hooks/user-dashboard/connect/useJwtRedirect';
2121
import { ReadAuthInfo } from '@/hooks/user-dashboard/useAuthInfo';
2222
import { litNodeClient } from '@/utils/user-dashboard/lit';
23+
import { wait } from '@/lib/utils';
2324

2425
interface UpdateVersionCardProps {
2526
connectInfoMap: ConnectInfoMap;
@@ -56,8 +57,11 @@ export function UpdateVersionCard({
5657
// Handle redirect when JWT is ready
5758
useEffect(() => {
5859
if (redirectUrl && !localSuccess) {
59-
setLocalSuccess('Success! Redirecting to app...');
60-
executeRedirect();
60+
(async () => {
61+
setLocalSuccess('Success! Redirecting to app...');
62+
await wait(1000);
63+
executeRedirect();
64+
})();
6165
}
6266
}, [redirectUrl, localSuccess, executeRedirect]);
6367

packages/apps/app-dashboard/src/components/user-dashboard/dashboard/RepermitConnectPage.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ConnectAppHeader } from '../connect/ui/ConnectAppHeader';
1616
import { PageHeader } from './ui/PageHeader';
1717
import { ActionButtons } from '../connect/ui/ActionButtons';
1818
import { Breadcrumb } from '@/components/shared/ui/Breadcrumb';
19+
import { wait } from '@/lib/utils';
1920

2021
interface RepermitConnectPageProps {
2122
appData: App;
@@ -55,8 +56,11 @@ export function RepermitConnectPage({
5556
// Handle redirect when JWT is ready
5657
useEffect(() => {
5758
if (redirectUrl && !localSuccess) {
58-
setLocalSuccess('Success! Redirecting to app...');
59-
executeRedirect();
59+
(async () => {
60+
setLocalSuccess('Success! Redirecting to app...');
61+
await wait(1000);
62+
executeRedirect();
63+
})();
6064
}
6165
}, [redirectUrl, localSuccess, executeRedirect]);
6266

@@ -92,7 +96,8 @@ export function RepermitConnectPage({
9296
setIsConnectProcessing(false);
9397
setLocalSuccess('App re-permitted successfully!');
9498

95-
// Generate JWT for redirect or navigate
99+
// Generate JWT for redirect or navigate after showing success message
100+
await wait(2000);
96101
setLocalSuccess(null);
97102
// Only generate JWT if there's an effectiveRedirectUri (for app redirects)
98103
if (effectiveRedirectUri) {

packages/apps/app-dashboard/src/components/user-dashboard/dashboard/UpdateVersionPage.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { useJwtRedirect } from '@/hooks/user-dashboard/connect/useJwtRedirect';
1919
import { useUrlRedirectUri } from '@/hooks/user-dashboard/connect/useUrlRedirectUri';
2020
import { ActionButtons } from '@/components/user-dashboard/connect/ui/ActionButtons';
2121
import { Breadcrumb } from '@/components/shared/ui/Breadcrumb';
22+
import { wait } from '@/lib/utils';
2223

2324
interface UpdateVersionPageProps {
2425
connectInfoMap: ConnectInfoMap;
@@ -53,8 +54,11 @@ export function UpdateVersionPage({
5354
// Handle redirect when JWT is ready
5455
useEffect(() => {
5556
if (redirectUrl && !localSuccess) {
56-
setLocalSuccess('Success! Redirecting to app...');
57-
executeRedirect();
57+
(async () => {
58+
setLocalSuccess('Success! Redirecting to app...');
59+
await wait(1000);
60+
executeRedirect();
61+
})();
5862
}
5963
}, [redirectUrl, localSuccess, executeRedirect]);
6064

@@ -120,6 +124,7 @@ export function UpdateVersionPage({
120124
setLocalStatus(null);
121125
// Show success state then redirect or reload
122126
setLocalSuccess('Version updated successfully!');
127+
await wait(2000);
123128
setLocalSuccess(null);
124129
// Only generate JWT if there's a redirectUri (for app redirects)
125130
if (redirectUri) {

packages/apps/app-dashboard/src/components/user-dashboard/dashboard/UserPermissionPage.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ReadAuthInfo } from '@/hooks/user-dashboard/useAuthInfo';
1919
import { AppVersion } from '@/types/developer-dashboard/appTypes';
2020
import { hasConfigurablePolicies } from '@/utils/user-dashboard/hasConfigurablePolicies';
2121
import { litNodeClient } from '@/utils/user-dashboard/lit';
22+
import { wait } from '@/lib/utils';
2223

2324
interface AppPermissionPageProps {
2425
connectInfoMap: ConnectInfoMap;
@@ -65,8 +66,11 @@ export function AppPermissionPage({
6566
// Handle redirect when JWT is ready
6667
useEffect(() => {
6768
if (redirectUrl && !localSuccess) {
68-
setLocalSuccess('Success! Redirecting to app...');
69-
executeRedirect();
69+
(async () => {
70+
setLocalSuccess('Success! Redirecting to app...');
71+
await wait(1000);
72+
executeRedirect();
73+
})();
7074
}
7175
}, [redirectUrl, localSuccess, executeRedirect]);
7276

@@ -174,6 +178,7 @@ export function AppPermissionPage({
174178
if (!hasAnyChanges) {
175179
setLocalStatus(null);
176180
setLocalSuccess('Permissions are up to date.');
181+
await wait(2000);
177182
setLocalSuccess(null);
178183
return;
179184
}
@@ -211,6 +216,7 @@ export function AppPermissionPage({
211216
setLocalSuccess('Permissions granted successfully!');
212217

213218
// Generate JWT for redirect (useJwtRedirect will handle if there's a redirectUri)
219+
await wait(2000);
214220
setLocalSuccess(null);
215221
// Only generate JWT if there's a redirectUri (for app redirects)
216222
if (redirectUri) {
@@ -273,7 +279,8 @@ export function AppPermissionPage({
273279
setLocalStatus(null);
274280
// Show success state until redirect
275281
setLocalSuccess('App unpermitted successfully!');
276-
// Force the refresh for the sidebar to update
282+
// Force the refresh for the sidebar to update after showing success message
283+
await wait(2000);
277284
window.location.href = `/user/apps`;
278285
} catch (error) {
279286
setLocalError(error instanceof Error ? error.message : 'Failed to unpermit app');

packages/apps/app-dashboard/src/lib/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ import { twMerge } from 'tailwind-merge';
44
export function cn(...inputs: ClassValue[]) {
55
return twMerge(clsx(inputs));
66
}
7+
8+
/**
9+
* Utility function to wait for a specified amount of time
10+
* @param time Time to wait in milliseconds (default: 3000ms)
11+
*/
12+
export async function wait(time = 3_000): Promise<void> {
13+
await new Promise((resolve) => setTimeout(resolve, time));
14+
}

0 commit comments

Comments
 (0)