fp/services/next/app/profile/hooks/useMetadata.ts

53 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-12-16 20:39:23 +00:00
// import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
// export type MetadataPayload = {
// metadata: {
// first_name: string
// last_name: string
// patreon: {
// entitledTiers: string[],
// lifetimeSupportCents: number,
// currentlyEntitledSupportCents: number
// },
// isUsernamePublic: boolean
// }
// }
// export type UpdateMetadataInput = { isUsernamePublic: boolean }
// const fetchMetadata = async (): Promise<MetadataPayload> => {
// const response = await fetch(`/api/user/attributes`)
// const data = await response.json()
// return data
// }
// const fetchMutateMetadata = async (data: UpdateMetadataInput): Promise<void> => {
// const res = await fetch('/api/user/attributes', {
// method: 'POST',
// body: JSON.stringify({
// isUsernamePublic: data.isUsernamePublic
// })
// })
// if (!res.ok) throw new Error(`failed to fetchMutateMetadata. ${res.status} ${res.statusText}`);
// }
// const useMetadata = () => {
// return useQuery({
// queryKey: ['user/attributes'],
// queryFn: () => fetchMetadata()
// })
// }
// const useMutateMetadata = () => {
// const queryClient = useQueryClient()
// return useMutation({
// mutationFn: (data: UpdateMetadataInput) => fetchMutateMetadata(data),
// onSuccess: () => {
// queryClient.invalidateQueries({ queryKey: ['user/attributes'] })
// }
// })
// }
// export { useMetadata, fetchMetadata, useMutateMetadata }