import NotificationActionCreator from "../models/client/NotificationActionCreator" ; import { Dispatch } from "redux" ; import fetch from "../shared/fetch" ; import GetNotificationsResponse from "../models/response/GetNotificationsResponse" ; import actions from "./common" ; export const ACKNOWLEDGE_NOTIFICATION_BEGIN = "ACKNOWLEDGE_NOTIFICATION_BEGIN" ; export const ACKNOWLEDGE_NOTIFICATION_SUCCESS = "ACKNOWLEDGE_NOTIFICATION_SUCCESS" ; export const ACKNOWLEDGE_NOTIFICATION_FAILED = "ACKNOWLEDGE_NOTIFICATION_FAILED" ; export const GET_NOTIFICATIONS_BEGIN = "GET_NOTIFICATIONS_BEGIN" ; export const GET_NOTIFICATIONS_SUCCESS = "GET_NOTIFICATIONS_SUCCESS" ; export const GET_NOTIFICATIONS_FAILED = "GET_NOTIFICATIONS_FAILED" ; const notificationActionCreator = { acknowledgeNotification ( id ) { return ( dispatch ) : void => { dispatch ( { type : ACKNOWLEDGE_NOTIFICATION_BEGIN } ) ; fetch ( `/api/notification/acknowledge/${ id }` , undefined , "GET" , true ) . then ( ( json ) => { dispatch ( { type : ACKNOWLEDGE_NOTIFICATION_SUCCESS , id : id } ) ; } ) . catch ( ( error ) => { dispatch ( actions . handleFetchError ( ACKNOWLEDGE_NOTIFICATION_FAILED , error ) ) ; } ) ; } ; } , getAllNotifications ( ) { return ( dispatch ) : void => { dispatch ( { type : GET_NOTIFICATIONS_BEGIN } ) ; fetch ( "/api/notification" , undefined , "GET" , true ) . then ( ( json ) => { if ( json && json . data ) { dispatch ( { type : GET_NOTIFICATIONS_SUCCESS , notifications : json . data } ) ; } else { return Promise . reject ( { name : "500 Internal Server Error" , message : "" } ) ; } } ) . catch ( ( error ) => { dispatch ( actions . handleFetchError ( GET_NOTIFICATIONS_FAILED , error ) ) ; } ) ; } ; } } ; export default notificationActionCreator ;