refactor(client): use generated API client and hooks
Signed-off-by: Noa Virellia <noa@requiem.garden>
This commit is contained in:
16
client/cms/src/hooks/data/useExchangeToken.ts
Normal file
16
client/cms/src/hooks/data/useExchangeToken.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { postAuthExchangeMutation } from "@/client/@tanstack/react-query.gen";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export function useExchangeToken() {
|
||||
return useMutation({
|
||||
...postAuthExchangeMutation(),
|
||||
onSuccess: (data) => {
|
||||
window.location.href = data.data?.redirect_uri!;
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
toast("An error occurred while exchanging the token. Please login manually.");
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { axiosClient } from '@/lib/axios';
|
||||
|
||||
export function useCheckinCode(eventId: string, enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: ['getCheckinCode', eventId],
|
||||
queryFn: async () => {
|
||||
return axiosClient.get<{
|
||||
checkin_code: string;
|
||||
}>('/user/checkin', {
|
||||
params: {
|
||||
event_id: eventId,
|
||||
},
|
||||
});
|
||||
},
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
@@ -1,16 +1,8 @@
|
||||
import type { AuthorizeSearchParams } from '@/routes/authorize';
|
||||
import { postAuthMagicMutation } from '@/client/@tanstack/react-query.gen';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { axiosClient } from '@/lib/axios';
|
||||
|
||||
interface GetMagicLinkPayload extends AuthorizeSearchParams {
|
||||
email: string;
|
||||
turnstile_token: string;
|
||||
}
|
||||
|
||||
export function useGetMagicLink() {
|
||||
return useMutation({
|
||||
mutationFn: async (payload: GetMagicLinkPayload) => {
|
||||
return axiosClient.post<{ status: string }>('/auth/magic', payload);
|
||||
},
|
||||
});
|
||||
...postAuthMagicMutation()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
import { getUserInfoQueryKey, patchUserUpdateMutation } from '@/client/@tanstack/react-query.gen';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { axiosClient } from '@/lib/axios';
|
||||
|
||||
interface UpdateUserPayload {
|
||||
avatar?: string;
|
||||
bio?: string;
|
||||
nickname?: string;
|
||||
subtitle?: string;
|
||||
username?: string;
|
||||
}
|
||||
|
||||
export function useUpdateUser() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (payload: UpdateUserPayload) => {
|
||||
return axiosClient.patch<{ status: string }>('/user/update', payload);
|
||||
},
|
||||
...patchUserUpdateMutation(),
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({ queryKey: ['userInfo'] });
|
||||
await queryClient.invalidateQueries({ queryKey: getUserInfoQueryKey() });
|
||||
},
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,23 +1,9 @@
|
||||
import { getUserInfoOptions } from '@/client/@tanstack/react-query.gen';
|
||||
import { useSuspenseQuery } from '@tanstack/react-query';
|
||||
import { axiosClient } from '@/lib/axios';
|
||||
|
||||
export function useUserInfo() {
|
||||
return useSuspenseQuery({
|
||||
queryKey: ['userInfo'],
|
||||
queryFn: async () => {
|
||||
const response = await axiosClient.get<{
|
||||
username: string;
|
||||
user_id: string;
|
||||
email: string;
|
||||
type: string;
|
||||
nickname: string;
|
||||
subtitle: string;
|
||||
avatar: string;
|
||||
bio: string;
|
||||
}
|
||||
>('/user/info');
|
||||
return response.data;
|
||||
},
|
||||
staleTime: 10 * 60 * 1000,
|
||||
...getUserInfoOptions(),
|
||||
staleTime: 10 * 60 * 1000
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { useSuspenseQuery } from '@tanstack/react-query';
|
||||
import { axiosClient } from '@/lib/axios';
|
||||
|
||||
export function useValidateMagicLink(ticket: string) {
|
||||
return useSuspenseQuery({
|
||||
queryKey: ['validateMagicLink', ticket],
|
||||
queryFn: async () => {
|
||||
return axiosClient.get<{ access_token: string; refresh_token: string }>('/auth/magic/verify', { params: { token: ticket } });
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user