feat(18-05): add profile hooks and profile edit UI in settings

- Create usePublicProfile and useUpdateProfile hooks
- Create ProfileSection component with avatar upload, display name, bio
- Add Profile section to settings page (visible when authenticated)
This commit is contained in:
2026-04-05 13:17:31 +02:00
parent f7c9f3dc94
commit f120d179f7
3 changed files with 275 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiGet, apiPut } from "../lib/api";
interface PublicProfile {
id: number;
displayName: string | null;
avatarUrl: string | null;
bio: string | null;
setups: { id: number; name: string; createdAt: string }[];
}
interface UpdateProfileData {
displayName?: string;
avatarUrl?: string | null;
bio?: string;
}
interface ProfileResponse {
id: number;
displayName: string | null;
avatarUrl: string | null;
bio: string | null;
}
export function usePublicProfile(userId: number | null) {
return useQuery({
queryKey: ["profiles", userId],
queryFn: () => apiGet<PublicProfile>(`/api/users/${userId}/profile`),
enabled: userId != null,
});
}
export function useUpdateProfile() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: UpdateProfileData) =>
apiPut<ProfileResponse>("/api/auth/profile", data),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["profiles"] });
queryClient.invalidateQueries({ queryKey: ["auth"] });
},
});
}