From c194f2c575af7d7735759759ee3dbfda5c768a15 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Sun, 16 Feb 2020 12:18:31 -0500 Subject: [PATCH] add bills page --- src/_helpers/router.js | 2 + src/_services/bill.service.js | 15 +++++ src/_services/index.js | 1 + src/_store/bills.module.js | 67 ++++++++++++++++++++ src/_store/index.js | 4 +- src/account/payment/BillsPage.vue | 94 +++++++++++++++++++++++++++++ src/account/profile/SshKeysPage.vue | 11 ---- 7 files changed, 182 insertions(+), 12 deletions(-) create mode 100644 src/_services/bill.service.js create mode 100644 src/_store/bills.module.js create mode 100644 src/account/payment/BillsPage.vue diff --git a/src/_helpers/router.js b/src/_helpers/router.js index 6488d92..e8a592a 100644 --- a/src/_helpers/router.js +++ b/src/_helpers/router.js @@ -14,6 +14,7 @@ import PolicyPage from '../account/profile/PolicyPage' import DevicesPage from '../account/DevicesPage' import AppsPage from '../account/AppsPage' import AppPage from '../account/AppPage' +import BillsPage from '../account/payment/BillsPage' import AppSitePage from '../account/AppSitePage' import AppDataViewPage from '../account/AppDataViewPage' import AppConfigPage from '../account/AppConfigPage' @@ -65,6 +66,7 @@ export const router = new Router({ { path: '/me/changePassword', component: ChangePasswordPage }, { path: '/me/setPassword/:code', component: SetPasswordPage }, { path: '/me/keys', component: SshKeysPage }, + { path: '/me/bills', component: BillsPage }, { path: '/devices', component: DevicesPage }, { path: '/apps', component: AppsPage }, { path: '/app/:app', component: AppPage }, diff --git a/src/_services/bill.service.js b/src/_services/bill.service.js new file mode 100644 index 0000000..f4558d7 --- /dev/null +++ b/src/_services/bill.service.js @@ -0,0 +1,15 @@ +import config from 'config'; +import { util } from '../_helpers'; + +export const billService = { + getAllBillsByAccount, + getBillByAccountAndId +}; + +function getAllBillsByAccount(userId, messages, errors) { + return fetch(`${config.apiUrl}/users/${userId}/bills`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); +} + +function getBillByAccountAndId(userId, billId, messages, errors) { + return fetch(`${config.apiUrl}/users/${userId}/bills/${billId}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); +} diff --git a/src/_services/index.js b/src/_services/index.js index cefae99..6cf11e6 100644 --- a/src/_services/index.js +++ b/src/_services/index.js @@ -8,3 +8,4 @@ export * from './accountPlan.service'; export * from './network.service'; export * from './device.service'; export * from './app.service'; +export * from './bill.service'; diff --git a/src/_store/bills.module.js b/src/_store/bills.module.js new file mode 100644 index 0000000..2996d6c --- /dev/null +++ b/src/_store/bills.module.js @@ -0,0 +1,67 @@ +import { billService } from '../_services'; +import { util } from '../_helpers'; + +const state = { + loading: { + bills: false, bill: false + }, + error: null, + bills: null, + bill: null +}; + +const actions = { + getAllBillsByAccount({ commit }, {userId, messages, errors}) { + commit('getAllBillsByAccountRequest'); + billService.getAllBillsByAccount(userId, messages, errors) + .then( + bills => commit('getAllBillsByAccountSuccess', bills), + error => commit('getAllBillsByAccountFailure', error) + ); + }, + getBillByAccountAndId({ commit }, {userId, billId, messages, errors}) { + commit('getBillByAccountAndIdRequest'); + billService.getBillByAccountAndId(userId, billId, messages, errors) + .then( + bill => commit('getBillByAccountAndIdSuccess', bill), + error => commit('getBillByAccountAndIdFailure', error) + ); + } +}; + +const mutations = { + getAllBillsByAccountRequest(state) { + state.loading.bills = true; + }, + getAllBillsByAccountSuccess(state, bills) { + state.loading.bills = false; + state.bills = bills; + }, + getAllBillsByAccountFailure(state, error) { + state.loading.bills = false; + state.error = { error }; + }, + getBillByAccountAndIdRequest(state) { + state.loading.bill = true; + }, + getBillByAccountAndIdSuccess(state, bill) { + state.loading.bill = false; + state.bill = bill; + }, + getBillByAccountAndIdFailure(state, error) { + state.loading.bill = false; + state.error = { error }; + } +}; + +const getters = { + loading: util.checkLoading(state.loading) +}; + +export const bills = { + namespaced: true, + state, + actions, + mutations, + getters +}; \ No newline at end of file diff --git a/src/_store/index.js b/src/_store/index.js index 791aa60..0c716b3 100644 --- a/src/_store/index.js +++ b/src/_store/index.js @@ -13,6 +13,7 @@ import { accountPlans } from './accountPlans.module'; import { networks } from './networks.module'; import { devices } from './devices.module'; import { apps } from './apps.module'; +import { bills } from './bills.module'; Vue.use(Vuex); @@ -29,7 +30,8 @@ export const store = new Vuex.Store({ accountPlans, networks, devices, - apps + apps, + bills } }); diff --git a/src/account/payment/BillsPage.vue b/src/account/payment/BillsPage.vue new file mode 100644 index 0000000..d77e8ff --- /dev/null +++ b/src/account/payment/BillsPage.vue @@ -0,0 +1,94 @@ + + + \ No newline at end of file diff --git a/src/account/profile/SshKeysPage.vue b/src/account/profile/SshKeysPage.vue index 2d2e953..03574b4 100644 --- a/src/account/profile/SshKeysPage.vue +++ b/src/account/profile/SshKeysPage.vue @@ -151,13 +151,11 @@ if (this.me) { this.linkPrefix = '/me'; if (this.currentUser === null) { - this.admin = false; console.warn('SshKeysPage.created: /me requested but no currentUser, sending to home page'); this.$router.push('/'); return; } else { - this.admin = this.currentUser.admin === true; this.userId = this.currentUser.uuid; } @@ -175,15 +173,6 @@ this.userId = this.$route.params.id; this.linkPrefix = '/admin/accounts/' + this.userId; } - - // const user = util.currentUser(); - // if (util.userHasLocale(user)) { - // Settings.defaultLocale = util.jsLocale(this.user, null); - // } else if (this.detectedLocale === null) { - // this.detectLocale(); - // } else { - // Settings.defaultLocale = util.jsLocale(null, this.detectedLocale); - // } this.listSshKeysByUserId({userId: this.userId, messages: this.messages, errors: this.errors}); } };