Initial commit

This commit is contained in:
2026-06-01 16:48:21 +02:00
commit 53d157535a
159 changed files with 13641 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
import { useState, useEffect, useCallback } from 'react'
import * as api from '@/services/api'
import type { BreakPeriod } from '@/types'
interface UseBreakPeriodsResult {
data: BreakPeriod[] | null
isLoading: boolean
error: string | null
refresh: () => Promise<void>
add: (
startDate: string,
endDate: string,
name: string,
targetWeeks: number
) => Promise<BreakPeriod>
remove: (id: string) => Promise<void>
}
export function useBreakPeriods(workspaceId: string | null): UseBreakPeriodsResult {
const [data, setData] = useState<BreakPeriod[] | null>(null)
const [isLoading, setIsLoading] = useState(false)
const [error, setError] = useState<string | null>(null)
const fetch = useCallback(async () => {
if (!workspaceId) return
setIsLoading(true)
setError(null)
try {
const response = await api.getBreakPeriods(workspaceId)
setData(response)
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to fetch break periods')
setData(null)
} finally {
setIsLoading(false)
}
}, [workspaceId])
const add = useCallback(
async (startDate: string, endDate: string, name: string, targetWeeks: number) => {
if (!workspaceId) throw new Error('Workspace not selected')
const result = await api.createBreakPeriod(workspaceId, {
name,
start_date: startDate,
end_date: endDate,
target_weeks: targetWeeks,
})
await fetch()
return result
},
[workspaceId, fetch]
)
const remove = useCallback(
async (id: string) => {
await api.deleteBreakPeriod(id)
await fetch()
},
[fetch]
)
useEffect(() => {
fetch()
}, [fetch])
return { data, isLoading, error, refresh: fetch, add, remove }
}