PhoenixKitBookings.Web.Public.BookingFlow (PhoenixKitBookings v0.1.1)

Copy Markdown View Source

The shared public booking flow: state, events, and markup used by BOTH Public.BookLive (the routed page) and Public.BookingWidgetLive (the live_render/3 embeddable). The two LiveViews stay thin shells that delegate handle_event/3 + handle_info/2 here — one flow, two mounts, because an embeddable LiveView must not export handle_params/3 (Phoenix refuses to mount it outside a router live route).

Steps

:pick (mode-aware slot/date/range picker) → :details (customer form or login gate) → :done (confirmation + manage link). The picker panel varies by the service's shape:

  • fixed slots — date input + slot button grid (Engine.bookable_slots)
  • free-form — date + start/end time inputs, validated server-side
  • day/night — check-in/check-out date inputs + remaining-capacity note

Live updates

Mounting flows subscribe to the service's PubSub topic; any booking mutation re-runs the current picker query, so a slot taken in another session greys out in real time.

Summary

Functions

Initializes flow assigns for a mounted LiveView. user is the viewer's %{uuid, email}-shaped struct or nil; prefill optionally seeds the customer form (embed contract).

Releases the visitor's hold when their LiveView goes away — both public LVs call this from terminate/2.

Re-queries the data behind the current picker panel.

Functions

assign_flow(socket, service, user, prefill \\ %{})

Initializes flow assigns for a mounted LiveView. user is the viewer's %{uuid, email}-shaped struct or nil; prefill optionally seeds the customer form (embed contract).

flow(assigns)

Attributes

  • service (PhoenixKitBookings.Schemas.Service) (required)
  • rules (:list) (required)
  • step (:atom) (required)
  • pick_date (Date) (required)
  • slots (:list) (required)
  • day_capacity (:map) (required)
  • selected_range (:any) (required)
  • customer_form (:any) (required)
  • booking (:any) (required)
  • flow_error (:any) (required)
  • flow_error_reason (:any) - Defaults to nil.
  • waitlist_done (:boolean) - Defaults to false.
  • current_user (:any) (required)

handle_event(binary, arg2, socket)

handle_info(arg1, socket)

on_terminate(socket)

Releases the visitor's hold when their LiveView goes away — both public LVs call this from terminate/2.

refresh_pick(socket)

Re-queries the data behind the current picker panel.