mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
Members Index: - "Invite Member" button opens InviteMemberModal (email + role dropdown) - Pending invitations section shows below members table with cancel buttons - Members store gains inviteMember, fetchPendingInvitations, cancelInvitation CompanySwitcher: - Shows pending invitations greyed out below active companies - Each with Accept/Decline mini-buttons - Accepting refreshes bootstrap and switches to new company NoCompanyView: - Standalone page for users with zero accepted companies - Shows pending invitations with Accept/Decline or "no companies" message - Route: /admin/no-company Invitation Pinia store: - Manages user's own pending invitations (fetchPending, accept, decline) - Bootstrap populates invitations from API response Global store: - Bootstrap action stores pending_invitations from response
57 lines
1.4 KiB
JavaScript
Vendored
57 lines
1.4 KiB
JavaScript
Vendored
import { defineStore } from 'pinia'
|
|
import { useNotificationStore } from '@/scripts/stores/notification'
|
|
import { useGlobalStore } from '@/scripts/admin/stores/global'
|
|
import http from '@/scripts/http'
|
|
|
|
export const useInvitationStore = defineStore('invitation', {
|
|
state: () => ({
|
|
pendingInvitations: [],
|
|
}),
|
|
|
|
actions: {
|
|
setPendingInvitations(invitations) {
|
|
this.pendingInvitations = invitations
|
|
},
|
|
|
|
async fetchPending() {
|
|
const response = await http.get('/api/v1/invitations/pending')
|
|
this.pendingInvitations = response.data.invitations
|
|
return response
|
|
},
|
|
|
|
async accept(token) {
|
|
const notificationStore = useNotificationStore()
|
|
const globalStore = useGlobalStore()
|
|
|
|
const response = await http.post(`/api/v1/invitations/${token}/accept`)
|
|
|
|
notificationStore.showNotification({
|
|
type: 'success',
|
|
message: 'Invitation accepted!',
|
|
})
|
|
|
|
// Refresh bootstrap to get updated companies list
|
|
await globalStore.bootstrap()
|
|
|
|
return response
|
|
},
|
|
|
|
async decline(token) {
|
|
const notificationStore = useNotificationStore()
|
|
|
|
const response = await http.post(`/api/v1/invitations/${token}/decline`)
|
|
|
|
this.pendingInvitations = this.pendingInvitations.filter(
|
|
(inv) => inv.token !== token
|
|
)
|
|
|
|
notificationStore.showNotification({
|
|
type: 'success',
|
|
message: 'Invitation declined.',
|
|
})
|
|
|
|
return response
|
|
},
|
|
},
|
|
})
|