feat: add device deletion endpoint with cascade cleanup and admin UI integration
Add DELETE /admin/devices/{id} endpoint with cascade deletion of device records, WireGuard peers, IP allocations, and device access profile settings. Update device status to 'deleted' and set deleted_at timestamp while preserving revoked_at if already set.
Add deleteDevice API method and delete button to devices page with query invalidation for both devices and device-profile lists. Record admin.device.deleted audit
This commit is contained in:
@@ -225,6 +225,10 @@ export const api = {
|
||||
method: "POST",
|
||||
body: JSON.stringify({})
|
||||
}),
|
||||
deleteDevice: (deviceId: string) =>
|
||||
request<{ ok: boolean }>(`/admin/devices/${deviceId}`, {
|
||||
method: "DELETE"
|
||||
}),
|
||||
rotateDevice: (deviceId: string) =>
|
||||
request<{ ok: boolean }>(`/admin/devices/${deviceId}/rotate`, {
|
||||
method: "POST",
|
||||
|
||||
@@ -46,6 +46,13 @@ export function DevicesPage() {
|
||||
mutationFn: api.revokeDevice,
|
||||
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["devices"] })
|
||||
});
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: api.deleteDevice,
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: ["devices"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["device-profile"] });
|
||||
}
|
||||
});
|
||||
const rotateMutation = useMutation({
|
||||
mutationFn: api.rotateDevice,
|
||||
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["devices"] })
|
||||
@@ -85,6 +92,7 @@ export function DevicesPage() {
|
||||
<div className="action-row">
|
||||
<button className="button" onClick={() => rotateMutation.mutate(rows[0].id)}>Rotate profile</button>
|
||||
<button className="ghost-button" onClick={() => revokeMutation.mutate(rows[0].id)}>Revoke device</button>
|
||||
<button className="ghost-button" onClick={() => deleteMutation.mutate(rows[0].id)}>Delete device</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user