25 lines
872 B
TypeScript
25 lines
872 B
TypeScript
import { ContactApi, Configuration, type ContactMessageDto } from '~~/.api-client'
|
|
import { cleanDoubleSlashes, withoutTrailingSlash } from 'ufo'
|
|
import { wrappedFetchWrap } from '~/utils/wrappedFetch'
|
|
|
|
export function useContactApi() {
|
|
const appBaseUrl = useRuntimeConfig().app.baseURL
|
|
const { serverApiBasePath, clientProxyBasePath } = useRuntimeConfig().public
|
|
|
|
const basePath = withoutTrailingSlash(
|
|
cleanDoubleSlashes(import.meta.client ? appBaseUrl + clientProxyBasePath : clientProxyBasePath + serverApiBasePath)
|
|
)
|
|
|
|
const contactApiClient = new ContactApi(
|
|
new Configuration({ basePath, fetchApi: wrappedFetchWrap(useRequestFetch()) })
|
|
)
|
|
|
|
async function sendContactMessage(contactMessageDto: ContactMessageDto): Promise<void> {
|
|
return contactApiClient.sendContactMessage({ contactMessageDto })
|
|
}
|
|
|
|
return {
|
|
sendContactMessage
|
|
}
|
|
}
|