feat(pages): add contact page
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user