mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-14 00:01:03 +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.
107 lines
3.5 KiB
TypeScript
107 lines
3.5 KiB
TypeScript
/** Shared types and pure helpers for the admin page + its data hook. No React, no side effects. */
|
|
|
|
export interface AdminUser {
|
|
id: number
|
|
username: string
|
|
email: string
|
|
role: 'admin' | 'user'
|
|
created_at: string
|
|
last_login?: string | null
|
|
/** The later of the last sign-in and the last request the account made. */
|
|
last_active?: string | null
|
|
online?: boolean
|
|
oidc_issuer?: string | null
|
|
avatar_url?: string | null
|
|
}
|
|
|
|
/**
|
|
* The row after an edit. The update answers with the account fields only, so
|
|
* what the list derives (avatar, last activity, online) stays from the row; a
|
|
* reply that replaced the whole row showed the user as never signed in.
|
|
*/
|
|
export function mergeSavedUser(row: AdminUser, saved: Pick<AdminUser, 'username' | 'email' | 'role'>): AdminUser {
|
|
return { ...row, username: saved.username, email: saved.email, role: saved.role }
|
|
}
|
|
|
|
/** When a user was last active, with the year once it is not this one. */
|
|
export function formatLastActive(iso: string | null | undefined, locale: string, hour12: boolean, now = new Date()): string {
|
|
if (!iso) return '—'
|
|
const at = new Date(iso)
|
|
const sameYear = at.getFullYear() === now.getFullYear()
|
|
return at.toLocaleDateString(locale, {
|
|
day: 'numeric',
|
|
month: 'short',
|
|
...(sameYear ? {} : { year: 'numeric' }),
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
hour12,
|
|
})
|
|
}
|
|
|
|
export interface AdminStats {
|
|
totalUsers: number
|
|
totalTrips: number
|
|
totalPlaces: number
|
|
totalFiles: number
|
|
}
|
|
|
|
export interface OidcConfig {
|
|
issuer: string
|
|
client_id: string
|
|
client_secret: string
|
|
client_secret_set: boolean
|
|
display_name: string
|
|
discovery_url: string
|
|
}
|
|
|
|
export interface UpdateInfo {
|
|
update_available: boolean
|
|
latest: string
|
|
current: string
|
|
release_url?: string
|
|
is_docker?: boolean
|
|
is_prerelease?: boolean
|
|
}
|
|
|
|
export interface InviteStatus {
|
|
isExpired: boolean
|
|
isUsedUp: boolean
|
|
isActive: boolean
|
|
/** i18n key of the status pill: used up wins over expired. */
|
|
labelKey: 'admin.invite.usedUp' | 'admin.invite.expired' | 'admin.invite.active'
|
|
}
|
|
|
|
/**
|
|
* The grey line under an invite link: uses, expiry, the trip it adds to and who made it,
|
|
* one comma-joined sentence fragment so both admin shells print the same thing.
|
|
*/
|
|
export function inviteMeta(
|
|
invite: {
|
|
used_count: number
|
|
max_uses: number
|
|
expires_at?: string | null
|
|
trip_title?: string | null
|
|
created_by_name?: string | null
|
|
},
|
|
t: (key: string, params?: Record<string, string | number>) => string,
|
|
locale: string,
|
|
): string {
|
|
const parts = [`${invite.used_count}/${invite.max_uses === 0 ? '∞' : invite.max_uses} ${t('admin.invite.uses')}`]
|
|
if (invite.expires_at) parts.push(`${t('admin.invite.expiresAt')} ${new Date(invite.expires_at).toLocaleDateString(locale)}`)
|
|
if (invite.trip_title) parts.push(t('admin.invite.boundTo', { trip: invite.trip_title }))
|
|
parts.push(`${t('admin.invite.createdBy')} ${invite.created_by_name ?? ''}`)
|
|
return parts.join(', ')
|
|
}
|
|
|
|
/** Where an invite link stands: expired, used up (max_uses 0 is unlimited) or still active. */
|
|
export function inviteStatus(
|
|
invite: { expires_at?: string | null; max_uses: number; used_count: number },
|
|
now: Date = new Date(),
|
|
): InviteStatus {
|
|
const isExpired = !!invite.expires_at && new Date(invite.expires_at) < now
|
|
const isUsedUp = invite.max_uses > 0 && invite.used_count >= invite.max_uses
|
|
const isActive = !isExpired && !isUsedUp
|
|
const labelKey = isUsedUp ? 'admin.invite.usedUp' : isExpired ? 'admin.invite.expired' : 'admin.invite.active'
|
|
return { isExpired, isUsedUp, isActive, labelKey }
|
|
}
|