{value.map((s) => {
- const detailPath = `/sources/${s.id}`;
+ const detailPath = `/${orgHandle}/sources/${s.id}`;
const active =
props.pathname === detailPath || props.pathname.startsWith(`${detailPath}/`);
return (
{
- if (organizationId === props.activeOrganizationId) return;
- const exit = await doSwitchOrganization({
- payload: { organizationId },
- reactivityKeys: authWriteKeys,
- });
- if (Exit.isSuccess(exit)) window.location.reload();
- };
+ const auth = useAuth();
- return AsyncResult.match(organizations, {
- onInitial: () =>
Loading…,
- onFailure: () =>
Failed to load organizations,
- onSuccess: ({ value }) =>
- value.organizations.length === 0 ? (
-
No organizations
- ) : (
- <>
- {value.organizations.map((organization: { id: string; name: string }) => {
- const isActive = organization.id === props.activeOrganizationId;
- return (
-
handleSwitch(organization.id)}
- className="text-xs"
- >
- {organization.name}
- {isActive && }
-
- );
- })}
- >
- ),
- });
+ if (auth.status !== "authenticated") {
+ return
Loading…;
+ }
+ if (auth.organizations.length === 0) {
+ return
No organizations;
+ }
+ return (
+ <>
+ {auth.organizations.map((organization) => {
+ const isActive = organization.id === props.activeOrganizationId;
+ return (
+
+
+ {organization.name}
+ {isActive && }
+
+
+ );
+ })}
+ >
+ );
}
function CheckIcon() {
@@ -203,6 +251,7 @@ function CheckIcon() {
function UserFooter() {
const auth = useAuth();
+ const orgRoute = useOrgRoute();
const [createOrganizationOpen, setCreateOrganizationOpen] = useState(false);
const suggestedOrganizationName =
@@ -212,7 +261,15 @@ function UserFooter() {
const form = useCreateOrganizationForm({
defaultName: suggestedOrganizationName,
- onSuccess: () => window.location.reload(),
+ // The form returns the new org's handle on success — navigate via the URL
+ // by reloading at the new handle. Once we wire useNavigate in here we can
+ // do a soft navigation instead.
+ onSuccess: (org) => {
+ // Navigate to the new org's URL — the URL is the source of truth for
+ // active org now, so a hard reload at the new handle re-renders the
+ // shell with the right context.
+ window.location.href = `/${org.handle}`;
+ },
});
if (auth.status !== "authenticated") return null;
@@ -243,9 +300,7 @@ function UserFooter() {
{auth.user.name ?? auth.user.email}
- {auth.organization && (
-
{auth.organization.name}
- )}
+
{orgRoute.orgName}