mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-07 12:32:16 +00:00
fix: add loading feedback and invalidation to context menu actions
Use toast.promise for loading/success/error states and invalidate environment query after actions complete to update service status.
This commit is contained in:
@@ -874,19 +874,34 @@ const EnvironmentPage = (
|
|||||||
const idKey = getServiceIdKey(service);
|
const idKey = getServiceIdKey(service);
|
||||||
if (!actions || !idKey) return;
|
if (!actions || !idKey) return;
|
||||||
|
|
||||||
try {
|
const actionLabels = {
|
||||||
await actions[action].mutateAsync({
|
start: { loading: "Starting", success: "started", error: "starting" },
|
||||||
[idKey]: service.id,
|
stop: { loading: "Stopping", success: "stopped", error: "stopping" },
|
||||||
} as any);
|
deploy: {
|
||||||
toast.success(
|
loading: "Deploying",
|
||||||
`Service ${service.name} ${action === "deploy" ? "queued for deployment" : `${action}ed`} successfully`,
|
success: "queued for deployment",
|
||||||
);
|
error: "deploying",
|
||||||
refetch();
|
},
|
||||||
} catch (error) {
|
};
|
||||||
toast.error(
|
|
||||||
`Error ${action === "stop" ? "stopp" : action}ing service ${service.name}: ${error instanceof Error ? error.message : "Unknown error"}`,
|
const labels = actionLabels[action];
|
||||||
);
|
|
||||||
}
|
toast.promise(
|
||||||
|
(async () => {
|
||||||
|
await actions[action].mutateAsync({
|
||||||
|
[idKey]: service.id,
|
||||||
|
} as any);
|
||||||
|
})(),
|
||||||
|
{
|
||||||
|
loading: `${labels.loading} ${service.name}...`,
|
||||||
|
success: () => {
|
||||||
|
utils.environment.one.invalidate({ environmentId });
|
||||||
|
return `${service.name} ${labels.success} successfully`;
|
||||||
|
},
|
||||||
|
error: (error) =>
|
||||||
|
`Error ${labels.error} ${service.name}: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||||
|
},
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleServiceDelete = async (service: Services) => {
|
const handleServiceDelete = async (service: Services) => {
|
||||||
@@ -894,18 +909,22 @@ const EnvironmentPage = (
|
|||||||
const idKey = getServiceIdKey(service);
|
const idKey = getServiceIdKey(service);
|
||||||
if (!actions || !idKey) return;
|
if (!actions || !idKey) return;
|
||||||
|
|
||||||
try {
|
toast.promise(
|
||||||
await actions.delete.mutateAsync({
|
(async () => {
|
||||||
[idKey]: service.id,
|
await actions.delete.mutateAsync({
|
||||||
} as any);
|
[idKey]: service.id,
|
||||||
await utils.environment.one.invalidate({ environmentId });
|
} as any);
|
||||||
toast.success(`Service ${service.name} deleted successfully`);
|
})(),
|
||||||
refetch();
|
{
|
||||||
} catch (error) {
|
loading: `Deleting ${service.name}...`,
|
||||||
toast.error(
|
success: () => {
|
||||||
`Error deleting service ${service.name}: ${error instanceof Error ? error.message : "Unknown error"}`,
|
utils.environment.one.invalidate({ environmentId });
|
||||||
);
|
return `${service.name} deleted successfully`;
|
||||||
}
|
},
|
||||||
|
error: (error) =>
|
||||||
|
`Error deleting ${service.name}: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||||
|
},
|
||||||
|
);
|
||||||
setServiceToDelete(null);
|
setServiceToDelete(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user