feat: introducing team (HBE-86) (#36)
This commit is contained in:
@@ -41,17 +41,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-center sm:justify-end mt-8">
|
||||
<router-link to="/users">
|
||||
<button
|
||||
@click="submitTeam"
|
||||
class="px-4 py-2 text-gray-200 bg-emerald-900 rounded-md hover:bg-emerald-700 focus:outline-none focus:bg-emerald-800"
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
</router-link>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -74,8 +63,4 @@ const addNewMember = () => {
|
||||
const deleteMemberRow = (index: number) => {
|
||||
members.splice(index, 1);
|
||||
};
|
||||
|
||||
const submitTeam = () => {
|
||||
console.log('members', members);
|
||||
};
|
||||
</script>
|
||||
|
||||
483
packages/hoppscotch-sh-admin/src/components/teams/Details.vue
Normal file
483
packages/hoppscotch-sh-admin/src/components/teams/Details.vue
Normal file
@@ -0,0 +1,483 @@
|
||||
<template>
|
||||
<div class="sm:px-6 p-4" v-if="team">
|
||||
<h3 class="text-3xl font-medium text-zinc-800 dark:text-gray-200">
|
||||
Team Details
|
||||
</h3>
|
||||
|
||||
<div class="mt-5">
|
||||
<div class="grid gap-4">
|
||||
<div class="w-full">
|
||||
<div
|
||||
class="p-4 bg-zinc-200 dark:bg-zinc-800 rounded-md shadow-sm flex flex-col gap-1"
|
||||
>
|
||||
<div class="flex mb-6">
|
||||
<icon-lucide-user class="text-emerald-400 text-3xl" />
|
||||
|
||||
<h4
|
||||
class="text-3xl ml-2 font-semibold text-gray-700 dark:text-gray-200"
|
||||
>
|
||||
Team Info
|
||||
</h4>
|
||||
</div>
|
||||
<div class="flex text-xl">
|
||||
<h4 class="font-semibold text-gray-700 dark:text-gray-400">
|
||||
Team ID:
|
||||
</h4>
|
||||
<div class="text-gray-600 dark:text-gray-200 ml-2">
|
||||
{{ team.id }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex text-xl items-center">
|
||||
<h4 class="font-semibold text-gray-700 dark:text-gray-400">
|
||||
Team Name:
|
||||
</h4>
|
||||
<div class="text-gray-600 dark:text-gray-200 ml-2">
|
||||
<div v-if="showRenameInput" class="flex gap-4 items-center">
|
||||
<input
|
||||
class="w-full py-1 px-3 dark:bg-zinc-800 border-gray-200 dark:border-gray-600 rounded-md focus:border-emerald-600 focus:ring focus:ring-opacity-40 focus:ring-emerald-500 border"
|
||||
type="text"
|
||||
v-model="teamName"
|
||||
placeholder="Team Name"
|
||||
autofocus
|
||||
v-focus
|
||||
/>
|
||||
|
||||
<div>
|
||||
<HoppButtonPrimary
|
||||
class="py-1"
|
||||
filled
|
||||
label="Rename"
|
||||
@click="renameTeamName()"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="flex gap-2">
|
||||
<span>
|
||||
{{ teamName }}
|
||||
</span>
|
||||
<icon-lucide-edit
|
||||
class="cursor-pointer"
|
||||
@click="showRenameInput = true"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex text-xl">
|
||||
<h4 class="font-semibold text-gray-700 dark:text-gray-400">
|
||||
Number of members:
|
||||
</h4>
|
||||
<div class="text-gray-600 dark:text-gray-200 ml-2">
|
||||
{{ team.teamMembers.length }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-start mt-6">
|
||||
<HoppButtonSecondary
|
||||
class="mr-4"
|
||||
filled
|
||||
label="Delete"
|
||||
@click="team && deleteTeam(team.id)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="my-6">
|
||||
<div class="flex flex-col mb-6">
|
||||
<div class="flex items-center justify-between flex-1 pt-4 mb-4">
|
||||
<label for="memberList"> Members </label>
|
||||
<div class="flex">
|
||||
<HoppButtonSecondary
|
||||
:icon="IconUserPlus"
|
||||
label="Add Members"
|
||||
filled
|
||||
@click="showInvite = !showInvite"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="border rounded border-divider">
|
||||
<div
|
||||
v-if="team?.teamMembers?.length === 0"
|
||||
class="flex flex-col items-center justify-center p-4 text-secondaryLight"
|
||||
>
|
||||
<img
|
||||
:src="`/images/states/dark/add_group.svg`"
|
||||
loading="lazy"
|
||||
class="inline-flex flex-col object-contain object-center w-16 h-16 my-4"
|
||||
/>
|
||||
<span class="pb-4 text-center">
|
||||
No members in this team. Add members to this team to collaborate
|
||||
</span>
|
||||
<HoppButtonSecondary
|
||||
:icon="IconUserPlus"
|
||||
label="Add Members"
|
||||
@click="
|
||||
() => {
|
||||
showInvite = !showInvite;
|
||||
}
|
||||
"
|
||||
/>
|
||||
</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="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="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()"
|
||||
>
|
||||
<HoppSmartItem
|
||||
label="OWNER"
|
||||
:icon="
|
||||
member.role === 'OWNER' ? IconCircleDot : IconCircle
|
||||
"
|
||||
:active="member.role === 'OWNER'"
|
||||
@click="
|
||||
() => {
|
||||
updateMemberRole(
|
||||
member.userID,
|
||||
TeamMemberRole.Owner
|
||||
);
|
||||
hide();
|
||||
}
|
||||
"
|
||||
/>
|
||||
<HoppSmartItem
|
||||
label="EDITOR"
|
||||
:icon="
|
||||
member.role === 'EDITOR' ? IconCircleDot : IconCircle
|
||||
"
|
||||
:active="member.role === 'EDITOR'"
|
||||
@click="
|
||||
() => {
|
||||
updateMemberRole(
|
||||
member.userID,
|
||||
TeamMemberRole.Editor
|
||||
);
|
||||
hide();
|
||||
}
|
||||
"
|
||||
/>
|
||||
<HoppSmartItem
|
||||
label="VIEWER"
|
||||
:icon="
|
||||
member.role === 'VIEWER' ? IconCircleDot : IconCircle
|
||||
"
|
||||
:active="member.role === 'VIEWER'"
|
||||
@click="
|
||||
() => {
|
||||
updateMemberRole(
|
||||
member.userID,
|
||||
TeamMemberRole.Viewer
|
||||
);
|
||||
hide();
|
||||
}
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</tippy>
|
||||
</span>
|
||||
<div class="flex">
|
||||
<HoppButtonSecondary
|
||||
id="member"
|
||||
v-tippy="{ theme: 'tooltip' }"
|
||||
title="Remove"
|
||||
:icon="IconUserMinus"
|
||||
color="red"
|
||||
:loading="isLoadingIndex === index"
|
||||
@click="removeExistingTeamMember(member.userID, index)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!fetching && !team" class="flex flex-col items-center">
|
||||
<component :is="IconHelpCircle" class="mb-4 svg-icons" />
|
||||
Something went wrong. Please try again later.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<HoppButtonPrimary
|
||||
label="Save"
|
||||
:loading="isLoading"
|
||||
outline
|
||||
@click="saveTeam"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<TeamsPendingInvites :editingTeamID="team.id" />
|
||||
<HoppSmartConfirmModal
|
||||
:show="confirmDeletion"
|
||||
:title="`Confirm Deletion of ${team.name} team?`"
|
||||
@hide-modal="confirmDeletion = false"
|
||||
@resolve="deleteTeamMutation(deleteTeamUID)"
|
||||
/>
|
||||
<TeamsInvite
|
||||
:show="showInvite"
|
||||
:editingTeamID="team.id"
|
||||
@hide-modal="
|
||||
() => {
|
||||
showInvite = false;
|
||||
}
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
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';
|
||||
import { useClientHandle, useMutation } from '@urql/vue';
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useToast } from '../../composables/toast';
|
||||
import {
|
||||
RemoveTeamDocument,
|
||||
RenameTeamDocument,
|
||||
TeamInfoDocument,
|
||||
TeamMemberRole,
|
||||
UpdateTeamMemberRoleDocument,
|
||||
RemoveTeamMemberDocument,
|
||||
TeamInfoQuery,
|
||||
} from '../../helpers/backend/graphql';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const toast = useToast();
|
||||
|
||||
const team = ref<TeamInfoQuery['team'] | null>(null);
|
||||
const showRenameInput = ref(false);
|
||||
const showInvite = ref(false);
|
||||
const teamName = ref('');
|
||||
|
||||
const { client } = useClientHandle();
|
||||
const fetching = ref(true);
|
||||
|
||||
const teamDeletion = useMutation(RemoveTeamDocument);
|
||||
const teamRename = useMutation(RenameTeamDocument);
|
||||
const confirmDeletion = ref(false);
|
||||
const deleteTeamUID = ref<string | null>(null);
|
||||
|
||||
onMounted(async () => {
|
||||
await getTeamInfo();
|
||||
});
|
||||
|
||||
const getTeamInfo = async () => {
|
||||
fetching.value = true;
|
||||
const result = await client
|
||||
.query(TeamInfoDocument, { uid: route.params.id.toString() })
|
||||
.toPromise();
|
||||
|
||||
if (result.error) {
|
||||
return toast.error('Unable to Load Team Info..');
|
||||
}
|
||||
|
||||
if (result.data?.team) {
|
||||
team.value = result.data.team;
|
||||
teamName.value = team.value.name;
|
||||
}
|
||||
|
||||
fetching.value = false;
|
||||
};
|
||||
|
||||
const renameTeamName = async () => {
|
||||
if (!team.value) return;
|
||||
|
||||
if (team.value.name === teamName.value) {
|
||||
showRenameInput.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const variables = { uid: team.value.id, name: teamName.value };
|
||||
await teamRename.executeMutation(variables).then((result) => {
|
||||
if (result.error) {
|
||||
toast.error('Renaming team Failed');
|
||||
} else {
|
||||
showRenameInput.value = false;
|
||||
toast.success('Team Renamed Successfully');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const deleteTeam = (id: string) => {
|
||||
confirmDeletion.value = true;
|
||||
deleteTeamUID.value = id;
|
||||
};
|
||||
|
||||
const deleteTeamMutation = async (id: string | null) => {
|
||||
if (!id) {
|
||||
confirmDeletion.value = false;
|
||||
toast.error('User Deletion Failed');
|
||||
return;
|
||||
}
|
||||
const variables = { uid: id };
|
||||
await teamDeletion.executeMutation(variables).then((result) => {
|
||||
if (result.error) {
|
||||
toast.error('User Deletion Failed');
|
||||
} else {
|
||||
toast.success('User Deleted Successfully');
|
||||
}
|
||||
});
|
||||
confirmDeletion.value = false;
|
||||
deleteTeamUID.value = null;
|
||||
router.push('/teams');
|
||||
};
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'refetch-teams'): void;
|
||||
(e: 'invite-team'): void;
|
||||
}>();
|
||||
|
||||
// Template refs
|
||||
const tippyActions = ref<any | null>(null);
|
||||
|
||||
const roleUpdates = ref<
|
||||
{
|
||||
userID: string;
|
||||
role: TeamMemberRole;
|
||||
}[]
|
||||
>([]);
|
||||
|
||||
watch(
|
||||
() => team.value,
|
||||
(teamDetails) => {
|
||||
const members = teamDetails?.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 (!team.value) return [];
|
||||
const members = (team.value.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;
|
||||
});
|
||||
|
||||
const isLoadingIndex = ref<null | number>(null);
|
||||
|
||||
const removeExistingTeamMember = async (userID: string, index: number) => {
|
||||
if (!team.value) return;
|
||||
isLoadingIndex.value = index;
|
||||
const removeTeamMemberResult = await removeTeamMember(
|
||||
userID,
|
||||
team.value.id
|
||||
)();
|
||||
if (removeTeamMemberResult.error) {
|
||||
toast.error(`Something went wrong`);
|
||||
} else {
|
||||
toast.success(`Member removed successfully`);
|
||||
emit('refetch-teams');
|
||||
getTeamInfo();
|
||||
}
|
||||
isLoadingIndex.value = null;
|
||||
};
|
||||
|
||||
const isLoading = ref(false);
|
||||
|
||||
const saveTeam = async () => {
|
||||
isLoading.value = true;
|
||||
roleUpdates.value.forEach(async (update) => {
|
||||
if (!team.value) return;
|
||||
const updateMemberRoleResult = await updateTeamMemberRole(
|
||||
update.userID,
|
||||
team.value.id,
|
||||
update.role
|
||||
);
|
||||
if (updateMemberRoleResult.error) {
|
||||
toast.error(`Something went wrong`);
|
||||
} else {
|
||||
toast.success(`Roles updated successfully`);
|
||||
}
|
||||
isLoading.value = false;
|
||||
});
|
||||
};
|
||||
|
||||
const updateTeamMemberRoleMutation = useMutation(UpdateTeamMemberRoleDocument);
|
||||
const updateTeamMemberRole = (
|
||||
userUid: string,
|
||||
teamID: string,
|
||||
newRole: TeamMemberRole
|
||||
) => {
|
||||
return updateTeamMemberRoleMutation.executeMutation({
|
||||
userUid,
|
||||
teamID,
|
||||
newRole,
|
||||
});
|
||||
};
|
||||
|
||||
const removeTeamMemberMutation = useMutation(RemoveTeamMemberDocument);
|
||||
const removeTeamMember = (userUid: string, teamID: string) => {
|
||||
return () =>
|
||||
removeTeamMemberMutation.executeMutation({
|
||||
userUid,
|
||||
teamID,
|
||||
});
|
||||
};
|
||||
</script>
|
||||
402
packages/hoppscotch-sh-admin/src/components/teams/Invite.vue
Normal file
402
packages/hoppscotch-sh-admin/src/components/teams/Invite.vue
Normal file
@@ -0,0 +1,402 @@
|
||||
<template>
|
||||
<HoppSmartModal v-if="show" dialog title="Add Member" @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">
|
||||
We have sent you an invite link
|
||||
</h3>
|
||||
<p class="text-center">
|
||||
You can use this link to invite your team members to join your team.
|
||||
</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"
|
||||
>
|
||||
<HoppSmartSpinner />
|
||||
</div>
|
||||
<div v-else class="flex flex-col">
|
||||
<div class="flex items-center justify-between flex-1 pt-4">
|
||||
<label for="memberList" class="p-4"> Add members </label>
|
||||
<div class="flex">
|
||||
<HoppButtonSecondary
|
||||
:icon="IconPlus"
|
||||
label="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="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="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()"
|
||||
>
|
||||
<HoppSmartItem
|
||||
label="OWNER"
|
||||
:icon="
|
||||
invitee.value === 'OWNER' ? IconCircleDot : IconCircle
|
||||
"
|
||||
:active="invitee.value === 'OWNER'"
|
||||
@click="
|
||||
() => {
|
||||
updateNewInviteeRole(index, TeamMemberRole.Owner);
|
||||
hide();
|
||||
}
|
||||
"
|
||||
/>
|
||||
<HoppSmartItem
|
||||
label="EDITOR"
|
||||
:icon="
|
||||
invitee.value === 'EDITOR' ? IconCircleDot : IconCircle
|
||||
"
|
||||
:active="invitee.value === 'EDITOR'"
|
||||
@click="
|
||||
() => {
|
||||
updateNewInviteeRole(index, TeamMemberRole.Editor);
|
||||
hide();
|
||||
}
|
||||
"
|
||||
/>
|
||||
<HoppSmartItem
|
||||
label="VIEWER"
|
||||
:icon="
|
||||
invitee.value === 'VIEWER' ? IconCircleDot : IconCircle
|
||||
"
|
||||
:active="invitee.value === 'VIEWER'"
|
||||
@click="
|
||||
() => {
|
||||
updateNewInviteeRole(index, TeamMemberRole.Viewer);
|
||||
hide();
|
||||
}
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</tippy>
|
||||
</span>
|
||||
<div class="flex">
|
||||
<HoppButtonSecondary
|
||||
id="member"
|
||||
v-tippy="{ theme: 'tooltip' }"
|
||||
title="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/dark/add_group.svg`"
|
||||
loading="lazy"
|
||||
class="inline-flex flex-col object-contain object-center w-16 h-16 mb-4"
|
||||
/>
|
||||
<span class="pb-4 text-center"> No invites </span>
|
||||
<HoppButtonSecondary
|
||||
label="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"
|
||||
/>
|
||||
Roles
|
||||
</span>
|
||||
<p>
|
||||
<span class="text-secondaryLight">
|
||||
Roles are used to control access to the shared collections.
|
||||
</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"
|
||||
>
|
||||
Owner
|
||||
</span>
|
||||
<span class="flex flex-1">
|
||||
Owners can add, edit, and delete requests, collections and team
|
||||
members.
|
||||
</span>
|
||||
</li>
|
||||
<li class="flex">
|
||||
<span
|
||||
class="w-1/4 font-semibold uppercase truncate text-secondaryDark max-w-16"
|
||||
>
|
||||
Editor
|
||||
</span>
|
||||
<span class="flex flex-1">
|
||||
Editors can add, edit, and delete requests.
|
||||
</span>
|
||||
</li>
|
||||
<li class="flex">
|
||||
<span
|
||||
class="w-1/4 font-semibold uppercase truncate text-secondaryDark max-w-16"
|
||||
>
|
||||
Viewer
|
||||
</span>
|
||||
<span class="flex flex-1">
|
||||
Viewers can only view and use requests.
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<p
|
||||
v-if="sendInvitesResult.length"
|
||||
class="flex justify-between flex-1 text-secondaryLight"
|
||||
>
|
||||
<HoppButtonSecondary
|
||||
class="link !p-0"
|
||||
label="Invite more"
|
||||
:icon="IconArrowLeft"
|
||||
@click="
|
||||
() => {
|
||||
sendInvitesResult = [];
|
||||
newInvites = [
|
||||
{
|
||||
key: '',
|
||||
value: TeamMemberRole.Viewer,
|
||||
},
|
||||
];
|
||||
}
|
||||
"
|
||||
/>
|
||||
<HoppButtonSecondary
|
||||
class="link !p-0"
|
||||
label="Dismiss"
|
||||
@click="hideModal"
|
||||
/>
|
||||
</p>
|
||||
<span v-else class="flex space-x-2">
|
||||
<HoppButtonPrimary label="Invite" outline @click="sendInvites" />
|
||||
<HoppButtonSecondary label="Cancel" outline filled @click="hideModal" />
|
||||
</span>
|
||||
</template>
|
||||
</HoppSmartModal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import * as A from 'fp-ts/Array';
|
||||
import * as O from 'fp-ts/Option';
|
||||
import { pipe } from 'fp-ts/function';
|
||||
import {
|
||||
TeamMemberRole,
|
||||
CreateTeamInvitationDocument,
|
||||
} from '../../helpers/backend/graphql';
|
||||
|
||||
import { useToast } from '~/composables/toast';
|
||||
|
||||
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 { useMutation } from '@urql/vue';
|
||||
import { Email, EmailCodec } from '~/helpers/backend/Email';
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
// Template refs
|
||||
const tippyActions = ref<any | null>(null);
|
||||
|
||||
const props = defineProps({
|
||||
show: Boolean,
|
||||
editingTeamID: { type: String, default: null },
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'hide-modal'): void;
|
||||
}>();
|
||||
|
||||
const t = (key: string) => key;
|
||||
|
||||
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: any;
|
||||
}
|
||||
| {
|
||||
email: Email;
|
||||
status: 'success';
|
||||
};
|
||||
|
||||
const sendInvitesResult = ref<Array<SendInvitesErrorType>>([]);
|
||||
|
||||
const sendingInvites = ref<boolean>(false);
|
||||
|
||||
const sendInvites = async () => {
|
||||
sendingInvites.value = true;
|
||||
|
||||
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(`Invalid email address`);
|
||||
sendingInvites.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
hideModal();
|
||||
};
|
||||
|
||||
const getErrorMessage = (error: SendInvitesErrorType | any) => {
|
||||
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');
|
||||
};
|
||||
|
||||
const teamInvitationMutation = useMutation(CreateTeamInvitationDocument);
|
||||
const createTeamInvitation = async (
|
||||
inviteeEmail: Email,
|
||||
inviteeRole: TeamMemberRole,
|
||||
teamID: string
|
||||
) => {
|
||||
const res = await teamInvitationMutation.executeMutation({
|
||||
inviteeEmail,
|
||||
inviteeRole,
|
||||
teamID,
|
||||
});
|
||||
|
||||
return res;
|
||||
};
|
||||
</script>
|
||||
329
packages/hoppscotch-sh-admin/src/components/teams/Members.vue
Normal file
329
packages/hoppscotch-sh-admin/src/components/teams/Members.vue
Normal file
@@ -0,0 +1,329 @@
|
||||
<template>
|
||||
<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">
|
||||
<HoppButtonSecondary
|
||||
:icon="IconUserPlus"
|
||||
:label="t('team.invite')"
|
||||
filled
|
||||
@click="
|
||||
() => {
|
||||
emit('invite-team');
|
||||
}
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="teamDetails.loading" class="border rounded border-divider">
|
||||
<div class="flex items-center justify-center p-4">
|
||||
<HoppSmartSpinner />
|
||||
</div>
|
||||
</div>
|
||||
<div class="border rounded border-divider">
|
||||
<div
|
||||
v-if="teamMembers === 0"
|
||||
class="flex flex-col items-center justify-center p-4 text-secondaryLight"
|
||||
>
|
||||
<img
|
||||
:src="`/images/states/dark/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>
|
||||
<HoppButtonSecondary
|
||||
: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()"
|
||||
>
|
||||
<HoppSmartItem
|
||||
label="OWNER"
|
||||
:icon="member.role === 'OWNER' ? IconCircleDot : IconCircle"
|
||||
:active="member.role === 'OWNER'"
|
||||
@click="
|
||||
() => {
|
||||
updateMemberRole(member.userID, TeamMemberRole.Owner);
|
||||
hide();
|
||||
}
|
||||
"
|
||||
/>
|
||||
<HoppSmartItem
|
||||
label="EDITOR"
|
||||
:icon="
|
||||
member.role === 'EDITOR' ? IconCircleDot : IconCircle
|
||||
"
|
||||
:active="member.role === 'EDITOR'"
|
||||
@click="
|
||||
() => {
|
||||
updateMemberRole(member.userID, TeamMemberRole.Editor);
|
||||
hide();
|
||||
}
|
||||
"
|
||||
/>
|
||||
<HoppSmartItem
|
||||
label="VIEWER"
|
||||
:icon="
|
||||
member.role === 'VIEWER' ? IconCircleDot : IconCircle
|
||||
"
|
||||
:active="member.role === 'VIEWER'"
|
||||
@click="
|
||||
() => {
|
||||
updateMemberRole(member.userID, TeamMemberRole.Viewer);
|
||||
hide();
|
||||
}
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</tippy>
|
||||
</span>
|
||||
<div class="flex">
|
||||
<HoppButtonSecondary
|
||||
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>
|
||||
<HoppButtonPrimary
|
||||
:label="t('action.save')"
|
||||
:loading="isLoading"
|
||||
outline
|
||||
@click="saveTeam"
|
||||
/>
|
||||
</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,
|
||||
RemoveTeamMemberDocument,
|
||||
} from '~/helpers/backend/graphql';
|
||||
import {
|
||||
removeTeamMember,
|
||||
updateTeamMemberRole,
|
||||
} from '~/helpers/backend/mutations/Team';
|
||||
|
||||
import { useToast } from '~/composables/toast';
|
||||
|
||||
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 = (key: string) => key;
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'hide-modal'): void;
|
||||
(e: 'refetch-teams'): void;
|
||||
(e: 'invite-team'): void;
|
||||
}>();
|
||||
|
||||
// Template refs
|
||||
const tippyActions = ref<any | null>(null);
|
||||
|
||||
const props = defineProps<{
|
||||
show: boolean;
|
||||
editingTeam: {
|
||||
name: string;
|
||||
};
|
||||
editingTeamID: string;
|
||||
teamMembers: any;
|
||||
}>();
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
const name = toRef(props.editingTeam, 'name');
|
||||
|
||||
watch(
|
||||
() => props.editingTeam.name,
|
||||
(newName: string) => {
|
||||
name.value = newName;
|
||||
}
|
||||
);
|
||||
|
||||
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(() => {
|
||||
const members = (props.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;
|
||||
});
|
||||
|
||||
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;
|
||||
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')}`);
|
||||
|
||||
isLoading.value = false;
|
||||
};
|
||||
|
||||
const hideModal = () => {
|
||||
emit('hide-modal');
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,99 @@
|
||||
<template>
|
||||
<div class="flex items-center justify-between flex-1">
|
||||
<label for="memberList" class="pb-4"> Pending Invites </label>
|
||||
</div>
|
||||
<div class="border rounded divide-y divide-dividerLight border-divider">
|
||||
<div v-if="fetching" class="flex items-center justify-center p-4">
|
||||
<HoppSmartSpinner />
|
||||
</div>
|
||||
<div v-else>
|
||||
<div v-if="data" class="divide-y divide-dividerLight">
|
||||
<div
|
||||
v-for="(invitee, index) in data?.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="Email"
|
||||
:name="'param' + index"
|
||||
:value="invitee.inviteeEmail"
|
||||
readonly
|
||||
/>
|
||||
<input
|
||||
class="flex flex-1 px-4 py-2 bg-transparent text-secondaryLight"
|
||||
placeholder="Permissions"
|
||||
:name="'value' + index"
|
||||
:value="invitee.inviteeRole"
|
||||
readonly
|
||||
/>
|
||||
<div class="flex">
|
||||
<HoppButtonSecondary
|
||||
v-tippy="{ theme: 'tooltip' }"
|
||||
title="Remove"
|
||||
:icon="IconTrash"
|
||||
color="red"
|
||||
:loading="isLoadingIndex === index"
|
||||
@click="removeInvitee(invitee.id, index)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="data && data?.team?.teamInvitations.length === 0"
|
||||
class="flex flex-col items-center justify-center p-4 text-secondaryLight"
|
||||
>
|
||||
<span class="text-center"> No pending invites </span>
|
||||
</div>
|
||||
<div v-if="!fetching && error" class="flex flex-col items-center p-4">
|
||||
<component :is="IconHelpCircle" class="mb-4 svg-icons" />
|
||||
Something went wrong. Please try again later.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import IconTrash from '~icons/lucide/trash';
|
||||
import IconHelpCircle from '~icons/lucide/help-circle';
|
||||
import { useMutation, useQuery } from '@urql/vue';
|
||||
import { ref } from 'vue';
|
||||
import {
|
||||
GetPendingInvitesDocument,
|
||||
RevokeTeamInvitationDocument,
|
||||
} from '~/helpers/backend/graphql';
|
||||
import { useToast } from '~/composables/toast';
|
||||
|
||||
const props = defineProps({
|
||||
editingTeamID: { type: String, default: null },
|
||||
});
|
||||
|
||||
const toast = useToast();
|
||||
const isLoadingIndex = ref<null | number>(null);
|
||||
|
||||
const { fetching, data, error } = useQuery({
|
||||
query: GetPendingInvitesDocument,
|
||||
variables: {
|
||||
teamID: props.editingTeamID,
|
||||
},
|
||||
});
|
||||
|
||||
console.log(data);
|
||||
|
||||
const removeInvitee = async (id: string, index: number) => {
|
||||
isLoadingIndex.value = index;
|
||||
const result = await revokeTeamInvitation(id);
|
||||
if (result.error) {
|
||||
toast.error(`Member could not be removed`);
|
||||
} else {
|
||||
toast.success(`Member removed successfully`);
|
||||
}
|
||||
isLoadingIndex.value = null;
|
||||
};
|
||||
|
||||
const revokeInvitationMutation = useMutation(RevokeTeamInvitationDocument);
|
||||
function revokeTeamInvitation(inviteID: string) {
|
||||
return revokeInvitationMutation.executeMutation({ inviteID });
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user