Refactor frontend components and enhance API integration
- Updated frontend-nuxt.mdc to specify usage of composables for API calls. - Added new AuthCard and ConfirmModal components for improved UI consistency. - Introduced UserAvatar component for user profile display, replacing previous Gravatar implementation. - Implemented useFormSubmit composable for handling form submissions with loading and error states. - Enhanced vitest.config.ts to include coverage reporting for composables and components. - Removed deprecated useAdminApi and useAuth composables to streamline API interactions. - Updated login and setup pages to utilize new components and composables for better user experience.
This commit is contained in:
24
frontend-nuxt/composables/useFormSubmit.ts
Normal file
24
frontend-nuxt/composables/useFormSubmit.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Composable for form submit with loading and error state.
|
||||
* Use run(fn) to execute an async action; loading and error are updated automatically.
|
||||
*/
|
||||
export function useFormSubmit(defaultError = 'Something went wrong') {
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
|
||||
async function run<T>(fn: () => Promise<T>): Promise<T | undefined> {
|
||||
error.value = ''
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await fn()
|
||||
return result
|
||||
} catch (e: unknown) {
|
||||
error.value = e instanceof Error ? e.message : defaultError
|
||||
return undefined
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return { loading, error, run }
|
||||
}
|
||||
Reference in New Issue
Block a user