Add.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <SmartModal v-if="show" :title="$t('team.new')" @close="hideModal">
  3. <template #body>
  4. <div class="flex flex-col px-2">
  5. <input
  6. id="selectLabelTeamAdd"
  7. v-model="name"
  8. v-focus
  9. class="input floating-input"
  10. placeholder=" "
  11. type="text"
  12. autocomplete="off"
  13. @keyup.enter="addNewTeam"
  14. />
  15. <label for="selectLabelTeamAdd">
  16. {{ $t("action.label") }}
  17. </label>
  18. </div>
  19. </template>
  20. <template #footer>
  21. <span>
  22. <ButtonPrimary :label="$t('action.save')" @click.native="addNewTeam" />
  23. <ButtonSecondary
  24. :label="$t('action.cancel')"
  25. @click.native="hideModal"
  26. />
  27. </span>
  28. </template>
  29. </SmartModal>
  30. </template>
  31. <script>
  32. import { defineComponent } from "@nuxtjs/composition-api"
  33. import * as teamUtils from "~/helpers/teams/utils"
  34. export default defineComponent({
  35. props: {
  36. show: Boolean,
  37. },
  38. data() {
  39. return {
  40. name: null,
  41. }
  42. },
  43. methods: {
  44. addNewTeam() {
  45. // We save the user input in case of an error
  46. const name = this.name
  47. // We clear it early to give the UI a snappy feel
  48. this.name = ""
  49. if (!name) {
  50. this.$toast.error(this.$t("empty.team_name"), {
  51. icon: "error_outline",
  52. })
  53. return
  54. }
  55. if (name !== null && name.replace(/\s/g, "").length < 6) {
  56. this.$toast.error(this.$t("team.name_length_insufficient"), {
  57. icon: "error_outline",
  58. })
  59. return
  60. }
  61. // Call to the graphql mutation
  62. teamUtils
  63. .createTeam(this.$apollo, name)
  64. .then(() => {
  65. this.hideModal()
  66. })
  67. .catch((e) => {
  68. console.error(e)
  69. // We restore the initial user input
  70. this.name = name
  71. })
  72. this.hideModal()
  73. },
  74. hideModal() {
  75. this.name = null
  76. this.$emit("hide-modal")
  77. },
  78. },
  79. })
  80. </script>