Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/presentation/components/team/MoreActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { ref, computed } from 'vue';
import { Icon, ContextMenu, usePopover, useConfirm, type ContextMenuItem } from '@codexteam/ui/vue';
import { type TeamMember } from '@/domain/entities/Team';
import { useI18n } from 'vue-i18n';
import { NoteId } from '@/domain/entities/Note';
import useNoteSettings from '@/application/services/useNoteSettings';
import { useAppState } from '@/application/services/useAppState';

const { removeMemberByUserId } = useNoteSettings();

const props = defineProps<{
/**
* Team member data
Expand All @@ -32,34 +32,41 @@ const props = defineProps<{
noteId: NoteId;
}>();

const { user } = useAppState();
const { t } = useI18n();
const { showPopover, hide } = usePopover();
const { confirm } = useConfirm();

const triggerButton = ref<HTMLButtonElement>();

const menuItems: ContextMenuItem[] = [
{
title: t('noteSettings.team.contextMenu.remove'),
onActivate: async () => {
hide();
await handleRemove(props.teamMember);
},
},
];
const menuItems = computed<ContextMenuItem[]>(() => {
const items: ContextMenuItem[] = [];

if (props.teamMember.user.email !== user.value?.email) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing by email – since both user.value and teamMember.user are User objects with an id, and handleRemove below already uses member.user.id, might be better to key this check off user.id too?

Matches how the API guard in codex-team/notes.api#304 identifies the user, and avoids any edge case where email casing differs between the session user and the team record.

items.push({
title: t('noteSettings.team.contextMenu.remove'),
onActivate: async () => {
hide();
await handleRemove(props.teamMember);
},
});
}

return items;
});

const emit = defineEmits<{
teamMemberRemoved: [userId: TeamMember['user']['id']];
}>();

const handleButtonClick = (): void => {
if (triggerButton.value) {
if (triggerButton.value && menuItems.value.length > 0) {
showPopover({
targetEl: triggerButton.value,
with: {
component: ContextMenu,
props: {
items: menuItems,
items: menuItems.value,
},
},
align: {
Expand Down
Loading