index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 items-center"
  23. >
  24. <i class="mr-4 material-icons">help_outline</i>
  25. {{ $t("empty.teams") }}
  26. </div>
  27. <div
  28. v-else-if="!myTeams.loading && E.isRight(myTeams.data)"
  29. class="grid gap-4"
  30. :class="modal ? 'grid-cols-1' : 'sm:grid-cols-3 md:grid-cols-4'"
  31. >
  32. <TeamsTeam
  33. v-for="(team, index) in myTeams.data.right.myTeams"
  34. :key="`team-${String(index)}`"
  35. :team-i-d="team.id"
  36. :team="team"
  37. @edit-team="editTeam(team, team.id)"
  38. />
  39. </div>
  40. <div
  41. v-if="!myTeams.loading && E.isLeft(myTeams.data)"
  42. class="flex items-center flex-col"
  43. >
  44. <i class="mb-4 material-icons">help_outline</i>
  45. {{ $t("error.something_went_wrong") }}
  46. </div>
  47. </div>
  48. <TeamsAdd :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
  49. <!-- ¯\_(ツ)_/¯ -->
  50. <TeamsEdit
  51. v-if="
  52. !myTeams.loading &&
  53. E.isRight(myTeams.data) &&
  54. myTeams.data.right.myTeams.length > 0
  55. "
  56. :team="myTeams.data.right.myTeams[0]"
  57. :show="showModalEdit"
  58. :editing-team="editingTeam"
  59. :editingteam-i-d="editingTeamID"
  60. @hide-modal="displayModalEdit(false)"
  61. />
  62. </AppSection>
  63. </template>
  64. <script setup lang="ts">
  65. import { gql } from "@apollo/client/core"
  66. import { ref, watchEffect } from "@nuxtjs/composition-api"
  67. import * as E from "fp-ts/Either"
  68. import { useGQLQuery } from "~/helpers/backend/GQLClient"
  69. import { MyTeamsQueryError } from "~/helpers/backend/QueryErrors"
  70. import { TeamMemberRole } from "~/helpers/backend/types/TeamMemberRole"
  71. defineProps<{
  72. modal: boolean
  73. }>()
  74. const showModalAdd = ref(false)
  75. const showModalEdit = ref(false)
  76. const editingTeam = ref<any>({}) // TODO: Check this out
  77. const editingTeamID = ref<any>("")
  78. const myTeams = useGQLQuery<
  79. {
  80. myTeams: Array<{
  81. id: string
  82. name: string
  83. myRole: TeamMemberRole
  84. ownersCount: number
  85. members: Array<{
  86. membershipID: string
  87. user: {
  88. photoURL: string | null
  89. displayName: string
  90. email: string
  91. uid: string
  92. }
  93. role: TeamMemberRole
  94. }>
  95. }>
  96. },
  97. MyTeamsQueryError
  98. >(
  99. gql`
  100. query GetMyTeams {
  101. myTeams {
  102. id
  103. name
  104. myRole
  105. ownersCount
  106. members {
  107. membershipID
  108. user {
  109. photoURL
  110. displayName
  111. email
  112. uid
  113. }
  114. role
  115. }
  116. }
  117. }
  118. `
  119. )
  120. watchEffect(() => {
  121. console.log(myTeams)
  122. })
  123. const displayModalAdd = (shouldDisplay: boolean) => {
  124. showModalAdd.value = shouldDisplay
  125. }
  126. const displayModalEdit = (shouldDisplay: boolean) => {
  127. showModalEdit.value = shouldDisplay
  128. if (!shouldDisplay) resetSelectedData()
  129. }
  130. const editTeam = (team: any, teamID: any) => {
  131. editingTeam.value = team
  132. editingTeamID.value = teamID
  133. displayModalEdit(true)
  134. }
  135. const resetSelectedData = () => {
  136. editingTeam.value = undefined
  137. editingTeamID.value = undefined
  138. }
  139. </script>