import Redux from 'redux' ; import { handleFetchErrors } from 'shared/requests' ; import { URLS } from '../Constants' ; import { AnnouncementSetAction , FetchAnnouncementResponse } from './ActionTypes' ; export function fetchAnnouncements ( ) { return ( dispatch ) : any => { fetch ( URLS . ANNOUNCEMENTS ) . then ( handleFetchErrors ) . then ( ( response ) => response . json ( ) ) . then ( ( data ) => { dispatch ( handleAnnouncements ( data ) ) ; } ) . catch ( ( error ) => { } ) ; } ; } export function handleAnnouncements ( data ) { return ( dispatch ) : any => { if ( data . message !== null && data . message !== '' ) { dispatch ( setAnnouncement ( true , data . message , data . link ) ) ; } } ; } export function setAnnouncement ( open , message ? , link ? ) { return { type : 'ANNOUNCEMENT_SET' , open , message , link } ; }