@modyo/cli
Version:
Modyo Command Line Interface
78 lines (69 loc) • 1.73 kB
JavaScript
/* eslint no-param-reassign: ["error", {"ignorePropertyModificationsFor": ["state"] }] */
import Vuex from 'vuex';
import axios from 'axios';
export default new Vuex.Store({
state: {
client: {},
clientId: 1,
fromAccount: {},
toAccount: {},
amount: 0,
toOthers: false,
toEmail: '',
message: '',
fromEmail: '',
sendNotification: false,
},
mutations: {
SET_CLIENT(state, data) {
state.client = data;
},
SET_CLIENT_ID(state, data) {
state.clientId = data;
},
SET_FROM_ACCOUNT(state, data) {
state.fromAccount = data;
},
SET_TO_ACCOUNT(state, data) {
state.toAccount = data;
},
SET_TO_OTHERS(state, data) {
state.toOthers = data;
},
SET_AMOUNT(state, data) {
state.amount = data;
},
SET_TO_EMAIL(state, data) {
state.toEmail = data;
},
SET_MESSAGE(state, data) {
state.message = data;
},
SET_FROM_EMAIL(state, data) {
state.fromEmail = data;
},
SET_SEND_NOTIFICATION(state, data) {
state.sendNotification = data;
},
},
actions: {
DO_DATA_INITIALIZATION(context) {
return new Promise(((resolve, reject) => {
context.dispatch('GET_CLIENT')
.then((client) => {
resolve(client);
})
.catch(error => reject(error));
}));
},
GET_CLIENT(context) {
return axios.get(`https://api-bank.herokuapp.com/api/v1/clients/${context.state.clientId}`)
.then((client) => {
context.commit('SET_CLIENT', client.data);
context.commit('SET_FROM_EMAIL', client.data.email);
return client;
})
.catch(error => error);
},
},
});