mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-26 21:58:45 +00:00
Refactor Sidebar organization actions: streamline default organization setting and deletion logic, ensuring proper error handling and UI consistency.
This commit is contained in:
@@ -627,90 +627,93 @@ function SidebarLogo() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
{org.ownerId === session?.user?.id && (
|
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
className={cn(
|
className={cn(
|
||||||
"group",
|
"group",
|
||||||
isDefault
|
isDefault
|
||||||
? "hover:bg-yellow-500/10"
|
? "hover:bg-yellow-500/10"
|
||||||
: "hover:bg-blue-500/10",
|
: "hover:bg-blue-500/10",
|
||||||
)}
|
)}
|
||||||
isLoading={isSettingDefault && !isDefault}
|
isLoading={isSettingDefault && !isDefault}
|
||||||
disabled={isDefault}
|
disabled={isDefault}
|
||||||
onClick={async (e) => {
|
onClick={async (e) => {
|
||||||
if (isDefault) return;
|
if (isDefault) return;
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
await setDefaultOrganization({
|
await setDefaultOrganization({
|
||||||
organizationId: org.id,
|
organizationId: org.id,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
refetch();
|
||||||
|
toast.success("Default organization updated");
|
||||||
})
|
})
|
||||||
.then(() => {
|
.catch((error) => {
|
||||||
refetch();
|
toast.error(
|
||||||
toast.success("Default organization updated");
|
error?.message ||
|
||||||
|
"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 setting default organization",
|
"Organization deleted successfully",
|
||||||
);
|
);
|
||||||
});
|
})
|
||||||
}}
|
.catch((error) => {
|
||||||
title={
|
toast.error(
|
||||||
isDefault
|
error?.message ||
|
||||||
? "Default organization"
|
"Error deleting 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>
|
|
||||||
<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,
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
refetch();
|
|
||||||
toast.success(
|
|
||||||
"Organization deleted successfully",
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
toast.error(
|
|
||||||
error?.message ||
|
|
||||||
"Error deleting organization",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
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"
|
||||||
</div>
|
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>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
Reference in New Issue
Block a user