feat(pages): add contact page

This commit is contained in:
2025-11-19 22:03:35 +01:00
parent 0b65e17903
commit 10e51b5da4
7 changed files with 230 additions and 7 deletions

View File

@@ -14,7 +14,17 @@ vi.mock('#app', () => ({
}));
// Mock $fetch globally
global.$fetch = vi.fn();
declare global {
var $fetch: ReturnType<typeof vi.fn>;
}
// global.$fetch = vi.fn();
vi.mock('#app', () => ({
useRuntimeConfig: vi.fn(() => ({
public: {
apiBase: 'http://localhost:3100/api'
}
}))
}))
describe('useApi', () => {
beforeEach(() => {

View File

@@ -3,6 +3,8 @@ import type { ApiError } from '~/types/api/error';
import type { HttpMethod } from '~/types/http-method';
import { QueryResult } from '~/types/query-result';
export type UseApiResponse<T, B = unknown> = QueryResult<T, B>;
export interface UseApi {
get: <T>(path: string, opts?: FetchOptions, immediate?: boolean) => UseApiResponse<T>;
del: <T>(path: string, opts?: FetchOptions, immediate?: boolean) => UseApiResponse<T>;

View File

@@ -1,12 +1,13 @@
import type { ContactRequest, ContactResponse } from '~/types/api/contact';
import type { MetaResponse } from '~/types/api/meta';
import type { UseApiResponse } from './useApi';
export const useBackend = () => {
const api = useApi();
const getMeta = (): UseApiResponse<MetaResponse> => api.get<MetaResponse>('/meta');
const postContact = (): UseApiResponse<ContactResponse, ContactRequest> =>
api.post<ContactResponse, ContactRequest>('/contact', false);
api.post<ContactResponse, ContactRequest>('/contact', undefined, true);
return { getMeta, postContact };
};