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 return null
}, },
getNamespaceById: state => namespaceId => { getNamespaceById: state => namespaceId => {
for (const n in state.namespaces) { return state.namespaces.find(({id}) => id == namespaceId) || null
if (state.namespaces[n].id === namespaceId) {
return state.namespaces[n]
}
}
return null
}, },
}, },
actions: { actions: {

View file

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