export default function TeamSwitcher({ className }: TeamSwitcherProps) {
const ctx = api.useContext();
const { data: session } = useSession();
const { data: workspaces } = api.workspace.getAllForLoggedUser.useQuery(
undefined,
{
enabled: session?.user !== undefined,
}
);
const { mutateAsync } = api.user.switchActiveWorkspace.useMutation({
onSuccess: () => {
void ctx.workspace.getAllForLoggedUser.invalidate();
},
});
const [selectedWS, setSelectedWS] = React.useState<Workspace>({
id: session?.user?.activeWorkspaceId || "",
name:
workspaces?.find((w) => w.id === session?.user?.activeWorkspaceId)
?.name || "", //This was supposed to be working 🥲
});
return (
{/*tsx Code.
At some point there is a mapping of the workspaces array and on each item there is a onSelect like this
onSelect={() => {
setSelectedWS({
id: ws.id,
name: ws.name,
});
setOpen(false);
void mutateAsync({ workspaceId: ws.id });
}}
*/}
)
}
export default function TeamSwitcher({ className }: TeamSwitcherProps) {
const ctx = api.useContext();
const { data: session } = useSession();
const { data: workspaces } = api.workspace.getAllForLoggedUser.useQuery(
undefined,
{
enabled: session?.user !== undefined,
}
);
const { mutateAsync } = api.user.switchActiveWorkspace.useMutation({
onSuccess: () => {
void ctx.workspace.getAllForLoggedUser.invalidate();
},
});
const [selectedWS, setSelectedWS] = React.useState<Workspace>({
id: session?.user?.activeWorkspaceId || "",
name:
workspaces?.find((w) => w.id === session?.user?.activeWorkspaceId)
?.name || "", //This was supposed to be working 🥲
});
return (
{/*tsx Code.
At some point there is a mapping of the workspaces array and on each item there is a onSelect like this
onSelect={() => {
setSelectedWS({
id: ws.id,
name: ws.name,
});
setOpen(false);
void mutateAsync({ workspaceId: ws.id });
}}
*/}
)
}