mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 03:26:07 +00:00
31859651d7
Every help screen checked against the v5 redesign. Tours is documented for the first time, as a screen of its own with twelve screens under it, and notifications get help of their own. All pictures are taken again on a realistic demo trip, with short loops where a still cannot show the motion. The English is plain and every language is written naturally rather than word for word. The switcher shows two levels at most, a screen's overview lists its sub-screens as cards above its guides, each wiki page is linked once, and the help sidebar is wider. Fixes found along the way: Save to Collection keeps a tour's route, a track dropped on the places column opens the Tours import, tour Share on desktop, the unsaved tour draft lives on the account, a route click no longer adds an end point, Trip places leaves the trip's tours out, Escape closes a stage's day menu, confirms before destructive deletes, DWD warnings sharing one id kept apart, a booking's date moves with it, and smaller fixes across notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and the admin screens.
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { useState } from 'react';
|
|
import { useTranslation } from '../../i18n';
|
|
import type { BudgetItem } from '../../types';
|
|
import ConfirmDialog from '../shared/ConfirmDialog';
|
|
|
|
/**
|
|
* The bin on an expense asks before anything is sent. An expense is deleted
|
|
* with its splits and receipt links, so a stray click would cost more than the
|
|
* row. The hook holds the expense being asked about and renders the dialog for
|
|
* it; the delete itself stays with the caller.
|
|
*/
|
|
export function useExpenseDeleteConfirm(items: BudgetItem[], onDelete: (id: number) => Promise<unknown>) {
|
|
const { t } = useTranslation();
|
|
const [target, setTarget] = useState<BudgetItem | null>(null);
|
|
|
|
// The table reports a row by its id, so the expense is looked up for its name and receipts.
|
|
const askById = (id: number) => setTarget(items.find((b) => b.id === id) ?? null);
|
|
|
|
const hasReceipts = (target?.receipts || []).length > 0;
|
|
const dialog = (
|
|
<ConfirmDialog
|
|
isOpen={target !== null}
|
|
onClose={() => setTarget(null)}
|
|
title={t('costs.confirm.deleteTitle')}
|
|
message={t(hasReceipts ? 'costs.confirm.deleteBodyReceipts' : 'costs.confirm.deleteBody', {
|
|
name: target?.name ?? '',
|
|
})}
|
|
confirmLabel={t('common.delete')}
|
|
cancelLabel={t('common.cancel')}
|
|
onConfirm={() => {
|
|
const id = target?.id;
|
|
setTarget(null);
|
|
if (id !== undefined) void onDelete(id);
|
|
}}
|
|
/>
|
|
);
|
|
|
|
return { ask: setTarget, askById, dialog };
|
|
}
|