chore: split app to commons and web (squash commit)

This commit is contained in:
Andrew Bastin
2022-12-02 02:57:46 -05:00
parent fb827e3586
commit 3d004f2322
535 changed files with 1487 additions and 501 deletions

View File

@@ -0,0 +1,93 @@
<template>
<SmartModal v-if="show" dialog :title="t('team.new')" @close="hideModal">
<template #body>
<div class="flex flex-col">
<input
id="selectLabelTeamAdd"
v-model="name"
v-focus
class="input floating-input"
placeholder=" "
type="text"
autocomplete="off"
@keyup.enter="addNewTeam"
/>
<label for="selectLabelTeamAdd">
{{ t("action.label") }}
</label>
</div>
</template>
<template #footer>
<span class="flex space-x-2">
<ButtonPrimary
:label="t('action.save')"
:loading="isLoading"
outline
@click="addNewTeam"
/>
<ButtonSecondary
:label="t('action.cancel')"
outline
filled
@click="hideModal"
/>
</span>
</template>
</SmartModal>
</template>
<script setup lang="ts">
import { ref } from "vue"
import { pipe } from "fp-ts/function"
import * as TE from "fp-ts/TaskEither"
import { createTeam } from "~/helpers/backend/mutations/Team"
import { TeamNameCodec } from "~/helpers/backend/types/TeamName"
import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast"
const t = useI18n()
const toast = useToast()
defineProps<{
show: boolean
}>()
const emit = defineEmits<{
(e: "hide-modal"): void
}>()
const name = ref<string | null>(null)
const isLoading = ref(false)
const addNewTeam = async () => {
isLoading.value = true
await pipe(
TeamNameCodec.decode(name.value),
TE.fromEither,
TE.mapLeft(() => "invalid_name" as const),
TE.chainW(createTeam),
TE.match(
(err) => {
// err is of type "invalid_name" | GQLError<Err>
if (err === "invalid_name") {
toast.error(`${t("team.name_length_insufficient")}`)
} else {
// Handle GQL errors (use err obj)
}
},
() => {
toast.success(`${t("team.new_created")}`)
hideModal()
}
)
)()
isLoading.value = false
}
const hideModal = () => {
name.value = null
emit("hide-modal")
}
</script>

View File

