Files
InvoiceShelf/resources/scripts/admin/stores/invitation.js
Darko Gjorgjijoski 6343b4a17f Add invitation frontend: invite modal, pending invitations, no-company view
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
2026-04-03 23:20:41 +02:00

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
},
},
})