Skip to content

Commit

Permalink
fix: Simplify isCreator check
Browse files Browse the repository at this point in the history
After some manipulations on notes.api, it is possible to get creatorId directly as note property.
  • Loading branch information
DeadCreator committed Jan 29, 2025
1 parent 9423b28 commit d054375
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/domain/entities/Note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ export interface Note {
* @todo Resolve the optionality issue
*/
updatedAt?: string;

creatorId?: number;
}
24 changes: 6 additions & 18 deletions src/presentation/components/team/RoleSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
<Select
v-model="selectedRole"
:align="{ vertically: 'below', horizontally: 'right' }"
:is-disabled="teamMember.user.id == user?.id || isCreator"
:is-disabled="teamMember.user.id == user?.id || (note !== null && (note as Note).creatorId === teamMember.id)"
:items="roleItems"
/>
</div>
</template>

<script setup lang="ts">
import { MemberRole, TeamMember } from '@/domain/entities/Team.ts';
import { NoteId } from '@/domain/entities/Note.ts';
import { computed, onMounted, ref, watch } from 'vue';
import { Note, NoteId } from '@/domain/entities/Note.ts';
import { computed, ref, watch } from 'vue';
import useNoteSettings from '@/application/services/useNoteSettings.ts';
import { useAppState } from '@/application/services/useAppState';
import { ContextMenuItem, DefaultItem, Select } from 'codex-ui/vue';
import useNote from '@/application/services/useNote.ts';
/**
* TeamMember props
Expand All @@ -31,9 +32,6 @@ const props = defineProps<{
noteId: NoteId;
}>();
/* property to disable select for changing creator's role */
let isCreator = false;
const selectedRole = ref<DefaultItem>({
title: MemberRole[props.teamMember.role],
onActivate: () => {},
Expand All @@ -50,6 +48,7 @@ roleOptions.value.forEach((role) => {
});
const { changeRole } = useNoteSettings();
const { note } = useNote({ id: props.noteId });
const { user } = useAppState();
/* Watch role's update */
Expand All @@ -58,25 +57,14 @@ watch(selectedRole, (newRole, oldRole) => {
updateMemberRole(newRole.title);
}
});
/**
* Updates the user role if it has been changed
*
* @param updatedRole - new role needed to set
*/
async function updateMemberRole(updatedRole: string | any) {
changeRole(props.noteId, props.teamMember.user.id, MemberRole[updatedRole as keyof typeof MemberRole]).catch(() => {
selectedRole.value = {
title: 'Write',
onActivate: () => {},
};
isCreator = true;
});
changeRole(props.noteId, props.teamMember.user.id, MemberRole[updatedRole as keyof typeof MemberRole]);
}
/* Check, is the user creator or not to disable select on true */
onMounted(() => {
updateMemberRole(MemberRole[props.teamMember.role]);
});
</script>

<style scoped>
Expand Down

0 comments on commit d054375

Please sign in to comment.