feat(defter): haftanın girişleri, düzenle/sil + geri al, haftalık özet
- Girişler gün gün, gün toplamıyla; satırda kategori, grup, ödeme türü, açıklama - Düzenleme aynı formda (sürüm kontrolü, pasif kategori korunur) - Silmede "Geri al" bildirimi; grup bazlı bütçe / harcanan / kalan özeti Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
import { keepPreviousData, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import type { Entry } from '@/types/Entry'
|
||||
import type { EntryCreateRequest } from '@/types/EntryCreateRequest'
|
||||
import type { EntryUpdateRequest } from '@/types/EntryUpdateRequest'
|
||||
import { api } from './api'
|
||||
import { queryKeys } from './query'
|
||||
|
||||
@@ -28,3 +29,30 @@ export function useCreateEntry(periodId: string) {
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.period(periodId) }),
|
||||
})
|
||||
}
|
||||
|
||||
/** Düzenle (`version` ile: başkası değiştirdiyse 409). Hata da olsa liste yenilenir. */
|
||||
export function useUpdateEntry(periodId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: ({ id, ...body }: EntryUpdateRequest & { id: string }) =>
|
||||
api.patch<Entry>(`/entries/${id}`, body),
|
||||
onSettled: () => qc.invalidateQueries({ queryKey: queryKeys.period(periodId) }),
|
||||
})
|
||||
}
|
||||
|
||||
/** Sil (soft) → `useRestoreEntry` ile geri alınabilir */
|
||||
export function useDeleteEntry(periodId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.delete(`/entries/${id}`),
|
||||
onSettled: () => qc.invalidateQueries({ queryKey: queryKeys.period(periodId) }),
|
||||
})
|
||||
}
|
||||
|
||||
export function useRestoreEntry(periodId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.post<Entry>(`/entries/${id}/restore`),
|
||||
onSettled: () => qc.invalidateQueries({ queryKey: queryKeys.period(periodId) }),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user