@fleetbridge/ui 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,208 @@
1
- # Temporary Holding Version
1
+ # @fleetbridge/ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ FleetBridge's customer UI: the search form, the results page (filters, car cards, the booking wizard), manage-booking, and the return from online payment. It's one package for every kind of site:
4
+
5
+ - **WordPress**: the FleetBridge plugin's shortcodes mount these components with `wordpressTransport` (admin-ajax).
6
+ - **Next.js, Remix, Express, any custom code**: mount the same components with `httpTransport`, and serve the actions from your own route with `createPublicHandler` from `@fleetbridge/ui/server`, which runs them on [`@fleetbridge/sdk`](../../sdks/ts).
7
+
8
+ It's built on `@fleetbridge/components` (shadcn primitives), which is bundled in.
9
+
10
+ ## Install
11
+
12
+ Inside this repository: `"@fleetbridge/ui": "workspace:*"`.
13
+
14
+ Outside it, build once (`bun run build` in `packages/ui`) and install the packed tarball, next to the SDK:
15
+
16
+ ```json
17
+ "@fleetbridge/sdk": "file:../FLEETBRIDGE/sdks/ts/dist",
18
+ "@fleetbridge/ui": "file:../FLEETBRIDGE/packages/ui/release/fleetbridge-ui.tgz"
19
+ ```
20
+
21
+ Use the tarball, not the `dist/` folder. Bun installs a `file:` folder as symlinks into this repository, so the site's bundler (and Node) would resolve `react` from here and load two copies of React, which breaks hooks. The tarball is copied in and resolves everything from the site. After a rebuild, run `bun install --force` (or `bun add file:…tgz` again) in the site to pick up the new tarball.
22
+
23
+ Peer dependencies: `react` and `react-dom` 19, plus `@fleetbridge/sdk` when you use `@fleetbridge/ui/server`.
24
+
25
+ ## The pieces
26
+
27
+ ```ts
28
+ import {
29
+ FleetBridgeProvider, // transport, query cache, tooltips, toasts, looks, theme, page URLs
30
+ httpTransport, wordpressTransport,
31
+ SearchWidget, ResultsPage, ManageBooking, PaymentReturn, ConfirmationPreview,
32
+ } from '@fleetbridge/ui';
33
+ import '@fleetbridge/ui/styles.css';
34
+ ```
35
+
36
+ | Component | Props | What it is |
37
+ |---|---|---|
38
+ | `SearchWidget` | `resultsPageUrl?` (default: provider `resultsUrl`), `searchStyle?: 'bar' \| 'hero' \| 'pill' \| 'sidebar' \| 'steps'`, `title?`, `subtitle?`, `fallback?` | The search form. Sends the customer to the results page with the trip in the query string. |
39
+ | `ResultsPage` | `bookingUrl?` (default: provider `bookingUrl`), `listStyle?: 'grid' \| 'rows' \| 'table' \| 'showcase' \| 'grouped'`, `fallback?` | Reads the trip from the URL, searches every source, and shows filters, cars and the booking wizard. |
40
+ | `ManageBooking` | `showTrigger?: boolean`, `listStyle?`, `fallback?` | Find a booking by number + PIN, then change or cancel it. Also opens itself from `#manage=booking&id=…&pin=…` links. |
41
+ | `PaymentReturn` | `fallback?` | Put it on the results page. It picks up the customer coming back from paying online (`?fb_payment=…`). |
42
+ | `ConfirmationPreview` | `enabled: boolean`, `fallback?` | A sample "booking confirmed" screen, opened by `?fleetbridge_preview=confirmed`. |
43
+
44
+ The page-level components render in the browser only. On the server, and during hydration, they render `fallback` (default nothing), so they're safe in Next.js App Router server components. The bundle starts with `'use client'`.
45
+
46
+ Building blocks for custom layouts are exported too: `SearchPanel`, `SearchBar`, `CarCard`, `CarList`, `FilterPanel`, `BookingWizard`, `BookingConfirmation`, `BookingSteps`, `LookupForm`, the primitives (`CtaButton`, `GhostPill`, `Segmented`…), `LooksProvider`/`useLook`, and the search helpers (`criteriaToQuery`, `criteriaFromParams`, `DEFAULT_CRITERIA`…).
47
+
48
+ ### FleetBridgeProvider
49
+
50
+ ```tsx
51
+ <FleetBridgeProvider
52
+ transport={httpTransport({ endpoint: '/api/fleetbridge' })}
53
+ resultsUrl="/search" // where SearchWidget sends the customer
54
+ manageUrl="/manage-booking"
55
+ bookingUrl={undefined} // optional: your own booking page for car CTAs
56
+ looks={{ filters: 'rail', steps: 'line', extras: 'cards', price: 'side', done: 'pass', find: 'card' }}
57
+ theme={{ primary: '#153673', accent: '#F3E34C' }}
58
+ queryClient={myQueryClient} // optional: share a TanStack cache
59
+ persistCache // default true: keep good searches in localStorage for 10 min
60
+ toaster // default true
61
+ >
62
+ …
63
+ </FleetBridgeProvider>
64
+ ```
65
+
66
+ ## Next.js (or any custom site)
67
+
68
+ **1. The route** that answers the UI. Keep keys on the server.
69
+
70
+ ```ts
71
+ // app/api/fleetbridge/route.ts
72
+ import { createAppConnector, PostgresStorage } from '@fleetbridge/sdk';
73
+ import { createPublicHandler, readSuppliersFromEnv } from '@fleetbridge/ui/server';
74
+ import { Pool } from 'pg';
75
+
76
+ const connector = createAppConnector({
77
+ storage: new PostgresStorage(new Pool({ connectionString: process.env.DATABASE_URL })),
78
+ });
79
+
80
+ export const POST = createPublicHandler({
81
+ connector,
82
+ suppliers: async () => readSuppliersFromEnv(),
83
+ siteUrl: process.env.SITE_URL!,
84
+ });
85
+ ```
86
+
87
+ **2. The pages**
88
+
89
+ ```tsx
90
+ // app/search/page.tsx (a server component is fine)
91
+ import { FleetBridgeProvider, httpTransport, ResultsPage, PaymentReturn } from '@fleetbridge/ui';
92
+
93
+ const transport = httpTransport({ endpoint: '/api/fleetbridge' });
94
+
95
+ export default function SearchPage() {
96
+ return (
97
+ <FleetBridgeProvider transport={transport} resultsUrl="/search">
98
+ <ResultsPage listStyle="rows" />
99
+ <PaymentReturn />
100
+ </FleetBridgeProvider>
101
+ );
102
+ }
103
+ ```
104
+
105
+ (`httpTransport` returns a plain object, so create it inside a client component if you prefer not to pass it across the server/client boundary.)
106
+
107
+ ## WordPress
108
+
109
+ The plugin's public bundle (`packages/wordpress/src/public-main.tsx`) mounts each shortcode like this:
110
+
111
+ ```tsx
112
+ const transport = wordpressTransport({ ajaxUrl: el.dataset.ajaxUrl, nonce: el.dataset.nonce });
113
+
114
+ <FleetBridgeProvider transport={transport} looks={looksFrom(el.dataset.looks)}>
115
+ <ResultsPage listStyle={listStyleFrom(el.dataset.listStyle)} />
116
+ </FleetBridgeProvider>
117
+ ```
118
+
119
+ `wordpressTransport` posts `action=fleetbridge_<name>` and `nonce` to admin-ajax.php. Inside this monorepo, the WordPress Vite builds compile `@fleetbridge/ui` straight from `src/` (see the `resolve.alias` in `packages/wordpress/vite.config*.ts`), so no package build is needed first.
120
+
121
+ ## Transports
122
+
123
+ ```ts
124
+ interface FleetBridgeTransport {
125
+ post<T>(action: string, fields?: Record<string, string>): Promise<QueryResult<T>>;
126
+ }
127
+ type QueryResult<T> = { success: true; data: T } | { success: false; error: string; data?: Partial<T> };
128
+ ```
129
+
130
+ - `wordpressTransport({ ajaxUrl, nonce })`: FormData `action=fleetbridge_<name>`, `nonce`, fields → admin-ajax.php.
131
+ - `httpTransport({ endpoint, headers?, credentials? })`: FormData `action=<name>`, fields → your endpoint.
132
+
133
+ Both read the `{ success, data }` envelope (`data.message` on failure) and give the same customer-facing copy for a 429 ("Too many requests…") or an unreachable site. Write your own transport for anything else (an RPC layer, tests): any object with `post` works. Outside React, call `setTransport(transport)`.
134
+
135
+ ### Actions
136
+
137
+ `action` is the short name. WordPress adds the `fleetbridge_` prefix.
138
+
139
+ | Action | Used by |
140
+ |---|---|
141
+ | `public_branches` | search form: pick-up/return places |
142
+ | `search_sources` | results: which sources to ask (each is then searched on its own) |
143
+ | `search_availability` | results: cars for one source, or all at once |
144
+ | `get_estimation` | car card / wizard: live quote (deposit, excess…) |
145
+ | `get_extras` | wizard: add-ons |
146
+ | `get_one_way_fee` | car card / wizard: one-way fee |
147
+ | `supplier_terms` | wizard: the supplier's terms |
148
+ | `booking_request` | wizard: book |
149
+ | `request_quote` | wizard: email me a quote |
150
+ | `lookup_quote`, `confirm_quote` | manage booking: quotes |
151
+ | `lookup_booking`, `cancel_my_booking`, `amend_my_booking` | manage booking |
152
+ | `payment_methods`, `start_payment`, `verify_payment` | wizard + PaymentReturn: pay online |
153
+
154
+ `PUBLIC_ACTIONS` exports this list.
155
+
156
+ ## Theming
157
+
158
+ Every colour is a CSS custom property, so a host restyles the UI without touching the package:
159
+
160
+ - **The base palette** (shadcn names, on `:root`): `--primary`, `--primary-foreground`, `--accent`, `--accent-foreground`, `--background`, `--foreground`, `--muted`, `--muted-foreground`, `--border`, `--ring`, `--radius`.
161
+ - **The font**: `--fb-font-sans`. The host page loads the font itself; the package ships none.
162
+ - **Per-surface tokens**, which default to the base palette: `--fb-search-*` (search form), `--fb-listing-*` (results chrome), `--fb-car-*` (car cards), `--fb-filter-*` (filters), `--fb-wizard-*` (booking flow). See `src/styles/public-tokens.css` for the full list.
163
+
164
+ The typed shortcut:
165
+
166
+ ```tsx
167
+ import { FleetBridgeProvider, themeToCss, type FleetBridgeTheme } from '@fleetbridge/ui';
168
+
169
+ const carhire: FleetBridgeTheme = {
170
+ primary: '#153673', primaryForeground: '#FFFFFF', // navy
171
+ accent: '#F3E34C', accentForeground: '#153673', // yellow "View deal" buttons
172
+ foreground: '#101A33', muted: '#F3F4F8', border: '#E1E5F0',
173
+ radius: '12px',
174
+ fontFamily: 'Inter, system-ui, sans-serif',
175
+ vars: { '--fb-filter-bar': '#596AC0' }, // blue price histogram
176
+ };
177
+
178
+ const saniSixt: FleetBridgeTheme = {
179
+ primary: '#1a1a1a', primaryForeground: '#ffffff',
180
+ accent: '#ff5f00', accentForeground: '#1a1a1a',
181
+ foreground: '#1a1a1a', radius: '4px',
182
+ fontFamily: '"Inter Tight", "Helvetica Neue", Arial, sans-serif',
183
+ vars: { '--fb-search-button': '#ff5f00', '--fb-search-button-fg': '#1a1a1a' },
184
+ };
185
+
186
+ <FleetBridgeProvider transport={transport} theme={carhire}>…</FleetBridgeProvider>
187
+
188
+ // For a flash-free first paint on a server-rendered page, also print it:
189
+ <style dangerouslySetInnerHTML={{ __html: themeToCss(carhire) }} />
190
+ ```
191
+
192
+ The provider writes the theme on `:root` while it's mounted, because portalled dialogs render on `<body>`. You can set the same properties in your own stylesheet instead. Layout variants come from `looks` on the provider (filters, steps, extras, price, done, find), plus `searchStyle` and `listStyle` on the components.
193
+
194
+ ### How the stylesheet behaves on a host page
195
+
196
+ `styles.css` follows the WordPress public bundle's rules, because the UI lands on pages it doesn't own:
197
+
198
+ - Every utility is `!important` (Tailwind's `important` flag), so a host theme's generic resets can't override the UI's classes.
199
+ - Tailwind's base layer sits in `@layer base`, so unlayered host CSS still wins on the host's own elements. Unlike the WordPress admin, the package doesn't set the page's `body` background, colour or font.
200
+ - Anything GSAP animates is styled by unlayered `.fb-*` classes, never by utilities.
201
+
202
+ ## Building
203
+
204
+ ```sh
205
+ bun run build # dist/index.js + .d.ts, dist/server.js + .d.ts, dist/styles.css, dist/package.json, release/fleetbridge-ui.tgz
206
+ bun run dev # watch
207
+ bun run type-check
208
+ ```