@@ -0,0 +1,437 @@
<template>
<SmartModal v-if="show" dialog :title="t('team.edit')" @close="hideModal">
<template #body>
<div class="flex flex-col">
<div class="relative flex">
<input
id="selectLabelTeamEdit"
v-model="name"
v-focus
class="input floating-input"
placeholder=" "
type="text"
autocomplete="off"
@keyup.enter="saveTeam"
/>
<label for="selectLabelTeamEdit">
{{ t("action.label") }}
</label>
</div>
<div class="flex items-center justify-between flex-1 pt-4">
<label for="memberList" class="p-4">
{{ t("team.members") }}
</label>
<div class="flex">
<ButtonSecondary
:icon="IconUserPlus"
:label="t('team.invite')"
filled
@click="
() => {
emit('invite-team')
}
"
/>
</div>
</div>
<div
v-if="teamDetails.loading"
class="flex flex-col items-center justify-center"
>
<SmartSpinner class="mb-4" />
<span class="text-secondaryLight">{{ t("state.loading") }}</span>
</div>
<div
v-if="
!teamDetails.loading &&
E.isRight(teamDetails.data) &&
teamDetails.data.right.team.teamMembers
"
class="border rounded border-divider"
>
<div
v-if="teamDetails.data.right.team.teamMembers === 0"
class="flex flex-col items-center justify-center p-4 text-secondaryLight"
>
<img
:src="`/images/states/${colorMode.value}/add_group.svg`"
loading="lazy"
class="inline-flex flex-col object-contain object-center w-16 h-16 my-4"
:alt="`${t('empty.members')}`"
/>
<span class="pb-4 text-center">
{{ t("empty.members") }}
</span>
<ButtonSecondary
:icon="IconUserPlus"
:label="t('team.invite')"
@click="
() => {
emit('invite-team')
}
"
/>
</div>
<div v-else class="divide-y divide-dividerLight">
<div
v-for="(member, index) in membersList"
:key="`member-${index}`"
class="flex divide-x divide-dividerLight"
>
<input
class="flex flex-1 px-4 py-2 bg-transparent"
:placeholder="`${t('team.email')}`"
:name="'param' + index"
:value="member.email"
readonly
/>
<span>
<tippy
interactive
trigger="click"
theme="popover"
:on-shown="() => tippyActions![index].focus()"
>
<span class="select-wrapper">
<input
class="flex flex-1 px-4 py-2 bg-transparent cursor-pointer"
:placeholder="`${t('team.permissions')}`"
:name="'value' + index"
:value="member.role"
readonly
/>
</span>
<template #content="{ hide }">
<div
ref="tippyActions"
class="flex flex-col focus:outline-none"
tabindex="0"
@keyup.escape="hide()"
>
<SmartItem
label="OWNER"
:icon="
member.role === 'OWNER' ? IconCircleDot : IconCircle
"
:active="member.role === 'OWNER'"
@click="
() => {
updateMemberRole(member.userID, 'OWNER')
hide()
}
"
/>
<SmartItem
label="EDITOR"
:icon="
member.role === 'EDITOR' ? IconCircleDot : IconCircle
"
:active="member.role === 'EDITOR'"
@click="
() => {
updateMemberRole(member.userID, 'EDITOR')
hide()
}
"
/>
<SmartItem
label="VIEWER"
:icon="
member.role === 'VIEWER' ? IconCircleDot : IconCircle
"
:active="member.role === 'VIEWER'"
@click="
() => {
updateMemberRole(member.userID, 'VIEWER')
hide()
}
"
/>
</div>
</template>
</tippy>
</span>
<div class="flex">
<ButtonSecondary
id="member"
v-tippy="{ theme: 'tooltip' }"
:title="t('action.remove')"
:icon="IconUserMinus"
color="red"
:loading="isLoadingIndex === index"
@click="removeExistingTeamMember(member.userID, index)"
/>
</div>
</div>
</div>
</div>
<div
v-if="!teamDetails.loading && E.isLeft(teamDetails.data)"
class="flex flex-col items-center"
>
<component :is="IconHelpCircle" class="mb-4 svg-icons" />
{{ t("error.something_went_wrong") }}
</div>
</div>
</template>
<template #footer>
<span class="flex space-x-2">
<ButtonPrimary
:label="t('action.save')"
:loading="isLoading"
outline
@click="saveTeam"
/>
<ButtonSecondary
:label="t('action.cancel')"
outline
filled
@click="hideModal"
/>
</span>
</template>
</SmartModal>
</template>
<script setup lang="ts">
import { computed, ref, toRef, watch } from "vue"
import * as E from "fp-ts/Either"
import {
GetTeamDocument,
GetTeamQuery,
GetTeamQueryVariables,
TeamMemberAddedDocument,
TeamMemberRemovedDocument,
TeamMemberRole,
TeamMemberUpdatedDocument,
} from "~/helpers/backend/graphql"
import {
removeTeamMember,
renameTeam,
updateTeamMemberRole,
} from "~/helpers/backend/mutations/Team"
import { TeamNameCodec } from "~/helpers/backend/types/TeamName"
import { useGQLQuery } from "~/composables/graphql"
import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast"
import { useColorMode } from "@composables/theming"
import { TippyComponent } from "vue-tippy"
import IconCircleDot from "~icons/lucide/circle-dot"
import IconCircle from "~icons/lucide/circle"
import IconUserPlus from "~icons/lucide/user-plus"
import IconUserMinus from "~icons/lucide/user-minus"
import IconHelpCircle from "~icons/lucide/help-circle"
const t = useI18n()
const colorMode = useColorMode()
const emit = defineEmits<{
(e: "hide-modal"): void
(e: "refetch-teams"): void
(e: "invite-team"): void
}>()
// Template refs
const tippyActions = ref<TippyComponent[] | null>(null)
const props = defineProps<{
show: boolean
editingTeam: {
name: string
}
editingTeamID: string
}>()
const toast = useToast()
const name = toRef(props.editingTeam, "name")
watch(
() => props.editingTeam.name,
(newName: string) => {
name.value = newName
}
)
watch(
() => props.editingTeamID,
(teamID: string) => {
teamDetails.execute({ teamID })
}
)
const teamDetails = useGQLQuery<GetTeamQuery, GetTeamQueryVariables, "">({
query: GetTeamDocument,
variables: {
teamID: props.editingTeamID,
},
pollDuration: 10000,
defer: true,
updateSubs: computed(() => {
if (props.editingTeamID) {
return [
{
key: 1,
query: TeamMemberAddedDocument,
variables: {
teamID: props.editingTeamID,
},
},
{
key: 2,
query: TeamMemberUpdatedDocument,
variables: {
teamID: props.editingTeamID,
},
},
{
key: 3,
query: TeamMemberRemovedDocument,
variables: {
teamID: props.editingTeamID,
},
},
]
} else return []
}),
})
watch(
() => props.show,
(show) => {
if (!show) {
teamDetails.pause()
} else {
teamDetails.unpause()
}
}
)
const roleUpdates = ref<
{
userID: string
role: TeamMemberRole
}[]
>([])
watch(
() => teamDetails,
() => {
if (teamDetails.loading) return
const data = teamDetails.data
if (E.isRight(data)) {
const members = data.right.team?.teamMembers ?? []
// Remove deleted members
roleUpdates.value = roleUpdates.value.filter(
(update) =>
members.findIndex((y) => y.user.uid === update.userID) !== -1
)
}
}
)
const updateMemberRole = (userID: string, role: TeamMemberRole) => {
const updateIndex = roleUpdates.value.findIndex(
(item) => item.userID === userID
)
if (updateIndex !== -1) {
// Role Update exists
roleUpdates.value[updateIndex].role = role
} else {
// Role Update does not exist
roleUpdates.value.push({
userID,
role,
})
}
}
const membersList = computed(() => {
if (teamDetails.loading) return []
const data = teamDetails.data
if (E.isLeft(data)) return []
if (E.isRight(data)) {
const members = (data.right.team?.teamMembers ?? []).map((member) => {
const updatedRole = roleUpdates.value.find(
(update) => update.userID === member.user.uid
)
return {
userID: member.user.uid,
email: member.user.email!,
role: updatedRole?.role ?? member.role,
}
})
return members
}
return []
})
const isLoadingIndex = ref<null | number>(null)
const removeExistingTeamMember = async (userID: string, index: number) => {
isLoadingIndex.value = index
const removeTeamMemberResult = await removeTeamMember(
userID,
props.editingTeamID
)()
if (E.isLeft(removeTeamMemberResult)) {
toast.error(`${t("error.something_went_wrong")}`)
} else {
toast.success(`${t("team.member_removed")}`)
emit("refetch-teams")
teamDetails.execute({ teamID: props.editingTeamID })
}
isLoadingIndex.value = null
}
const isLoading = ref(false)
const saveTeam = async () => {
isLoading.value = true
if (name.value !== "") {
if (TeamNameCodec.is(name.value)) {
const updateTeamNameResult = await renameTeam(
props.editingTeamID,
name.value
)()
if (E.isLeft(updateTeamNameResult)) {
toast.error(`${t("error.something_went_wrong")}`)
} else {
roleUpdates.value.forEach(async (update) => {
const updateMemberRoleResult = await updateTeamMemberRole(
update.userID,
props.editingTeamID,
update.role
)()
if (E.isLeft(updateMemberRoleResult)) {
toast.error(`${t("error.something_went_wrong")}`)
console.error(updateMemberRoleResult.left.error)
}
})
}
hideModal()
toast.success(`${t("team.saved")}`)
} else {
toast.error(`${t("team.name_length_insufficient")}`)
}
} else {
toast.error(`${t("empty.team_name")}`)
}
isLoading.value = false
}
const hideModal = () => {
emit("hide-modal")
}
</script>

