Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions client/src/components/Vacay/VacayCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Building2, MousePointer2 } from 'lucide-react'

export default function VacayCalendar() {
const { t } = useTranslation()
const { selectedYear, selectedUserId, entries, companyHolidays, toggleEntry, toggleCompanyHoliday, plan, users, holidays } = useVacayStore()
const { selectedYear, entries, companyHolidays, foreignEntries, visibleGranterIds, toggleEntry, toggleCompanyHoliday, plan, holidays } = useVacayStore()
const [companyMode, setCompanyMode] = useState(false)
const [tripDates, setTripDates] = useState<Set<string>>(new Set())

Expand Down Expand Up @@ -36,25 +36,33 @@ export default function VacayCalendar() {
}, [selectedYear])

const companyHolidaySet = useMemo(() => {
const s = new Set()
const s = new Set<string>()
companyHolidays.forEach(h => s.add(h.date))
return s
}, [companyHolidays])

const entryMap = useMemo(() => {
const map = {}
const map: Record<string, { date: string; user_id: number; person_color?: string; person_name?: string }[]> = {}
entries.forEach(e => {
if (!map[e.date]) map[e.date] = []
map[e.date].push(e)
})
foreignEntries
.filter(e => visibleGranterIds.includes(e.user_id))
.forEach(e => {
if (!map[e.date]) map[e.date] = []
if (!map[e.date].some(x => x.user_id === e.user_id)) {
map[e.date].push(e)
}
})
return map
}, [entries])
}, [entries, foreignEntries, visibleGranterIds])

const blockWeekends = plan?.block_weekends !== false
const weekendDays: number[] = plan?.weekend_days ? String(plan.weekend_days).split(',').map(Number) : [0, 6]
const companyHolidaysEnabled = plan?.company_holidays_enabled !== false

