Newer
Older
<template>
<b-modal id="add-group-modal" title="Add group" @show="resetModal" ok-title="Add" @ok="addGroup">
<b-form inline>
<label class="w-25" for="new-group-name-input">Group name:</label>
<b-form-input v-model="newGroupName"
id="new-group-name-input"
class="w-75"
aria-describedby="new-group-name-input-feedback"
:state="newGroupNameState"
v-on:input="resetError">
</b-form-input>
<b-form-invalid-feedback id="new-group-name-input-feedback">{{newGroupNameError}}</b-form-invalid-feedback>
</b-form>
</b-modal>
</template>
<script>
import client from 'api-client';
export default {
name: 'AddGroupModal',
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
computed: {
newGroupNameState() {
if(this.newGroupNameError) {
return 'invalid';
}
}
},
data: function() {
return {
newGroupName: null,
newGroupNameError: null
};
},
methods: {
resetModal: function() {
this.newGroupName = null;
this.resetError();
},
resetError: function() {
this.newGroupNameError = null;
},
addGroup: function(event) {
// Prevent modal from closing
event.preventDefault();
if(!this.newGroupName) {
this.newGroupNameError = "Group name is required";
return;
}
let parent = this.$store.getters.selectedGroupId;
client.addGroup(this.newGroupName, this.$store.state.input)
.then(res => {
if(res.status === 400) {
this.newGroupNameError = res.message;
} else {
this.$store.commit('updateGroupsPanel', res);
this.$bvModal.hide('add-group-modal');
}
});
}
}
}
</script>