index.vue 3.9 KB

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