Add.vue 1.6 KB

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