@ -1,6 +1,13 @@
'use strict' ;
import { getConversations , downloadVoiceMail } from '../api/conversations'
import { getConversations , downloadVoiceMail , downloadFax } from '../api/conversations'
const RequestState = {
button : 'button' ,
requesting : 'requesting' ,
succeeded : 'succeeded' ,
failed : 'failed'
} ;
export default {
namespaced : true ,
@ -8,34 +15,63 @@ export default {
page : 1 ,
rows : 10 ,
conversations : [
]
] ,
downloadVoiceMailState : RequestState . button ,
downloadVoiceMailError : null ,
downloadFaxState : RequestState . button ,
downloadFaxError : null
} ,
mutations : {
loadConversations ( state , options ) {
state . conversations = state . conversations . concat ( options ) ;
state . page ++ ;
} ,
downloadVoiceMailRequesting ( state ) {
state . downloadVoiceMailState = RequestState . requesting ;
state . downloadVoiceMailError = null ;
} ,
downloadVoiceMailSucceeded ( state ) {
state . downloadVoiceMailState = RequestState . succeeded ;
state . downloadVoiceMailError = null ;
} ,
downloadVoiceMailFailed ( state , error ) {
state . downloadVoiceMailState = RequestState . failed ;
state . downloadVoiceMailError = error ;
} ,
downloadFaxRequesting ( state ) {
state . downloadFaxState = RequestState . requesting ;
state . downloadFaxError = null ;
} ,
downloadFaxSucceeded ( state ) {
state . downloadFaxState = RequestState . succeeded ;
state . downloadFaxError = null ;
} ,
downloadFaxFailed ( state , error ) {
state . downloadFaxState = RequestState . failed ;
state . downloadFaxError = error ;
}
} ,
actions : {
loadConversations ( context ) {
return new Promise ( ( resolve , reject ) => {
getConversations ( localStorage . getItem ( 'subscriberId' ) , context . state . page , context . state . rows )
. then ( result => {
context . commit ( 'loadConversations' , result ) ;
resolve ( ) ;
} )
. catch ( ( err ) => {
reject ( err ) ;
} ) ;
} ) ;
getConversations ( localStorage . getItem ( 'subscriberId' ) , context . state . page , context . state . rows )
. then ( result => {
context . commit ( 'loadConversations' , result ) ;
} )
} ,
downloadVoiceMail ( context , id ) {
return new Promise ( ( resolve , reject ) => {
downloadVoiceMail ( id ) . then ( ( ) => {
resolve ( ) ;
} ) . catch ( ( err ) => {
reject ( err ) ;
} ) ;
context . commit ( 'downloadVoiceMailRequesting' ) ;
downloadVoiceMail ( id ) . then ( ( ) => {
context . commit ( 'downloadVoiceMailSucceeded' ) ;
} ) . catch ( ( err ) => {
context . commit ( 'downloadVoiceMailFailed' , err . body . message ) ;
} ) ;
} ,
downloadFax ( context , id ) {
context . commit ( 'downloadFaxRequesting' ) ;
downloadFax ( id ) . then ( ( ) => {
context . commit ( 'downloadFaxSucceeded' ) ;
} ) . catch ( ( err ) => {
context . commit ( 'downloadFaxFailed' , err . body . message ) ;
} ) ;
}
}