Add.vue 1.6 KB

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