refactor: replace common confirm dialogs with maintenance CRUD dialogs and streamline form handling in MasterDetailMntC.vue and SingleRecordMnt.vue
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ref } from 'vue'
|
||||
import { ref, type Ref } from 'vue'
|
||||
import { type ApiRequestError, normalizeError } from '@/services/error'
|
||||
import { useSnackbarStore } from '@/stores/snackbar'
|
||||
|
||||
@@ -9,6 +9,15 @@ type Options = {
|
||||
errorToastLevel?: (error: ApiRequestError) => ToastLevel
|
||||
}
|
||||
|
||||
interface UseApiCallResult<TResult, TArgs extends unknown[]> {
|
||||
loading: Ref<boolean>
|
||||
data: Ref<TResult | null>
|
||||
error: Ref<ApiRequestError | null>
|
||||
execute: (...args: TArgs) => Promise<TResult>
|
||||
executeSafe: (...args: TArgs) => Promise<TResult | null>
|
||||
reset: () => void
|
||||
}
|
||||
|
||||
function getDefaultToastLevel (error: ApiRequestError): ToastLevel {
|
||||
if (typeof error.status === 'number' && error.status >= 500) return 'error'
|
||||
return 'warning'
|
||||
@@ -21,9 +30,9 @@ function levelToColor (level: ToastLevel): string {
|
||||
}
|
||||
|
||||
export function useApiCall <TResult, TArgs extends unknown[]>(action: (...args: TArgs) => Promise<TResult>,
|
||||
options?: Options) {
|
||||
options?: Options): UseApiCallResult<TResult, TArgs> {
|
||||
const loading = ref(false)
|
||||
const data = ref<TResult | null>(null)
|
||||
const data = ref<TResult | null>(null) as Ref<TResult | null>
|
||||
const error = ref<ApiRequestError | null>(null)
|
||||
|
||||
const snackbar = useSnackbarStore()
|
||||
@@ -80,4 +89,3 @@ export function useApiCall <TResult, TArgs extends unknown[]>(action: (...args:
|
||||
reset,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user