mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-17 09:25:20 +00:00
refactor(sidebar): streamline organization dropdown menu interactions
- Simplified the organization selection process by enhancing the dropdown menu structure. - Improved the layout for better visibility and usability, ensuring a smoother user experience when setting default organizations and deleting them. - Added error handling for organization actions to provide user feedback on success or failure.
This commit is contained in:
@@ -640,126 +640,126 @@ function SidebarLogo() {
|
|||||||
</DropdownMenuLabel>
|
</DropdownMenuLabel>
|
||||||
<div className="overflow-y-auto overflow-x-hidden min-h-0 -mx-1 px-1">
|
<div className="overflow-y-auto overflow-x-hidden min-h-0 -mx-1 px-1">
|
||||||
{organizations?.map((org) => {
|
{organizations?.map((org) => {
|
||||||
const isDefault = org.members?.[0]?.isDefault ?? false;
|
const isDefault = org.members?.[0]?.isDefault ?? false;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="flex flex-row justify-between"
|
className="flex flex-row justify-between"
|
||||||
key={org.name}
|
key={org.name}
|
||||||
>
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={async () => {
|
|
||||||
await authClient.organization.setActive({
|
|
||||||
organizationId: org.id,
|
|
||||||
});
|
|
||||||
window.location.reload();
|
|
||||||
}}
|
|
||||||
className="w-full gap-2 p-2"
|
|
||||||
>
|
>
|
||||||
<div className="flex flex-col gap-1">
|
<DropdownMenuItem
|
||||||
<div className="flex items-center gap-2">
|
onClick={async () => {
|
||||||
{org.name}
|
await authClient.organization.setActive({
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="flex size-6 items-center justify-center rounded-sm border">
|
|
||||||
<Logo
|
|
||||||
className={cn(
|
|
||||||
"transition-all",
|
|
||||||
state === "collapsed" ? "size-6" : "size-10",
|
|
||||||
)}
|
|
||||||
logoUrl={org.logo ?? undefined}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
className={cn(
|
|
||||||
"group",
|
|
||||||
isDefault
|
|
||||||
? "hover:bg-yellow-500/10"
|
|
||||||
: "hover:bg-blue-500/10",
|
|
||||||
)}
|
|
||||||
isLoading={isSettingDefault && !isDefault}
|
|
||||||
disabled={isDefault}
|
|
||||||
onClick={async (e) => {
|
|
||||||
if (isDefault) return;
|
|
||||||
e.stopPropagation();
|
|
||||||
await setDefaultOrganization({
|
|
||||||
organizationId: org.id,
|
organizationId: org.id,
|
||||||
})
|
});
|
||||||
.then(() => {
|
window.location.reload();
|
||||||
refetch();
|
|
||||||
toast.success("Default organization updated");
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
toast.error(
|
|
||||||
error?.message ||
|
|
||||||
"Error setting default organization",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
title={
|
className="w-full gap-2 p-2"
|
||||||
isDefault
|
|
||||||
? "Default organization"
|
|
||||||
: "Set as default"
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{isDefault ? (
|
<div className="flex flex-col gap-1">
|
||||||
<Star
|
<div className="flex items-center gap-2">
|
||||||
fill="#eab308"
|
{org.name}
|
||||||
stroke="#eab308"
|
</div>
|
||||||
className="size-4 text-yellow-500"
|
</div>
|
||||||
|
<div className="flex size-6 items-center justify-center rounded-sm border">
|
||||||
|
<Logo
|
||||||
|
className={cn(
|
||||||
|
"transition-all",
|
||||||
|
state === "collapsed" ? "size-6" : "size-10",
|
||||||
|
)}
|
||||||
|
logoUrl={org.logo ?? undefined}
|
||||||
/>
|
/>
|
||||||
) : (
|
</div>
|
||||||
<Star
|
</DropdownMenuItem>
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
<div className="flex items-center gap-2">
|
||||||
className="size-4 text-gray-400 group-hover:text-blue-500 transition-colors"
|
<Button
|
||||||
/>
|
variant="ghost"
|
||||||
)}
|
size="icon"
|
||||||
</Button>
|
className={cn(
|
||||||
{org.ownerId === session?.user?.id && (
|
"group",
|
||||||
<>
|
isDefault
|
||||||
<AddOrganization organizationId={org.id} />
|
? "hover:bg-yellow-500/10"
|
||||||
<DialogAction
|
: "hover:bg-blue-500/10",
|
||||||
title="Delete Organization"
|
)}
|
||||||
description="Are you sure you want to delete this organization?"
|
isLoading={isSettingDefault && !isDefault}
|
||||||
type="destructive"
|
disabled={isDefault}
|
||||||
onClick={async () => {
|
onClick={async (e) => {
|
||||||
await deleteOrganization({
|
if (isDefault) return;
|
||||||
organizationId: org.id,
|
e.stopPropagation();
|
||||||
|
await setDefaultOrganization({
|
||||||
|
organizationId: org.id,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
refetch();
|
||||||
|
toast.success("Default organization updated");
|
||||||
})
|
})
|
||||||
.then(() => {
|
.catch((error) => {
|
||||||
refetch();
|
toast.error(
|
||||||
toast.success(
|
error?.message ||
|
||||||
"Organization deleted successfully",
|
"Error setting default organization",
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
title={
|
||||||
|
isDefault
|
||||||
|
? "Default organization"
|
||||||
|
: "Set as default"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{isDefault ? (
|
||||||
|
<Star
|
||||||
|
fill="#eab308"
|
||||||
|
stroke="#eab308"
|
||||||
|
className="size-4 text-yellow-500"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Star
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
className="size-4 text-gray-400 group-hover:text-blue-500 transition-colors"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
{org.ownerId === session?.user?.id && (
|
||||||
|
<>
|
||||||
|
<AddOrganization organizationId={org.id} />
|
||||||
|
<DialogAction
|
||||||
|
title="Delete Organization"
|
||||||
|
description="Are you sure you want to delete this organization?"
|
||||||
|
type="destructive"
|
||||||
|
onClick={async () => {
|
||||||
|
await deleteOrganization({
|
||||||
|
organizationId: org.id,
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.then(() => {
|
||||||
toast.error(
|
refetch();
|
||||||
error?.message ||
|
toast.success(
|
||||||
"Error deleting organization",
|
"Organization deleted successfully",
|
||||||
);
|
);
|
||||||
});
|
})
|
||||||
}}
|
.catch((error) => {
|
||||||
>
|
toast.error(
|
||||||
<Button
|
error?.message ||
|
||||||
variant="ghost"
|
"Error deleting organization",
|
||||||
size="icon"
|
);
|
||||||
className="group hover:bg-red-500/10"
|
});
|
||||||
isLoading={isRemoving}
|
}}
|
||||||
>
|
>
|
||||||
<Trash2 className="size-4 text-primary group-hover:text-red-500" />
|
<Button
|
||||||
</Button>
|
variant="ghost"
|
||||||
</DialogAction>
|
size="icon"
|
||||||
</>
|
className="group hover:bg-red-500/10"
|
||||||
)}
|
isLoading={isRemoving}
|
||||||
|
>
|
||||||
|
<Trash2 className="size-4 text-primary group-hover:text-red-500" />
|
||||||
|
</Button>
|
||||||
|
</DialogAction>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
);
|
})}
|
||||||
})}
|
|
||||||
</div>
|
</div>
|
||||||
{(user?.role === "owner" ||
|
{(user?.role === "owner" ||
|
||||||
user?.role === "admin" ||
|
user?.role === "admin" ||
|
||||||
|
|||||||
Reference in New Issue
Block a user