Files
speckle-server/packages/frontend-2/components/header/nav/notifications/ProjectInvite.vue
T

70 lines
1.8 KiB
Vue

<template>
<HeaderNavNotificationsInvite
:invite="invite"
:disabled="loading"
@processed="processInvite"
>
<template #message>
<span class="font-medium">{{ invite.invitedBy.name }}</span>
has invited you to join the project
<span class="font-medium">{{ invite.projectName }}</span>
</template>
</HeaderNavNotificationsInvite>
</template>
<script setup lang="ts">
import { graphql } from '~~/lib/common/generated/gql'
import type { HeaderNavNotificationsProjectInvite_PendingStreamCollaboratorFragment } from '~~/lib/common/generated/gql/graphql'
import type { Optional } from '@speckle/shared'
import { useProjectInviteManager } from '~/lib/projects/composables/invites'
import { useNavigation } from '~/lib/navigation/composables/navigation'
import { projectRoute } from '~/lib/common/helpers/route'
graphql(`
fragment HeaderNavNotificationsProjectInvite_PendingStreamCollaborator on PendingStreamCollaborator {
id
invitedBy {
...LimitedUserAvatar
}
projectId
projectName
token
workspaceSlug
user {
id
}
}
`)
const props = defineProps<{
invite: HeaderNavNotificationsProjectInvite_PendingStreamCollaboratorFragment
}>()
const { mutateActiveWorkspaceSlug, mutateIsProjectsActive } = useNavigation()
const { useInvite } = useProjectInviteManager()
const loading = ref(false)
const processInvite = async (accept: boolean, token: Optional<string>) => {
if (!token) return
loading.value = true
await useInvite({
projectId: props.invite.projectId,
accept,
token,
inviteId: props.invite.id
})
if (props.invite.workspaceSlug) {
mutateActiveWorkspaceSlug(props.invite.workspaceSlug)
} else {
mutateIsProjectsActive(true)
}
navigateTo(projectRoute(props.invite.projectId))
loading.value = false
}
</script>