index.vue 4.2 KB

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