const handleCellClick = useCallback(async (dateStr) => {
const handleCellClick = useCallback(async (dateStr: string) => {
if (companyMode) {
if (!companyHolidaysEnabled) return
await toggleCompanyHoliday(dateStr)
Expand All @@ -63,10 +71,8 @@ export default function VacayCalendar() {
if (holidays[dateStr]) return
if (blockWeekends && isWeekend(dateStr, weekendDays)) return
if (companyHolidaysEnabled && companyHolidaySet.has(dateStr)) return
await toggleEntry(dateStr, selectedUserId || undefined)
}, [companyMode, toggleEntry, toggleCompanyHoliday, holidays, companyHolidaySet, blockWeekends, companyHolidaysEnabled, selectedUserId])

const selectedUser = users.find(u => u.id === selectedUserId)
await toggleEntry(dateStr)
}, [companyMode, toggleEntry, toggleCompanyHoliday, holidays, companyHolidaySet, blockWeekends, companyHolidaysEnabled])

return (
<div>
Expand Down Expand Up @@ -102,8 +108,7 @@ export default function VacayCalendar() {
border: companyMode ? '1px solid var(--border-primary)' : '1px solid transparent',
}}>
<MousePointer2 size={13} />
{selectedUser && <span className="w-2.5 h-2.5 rounded-full shrink-0" style={{ backgroundColor: selectedUser.color }} />}
{selectedUser ? selectedUser.username : t('vacay.modeVacation')}
{t('vacay.modeVacation')}
</button>
{companyHolidaysEnabled && (
<button
Expand Down
35 changes: 20 additions & 15 deletions client/src/components/Vacay/VacayMonthCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export default function VacayMonthCard({
const isCompany = companyHolidaysEnabled && companyHolidaySet.has(dateStr)
const dayEntries = entryMap[dateStr] || []
const isBlocked = !!holiday || (weekend && blockWeekends) || (isCompany && !companyMode)
// When company holiday and person entries coexist, treat company holiday as a virtual first entry
const COMPANY_COLOR = '#f59e0b'
const displayEntries = isCompany && dayEntries.length > 0
? [{ person_color: COMPANY_COLOR, user_id: -1, date: dateStr }, ...dayEntries]
: dayEntries

return (
<div
Expand All @@ -104,30 +109,30 @@ export default function VacayMonthCard({
onMouseLeave={e => { e.currentTarget.style.background = weekend ? 'var(--bg-secondary)' : 'transparent' }}
>
{holiday && <div className="absolute inset-0.5 rounded" style={{ background: hexToRgba(holiday.color, 0.12) }} />}
{isCompany && <div className="absolute inset-0.5 rounded" style={{ background: 'rgba(245,158,11,0.15)' }} />}
{isCompany && dayEntries.length === 0 && <div className="absolute inset-0.5 rounded" style={{ background: 'rgba(245,158,11,0.15)' }} />}

{dayEntries.length === 1 && (
<div className="absolute inset-0.5 rounded" style={{ backgroundColor: dayEntries[0].person_color, opacity: 0.4 }} />
{displayEntries.length === 1 && (
<div className="absolute inset-0.5 rounded" style={{ backgroundColor: displayEntries[0].person_color, opacity: 0.4 }} />
)}
{dayEntries.length === 2 && (
{displayEntries.length === 2 && (
<div className="absolute inset-0.5 rounded" style={{
background: `linear-gradient(135deg, ${dayEntries[0].person_color} 50%, ${dayEntries[1].person_color} 50%)`,
background: `linear-gradient(135deg, ${displayEntries[0].person_color} 50%, ${displayEntries[1].person_color} 50%)`,
opacity: 0.4,
}} />
)}
{dayEntries.length === 3 && (
{displayEntries.length === 3 && (
<div className="absolute inset-0.5 rounded overflow-hidden" style={{ opacity: 0.4 }}>
<div className="absolute top-0 left-0 w-1/2 h-full" style={{ backgroundColor: dayEntries[0].person_color }} />
<div className="absolute top-0 right-0 w-1/2 h-1/2" style={{ backgroundColor: dayEntries[1].person_color }} />
<div className="absolute bottom-0 right-0 w-1/2 h-1/2" style={{ backgroundColor: dayEntries[2].person_color }} />
<div className="absolute top-0 left-0 w-1/2 h-full" style={{ backgroundColor: displayEntries[0].person_color }} />
<div className="absolute top-0 right-0 w-1/2 h-1/2" style={{ backgroundColor: displayEntries[1].person_color }} />
<div className="absolute bottom-0 right-0 w-1/2 h-1/2" style={{ backgroundColor: displayEntries[2].person_color }} />
</div>
)}
{dayEntries.length >= 4 && (
{displayEntries.length >= 4 && (
<div className="absolute inset-0.5 rounded overflow-hidden" style={{ opacity: 0.4 }}>
<div className="absolute top-0 left-0 w-1/2 h-1/2" style={{ backgroundColor: dayEntries[0].person_color }} />
<div className="absolute top-0 right-0 w-1/2 h-1/2" style={{ backgroundColor: dayEntries[1].person_color }} />
<div className="absolute bottom-0 left-0 w-1/2 h-1/2" style={{ backgroundColor: dayEntries[2].person_color }} />
<div className="absolute bottom-0 right-0 w-1/2 h-1/2" style={{ backgroundColor: dayEntries[3].person_color }} />
<div className="absolute top-0 left-0 w-1/2 h-1/2" style={{ backgroundColor: displayEntries[0].person_color }} />
<div className="absolute top-0 right-0 w-1/2 h-1/2" style={{ backgroundColor: displayEntries[1].person_color }} />
<div className="absolute bottom-0 left-0 w-1/2 h-1/2" style={{ backgroundColor: displayEntries[2].person_color }} />
<div className="absolute bottom-0 right-0 w-1/2 h-1/2" style={{ backgroundColor: displayEntries[3].person_color }} />
</div>
)}

Expand All @@ -137,7 +142,7 @@ export default function VacayMonthCard({

<span className="relative z-[1] text-[11px] font-medium" style={{
color: holiday ? holiday.color : weekend ? 'var(--text-faint)' : 'var(--text-primary)',
fontWeight: dayEntries.length > 0 ? 700 : 500,
fontWeight: displayEntries.length > 0 ? 700 : 500,
}}>
{day}
</span>
Expand Down
Loading
Loading