Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clients/organisation: navigate to last visited organisation #4633

Merged

Conversation

magarpratik
Copy link
Contributor

@magarpratik magarpratik commented Dec 14, 2024

Closes #4619

This PR add functionality to remember last visited organization.

When an authenticated user visits the default home page, they will be redirected to the last visited organization's dashboard.

remember_last_visited_org.mov

Copy link

vercel bot commented Dec 14, 2024

@magarpratik is attempting to deploy a commit to the polar-sh Team on Vercel.

A member of the Team first needs to authorize it.

@frankie567
Copy link
Member

Thank you for this @magarpratik 👍 That's interesting, but I would have liked a server-side approach. Basically, the logic is handled on the following route:

export default async function Page() {
const api = getServerSideAPI()
const userOrganizations = await getUserOrganizations(api)
if (userOrganizations.length === 0) {
redirect('/purchases')
}
redirect(`/dashboard/${userOrganizations[0].slug}`)
}

Ideally, this would check for the existence of a cookie (instead of local storage) to directly redirect to the last organization at that point.

This cookie could be then be set client-side on the DashboardLayout component for example:

const DashboardLayout = (
props: PropsWithChildren<{
breadcrumb?: React.ReactNode
className?: string
}>,
) => {
const { organization } = useContext(MaintainerOrganizationContext)
return (
<DashboardProvider organization={organization}>
<div className="relative flex h-full w-full flex-col gap-x-8 bg-gray-100 md:flex-row md:p-6 dark:bg-transparent">
<MobileNav />
<div className="hidden md:flex">
<DashboardSidebar />
</div>
<div
className={twMerge(
'relative flex h-full w-full flex-col gap-y-4',
props.className,
)}
>
<DashboardTopbar breadcrumb={props.breadcrumb} />
{/* On large devices, scroll here. On small devices the _document_ is the only element that should scroll. */}
<main className="relative flex min-h-0 w-full flex-grow flex-col">
{props.children}
</main>
</div>
</div>
</DashboardProvider>
)
}

What do you think? :)

@magarpratik
Copy link
Contributor Author

magarpratik commented Dec 16, 2024

Hi @frankie567,

Thank you for the feedback. 🙌

It makes sense and it would probably be a bit more efficient too. I'll give it a go. 🫡

@magarpratik
Copy link
Contributor Author

Hi @frankie567, I've implemented your feedback.

PR is ready for re-review. 👍

Copy link
Member

@frankie567 frankie567 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just need to bump that cookie expiration and we'll be good to go!

clients/apps/web/src/utils/cookies.ts Outdated Show resolved Hide resolved
Copy link

vercel bot commented Dec 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
polar ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 18, 2024 8:46am
polar-sandbox 🛑 Canceled (Inspect) Dec 18, 2024 8:46am

@vercel vercel bot temporarily deployed to Preview – polar-sandbox December 18, 2024 08:32 Inactive
@frankie567 frankie567 merged commit 0c8788c into polarsource:main Dec 18, 2024
6 of 8 checks passed
@magarpratik magarpratik deleted the enhance/remember-last-visited-org branch December 18, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remember last organization when opening dashboard
2 participants