View File

@@ -0,0 +1,574 @@
<template>
<SmartModal v-if="show" dialog :title="t('team.invite')" @close="hideModal">
<template #body>
<div v-if="sendInvitesResult.length" class="flex flex-col px-4">
<div class="flex flex-col items-center justify-center max-w-md">
<icon-lucide-users class="w-6 h-6 text-accent" />
<h3 class="my-2 text-lg text-center">
{{ t("team.we_sent_invite_link") }}
</h3>
<p class="text-center">
{{ t("team.we_sent_invite_link_description") }}
</p>
</div>
<div
class="flex flex-col p-4 mt-8 border rounded space-y-6 border-dividerLight"
>
<div
v-for="(invitee, index) in sendInvitesResult"
:key="`invitee-${index}`"
>
<p class="flex items-center">
<component
:is="
invitee.status === 'error' ? IconAlertTriangle : IconMailCheck
"
class="mr-4 svg-icons"
:class="
invitee.status === 'error' ? 'text-red-500' : 'text-green-500'
"
/>
<span class="truncate">{{ invitee.email }}</span>
</p>
<p v-if="invitee.status === 'error'" class="mt-2 ml-8 text-red-500">
{{ getErrorMessage(invitee.error) }}
</p>
</div>
</div>
</div>
<div
v-else-if="sendingInvites"
class="flex items-center justify-center p-4"
>
<SmartSpinner />
</div>
<div v-else class="flex flex-col">
<div class="flex items-center justify-between flex-1">
<label for="memberList" class="px-4 pb-4">
{{ t("team.pending_invites") }}
</label>
</div>
<div class="border rounded divide-y divide-dividerLight border-divider">
<div
v-if="pendingInvites.loading"
class="flex items-center justify-center p-4"
>
<SmartSpinner />
</div>
<div v-else>
<div
v-if="!pendingInvites.loading && E.isRight(pendingInvites.data)"
class="divide-y divide-dividerLight"
>
<div
v-for="(invitee, index) in pendingInvites.data.right.team
.teamInvitations"
:key="`invitee-${index}`"
class="flex divide-x divide-dividerLight"
>
<input
v-if="invitee"
class="flex flex-1 px-4 py-2 bg-transparent text-secondaryLight"
:placeholder="`${t('team.email')}`"
:name="'param' + index"
:value="invitee.inviteeEmail"
readonly
/>
<input
class="flex flex-1 px-4 py-2 bg-transparent text-secondaryLight"
:placeholder="`${t('team.permissions')}`"
:name="'value' + index"
:value="invitee.inviteeRole"
readonly
/>
<div class="flex">
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
:title="t('action.remove')"
:icon="IconTrash"
color="red"
:loading="isLoadingIndex === index"
@click="removeInvitee(invitee.id, index)"
/>
</div>
</div>
</div>
<div
v-if="
E.isRight(pendingInvites.data) &&
pendingInvites.data.right.team.teamInvitations.length === 0
"
class="flex flex-col items-center justify-center p-4 text-secondaryLight"
>
<span class="text-center">
{{ t("empty.pending_invites") }}
</span>
</div>
<div
v-if="!pendingInvites.loading && E.isLeft(pendingInvites.data)"
class="flex flex-col items-center p-4"
>
<component :is="IconHelpCircle" class="mb-4 svg-icons" />
{{ t("error.something_went_wrong") }}
</div>
</div>
</div>
<div class="flex items-center justify-between flex-1 pt-4">
<label for="memberList" class="p-4">
{{ t("team.invite_tooltip") }}
</label>
<div class="flex">
<ButtonSecondary
:icon="IconPlus"
:label="t('add.new')"
filled
@click="addNewInvitee"
/>
</div>
</div>
<div class="border rounded divide-y divide-dividerLight border-divider">
<div
v-for="(invitee, index) in newInvites"
:key="`new-invitee-${index}`"
class="flex divide-x divide-dividerLight"
>
<input
v-model="invitee.key"
class="flex flex-1 px-4 py-2 bg-transparent"
:placeholder="`${t('team.email')}`"
:name="'invitee' + index"
autofocus
/>
<span>
<tippy
interactive
trigger="click"
theme="popover"
:on-shown="() => tippyActions![index].focus()"
>
<span class="select-wrapper">
<input
class="flex flex-1 px-4 py-2 bg-transparent cursor-pointer"
:placeholder="`${t('team.permissions')}`"
:name="'value' + index"
:value="invitee.value"
readonly
/>
</span>
<template #content="{ hide }">
<div
ref="tippyActions"
class="flex flex-col focus:outline-none"
tabindex="0"
@keyup.escape="hide()"
>
<SmartItem
label="OWNER"
:icon="
invitee.value === 'OWNER' ? IconCircleDot : IconCircle
"
:active="invitee.value === 'OWNER'"
@click="
() => {
updateNewInviteeRole(index, 'OWNER')
hide()
}
"
/>
<SmartItem
label="EDITOR"
:icon="
invitee.value === 'EDITOR' ? IconCircleDot : IconCircle
"
:active="invitee.value === 'EDITOR'"
@click="
() => {
updateNewInviteeRole(index, 'EDITOR')
hide()
}
"
/>
<SmartItem
label="VIEWER"
:icon="
invitee.value === 'VIEWER' ? IconCircleDot : IconCircle
"
:active="invitee.value === 'VIEWER'"
@click="
() => {
updateNewInviteeRole(index, 'VIEWER')
hide()
}
"
/>
</div>
</template>
</tippy>
</span>
<div class="flex">
<ButtonSecondary
id="member"
v-tippy="{ theme: 'tooltip' }"
:title="t('action.remove')"
:icon="IconTrash"
color="red"
@click="removeNewInvitee(index)"
/>
</div>
</div>
<div
v-if="newInvites.length === 0"
class="flex flex-col items-center justify-center p-4 text-secondaryLight"
>
<img
:src="`/images/states/${colorMode.value}/add_group.svg`"
loading="lazy"
class="inline-flex flex-col object-contain object-center w-16 h-16 mb-4"
:alt="`${t('empty.invites')}`"
/>
<span class="pb-4 text-center">
{{ t("empty.invites") }}
</span>
<ButtonSecondary
:label="t('add.new')"
filled
@click="addNewInvitee"
/>
</div>
</div>
<div
v-if="newInvites.length"
class="flex flex-col items-start px-4 py-4 mt-4 border rounded border-dividerLight"
>
<span
class="flex items-center justify-center px-2 py-1 mb-4 font-semibold border rounded-full bg-primaryDark border-divider"
>
<component
:is="IconHelpCircle"
class="mr-2 text-secondaryLight svg-icons"
/>
{{ t("profile.roles") }}
</span>
<p>
<span class="text-secondaryLight">
{{ t("profile.roles_description") }}
</span>
</p>
<ul class="mt-4 space-y-4">
<li class="flex">
<span
class="w-1/4 font-semibold uppercase truncate text-secondaryDark max-w-16"
>
{{ t("profile.owner") }}
</span>
<span class="flex flex-1">
{{ t("profile.owner_description") }}
</span>
</li>
<li class="flex">
<span
class="w-1/4 font-semibold uppercase truncate text-secondaryDark max-w-16"
>
{{ t("profile.editor") }}
</span>
<span class="flex flex-1">
{{ t("profile.editor_description") }}
</span>
</li>
<li class="flex">
<span
class="w-1/4 font-semibold uppercase truncate text-secondaryDark max-w-16"
>
{{ t("profile.viewer") }}
</span>
<span class="flex flex-1">
{{ t("profile.viewer_description") }}
</span>
</li>
</ul>
</div>
</div>
</template>
<template #footer>
<p
v-if="sendInvitesResult.length"
class="flex justify-between flex-1 text-secondaryLight"
>
<ButtonSecondary
class="link !p-0"
:label="t('team.invite_more')"
:icon="IconArrowLeft"
@click="
() => {
sendInvitesResult = []
newInvites = [
{
key: '',
value: TeamMemberRole.Viewer,
},
]
}
"
/>
<ButtonSecondary
class="link !p-0"
:label="`${t('action.dismiss')}`"
@click="hideModal"
/>
</p>
<span v-else class="flex space-x-2">
<ButtonPrimary :label="t('team.invite')" outline @click="sendInvites" />
<ButtonSecondary
:label="t('action.cancel')"
outline
filled
@click="hideModal"
/>
</span>
</template>
</SmartModal>
</template>
<script setup lang="ts">
import { watch, ref, reactive, computed } from "vue"
import * as T from "fp-ts/Task"
import * as E from "fp-ts/Either"
import * as A from "fp-ts/Array"
import * as O from "fp-ts/Option"
import { flow, pipe } from "fp-ts/function"
import { Email, EmailCodec } from "../../helpers/backend/types/Email"
import {
TeamInvitationAddedDocument,
TeamInvitationRemovedDocument,
TeamMemberRole,
GetPendingInvitesDocument,
GetPendingInvitesQuery,
GetPendingInvitesQueryVariables,
} from "../../helpers/backend/graphql"
import {
createTeamInvitation,
CreateTeamInvitationErrors,
revokeTeamInvitation,
} from "../../helpers/backend/mutations/TeamInvitation"
import { GQLError } from "~/helpers/backend/GQLClient"
import { useGQLQuery } from "@composables/graphql"
import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast"
import { useColorMode } from "~/composables/theming"
import IconTrash from "~icons/lucide/trash"
import IconPlus from "~icons/lucide/plus"
import IconHelpCircle from "~icons/lucide/help-circle"
import IconAlertTriangle from "~icons/lucide/alert-triangle"
import IconMailCheck from "~icons/lucide/mail-check"
import IconCircleDot from "~icons/lucide/circle-dot"
import IconCircle from "~icons/lucide/circle"
import IconArrowLeft from "~icons/lucide/arrow-left"
import { TippyComponent } from "vue-tippy"
const t = useI18n()
const toast = useToast()
const colorMode = useColorMode()
// Template refs
const tippyActions = ref<TippyComponent[] | null>(null)
const props = defineProps({
show: Boolean,
editingTeamID: { type: String, default: null },
})
const emit = defineEmits<{
(e: "hide-modal"): void
}>()
const pendingInvites = useGQLQuery<
GetPendingInvitesQuery,
GetPendingInvitesQueryVariables,
""
>({
query: GetPendingInvitesDocument,
variables: reactive({
teamID: props.editingTeamID,
}),
pollDuration: 10000,
updateSubs: computed(() =>
!props.editingTeamID
? []
: [
{
key: 4,
query: TeamInvitationAddedDocument,
variables: {
teamID: props.editingTeamID,
},
},
{
key: 5,
query: TeamInvitationRemovedDocument,
variables: {
teamID: props.editingTeamID,
},
},
]
),
defer: true,
})
watch(
() => props.show,
(show) => {
if (!show) {
pendingInvites.pause()
} else {
pendingInvites.unpause()
}
}
)
watch(
() => props.editingTeamID,
() => {
if (props.editingTeamID) {
pendingInvites.execute({
teamID: props.editingTeamID,
})
}
}
)
const isLoadingIndex = ref<null | number>(null)
const removeInvitee = async (id: string, index: number) => {
isLoadingIndex.value = index
const result = await revokeTeamInvitation(id)()
if (E.isLeft(result)) {
toast.error(`${t("error.something_went_wrong")}`)
} else {
toast.success(`${t("team.member_removed")}`)
}
isLoadingIndex.value = null
}
const newInvites = ref<Array<{ key: string; value: TeamMemberRole }>>([
{
key: "",
value: TeamMemberRole.Viewer,
},
])
const addNewInvitee = () => {
newInvites.value.push({
key: "",
value: TeamMemberRole.Viewer,
})
}
const updateNewInviteeRole = (index: number, role: TeamMemberRole) => {
newInvites.value[index].value = role
}
const removeNewInvitee = (id: number) => {
newInvites.value.splice(id, 1)
}
type SendInvitesErrorType =
| {
email: Email
status: "error"
error: GQLError<CreateTeamInvitationErrors>
}
| {
email: Email
status: "success"
}
const sendInvitesResult = ref<Array<SendInvitesErrorType>>([])
const sendingInvites = ref<boolean>(false)
const sendInvites = async () => {
const validationResult = pipe(
newInvites.value,
O.fromPredicate(
(invites): invites is Array<{ key: Email; value: TeamMemberRole }> =>
pipe(
invites,
A.every((invitee) => EmailCodec.is(invitee.key))
)
),
O.map(
A.map((invitee) =>
createTeamInvitation(invitee.key, invitee.value, props.editingTeamID)
)
)
)
if (O.isNone(validationResult)) {
// Error handling for no validation
toast.error(`${t("error.incorrect_email")}`)
return
}
sendingInvites.value = true
sendInvitesResult.value = await pipe(
A.sequence(T.task)(validationResult.value),
T.chain(
flow(
A.mapWithIndex((i, el) =>
pipe(
el,
E.foldW(
(err) => ({
status: "error" as const,
email: newInvites.value[i].key as Email,
error: err,
}),
() => ({
status: "success" as const,
email: newInvites.value[i].key as Email,
})
)
)
),
T.of
)
)
)()
sendingInvites.value = false
}
const getErrorMessage = (error: SendInvitesErrorType) => {
if (error.type === "network_error") {
return t("error.network_error")
} else {
switch (error.error) {
case "team/invalid_id":
return t("team.invalid_id")
case "team/member_not_found":
return t("team.member_not_found")
case "team_invite/already_member":
return t("team.already_member")
case "team_invite/member_has_invite":
return t("team.member_has_invite")
}
}
}
const hideModal = () => {
sendingInvites.value = false
sendInvitesResult.value = []
newInvites.value = [
{
key: "",
value: TeamMemberRole.Viewer,
},
]
emit("hide-modal")
}
</script>

