52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
|
|
/**
|
||
|
|
* Canonical human-readable labels for URL path segments. Used by the smart
|
||
|
|
* back button to derive a sensible "Back to <X>" label from the URL when a
|
||
|
|
* detail page hasn't registered an explicit back-context hint, and by the
|
||
|
|
* mobile topbar's title fallback.
|
||
|
|
*
|
||
|
|
* Add new top-level routes here so the back button doesn't fall through to
|
||
|
|
* a slugified guess (e.g. "berths" -> "Berths" works automatically via
|
||
|
|
* `formatSegment`, but "audit" would render as "Audit" instead of "Audit Log"
|
||
|
|
* without the explicit entry).
|
||
|
|
*/
|
||
|
|
export const SEGMENT_LABELS: Record<string, string> = {
|
||
|
|
dashboard: 'Dashboard',
|
||
|
|
clients: 'Clients',
|
||
|
|
yachts: 'Yachts',
|
||
|
|
companies: 'Companies',
|
||
|
|
interests: 'Interests',
|
||
|
|
berths: 'Berths',
|
||
|
|
documents: 'Documents',
|
||
|
|
files: 'Files',
|
||
|
|
expenses: 'Expenses',
|
||
|
|
invoices: 'Invoices',
|
||
|
|
email: 'Email',
|
||
|
|
inbox: 'Inbox',
|
||
|
|
reminders: 'Reminders',
|
||
|
|
alerts: 'Alerts',
|
||
|
|
settings: 'Settings',
|
||
|
|
admin: 'Administration',
|
||
|
|
reports: 'Reports',
|
||
|
|
tenancies: 'Tenancies',
|
||
|
|
residential: 'Residential',
|
||
|
|
new: 'New',
|
||
|
|
edit: 'Edit',
|
||
|
|
profile: 'Profile',
|
||
|
|
notifications: 'Notifications',
|
||
|
|
'website-analytics': 'Website Analytics',
|
||
|
|
};
|
||
|
|
|
||
|
|
/** UUID v4-ish (or any 36-char hex+dash) - used to skip entity-id segments
|
||
|
|
* from URL-derived labels since they're never human-readable. */
|
||
|
|
export const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||
|
|
|
||
|
|
export function isIdSegment(segment: string): boolean {
|
||
|
|
return UUID_RE.test(segment);
|
||
|
|
}
|
||
|
|
|
||
|
|
export function formatSegment(segment: string): string {
|
||
|
|
return (
|
||
|
|
SEGMENT_LABELS[segment] ?? segment.replace(/-/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase())
|
||
|
|
);
|
||
|
|
}
|