fix: access namespace only if loaded

This commit is contained in:
Dominik Pschenitschni 2021-10-02 22:19:55 +02:00
parent 1964c1352c
commit e064c3bf96
No known key found for this signature in database
GPG key ID: B257AC0149F43A77
2 changed files with 19 additions and 20 deletions

View file

@ -90,12 +90,7 @@ export default {
return null
},
getNamespaceById: state => namespaceId => {
for (const n in state.namespaces) {
if (state.namespaces[n].id === namespaceId) {
return state.namespaces[n]
}
}
return null
return state.namespaces.find(({id}) => id == namespaceId) || null
},
},
actions: {

View file

@ -13,26 +13,30 @@
</template>
<script>
import NamespaceService from '@/services/namespace'
export default {
name: 'namespace-setting-delete',
data() {
return {
namespaceService: new NamespaceService(),
title: '',
}
computed: {
namespace() {
return this.$store.getters['namespaces/getNamespaceById'](this.$route.params.id)
},
title() {
if (!this.namespace) {
return
}
return this.$t('namespace.delete.title', {namespace: this.namespace.title})
},
},
created() {
const namespace = this.$store.getters['namespaces/getNamespaceById'](this.$route.params.id)
this.title = this.$t('namespace.delete.title', {namespace: namespace.title})
this.setTitle(this.title)
watch: {
title: {
handler(title) {
this.setTitle(title)
},
immediate: true,
},
},
methods: {
deleteNamespace() {
const namespace = this.$store.getters['namespaces/getNamespaceById'](this.$route.params.id)
this.$store.dispatch('namespaces/deleteNamespace', namespace)
this.$store.dispatch('namespaces/deleteNamespace', this.namespace)
.then(() => {
this.$message.success({message: this.$t('namespace.delete.success')})
this.$router.push({name: 'home'})