diff --git a/src/components/ImportModal.vue b/src/components/ImportModal.vue
new file mode 100644
index 0000000..fc859c6
--- /dev/null
+++ b/src/components/ImportModal.vue
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+ Your current data will be erased and overwritten with the imported data!
+
+
+
+
+
diff --git a/src/components/form/AppFileInput.vue b/src/components/form/AppFileInput.vue
new file mode 100644
index 0000000..928a437
--- /dev/null
+++ b/src/components/form/AppFileInput.vue
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
diff --git a/src/store/data.js b/src/store/data.js
new file mode 100644
index 0000000..3a0e0d5
--- /dev/null
+++ b/src/store/data.js
@@ -0,0 +1,41 @@
+import localForage from 'localforage';
+import { download } from '../utils/helpers';
+
+export default {
+ namespaced: true,
+ state: {
+ isImportModalOpen: false,
+ },
+ mutations: {
+ isImportModalOpen(state, isOpen) {
+ state.isImportModalOpen = isOpen;
+ },
+ },
+ actions: {
+ async exportJson() {
+ let results = [];
+ const keys = await localForage.keys();
+ keys.forEach((key) => {
+ results.push(localForage.getItem(key));
+ });
+ results = await Promise.all(results);
+
+ const data = {};
+ keys.forEach((key, index) => {
+ data[key] = results[index];
+ });
+
+ download(JSON.stringify(data), 'serverless-invoices.json', 'application/json');
+ },
+ async importJson({ dispatch }, data) {
+ const results = [];
+ Object.keys(data).forEach((key) => {
+ results.push(localForage.setItem(key, data[key]));
+ });
+ await Promise.all(results);
+ await dispatch('teams/terminate', null, { root: true });
+ return dispatch('teams/init', null, { root: true });
+ },
+ },
+ getters: {},
+};
diff --git a/src/store/store.js b/src/store/store.js
index 32e5b75..22298b3 100644
--- a/src/store/store.js
+++ b/src/store/store.js
@@ -12,8 +12,7 @@ import clients from '@/store/clients';
import invoices from '@/store/invoices';
import teams from '@/store/teams';
import themes from '@/store/themes';
-import localForage from 'localforage';
-import { download } from '../utils/helpers';
+import data from '@/store/data';
Vue.use(Vuex);
@@ -34,27 +33,9 @@ export default new Vuex.Store({
invoices,
teams,
themes,
+ data,
},
state: {},
mutations: {},
- actions: {
- async exportJson() {
- let results = [];
- const keys = await localForage.keys();
- keys.forEach((key) => {
- results.push(localForage.getItem(key));
- });
- results = await Promise.all(results);
-
- const data = {};
- keys.forEach((key, index) => {
- data[key] = results[index];
- });
-
- download(JSON.stringify(data), 'serverless-invoices.json', 'application/json');
- },
- importJson() {
-
- },
- },
+ actions: {},
});
diff --git a/src/store/teams.js b/src/store/teams.js
index ba639f7..0b65fce 100644
--- a/src/store/teams.js
+++ b/src/store/teams.js
@@ -7,9 +7,11 @@ export default {
mutations: {},
actions: {
async init({ dispatch }) {
- dispatch('clients/terminate', null, { root: true });
- dispatch('bankAccounts/terminate', null, { root: true });
- dispatch('invoices/terminate', null, { root: true });
+ await Promise.all([
+ dispatch('clients/terminate', null, { root: true }),
+ dispatch('bankAccounts/terminate', null, { root: true }),
+ dispatch('invoices/terminate', null, { root: true }),
+ ]);
await dispatch('getTeam');
@@ -17,6 +19,9 @@ export default {
dispatch('bankAccounts/init', null, { root: true });
dispatch('invoices/init', null, { root: true });
},
+ async terminate() {
+ return Team.deleteAll();
+ },
async getTeam() {
const team = await TeamService.getTeam();
await Team.create({ data: team });
diff --git a/src/views/dashboard/Dashboard.vue b/src/views/dashboard/Dashboard.vue
index 373c601..386f854 100644
--- a/src/views/dashboard/Dashboard.vue
+++ b/src/views/dashboard/Dashboard.vue
@@ -16,7 +16,7 @@
What about my data?
@@ -46,6 +46,7 @@
+
@@ -54,6 +55,7 @@ import { mapGetters, mapState } from 'vuex';
import ClientModal from '@/components/clients/ClientModal';
import BankAccountModal from '@/components/bank-accounts/BankAccountModal';
import { VBTooltip } from 'bootstrap-vue';
+import ImportModal from '../../components/ImportModal';
export default {
@@ -61,6 +63,7 @@ export default {
'b-tooltip': VBTooltip,
},
components: {
+ ImportModal,
BankAccountModal,
ClientModal,
},
diff --git a/src/views/dashboard/Invoices.vue b/src/views/dashboard/Invoices.vue
index da6f387..1622fa4 100644
--- a/src/views/dashboard/Invoices.vue
+++ b/src/views/dashboard/Invoices.vue
@@ -9,7 +9,7 @@
more_vert
Export
- Import
+ Import
@@ -46,10 +46,10 @@ export default {
.then(id => this.$router.push({ name: 'invoice', params: { id } }));
},
exportJson() {
- this.$store.dispatch('exportJson');
+ this.$store.dispatch('data/exportJson');
},
- importJson() {
- this.$store.dispatch('importJson');
+ openImportModal() {
+ this.$store.commit('data/isImportModalOpen', true);
},
},
};