EditRequest.vue 2.0 KB

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