Skip to content

useDrinkRedemptionStore

Manages drink redemptions for a run event. Caches active cards, entitlement limits, and run redemptions locally so the full flow works offline. Follows the same online/offline/queue pattern as onsiteSalesStore.

📄 View source on GitHub

Used by

Used Stores

State

NameTypeDescription
redemptionsref
activeCardsref
limitsref
redemptionsLoadedref
cardsLoadedref
limitsLoadedref

Initialization

initializeDrinkRedemptionStore 🚀

Initialises the store: loads persisted state, flushes any queued offline redemptions, then fetches fresh data from the backend.

Actions

persist

fetchActiveCards

Fetches all active cards with their member info and caches them locally. Enables offline QR scan resolution and in-app QR display.

fetchLimits

Fetches entitlement limits from HarelineConfig and caches them locally.

fetchRedemptions

Fetches all redemptions for the current run date and caches them locally. Required for accurate offline entitlement checks.

processQueue

Processes the sync queue, replaying any redemptions created while offline. Aborts on network errors (returns 'partial'); server errors are logged and the task is discarded (retrying a 4xx won't help).

checkEntitlement

Checks whether a card has remaining entitlement for the requested drink. Runs entirely against cached local state — works offline. Rules: - Non-beer member: up to member_non_beer_limit softies; no beer. - Beer member / guest: budget of member_beer_limit / guest_beer_limit "beer units". Each beer costs 1 unit; softies cost ceil(quantity / beer_softie_conversion) units.

redeemDrink

Records a drink redemption. Checks entitlement locally first, then posts to the backend if online. Falls back to the sync queue when offline or on network errors, with an optimistic local state update so further entitlement checks remain accurate.

enqueueRedemptionFallback

deleteRedemption

Deletes a redemption. When online, sends DELETE immediately; on network failure or when already offline, enqueues for later sync with an optimistic local removal so the UI stays consistent.

enqueueDeleteFallback

abortOnNetworkError

Getters/Setters

cardByUid (computed)

Lookup map: card_uid → card object (computed once, used for O(1) scan resolution)

Released under the MIT License.