api-client/components/teams/Add.vue

82 lines
1.9 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("action.label") }}
2021-08-07 09:21:13 +00:00
</label>
2021-07-09 17:19:45 +00:00
</div>
</template>
<template #footer>
<span>
<ButtonPrimary :label="$t('action.save')" @click.native="addNewTeam" />
<ButtonSecondary
:label="$t('action.cancel')"
@click.native="hideModal"
/>
</span>
</template>
</SmartModal>
</template>
<script>
2021-08-24 03:44:46 +00:00
import { defineComponent } from "@nuxtjs/composition-api"
2021-05-18 09:27:29 +00:00
import * as teamUtils from "~/helpers/teams/utils"
2021-08-24 03:44:46 +00:00
export default defineComponent({
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) {
2021-08-20 09:38:54 +00:00
this.$toast.error(this.$t("empty.team_name"), {
icon: "error_outline",
})
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"), {
2021-08-20 09:38:54 +00:00
icon: "error_outline",
})
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")
},
},
2021-08-24 03:44:46 +00:00
})
</script>