chahinebrini dd3d8c6667 feat(devices): wire Windows DoH AddWindowsSheet into devices screen
- AddWindowsSheet: 5-step Lyra flow (download → datei → shield-check → wifi → done)
- devices.tsx: Windows button enabled, opens AddWindowsSheet
- protectedDevices store: enroll() takes platform 'mac' | 'windows'
- AddMacSheet: pass 'mac' to enroll()

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:44:41 +02:00

79 lines
2.1 KiB
TypeScript

import { create } from 'zustand';
import { apiFetch } from '../lib/api';
export type ProtectedDeviceStatus = 'pending' | 'active' | 'revoked';
export interface ProtectedDevice {
id: string;
platform: 'mac' | 'windows' | string;
label: string;
status: ProtectedDeviceStatus;
installedAt: string | null;
createdAt: string;
}
export interface EnrollResult {
deviceId: string;
downloadUrl: string;
}
type ProtectedDevicesState = {
devices: ProtectedDevice[];
loading: boolean;
enrolling: boolean;
load: () => Promise<void>;
enroll: (label: string, platform: 'mac' | 'windows') => Promise<EnrollResult>;
confirmInstalled: (id: string) => Promise<void>;
remove: (id: string) => Promise<{ manualRemovalRequired: boolean }>;
};
export const useProtectedDevicesStore = create<ProtectedDevicesState>((set, get) => ({
devices: [],
loading: false,
enrolling: false,
load: async () => {
set({ loading: true });
try {
const devices = await apiFetch<ProtectedDevice[]>('/api/devices/protected');
set({ devices });
} catch {
// endpoint might not be ready yet — keep empty state, screen handles it
} finally {
set({ loading: false });
}
},
enroll: async (label: string, platform: 'mac' | 'windows') => {
set({ enrolling: true });
try {
const result = await apiFetch<EnrollResult>('/api/devices/enroll', {
method: 'POST',
body: { platform, label },
});
await get().load();
return result;
} finally {
set({ enrolling: false });
}
},
confirmInstalled: async (id: string) => {
await apiFetch(`/api/devices/${id}/confirm-installed`, { method: 'POST' });
set((s) => ({
devices: s.devices.map((d) =>
d.id === id ? { ...d, status: 'active' as const, installedAt: new Date().toISOString() } : d
),
}));
},
remove: async (id: string) => {
const res = await apiFetch<{ manualRemovalRequired: boolean }>(`/api/devices/${id}/revoke`, {
method: 'DELETE',
});
set((s) => ({ devices: s.devices.filter((d) => d.id !== id) }));
return res;
},
}));