import { ILocation , IOfflineData } from '@client/offline/reducer' ; import { ILanguageState } from '@client/i18n/reducer' ; import { ILocationDataResponse , IFacilitiesDataResponse , IDefinitionsResponse , IAssetResponse } from '@client/utils/referenceApi' ; import { IUserDetails } from '@client/utils/userUtils' ; export const GET_LOCATIONS = 'OFFLINE/GET_LOCATIONS' ; type GetLocations = { type : typeof GET_LOCATIONS ; payload : string ; } ; export const DEFINITIONS_LOADED = 'OFFLINE/DEFINITIONS_LOADED' ; export type DefinitionsLoadedAction = { type : typeof DEFINITIONS_LOADED ; payload : IDefinitionsResponse ; } ; export const DEFINITIONS_FAILED = 'OFFLINE/DEFINITIONS_FAILED' ; export type DefinitionsFailedAction = { type : typeof DEFINITIONS_FAILED ; payload : Error ; } ; export const LOCATIONS_LOADED = 'OFFLINE/LOCATIONS_LOADED' ; export type LocationsLoadedAction = { type : typeof LOCATIONS_LOADED ; payload : { [ key ] : ILocation ; } ; } ; export const LOCATIONS_FAILED = 'OFFLINE/LOCATIONS_FAILED' ; export type LocationsFailedAction = { type : typeof LOCATIONS_FAILED ; payload : Error ; } ; export const FACILITIES_LOADED = 'OFFLINE/FACILITIES_LOADED' ; export type FacilitiesLoadedAction = { type : typeof FACILITIES_LOADED ; payload : { [ key ] : ILocation ; } ; } ; export const FACILITIES_FAILED = 'OFFLINE/FACILITIES_FAILED' ; export type FacilitiesFailedAction = { type : typeof FACILITIES_FAILED ; payload : Error ; } ; export const PILOT_LOCATIONS_LOADED = 'OFFLINE/PILOT_LOCATIONS_LOADED' ; export type PilotLocationsLoadedAction = { type : typeof PILOT_LOCATIONS_LOADED ; payload : { [ key ] : ILocation ; } ; } ; export const PILOT_LOCATIONS_FAILED = 'OFFLINE/PILOT_LOCATIONS_FAILED' ; export type PilotLocationsFailedAction = { type : typeof PILOT_LOCATIONS_FAILED ; payload : Error ; } ; export const ASSETS_LOADED = 'OFFLINE/ASSETS_LOADED' ; export type AssetsLoadedAction = { type : typeof ASSETS_LOADED ; payload : IAssetResponse ; } ; export const ASSETS_FAILED = 'OFFLINE/ASSETS_FAILED' ; export type AssetsFailedAction = { type : typeof ASSETS_FAILED ; payload : Error ; } ; export const GET_EXISTING_OFFLINE_DATA = 'OFFLINE/SET_OFFLINE_DATA' ; type SetOfflineData = { type : typeof GET_EXISTING_OFFLINE_DATA ; payload : IUserDetails ; } ; export const GET_OFFLINE_DATA_SUCCESS = 'OFFLINE/GET_OFFLINE_DATA_SUCCESS' ; export type IGetOfflineDataSuccessAction = { type : typeof GET_OFFLINE_DATA_SUCCESS ; payload : string ; } ; export const GET_OFFLINE_DATA_FAILED = 'OFFLINE/GET_OFFLINE_DATA_FAILED' ; export type IGetOfflineDataFailedAction = { type : typeof GET_OFFLINE_DATA_FAILED ; } ; export const FORMAT_LOCATIONS = 'OFFLINE/FORMAT_LOCATIONS' ; export type IFilterLocationsAction = { type : typeof FORMAT_LOCATIONS ; payload : ILanguageState ; } ; export const READY = 'OFFLINE/READY' as const ; export const UPDATED = 'OFFLINE/UPDATED' as const ; export const locationsLoaded = ( payload ) : LocationsLoadedAction => ( { type : LOCATIONS_LOADED , payload : payload } ) ; export const facilitiesFailed = ( error ) : FacilitiesFailedAction => ( { type : FACILITIES_FAILED , payload : error } ) ; export const facilitiesLoaded = ( payload ) : FacilitiesLoadedAction => ( { type : FACILITIES_LOADED , payload : payload } ) ; export const locationsFailed = ( error ) : LocationsFailedAction => ( { type : LOCATIONS_FAILED , payload : error } ) ; export const pilotLocationsLoaded = ( payload ) : PilotLocationsLoadedAction => ( { type : PILOT_LOCATIONS_LOADED , payload : payload } ) ; export const pilotLocationsFailed = ( error ) : PilotLocationsFailedAction => ( { type : PILOT_LOCATIONS_FAILED , payload : error } ) ; export const setOfflineData = ( userDetails ) : SetOfflineData => ( { type : GET_EXISTING_OFFLINE_DATA , payload : userDetails } ) ; export const getOfflineDataSuccess = ( response ) : IGetOfflineDataSuccessAction => ( { type : GET_OFFLINE_DATA_SUCCESS , payload : response } ) ; export const getOfflineDataFailed = ( ) : IGetOfflineDataFailedAction => ( { type : GET_OFFLINE_DATA_FAILED } ) ; export const definitionsLoaded = ( payload ) : DefinitionsLoadedAction => ( { type : DEFINITIONS_LOADED , payload : payload } ) ; export const definitionsFailed = ( error ) : DefinitionsFailedAction => ( { type : DEFINITIONS_FAILED , payload : error } ) ; export const assetsLoaded = ( payload ) : AssetsLoadedAction => ( { type : ASSETS_LOADED , payload : payload } ) ; export const assetsFailed = ( error ) : AssetsFailedAction => ( { type : ASSETS_FAILED , payload : error } ) ; export const offlineDataReady = ( state ) => ( { type : READY , payload : state } ) ; export const offlineDataUpdated = ( state ) => ( { type : UPDATED , payload : state } ) ; export const REFRESH_OFFLINE_DATA = 'OFFLINE/REFRESH_OFFLINE_DATA' as const ; export const refreshOfflineData = ( ) => ( { type : REFRESH_OFFLINE_DATA } ) ; export type Action = GetLocations | LocationsFailedAction | LocationsLoadedAction | SetOfflineData | IGetOfflineDataSuccessAction | IGetOfflineDataFailedAction | FacilitiesLoadedAction | FacilitiesFailedAction | PilotLocationsLoadedAction | PilotLocationsFailedAction | DefinitionsFailedAction | DefinitionsLoadedAction | AssetsLoadedAction | AssetsFailedAction | IFilterLocationsAction | ReturnType < typeof offlineDataReady > | ReturnType < typeof offlineDataUpdated > | ReturnType < typeof refreshOfflineData > ;