Skip to content

Commit 715b9bd

Browse files
committed
refactor: clean up organization selector
1 parent e3d8604 commit 715b9bd

File tree

5 files changed

+58
-72
lines changed

5 files changed

+58
-72
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
"source.fixAll.biome": "explicit",
1616
"source.organizeImports.biome": "explicit"
1717
},
18-
"typescript.experimental.useTsgo": false
18+
"typescript.experimental.useTsgo": true
1919
}

apps/dashboard/components/layout/organization-selector.tsx

Lines changed: 27 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
'use client';
22

3+
import { authClient } from '@databuddy/auth/client';
34
import {
45
CaretDownIcon,
56
CheckIcon,
67
PlusIcon,
78
SpinnerGapIcon,
89
UserIcon,
910
} from '@phosphor-icons/react';
10-
import { useCallback, useState } from 'react';
11+
import { useState } from 'react';
12+
import { toast } from 'sonner';
1113
import { CreateOrganizationDialog } from '@/components/organizations/create-organization-dialog';
1214
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
1315
import { Button } from '@/components/ui/button';
@@ -19,7 +21,6 @@ import {
1921
DropdownMenuTrigger,
2022
} from '@/components/ui/dropdown-menu';
2123
import { Skeleton } from '@/components/ui/skeleton';
22-
import { useOrganizations } from '@/hooks/use-organizations';
2324
import { cn } from '@/lib/utils';
2425

