Skip to content

Commit

Permalink
Merge pull request #986 from tailwarden/feature/tech-1640
Browse files Browse the repository at this point in the history
Display onboarding wizard if no cloud account was connected
  • Loading branch information
greghub authored Sep 27, 2023
2 parents 791ef40 + 0083e0c commit 5c7d07f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,37 @@ function useCloudAccount() {
const [cloudAccounts, setCloudAccounts] = useState<CloudAccount[]>([]);
const [cloudAccountItem, setCloudAccountItem] = useState<CloudAccount>();
const isNotCustomView = !router.query.view;
const [loading, setLoading] = useState(true);
const [error, setError] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const [hasError, setHasError] = useState(false);

useEffect(() => {
settingsService.getCloudAccounts().then(res => {
if (!loading) {
setLoading(true);
}
if (!isLoading) {
setIsLoading(true);
}

if (error) {
setError(false);
}
settingsService
.getOnboardingStatus()
.then(res => {
if (
res !== Error &&
res.onboarded === false &&
res.status === 'PENDING_DATABASE'
) {
router.push('/onboarding/choose-database');
} else {
router.push('/onboarding/choose-cloud');
}
})
.finally(() => setIsLoading(false));

settingsService.getCloudAccounts().then(res => {
if (res === Error) {
setLoading(false);
setError(true);
setHasError(true);
} else {
setLoading(false);
setCloudAccounts(res);
}

setIsLoading(false);
});
}, []);

Expand All @@ -67,11 +78,13 @@ function useCloudAccount() {
setCloudAccountItem,
goTo,
toast,
hasError,
setToast,
dismissToast,
cloudAccounts,
setCloudAccounts,
isNotCustomView
isNotCustomView,
isLoading
};
}

Expand Down
5 changes: 3 additions & 2 deletions dashboard/pages/cloud-accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function CloudAccounts() {
toast,
setToast,
dismissToast,
isNotCustomView
isNotCustomView,
isLoading
} = useCloudAccount();

useEffect(() => {
Expand Down Expand Up @@ -68,7 +69,7 @@ function CloudAccounts() {
setIsDeleteModalOpen(false);
};

if (!cloudAccounts) return null;
if (!cloudAccounts || isLoading) return null;

return (
<>
Expand Down
10 changes: 10 additions & 0 deletions dashboard/services/settingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,16 @@ const settingsService = {
} catch (error) {
return Error;
}
},

async getOnboardingStatus() {
try {
const res = await fetch(`${BASE_URL}/is_onboarded`, settings('GET'));
const data = await res.json();
return data;
} catch (error) {
return Error;
}
}
};

Expand Down

0 comments on commit 5c7d07f

Please sign in to comment.