Skip to content

Commit

Permalink
fix(textile): catch textile errors during registration and show error…
Browse files Browse the repository at this point in the history
… popup
  • Loading branch information
vimercati-samir authored and stavares843 committed May 10, 2022
1 parent 29f80ab commit 271827e
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 45 deletions.
2 changes: 1 addition & 1 deletion components/ui/Popups/ErrorNetwork/ErrorNetwork.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:size="6"
class="subtitle"
/>
<InteractablesButton type="primary" class="action" :action="action">
<InteractablesButton type="primary" class="action" :action="tryAgain">
<refresh-cw-icon size="1.5x" />
<TypographyText
:text="$t('popups.error_network.action')"
Expand Down
25 changes: 20 additions & 5 deletions components/ui/Popups/ErrorNetwork/ErrorNetwork.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,26 @@ export default Vue.extend({
components: {
RefreshCwIcon,
},
props: {
action: {
type: Function,
default: () => {},
required: true,
methods: {
/**
* @method toggleNetworkErrorPopup
* @description
* @example
*/
closeNetworkErrorPopup() {
this.$store.commit('ui/toggleErrorNetworkModal', {
state: false,
action: null,
})
},
/**
* @method tryAgain
* @description
* @example
*/
tryAgain() {
this.$store.state.ui.modals.errorNetwork.action()
this.closeNetworkErrorPopup()
},
},
})
Expand Down
3 changes: 3 additions & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<div id="app" :class="$store.state.ui.theme.base.class">
<UiModal v-if="$store.state.ui.modals.errorNetwork.isOpen" nopad>
<UiPopupsErrorNetwork />
</UiModal>
<Nuxt />
<!-- Sets the global css variable for the theme flair color -->
<v-style>
Expand Down
17 changes: 12 additions & 5 deletions pages/auth/register/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,18 @@ export default Vue.extend({
},
methods: {
async confirm(userData: UserRegistrationData) {
this.$store.dispatch('accounts/registerUser', {
name: userData.username,
image: userData.photoHash,
status: userData.status,
})
try {
await this.$store.dispatch('accounts/registerUser', {
name: userData.username,
image: userData.photoHash,
status: userData.status,
})
} catch (error: any) {
this.$store.commit('ui/toggleErrorNetworkModal', {
state: true,
action: () => this.confirm(userData),
})
}
},
},
})
Expand Down
33 changes: 2 additions & 31 deletions pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<template>
<div class="container">
<UiModal
v-if="$store.state.ui.modals.errorNetwork"
v-click-outside="() => toggleNetworkErrorPopup()"
nopad
>
<UiPopupsErrorNetwork :action="tryAgain" />
</UiModal>
<UiLoadersPageLoader
:is-loading="true"
:title="$t('pages.loading.loading')"
Expand Down Expand Up @@ -86,34 +79,12 @@ export default Vue.extend({
return
}
this.$store.commit('ui/toggleModal', {
name: 'errorNetwork',
this.$store.commit('ui/toggleErrorNetworkModal', {
state: true,
action: this.loadAccount,
})
}
},
/**
* @method toggleNetworkErrorPopup
* @description
* @example
*/
toggleNetworkErrorPopup() {
const modalName = 'errorNetwork'
this.$store.commit('ui/toggleModal', {
name: modalName,
state: !this.$store.state.ui.modals[modalName],
})
},
/**
* @method tryAgain
* @description
* @example
*/
tryAgain() {
this.toggleNetworkErrorPopup()
this.loadAccount()
},
},
})
</script>
Expand Down
5 changes: 4 additions & 1 deletion store/ui/__snapshots__/state.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ Object {
"creategroup": false,
"crop": false,
"error": false,
"errorNetwork": false,
"errorNetwork": Object {
"action": null,
"isOpen": false,
},
"glyph": false,
"groupInvite": Object {
"isOpen": false,
Expand Down
7 changes: 7 additions & 0 deletions store/ui/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ export default {
// @ts-ignore
state.modals[modal.name] = modal.state
},
toggleErrorNetworkModal(
state: UIState,
modal: { state: boolean; action: Function | null },
) {
// @ts-ignore
state.modals.errorNetwork = { isOpen: modal.state, action: modal.action }
},
setGlyphModalPack(state: UIState, pack: string) {
state.glyphModalPack = pack
},
Expand Down
2 changes: 1 addition & 1 deletion store/ui/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const InitialUIState = (): UIState => ({
callToAction: false,
renameFile: false,
crop: false,
errorNetwork: false,
errorNetwork: { isOpen: false, action: null },
},
glyphModalPack: '',
chatbarContent: '',
Expand Down
2 changes: 1 addition & 1 deletion store/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export interface UIState {
showSearchResult: boolean
showSidebar: boolean
modals: {
[key: string]: boolean
[key: string]: boolean | object
}
glyphModalPack: string
chatbarContent: string
Expand Down

0 comments on commit 271827e

Please sign in to comment.