mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-11 17:52:15 +01:00
add invitations tab to members page
This commit is contained in:
54
resources/js/utils/useInvitations.ts
Normal file
54
resources/js/utils/useInvitations.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { api } from '../../../openapi.json.client';
|
||||
import { computed, ref } from 'vue';
|
||||
import type {
|
||||
InvitationsIndexResponse,
|
||||
CreateInvitationBody,
|
||||
Invitation,
|
||||
} from '@/utils/api';
|
||||
import { getCurrentOrganizationId } from '@/utils/useUser';
|
||||
import { useNotificationsStore } from '@/utils/notification';
|
||||
|
||||
export const useInvitationsStore = defineStore('invitations', () => {
|
||||
const invitationsResponse = ref<InvitationsIndexResponse | null>(null);
|
||||
const { handleApiRequestNotifications } = useNotificationsStore();
|
||||
|
||||
async function fetchInvitations() {
|
||||
const organization = getCurrentOrganizationId();
|
||||
if (organization) {
|
||||
invitationsResponse.value = await handleApiRequestNotifications(
|
||||
api.getInvitations({
|
||||
params: {
|
||||
organization: organization,
|
||||
},
|
||||
}),
|
||||
undefined,
|
||||
'Failed to fetch invitations'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function createInvitation(
|
||||
inviteBody: CreateInvitationBody
|
||||
): Promise<undefined> {
|
||||
const organization = getCurrentOrganizationId();
|
||||
if (organization) {
|
||||
await handleApiRequestNotifications(
|
||||
api.invite(inviteBody, {
|
||||
params: {
|
||||
organization: organization,
|
||||
},
|
||||
}),
|
||||
'User successfully invited',
|
||||
'Failed to invite user'
|
||||
);
|
||||
await fetchInvitations();
|
||||
}
|
||||
}
|
||||
|
||||
const invitations = computed<Invitation[]>(() => {
|
||||
return invitationsResponse.value?.data || [];
|
||||
});
|
||||
|
||||
return { invitations, fetchInvitations, createInvitation };
|
||||
});
|
||||
Reference in New Issue
Block a user