AddRequest.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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="selectLabelAddRequest"
  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="selectLabelAddRequest">{{ $t("action.label") }}</label>
  21. </div>
  22. </template>
  23. <template #footer>
  24. <span>
  25. <ButtonPrimary
  26. :label="$t('action.save')"
  27. :loading="loadingState"
  28. @click.native="addRequest"
  29. />
  30. <ButtonSecondary
  31. :label="$t('action.cancel')"
  32. @click.native="hideModal"
  33. />
  34. </span>
  35. </template>
  36. </SmartModal>
  37. </template>
  38. <script setup lang="ts">
  39. import { ref, watch } from "@nuxtjs/composition-api"
  40. import { useI18n, useToast } from "~/helpers/utils/composables"
  41. import { getRESTRequest } from "~/newstore/RESTSession"
  42. const toast = useToast()
  43. const t = useI18n()
  44. const props = defineProps<{
  45. show: boolean
  46. loadingState: boolean
  47. folder?: object
  48. folderPath?: string
  49. }>()
  50. const emit = defineEmits<{
  51. (e: "hide-modal"): void
  52. (
  53. e: "add-request",
  54. v: {
  55. name: string
  56. folder: object | undefined
  57. path: string | undefined
  58. }
  59. ): void
  60. }>()
  61. const name = ref("")
  62. watch(
  63. () => props.show,
  64. (show) => {
  65. if (show) {
  66. name.value = getRESTRequest().name
  67. }
  68. }
  69. )
  70. const addRequest = () => {
  71. if (!name.value) {
  72. toast.error(`${t("error.empty_req_name")}`)
  73. return
  74. }
  75. emit("add-request", {
  76. name: name.value,
  77. folder: props.folder,
  78. path: props.folderPath,
  79. })
  80. }
  81. const hideModal = () => {
  82. emit("hide-modal")
  83. }
  84. </script>