mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: move check updates function, use new api
This commit is contained in:
@@ -20,10 +20,28 @@ export const UpdateServer = () => {
|
|||||||
const [isUpdateAvailable, setIsUpdateAvailable] = useState<null | boolean>(
|
const [isUpdateAvailable, setIsUpdateAvailable] = useState<null | boolean>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
const { mutateAsync: checkServerUpdates, isLoading } =
|
const { mutateAsync: checkForUpdate, isLoading } =
|
||||||
api.settings.checkServerUpdates.useMutation();
|
api.settings.checkForUpdate.useMutation();
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
|
||||||
|
const handleCheckUpdates = async () => {
|
||||||
|
try {
|
||||||
|
const updateAvailable = await checkForUpdate();
|
||||||
|
setIsUpdateAvailable(updateAvailable);
|
||||||
|
if (updateAvailable) {
|
||||||
|
toast.success("Update is available!");
|
||||||
|
} else {
|
||||||
|
toast.info("No updates available");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error checking for updates:", error);
|
||||||
|
setIsUpdateAvailable(false);
|
||||||
|
toast.error(
|
||||||
|
"An error occurred while checking for updates, please try again.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
@@ -76,24 +94,7 @@ export const UpdateServer = () => {
|
|||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
className="w-full"
|
className="w-full"
|
||||||
onClick={async () => {
|
onClick={handleCheckUpdates}
|
||||||
await checkServerUpdates()
|
|
||||||
.then(async (updateAvailable) => {
|
|
||||||
setIsUpdateAvailable(updateAvailable);
|
|
||||||
toast.info(
|
|
||||||
updateAvailable
|
|
||||||
? "Update is available"
|
|
||||||
: "No updates available",
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Error checking for updates:", error);
|
|
||||||
setIsUpdateAvailable(false);
|
|
||||||
toast.error(
|
|
||||||
"An error occurred while checking for updates, please try again.",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
>
|
>
|
||||||
{isLoading ? "Checking for updates..." : "Check for updates"}
|
{isLoading ? "Checking for updates..." : "Check for updates"}
|
||||||
|
|||||||
Reference in New Issue
Block a user