// workspaceId is passed in from my page layout.tsx file (it is obtained through the URL search params, eg: /dashboard/workspaceId/home
export const WorkspaceSelector = ({ workspaceId }: Props) => {
const { data: workspaces } = api.workspace.list.useQuery();
const {selectedWorkspace, setSelectedWorkspace} = selectedWorkspaceStore();
useEffect(() => {
const workspace = workspaces?.find((workspace) => workspace.id === workspaceId);
if (!workspace) return;
setSelectedWorkspace(workspace); // store the current selected workspace in zustand
}, [workspaceId, workspaces]);
// workspaceId is passed in from my page layout.tsx file (it is obtained through the URL search params, eg: /dashboard/workspaceId/home
export const WorkspaceSelector = ({ workspaceId }: Props) => {
const { data: workspaces } = api.workspace.list.useQuery();
const {selectedWorkspace, setSelectedWorkspace} = selectedWorkspaceStore();
useEffect(() => {
const workspace = workspaces?.find((workspace) => workspace.id === workspaceId);
if (!workspace) return;
setSelectedWorkspace(workspace); // store the current selected workspace in zustand
}, [workspaceId, workspaces]);