fix(sites): name the site in the delete confirmation and toast

This commit is contained in:
Alexandre Brandizzi 2026-09-25 11:55:09 -03:00
parent 551f6af208
commit c5816f8907
3 changed files with 17 additions and 4 deletions

View file

@ -23,10 +23,10 @@ export function LocationDeleteDialog({
}: LocationDeleteDialogProps) {
return (
<Dialog open={Boolean(target)} onClose={onClose}>
<DialogTitle>Delete Location</DialogTitle>
<DialogTitle>Delete this site?</DialogTitle>
<DialogContent>
<DialogContentText>
Are you sure you want to delete &quot;{target?.name}&quot;? This action cannot be undone.
This will permanently remove {target?.name} from Sites. This cannot be undone.
</DialogContentText>
</DialogContent>
<DialogActions>

View file

@ -10,10 +10,10 @@ export function useDeleteLocation(): UseMutationResult<void, Error, string | num
mutationFn: (id: string | number) => locationsApi.delete(id),
onSuccess: () => {
void queryClient.invalidateQueries({ queryKey: queryKeys.locations.all });
toast.success("Location deleted successfully!");
toast.success("Site deleted");
},
onError: (error: Error) => {
toast.error(error.message || "Failed to delete location");
toast.error(error.message || "Failed to delete site");
},
});
}

View file

@ -202,4 +202,17 @@ describe("Sites page detail panel", () => {
expect(screen.queryByRole("heading", { name: "DAL1" })).not.toBeInTheDocument(),
);
});
it("row delete asks to confirm removing the site without opening the panel", async () => {
renderWithProviders(<LocationsListPage />, { withAuth: false });
fireEvent.click(await screen.findByRole("button", { name: "Delete site DAL1" }));
const confirm = await screen.findByRole("dialog", { name: "Delete this site?" });
expect(
within(confirm).getByText(
"This will permanently remove DAL1 from Sites. This cannot be undone.",
),
).toBeInTheDocument();
expect(screen.queryByRole("heading", { name: "DAL1" })).not.toBeInTheDocument();
});
});