View File

@@ -0,0 +1,30 @@
<template>
<SmartModal
v-if="show"
dialog
:title="t('team.select_a_team')"
@close="hideModal"
>
<template #body>
<Teams :modal="true" />
</template>
</SmartModal>
</template>
<script setup lang="ts">
import { useI18n } from "@composables/i18n"
const t = useI18n()
defineProps<{
show: boolean
}>()
const emit = defineEmits<{
(e: "hide-modal"): void
}>()
const hideModal = () => {
emit("hide-modal")
}
</script>

View File

@@ -0,0 +1,260 @@
<template>
<div
class="flex flex-col flex-1 border rounded border-divider"
@contextmenu.prevent="!compact ? options.tippy.show() : null"
>
<div
class="flex items-start flex-1"
:class="
compact
? team.myRole === 'OWNER'
? 'cursor-pointer hover:bg-primaryDark transition hover:border-dividerDark focus-visible:border-dividerDark'
: 'cursor-not-allowed bg-primaryLight'
: ''
"
@click="
compact
? team.myRole === 'OWNER'
? $emit('invite-team')
: noPermission()
: ''
"
>
<div class="p-4">
<label
class="font-semibold text-secondaryDark"
:class="{ 'cursor-pointer': compact && team.myRole === 'OWNER' }"
>
{{ team.name || t("state.nothing_found") }}
</label>
<div class="flex mt-2 overflow-hidden -space-x-1">
<div
v-for="(member, index) in team.teamMembers"
:key="`member-${index}`"
v-tippy="{ theme: 'tooltip' }"
:title="
member.user.displayName ||
member.user.email ||
t('default_hopp_displayName')
"
class="inline-flex"
>
<ProfilePicture
v-if="member.user.photoURL"
:url="member.user.photoURL"
:alt="member.user.displayName"
class="ring-primary ring-2"
/>
<ProfilePicture
v-else
:initial="member.user.displayName || member.user.email"
class="ring-primary ring-2"
/>
</div>
</div>
</div>
</div>
<div v-if="!compact" class="flex items-end justify-between flex-shrink-0">
<span>
<ButtonSecondary
v-if="team.myRole === 'OWNER'"
:icon="IconEdit"
class="rounded-none"
:label="t('action.edit')"
@click="
() => {
$emit('edit-team')
}
"
/>
<ButtonSecondary
v-if="team.myRole === 'OWNER'"
:icon="IconUserPlus"
class="rounded-none"
:label="t('team.invite')"
@click="
() => {
emit('invite-team')
}
"
/>
</span>
<span>
<tippy
ref="options"
interactive
trigger="click"
theme="popover"
:on-shown="() => tippyActions.focus()"
>
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
:title="t('action.more')"
:icon="IconMoreVertical"
/>
<template #content="{ hide }">
<div
ref="tippyActions"
class="flex flex-col focus:outline-none"
tabindex="0"
@keyup.e="team.myRole === 'OWNER' ? edit.$el.click() : null"
@keyup.x="
!(team.myRole === 'OWNER' && team.ownersCount == 1)
? exit.$el.click()
: null
"
@keyup.delete="
team.myRole === 'OWNER' ? deleteAction.$el.click() : null
"
@keyup.escape="hide()"
>
<SmartItem
v-if="team.myRole === 'OWNER'"
ref="edit"
:icon="IconEdit"
:label="t('action.edit')"
:shortcut="['E']"
@click="
() => {
$emit('edit-team')
hide()
}
"
/>
<SmartItem
v-if="!(team.myRole === 'OWNER' && team.ownersCount == 1)"
ref="exit"
:icon="IconUserX"
:label="t('team.exit')"
:shortcut="['X']"
@click="
() => {
confirmExit = true
hide()
}
"
/>
<SmartItem
v-if="team.myRole === 'OWNER'"
ref="deleteAction"
:icon="IconTrash2"
:label="t('action.delete')"
:shortcut="['⌫']"
@click="
() => {
confirmRemove = true
hide()
}
"
/>
</div>
</template>
</tippy>
</span>
</div>
<SmartConfirmModal
:show="confirmRemove"
:title="t('confirm.remove_team')"
@hide-modal="confirmRemove = false"
@resolve="deleteTeam()"
/>
<SmartConfirmModal
:show="confirmExit"
:title="t('confirm.exit_team')"
@hide-modal="confirmExit = false"
@resolve="exitTeam()"
/>
</div>
</template>
<script setup lang="ts">
import { ref } from "vue"
import { pipe } from "fp-ts/function"
import * as TE from "fp-ts/TaskEither"
import { TeamMemberRole } from "~/helpers/backend/graphql"
import {
deleteTeam as backendDeleteTeam,
leaveTeam,
} from "~/helpers/backend/mutations/Team"
import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast"
import IconEdit from "~icons/lucide/edit"
import IconMoreVertical from "~icons/lucide/more-vertical"
import IconUserX from "~icons/lucide/user-x"
import IconUserPlus from "~icons/lucide/user-plus"
import IconTrash2 from "~icons/lucide/trash-2"
const t = useI18n()
const props = defineProps<{
team: {
name: string
myRole: TeamMemberRole
ownersCount: number
teamMembers: Array<{
user: {
displayName: string
photoURL: string | null
email: string | null
}
}>
}
teamID: string
compact: boolean
}>()
const emit = defineEmits<{
(e: "edit-team"): void
(e: "invite-team"): void
}>()
const toast = useToast()
const confirmRemove = ref(false)
const confirmExit = ref(false)
const deleteTeam = () => {
pipe(
backendDeleteTeam(props.teamID),
TE.match(
(err) => {
// TODO: Better errors ? We know the possible errors now
toast.error(`${t("error.something_went_wrong")}`)
console.error(err)
},
() => {
toast.success(`${t("team.deleted")}`)
}
)
)() // Tasks (and TEs) are lazy, so call the function returned
}
const exitTeam = () => {
pipe(
leaveTeam(props.teamID),
TE.match(
(err) => {
// TODO: Better errors ?
toast.error(`${t("error.something_went_wrong")}`)
console.error(err)
},
() => {
toast.success(`${t("team.left")}`)
}
)
)() // Tasks (and TEs) are lazy, so call the function returned
}
const noPermission = () => {
toast.error(`${t("profile.no_permission")}`)
}
// Template refs
const tippyActions = ref<any | null>(null)
const options = ref<any | null>(null)
const edit = ref<any | null>(null)
const deleteAction = ref<any | null>(null)
const exit = ref<any | null>(null)
</script>

