AddRequest.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <SmartModal
  3. v-if="show"
  4. dialog
  5. :title="$t('request.new')"
  6. @close="$emit('hide-modal')"
  7. >
  8. <template #body>
  9. <div class="flex flex-col px-2">
  10. <input
  11. id="selectLabelGqlAddRequest"
  12. v-model="name"
  13. v-focus
  14. class="input floating-input"
  15. placeholder=" "
  16. type="text"
  17. autocomplete="off"
  18. @keyup.enter="addRequest"
  19. />
  20. <label for="selectLabelGqlAddRequest">
  21. {{ $t("action.label") }}
  22. </label>
  23. </div>
  24. </template>
  25. <template #footer>
  26. <span>
  27. <ButtonPrimary :label="$t('action.save')" @click.native="addRequest" />
  28. <ButtonSecondary
  29. :label="$t('action.cancel')"
  30. @click.native="hideModal"
  31. />
  32. </span>
  33. </template>
  34. </SmartModal>
  35. </template>
  36. <script setup lang="ts">
  37. import { ref, watch } from "@nuxtjs/composition-api"
  38. import { useI18n, useToast } from "~/helpers/utils/composables"
  39. import { getGQLSession } from "~/newstore/GQLSession"
  40. const toast = useToast()
  41. const t = useI18n()
  42. const props = defineProps<{
  43. show: boolean
  44. folderPath?: string
  45. }>()
  46. const emit = defineEmits<{
  47. (e: "hide-modal"): void
  48. (
  49. e: "add-request",
  50. v: {
  51. name: string
  52. path: string | undefined
  53. }
  54. ): void
  55. }>()
  56. const name = ref("")
  57. watch(
  58. () => props.show,
  59. (show) => {
  60. if (show) {
  61. name.value = getGQLSession().request.name
  62. }
  63. }
  64. )
  65. const addRequest = () => {
  66. if (!name.value) {
  67. toast.error(`${t("error.empty_req_name")}`)
  68. return
  69. }
  70. emit("add-request", {
  71. name: name.value,
  72. path: props.folderPath,
  73. })
  74. hideModal()
  75. }
  76. const hideModal = () => {
  77. emit("hide-modal")
  78. }
  79. </script>