Files
triqura-ecd/stores/swift-store.ts
colinislit d67405df5f feat(swift): Epic 4 - Navigation & Auth compleet
E4.S1 - Login form uitbreiden:
- Interface selector (Swift/Klassiek) toegevoegd
- Visuele keuze met icons (Layout/Zap)
- Redirect naar gekozen interface na login

E4.S2 - Preference opslag:
- updateInterfacePreference() in lib/auth/client.ts
- getInterfacePreference() voor ophalen
- Opslag in user_metadata.preferred_interface

E4.S3 - Redirect middleware:
- /epd → redirect naar preferred interface
- /login → redirect naar preferred interface (als ingelogd)
- Default: klassiek (/epd/clients)

E4.S4 - Fallback Picker:
- FallbackPicker component voor lage confidence
- Grid met 3 opties (Notitie, Zoeken, Overdracht)
- Keyboard shortcuts [1], [2], [3]
- Toont originele input voor context

Voortgang: Epic 4 compleet (8 SP)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-24 09:28:10 +01:00

172 lines
4.0 KiB
TypeScript

import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
import type { Database } from '@/lib/supabase/database.types';
import type { VerpleegkundigCategory } from '@/lib/types/report';
// Database types
export type Patient = Database['public']['Tables']['patients']['Row'];
// Swift-specific types
export type ShiftType = 'nacht' | 'ochtend' | 'middag' | 'avond';
export type SwiftIntent =
| 'dagnotitie'
| 'zoeken'
| 'overdracht'
| 'unknown';
export type BlockType = Exclude<SwiftIntent, 'unknown'> | 'fallback';
// Extracted entities from user input
export interface ExtractedEntities {
patientName?: string;
patientId?: string;
category?: VerpleegkundigCategory;
content?: string;
}
// Block prefill data
export interface BlockPrefillData extends ExtractedEntities {
// Additional prefill data specific to blocks
}
// Recent action for the Recent Strip
export interface RecentAction {
id: string;
intent: SwiftIntent;
label: string;
timestamp: Date;
patientName?: string;
}
// Store interface
interface SwiftStore {
// Context
activePatient: Patient | null;
shift: ShiftType;
// Block state
activeBlock: BlockType | null;
prefillData: BlockPrefillData;
isBlockLoading: boolean;
// Input state
inputValue: string;
isVoiceActive: boolean;
// Recent actions
recentActions: RecentAction[];
// Context actions
setActivePatient: (patient: Patient | null) => void;
setShift: (shift: ShiftType) => void;
// Block actions
openBlock: (type: BlockType, prefill?: BlockPrefillData) => void;
closeBlock: () => void;
setBlockLoading: (loading: boolean) => void;
// Input actions
setInputValue: (value: string) => void;
setVoiceActive: (active: boolean) => void;
clearInput: () => void;
// Recent actions
addRecentAction: (action: Omit<RecentAction, 'id' | 'timestamp'>) => void;
// Reset
reset: () => void;
}
// Helper to calculate current shift based on time
function getCurrentShift(): ShiftType {
const hour = new Date().getHours();
if (hour >= 0 && hour < 7) return 'nacht';
if (hour >= 7 && hour < 12) return 'ochtend';
if (hour >= 12 && hour < 17) return 'middag';
return 'avond';
}
// Initial state
const initialState = {
activePatient: null,
shift: getCurrentShift(),
activeBlock: null,
prefillData: {},
isBlockLoading: false,
inputValue: '',
isVoiceActive: false,
recentActions: [],
};
// Create the store
export const useSwiftStore = create<SwiftStore>()(
devtools(
(set, get) => ({
...initialState,
// Context actions
setActivePatient: (patient) => set({ activePatient: patient }, false, 'setActivePatient'),
setShift: (shift) => set({ shift }, false, 'setShift'),
// Block actions
openBlock: (type, prefill = {}) => {
set(
{
activeBlock: type,
prefillData: prefill,
isBlockLoading: false,
},
false,
'openBlock'
);
},
closeBlock: () => {
set(
{
activeBlock: null,
prefillData: {},
isBlockLoading: false,
},
false,
'closeBlock'
);
},
setBlockLoading: (loading) => set({ isBlockLoading: loading }, false, 'setBlockLoading'),
// Input actions
setInputValue: (value) => set({ inputValue: value }, false, 'setInputValue'),
setVoiceActive: (active) => set({ isVoiceActive: active }, false, 'setVoiceActive'),
clearInput: () => set({ inputValue: '' }, false, 'clearInput'),
// Recent actions
addRecentAction: (action) => {
const newAction: RecentAction = {
...action,
id: crypto.randomUUID(),
timestamp: new Date(),
};
set(
(state) => ({
recentActions: [newAction, ...state.recentActions].slice(0, 5),
}),
false,
'addRecentAction'
);
},
// Reset
reset: () => set(initialState, false, 'reset'),
}),
{
name: 'swift-store',
}
)
);