mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: adapt to navbar version, move confirm action, add reload info
This commit is contained in:
@@ -13,22 +13,49 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
export const UpdateWebServer = () => {
|
interface Props {
|
||||||
|
isNavbar?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const UpdateWebServer = ({ isNavbar }: Props) => {
|
||||||
const { mutateAsync: updateServer, isLoading } =
|
const { mutateAsync: updateServer, isLoading } =
|
||||||
api.settings.updateServer.useMutation();
|
api.settings.updateServer.useMutation();
|
||||||
|
|
||||||
|
const buttonLabel = isNavbar ? "Update available" : "Update server";
|
||||||
|
|
||||||
|
const handleConfirm = async () => {
|
||||||
|
try {
|
||||||
|
await updateServer();
|
||||||
|
toast.success(
|
||||||
|
"The server has been updated. The page will be reloaded to reflect the changes...",
|
||||||
|
);
|
||||||
|
setTimeout(() => {
|
||||||
|
// Allow seeing the toast before reloading
|
||||||
|
window.location.reload();
|
||||||
|
}, 2000);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error updating server:", error);
|
||||||
|
toast.error(
|
||||||
|
"An error occurred while updating the server, please try again.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AlertDialog>
|
<AlertDialog>
|
||||||
<AlertDialogTrigger asChild>
|
<AlertDialogTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
className="relative w-full"
|
className="relative w-full"
|
||||||
variant="secondary"
|
variant={isNavbar ? "outline" : "secondary"}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
>
|
>
|
||||||
<span className="absolute -right-1 -top-2 flex h-3 w-3">
|
{!isLoading && (
|
||||||
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75" />
|
<span className="absolute -right-1 -top-2 flex h-3 w-3">
|
||||||
<span className="relative inline-flex rounded-full h-3 w-3 bg-green-500" />
|
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75" />
|
||||||
</span>
|
<span className="relative inline-flex rounded-full h-3 w-3 bg-green-500" />
|
||||||
Update Server
|
</span>
|
||||||
|
)}
|
||||||
|
{isLoading ? "Updating..." : buttonLabel}
|
||||||
</Button>
|
</Button>
|
||||||
</AlertDialogTrigger>
|
</AlertDialogTrigger>
|
||||||
<AlertDialogContent>
|
<AlertDialogContent>
|
||||||
@@ -36,19 +63,12 @@ export const UpdateWebServer = () => {
|
|||||||
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
|
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
|
||||||
<AlertDialogDescription>
|
<AlertDialogDescription>
|
||||||
This action cannot be undone. This will update the web server to the
|
This action cannot be undone. This will update the web server to the
|
||||||
new version.
|
new version. The page will be reloaded once the update is finished.
|
||||||
</AlertDialogDescription>
|
</AlertDialogDescription>
|
||||||
</AlertDialogHeader>
|
</AlertDialogHeader>
|
||||||
<AlertDialogFooter>
|
<AlertDialogFooter>
|
||||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||||
<AlertDialogAction
|
<AlertDialogAction onClick={handleConfirm}>Confirm</AlertDialogAction>
|
||||||
onClick={async () => {
|
|
||||||
await updateServer();
|
|
||||||
toast.success("Please reload the browser to see the changes");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Confirm
|
|
||||||
</AlertDialogAction>
|
|
||||||
</AlertDialogFooter>
|
</AlertDialogFooter>
|
||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
</AlertDialog>
|
</AlertDialog>
|
||||||
|
|||||||
Reference in New Issue
Block a user