mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 01:44:13 +00:00
feat(dayplan): a day can be deleted from the reorder dialog, after a warning that says what goes with it
Every row of the reorder dialog, and of the days sheet on a phone, now has a delete button. It first asks, and the question lists what goes with the day: planned places stay in the place list, notes and day texts are deleted, bookings stay without a day, a stay that checks in or out on the day is cancelled with its booking and expense (shown in the danger tone), and on a dated trip the later days and their bookings move one date earlier or the trip ends a day earlier. The server side moved from a bare DELETE into DayRemovalService, which REST, the delete_day tool and the plugin RPC all use. It closes the numbering, keeps the dates on their positions like a reorder, re-stamps the moved bookings, shifts the road trip boundaries, cancels touching stays through the accommodations domain, refuses the last day of a trip, and fans out day:deleted, day:reordered and trip:updated so collaborators renumber and see the new day count and end date. The trip query moved into a leaf file so the days domain can read it without a module cycle. On the client the delete is online only, runs optimistically through the days slice with the same reducer collaborators apply, and the ConfirmDialog gained a slot for extra content, an Escape that only closes itself, and the danger and accent tokens.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import DayImpactList, { type ImpactListSkin } from '../../components/shared/DayImpactList'
|
||||
import type { ImpactLine } from '../../utils/dayImpactLines'
|
||||
|
||||
/** The mobile tokens for the same rows: an inset card with hairlines between rows. */
|
||||
const PHONE: ImpactListSkin = {
|
||||
list: 'mt-3 overflow-hidden rounded-[13px] border border-[color:var(--m-inbr)] bg-[color:var(--m-inner)]',
|
||||
row: 'flex items-start gap-[10px] px-[11px] py-[9px]',
|
||||
divider: 'border-t border-[color:var(--m-rowbr)]',
|
||||
chip: 'mt-[1px] flex h-[26px] w-[26px] flex-none items-center justify-center rounded-full',
|
||||
iconSize: 13,
|
||||
text: 'text-[0.78125rem] font-semibold leading-snug',
|
||||
hint: 'mt-[2px] text-[0.6875rem] leading-snug text-m-muted',
|
||||
chipTone: {
|
||||
neutral: 'bg-[color:var(--m-ic)] text-m-muted',
|
||||
muted: 'bg-[color:var(--m-ic)] text-m-faint',
|
||||
warning: 'bg-[color:color-mix(in_srgb,var(--m-st-pending)_14%,transparent)] text-[color:var(--m-st-pending)]',
|
||||
danger: 'bg-[color:color-mix(in_srgb,var(--m-st-danger)_12%,transparent)] text-[color:var(--m-st-danger)]',
|
||||
},
|
||||
textTone: {
|
||||
neutral: 'text-m-ink',
|
||||
muted: 'text-m-muted',
|
||||
warning: 'text-m-ink',
|
||||
danger: 'text-[color:var(--m-st-danger)]',
|
||||
},
|
||||
}
|
||||
|
||||
/** The phone's day impact list: DayImpactList drawn in the mobile tokens. */
|
||||
export default function MDayImpactList({ lines, label }: { lines: ImpactLine[]; label?: string }) {
|
||||
return <DayImpactList lines={lines} label={label} skin={PHONE} />
|
||||
}
|
||||
@@ -1,33 +1,24 @@
|
||||
import { CalendarRange, Plus } from 'lucide-react'
|
||||
import { CalendarRange, Plus, Trash2 } from 'lucide-react'
|
||||
import MSheet from '../../../components/MSheet'
|
||||
import { ReorderStack } from '../plan/MPlanTimelineRows'
|
||||
import { INNER_CLS, TileHeader } from './MTripSheetUi'
|
||||
import { useTranslation } from '../../../../i18n'
|
||||
import { dayLabel } from '../../../../utils/dayLabel'
|
||||
import type { MTripSheetsProps } from '../MTripShell'
|
||||
import type { Day } from '../../../../types'
|
||||
|
||||
/**
|
||||
* Day management sheet ('days'): move whole days up/down and append a new day —
|
||||
* the mobile counterpart of the desktop DayReorderPopup, button-based like the
|
||||
* rest of the touch reordering (#1432). A day's places, notes and bookings
|
||||
* move with it (store handles that optimistically).
|
||||
* Day management sheet ('days'): move whole days up/down, append a new day or
|
||||
* delete one, the mobile counterpart of the desktop DayReorderPopup and
|
||||
* button-based like the rest of the touch reordering (#1432). A day's places,
|
||||
* notes and bookings move with it (store handles that optimistically). Delete
|
||||
* only asks; the confirm sheet with what goes with the day is MTripSheets'.
|
||||
*/
|
||||
export default function MDaysSheet({ planner, shell }: MTripSheetsProps) {
|
||||
const { t, locale } = useTranslation()
|
||||
const open = shell.sheet?.id === 'days'
|
||||
const canEditDays = planner.can('day_edit', planner.trip)
|
||||
const ordered = [...planner.days].sort((a, b) => (a.day_number ?? 0) - (b.day_number ?? 0))
|
||||
|
||||
const label = (day: Day, index: number): string => {
|
||||
if (day.title) return day.title
|
||||
if (day.date) {
|
||||
const d = new Date(`${day.date.slice(0, 10)}T00:00:00`)
|
||||
if (!Number.isNaN(d.getTime())) {
|
||||
return d.toLocaleDateString(locale, { weekday: 'short', day: 'numeric', month: 'short' })
|
||||
}
|
||||
}
|
||||
return t('planner.dayN', { n: day.day_number ?? index + 1 })
|
||||
}
|
||||
const deleteBlocked = planner.deleteDayBlocked
|
||||
|
||||
const move = (from: number, to: number) => {
|
||||
if (to < 0 || to >= ordered.length || from === to) return
|
||||
@@ -57,7 +48,7 @@ export default function MDaysSheet({ planner, shell }: MTripSheetsProps) {
|
||||
<span className="flex h-6 w-6 flex-none items-center justify-center rounded-full bg-[color:var(--m-ic)] font-geist text-[0.65625rem] font-bold text-m-muted">
|
||||
{i + 1}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate text-[0.8125rem] font-semibold">{label(day, i)}</span>
|
||||
<span className="min-w-0 flex-1 truncate text-[0.8125rem] font-semibold">{dayLabel(day, i, t, locale)}</span>
|
||||
{canEditDays && (
|
||||
<ReorderStack
|
||||
onUp={() => move(i, i - 1)}
|
||||
@@ -67,6 +58,18 @@ export default function MDaysSheet({ planner, shell }: MTripSheetsProps) {
|
||||
t={t}
|
||||
/>
|
||||
)}
|
||||
{canEditDays && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => planner.handleDeleteDay(day.id)}
|
||||
disabled={!!deleteBlocked}
|
||||
aria-label={t('dayplan.deleteDay')}
|
||||
title={deleteBlocked ?? undefined}
|
||||
className="flex h-[30px] w-[30px] flex-none items-center justify-center rounded-full bg-[color:var(--m-ic)] text-[color:var(--m-st-danger)] disabled:text-m-faint disabled:opacity-40"
|
||||
>
|
||||
<Trash2 size={13} strokeWidth={2.2} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -80,6 +83,9 @@ export default function MDaysSheet({ planner, shell }: MTripSheetsProps) {
|
||||
{t('dayplan.addDay')}
|
||||
</button>
|
||||
)}
|
||||
{canEditDays && deleteBlocked && (
|
||||
<p className="mt-[10px] text-center text-[0.6875rem] text-m-muted">{deleteBlocked}</p>
|
||||
)}
|
||||
</div>
|
||||
</MSheet>
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ import { useAuthStore } from '../../../../store/authStore'
|
||||
import { useSettingsStore } from '../../../../store/settingsStore'
|
||||
import { useTripStore } from '../../../../store/tripStore'
|
||||
import MConfirmSheet from '../../settings/MConfirmSheet'
|
||||
import MDayImpactList from '../../../components/MDayImpactList'
|
||||
import MDaySheet from './MDaySheet'
|
||||
import MDaysSheet from './MDaysSheet'
|
||||
import MAccommodationSheet from './MAccommodationSheet'
|
||||
@@ -201,6 +202,22 @@ export default function MTripSheets({ planner, shell }: MTripSheetsProps) {
|
||||
planner.setDeletePlaceId(null)
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Delete-day confirm behind the days sheet's delete buttons. Mounted
|
||||
last, so it opens over that sheet; the list of what goes with the day
|
||||
comes ready made from the planner, the same one the desktop shows. */}
|
||||
<MConfirmSheet
|
||||
open={planner.deleteDayId != null}
|
||||
onClose={() => planner.setDeleteDayId(null)}
|
||||
title={planner.deleteDayTitle}
|
||||
message={t('dayplan.deleteDayBody')}
|
||||
confirmLabel={t('dayplan.deleteDay')}
|
||||
cancelLabel={t('common.cancel')}
|
||||
danger
|
||||
onConfirm={() => { void planner.confirmDeleteDay() }}
|
||||
>
|
||||
<MDayImpactList lines={planner.deleteDayLines} label={planner.deleteDayTitle} />
|
||||
</MConfirmSheet>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user