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:
Mauricio Siu
2026-04-13 20:51:22 -06:00
parent 638b3dd546
commit 7f25ddca44
@@ -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 = {
start: { loading: "Starting", success: "started", error: "starting" },
stop: { loading: "Stopping", success: "stopped", error: "stopping" },
deploy: {
loading: "Deploying",
success: "queued for deployment",
error: "deploying",
},
};
const labels = actionLabels[action];
toast.promise(
(async () => {
await actions[action].mutateAsync({ await actions[action].mutateAsync({
[idKey]: service.id, [idKey]: service.id,
} as any); } as any);
toast.success( })(),
`Service ${service.name} ${action === "deploy" ? "queued for deployment" : `${action}ed`} successfully`, {
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"}`,
},
); );
refetch();
} catch (error) {
toast.error(
`Error ${action === "stop" ? "stopp" : action}ing service ${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(
(async () => {
await actions.delete.mutateAsync({ await actions.delete.mutateAsync({
[idKey]: service.id, [idKey]: service.id,
} as any); } as any);
await utils.environment.one.invalidate({ environmentId }); })(),
toast.success(`Service ${service.name} deleted successfully`); {
refetch(); loading: `Deleting ${service.name}...`,
} catch (error) { success: () => {
toast.error( utils.environment.one.invalidate({ environmentId });
`Error deleting service ${service.name}: ${error instanceof Error ? error.message : "Unknown error"}`, return `${service.name} deleted successfully`;
},
error: (error) =>
`Error deleting ${service.name}: ${error instanceof Error ? error.message : "Unknown error"}`,
},
); );
}
setServiceToDelete(null); setServiceToDelete(null);
}; };