feat(web,api): клиент/хуки расписания/каналов/истории + lastCheckStatus в domainResponse

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BwxdSt4reTm7Dj1oxRvpP3
This commit is contained in:
2026-07-04 14:24:02 +07:00
parent b31f886ae2
commit 45259b9720
5 changed files with 162 additions and 2 deletions
+69 -1
View File
@@ -1,7 +1,7 @@
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"
import { api } from "@/api/client"
import { useAuth } from "@/auth/AuthContext"
import type { CreateAccountInput, CreateTemplateInput, ApplyRequest, Project } from "@/api/types"
import type { CreateAccountInput, CreateTemplateInput, ApplyRequest, Project, Schedule, CreateChannelInput } from "@/api/types"
function requireProjectId(project: Project | null): string {
if (!project) throw new Error("no active project")
@@ -141,3 +141,71 @@ export function useApplyDomain(id: string) {
onSuccess: () => qc.invalidateQueries({ queryKey: ["check", project?.id, id] }),
})
}
export function useDomainHistory(id: string) {
const { project } = useAuth()
return useQuery({
queryKey: ["domainHistory", project?.id, id],
queryFn: () => api.domainHistory(project!.id, id),
enabled: !!project && !!id,
})
}
export function useSchedule() {
const { project } = useAuth()
return useQuery({
queryKey: ["schedule", project?.id],
queryFn: () => api.getSchedule(project!.id),
enabled: !!project,
})
}
export function useUpdateSchedule() {
const { project } = useAuth()
const qc = useQueryClient()
return useMutation({
mutationFn: (input: Schedule) => {
const pid = requireProjectId(project)
return api.putSchedule(pid, input)
},
onSuccess: () => qc.invalidateQueries({ queryKey: ["schedule", project?.id] }),
})
}
export function useChannels() {
const { project } = useAuth()
return useQuery({
queryKey: ["channels", project?.id],
queryFn: () => api.listChannels(project!.id),
enabled: !!project,
})
}
export function useCreateChannel() {
const { project } = useAuth()
const qc = useQueryClient()
return useMutation({
mutationFn: (input: CreateChannelInput) => {
const pid = requireProjectId(project)
return api.createChannel(pid, input)
},
onSuccess: () => qc.invalidateQueries({ queryKey: ["channels", project?.id] }),
})
}
export function useDeleteChannel() {
const { project } = useAuth()
const qc = useQueryClient()
return useMutation({
mutationFn: (id: string) => {
const pid = requireProjectId(project)
return api.deleteChannel(pid, id)
},
onSuccess: () => qc.invalidateQueries({ queryKey: ["channels", project?.id] }),
})
}
export function useTestChannel() {
const { project } = useAuth()
return useMutation({
mutationFn: (id: string) => {
const pid = requireProjectId(project)
return api.testChannel(pid, id)
},
})
}