feat: implement configuration management and enhance user registration flow

This commit is contained in:
2026-03-11 22:26:16 +01:00
parent 62549faffa
commit 0f1b9c11fe
12 changed files with 370 additions and 95 deletions

View File

@@ -1,10 +1,19 @@
"use client";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { toast } from "sonner";
import { api } from "@/lib/api";
import { useAuthContext } from "@/context/auth-context";
import type { CreateChannelRequest, UpdateChannelRequest } from "@/lib/types";
export function useConfig() {
return useQuery({
queryKey: ["config"],
queryFn: () => api.config.get(),
staleTime: Infinity, // config doesn't change at runtime
});
}
export function useChannels() {
const { token } = useAuthContext();
return useQuery({
@@ -29,9 +38,11 @@ export function useCreateChannel() {
return useMutation({
mutationFn: (data: CreateChannelRequest) =>
api.channels.create(data, token!),
onSuccess: () => {
onSuccess: (channel) => {
queryClient.invalidateQueries({ queryKey: ["channels"] });
toast.success(`Channel "${channel.name}" created`);
},
onError: (e: Error) => toast.error(e.message),
});
}
@@ -44,7 +55,9 @@ export function useUpdateChannel() {
onSuccess: (updated) => {
queryClient.invalidateQueries({ queryKey: ["channels"] });
queryClient.invalidateQueries({ queryKey: ["channel", updated.id] });
toast.success(`Channel "${updated.name}" saved`);
},
onError: (e: Error) => toast.error(e.message),
});
}
@@ -55,7 +68,9 @@ export function useDeleteChannel() {
mutationFn: (id: string) => api.channels.delete(id, token!),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["channels"] });
toast.success("Channel deleted");
},
onError: (e: Error) => toast.error(e.message),
});
}
@@ -67,7 +82,9 @@ export function useGenerateSchedule() {
api.schedule.generate(channelId, token!),
onSuccess: (_, channelId) => {
queryClient.invalidateQueries({ queryKey: ["schedule", channelId] });
toast.success("Schedule generated");
},
onError: (e: Error) => toast.error(`Schedule failed: ${e.message}`),
});
}