Add.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <SmartModal
  3. v-if="show"
  4. :title="`${$t('environment.new')}`"
  5. @close="hideModal"
  6. >
  7. <template #body>
  8. <div class="flex flex-col px-2">
  9. <input
  10. id="selectLabelEnvAdd"
  11. v-model="name"
  12. v-focus
  13. class="input floating-input"
  14. placeholder=" "
  15. type="text"
  16. autocomplete="off"
  17. @keyup.enter="addNewEnvironment"
  18. />
  19. <label for="selectLabelEnvAdd">
  20. {{ $t("action.label") }}
  21. </label>
  22. </div>
  23. </template>
  24. <template #footer>
  25. <span>
  26. <ButtonPrimary
  27. :label="`${$t('action.save')}`"
  28. @click.native="addNewEnvironment"
  29. />
  30. <ButtonSecondary
  31. :label="`${$t('action.cancel')}`"
  32. @click.native="hideModal"
  33. />
  34. </span>
  35. </template>
  36. </SmartModal>
  37. </template>
  38. <script lang="ts">
  39. import { defineComponent } from "@nuxtjs/composition-api"
  40. import { createEnvironment } from "~/newstore/environments"
  41. export default defineComponent({
  42. props: {
  43. show: Boolean,
  44. },
  45. data() {
  46. return {
  47. name: null as string | null,
  48. }
  49. },
  50. methods: {
  51. addNewEnvironment() {
  52. if (!this.name) {
  53. this.$toast.error(`${this.$t("environment.invalid_name")}`)
  54. return
  55. }
  56. createEnvironment(this.name)
  57. this.hideModal()
  58. },
  59. hideModal() {
  60. this.name = null
  61. this.$emit("hide-modal")
  62. },
  63. },
  64. })
  65. </script>