fix(frontend): Loading and removal of members of organization
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
import type { ActiveOrganization, Organization, Invitation } from '~/composables/useAuth'
|
||||
import type {
|
||||
ActiveOrganization,
|
||||
Organization,
|
||||
Invitation,
|
||||
ListMembersOptions,
|
||||
ListMembersResponse,
|
||||
ListMembersQuery
|
||||
} from '~/composables/useAuth'
|
||||
import { useOrganizationApi } from '~/composables/organization/useOrganizationApi'
|
||||
import type { LegalRole } from '~/server/utils/permissions'
|
||||
|
||||
@@ -6,6 +13,7 @@ export const useOrganizationStore = defineStore('Organization', () => {
|
||||
const activeOrganization = ref<ActiveOrganization | null>(null)
|
||||
const organizations = ref<Organization[]>([])
|
||||
const invitations = ref<Invitation[]>([])
|
||||
const activeOrganizationMembers = ref<ListMembersResponse>([])
|
||||
|
||||
const organizationApi = useOrganizationApi()
|
||||
const toast = useToast()
|
||||
@@ -87,6 +95,19 @@ export const useOrganizationStore = defineStore('Organization', () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function removeMember(memberId: string) {
|
||||
try {
|
||||
await organizationApi.removeMember(memberId)
|
||||
activeOrganizationMembers.value = activeOrganizationMembers.value.filter(
|
||||
(member: Member) => member.id !== memberId
|
||||
)
|
||||
toast.add({ title: 'Member removed successfully', color: 'success' })
|
||||
} catch (e) {
|
||||
toast.add({ title: 'Error removing member', color: 'error' })
|
||||
console.error('Error removing member:', e)
|
||||
}
|
||||
}
|
||||
|
||||
async function acceptInvitation(invitationId: string) {
|
||||
try {
|
||||
await organizationApi.acceptInvitation(invitationId)
|
||||
@@ -157,14 +178,36 @@ export const useOrganizationStore = defineStore('Organization', () => {
|
||||
|
||||
const { data: invitationsToSet } = await organizationApi.listInvitations(activeOrganizationToSet?.id)
|
||||
invitations.value = invitationsToSet ?? []
|
||||
|
||||
await loadMembers()
|
||||
} catch (e) {
|
||||
toast.add({ title: 'Error setting active organizations', color: 'error' })
|
||||
console.error('Error setting active organizations:', e)
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMembers(options?: Omit<NonNullable<ListMembersQuery>, 'organizationId'>) {
|
||||
try {
|
||||
if (!activeOrganization.value?.id) return null
|
||||
|
||||
const memberOptions: ListMembersOptions = {
|
||||
query: {
|
||||
organizationId: activeOrganization.value.id,
|
||||
...options
|
||||
}
|
||||
}
|
||||
|
||||
const { data: response } = await organizationApi.listMembers(memberOptions)
|
||||
activeOrganizationMembers.value = response?.members ?? []
|
||||
} catch (e) {
|
||||
toast.add({ title: 'Error getting members', color: 'error' })
|
||||
console.error('Error getting members:', e)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
activeOrganization,
|
||||
activeOrganizationMembers,
|
||||
organizations,
|
||||
createOrganization,
|
||||
deleteOrganization,
|
||||
@@ -172,6 +215,7 @@ export const useOrganizationStore = defineStore('Organization', () => {
|
||||
getInvitation,
|
||||
loadInvitations,
|
||||
inviteMember,
|
||||
removeMember,
|
||||
acceptInvitation,
|
||||
rejectInvitation,
|
||||
cancelSentInvitation,
|
||||
|
||||
Reference in New Issue
Block a user