feat(frontend): add react spa with wishlist flows and public profile
This commit is contained in:
41
apps/frontend/src/features/wishes/wishes.api.ts
Normal file
41
apps/frontend/src/features/wishes/wishes.api.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type {
|
||||
CreateWishInput,
|
||||
UpdateWishInput,
|
||||
Wish,
|
||||
WishStatus,
|
||||
} from '@family-wishlist/shared';
|
||||
import { api } from '@/lib/api';
|
||||
|
||||
export type WishWithOwnerBadge = Wish & { isNewForOwner?: boolean };
|
||||
|
||||
export type OwnerStatus = 'active' | 'archived' | 'completed' | 'deleted';
|
||||
|
||||
export const wishesApi = {
|
||||
list: (status: OwnerStatus) =>
|
||||
api.get<WishWithOwnerBadge[]>(`/api/wishes?status=${status}`),
|
||||
|
||||
get: (id: string) => api.get<Wish>(`/api/wishes/${id}`),
|
||||
|
||||
create: (input: CreateWishInput) => api.post<Wish, CreateWishInput>('/api/wishes', input),
|
||||
|
||||
update: (id: string, input: UpdateWishInput) =>
|
||||
api.patch<Wish, UpdateWishInput>(`/api/wishes/${id}`, input),
|
||||
|
||||
remove: (id: string) => api.delete<Wish>(`/api/wishes/${id}`),
|
||||
archive: (id: string) => api.post<Wish>(`/api/wishes/${id}/archive`),
|
||||
complete: (id: string) => api.post<Wish>(`/api/wishes/${id}/complete`),
|
||||
restore: (id: string) => api.post<Wish>(`/api/wishes/${id}/restore`),
|
||||
duplicate: (id: string) => api.post<Wish>(`/api/wishes/${id}/duplicate`),
|
||||
|
||||
uploadImage: (id: string, file: File) => {
|
||||
const fd = new FormData();
|
||||
fd.append('file', file, file.name);
|
||||
return api.upload<Wish>(`/api/wishes/${id}/image`, fd);
|
||||
},
|
||||
refreshOg: (id: string) => api.post<Wish>(`/api/wishes/${id}/image/refresh-og`),
|
||||
deleteImage: (id: string) => api.delete<Wish>(`/api/wishes/${id}/image`),
|
||||
};
|
||||
|
||||
export function statusToQuery(s: WishStatus): OwnerStatus {
|
||||
return s.toLowerCase() as OwnerStatus;
|
||||
}
|
||||
Reference in New Issue
Block a user