feat: add collaborative shopping lists with items and invitations
Some checks failed
CI / Verify (push) Has been cancelled
Some checks failed
CI / Verify (push) Has been cancelled
API: lists, items and invitations modules (list, create, get, update, set-primary, items create/list, invitation create/accept/list-pending), BetterAuth session helper, list membership, mailer and Prisma schema plus migrations. Web: lists overview, list detail (items) and list management (settings) views, item and invitation forms/hooks, sign-up and invitation accept pages. Shared: shopping list DTOs. Tooling: ignore the generated TanStack Router cache (apps/web/.tanstack).
This commit is contained in:
49
apps/web/src/hooks/use-lists.ts
Normal file
49
apps/web/src/hooks/use-lists.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import type { ShoppingListSummary } from '@superlist/shared'
|
||||
import { queryOptions, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
|
||||
import { apiFetch } from '@/lib/api-client'
|
||||
|
||||
export const listsQueryOptions = () =>
|
||||
queryOptions({
|
||||
queryKey: ['lists'],
|
||||
queryFn: () => apiFetch<ShoppingListSummary[]>('/lists'),
|
||||
})
|
||||
|
||||
export function useLists() {
|
||||
return useQuery(listsQueryOptions())
|
||||
}
|
||||
|
||||
export function useCreateList() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (input: { name: string }) =>
|
||||
apiFetch<ShoppingListSummary>('/lists', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(input),
|
||||
}),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['lists'] }),
|
||||
})
|
||||
}
|
||||
|
||||
export function useRenameList(listId: string) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (input: { name: string }) =>
|
||||
apiFetch<ShoppingListSummary>(`/lists/${listId}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(input),
|
||||
}),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['lists'] }),
|
||||
})
|
||||
}
|
||||
|
||||
export function useSetPrimaryList() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (listId: string) => apiFetch<void>(`/lists/${listId}/primary`, { method: 'POST' }),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['lists'] }),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user