mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
build passes Create all missing components (modals, dropdowns, icons, tabs, mail drivers, customer partials), fix all @/scripts/ imports to @v2/, wire up vite entry point and blade template. 382 files, 48883 lines. - 27 settings components: modals (tax, payment, custom field, note, category, role, exchange rate, unit, mail test), dropdowns (6), customization tabs (4), mail driver forms (4) - 22 icon components: 5 utility icons, 4 dashboard icons, 13 editor toolbar icons with typed barrel export - 3 customer components: info, chart placeholder, custom fields single - Fixed usePopper composable, client/format-money import patterns - Zero remaining @/scripts/ imports in scripts-v2/ Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
102 lines
2.2 KiB
TypeScript
102 lines
2.2 KiB
TypeScript
import { ref, computed, readonly } from 'vue'
|
|
import type { DeepReadonly, Ref, ComputedRef } from 'vue'
|
|
import type { ModalSize } from '@v2/config/constants'
|
|
|
|
export interface ModalState {
|
|
active: boolean
|
|
componentName: string
|
|
title: string
|
|
content: string
|
|
id: string
|
|
size: ModalSize
|
|
data: unknown
|
|
refreshData: (() => void) | null
|
|
variant: string
|
|
}
|
|
|
|
export interface OpenModalOptions {
|
|
componentName: string
|
|
title?: string
|
|
content?: string
|
|
id?: string
|
|
size?: ModalSize
|
|
data?: unknown
|
|
refreshData?: () => void
|
|
variant?: string
|
|
}
|
|
|
|
export interface UseModalReturn {
|
|
modalState: DeepReadonly<Ref<ModalState>>
|
|
isEdit: ComputedRef<boolean>
|
|
openModal: (options: OpenModalOptions) => void
|
|
closeModal: () => void
|
|
resetModalData: () => void
|
|
}
|
|
|
|
const DEFAULT_STATE: ModalState = {
|
|
active: false,
|
|
componentName: '',
|
|
title: '',
|
|
content: '',
|
|
id: '',
|
|
size: 'md',
|
|
data: null,
|
|
refreshData: null,
|
|
variant: '',
|
|
}
|
|
|
|
const modalState = ref<ModalState>({ ...DEFAULT_STATE })
|
|
|
|
/**
|
|
* Composable for managing a global modal.
|
|
* Supports opening modals by component name with props, and tracks edit vs create mode.
|
|
*/
|
|
export function useModal(): UseModalReturn {
|
|
const isEdit = computed<boolean>(() => modalState.value.id !== '')
|
|
|
|
/**
|
|
* Open a modal with the specified options.
|
|
*
|
|
* @param options - Modal configuration including component name and optional props
|
|
*/
|
|
function openModal(options: OpenModalOptions): void {
|
|
modalState.value = {
|
|
active: true,
|
|
componentName: options.componentName,
|
|
title: options.title ?? '',
|
|
content: options.content ?? '',
|
|
id: options.id ?? '',
|
|
size: options.size ?? 'md',
|
|
data: options.data ?? null,
|
|
refreshData: options.refreshData ?? null,
|
|
variant: options.variant ?? '',
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Close the modal with a brief delay for animation.
|
|
*/
|
|
function closeModal(): void {
|
|
modalState.value.active = false
|
|
|
|
setTimeout(() => {
|
|
resetModalData()
|
|
}, 300)
|
|
}
|
|
|
|
/**
|
|
* Reset modal data back to defaults.
|
|
*/
|
|
function resetModalData(): void {
|
|
modalState.value = { ...DEFAULT_STATE }
|
|
}
|
|
|
|
return {
|
|
modalState: readonly(modalState),
|
|
isEdit,
|
|
openModal,
|
|
closeModal,
|
|
resetModalData,
|
|
}
|
|
}
|