chahinebrini 6700391eed feat(devices): Settings → Geräte UI + AddMacSheet 3-step Lyra flow
Frontend:
- New devices.tsx: section 'this device' + 'protected devices' + Legend CTA
- AddMacSheet: label → Lyra-onboarding (4 steps) → success
- protectedDevices store (Zustand): load, enroll, confirmInstalled, remove
- Locale strings DE + EN (devices namespace, 36 keys each)
- Path-fix: /api/devices/protected (was /api/devices) + /api/devices/:id/revoke

Free/Pro see upgrade-CTA, Legend see add-Mac. Windows button shown disabled (soon).

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

79 lines
2.0 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) => 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) => {
set({ enrolling: true });
try {
const result = await apiFetch<EnrollResult>('/api/devices/enroll', {
method: 'POST',
body: { platform: 'mac', 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;
},
}));