Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/(loading-group)/[organizationSlug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ const OrganizationHomePage: FunctionComponent = () => {
mutate();
};

useEffect(() => {
localStorage.setItem("lastActiveOrg", activeOrg.slug);
}, [activeOrg.slug]);

useEffect(() => {
// trigger a sync on page load - if the org has an external entity provider
if (activeOrg.externalEntityProviderId) {
Expand Down
34 changes: 25 additions & 9 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
"use client";

import { redirect } from "next/navigation";
import { useRouter } from "next/navigation";
import { useSession } from "../context/SessionContext";
import { useEffect } from "react";

const Index = () => {
// decide where to go based on if the user has any orgs
const { organizations } = useSession();
if (organizations.length > 0) {
// redirect to the first org
redirect(`/${organizations[0].slug}`);
} else {
// redirect to the onboarding page
redirect("/setup");
}
const router = useRouter();

useEffect(() => {
if (organizations.length > 0) {
const lastActiveOrg = localStorage.getItem("lastActiveOrg");
if (lastActiveOrg) {
const orgExists = organizations.some(
(org) => org.slug === lastActiveOrg,
);
if (orgExists) {
router.replace(`/${lastActiveOrg}`);
} else {
router.replace(`/${organizations[0].slug}`);
}
} else {
router.replace(`/${organizations[0].slug}`);
}
} else {
router.replace("/setup");
}
}, [organizations, router]);

return null;
};

export default Index;
Loading