Add.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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").toString(), {
  51. icon: "error_outline",
  52. })
  53. return
  54. }
  55. addGraphqlCollection(
  56. makeCollection<HoppGQLRequest>({
  57. name: this.name,
  58. folders: [],
  59. requests: [],
  60. })
  61. )
  62. this.hideModal()
  63. },
  64. hideModal() {
  65. this.name = null
  66. this.$emit("hide-modal")
  67. },
  68. },
  69. })
  70. </script>