import { createActions } from 'reduxsauce'; import { IService } from '../../utils/types'; interface IAuthActionTypes { GET_SESSION: 'GET_SESSION'; GET_SESSION_SUCCESS: 'GET_SESSION_SUCCESS'; GET_SESSION_FAILURE: 'GET_SESSION_FAILURE'; VERIFY_USER_SESSION: 'VERIFY_USER_SESSION'; VERIFY_USER_SESSION_SUCCESS: 'VERIFY_USER_SESSION_SUCCESS'; VERIFY_USER_SESSION_FAILURE: 'VERIFY_USER_SESSION_FAILURE'; RESET_AUTH_STATE: 'RESET_AUTH_STATE'; } export interface IGetSessionAction { type: IAuthActionTypes['GET_SESSION']; sessionId: string; } export interface IGetSessionSuccessAction { type: IAuthActionTypes['GET_SESSION_SUCCESS']; isNewUser: boolean; service: IService; } export interface IGetSessionFailureAction { type: IAuthActionTypes['GET_SESSION_FAILURE']; error: string; } export interface IVerifyUserSessionAction { type: IAuthActionTypes['VERIFY_USER_SESSION']; userId: string; sessionId: string; } export interface IVerifyUserSessionSuccessAction { type: IAuthActionTypes['VERIFY_USER_SESSION_SUCCESS']; } export interface IVerifyUserSessionFailureAction { type: IAuthActionTypes['VERIFY_USER_SESSION_FAILURE']; error: string; } export interface IResetAuthStateAction { type: IAuthActionTypes['RESET_AUTH_STATE']; } interface IAuthActionCreators { getSessiom(): IGetSessionAction; getSessionSuccess(isNewUser: boolean, service: IService): IGetSessionSuccessAction; getSessionFailure(error: string): IGetSessionFailureAction; verifyUserSession(userId: string, sessionId: string): IVerifyUserSessionAction; verifyUserSessionSuccess(): IVerifyUserSessionSuccessAction; verifyUserSessionFailure(error: string): IVerifyUserSessionFailureAction; resetAuthState(): IResetAuthStateAction; } export type AuthAction = | IGetSessionAction | IGetSessionSuccessAction | IGetSessionFailureAction | IVerifyUserSessionAction | IVerifyUserSessionSuccessAction | IVerifyUserSessionFailureAction | IResetAuthStateAction; const { Types, Creators } = createActions( { getSession: ['sessionId'], getSessionSuccess: ['isNewUser', 'service'], getSessionFailure: ['error'], verifyUserSession: ['userId', 'sessionId'], verifyUserSessionSuccess: null, verifyUserSessionFailure: ['error'], resetAuthState: null, }, { prefix: 'AUTH/', }, ); export const authActionTypes = Types; export const authActionCreators = Creators;