MVP frontend+backend
This commit is contained in:
@@ -11,17 +11,17 @@ interface UsePlannedDaysResult {
|
||||
remove: (id: string) => Promise<void>
|
||||
}
|
||||
|
||||
export function usePlannedDays(workspaceId: string | null, childId?: string): UsePlannedDaysResult {
|
||||
export function usePlannedDays(childId?: string): UsePlannedDaysResult {
|
||||
const [data, setData] = useState<PlannedLeaveDay[] | null>(null)
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const fetch = useCallback(async () => {
|
||||
if (!workspaceId || !childId) return
|
||||
if (!childId) return
|
||||
setIsLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const response = await api.getPlannedDays(workspaceId, childId)
|
||||
const response = await api.getPlannedDays(childId)
|
||||
setData(response)
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to fetch planned days')
|
||||
@@ -29,19 +29,18 @@ export function usePlannedDays(workspaceId: string | null, childId?: string): Us
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}, [workspaceId, childId])
|
||||
}, [childId])
|
||||
|
||||
const add = useCallback(
|
||||
async (date: string, childId: string, leaveType: string) => {
|
||||
if (!workspaceId) throw new Error('Workspace not selected')
|
||||
const result = await api.createPlannedDay(workspaceId, childId, {
|
||||
const result = await api.createPlannedDay(childId, {
|
||||
date,
|
||||
leaveType,
|
||||
})
|
||||
await fetch()
|
||||
return result
|
||||
},
|
||||
[workspaceId, fetch]
|
||||
[fetch]
|
||||
)
|
||||
|
||||
const remove = useCallback(
|
||||
|
||||
Reference in New Issue
Block a user