Skip to content

Commit 0810ac0

Browse files
committed
Account settings uses live data
1 parent 2626e78 commit 0810ac0

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

src/capturoo-client/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,29 @@ class CapturooClient {
239239
}
240240
}
241241

242+
/**
243+
* getAccount fetches the account object.
244+
* @param accountId? account id or defaults to the account in the claim if not set
245+
* @returns {Promise.<Account>}
246+
*/
247+
async getAccount(accountId?: string): Promise<Account> {
248+
try {
249+
if (!accountId) {
250+
accountId = this.claimAccountId
251+
}
252+
253+
const response = await this.get(`/accounts/${accountId}`)
254+
if (response.status === 200) {
255+
const account: Account = await response.json()
256+
return account
257+
}
258+
259+
const data = await response.json()
260+
throw new CapturooError(response.status, 'unknown-error', data.toString())
261+
} catch (err) {
262+
throw err
263+
}
264+
}
242265
/**
243266
* createBucket creates a new bucket inside the account associated to the
244267
* currently signed in user

src/store/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export default new Vuex.Store({
1212
user: null
1313
},
1414
getters: {
15+
account(state) {
16+
return state.account
17+
},
1518
buckets(state) {
1619
return state.buckets
1720
},
@@ -54,6 +57,15 @@ export default new Vuex.Store({
5457
throw err
5558
}
5659
},
60+
async getAccount({ commit, state }) {
61+
try {
62+
const account = await capturoo.admin().getAccount()
63+
commit('setAccount', account)
64+
return account
65+
} catch (err) {
66+
throw err
67+
}
68+
},
5769
async signInWithEmailAndPassword({ commit, state }, { email, password }) {
5870
try {
5971
const userCredential = await firebase.auth().signInWithEmailAndPassword(email, password);

src/views/account/AccountSettings.vue

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
<v-card-text>
1818
<v-list-item three-line>
1919
<v-list-item-content>
20-
<v-list-item-title class="headline mb-1">Jon Doe</v-list-item-title>
21-
<v-list-item-subtitle>[email protected]</v-list-item-subtitle>
22-
<p class="grey--text darken-12 pt-4">Created: 28 April 2020 4:25pm</p>
20+
<v-list-item-title class="headline mb-1">{{ account.displayName }}</v-list-item-title>
21+
<v-list-item-subtitle>{{ account.email }}</v-list-item-subtitle>
22+
<p class="grey--text text--darken-1 pt-4">Account id: {{ account.accountId }}</p>
23+
<p class="grey--text text--darken-1 pt-4">Created: {{ account.created }}</p>
2324
</v-list-item-content>
2425
</v-list-item>
2526
</v-card-text>
@@ -33,7 +34,7 @@
3334
<v-list-item three-line>
3435
<v-list-item-content>
3536
<v-list-item-title class="headline mb-1">Private API Key</v-list-item-title>
36-
<v-list-item-subtitle>Crl1Ml8BtiWD1CISVLQeaSgZ6tzZHObZN6tu9dukcf3</v-list-item-subtitle>
37+
<v-list-item-subtitle>{{ account.developerKey }}</v-list-item-subtitle>
3738
</v-list-item-content>
3839
</v-list-item>
3940
</v-card-text>
@@ -50,6 +51,29 @@ export default {
5051
return {
5152
tab: null
5253
}
54+
},
55+
computed: {
56+
account() {
57+
return this.$store.getters.account
58+
}
59+
},
60+
beforeMount: async function() {
61+
this.loading = true;
62+
console.log('loading account')
63+
const account = await this.getBuckets();
64+
console.log('account loaded')
65+
console.log(account)
66+
},
67+
methods: {
68+
async getBuckets() {
69+
const account = await this.$store.dispatch('getAccount')
70+
console.log('method: getBuckets')
71+
console.log(account)
72+
return account
73+
},
74+
async deleteConfirm(bucketId) {
75+
await this.$store.dispatch('deleteBucket', { bucketId })
76+
}
5377
}
5478
}
5579
</script>

0 commit comments

Comments
 (0)