Skip to content

Commit 879ff7c

Browse files
committed
refactor: removeTeamMember optimization
1 parent 98111c0 commit 879ff7c

File tree

7 files changed

+36
-24
lines changed

7 files changed

+36
-24
lines changed

src/application/services/useNoteSettings.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ interface UseNoteSettingsComposableState {
7171
* Delete team member by user id
7272
* @param id - Note id
7373
* @param userId - User id
74+
* @returns true if user was removed
7475
*/
75-
removeMemberByUserId: (id: NoteId, userId: UserId) => Promise<void>;
76+
removeMemberByUserId: (id: NoteId, userId: UserId) => Promise<boolean>;
7677
}
7778

7879
/**
@@ -199,9 +200,10 @@ export default function (): UseNoteSettingsComposableState {
199200
* Delete team member by user id
200201
* @param id - Note id
201202
* @param userId - User id
203+
* @returns true if user was removed
202204
*/
203-
const removeMemberByUserId = async (id: NoteId, userId: UserId): Promise<void> => {
204-
await noteSettingsService.removeMemberByUserId(id, userId);
205+
const removeMemberByUserId = async (id: NoteId, userId: UserId): Promise<boolean> => {
206+
return await noteSettingsService.removeMemberByUserId(id, userId);
205207
};
206208

207209
return {

src/domain/noteSettings.repository.interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default interface NoteSettingsRepositoryInterface {
4848
* Delete team member by user id
4949
* @param id - Note id
5050
* @param userId - User id
51+
* @returns true if user was removed
5152
*/
52-
removeMemberByUserId(id: NoteId, userId: UserId): Promise<void>;
53+
removeMemberByUserId(id: NoteId, userId: UserId): Promise<boolean>;
5354
}

src/domain/noteSettings.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ export default class NoteSettingsService {
123123
* Delete team member by user id
124124
* @param id - Note id
125125
* @param userId - User id
126+
* @returns true if user was removed
126127
*/
127-
public async removeMemberByUserId(id: NoteId, userId: UserId): Promise<void> {
128+
public async removeMemberByUserId(id: NoteId, userId: UserId): Promise<boolean> {
128129
return await this.noteSettingsRepository.removeMemberByUserId(id, userId);
129130
}
130131
}

src/infrastructure/noteSettings.repository.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ export default class NoteSettingsRepository implements NoteSettingsRepositoryInt
7474
* Delete team member by user id
7575
* @param id - Note id
7676
* @param userId - User id
77+
* @returns true if user was removed
7778
*/
78-
public async removeMemberByUserId(id: NoteId, userId: UserId): Promise<void> {
79+
public async removeMemberByUserId(id: NoteId, userId: UserId): Promise<boolean> {
7980
const data = { userId };
81+
const response = await this.transport.delete<number>(`/note-settings/${id}/team`, data);
8082

81-
await this.transport.delete<boolean>(`/note-settings/${id}/team`, data);
83+
return response === userId;
8284
}
8385
}

src/presentation/components/team/MoreActions.vue

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
22
<button
33
ref="triggerButton"
4+
:title="t('noteSettings.team.contextMenu.title')"
45
class="more-actions-button"
56
@click="handleButtonClick"
6-
:title="t('noteSettings.team.contextMenu.title')"
77
>
88
<Icon
99
name="EtcVertical"
@@ -43,17 +43,13 @@ const menuItems: ContextMenuItem[] = [
4343
title: t('noteSettings.team.contextMenu.remove'),
4444
onActivate: async () => {
4545
hide();
46-
try {
47-
await handleRemove(props.teamMember);
48-
} catch (error) {
49-
console.error('Failed to remove team member', error);
50-
}
46+
await handleRemove(props.teamMember);
5147
},
5248
},
5349
];
5450
5551
const emit = defineEmits<{
56-
teamMemberRemoved: [];
52+
teamMemberRemoved: [userId: TeamMember['user']['id']];
5753
}>();
5854
5955
const handleButtonClick = (): void => {
@@ -87,8 +83,11 @@ const handleRemove = async (member: TeamMember): Promise<void> => {
8783
);
8884
8985
if (shouldRemove) {
90-
await removeMemberByUserId(props.noteId, member.user.id);
91-
emit('teamMemberRemoved');
86+
const isDeleted = await removeMemberByUserId(props.noteId, member.user.id);
87+
88+
if (isDeleted) {
89+
emit('teamMemberRemoved', member.user.id);
90+
}
9291
}
9392
};
9493
</script>

src/presentation/components/team/Team.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
<script setup lang="ts">
4141
import { computed } from 'vue';
42-
import { Team, MemberRole } from '@/domain/entities/Team';
42+
import { Team, MemberRole, TeamMember } from '@/domain/entities/Team';
4343
import { Note, NoteId } from '@/domain/entities/Note';
4444
import { Section, Row, Avatar } from '@codexteam/ui/vue';
4545
import RoleSelect from './RoleSelect.vue';
@@ -59,7 +59,7 @@ const props = defineProps<{
5959
}>();
6060
6161
const emit = defineEmits<{
62-
teamMemberRemoved: [];
62+
teamMemberRemoved: [id: TeamMember['user']['id']];
6363
}>();
6464
6565
const { t } = useI18n();
@@ -91,8 +91,8 @@ const sortedTeam = computed(() => {
9191
});
9292
9393
// Listen for teamMemberRemoved event from child component and bubble them up
94-
const handleMemberRemoved = () => {
95-
emit('teamMemberRemoved');
94+
const handleMemberRemoved = (userId: TeamMember['user']['id']): void => {
95+
emit('teamMemberRemoved', userId);
9696
};
9797
</script>
9898

src/presentation/pages/NoteSettings.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ import { getTimeFromNow } from '@/infrastructure/utils/date';
112112
import InviteLink from '@/presentation/components/noteSettings/InviteLink.vue';
113113
import useNavbar from '@/application/services/useNavbar';
114114
import { useRoute } from 'vue-router';
115+
import { TeamMember } from '@/domain/entities/Team';
115116
116117
const { t } = useI18n();
117118
@@ -223,12 +224,18 @@ onMounted(async () => {
223224
});
224225
225226
/**
226-
* Handle team member removal by refreshing the note settings
227+
* Handle team member removal by refreshing the note settings and removing the member from the team
228+
*
229+
* @param userId - user id of the member to remove
227230
*/
228-
async function handleTeamMemberRemoved() {
229-
await loadSettings(props.id);
231+
async function handleTeamMemberRemoved(userId: TeamMember['user']['id']) {
232+
if (noteSettings.value !== null) {
233+
noteSettings.value = {
234+
...noteSettings.value,
235+
team: noteSettings.value.team.filter(member => member.user.id !== userId),
236+
};
237+
}
230238
}
231-
232239
</script>
233240

234241
<style setup lang="postcss" scoped>

0 commit comments

Comments
 (0)