mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
1824cc77ec
The second run of #3157 was red in six jobs: - Server types: ReminderJobsService takes AddonsService now; RJOB-007 built it with five arguments. - Server tests 2/10: the doc-sync job tests stubbed AddonsService without isEnabledForTrip, which the sync asks per trip now. - Client tests 4/10: toursPermissions mocked useAuthStore as a bare selector; tripAddonsStore keys its lists by account through getState. - Server lint (knip): TripAddonRow was exported without a reader outside its file. - Client lint and Client types: no-unused-vars and the strict errors in useTripPlanner.ts went down by one, so their entries are lowered.
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import {
|
|
CarFront,
|
|
Compass,
|
|
FileText,
|
|
ListChecks,
|
|
Mountain,
|
|
Puzzle,
|
|
Users,
|
|
Wallet,
|
|
type LucideIcon,
|
|
} from 'lucide-react';
|
|
import { useState } from 'react';
|
|
|
|
import { useTranslation } from '../../i18n';
|
|
import { useTripAddons } from './useTripAddons';
|
|
|
|
/** The addons table's `icon` names of the trip addons; road trip was seeded as `Route`, the car says it better. */
|
|
const ICONS: Readonly<Record<string, LucideIcon>> = {
|
|
ListChecks,
|
|
Wallet,
|
|
FileText,
|
|
Users,
|
|
Route: CarFront,
|
|
Mountain,
|
|
Compass,
|
|
};
|
|
|
|
/** One trip addon as the trip settings list it. */
|
|
interface TripAddonRow {
|
|
id: string;
|
|
name: string;
|
|
description: string;
|
|
Icon: LucideIcon;
|
|
enabled: boolean;
|
|
/** The owner chose this for the trip, so it differs from the instance. */
|
|
ownChoice: boolean;
|
|
busy: boolean;
|
|
toggle: () => void;
|
|
}
|
|
|
|
/**
|
|
* The rows of the trip settings' Addons area, the same on the desktop dialog and
|
|
* the phone sheet. Flipping a switch back to what the instance says drops the
|
|
* trip's own choice instead of storing a copy of it, so a later change by the
|
|
* admin reaches the trip again and no reset button is needed.
|
|
*/
|
|
export function useTripAddonRows(tripId: number) {
|
|
const { t } = useTranslation();
|
|
const trip = useTripAddons(tripId);
|
|
const [busy, setBusy] = useState<string | null>(null);
|
|
|
|
const rows: TripAddonRow[] = trip.addons.map((addon) => {
|
|
// Spelled out inside t() so the key check sees which catalog keys this reaches.
|
|
const name = t(`admin.addons.catalog.${addon.id}.name`);
|
|
const description = t(`admin.addons.catalog.${addon.id}.description`);
|
|
return {
|
|
id: addon.id,
|
|
name: name === `admin.addons.catalog.${addon.id}.name` ? addon.name : name,
|
|
description: description === `admin.addons.catalog.${addon.id}.description` ? '' : description,
|
|
Icon: (addon.icon && ICONS[addon.icon]) || Puzzle,
|
|
enabled: addon.enabled,
|
|
ownChoice: addon.overridden,
|
|
busy: busy === addon.id,
|
|
toggle: () => {
|
|
if (busy) return;
|
|
const next = !addon.enabled;
|
|
setBusy(addon.id);
|
|
void trip.setOverride(addon.id, next === addon.instanceEnabled ? null : next).finally(() => setBusy(null));
|
|
},
|
|
};
|
|
});
|
|
|
|
return { rows, loading: trip.loading && rows.length === 0 };
|
|
}
|