mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +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:
@@ -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)' }
|
||||
|
||||
Reference in New Issue
Block a user