index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <AppSection label="teams">
  3. <div class="space-y-4 p-4">
  4. <ButtonSecondary
  5. :label="`${t('team.create_new')}`"
  6. outline
  7. @click.native="displayModalAdd(true)"
  8. />
  9. <div
  10. v-if="myTeams.loading"
  11. class="flex flex-col items-center justify-center"
  12. >
  13. <SmartSpinner class="mb-4" />
  14. <span class="text-secondaryLight">{{ t("state.loading") }}</span>
  15. </div>
  16. <div
  17. v-if="
  18. !myTeams.loading &&
  19. E.isRight(myTeams.data) &&
  20. myTeams.data.right.myTeams.length === 0
  21. "
  22. class="flex flex-col text-secondaryLight p-4 items-center justify-center"
  23. >
  24. <img
  25. :src="`/images/states/${$colorMode.value}/add_group.svg`"
  26. loading="lazy"
  27. class="flex-col object-contain object-center h-16 mb-8 w-16 inline-flex"
  28. :alt="`${t('empty.teams')}`"
  29. />
  30. <span class="text-center mb-4">
  31. {{ t("empty.teams") }}
  32. </span>
  33. <ButtonSecondary
  34. :label="`${t('team.create_new')}`"
  35. filled
  36. @click.native="displayModalAdd(true)"
  37. />
  38. </div>
  39. <div
  40. v-else-if="!myTeams.loading && E.isRight(myTeams.data)"
  41. class="grid gap-4"
  42. :class="
  43. modal ? 'grid-cols-1' : 'sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4'
  44. "
  45. >
  46. <TeamsTeam
  47. v-for="(team, index) in myTeams.data.right.myTeams"
  48. :key="`team-${String(index)}`"
  49. :team-i-d="team.id"
  50. :team="team"
  51. :compact="modal"
  52. @edit-team="editTeam(team, team.id)"
  53. @invite-team="inviteTeam(team, team.id)"
  54. />
  55. </div>
  56. <div
  57. v-if="!myTeams.loading && E.isLeft(myTeams.data)"
  58. class="flex flex-col items-center"
  59. >
  60. <i class="mb-4 material-icons">help_outline</i>
  61. {{ t("error.something_went_wrong") }}
  62. </div>
  63. </div>
  64. <TeamsAdd :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
  65. <!-- ¯\_(ツ)_/¯ -->
  66. <TeamsEdit
  67. v-if="
  68. !myTeams.loading &&
  69. E.isRight(myTeams.data) &&
  70. myTeams.data.right.myTeams.length > 0
  71. "
  72. :team="myTeams.data.right.myTeams[0]"
  73. :show="showModalEdit"
  74. :editing-team="editingTeam"
  75. :editing-team-i-d="editingTeamID"
  76. @hide-modal="displayModalEdit(false)"
  77. @invite-team="inviteTeam(editingTeam, editingTeamID)"
  78. />
  79. <TeamsInvite
  80. v-if="
  81. !myTeams.loading &&
  82. E.isRight(myTeams.data) &&
  83. myTeams.data.right.myTeams.length > 0
  84. "
  85. :team="myTeams.data.right.myTeams[0]"
  86. :show="showModalInvite"
  87. :editing-team="editingTeam"
  88. :editing-team-i-d="editingTeamID"
  89. @hide-modal="displayModalInvite(false)"
  90. />
  91. </AppSection>
  92. </template>
  93. <script setup lang="ts">
  94. import { ref } from "@nuxtjs/composition-api"
  95. import * as E from "fp-ts/Either"
  96. import { useGQLQuery } from "~/helpers/backend/GQLClient"
  97. import {
  98. MyTeamsDocument,
  99. MyTeamsQuery,
  100. MyTeamsQueryVariables,
  101. } from "~/helpers/backend/graphql"
  102. import { MyTeamsQueryError } from "~/helpers/backend/QueryErrors"
  103. import { useI18n } from "~/helpers/utils/composables"
  104. const t = useI18n()
  105. defineProps<{
  106. modal: boolean
  107. }>()
  108. const showModalAdd = ref(false)
  109. const showModalEdit = ref(false)
  110. const showModalInvite = ref(false)
  111. const editingTeam = ref<any>({}) // TODO: Check this out
  112. const editingTeamID = ref<any>("")
  113. const myTeams = useGQLQuery<
  114. MyTeamsQuery,
  115. MyTeamsQueryVariables,
  116. MyTeamsQueryError
  117. >({
  118. query: MyTeamsDocument,
  119. pollDuration: 5000,
  120. })
  121. const displayModalAdd = (shouldDisplay: boolean) => {
  122. showModalAdd.value = shouldDisplay
  123. }
  124. const displayModalEdit = (shouldDisplay: boolean) => {
  125. showModalEdit.value = shouldDisplay
  126. }
  127. const displayModalInvite = (shouldDisplay: boolean) => {
  128. showModalInvite.value = shouldDisplay
  129. }
  130. const editTeam = (team: any, teamID: any) => {
  131. editingTeam.value = team
  132. editingTeamID.value = teamID
  133. displayModalEdit(true)
  134. }
  135. const inviteTeam = (team: any, teamID: any) => {
  136. editingTeam.value = team
  137. editingTeamID.value = teamID
  138. displayModalInvite(true)
  139. }
  140. </script>