mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 18:04:18 +00:00
* feat(vacay): read-only calendar shares on the server (#444, #667) * feat(vacay): shared calendars card and ring overlay on desktop * feat(vacay): share sheet and calendar rings on mobile * test(vacay): cover the calendar share flows * docs(vacay): document read-only calendar sharing
This commit is contained in:
@@ -38,6 +38,7 @@ const EVENT_LABEL_KEYS: Record<string, string> = {
|
||||
trip_reminder: 'settings.notifyTripReminder',
|
||||
todo_due: 'settings.notifyTodoDue',
|
||||
vacay_invite: 'settings.notifyVacayInvite',
|
||||
vacay_share: 'settings.notifyVacayShare',
|
||||
photos_shared: 'settings.notifyPhotosShared',
|
||||
collab_message: 'settings.notifyCollabMessage',
|
||||
packing_tagged: 'settings.notifyPackingTagged',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Building2, ChevronLeft, ChevronRight, Eye, Minus, PenLine, Pencil, Plus, Settings2, ShieldCheck, Trash2, Unlink, UserPlus } from 'lucide-react'
|
||||
import { Building2, ChevronLeft, ChevronRight, Eye, Minus, PenLine, Pencil, Plus, Settings2, Share2, ShieldCheck, Trash2, Unlink, UserPlus } from 'lucide-react'
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import MSheet from '../../components/MSheet'
|
||||
import MIconBtn from '../../components/MIconBtn'
|
||||
@@ -8,6 +8,7 @@ import { useMVacay } from './useMVacay'
|
||||
import MVacayMonth from './MVacayMonth'
|
||||
import MVacayInviteSheet from './MVacayInviteSheet'
|
||||
import MVacaySettingsSheet from './MVacaySettingsSheet'
|
||||
import MVacayShareSheet from './MVacayShareSheet'
|
||||
import { FALLBACK_PERSON_COLOR } from './vacayDayModel'
|
||||
|
||||
const WEEKDAY_KEYS_MONDAY = ['vacay.mon', 'vacay.tue', 'vacay.wed', 'vacay.thu', 'vacay.fri', 'vacay.sat', 'vacay.sun'] as const
|
||||
@@ -46,6 +47,9 @@ export default function MVacay() {
|
||||
<MIconBtn onClick={() => v.setSheet('invite')} ariaLabel={t('vacay.inviteUser')}>
|
||||
<UserPlus size={16} strokeWidth={2} className="text-m-muted" />
|
||||
</MIconBtn>
|
||||
<MIconBtn onClick={() => v.setSheet('share')} ariaLabel={t('vacay.sharedCalendars')}>
|
||||
<Share2 size={16} strokeWidth={2} className="text-m-muted" />
|
||||
</MIconBtn>
|
||||
<span className="flex flex-1 items-center justify-between rounded-full border border-[color:var(--m-gbr)] bg-[color:var(--m-sheet)] p-1 shadow-[0_5px_12px_-8px_rgba(0,0,0,.18)]">
|
||||
<button type="button" onClick={v.prevYear} aria-label={t('mobileVacay.prevYear')} className="flex h-[34px] w-[34px] flex-none items-center justify-center rounded-full">
|
||||
<ChevronLeft size={17} strokeWidth={2.2} />
|
||||
@@ -135,6 +139,22 @@ export default function MVacay() {
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
{/* Shared read-only calendars: tap toggles that person's ring overlay. */}
|
||||
{v.incomingShares.map(s => (
|
||||
<button
|
||||
key={`share-${s.id}`}
|
||||
type="button"
|
||||
onClick={() => v.toggleShareHidden(s.id, !s.hidden)}
|
||||
aria-pressed={!s.hidden}
|
||||
className="box-border inline-flex min-w-0 flex-[1_1_calc(25%-6px)] items-center justify-center gap-1 rounded-full px-1 py-1 font-geist text-[0.625rem] font-bold"
|
||||
style={s.hidden
|
||||
? { background: 'var(--m-sheetop)', border: '1px solid var(--m-rowbr)', color: 'var(--m-faint)', opacity: 0.7 }
|
||||
: { background: `${s.color}1f`, border: `1px solid ${s.color}`, color: 'var(--m-ink)' }}
|
||||
>
|
||||
<span className="h-[9px] w-[9px] flex-none rounded-[3px]" style={{ border: `2px solid ${s.color}` }} />
|
||||
<span className="truncate">{s.username}</span>
|
||||
</button>
|
||||
))}
|
||||
{v.companyHolidaysEnabled && (
|
||||
<LegendChip color="#F5D9A6" label={t('mobileVacay.companyLegend')} />
|
||||
)}
|
||||
@@ -280,6 +300,7 @@ export default function MVacay() {
|
||||
{/* Sheets */}
|
||||
<MVacayInviteSheet open={v.sheet === 'invite'} onClose={() => v.setSheet(null)} />
|
||||
<MVacaySettingsSheet open={v.sheet === 'settings'} onClose={() => v.setSheet(null)} />
|
||||
<MVacayShareSheet open={v.sheet === 'share'} onClose={() => v.setSheet(null)} />
|
||||
<MVacayIncomingInvite
|
||||
invites={v.incomingInvites}
|
||||
onAccept={v.acceptInvite}
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { ChevronDown, Eye, EyeOff, Loader2, Share2, X } from 'lucide-react'
|
||||
import MSheet from '../../components/MSheet'
|
||||
import MIconBtn from '../../components/MIconBtn'
|
||||
import { useVacayStore } from '../../../store/vacayStore'
|
||||
import { useTranslation } from '../../../i18n'
|
||||
import { useToast } from '../../../components/shared/Toast'
|
||||
import { getApiErrorMessage } from '../../../types'
|
||||
import apiClient from '../../../api/client'
|
||||
|
||||
interface MVacayShareSheetProps {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Read-only calendar sharing sheet (#444/#667): share your own calendar with
|
||||
* another TREK user (view only, no fusion), see who shares with you (with a
|
||||
* per-person overlay eye toggle) and stop shares in both directions.
|
||||
*/
|
||||
export default function MVacayShareSheet({ open, onClose }: MVacayShareSheetProps) {
|
||||
const { t } = useTranslation()
|
||||
const toast = useToast()
|
||||
const { incomingShares, outgoingShares, shareWith, removeShare, setShareHidden } = useVacayStore()
|
||||
const [available, setAvailable] = useState<{ id: number; username: string }[]>([])
|
||||
const [selected, setSelected] = useState<number | null>(null)
|
||||
const [pickerOpen, setPickerOpen] = useState(false)
|
||||
const [sending, setSending] = useState(false)
|
||||
|
||||
const showError = (err: unknown) => toast.error(getApiErrorMessage(err, t('vacay.shareFailed')))
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
setSelected(null)
|
||||
setPickerOpen(false)
|
||||
apiClient.get('/addons/vacay/shares/available-users')
|
||||
.then(r => setAvailable(r.data.users))
|
||||
.catch(() => setAvailable([]))
|
||||
}, [open])
|
||||
|
||||
const selectedUser = available.find(u => u.id === selected)
|
||||
|
||||
const handleShare = async () => {
|
||||
if (!selected) return
|
||||
setSending(true)
|
||||
try {
|
||||
await shareWith(selected)
|
||||
toast.success(t('vacay.shareSent'))
|
||||
setSelected(null)
|
||||
} catch (err: unknown) {
|
||||
toast.error(getApiErrorMessage(err, t('vacay.shareFailed')))
|
||||
} finally {
|
||||
setSending(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<MSheet open={open} onClose={onClose} variant="card" material="glass" ariaLabel={t('vacay.sharedCalendars')}>
|
||||
<div className="px-[18px] pb-[18px] pt-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex-1 text-[1.0625rem] font-bold">{t('vacay.sharedCalendars')}</div>
|
||||
<MIconBtn variant="neutral" size={34} onClick={onClose} ariaLabel={t('common.close')}>
|
||||
<X size={15} strokeWidth={2.2} />
|
||||
</MIconBtn>
|
||||
</div>
|
||||
<div className="mb-3 mt-2 font-geist text-[0.75rem] leading-normal text-m-muted">
|
||||
{t('vacay.shareCalendarHint')}
|
||||
</div>
|
||||
|
||||
{available.length === 0 ? (
|
||||
<div className="rounded-[14px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] px-[14px] py-3 text-center font-geist text-[0.75rem] text-m-faint">
|
||||
{t('vacay.noUsersAvailable')}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setPickerOpen(o => !o)}
|
||||
className="flex min-w-0 flex-1 items-center gap-[9px] rounded-[14px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] px-[14px] py-3 text-[0.8125rem] font-semibold"
|
||||
>
|
||||
<span className={`min-w-0 flex-1 truncate text-left ${selectedUser ? '' : 'text-m-muted'}`}>
|
||||
{selectedUser ? selectedUser.username : t('vacay.selectUser')}
|
||||
</span>
|
||||
<ChevronDown size={14} strokeWidth={2} className="flex-none text-m-faint" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleShare}
|
||||
disabled={!selected || sending}
|
||||
className="flex flex-none items-center gap-[6px] rounded-full bg-m-act px-4 py-[10px] text-[0.78125rem] font-semibold text-m-actfg disabled:opacity-40"
|
||||
>
|
||||
{sending ? <Loader2 size={13} className="animate-spin" /> : <Share2 size={13} strokeWidth={2.2} />}
|
||||
{t('vacay.share')}
|
||||
</button>
|
||||
</div>
|
||||
{pickerOpen && (
|
||||
<div className="mt-[6px] max-h-[180px] overflow-y-auto rounded-[14px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-sheetop)] p-[6px]">
|
||||
{available.map(u => (
|
||||
<button
|
||||
key={u.id}
|
||||
type="button"
|
||||
onClick={() => { setSelected(u.id); setPickerOpen(false) }}
|
||||
className={`flex w-full items-center gap-[9px] rounded-[10px] px-[10px] py-[9px] text-left text-[0.8125rem] font-semibold ${
|
||||
u.id === selected ? 'bg-[color:var(--m-ic)]' : ''
|
||||
}`}
|
||||
>
|
||||
<span className="min-w-0 flex-1 truncate">{u.username}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{incomingShares.length > 0 && (
|
||||
<div className="mt-3 flex flex-col gap-[6px]">
|
||||
<div className="px-1 font-geist text-[0.625rem] font-bold uppercase tracking-[.06em] text-m-faint">
|
||||
{t('vacay.sharedWithYou')}
|
||||
</div>
|
||||
{incomingShares.map(s => (
|
||||
<div key={s.id} className="flex items-center gap-[9px] rounded-[14px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-sheetop)] px-[14px] py-[10px]">
|
||||
<span className="h-[11px] w-[11px] flex-none rounded-full" style={{ border: `2.5px solid ${s.color}` }} />
|
||||
<span className={`min-w-0 flex-1 truncate text-[0.8125rem] font-semibold ${s.hidden ? 'text-m-faint' : ''}`}>
|
||||
{s.username}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShareHidden(s.id, !s.hidden).catch(showError)}
|
||||
aria-label={s.hidden ? t('vacay.showInCalendar') : t('vacay.hideFromCalendar')}
|
||||
className="flex h-[28px] w-[28px] flex-none items-center justify-center rounded-full bg-[color:var(--m-ic)]"
|
||||
>
|
||||
{s.hidden
|
||||
? <EyeOff size={13} strokeWidth={2.2} className="text-m-faint" />
|
||||
: <Eye size={13} strokeWidth={2.2} className="text-m-muted" />}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeShare(s.id).catch(showError)}
|
||||
className="flex-none rounded-full px-[8px] py-1 font-geist text-[0.6875rem] font-semibold text-m-muted"
|
||||
>
|
||||
{t('vacay.remove')}
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{outgoingShares.length > 0 && (
|
||||
<div className="mt-3 flex flex-col gap-[6px]">
|
||||
<div className="px-1 font-geist text-[0.625rem] font-bold uppercase tracking-[.06em] text-m-faint">
|
||||
{t('vacay.youShareWith')}
|
||||
</div>
|
||||
{outgoingShares.map(s => (
|
||||
<div key={s.id} className="flex items-center gap-[9px] rounded-[14px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-sheetop)] px-[14px] py-[10px]">
|
||||
<Share2 size={13} strokeWidth={2} className="flex-none text-m-faint" />
|
||||
<span className="min-w-0 flex-1 truncate text-[0.8125rem] font-semibold">{s.username}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeShare(s.id).catch(showError)}
|
||||
className="flex-none rounded-full px-[10px] py-1 font-geist text-[0.6875rem] font-semibold text-m-muted"
|
||||
>
|
||||
{t('vacay.stopSharing')}
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</MSheet>
|
||||
)
|
||||
}
|
||||
@@ -4,14 +4,15 @@ import { useVacay } from '../../../pages/vacay/useVacay'
|
||||
import { useVacayStore } from '../../../store/vacayStore'
|
||||
import { useAuthStore } from '../../../store/authStore'
|
||||
import { useTranslation } from '../../../i18n'
|
||||
import { useToast } from '../../../components/shared/Toast'
|
||||
import { tripsApi } from '../../../api/client'
|
||||
import { isWeekend } from '../../../components/Vacay/holidays'
|
||||
import { FALLBACK_PERSON_COLOR, localDateStr, type DayVisualContext } from './vacayDayModel'
|
||||
import type { Trip } from '../../../types'
|
||||
import { getApiErrorMessage, type Trip } from '../../../types'
|
||||
|
||||
export type MVacayView = 'grid' | 'edit'
|
||||
export type MVacayMode = 'vacation' | 'company'
|
||||
export type MVacaySheet = 'invite' | 'settings' | null
|
||||
export type MVacaySheet = 'invite' | 'settings' | 'share' | null
|
||||
|
||||
/**
|
||||
* Screen state of the mobile Vacay experience. Data loading, WebSocket sync
|
||||
@@ -20,7 +21,8 @@ export type MVacaySheet = 'invite' | 'settings' | null
|
||||
* mode, sheets) plus the derived per-day render context.
|
||||
*/
|
||||
export function useMVacay() {
|
||||
const { locale } = useTranslation()
|
||||
const { t, locale } = useTranslation()
|
||||
const toast = useToast()
|
||||
const navigate = useNavigate()
|
||||
const {
|
||||
years, selectedYear, setSelectedYear, loading,
|
||||
@@ -31,6 +33,7 @@ export function useMVacay() {
|
||||
entries, companyHolidays, stats, users, holidays,
|
||||
selectedUserId, setSelectedUserId, isFused,
|
||||
toggleEntry, toggleCompanyHoliday, updateVacationDays,
|
||||
incomingShares, sharedCalendars, setShareHidden,
|
||||
} = useVacayStore()
|
||||
const currentUser = useAuthStore(s => s.user)
|
||||
|
||||
@@ -95,9 +98,23 @@ export function useMVacay() {
|
||||
return localDateStr(d.getFullYear(), d.getMonth(), d.getDate())
|
||||
}, [])
|
||||
|
||||
// Shared read-only calendars (#444/#667) overlay as rings; hidden ones stay out.
|
||||
const sharedMap = useMemo(() => {
|
||||
const map: Record<string, { color: string }[]> = {}
|
||||
sharedCalendars.filter(c => !c.hidden).forEach(cal => {
|
||||
const push = (date: string) => {
|
||||
if (!map[date]) map[date] = []
|
||||
map[date].push({ color: cal.color })
|
||||
}
|
||||
cal.entries.forEach(e => push(e.date))
|
||||
cal.companyHolidays.forEach(h => push(h.date))
|
||||
})
|
||||
return map
|
||||
}, [sharedCalendars])
|
||||
|
||||
const dayCtx = useMemo<DayVisualContext>(() => ({
|
||||
todayStr, entryMap, companyHolidaySet, companyHolidaysEnabled, holidays, weekendDays,
|
||||
}), [todayStr, entryMap, companyHolidaySet, companyHolidaysEnabled, holidays, weekendDays])
|
||||
todayStr, entryMap, companyHolidaySet, companyHolidaysEnabled, holidays, weekendDays, sharedMap,
|
||||
}), [todayStr, entryMap, companyHolidaySet, companyHolidaysEnabled, holidays, weekendDays, sharedMap])
|
||||
|
||||
const monthNamesShort = useMemo(() => {
|
||||
const fmt = new Intl.DateTimeFormat(locale, { month: 'short' })
|
||||
@@ -113,6 +130,12 @@ export function useMVacay() {
|
||||
const selectedColor = selectedUser?.color || FALLBACK_PERSON_COLOR
|
||||
const selectedStat = stats.find(s => s.user_id === selectedUserId)
|
||||
|
||||
// Shared-chip tap: the optimistic hide toggle rolls back on server errors —
|
||||
// tell the user instead of letting the chip snap back silently.
|
||||
const toggleShareHidden = useCallback((shareId: number, hidden: boolean) => {
|
||||
setShareHidden(shareId, hidden).catch((err: unknown) => toast.error(getApiErrorMessage(err, t('vacay.shareFailed'))))
|
||||
}, [setShareHidden, toast, t])
|
||||
|
||||
// Fusion: logging for each other — any fused member is selectable.
|
||||
const selectPerson = useCallback((id: number) => {
|
||||
if (isFused || id === currentUser?.id) {
|
||||
@@ -174,6 +197,7 @@ export function useMVacay() {
|
||||
loading, plan, selectedYear,
|
||||
users, isFused, currentUser,
|
||||
incomingInvites, acceptInvite, declineInvite,
|
||||
incomingShares, toggleShareHidden,
|
||||
view, month, mode, halfDay, setHalfDay, sheet, setSheet, setMode, setMonth,
|
||||
tripDates, tripDotColor,
|
||||
blockWeekends, companyHolidaysEnabled, holidaysEnabled, weekStart, weekendDays,
|
||||
|
||||
@@ -19,6 +19,9 @@ export interface DayVisualContext {
|
||||
companyHolidaysEnabled: boolean
|
||||
holidays: HolidaysMap
|
||||
weekendDays: number[]
|
||||
// Shared read-only calendars per date (#444/#667) — drawn as inset rings on
|
||||
// top of whatever the cell shows, never as fills.
|
||||
sharedMap?: Record<string, { color: string }[]>
|
||||
}
|
||||
|
||||
function hexToHsl(hex: string): { h: number; s: number; l: number } | null {
|
||||
@@ -80,7 +83,7 @@ export function splitBackground(colors: string[]): string {
|
||||
* plain. Logged and company cells keep hard dark inks — the pastels are
|
||||
* theme-independent surfaces.
|
||||
*/
|
||||
export function dayVisual(dateStr: string, dayOfWeek: number, ctx: DayVisualContext): DayVisual {
|
||||
function baseDayVisual(dateStr: string, dayOfWeek: number, ctx: DayVisualContext): DayVisual {
|
||||
if (dateStr === ctx.todayStr) {
|
||||
return { background: 'transparent', numColor: 'var(--m-ink)', boxShadow: 'inset 0 0 0 1.5px var(--m-ink)' }
|
||||
}
|
||||
@@ -107,6 +110,20 @@ export function dayVisual(dateStr: string, dayOfWeek: number, ctx: DayVisualCont
|
||||
return { background: 'transparent', numColor: 'var(--m-muted)' }
|
||||
}
|
||||
|
||||
export function dayVisual(dateStr: string, dayOfWeek: number, ctx: DayVisualContext): DayVisual {
|
||||
const visual = baseDayVisual(dateStr, dayOfWeek, ctx)
|
||||
// Shared calendars (#444/#667) draw inset rings over the base cell — capped at
|
||||
// two so tiny mini-grid cells stay readable. Nested inside the today ring.
|
||||
const rings = [...new Set((ctx.sharedMap?.[dateStr] || []).map(m => m.color))].slice(0, 2)
|
||||
if (rings.length > 0) {
|
||||
const shadows = visual.boxShadow ? [visual.boxShadow] : []
|
||||
const base = visual.boxShadow ? 1.5 : 0
|
||||
rings.forEach((c, i) => shadows.push(`inset 0 0 0 ${base + (i + 1) * 1.5}px ${c}`))
|
||||
visual.boxShadow = shadows.join(', ')
|
||||
}
|
||||
return visual
|
||||
}
|
||||
|
||||
/** Empty leading cells before the 1st, honoring the configured week start. */
|
||||
export function monthLead(year: number, month: number, weekStart: number): number {
|
||||
return (new Date(year, month, 1).getDay() - weekStart + 7) % 7
|
||||
|
||||
Reference in New Issue
Block a user