2526
const getOrganizationInitials = (name: string) => {
@@ -125,55 +126,39 @@ function OrganizationSelectorTrigger({
125126
}
126127

127128
export function OrganizationSelector() {
128-
const {
129-
organizations,
130-
activeOrganization,
131-
isLoading,
132-
setActiveOrganization,
133-
isSettingActiveOrganization,
134-
hasError,
135-
activeOrganizationError,
136-
} = useOrganizations();
129+
const { data: organizations, isPending: isLoadingOrgs } = authClient.useListOrganizations();
130+
const { data: activeOrganization, isPending: isLoadingActive } = authClient.useActiveOrganization();
137131
const [isOpen, setIsOpen] = useState(false);
138132
const [showCreateDialog, setShowCreateDialog] = useState(false);
139133
const [query, setQuery] = useState('');
134+
const [isSwitching, setIsSwitching] = useState(false);
140135

141-
const [hasHandledMissingOrg, setHasHandledMissingOrg] = useState(false);
136+
const isLoading = isLoadingOrgs || isLoadingActive;
142137

143-
const isActiveOrgNotFound =
144-
activeOrganizationError?.message?.includes('ORGANIZATION_NOT_FOUND') ||
145-
activeOrganizationError?.message?.includes('Organization not found');
138+
const handleSelectOrganization = async (organizationId: string | null) => {
139+
if (organizationId === activeOrganization?.id) return;
140+
if (organizationId === null && !activeOrganization) return;
146141

147-
if (
148-
isActiveOrgNotFound &&
149-
!hasHandledMissingOrg &&
150-
!isSettingActiveOrganization
151-
) {
152-
setHasHandledMissingOrg(true);
153-
// Clear the active organization to fall back to personal workspace
154-
setActiveOrganization(null);
155-
}
142+
setIsSwitching(true);
143+
setIsOpen(false);
156144

157-
const handleSelectOrganization = useCallback(
158-
(organizationId: string | null) => {
159-
if (organizationId === activeOrganization?.id) {
160-
return;
161-
}
162-
if (organizationId === null && !activeOrganization) {
163-
return;
164-
}
165-
setActiveOrganization(organizationId);
166-
setIsOpen(false);
167-
},
168-
[activeOrganization, setActiveOrganization]
169-
);
145+
const { error } = await authClient.organization.setActive({ organizationId });
146+
147+
if (error) {
148+
toast.error(error.message || 'Failed to switch workspace');
149+
} else {
150+
toast.success('Workspace updated');
151+
}
152+
153+
setIsSwitching(false);
154+
};
170155

171-
const handleCreateOrganization = useCallback(() => {
156+
const handleCreateOrganization = () => {
172157
setShowCreateDialog(true);
173158
setIsOpen(false);
174-
}, []);
159+
};
175160

176-
const filteredOrganizations = filterOrganizations(organizations, query);
161+
const filteredOrganizations = filterOrganizations(organizations || [], query);
177162

178163
if (isLoading) {
179164
return (
@@ -194,22 +179,6 @@ export function OrganizationSelector() {
194179
);
195180
}
196181

197-
if (hasError && !isActiveOrgNotFound) {
198-
return (
199-
<div className="border-sidebar-border border-b bg-destructive/10 px-3 py-3">
200-
<div className="flex items-center gap-3">
201-
<div className="rounded bg-sidebar/80 p-1.5 shadow-sm ring-1 ring-destructive/50">
202-
<UserIcon className="h-5 w-5 text-destructive" weight="duotone" />
203-
</div>
204-
<div className="min-w-0 flex-1">
205-
<span className="font-semibold text-destructive text-sm">
206-
Failed to load workspaces
207-
</span>
208-
</div>
209-
</div>
210-
</div>
211-
);
212-
}
213182

214183
return (
215184
<>
@@ -227,14 +196,14 @@ export function OrganizationSelector() {
227196
aria-expanded={isOpen}
228197
aria-haspopup="listbox"
229198
className="h-auto w-full rounded-none p-0 hover:bg-transparent"
230-
disabled={isSettingActiveOrganization}
199+
disabled={isSwitching}
231200
type="button"
232201
variant="ghost"
233202
>
234203
<OrganizationSelectorTrigger
235204
activeOrganization={activeOrganization}
236205
isOpen={isOpen}
237-
isSettingActiveOrganization={isSettingActiveOrganization}
206+
isSettingActiveOrganization={isSwitching}
238207
/>
239208
</Button>
240209
</DropdownMenuTrigger>

apps/docs/next.config.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ const config = {
4949
];
5050
},
5151

52-
// biome-ignore lint/suspicious/useAwait: "redirects is async"
5352
async redirects() {
5453
return [
5554
{
@@ -98,7 +97,7 @@ const config = {
9897
},
9998
],
10099
formats: ['image/webp', 'image/avif'],
101-
minimumCacheTTL: 60 * 60 * 24 * 30, // 30 days
100+
minimumCacheTTL: 60 * 60 * 24 * 30
102101
},
103102

104103
experimental: {

bun.lock

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"": {
55
"name": "databuddy",
66
"devDependencies": {
7-
"@biomejs/biome": "2.1.2",
7+
"@biomejs/biome": "2.2.5",
88
"@types/bun": "latest",
99
"@typescript/native-preview": "^7.0.0-dev.20250921.1",
1010
"dotenv-cli": "^10.0.0",
@@ -498,23 +498,23 @@
498498

499499
"@better-fetch/fetch": ["@better-fetch/[email protected]", "", {}, "sha512-rEFOE1MYIsBmoMJtQbl32PGHHXuG2hDxvEd7rUHE0vCBoFQVSDqaVs9hkZEtHCxRoY+CljXKFCOuJ8uxqw1LcA=="],
500500

501-
"@biomejs/biome": ["@biomejs/biome@2.1.2", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.1.2", "@biomejs/cli-darwin-x64": "2.1.2", "@biomejs/cli-linux-arm64": "2.1.2", "@biomejs/cli-linux-arm64-musl": "2.1.2", "@biomejs/cli-linux-x64": "2.1.2", "@biomejs/cli-linux-x64-musl": "2.1.2", "@biomejs/cli-win32-arm64": "2.1.2", "@biomejs/cli-win32-x64": "2.1.2" }, "bin": { "biome": "bin/biome" } }, "sha512-yq8ZZuKuBVDgAS76LWCfFKHSYIAgqkxVB3mGVVpOe2vSkUTs7xG46zXZeNPRNVjiJuw0SZ3+J2rXiYx0RUpfGg=="],
501+
"@biomejs/biome": ["@biomejs/biome@2.2.5", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.2.5", "@biomejs/cli-darwin-x64": "2.2.5", "@biomejs/cli-linux-arm64": "2.2.5", "@biomejs/cli-linux-arm64-musl": "2.2.5", "@biomejs/cli-linux-x64": "2.2.5", "@biomejs/cli-linux-x64-musl": "2.2.5", "@biomejs/cli-win32-arm64": "2.2.5", "@biomejs/cli-win32-x64": "2.2.5" }, "bin": { "biome": "bin/biome" } }, "sha512-zcIi+163Rc3HtyHbEO7CjeHq8DjQRs40HsGbW6vx2WI0tg8mYQOPouhvHSyEnCBAorfYNnKdR64/IxO7xQ5faw=="],
502502

503-
"@biomejs/cli-darwin-arm64": ["@biomejs/cli-darwin-arm64@2.1.2", "", { "os": "darwin", "cpu": "arm64" }, "sha512-leFAks64PEIjc7MY/cLjE8u5OcfBKkcDB0szxsWUB4aDfemBep1WVKt0qrEyqZBOW8LPHzrFMyDl3FhuuA0E7g=="],
503+
"@biomejs/cli-darwin-arm64": ["@biomejs/cli-darwin-arm64@2.2.5", "", { "os": "darwin", "cpu": "arm64" }, "sha512-MYT+nZ38wEIWVcL5xLyOhYQQ7nlWD0b/4mgATW2c8dvq7R4OQjt/XGXFkXrmtWmQofaIM14L7V8qIz/M+bx5QQ=="],
504504

505-
"@biomejs/cli-darwin-x64": ["@biomejs/cli-darwin-x64@2.1.2", "", { "os": "darwin", "cpu": "x64" }, "sha512-Nmmv7wRX5Nj7lGmz0FjnWdflJg4zii8Ivruas6PBKzw5SJX/q+Zh2RfnO+bBnuKLXpj8kiI2x2X12otpH6a32A=="],
505+
"@biomejs/cli-darwin-x64": ["@biomejs/cli-darwin-x64@2.2.5", "", { "os": "darwin", "cpu": "x64" }, "sha512-FLIEl73fv0R7dI10EnEiZLw+IMz3mWLnF95ASDI0kbx6DDLJjWxE5JxxBfmG+udz1hIDd3fr5wsuP7nwuTRdAg=="],
506506

507-
"@biomejs/cli-linux-arm64": ["@biomejs/cli-linux-arm64@2.1.2", "", { "os": "linux", "cpu": "arm64" }, "sha512-NWNy2Diocav61HZiv2enTQykbPP/KrA/baS7JsLSojC7Xxh2nl9IczuvE5UID7+ksRy2e7yH7klm/WkA72G1dw=="],
507+
"@biomejs/cli-linux-arm64": ["@biomejs/cli-linux-arm64@2.2.5", "", { "os": "linux", "cpu": "arm64" }, "sha512-5DjiiDfHqGgR2MS9D+AZ8kOfrzTGqLKywn8hoXpXXlJXIECGQ32t+gt/uiS2XyGBM2XQhR6ztUvbjZWeccFMoQ=="],
508508

509-
"@biomejs/cli-linux-arm64-musl": ["@biomejs/cli-linux-arm64-musl@2.1.2", "", { "os": "linux", "cpu": "arm64" }, "sha512-qgHvafhjH7Oca114FdOScmIKf1DlXT1LqbOrrbR30kQDLFPEOpBG0uzx6MhmsrmhGiCFCr2obDamu+czk+X0HQ=="],
509+
"@biomejs/cli-linux-arm64-musl": ["@biomejs/cli-linux-arm64-musl@2.2.5", "", { "os": "linux", "cpu": "arm64" }, "sha512-5Ov2wgAFwqDvQiESnu7b9ufD1faRa+40uwrohgBopeY84El2TnBDoMNXx6iuQdreoFGjwW8vH6k68G21EpNERw=="],
510510

511-
"@biomejs/cli-linux-x64": ["@biomejs/cli-linux-x64@2.1.2", "", { "os": "linux", "cpu": "x64" }, "sha512-Km/UYeVowygTjpX6sGBzlizjakLoMQkxWbruVZSNE6osuSI63i4uCeIL+6q2AJlD3dxoiBJX70dn1enjQnQqwA=="],
511+
"@biomejs/cli-linux-x64": ["@biomejs/cli-linux-x64@2.2.5", "", { "os": "linux", "cpu": "x64" }, "sha512-fq9meKm1AEXeAWan3uCg6XSP5ObA6F/Ovm89TwaMiy1DNIwdgxPkNwxlXJX8iM6oRbFysYeGnT0OG8diCWb9ew=="],
512512

513-
"@biomejs/cli-linux-x64-musl": ["@biomejs/cli-linux-x64-musl@2.1.2", "", { "os": "linux", "cpu": "x64" }, "sha512-xlB3mU14ZUa3wzLtXfmk2IMOGL+S0aHFhSix/nssWS/2XlD27q+S6f0dlQ8WOCbYoXcuz8BCM7rCn2lxdTrlQA=="],
513+
"@biomejs/cli-linux-x64-musl": ["@biomejs/cli-linux-x64-musl@2.2.5", "", { "os": "linux", "cpu": "x64" }, "sha512-AVqLCDb/6K7aPNIcxHaTQj01sl1m989CJIQFQEaiQkGr2EQwyOpaATJ473h+nXDUuAcREhccfRpe/tu+0wu0eQ=="],
514514

515-
"@biomejs/cli-win32-arm64": ["@biomejs/cli-win32-arm64@2.1.2", "", { "os": "win32", "cpu": "arm64" }, "sha512-G8KWZli5ASOXA3yUQgx+M4pZRv3ND16h77UsdunUL17uYpcL/UC7RkWTdkfvMQvogVsAuz5JUcBDjgZHXxlKoA=="],
515+
"@biomejs/cli-win32-arm64": ["@biomejs/cli-win32-arm64@2.2.5", "", { "os": "win32", "cpu": "arm64" }, "sha512-xaOIad4wBambwJa6mdp1FigYSIF9i7PCqRbvBqtIi9y29QtPVQ13sDGtUnsRoe6SjL10auMzQ6YAe+B3RpZXVg=="],
516516

517-
"@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@2.1.2", "", { "os": "win32", "cpu": "x64" }, "sha512-9zajnk59PMpjBkty3bK2IrjUsUHvqe9HWwyAWQBjGLE7MIBjbX2vwv1XPEhmO2RRuGoTkVx3WCanHrjAytICLA=="],
517+
"@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@2.2.5", "", { "os": "win32", "cpu": "x64" }, "sha512-F/jhuXCssPFAuciMhHKk00xnCAxJRS/pUzVfXYmOMUp//XW7mO6QeCjsjvnm8L4AO/dG2VOB0O+fJPiJ2uXtIw=="],
518518

519519
"@borewit/text-codec": ["@borewit/[email protected]", "", {}, "sha512-5L/uBxmjaCIX5h8Z+uu+kA9BQLkc/Wl06UGR5ajNRxu+/XjonB5i8JpgFMrPj3LXTCPA0pv8yxUvbUi+QthGGA=="],
520520

@@ -3060,6 +3060,8 @@
30603060

30613061
"@databuddy/dashboard/ultracite": ["[email protected]", "", { "dependencies": { "@clack/prompts": "^0.11.0", "deepmerge": "^4.3.1", "jsonc-parser": "^3.3.1", "nypm": "^0.6.1", "trpc-cli": "^0.10.2", "vitest": "^3.2.4", "zod": "^4.1.5" }, "bin": { "ultracite": "dist/index.js" } }, "sha512-N8n4O2rxv8IA9iX/xb2MBNCjgLQBHMiwMg8YJEzCn+vzRI0Z33ZRAFurZfbP/SDwE/5N0wRYgZHzBt/xczaomg=="],
30623062

3063+
"@databuddy/docs/@biomejs/biome": ["@biomejs/[email protected]", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.1.2", "@biomejs/cli-darwin-x64": "2.1.2", "@biomejs/cli-linux-arm64": "2.1.2", "@biomejs/cli-linux-arm64-musl": "2.1.2", "@biomejs/cli-linux-x64": "2.1.2", "@biomejs/cli-linux-x64-musl": "2.1.2", "@biomejs/cli-win32-arm64": "2.1.2", "@biomejs/cli-win32-x64": "2.1.2" }, "bin": { "biome": "bin/biome" } }, "sha512-yq8ZZuKuBVDgAS76LWCfFKHSYIAgqkxVB3mGVVpOe2vSkUTs7xG46zXZeNPRNVjiJuw0SZ3+J2rXiYx0RUpfGg=="],
3064+
30633065
"@databuddy/docs/@databuddy/sdk": ["@databuddy/[email protected]", "", {}, "sha512-WhfjUcfmKQrl1qSmFTfwd/suvN02O/SIpJSEJda+f9zJYzRNCiYx6oPOgGuzmB0fdYEtNM/GQxfblN+7AaaNGw=="],
30643066

30653067
"@databuddy/docs/@hookform/resolvers": ["@hookform/[email protected]", "", { "dependencies": { "@standard-schema/utils": "^0.3.0" }, "peerDependencies": { "react-hook-form": "^7.55.0" } }, "sha512-A/IxlMLShx3KjV/HeTcTfaMxdwy690+L/ZADoeaTltLx+CVuzkeVIPuybK3jrRfw7YZnmdKsVVHAlEPIAEUNlA=="],
@@ -3336,6 +3338,22 @@
33363338

33373339
"@databuddy/dashboard/autumn-js/zod": ["[email protected]", "", {}, "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ=="],
33383340

3341+
"@databuddy/docs/@biomejs/biome/@biomejs/cli-darwin-arm64": ["@biomejs/[email protected]", "", { "os": "darwin", "cpu": "arm64" }, "sha512-leFAks64PEIjc7MY/cLjE8u5OcfBKkcDB0szxsWUB4aDfemBep1WVKt0qrEyqZBOW8LPHzrFMyDl3FhuuA0E7g=="],
3342+
3343+
"@databuddy/docs/@biomejs/biome/@biomejs/cli-darwin-x64": ["@biomejs/[email protected]", "", { "os": "darwin", "cpu": "x64" }, "sha512-Nmmv7wRX5Nj7lGmz0FjnWdflJg4zii8Ivruas6PBKzw5SJX/q+Zh2RfnO+bBnuKLXpj8kiI2x2X12otpH6a32A=="],
3344+
3345+
"@databuddy/docs/@biomejs/biome/@biomejs/cli-linux-arm64": ["@biomejs/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-NWNy2Diocav61HZiv2enTQykbPP/KrA/baS7JsLSojC7Xxh2nl9IczuvE5UID7+ksRy2e7yH7klm/WkA72G1dw=="],
3346+
3347+
"@databuddy/docs/@biomejs/biome/@biomejs/cli-linux-arm64-musl": ["@biomejs/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-qgHvafhjH7Oca114FdOScmIKf1DlXT1LqbOrrbR30kQDLFPEOpBG0uzx6MhmsrmhGiCFCr2obDamu+czk+X0HQ=="],
3348+
3349+
"@databuddy/docs/@biomejs/biome/@biomejs/cli-linux-x64": ["@biomejs/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-Km/UYeVowygTjpX6sGBzlizjakLoMQkxWbruVZSNE6osuSI63i4uCeIL+6q2AJlD3dxoiBJX70dn1enjQnQqwA=="],
3350+
3351+
"@databuddy/docs/@biomejs/biome/@biomejs/cli-linux-x64-musl": ["@biomejs/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-xlB3mU14ZUa3wzLtXfmk2IMOGL+S0aHFhSix/nssWS/2XlD27q+S6f0dlQ8WOCbYoXcuz8BCM7rCn2lxdTrlQA=="],
3352+
3353+
"@databuddy/docs/@biomejs/biome/@biomejs/cli-win32-arm64": ["@biomejs/[email protected]", "", { "os": "win32", "cpu": "arm64" }, "sha512-G8KWZli5ASOXA3yUQgx+M4pZRv3ND16h77UsdunUL17uYpcL/UC7RkWTdkfvMQvogVsAuz5JUcBDjgZHXxlKoA=="],
3354+
3355+
"@databuddy/docs/@biomejs/biome/@biomejs/cli-win32-x64": ["@biomejs/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-9zajnk59PMpjBkty3bK2IrjUsUHvqe9HWwyAWQBjGLE7MIBjbX2vwv1XPEhmO2RRuGoTkVx3WCanHrjAytICLA=="],
3356+
33393357
"@databuddy/email/@types/node/undici-types": ["[email protected]", "", {}, "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag=="],
33403358

33413359
"@databuddy/email/react-dom/scheduler": ["[email protected]", "", {}, "sha512-NlHwttCI/l5gCPR3D1nNXtWABUmBwvZpEQiD4IXSbIDq8BzLIK/7Ir5gTFSGZDUu37K5cMNp0hFtzO38sC7gWA=="],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"dashboard:dev": "dotenv -- cd apps/dashboard; bun run dev"
2121
},
2222
"devDependencies": {
23-
"@biomejs/biome": "2.1.2",
23+
"@biomejs/biome": "2.2.5",
2424
"@types/bun": "latest",
2525
"@typescript/native-preview": "^7.0.0-dev.20250921.1",
2626
"dotenv-cli": "^10.0.0",

0 commit comments

Comments
 (0)