Skip to content

Commit 04c0ba8

Browse files
drew-harrisskeptrunedev
authored andcommitted
feat: save orgid in query params on dashboard
1 parent 11ce08d commit 04c0ba8

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

frontends/dashboard/src/contexts/UserContext.tsx

+14-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
createMemo,
99
createResource,
1010
createSignal,
11+
on,
1112
} from "solid-js";
1213
import { createToast } from "../components/ShowToasts";
1314
import { redirect, useSearchParams } from "@solidjs/router";
@@ -55,7 +56,7 @@ export const UserContextWrapper = (props: UserStoreContextProps) => {
5556
const apiHost = import.meta.env.VITE_API_HOST as string;
5657

5758
const trieve = useTrieve();
58-
const [searchParams] = useSearchParams();
59+
const [searchParams, setSearchParams] = useSearchParams();
5960

6061
const [user, setUser] = createSignal<SlimUser | null>(null);
6162
const [isNewUser, setIsNewUser] = createSignal(false);
@@ -103,9 +104,11 @@ export const UserContextWrapper = (props: UserStoreContextProps) => {
103104
window.localStorage.setItem("trieve:user", JSON.stringify(data));
104105

105106
// Grab org id from localstorage
106-
const possibleOrgId = window.localStorage.getItem(
107-
`${data.id}:selectedOrg`,
108-
);
107+
let possibleOrgId = window.localStorage.getItem(`${data.id}:selectedOrg`);
108+
if (searchParams["org"]) {
109+
possibleOrgId = searchParams["org"];
110+
}
111+
109112
if (possibleOrgId) {
110113
const matchingOrg = data.orgs.find((org) => org.id === possibleOrgId);
111114
if (matchingOrg) {
@@ -162,6 +165,13 @@ export const UserContextWrapper = (props: UserStoreContextProps) => {
162165
}
163166
};
164167

168+
// Set the orgid in the query params
169+
createEffect(
170+
on(selectedOrgId, (orgId) => {
171+
setSearchParams({ ...searchParams, org: orgId });
172+
}),
173+
);
174+
165175
const setSelectedOrg = (orgId: string) => {
166176
localStorage.setItem(`${user()?.id}:selectedOrg`, orgId);
167177
const org = user()?.orgs.find((org) => org.id === orgId);
@@ -211,9 +221,6 @@ export const UserContextWrapper = (props: UserStoreContextProps) => {
211221
}}
212222
>
213223
{props.children}
214-
<Show when={isNewUser()}>
215-
<div>New user!!</div>
216-
</Show>
217224
</UserContext.Provider>
218225
)}
219226
</Show>

0 commit comments

Comments
 (0)