@autobusal/routes-order 1.32.0 → 1.33.0

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/services.ts CHANGED
@@ -4,7 +4,7 @@ import { apiClient } from '@autobusal/providers';
4
4
  import { RoutesSearchForm } from '@autobusal/routes-search/types';
5
5
  import { FoundData, FlexOffer } from '@autobusal/providers/types/routes';
6
6
  import { CouponData } from '@autobusal/providers/types/orders';
7
- import { BillingData, PersonData } from '@autobusal/providers/types/persons';
7
+ import { BillingData, PersonData, SavedPassengerRecord, SavedPassengersData } from '@autobusal/providers/types/persons';
8
8
  import { FoundDay, ActionData, SaveData, OrderedData, CouponForm, AddonsSelection, AlternativesData, PriceAlertRequest, PriceAlertData } from './types';
9
9
 
10
10
  export const useGetDepartures = (data: RoutesSearchForm): UseQueryResult<FoundData[]> => (
@@ -313,3 +313,77 @@ export const usePostPriceAlert = (): UseMutationResult<PriceAlertData, AxiosErro
313
313
  retry: false
314
314
  })
315
315
  );
316
+
317
+ /**
318
+ * The travellers this account has saved, measured against THIS journey.
319
+ *
320
+ * Edited: Claude - Date: 2026-08-20
321
+ *
322
+ * The price ids are what make the answer journey-specific: obtapi puts a
323
+ * `missing` array on every row naming the fields these particular routes
324
+ * collect and this particular saved traveller has not got (see
325
+ * Account\PassengersController::browse). Without them the rows come back
326
+ * with no `missing` key at all, which is a different answer from an empty
327
+ * one - so they are always sent from here.
328
+ *
329
+ * `enabled` is the whole gate, and it is not an optimisation. The endpoint
330
+ * is `role:visitor`, so a guest or a member of staff gets a 404 - a correct
331
+ * refusal that confirms nothing, and one this UI must never turn into an
332
+ * error on somebody's checkout. Not asking is the only way to be sure of
333
+ * that; `retry: false` covers the case where the account changes underneath
334
+ * a query already in flight.
335
+ */
336
+ export const useGetSavedPassengers = (
337
+ departurePriceId: (number | undefined),
338
+ returnPriceId: (number | undefined),
339
+ enabled: boolean
340
+ ): UseQueryResult<SavedPassengersData> => (
341
+ useQuery({
342
+ queryKey: ['saved-passengers-checkout', { departurePriceId, returnPriceId }],
343
+ enabled: enabled && departurePriceId !== undefined,
344
+ retry: false,
345
+ queryFn: async () => (
346
+ await apiClient
347
+ .get('/api/account/passengers/browse', {
348
+ params: {
349
+ departure_price_id: departurePriceId,
350
+ return_price_id: returnPriceId
351
+ }
352
+ })
353
+ .then(response => (
354
+ response.data
355
+ ))
356
+ )
357
+ })
358
+ );
359
+
360
+ /**
361
+ * One saved traveller, passport included.
362
+ *
363
+ * Edited: Claude - Date: 2026-08-20
364
+ *
365
+ * A mutation for a GET, deliberately. This is not data the screen renders -
366
+ * it is fetched at the moment somebody picks a name out of the chooser, and
367
+ * what comes back is written into a form rather than displayed. A query
368
+ * would need the chosen id in render state and an effect to notice it
369
+ * landing; `mutate(id, { onSuccess })` is the same fetch with the answer
370
+ * arriving where the decision was made.
371
+ *
372
+ * This is also the ONLY request in the app that returns a stored passport
373
+ * number, which is why it is one traveller at a time and only after a
374
+ * customer has said who is sitting in this seat.
375
+ */
376
+ export const useGetSavedPassenger = (): UseMutationResult<SavedPassengerRecord, Error, number, unknown> => (
377
+ useMutation({
378
+ mutationKey: ['saved-passenger-record'],
379
+ mutationFn: async (id: number) => (
380
+ await apiClient
381
+ .get('/api/account/passengers/get', {
382
+ params: { id }
383
+ })
384
+ .then(response => (
385
+ response.data
386
+ ))
387
+ )
388
+ })
389
+ );