useSignInMembersStore
This store is responsible for handling the members registrations. It provides methods to update, and delete member registrations, as well as the active members list. It manages online and offline work by persisting data when offline and syncing it when back online again.
Used by
Used Stores
State
| Name | Type | Description |
|---|---|---|
memberSignIns | ref | Holds the list of member registrations for the actual run |
activeMembers | ref | Holds the list with all active members which could be registered for the actual run |
membersLoaded | ref | Holds the loading state for the activeMembers |
signInsLoaded | ref | Holds the loading state for the memberSignIns |
Initialization
initializeMemberSignInStore 🚀
Initializes the member registration store. Tries to load the state from local storage, processes any pending sync tasks, and if skipFetch is not set to true, fetches the member registrations and active members from the backend and updates the store.
Actions
persist
Persist the current state of the store to the browser's local storage. This function should be called when every time data was loaded / store state was changed.
fetchMemberSignIns
Fetches the member registrations from the /members-sign-ins endpoint for the given run date and stores them in the memberSignIns state. It also updates the signInsLoaded state to indicate whether the data has been loaded successfully. If the data is loaded successfully, it calls persist to save the state to local storage. If the data cannot be loaded, it logs an error and sets signInsLoaded to false.
fetchActiveMembers
Fetches the active members from the /members/getsigninjson endpoint for the given run date and stores them in the activeMembers state. It also updates the membersLoaded state to indicate whether the data has been loaded successfully. If the data is loaded successfully, it calls persist to save the state to local storage. If the data cannot be loaded, it logs an error and sets membersLoaded to false.
createSignInEntry
Creates a new member registration. If the user is offline, enqueues a sync task to register the member when the user comes back online. If the request fails due to a network error, also enqueues a sync task. If the request fails due to a server-side error, shows an error message.
enqueueSignInFallback
Nested in:: createSignInEntry
Enqueues a sync task to create member registration when the user comes online later, and adds the registration to the local state. This function is called when the device is offline or a network error occurs during the createSignInEntry function. The function generates a unique idempotency key, a unique registration id, and enqueues the registration with the sync store. It then adds the registration to the local state with the document id set to the generated registration id.
toggleCheckIn
Toggles the sign-in status of a member registration. This asynchronous function updates the sign-in/sign/out status of the given registration. If the device is offline, the toggle operation is enqueued for later synchronization. On successful update, the member registrations are refreshed. In case of a network error, the toggle is also enqueued for later sync.
enqueueToggleFallback
Nested in: toggleCheckIn
Enqueues a sync task to toggle the sign-in/sign-out status of a member registration and updates the local state of registration. This function is called when the device is offline or a network error occurs during the toggleCheckIn function. The function enqueues the sign-in change with the sync store and then updates the local state of registration with the given newState.
deleteSignInEntry
Deletes a member registration. If the device is offline, this function will enqueue a sync task to delete the registration when the user comes online later. If a network error occurs, this function will also enqueue a sync task to delete the registration when the user comes online later.
enqueueDeleteFallback
Nested in: deleteSignInEntry
Enqueues the member registration for later deletion and removes it from the local state of registrations, but only if the device is offline or a network error occurs. The function enqueues the member registration with the sync store and then filters the local state of registrations to remove the registration with the given document id.
processQueue
Processes the sync queue for member registrations, which are created, updated, or deleted offline. The function processes the queue by sending each task to the backend server. If a network error occurs or the device is offline, the function aborts and sets the application as offline. Otherwise, the function processes the queue and updates the registration entries in the store.
abortOnError
Nested in: abortOnError
Checks if the given error is a network error (i.e. 'network', 'timeout', or 'aborted'), and if so, logs a warning message, sets the app as offline, and returns true. Otherwise, returns false.
Getters/Setters
signedInMembers (computed)
Getter to transform the raw members entries to the format we need for the SignInTable
