mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
feat(vacay): add school holiday overlays (#1633)
* feat: add vacay school holiday overlays * fix(vacay): remove SOH control character corruption in locale files 13 of 22 vacay locale files contained a 0x01 (SOH) control character that corrupted the closing }; token. This broke the shared package build (tsdown/rolldown PARSE_ERROR: Invalid Character) and cascaded to all client tests failing to resolve @trek/shared. Affected locales: ar, br, ca, cs, es, fr, gr, hu, id, it, ja, ko, nl, pl, ru, sv, tr, uk, vi, zh, zh-TW * fix(vacay): school-holiday migration order, i18n dupes, settings layout - Move the school-holiday columns migration to the end of the migrations array. It sat before the #1435/#1281 migrations, which every existing DB had already run, so the runner skipped it and school_holidays_enabled / vacay_holiday_calendars.type were never created — PUT /addons/vacay/plan then 500'd with "no such column". - Remove duplicate i18n keys in 13 locale vacay files (TS1117) that failed the shared + client typechecks. - Move the school-holidays block into the right column, directly under public holidays, instead of full-width below everything. - Add the school-holidays section to the mobile Vacay settings sheet. * feat(vacay): modern school-holiday day styling + combined hover tooltip - Replace the stacked 2px underlines with a single rounded accent band and a soft background wash on plain school-break days (desktop + mobile — mobile did not render school holidays at all before). - Fold school holidays into the custom day tooltip under a divider instead of a separate native title, and show the tooltip on every set day (whole vacation days too), not only half days / shared calendars. --------- Co-authored-by: Otto <uif86164@automotive-wan.com> Co-authored-by: Maurice <mauriceboe@icloud.com>
This commit is contained in:
@@ -105,6 +105,8 @@ export default function VacayCalendar() {
|
||||
const selectedUser = users.find(u => u.id === selectedUserId)
|
||||
const tipEntries = tip ? entryMap[tip.date] : undefined
|
||||
const tipShared = tip ? sharedMap[tip.date] : undefined
|
||||
const tipHolidayRaw = tip ? holidays[tip.date] : undefined
|
||||
const tipSchool = (Array.isArray(tipHolidayRaw) ? tipHolidayRaw : tipHolidayRaw ? [tipHolidayRaw] : []).filter(h => h.type === 'school_holiday')
|
||||
const tipDate = tip ? new Intl.DateTimeFormat(locale, { weekday: 'short', day: 'numeric', month: 'long' }).format(new Date(tip.date + 'T00:00:00')) : ''
|
||||
|
||||
return (
|
||||
@@ -135,7 +137,7 @@ export default function VacayCalendar() {
|
||||
with half days, plus shared read-only calendars). Rendered fixed at the
|
||||
root (not inside a month card) so backdrop-filter stacking contexts
|
||||
can't clip or occlude it. */}
|
||||
{tip && ((tipEntries && tipEntries.length > 0) || (tipShared && tipShared.length > 0)) && (
|
||||
{tip && ((tipEntries && tipEntries.length > 0) || (tipShared && tipShared.length > 0) || tipSchool.length > 0) && (
|
||||
<div
|
||||
className="vg-card rounded-xl"
|
||||
style={{ position: 'fixed', top: tip.top - 9, left: tip.left, transform: 'translate(-50%, -100%)', zIndex: 80, pointerEvents: 'none' }}
|
||||
@@ -164,6 +166,24 @@ export default function VacayCalendar() {
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
{/* School holidays fold into this tooltip under a divider instead of a
|
||||
separate native title, so a half/full day and the school break read together. */}
|
||||
{tipSchool.length > 0 && (
|
||||
<>
|
||||
{((tipEntries?.length ?? 0) > 0 || (tipShared?.length ?? 0) > 0) && (
|
||||
<div style={{ height: 1, background: 'var(--vg-line)', margin: '7px 0 6px' }} />
|
||||
)}
|
||||
<div style={{ fontSize: 9, fontWeight: 700, letterSpacing: '0.04em', textTransform: 'uppercase', color: 'var(--vg-ink3)', marginBottom: 4 }}>
|
||||
{t('vacay.schoolHolidays')}
|
||||
</div>
|
||||
{tipSchool.map((h, i) => (
|
||||
<div key={`sch${i}`} className="flex items-center gap-2" style={{ marginTop: i ? 3 : 0 }}>
|
||||
<span className="w-2 h-2 rounded-full shrink-0" style={{ background: h.color }} />
|
||||
<span style={{ fontSize: 12, fontWeight: 600, color: 'var(--vg-ink)' }}>{h.label ? `${h.label}: ${h.localName}` : h.localName}</span>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -67,6 +67,16 @@ describe('VacayMonthCard', () => {
|
||||
expect(cell).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYMONTHCARD-014: School holiday markers do not recolor the day number', () => {
|
||||
const props = {
|
||||
...baseProps,
|
||||
holidays: { '2025-01-02': { name: 'School holiday', localName: 'School holiday', label: 'NL', color: '#22c55e', type: 'school_holiday' as const } },
|
||||
}
|
||||
render(<VacayMonthCard {...props} />)
|
||||
const daySpan = screen.getByText('2')
|
||||
expect(daySpan.style.color).toBe('var(--vg-ink2)')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYMONTHCARD-006: Weekend cell has default cursor (blocked)', () => {
|
||||
render(<VacayMonthCard {...baseProps} />)
|
||||
// January 5, 2025 is a Sunday (getDay() === 0), which is in weekendDays [0, 6]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useMemo } from 'react'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import type { HolidaysMap, VacayEntry } from '../../types'
|
||||
import { schoolHolidayBand, schoolHolidayWash } from './holidayVisual'
|
||||
|
||||
const WEEKDAY_KEYS = ['vacay.mon', 'vacay.tue', 'vacay.wed', 'vacay.thu', 'vacay.fri', 'vacay.sat', 'vacay.sun'] as const
|
||||
|
||||
@@ -96,13 +97,16 @@ export default function VacayMonthCard({
|
||||
const dateStr = `${year}-${pad(month + 1)}-${pad(day)}`
|
||||
const dayOfWeek = new Date(year, month, day).getDay()
|
||||
const weekend = weekendDays.includes(dayOfWeek)
|
||||
const holiday = holidays[dateStr]
|
||||
const rawHolidayMarkers = holidays[dateStr]
|
||||
const holidayMarkers = Array.isArray(rawHolidayMarkers) ? rawHolidayMarkers : rawHolidayMarkers ? [rawHolidayMarkers] : []
|
||||
const publicHoliday = holidayMarkers.find(h => (h.type ?? 'public_holiday') === 'public_holiday')
|
||||
const schoolHolidayMarkers = holidayMarkers.filter(h => h.type === 'school_holiday')
|
||||
const isCompany = companyHolidaysEnabled && companyHolidaySet.has(dateStr)
|
||||
const dayEntries = entryMap[dateStr] || []
|
||||
const hasEntries = dayEntries.length > 0
|
||||
const isBlocked = (weekend && blockWeekends) || (isCompany && !companyMode)
|
||||
const isToday = dateStr === todayStr
|
||||
const plain = !hasEntries && !holiday && !isCompany
|
||||
const plain = !hasEntries && holidayMarkers.length === 0 && !isCompany
|
||||
|
||||
// The fill always shows WHO is off (person colour, split for several) — half
|
||||
// days keep that fill and get a small corner ½ badge instead, so a half day
|
||||
@@ -119,7 +123,10 @@ export default function VacayMonthCard({
|
||||
if (dayEntries.length === 1) background = fill(dayEntries[0].person_color)
|
||||
else if (dayEntries.length === 2) background = `linear-gradient(135deg, ${fill(dayEntries[0].person_color)} 50%, ${fill(dayEntries[1].person_color)} 50%)`
|
||||
else if (dayEntries.length === 0 && isCompany) background = 'rgba(245,158,11,0.22)'
|
||||
else if (dayEntries.length === 0 && holiday) background = `color-mix(in srgb, ${holiday.color} 22%, transparent)`
|
||||
else if (dayEntries.length === 0 && publicHoliday) background = `color-mix(in srgb, ${publicHoliday.color} 22%, transparent)`
|
||||
// A plain school-break day gets a soft wash of its calendar colour so a run of
|
||||
// days reads as one gentle stretch; the rounded band below names the calendar.
|
||||
else if (dayEntries.length === 0 && schoolHolidayMarkers.length > 0) background = schoolHolidayWash(schoolHolidayMarkers[0].color)
|
||||
// Weekend / settings-blocked days read as inactive: subtle grey fill, like before the facelift.
|
||||
else if (weekend && blockWeekends) background = 'color-mix(in srgb, var(--vg-ink3) 7%, transparent)'
|
||||
|
||||
@@ -133,13 +140,13 @@ export default function VacayMonthCard({
|
||||
|
||||
let numColor = 'var(--vg-ink2)'
|
||||
if (hasEntries) numColor = '#fff'
|
||||
else if (holiday) numColor = holiday.color
|
||||
else if (publicHoliday) numColor = publicHoliday.color
|
||||
else if (weekend) numColor = 'var(--vg-ink3)'
|
||||
|
||||
return (
|
||||
<div
|
||||
key={di}
|
||||
title={holiday ? (holiday.label ? `${holiday.label}: ${holiday.localName}` : holiday.localName) : undefined}
|
||||
title={publicHoliday ? (publicHoliday.label ? `${publicHoliday.label}: ${publicHoliday.localName}` : publicHoliday.localName) : undefined}
|
||||
className="relative flex items-center justify-center transition-colors"
|
||||
style={{
|
||||
height: 28,
|
||||
@@ -151,11 +158,11 @@ export default function VacayMonthCard({
|
||||
onClick={() => onCellClick(dateStr)}
|
||||
onMouseEnter={e => {
|
||||
if (!isBlocked && plain) e.currentTarget.style.background = 'var(--vg-surf2)'
|
||||
if (anyHalf || sharedColors.length > 0) onCellHover?.(dateStr, e.currentTarget)
|
||||
if (hasEntries || sharedColors.length > 0 || schoolHolidayMarkers.length > 0) onCellHover?.(dateStr, e.currentTarget)
|
||||
}}
|
||||
onMouseLeave={e => {
|
||||
if (!isBlocked && plain) e.currentTarget.style.background = background
|
||||
if (anyHalf || sharedColors.length > 0) onCellHover?.(null, null)
|
||||
if (hasEntries || sharedColors.length > 0 || schoolHolidayMarkers.length > 0) onCellHover?.(null, null)
|
||||
}}
|
||||
>
|
||||
{/* 3+ people: quadrant overlay at full colour (1 & 2 use the cell background). */}
|
||||
@@ -185,6 +192,20 @@ export default function VacayMonthCard({
|
||||
<span className="absolute bottom-1 right-1 w-[5px] h-[5px] rounded-full z-[3] bg-[#f97316]" style={{ boxShadow: '0 0 0 1.5px var(--vg-surf)' }} aria-hidden />
|
||||
)}
|
||||
|
||||
{schoolHolidayMarkers.length > 0 && (
|
||||
<span
|
||||
className="absolute rounded-full z-[2]"
|
||||
style={{
|
||||
left: 4,
|
||||
right: 4,
|
||||
bottom: 3,
|
||||
height: 3,
|
||||
background: schoolHolidayBand(schoolHolidayMarkers.map(h => h.color)),
|
||||
}}
|
||||
aria-hidden
|
||||
/>
|
||||
)}
|
||||
|
||||
<span className="relative z-[1]" style={{
|
||||
fontFamily: 'var(--font-subtext)',
|
||||
fontSize: 12,
|
||||
|
||||
@@ -7,7 +7,8 @@ import { server } from '../../../tests/helpers/msw/server'
|
||||
import { http, HttpResponse } from 'msw'
|
||||
import { useVacayStore } from '../../store/vacayStore'
|
||||
import VacaySettings from './VacaySettings'
|
||||
import { fetchRegionOptions } from './holidayRegions'
|
||||
import { fetchRegionOptions, fetchSchoolHolidayRegionOptions } from './holidayRegions'
|
||||
import { SCHOOL_HOLIDAY_COUNTRY_CONFIG } from '../../vacay/schoolHolidayCountries'
|
||||
|
||||
const basePlan = {
|
||||
id: 1,
|
||||
@@ -445,6 +446,53 @@ describe('VacaySettings', () => {
|
||||
expect(await fetchRegionOptions('JP')).toEqual([])
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYSETTINGS-021: school holiday whitelist contains only approved green/yellow countries', () => {
|
||||
expect(Object.values(SCHOOL_HOLIDAY_COUNTRY_CONFIG).every(config => ['green', 'yellow'].includes(config.status))).toBe(true)
|
||||
expect(SCHOOL_HOLIDAY_COUNTRY_CONFIG.SE).toBeUndefined()
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYSETTINGS-022: German school holidays use subdivisions even when OpenHolidays exposes groups', async () => {
|
||||
server.use(
|
||||
http.get('/api/addons/vacay/school-holidays/regions/:country', () =>
|
||||
HttpResponse.json({
|
||||
groups: [
|
||||
{ code: 'DE-MV-ABS', name: [{ language: 'EN', text: 'General Schools' }] },
|
||||
],
|
||||
subdivisions: [
|
||||
{ code: 'DE-BY', name: [{ language: 'EN', text: 'Bavaria' }] },
|
||||
{ code: 'DE-NW', name: [{ language: 'EN', text: 'North Rhine-Westphalia' }] },
|
||||
],
|
||||
})
|
||||
),
|
||||
)
|
||||
|
||||
expect(await fetchSchoolHolidayRegionOptions('DE')).toEqual([
|
||||
{ value: 'DE-BY', label: 'Bavaria' },
|
||||
{ value: 'DE-NW', label: 'North Rhine-Westphalia' },
|
||||
])
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYSETTINGS-023: Dutch school holidays use OpenHolidays groups', async () => {
|
||||
server.use(
|
||||
http.get('/api/addons/vacay/school-holidays/regions/:country', () =>
|
||||
HttpResponse.json({
|
||||
groups: [
|
||||
{ code: 'NL-NO', name: [{ language: 'EN', text: 'North Region' }] },
|
||||
{ code: 'NL-MI', name: [{ language: 'EN', text: 'Central Region' }] },
|
||||
],
|
||||
subdivisions: [
|
||||
{ code: 'NL-DR', name: [{ language: 'EN', text: 'Drenthe' }] },
|
||||
],
|
||||
})
|
||||
),
|
||||
)
|
||||
|
||||
expect(await fetchSchoolHolidayRegionOptions('NL')).toEqual([
|
||||
{ value: 'NL|group:NL-MI', label: 'Central Region' },
|
||||
{ value: 'NL|group:NL-NO', label: 'North Region' },
|
||||
])
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYSETTINGS-018: adding weekend day calls updatePlan with day added', async () => {
|
||||
const user = userEvent.setup()
|
||||
const updatePlan = vi.fn().mockResolvedValue(undefined)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { type LucideIcon, CalendarOff, AlertCircle, Building2, Unlink, ArrowRightLeft, Globe, Plus, Trash2, CalendarDays } from 'lucide-react'
|
||||
import { type LucideIcon, CalendarOff, AlertCircle, Building2, Unlink, ArrowRightLeft, Globe, Plus, Trash2, CalendarDays, GraduationCap } from 'lucide-react'
|
||||
import { useVacayStore } from '../../store/vacayStore'
|
||||
import { getIntlLanguage, useTranslation } from '../../i18n'
|
||||
import { useToast } from '../shared/Toast'
|
||||
import CustomSelect from '../shared/CustomSelect'
|
||||
import apiClient from '../../api/client'
|
||||
import { fetchRegionOptions } from './holidayRegions'
|
||||
import { fetchRegionOptions, fetchSchoolHolidayRegionOptions } from './holidayRegions'
|
||||
import { SCHOOL_HOLIDAY_COUNTRY_CONFIG } from '../../vacay/schoolHolidayCountries'
|
||||
import type { VacayHolidayCalendar } from '../../types'
|
||||
|
||||
interface VacaySettingsProps {
|
||||
@@ -18,6 +19,7 @@ export default function VacaySettings({ onClose }: VacaySettingsProps) {
|
||||
const { plan, updatePlan, addHolidayCalendar, updateHolidayCalendar, deleteHolidayCalendar, isFused, dissolve, users } = useVacayStore()
|
||||
const [countries, setCountries] = useState<{ value: string; label: string }[]>([])
|
||||
const [showAddForm, setShowAddForm] = useState(false)
|
||||
const [showAddSchoolForm, setShowAddSchoolForm] = useState(false)
|
||||
|
||||
const { language } = useTranslation()
|
||||
|
||||
@@ -38,6 +40,9 @@ export default function VacaySettings({ onClose }: VacaySettingsProps) {
|
||||
if (!plan) return null
|
||||
|
||||
const toggle = (key: string) => updatePlan({ [key]: !plan[key] })
|
||||
const publicHolidayCalendars = (plan.holiday_calendars ?? []).filter(cal => (cal.type ?? 'public_holiday') === 'public_holiday')
|
||||
const schoolHolidayCalendars = (plan.holiday_calendars ?? []).filter(cal => cal.type === 'school_holiday')
|
||||
const schoolHolidayCountries = countries.filter(country => country.value in SCHOOL_HOLIDAY_COUNTRY_CONFIG)
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
@@ -162,15 +167,16 @@ export default function VacaySettings({ onClose }: VacaySettingsProps) {
|
||||
/>
|
||||
{plan.holidays_enabled && (
|
||||
<div className="ml-7 mt-2 space-y-2">
|
||||
{(plan.holiday_calendars ?? []).length === 0 && (
|
||||
{publicHolidayCalendars.length === 0 && (
|
||||
<p className="text-xs text-content-faint">{t('vacay.noCalendars')}</p>
|
||||
)}
|
||||
{(plan.holiday_calendars ?? []).map(cal => (
|
||||
{publicHolidayCalendars.map(cal => (
|
||||
<CalendarRow
|
||||
key={cal.id}
|
||||
cal={cal}
|
||||
countries={countries}
|
||||
language={language}
|
||||
calendarType="public_holiday"
|
||||
onUpdate={(data) => updateHolidayCalendar(cal.id, data)}
|
||||
onDelete={() => deleteHolidayCalendar(cal.id)}
|
||||
/>
|
||||
@@ -179,7 +185,8 @@ export default function VacaySettings({ onClose }: VacaySettingsProps) {
|
||||
<AddCalendarForm
|
||||
countries={countries}
|
||||
language={language}
|
||||
onAdd={async (data) => { await addHolidayCalendar(data); setShowAddForm(false) }}
|
||||
calendarType="public_holiday"
|
||||
onAdd={async (data) => { await addHolidayCalendar({ ...data, type: 'public_holiday' }); setShowAddForm(false) }}
|
||||
onCancel={() => setShowAddForm(false)}
|
||||
/>
|
||||
) : (
|
||||
@@ -195,6 +202,53 @@ export default function VacaySettings({ onClose }: VacaySettingsProps) {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* School holidays — sits on the right, directly under Public holidays */}
|
||||
<div>
|
||||
<SettingToggle
|
||||
icon={GraduationCap}
|
||||
label={t('vacay.schoolHolidays')}
|
||||
hint={t('vacay.schoolHolidaysHint')}
|
||||
value={plan.school_holidays_enabled}
|
||||
onChange={() => toggle('school_holidays_enabled')}
|
||||
/>
|
||||
{plan.school_holidays_enabled && (
|
||||
<div className="ml-7 mt-2 space-y-2">
|
||||
{schoolHolidayCalendars.length === 0 && (
|
||||
<p className="text-xs text-content-faint">{t('vacay.noSchoolCalendars')}</p>
|
||||
)}
|
||||
{schoolHolidayCalendars.map(cal => (
|
||||
<CalendarRow
|
||||
key={cal.id}
|
||||
cal={cal}
|
||||
countries={schoolHolidayCountries}
|
||||
language={language}
|
||||
calendarType="school_holiday"
|
||||
onUpdate={(data) => updateHolidayCalendar(cal.id, data)}
|
||||
onDelete={() => deleteHolidayCalendar(cal.id)}
|
||||
/>
|
||||
))}
|
||||
{showAddSchoolForm ? (
|
||||
<AddCalendarForm
|
||||
countries={schoolHolidayCountries}
|
||||
language={language}
|
||||
calendarType="school_holiday"
|
||||
defaultColor="#a5f3fc"
|
||||
onAdd={async (data) => { await addHolidayCalendar({ ...data, type: 'school_holiday' }); setShowAddSchoolForm(false) }}
|
||||
onCancel={() => setShowAddSchoolForm(false)}
|
||||
/>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => setShowAddSchoolForm(true)}
|
||||
className="flex items-center gap-1.5 text-xs px-2 py-1.5 rounded-md transition-colors text-content-muted bg-surface-secondary"
|
||||
>
|
||||
<Plus size={12} />
|
||||
{t('vacay.addCalendar')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -266,10 +320,11 @@ function SettingToggle({ icon: Icon, label, hint, value, onChange }: SettingTogg
|
||||
}
|
||||
|
||||
// ── Existing calendar row (inline edit) ──────────────────────────────────────
|
||||
function CalendarRow({ cal, countries, onUpdate, onDelete }: {
|
||||
function CalendarRow({ cal, countries, calendarType, onUpdate, onDelete }: {
|
||||
cal: VacayHolidayCalendar
|
||||
countries: { value: string; label: string }[]
|
||||
language: string
|
||||
calendarType: 'public_holiday' | 'school_holiday'
|
||||
onUpdate: (data: { region?: string; color?: string; label?: string | null }) => void
|
||||
onDelete: () => void
|
||||
}) {
|
||||
@@ -278,16 +333,18 @@ function CalendarRow({ cal, countries, onUpdate, onDelete }: {
|
||||
const [localLabel, setLocalLabel] = useState(cal.label || '')
|
||||
const [regions, setRegions] = useState<{ value: string; label: string }[]>([])
|
||||
|
||||
const selectedCountry = cal.region.split('-')[0]
|
||||
const selectedRegion = cal.region.includes('-') ? cal.region : ''
|
||||
const [baseRegion] = cal.region.split('|')
|
||||
const selectedCountry = baseRegion.split('-')[0]
|
||||
const selectedRegion = cal.region.includes('|group:') || baseRegion.includes('-') ? cal.region : ''
|
||||
|
||||
useEffect(() => { setLocalColor(cal.color) }, [cal.color])
|
||||
useEffect(() => { setLocalLabel(cal.label || '') }, [cal.label])
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedCountry) { setRegions([]); return }
|
||||
fetchRegionOptions(selectedCountry).then(setRegions)
|
||||
}, [selectedCountry])
|
||||
const load = calendarType === 'school_holiday' ? fetchSchoolHolidayRegionOptions : fetchRegionOptions
|
||||
load(selectedCountry).then(setRegions)
|
||||
}, [calendarType, selectedCountry])
|
||||
|
||||
const PRESET_COLORS = ['#fecaca', '#fed7aa', '#fde68a', '#bbf7d0', '#a5f3fc', '#c7d2fe', '#e9d5ff', '#fda4af', '#6366f1', '#ef4444', '#22c55e', '#3b82f6']
|
||||
const [showColorPicker, setShowColorPicker] = useState(false)
|
||||
@@ -349,27 +406,31 @@ function CalendarRow({ cal, countries, onUpdate, onDelete }: {
|
||||
}
|
||||
|
||||
// ── Add-new-calendar form ─────────────────────────────────────────────────────
|
||||
function AddCalendarForm({ countries, onAdd, onCancel }: {
|
||||
function AddCalendarForm({ countries, calendarType, onAdd, onCancel, defaultColor = '#fecaca' }: {
|
||||
countries: { value: string; label: string }[]
|
||||
language: string
|
||||
calendarType: 'public_holiday' | 'school_holiday'
|
||||
onAdd: (data: { region: string; color: string; label: string | null }) => void
|
||||
onCancel: () => void
|
||||
defaultColor?: string
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
const [region, setRegion] = useState('')
|
||||
const [color, setColor] = useState('#fecaca')
|
||||
const [color, setColor] = useState(defaultColor)
|
||||
const [label, setLabel] = useState('')
|
||||
const [regions, setRegions] = useState<{ value: string; label: string }[]>([])
|
||||
const [loadingRegions, setLoadingRegions] = useState(false)
|
||||
|
||||
const selectedCountry = region.split('-')[0] || ''
|
||||
const selectedRegion = region.includes('-') ? region : ''
|
||||
const [baseRegion] = region.split('|')
|
||||
const selectedCountry = baseRegion.split('-')[0] || ''
|
||||
const selectedRegion = region.includes('|group:') || baseRegion.includes('-') ? region : ''
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedCountry) { setRegions([]); return }
|
||||
setLoadingRegions(true)
|
||||
fetchRegionOptions(selectedCountry).then(list => { setRegions(list) }).finally(() => setLoadingRegions(false))
|
||||
}, [selectedCountry])
|
||||
const load = calendarType === 'school_holiday' ? fetchSchoolHolidayRegionOptions : fetchRegionOptions
|
||||
load(selectedCountry).then(list => { setRegions(list) }).finally(() => setLoadingRegions(false))
|
||||
}, [calendarType, selectedCountry])
|
||||
|
||||
const canAdd = selectedCountry && (regions.length === 0 || selectedRegion !== '')
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import apiClient from '../../api/client'
|
||||
import iso31662 from 'iso-3166-2'
|
||||
import { SCHOOL_HOLIDAY_COUNTRY_CONFIG } from '../../vacay/schoolHolidayCountries'
|
||||
|
||||
// Loads the subdivision (state/region) options for a holiday-calendar country.
|
||||
//
|
||||
@@ -32,3 +33,51 @@ export async function fetchRegionOptions(country: string): Promise<{ value: stri
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
type LocalizedName = { language: string; text: string }
|
||||
type OpenHolidayOption = {
|
||||
code: string
|
||||
shortName?: string
|
||||
name?: LocalizedName[]
|
||||
children?: OpenHolidayOption[] | null
|
||||
}
|
||||
|
||||
function localizedName(names: LocalizedName[] | undefined, fallback: string): string {
|
||||
return names?.find(n => n.language?.toUpperCase() === 'DE')?.text
|
||||
|| names?.find(n => n.language?.toUpperCase() === 'EN')?.text
|
||||
|| names?.[0]?.text
|
||||
|| fallback
|
||||
}
|
||||
|
||||
function flattenOptions(items: OpenHolidayOption[] | undefined, prefix = ''): { value: string; label: string }[] {
|
||||
const result: { value: string; label: string }[] = []
|
||||
for (const item of items ?? []) {
|
||||
const label = localizedName(item.name, item.shortName || item.code)
|
||||
result.push({ value: item.code, label: prefix ? `${prefix} / ${label}` : label })
|
||||
result.push(...flattenOptions(item.children ?? undefined, prefix ? `${prefix} / ${label}` : label))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export async function fetchSchoolHolidayRegionOptions(country: string): Promise<{ value: string; label: string }[]> {
|
||||
const config = SCHOOL_HOLIDAY_COUNTRY_CONFIG[country]
|
||||
if (!config || config.strategy === 'country') return []
|
||||
|
||||
try {
|
||||
const r = await apiClient.get(`/addons/vacay/school-holidays/regions/${country}`)
|
||||
if (config.strategy === 'groups') {
|
||||
return flattenOptions(r.data.groups)
|
||||
.map(opt => ({
|
||||
value: `${country}|group:${opt.value}`,
|
||||
label: opt.label,
|
||||
}))
|
||||
.sort((a, b) => a.label.localeCompare(b.label))
|
||||
}
|
||||
|
||||
return flattenOptions(r.data.subdivisions)
|
||||
.map(opt => ({ value: opt.value, label: opt.label }))
|
||||
.sort((a, b) => a.label.localeCompare(b.label))
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Shared visual treatment for school-holiday days, used by the desktop month card
|
||||
// (VacayMonthCard) and the mobile month grid (vacayDayModel/MVacayMonth) so both
|
||||
// surfaces render the layer identically.
|
||||
|
||||
/**
|
||||
* Bottom accent band for a school-holiday day: a single rounded bar in the
|
||||
* calendar colour, split into equal segments when several school calendars
|
||||
* cover the same day (capped at three).
|
||||
*/
|
||||
export function schoolHolidayBand(colors: string[]): string {
|
||||
if (colors.length === 0) return 'transparent'
|
||||
if (colors.length === 1) return colors[0]
|
||||
const seg = colors.slice(0, 3)
|
||||
const stops = seg
|
||||
.map((c, i) => `${c} ${Math.round((i * 100) / seg.length)}% ${Math.round(((i + 1) * 100) / seg.length)}%`)
|
||||
.join(', ')
|
||||
return `linear-gradient(90deg, ${stops})`
|
||||
}
|
||||
|
||||
/**
|
||||
* Soft background wash for a plain day that falls inside a school break — light
|
||||
* enough to read as a gentle range highlight without competing with the stronger
|
||||
* public-holiday / person fills.
|
||||
*/
|
||||
export function schoolHolidayWash(color: string): string {
|
||||
return `color-mix(in srgb, ${color} 15%, transparent)`
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { schoolHolidayBand } from '../../../components/Vacay/holidayVisual'
|
||||
import { dayVisual, localDateStr, monthLead, type DayVisualContext } from './vacayDayModel'
|
||||
|
||||
interface MVacayMonthProps {
|
||||
@@ -63,6 +64,15 @@ export default function MVacayMonth({
|
||||
style={{ background: '#f97316' }}
|
||||
/>
|
||||
)}
|
||||
{visual.school && visual.school.length > 0 && (
|
||||
<span
|
||||
aria-hidden
|
||||
className={`absolute rounded-full ${
|
||||
mini ? 'inset-x-[2px] bottom-[1.5px] h-[1.5px]' : 'inset-x-[4px] bottom-[3px] h-[2.5px]'
|
||||
}`}
|
||||
style={{ background: schoolHolidayBand(visual.school) }}
|
||||
/>
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { ArrowRightLeft, Building2, Calendar, CalendarX, ChevronDown, Globe, Plus, Trash2, Unlink, X } from 'lucide-react'
|
||||
import { ArrowRightLeft, Building2, Calendar, CalendarX, ChevronDown, Globe, GraduationCap, Plus, Trash2, Unlink, X } from 'lucide-react'
|
||||
import MSheet from '../../components/MSheet'
|
||||
import MIconBtn from '../../components/MIconBtn'
|
||||
import MToggle from '../../components/MToggle'
|
||||
@@ -7,7 +7,8 @@ import { useVacayStore } from '../../../store/vacayStore'
|
||||
import { getIntlLanguage, useTranslation } from '../../../i18n'
|
||||
import { useToast } from '../../../components/shared/Toast'
|
||||
import apiClient from '../../../api/client'
|
||||
import { fetchRegionOptions } from '../../../components/Vacay/holidayRegions'
|
||||
import { fetchRegionOptions, fetchSchoolHolidayRegionOptions } from '../../../components/Vacay/holidayRegions'
|
||||
import { SCHOOL_HOLIDAY_COUNTRY_CONFIG } from '../../../vacay/schoolHolidayCountries'
|
||||
import { FALLBACK_PERSON_COLOR } from './vacayDayModel'
|
||||
import type { VacayHolidayCalendar } from '../../../types'
|
||||
|
||||
@@ -31,6 +32,7 @@ export default function MVacaySettingsSheet({ open, onClose }: MVacaySettingsShe
|
||||
const { plan, updatePlan, addHolidayCalendar, updateHolidayCalendar, deleteHolidayCalendar, isFused, dissolve, users } = useVacayStore()
|
||||
const [countries, setCountries] = useState<Option[]>([])
|
||||
const [showAddForm, setShowAddForm] = useState(false)
|
||||
const [showAddSchoolForm, setShowAddSchoolForm] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
@@ -48,6 +50,12 @@ export default function MVacaySettingsSheet({ open, onClose }: MVacaySettingsShe
|
||||
|
||||
if (!plan) return null
|
||||
|
||||
// Public and school calendars live in the same holiday_calendars list, split by type
|
||||
// (a null type predates the school-holiday feature, so it counts as a public holiday).
|
||||
const publicHolidayCalendars = (plan.holiday_calendars ?? []).filter(cal => (cal.type ?? 'public_holiday') === 'public_holiday')
|
||||
const schoolHolidayCalendars = (plan.holiday_calendars ?? []).filter(cal => cal.type === 'school_holiday')
|
||||
const schoolHolidayCountries = countries.filter(country => country.value in SCHOOL_HOLIDAY_COUNTRY_CONFIG)
|
||||
|
||||
const weekendDays: number[] = plan.weekend_days ? String(plan.weekend_days).split(',').map(Number) : [0, 6]
|
||||
const weekdayChips = [
|
||||
{ day: 1, label: t('vacay.mon') },
|
||||
@@ -167,11 +175,12 @@ export default function MVacaySettingsSheet({ open, onClose }: MVacaySettingsShe
|
||||
</div>
|
||||
{plan.holidays_enabled && (
|
||||
<>
|
||||
{(plan.holiday_calendars ?? []).map(cal => (
|
||||
{publicHolidayCalendars.map(cal => (
|
||||
<CalendarEditor
|
||||
key={cal.id}
|
||||
cal={cal}
|
||||
countries={countries}
|
||||
calendarType="public_holiday"
|
||||
onUpdate={data => updateHolidayCalendar(cal.id, data)}
|
||||
onDelete={() => deleteHolidayCalendar(cal.id)}
|
||||
/>
|
||||
@@ -179,7 +188,8 @@ export default function MVacaySettingsSheet({ open, onClose }: MVacaySettingsShe
|
||||
{showAddForm ? (
|
||||
<AddCalendarDraft
|
||||
countries={countries}
|
||||
onAdd={async data => { await addHolidayCalendar(data); setShowAddForm(false) }}
|
||||
calendarType="public_holiday"
|
||||
onAdd={async data => { await addHolidayCalendar({ ...data, type: 'public_holiday' }); setShowAddForm(false) }}
|
||||
onCancel={() => setShowAddForm(false)}
|
||||
/>
|
||||
) : (
|
||||
@@ -194,6 +204,48 @@ export default function MVacaySettingsSheet({ open, onClose }: MVacaySettingsShe
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<div className="my-2 h-px bg-[color:var(--m-rowbr)]" />
|
||||
|
||||
{/* School holidays + calendar editor */}
|
||||
<div className="flex items-start gap-[11px] py-3">
|
||||
<GraduationCap size={17} strokeWidth={2} className="mt-[1px] flex-none text-m-muted" />
|
||||
<div className="flex-1">
|
||||
<div className="text-[0.84375rem] font-bold">{t('vacay.schoolHolidays')}</div>
|
||||
<div className="font-geist text-[0.65625rem] text-m-muted">{t('vacay.schoolHolidaysHint')}</div>
|
||||
</div>
|
||||
<MToggle checked={plan.school_holidays_enabled} onChange={() => updatePlan({ school_holidays_enabled: !plan.school_holidays_enabled })} ariaLabel={t('vacay.schoolHolidays')} />
|
||||
</div>
|
||||
{plan.school_holidays_enabled && (
|
||||
<>
|
||||
{schoolHolidayCalendars.map(cal => (
|
||||
<CalendarEditor
|
||||
key={cal.id}
|
||||
cal={cal}
|
||||
countries={schoolHolidayCountries}
|
||||
calendarType="school_holiday"
|
||||
onUpdate={data => updateHolidayCalendar(cal.id, data)}
|
||||
onDelete={() => deleteHolidayCalendar(cal.id)}
|
||||
/>
|
||||
))}
|
||||
{showAddSchoolForm ? (
|
||||
<AddCalendarDraft
|
||||
countries={schoolHolidayCountries}
|
||||
calendarType="school_holiday"
|
||||
onAdd={async data => { await addHolidayCalendar({ ...data, type: 'school_holiday' }); setShowAddSchoolForm(false) }}
|
||||
onCancel={() => setShowAddSchoolForm(false)}
|
||||
/>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowAddSchoolForm(true)}
|
||||
className="mt-2 inline-flex items-center gap-[6px] rounded-full border-[1.5px] border-dashed border-[color:var(--m-rowbr)] px-[13px] py-2 font-geist text-[0.6875rem] font-semibold text-m-muted"
|
||||
>
|
||||
<Plus size={12} strokeWidth={2.2} />
|
||||
{t('vacay.addCalendar')}
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Dissolve Fusion */}
|
||||
{isFused && (
|
||||
@@ -282,9 +334,10 @@ function ColorSwatch({ color, onPick }: { color: string; onPick: (color: string)
|
||||
)
|
||||
}
|
||||
|
||||
function CalendarEditor({ cal, countries, onUpdate, onDelete }: {
|
||||
function CalendarEditor({ cal, countries, calendarType = 'public_holiday', onUpdate, onDelete }: {
|
||||
cal: VacayHolidayCalendar
|
||||
countries: Option[]
|
||||
calendarType?: 'public_holiday' | 'school_holiday'
|
||||
onUpdate: (data: { region?: string; color?: string; label?: string | null }) => void
|
||||
onDelete: () => void
|
||||
}) {
|
||||
@@ -297,8 +350,9 @@ function CalendarEditor({ cal, countries, onUpdate, onDelete }: {
|
||||
useEffect(() => { setLabel(cal.label || '') }, [cal.label])
|
||||
useEffect(() => {
|
||||
if (!country) { setRegions([]); return }
|
||||
fetchRegionOptions(country).then(setRegions)
|
||||
}, [country])
|
||||
const load = calendarType === 'school_holiday' ? fetchSchoolHolidayRegionOptions : fetchRegionOptions
|
||||
load(country).then(setRegions)
|
||||
}, [country, calendarType])
|
||||
|
||||
return (
|
||||
<div className="mt-2 rounded-[14px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] p-3">
|
||||
@@ -324,8 +378,9 @@ function CalendarEditor({ cal, countries, onUpdate, onDelete }: {
|
||||
)
|
||||
}
|
||||
|
||||
function AddCalendarDraft({ countries, onAdd, onCancel }: {
|
||||
function AddCalendarDraft({ countries, calendarType = 'public_holiday', onAdd, onCancel }: {
|
||||
countries: Option[]
|
||||
calendarType?: 'public_holiday' | 'school_holiday'
|
||||
onAdd: (data: { region: string; color: string; label: string | null }) => void
|
||||
onCancel: () => void
|
||||
}) {
|
||||
@@ -340,8 +395,9 @@ function AddCalendarDraft({ countries, onAdd, onCancel }: {
|
||||
|
||||
useEffect(() => {
|
||||
if (!country) { setRegions([]); return }
|
||||
fetchRegionOptions(country).then(setRegions)
|
||||
}, [country])
|
||||
const load = calendarType === 'school_holiday' ? fetchSchoolHolidayRegionOptions : fetchRegionOptions
|
||||
load(country).then(setRegions)
|
||||
}, [country, calendarType])
|
||||
|
||||
const canAdd = Boolean(country) && (regions.length === 0 || selectedRegion !== '')
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { schoolHolidayWash } from '../../../components/Vacay/holidayVisual'
|
||||
import type { HolidaysMap, VacayEntry } from '../../../types'
|
||||
|
||||
// Users created before picking a color have color=null; same fallback the
|
||||
@@ -10,6 +11,9 @@ export interface DayVisual {
|
||||
boxShadow?: string
|
||||
// At least one person logged this day as a half day (#552) — the cell shows a ½ badge.
|
||||
half?: boolean
|
||||
// Colours of the school-holiday calendars covering this day — drawn as a rounded
|
||||
// accent band under the number, on top of whatever fill the cell already has.
|
||||
school?: string[]
|
||||
}
|
||||
|
||||
export interface DayVisualContext {
|
||||
@@ -84,11 +88,19 @@ export function splitBackground(colors: string[]): string {
|
||||
* theme-independent surfaces.
|
||||
*/
|
||||
function baseDayVisual(dateStr: string, dayOfWeek: number, ctx: DayVisualContext): DayVisual {
|
||||
const holidayMarkers = ctx.holidays[dateStr]
|
||||
const holidays = Array.isArray(holidayMarkers) ? holidayMarkers : holidayMarkers ? [holidayMarkers] : []
|
||||
const publicHoliday = holidays.find(holiday => (holiday.type ?? 'public_holiday') === 'public_holiday')
|
||||
const schoolColors = holidays.filter(holiday => holiday.type === 'school_holiday').map(holiday => holiday.color)
|
||||
// The school band sits on top of any fill (person / company / public), so tag it
|
||||
// onto whatever visual this day resolves to rather than picking a single winner.
|
||||
const withSchool = (v: DayVisual): DayVisual => (schoolColors.length > 0 ? { ...v, school: schoolColors } : v)
|
||||
|
||||
if (dateStr === ctx.todayStr) {
|
||||
return { background: 'transparent', numColor: 'var(--m-ink)', boxShadow: 'inset 0 0 0 1.5px var(--m-ink)' }
|
||||
return withSchool({ background: 'transparent', numColor: 'var(--m-ink)', boxShadow: 'inset 0 0 0 1.5px var(--m-ink)' })
|
||||
}
|
||||
if (ctx.companyHolidaysEnabled && ctx.companyHolidaySet.has(dateStr)) {
|
||||
return { background: '#F5D9A6', numColor: '#8A5A00' }
|
||||
return withSchool({ background: '#F5D9A6', numColor: '#8A5A00' })
|
||||
}
|
||||
const entries = ctx.entryMap[dateStr]
|
||||
if (entries && entries.length > 0) {
|
||||
@@ -98,11 +110,14 @@ function baseDayVisual(dateStr: string, dayOfWeek: number, ctx: DayVisualContext
|
||||
// true so full days keep their exact { background, numColor } shape.
|
||||
const visual: DayVisual = { background: tints.length === 1 ? tints[0] : splitBackground(tints), numColor: '#101013' }
|
||||
if (entries.some(e => (e.fraction ?? 1) === 0.5)) visual.half = true
|
||||
return visual
|
||||
return withSchool(visual)
|
||||
}
|
||||
const holiday = ctx.holidays[dateStr]
|
||||
if (holiday) {
|
||||
return { background: holiday.color, numColor: holidayInk(holiday.color) }
|
||||
if (publicHoliday) {
|
||||
return withSchool({ background: publicHoliday.color, numColor: holidayInk(publicHoliday.color) })
|
||||
}
|
||||
// Plain school-break day: soft wash + readable tinted ink, matching the desktop card.
|
||||
if (schoolColors.length > 0) {
|
||||
return { background: schoolHolidayWash(schoolColors[0]), numColor: holidayInk(schoolColors[0]), school: schoolColors }
|
||||
}
|
||||
if (ctx.weekendDays.includes(dayOfWeek)) {
|
||||
return { background: 'var(--m-ic)', numColor: 'var(--m-faint)' }
|
||||
|
||||
@@ -94,14 +94,17 @@ function VacayPageDesktop(): React.ReactElement {
|
||||
<VacaySharedCalendars />
|
||||
|
||||
{/* Legend */}
|
||||
{(plan?.holidays_enabled || plan?.company_holidays_enabled || plan?.block_weekends || hasVisibleShared) && (
|
||||
{(plan?.holidays_enabled || plan?.school_holidays_enabled || plan?.company_holidays_enabled || plan?.block_weekends || hasVisibleShared) && (
|
||||
<div className="vg-card rounded-[22px]" style={{ padding: '14px 18px' }}>
|
||||
<span style={{ fontSize: 11, fontWeight: 600, textTransform: 'uppercase', letterSpacing: '0.14em', color: 'var(--vg-ink3)' }}>{t('vacay.legend')}</span>
|
||||
<div className="mt-3 flex flex-wrap gap-x-3.5 gap-y-2.5">
|
||||
{plan?.holidays_enabled && (plan?.holiday_calendars ?? []).length === 0 && (
|
||||
{plan?.holidays_enabled && (plan?.holiday_calendars ?? []).filter(cal => (cal.type ?? 'public_holiday') === 'public_holiday').length === 0 && (
|
||||
<LegendItem color="#fecaca" label={t('vacay.publicHoliday')} />
|
||||
)}
|
||||
{plan?.holidays_enabled && (plan?.holiday_calendars ?? []).map(cal => (
|
||||
{plan?.holidays_enabled && (plan?.holiday_calendars ?? []).filter(cal => (cal.type ?? 'public_holiday') === 'public_holiday').map(cal => (
|
||||
<LegendItem key={cal.id} color={cal.color} label={cal.label || cal.region} />
|
||||
))}
|
||||
{plan?.school_holidays_enabled && (plan?.holiday_calendars ?? []).filter(cal => cal.type === 'school_holiday').map(cal => (
|
||||
<LegendItem key={cal.id} color={cal.color} label={cal.label || cal.region} />
|
||||
))}
|
||||
{plan?.company_holidays_enabled && <LegendItem color="#fde68a" label={t('vacay.companyHoliday')} />}
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
VacayPlan, VacayUser, VacayEntry, VacayStat, HolidaysMap, HolidayInfo, VacayHolidayCalendar,
|
||||
VacayShareOutgoing, VacayShareIncoming, SharedVacayCalendar,
|
||||
} from '../types'
|
||||
import { isSchoolHolidayCountrySupported } from '../vacay/schoolHolidayCountries'
|
||||
import type {
|
||||
VacaySetColorRequest, VacayInviteRequest, VacayInviteActionRequest,
|
||||
VacayAddYearRequest, VacayToggleEntryRequest, VacayCompanyHolidayRequest,
|
||||
@@ -54,6 +55,12 @@ interface VacayHolidayRaw {
|
||||
counties: string[] | null
|
||||
}
|
||||
|
||||
interface VacaySchoolHolidayRaw {
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
name?: string | { language?: string; text?: string }[]
|
||||
}
|
||||
|
||||
interface VacayApi {
|
||||
getPlan: () => Promise<VacayPlanResponse>
|
||||
updatePlan: (data: Partial<VacayPlan>) => Promise<{ plan: VacayPlan }>
|
||||
@@ -74,8 +81,9 @@ interface VacayApi {
|
||||
updateStats: (year: number, days: number, targetUserId?: number) => Promise<unknown>
|
||||
getCountries: () => Promise<{ countries: string[] }>
|
||||
getHolidays: (year: number, country: string) => Promise<VacayHolidayRaw[]>
|
||||
addHolidayCalendar: (data: { region: string; color?: string; label?: string | null }) => Promise<{ calendar: VacayHolidayCalendar }>
|
||||
updateHolidayCalendar: (id: number, data: { region?: string; color?: string; label?: string | null }) => Promise<{ calendar: VacayHolidayCalendar }>
|
||||
getSchoolHolidays: (year: number, country: string, subdivision?: string | null, group?: string | null) => Promise<VacaySchoolHolidayRaw[]>
|
||||
addHolidayCalendar: (data: { region: string; color?: string; label?: string | null; type?: 'public_holiday' | 'school_holiday' }) => Promise<{ calendar: VacayHolidayCalendar }>
|
||||
updateHolidayCalendar: (id: number, data: { region?: string; color?: string; label?: string | null; type?: 'public_holiday' | 'school_holiday' }) => Promise<{ calendar: VacayHolidayCalendar }>
|
||||
deleteHolidayCalendar: (id: number) => Promise<unknown>
|
||||
getShares: () => Promise<{ outgoing: VacayShareOutgoing[]; incoming: VacayShareIncoming[] }>
|
||||
share: (userId: number) => Promise<unknown>
|
||||
@@ -105,6 +113,12 @@ const api: VacayApi = {
|
||||
updateStats: (year, days, targetUserId) => ax.put(`/addons/vacay/stats/${year}`, { vacation_days: days, target_user_id: targetUserId } satisfies VacayUpdateStatsRequest).then((r: AxiosResponse) => r.data),
|
||||
getCountries: () => ax.get('/addons/vacay/holidays/countries').then((r: AxiosResponse) => r.data),
|
||||
getHolidays: (year, country) => ax.get(`/addons/vacay/holidays/${year}/${country}`).then((r: AxiosResponse) => r.data),
|
||||
getSchoolHolidays: (year, country, subdivision, group) => {
|
||||
const params = new URLSearchParams()
|
||||
if (group) params.set('group', group)
|
||||
const qs = params.toString()
|
||||
return ax.get(`/addons/vacay/school-holidays/${year}/${country}${subdivision ? `/${subdivision}` : ''}${qs ? `?${qs}` : ''}`).then((r: AxiosResponse) => r.data)
|
||||
},
|
||||
addHolidayCalendar: (data) => ax.post('/addons/vacay/plan/holiday-calendars', data).then((r: AxiosResponse) => r.data),
|
||||
updateHolidayCalendar: (id, data) => ax.put(`/addons/vacay/plan/holiday-calendars/${id}`, data).then((r: AxiosResponse) => r.data),
|
||||
deleteHolidayCalendar: (id) => ax.delete(`/addons/vacay/plan/holiday-calendars/${id}`).then((r: AxiosResponse) => r.data),
|
||||
@@ -116,6 +130,42 @@ const api: VacayApi = {
|
||||
getSharedCalendars: (year) => ax.get(`/addons/vacay/shares/calendars/${year}`).then((r: AxiosResponse) => r.data),
|
||||
}
|
||||
|
||||
function pushHolidayMarker(map: HolidaysMap, date: string, marker: HolidayInfo) {
|
||||
const existing = map[date]
|
||||
if (!existing) {
|
||||
map[date] = [marker]
|
||||
return
|
||||
}
|
||||
map[date] = Array.isArray(existing) ? [...existing, marker] : [existing, marker]
|
||||
}
|
||||
|
||||
function parseCalendarRegion(region: string): { country: string; subdivision: string | null; group: string | null } {
|
||||
const [base, meta] = region.split('|')
|
||||
const group = meta?.startsWith('group:') ? meta.slice('group:'.length) : null
|
||||
return {
|
||||
country: base.split('-')[0],
|
||||
subdivision: group ? null : base.includes('-') ? base : null,
|
||||
group,
|
||||
}
|
||||
}
|
||||
|
||||
function schoolHolidayName(h: VacaySchoolHolidayRaw): string {
|
||||
if (typeof h.name === 'string') return h.name
|
||||
const names = Array.isArray(h.name) ? h.name : []
|
||||
return names.find(n => n.language?.toUpperCase() === 'DE')?.text || names[0]?.text || 'School holidays'
|
||||
}
|
||||
|
||||
function datesBetween(startStr: string, endStr: string): string[] {
|
||||
const dates: string[] = []
|
||||
const start = new Date(startStr + 'T00:00:00')
|
||||
const end = new Date(endStr + 'T00:00:00')
|
||||
if (Number.isNaN(start.getTime()) || Number.isNaN(end.getTime())) return dates
|
||||
for (let d = new Date(start); d <= end; d.setDate(d.getDate() + 1)) {
|
||||
dates.push(`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`)
|
||||
}
|
||||
return dates
|
||||
}
|
||||
|
||||
interface VacayState {
|
||||
plan: VacayPlan | null
|
||||
users: VacayUser[]
|
||||
@@ -154,8 +204,8 @@ interface VacayState {
|
||||
loadStats: (year?: number) => Promise<void>
|
||||
updateVacationDays: (year: number, days: number, targetUserId?: number) => Promise<void>
|
||||
loadHolidays: (year?: number) => Promise<void>
|
||||
addHolidayCalendar: (data: { region: string; color?: string; label?: string | null }) => Promise<void>
|
||||
updateHolidayCalendar: (id: number, data: { region?: string; color?: string; label?: string | null }) => Promise<void>
|
||||
addHolidayCalendar: (data: { region: string; color?: string; label?: string | null; type?: 'public_holiday' | 'school_holiday' }) => Promise<void>
|
||||
updateHolidayCalendar: (id: number, data: { region?: string; color?: string; label?: string | null; type?: 'public_holiday' | 'school_holiday' }) => Promise<void>
|
||||
deleteHolidayCalendar: (id: number) => Promise<void>
|
||||
loadShares: () => Promise<void>
|
||||
loadSharedCalendars: (year?: number) => Promise<void>
|
||||
@@ -331,25 +381,38 @@ export const useVacayStore = create<VacayState>((set, get) => ({
|
||||
const y = year || get().selectedYear
|
||||
const plan = get().plan
|
||||
const calendars = plan?.holiday_calendars ?? []
|
||||
if (!plan?.holidays_enabled || calendars.length === 0) {
|
||||
const enabledCalendars = calendars.filter(cal =>
|
||||
(cal.type === 'school_holiday' && plan?.school_holidays_enabled) ||
|
||||
((cal.type ?? 'public_holiday') === 'public_holiday' && plan?.holidays_enabled)
|
||||
)
|
||||
if (enabledCalendars.length === 0) {
|
||||
set({ holidays: {} })
|
||||
return
|
||||
}
|
||||
const map: HolidaysMap = {}
|
||||
for (const cal of calendars) {
|
||||
const country = cal.region.split('-')[0]
|
||||
const region = cal.region.includes('-') ? cal.region : null
|
||||
for (const cal of enabledCalendars) {
|
||||
const { country, subdivision, group } = parseCalendarRegion(cal.region)
|
||||
try {
|
||||
const data = await api.getHolidays(y, country)
|
||||
const hasRegions = data.some((h: VacayHolidayRaw) => h.counties && h.counties.length > 0)
|
||||
if (hasRegions && !region) continue
|
||||
data.forEach((h: VacayHolidayRaw) => {
|
||||
if (h.global || !h.counties || (region && h.counties.includes(region))) {
|
||||
if (!map[h.date]) {
|
||||
map[h.date] = { name: h.name, localName: h.localName, color: cal.color, label: cal.label }
|
||||
if ((cal.type ?? 'public_holiday') === 'school_holiday') {
|
||||
if (!isSchoolHolidayCountrySupported(country)) continue
|
||||
const data = await api.getSchoolHolidays(y, country, subdivision, group)
|
||||
data.forEach((h: VacaySchoolHolidayRaw) => {
|
||||
if (!h.startDate) return
|
||||
const name = schoolHolidayName(h)
|
||||
datesBetween(h.startDate, h.endDate || h.startDate).filter(date => date.startsWith(`${y}-`)).forEach(date => {
|
||||
pushHolidayMarker(map, date, { name, localName: name, color: cal.color, label: cal.label, type: 'school_holiday' })
|
||||
})
|
||||
})
|
||||
} else {
|
||||
const data = await api.getHolidays(y, country)
|
||||
const hasRegions = data.some((h: VacayHolidayRaw) => h.counties && h.counties.length > 0)
|
||||
if (hasRegions && !subdivision) continue
|
||||
data.forEach((h: VacayHolidayRaw) => {
|
||||
if (h.global || !h.counties || (subdivision && h.counties.includes(subdivision))) {
|
||||
pushHolidayMarker(map, h.date, { name: h.name, localName: h.localName, color: cal.color, label: cal.label, type: 'public_holiday' })
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
} catch { /* API error, skip */ }
|
||||
}
|
||||
set({ holidays: map })
|
||||
|
||||
+4
-1
@@ -266,6 +266,7 @@ export interface WebSocketEvent {
|
||||
export interface VacayHolidayCalendar {
|
||||
id: number
|
||||
plan_id: number
|
||||
type?: 'public_holiday' | 'school_holiday'
|
||||
region: string
|
||||
label: string | null
|
||||
color: string
|
||||
@@ -275,6 +276,7 @@ export interface VacayHolidayCalendar {
|
||||
export interface VacayPlan {
|
||||
id: number
|
||||
holidays_enabled: boolean
|
||||
school_holidays_enabled?: boolean
|
||||
holidays_region: string | null
|
||||
holiday_calendars: VacayHolidayCalendar[]
|
||||
block_weekends: boolean
|
||||
@@ -326,10 +328,11 @@ export interface HolidayInfo {
|
||||
localName: string
|
||||
color: string
|
||||
label: string | null
|
||||
type?: 'public_holiday' | 'school_holiday'
|
||||
}
|
||||
|
||||
export interface HolidaysMap {
|
||||
[date: string]: HolidayInfo
|
||||
[date: string]: HolidayInfo | HolidayInfo[]
|
||||
}
|
||||
|
||||
// Read-only calendar shares (#444/#667)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
export type SchoolHolidayStrategy = 'country' | 'groups' | 'subdivisions'
|
||||
|
||||
// OpenHolidays models school holidays differently per country. Keep this list
|
||||
// explicit so new countries are only exposed after source coverage was checked.
|
||||
export const SCHOOL_HOLIDAY_COUNTRY_CONFIG: Record<string, { strategy: SchoolHolidayStrategy; status: 'green' | 'yellow' }> = {
|
||||
AT: { strategy: 'subdivisions', status: 'green' },
|
||||
BE: { strategy: 'groups', status: 'yellow' },
|
||||
CH: { strategy: 'subdivisions', status: 'yellow' },
|
||||
CZ: { strategy: 'subdivisions', status: 'green' },
|
||||
DE: { strategy: 'subdivisions', status: 'yellow' },
|
||||
EE: { strategy: 'country', status: 'green' },
|
||||
ES: { strategy: 'subdivisions', status: 'green' },
|
||||
FR: { strategy: 'subdivisions', status: 'green' },
|
||||
IE: { strategy: 'country', status: 'yellow' },
|
||||
IT: { strategy: 'subdivisions', status: 'yellow' },
|
||||
NL: { strategy: 'groups', status: 'yellow' },
|
||||
PL: { strategy: 'subdivisions', status: 'yellow' },
|
||||
PT: { strategy: 'subdivisions', status: 'green' },
|
||||
RS: { strategy: 'country', status: 'yellow' },
|
||||
SI: { strategy: 'subdivisions', status: 'yellow' },
|
||||
SK: { strategy: 'subdivisions', status: 'yellow' },
|
||||
}
|
||||
|
||||
export function isSchoolHolidayCountrySupported(country: string): boolean {
|
||||
return country in SCHOOL_HOLIDAY_COUNTRY_CONFIG
|
||||
}
|
||||
Reference in New Issue
Block a user