mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +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)`
|
||||
}
|
||||
Reference in New Issue
Block a user