api-client/components/teams/Add.vue

78 lines
1.8 KiB
Vue
Raw Normal View History

<template>
<SmartModal v-if="show" :title="$t('team.new')" @close="hideModal">
<template #body>
2021-07-17 17:40:28 +00:00
<div class="flex flex-col px-2">
2021-07-09 17:19:45 +00:00
<input
id="selectLabelTeamAdd"
v-model="name"
v-focus
2021-08-07 09:21:13 +00:00
class="input floating-input"
placeholder=" "
2021-07-09 17:19:45 +00:00
type="text"
@keyup.enter="addNewTeam"
/>
2021-08-07 09:21:13 +00:00
<label for="selectLabelTeamAdd">
{{ $t("label") }}
</label>
2021-07-09 17:19:45 +00:00
</div>
</template>
<template #footer>
<span>
2021-07-03 13:14:58 +00:00
<ButtonPrimary :label="$t('save')" @click.native="addNewTeam" />
2021-07-09 17:19:45 +00:00
<ButtonSecondary :label="$t('cancel')" @click.native="hideModal" />
</span>
</template>
</SmartModal>
</template>
<script>
2021-05-18 09:27:29 +00:00
import * as teamUtils from "~/helpers/teams/utils"
export default {
props: {
show: Boolean,
},
data() {
return {
name: null,
}
},
methods: {
addNewTeam() {
// We save the user input in case of an error
const name = this.name
// We clear it early to give the UI a snappy feel
this.name = ""
if (!name) {
this.$toast.info(this.$t("empty.team_name"), {
icon: "info",
})
return
}
if (name !== null && name.replace(/\s/g, "").length < 6) {
2021-08-02 15:27:18 +00:00
this.$toast.error(this.$t("team.name_length_insufficient"), {
icon: "error",
})
return
}
// Call to the graphql mutation
2021-05-18 09:27:29 +00:00
teamUtils
.createTeam(this.$apollo, name)
2021-05-18 09:27:29 +00:00
.then(() => {
this.hideModal()
})
.catch((e) => {
console.error(e)
// We restore the initial user input
this.name = name
})
this.hideModal()
},
hideModal() {
this.name = null
this.$emit("hide-modal")
},
},
}
</script>