Track preschool planning days, partner invites and real vacation forfeiture
Three strands of work that grew together across the same settings screen and
API client, so they land as one change.
Per-year preschool planning days ("studiedagar"): new table, repository
(SQLite + Postgres), service, router and migration 007, plus the hooks and
Settings UI to plan and record them per child and year. Allocation now
reserves the recorded figure for a year where one exists and only falls back
to the child-level estimate otherwise, marking that fallback as assumed.
Partner invitations: workspaces issue and list invitations, registration
accepts an invite token to join the inviter's workspace instead of creating a
personal one, and a /join/:token page plus the settings invite panel drive it.
Vacation forfeiture: tips and the dashboard now distinguish days a parent
genuinely loses from days that merely age, so the warning stops firing on
balances that were never at risk.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,13 @@ import type { DayOverride, DayOverrideCreateRequest } from '@/types'
|
||||
|
||||
interface UseDayOverridesResult {
|
||||
data: DayOverride[]
|
||||
/** True only while the initial (or workspace-switch) load is in flight —
|
||||
* safe to gate a full-page blocking spinner on. */
|
||||
isLoading: boolean
|
||||
/** True while a post-mutation background refresh is in flight. Never true
|
||||
* at the same time as `isLoading` — see `useLeaveWishes.ts`'s doc comment
|
||||
* for why a mutation's refetch must not flip the initial-load flag. */
|
||||
isRefreshing: boolean
|
||||
error: string | null
|
||||
upsert: (req: DayOverrideCreateRequest) => Promise<void>
|
||||
remove: (id: string) => Promise<void>
|
||||
@@ -15,26 +21,32 @@ interface UseDayOverridesResult {
|
||||
export function useDayOverrides(workspaceId: string): UseDayOverridesResult {
|
||||
const [data, setData] = useState<DayOverride[]>([])
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [isRefreshing, setIsRefreshing] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const { start, isCurrent } = useLatestRequest()
|
||||
const { bumpPlanVersion } = useWorkspace()
|
||||
|
||||
const fetch = useCallback(async () => {
|
||||
const requestId = start()
|
||||
if (!workspaceId) return
|
||||
setIsLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const result = await api.listDayOverridesByWorkspace(workspaceId)
|
||||
if (!isCurrent(requestId)) return
|
||||
setData(result)
|
||||
} catch (err: unknown) {
|
||||
if (!isCurrent(requestId)) return
|
||||
setError(err instanceof Error ? err.message : 'Failed to load day overrides')
|
||||
} finally {
|
||||
if (isCurrent(requestId)) setIsLoading(false)
|
||||
}
|
||||
}, [workspaceId, start, isCurrent])
|
||||
const fetch = useCallback(
|
||||
async (options?: { background?: boolean }) => {
|
||||
const requestId = start()
|
||||
if (!workspaceId) return
|
||||
const background = options?.background ?? false
|
||||
const setBusy = background ? setIsRefreshing : setIsLoading
|
||||
setBusy(true)
|
||||
setError(null)
|
||||
try {
|
||||
const result = await api.listDayOverridesByWorkspace(workspaceId)
|
||||
if (!isCurrent(requestId)) return
|
||||
setData(result)
|
||||
} catch (err: unknown) {
|
||||
if (!isCurrent(requestId)) return
|
||||
setError(err instanceof Error ? err.message : 'Failed to load day overrides')
|
||||
} finally {
|
||||
if (isCurrent(requestId)) setBusy(false)
|
||||
}
|
||||
},
|
||||
[workspaceId, start, isCurrent],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
void fetch()
|
||||
@@ -43,7 +55,7 @@ export function useDayOverrides(workspaceId: string): UseDayOverridesResult {
|
||||
const upsert = useCallback(
|
||||
async (req: DayOverrideCreateRequest) => {
|
||||
await api.upsertDayOverride(req)
|
||||
await fetch()
|
||||
await fetch({ background: true })
|
||||
// An override changes which days count as free/working, which feeds
|
||||
// the at-risk-days analytics — bump the shared invalidation counter
|
||||
// so other hook instances (e.g. useAnalytics) refetch. See
|
||||
@@ -56,11 +68,11 @@ export function useDayOverrides(workspaceId: string): UseDayOverridesResult {
|
||||
const remove = useCallback(
|
||||
async (id: string) => {
|
||||
await api.deleteDayOverride(id)
|
||||
await fetch()
|
||||
await fetch({ background: true })
|
||||
bumpPlanVersion()
|
||||
},
|
||||
[fetch, bumpPlanVersion],
|
||||
)
|
||||
|
||||
return { data, isLoading, error, upsert, remove }
|
||||
return { data, isLoading, isRefreshing, error, upsert, remove }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user