View File

@@ -0,0 +1,144 @@
<template>
<div>
<div class="space-y-4">
<ButtonSecondary
:label="`${t('team.create_new')}`"
outline
@click="displayModalAdd(true)"
/>
<div v-if="loading" class="flex flex-col items-center justify-center">
<SmartSpinner class="mb-4" />
<span class="text-secondaryLight">{{ t("state.loading") }}</span>
</div>
<div
v-if="!loading && myTeams.length === 0"
class="flex flex-col items-center justify-center p-4 text-secondaryLight"
>
<img
:src="`/images/states/${colorMode.value}/add_group.svg`"
loading="lazy"
class="inline-flex flex-col object-contain object-center w-16 h-16 mb-8"
:alt="`${t('empty.teams')}`"
/>
<span class="mb-4 text-center">
{{ t("empty.teams") }}
</span>
<ButtonSecondary
:label="`${t('team.create_new')}`"
filled
@click="displayModalAdd(true)"
/>
</div>
<div
v-else-if="!loading"
class="grid gap-4"
:class="
modal ? 'grid-cols-1' : 'sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4'
"
>
<TeamsTeam
v-for="(team, index) in myTeams"
:key="`team-${String(index)}`"
:team-i-d="team.id"
:team="team"
:compact="modal"
@edit-team="editTeam(team, team.id)"
@invite-team="inviteTeam(team, team.id)"
/>
</div>
<div v-if="!loading && adapterError" class="flex flex-col items-center">
<component :is="IconHelpCircle" class="mb-4 svg-icons" />
{{ t("error.something_went_wrong") }}
</div>
</div>
<TeamsAdd :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
<!-- ¯\_()_/¯ -->
<TeamsEdit
v-if="!loading && myTeams.length > 0"
:team="myTeams[0]"
:show="showModalEdit"
:editing-team="editingTeam"
:editing-team-i-d="editingTeamID"
@hide-modal="displayModalEdit(false)"
@invite-team="inviteTeam(editingTeam, editingTeamID)"
@refetch-teams="refetchTeams"
/>
<TeamsInvite
v-if="!loading && myTeams.length > 0"
:team="myTeams[0]"
:show="showModalInvite"
:editing-team="editingTeam"
:editing-team-i-d="editingTeamID"
@hide-modal="displayModalInvite(false)"
/>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from "vue"
import { onLoggedIn } from "@composables/auth"
import TeamListAdapter from "~/helpers/teams/TeamListAdapter"
import { useI18n } from "@composables/i18n"
import { useReadonlyStream } from "@composables/stream"
import { useColorMode } from "@composables/theming"
import IconHelpCircle from "~icons/lucide/help-circle"
const t = useI18n()
const colorMode = useColorMode()
defineProps<{
modal: boolean
}>()
const showModalAdd = ref(false)
const showModalEdit = ref(false)
const showModalInvite = ref(false)
const editingTeam = ref<any>({}) // TODO: Check this out
const editingTeamID = ref<any>("")
const adapter = new TeamListAdapter(true)
const adapterLoading = useReadonlyStream(adapter.loading$, false)
const adapterError = useReadonlyStream(adapter.error$, null)
const myTeams = useReadonlyStream(adapter.teamList$, [])
const loading = computed(
() => adapterLoading.value && myTeams.value.length === 0
)
onLoggedIn(() => {
adapter.initialize()
})
const displayModalAdd = (shouldDisplay: boolean) => {
showModalAdd.value = shouldDisplay
adapter.fetchList()
}
const displayModalEdit = (shouldDisplay: boolean) => {
showModalEdit.value = shouldDisplay
adapter.fetchList()
}
const displayModalInvite = (shouldDisplay: boolean) => {
showModalInvite.value = shouldDisplay
adapter.fetchList()
}
const editTeam = (team: any, teamID: any) => {
editingTeam.value = team
editingTeamID.value = teamID
displayModalEdit(true)
}
const inviteTeam = (team: any, teamID: any) => {
editingTeam.value = team
editingTeamID.value = teamID
displayModalInvite(true)
}
const refetchTeams = () => {
adapter.fetchList()
}
</script>