mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
Now that the legacy v1 frontend (commit 064bdf53) is gone, the v2 directory is the only frontend and the v2 suffix is just noise. Renames resources/scripts-v2 to resources/scripts via git mv (so git records the move as renames, preserving blame and log --follow), then bulk-rewrites the 152 files that imported via @v2/... to use @/scripts/... instead. The existing @ alias (resources/) covers the new path with no extra config needed.
Drops the now-unused @v2 alias from vite.config.js and points the laravel-vite-plugin entry at resources/scripts/main.ts. Updates the only blade reference (resources/views/app.blade.php) to match. The package.json test script (eslint ./resources/scripts) automatically targets the right place after the rename without any edit.
Verified: npm run build exits clean and the Vite warning lines now reference resources/scripts/plugins/i18n.ts, confirming every import resolved through the new path. git log --follow on any moved file walks back through its scripts-v2 history.
204 lines
5.0 KiB
TypeScript
204 lines
5.0 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
import { client } from '../../../api/client'
|
|
import { API } from '../../../api/endpoints'
|
|
import { useNotificationStore } from '../../../stores/notification.store'
|
|
import { handleApiError } from '../../../utils/error-handling'
|
|
import * as ls from '../../../utils/local-storage'
|
|
import type { Company } from '../../../types/domain/company'
|
|
import type { User } from '../../../types/domain/user'
|
|
import type { PaginatedResponse } from '../../../types/api'
|
|
|
|
export interface AdminDashboardData {
|
|
app_version: string
|
|
php_version: string
|
|
database: {
|
|
driver: string
|
|
version: string
|
|
}
|
|
counts: {
|
|
companies: number
|
|
users: number
|
|
}
|
|
}
|
|
|
|
export interface FetchCompaniesParams {
|
|
search?: string
|
|
orderByField?: string
|
|
orderBy?: string
|
|
page?: number
|
|
}
|
|
|
|
export interface FetchUsersParams {
|
|
display_name?: string
|
|
email?: string
|
|
phone?: string
|
|
orderByField?: string
|
|
orderBy?: string
|
|
page?: number
|
|
}
|
|
|
|
export interface UpdateCompanyData {
|
|
name: string
|
|
owner_id: number
|
|
vat_id?: string
|
|
tax_id?: string
|
|
address?: {
|
|
address_street_1?: string
|
|
address_street_2?: string
|
|
country_id?: number | null
|
|
state?: string
|
|
city?: string
|
|
phone?: string
|
|
zip?: string
|
|
}
|
|
}
|
|
|
|
export interface UpdateUserData {
|
|
name: string
|
|
email: string
|
|
phone?: string
|
|
password?: string
|
|
}
|
|
|
|
export const useAdminStore = defineStore('admin', () => {
|
|
// State
|
|
const companies = ref<Company[]>([])
|
|
const totalCompanies = ref<number>(0)
|
|
const selectedCompany = ref<Company | null>(null)
|
|
|
|
const users = ref<User[]>([])
|
|
const totalUsers = ref<number>(0)
|
|
|
|
const dashboardData = ref<AdminDashboardData | null>(null)
|
|
|
|
// Actions
|
|
async function fetchDashboard(): Promise<AdminDashboardData> {
|
|
try {
|
|
const { data } = await client.get(API.SUPER_ADMIN_DASHBOARD)
|
|
dashboardData.value = data
|
|
return data
|
|
} catch (err: unknown) {
|
|
handleApiError(err)
|
|
throw err
|
|
}
|
|
}
|
|
|
|
async function fetchCompanies(params: FetchCompaniesParams): Promise<PaginatedResponse<Company>> {
|
|
try {
|
|
const { data } = await client.get(API.SUPER_ADMIN_COMPANIES, { params })
|
|
companies.value = data.data
|
|
totalCompanies.value = data.meta?.total ?? data.data.length
|
|
return data
|
|
} catch (err: unknown) {
|
|
handleApiError(err)
|
|
throw err
|
|
}
|
|
}
|
|
|
|
async function fetchCompany(id: number | string): Promise<{ data: Company }> {
|
|
try {
|
|
const { data } = await client.get(`${API.SUPER_ADMIN_COMPANIES}/${id}`)
|
|
selectedCompany.value = data.data
|
|
return data
|
|
} catch (err: unknown) {
|
|
handleApiError(err)
|
|
throw err
|
|
}
|
|
}
|
|
|
|
async function updateCompany(id: number | string, payload: UpdateCompanyData): Promise<void> {
|
|
try {
|
|
await client.put(`${API.SUPER_ADMIN_COMPANIES}/${id}`, payload)
|
|
|
|
const notificationStore = useNotificationStore()
|
|
notificationStore.showNotification({
|
|
type: 'success',
|
|
message: 'Company updated successfully.',
|
|
})
|
|
} catch (err: unknown) {
|
|
handleApiError(err)
|
|
throw err
|
|
}
|
|
}
|
|
|
|
async function fetchUsers(params: FetchUsersParams): Promise<PaginatedResponse<User>> {
|
|
try {
|
|
const { data } = await client.get(API.SUPER_ADMIN_USERS, { params })
|
|
users.value = data.data
|
|
totalUsers.value = data.meta?.total ?? data.data.length
|
|
return data
|
|
} catch (err: unknown) {
|
|
handleApiError(err)
|
|
throw err
|
|
}
|
|
}
|
|
|
|
async function fetchUser(id: number | string): Promise<{ data: User }> {
|
|
try {
|
|
const { data } = await client.get(`${API.SUPER_ADMIN_USERS}/${id}`)
|
|
return data
|
|
} catch (err: unknown) {
|
|
handleApiError(err)
|
|
throw err
|
|
}
|
|
}
|
|
|
|
async function updateUser(id: number | string, payload: UpdateUserData): Promise<void> {
|
|
try {
|
|
await client.put(`${API.SUPER_ADMIN_USERS}/${id}`, payload)
|
|
|
|
const notificationStore = useNotificationStore()
|
|
notificationStore.showNotification({
|
|
type: 'success',
|
|
message: 'User updated successfully.',
|
|
})
|
|
} catch (err: unknown) {
|
|
handleApiError(err)
|
|
throw err
|
|
}
|
|
}
|
|
|
|
async function impersonateUser(id: number): Promise<void> {
|
|
try {
|
|
const { data } = await client.post(`${API.SUPER_ADMIN_USERS}/${id}/impersonate`)
|
|
ls.set('admin.impersonating', 'true')
|
|
ls.set('auth.token', `Bearer ${data.token}`)
|
|
} catch (err: unknown) {
|
|
handleApiError(err)
|
|
throw err
|
|
}
|
|
}
|
|
|
|
async function stopImpersonating(): Promise<void> {
|
|
try {
|
|
await client.post(API.SUPER_ADMIN_STOP_IMPERSONATING)
|
|
} catch (err: unknown) {
|
|
handleApiError(err)
|
|
} finally {
|
|
ls.remove('admin.impersonating')
|
|
ls.remove('auth.token')
|
|
}
|
|
}
|
|
|
|
return {
|
|
// State
|
|
companies,
|
|
totalCompanies,
|
|
selectedCompany,
|
|
users,
|
|
totalUsers,
|
|
dashboardData,
|
|
// Actions
|
|
fetchDashboard,
|
|
fetchCompanies,
|
|
fetchCompany,
|
|
updateCompany,
|
|
fetchUsers,
|
|
fetchUser,
|
|
updateUser,
|
|
impersonateUser,
|
|
stopImpersonating,
|
|
}
|
|
})
|