Get user deletion working from UI

This commit is contained in:
Matt Rider 2019-06-07 13:37:59 -03:00
parent fcb5ab8f1e
commit 70aa77bd2e
3 changed files with 37 additions and 13 deletions

View File

@ -59,7 +59,12 @@
</ds-flex-item> </ds-flex-item>
<ds-flex-item width="20%" /> <ds-flex-item width="20%" />
<ds-flex-item> <ds-flex-item>
<ds-button icon="trash" danger :disabled="isLoading || !deleteEnabled"> <ds-button
icon="trash"
danger
:disabled="isLoading || !deleteEnabled"
@click="handleSubmit"
>
{{ $t('settings.delete.name') }} {{ $t('settings.delete.name') }}
</ds-button> </ds-button>
</ds-flex-item> </ds-flex-item>
@ -71,6 +76,7 @@
</template> </template>
<script> <script>
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import gql from 'graphql-tag'
export default { export default {
name: 'DeleteAccount', name: 'DeleteAccount',
@ -82,8 +88,6 @@ export default {
}, },
deleteEnabled: false, deleteEnabled: false,
isLoading: false, isLoading: false,
countPosts: 0,
countComments: 0,
} }
}, },
computed: { computed: {
@ -92,12 +96,33 @@ export default {
}), }),
}, },
methods: { methods: {
enableDeletion() { handleSubmit() {
if (this.accept === 'I really want to delete my account') { let resourceArgs = []
this.disabled = false if (this.formData.deleteContributions) {
} else { resourceArgs.push('Post')
this.disabled = true
} }
if (this.formData.deleteComments) {
resourceArgs.push('Comment')
}
this.$apollo
.mutate({
mutation: gql`
mutation($id: ID!, $resource: [String]) {
DeleteUser(id: $id, resource: $resource) {
id
}
}
`,
variables: { id: this.currentUser.id, resource: resourceArgs },
})
.then(() => {
this.$toast.success(this.$t('settings.delete.success'))
this.$store.dispatch('auth/logout')
this.$router.replace('/')
})
.catch(error => {
this.$toast.error(error.message)
})
}, },
}, },
} }

View File

@ -78,7 +78,8 @@
"countPosts": "Delete my {count} posts", "countPosts": "Delete my {count} posts",
"countComments": "Delete my {count} comments", "countComments": "Delete my {count} comments",
"accountDescription": "Be aware that your Post and Comments are important to our community. If you still choose to delete those you have to mark them below.", "accountDescription": "Be aware that your Post and Comments are important to our community. If you still choose to delete those you have to mark them below.",
"accountWarning": "You <b>CAN'T MANAGE</b> and <b>CAN'T RECOVER</b> your Account, Posts... after deleting your account!" "accountWarning": "You <b>CAN'T MANAGE</b> and <b>CAN'T RECOVER</b> your Account, Posts... after deleting your account!",
"success": "Account successfully deleted"
}, },
"organizations": { "organizations": {
"name": "My Organizations" "name": "My Organizations"

View File

@ -13,13 +13,11 @@
resource-type="contribution" resource-type="contribution"
:resource="post" :resource="post"
:callbacks="{ confirm: () => deletePostCallback('page'), cancel: null }" :callbacks="{ confirm: () => deletePostCallback('page'), cancel: null }"
:is-owner="isAuthor(post.author.id)" :is-owner="isAuthor(post.author ? post.author.id : null)"
/> />
</no-ssr> </no-ssr>
<ds-space margin-bottom="small" /> <ds-space margin-bottom="small" />
<ds-heading tag="h3" no-margin> <ds-heading tag="h3" no-margin>{{ post.title }}</ds-heading>
{{ post.title }}
</ds-heading>
<ds-space margin-bottom="small" /> <ds-space margin-bottom="small" />
<!-- Content --> <!-- Content -->
<!-- eslint-disable vue/no-v-html --> <!-- eslint-disable vue/no-v-html -->