_id.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div class="flex flex-col items-center justify-between">
  3. <div
  4. v-if="invalidLink"
  5. class="flex flex-1 items-center justify-center flex-col"
  6. >
  7. <i class="opacity-75 pb-2 material-icons">error_outline</i>
  8. <h1 class="heading text-center">
  9. {{ $t("error.invalid_link") }}
  10. </h1>
  11. <p class="text-center mt-2">
  12. {{ $t("error.invalid_link_description") }}
  13. </p>
  14. </div>
  15. <div v-else class="flex-col flex-1 p-4 flex items-center justify-center">
  16. <div
  17. v-if="shortcodeDetails.loading"
  18. class="flex-col flex-1 p-4 flex items-center justify-center"
  19. >
  20. <SmartSpinner />
  21. </div>
  22. <div v-else>
  23. <div
  24. v-if="!shortcodeDetails.loading && E.isLeft(shortcodeDetails.data)"
  25. class="flex flex-col p-4 items-center"
  26. >
  27. <i class="mb-4 material-icons">error_outline</i>
  28. <p>
  29. {{ shortcodeDetails.data.left }}
  30. </p>
  31. <p class="mt-4">
  32. <ButtonSecondary to="/" svg="home" filled :label="$t('app.home')" />
  33. <ButtonSecondary
  34. svg="refresh-cw"
  35. :label="$t('app.reload')"
  36. filled
  37. @click.native="reloadApplication"
  38. />
  39. </p>
  40. </div>
  41. <div
  42. v-if="!shortcodeDetails.loading && E.isRight(shortcodeDetails.data)"
  43. class="flex-col flex-1 p-4 flex items-center justify-center"
  44. >
  45. <h1 class="heading">
  46. {{ $t("state.loading") }}
  47. </h1>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </template>
  53. <script lang="ts">
  54. import {
  55. defineComponent,
  56. useContext,
  57. useRoute,
  58. useRouter,
  59. watch,
  60. } from "@nuxtjs/composition-api"
  61. import * as E from "fp-ts/Either"
  62. import { useGQLQuery } from "~/helpers/backend/GQLClient"
  63. import {
  64. ResolveShortcodeDocument,
  65. ResolveShortcodeQuery,
  66. ResolveShortcodeQueryVariables,
  67. } from "~/helpers/backend/graphql"
  68. import { makeRESTRequest } from "~/helpers/types/HoppRESTRequest"
  69. import { setRESTRequest } from "~/newstore/RESTSession"
  70. export default defineComponent({
  71. setup() {
  72. const route = useRoute()
  73. const router = useRouter()
  74. const { localePath } = useContext() as any
  75. const shortcodeDetails = useGQLQuery<
  76. ResolveShortcodeQuery,
  77. ResolveShortcodeQueryVariables,
  78. ""
  79. >({
  80. query: ResolveShortcodeDocument,
  81. variables: {
  82. code: route.value.params.id as string,
  83. },
  84. })
  85. watch(
  86. () => shortcodeDetails.data,
  87. () => {
  88. if (shortcodeDetails.loading) return
  89. const data = shortcodeDetails.data
  90. if (E.isRight(data)) {
  91. const request = JSON.parse(data.right.shortcode?.request as string)
  92. setRESTRequest(makeRESTRequest(request))
  93. router.push({ path: localePath("/") })
  94. }
  95. }
  96. )
  97. const reloadApplication = () => {
  98. window.location.reload()
  99. }
  100. return {
  101. E,
  102. shortcodeDetails,
  103. reloadApplication,
  104. }
  105. },
  106. data() {
  107. return {
  108. invalidLink: false,
  109. shortcodeID: "",
  110. }
  111. },
  112. mounted() {
  113. if (typeof this.$route.params.id === "string") {
  114. this.shortcodeID = this.$route.params.id
  115. }
  116. this.invalidLink = !this.shortcodeID
  117. },
  118. })
  119. </script>