hooks/profile: allow pass empty args to useProfileQuery/useProfileMutation
This commit is contained in:
parent
8c8a588dfc
commit
ec32f56f8b
@ -5,7 +5,7 @@ import { useEffect, useState } from 'react';
|
||||
|
||||
export function UpdateProfile() {
|
||||
const initDataUser = useSignal(initData.user);
|
||||
const { mutate: updateProfile } = useProfileMutation({});
|
||||
const { mutate: updateProfile } = useProfileMutation();
|
||||
const [hasUpdated, setHasUpdated] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@ -30,8 +30,8 @@ export function ContactDataCard({ telegramId }: Readonly<ProfileProps>) {
|
||||
}
|
||||
|
||||
export function ProfileDataCard() {
|
||||
const { data: customer } = useProfileQuery({});
|
||||
const { mutate: updateProfile } = useProfileMutation({});
|
||||
const { data: customer } = useProfileQuery();
|
||||
const { mutate: updateProfile } = useProfileMutation();
|
||||
|
||||
if (!customer) return null;
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ type Parameters_ = {
|
||||
|
||||
export function useCustomerContacts(parameters?: Parameters_) {
|
||||
const { filter, setFilter } = use(ContactsFilterContext);
|
||||
const { data: customer, isLoading: isLoadingProfile } = useProfileQuery({});
|
||||
const { data: customer, isLoading: isLoadingProfile } = useProfileQuery();
|
||||
|
||||
const {
|
||||
data: clientsData,
|
||||
|
||||
@ -3,19 +3,21 @@ import { getProfile, updateProfile } from '@/actions/profile';
|
||||
import { type ProfileProps } from '@/components/profile/types';
|
||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||
|
||||
export const useProfileQuery = ({ telegramId }: ProfileProps) => {
|
||||
export const useProfileQuery = (props?: ProfileProps) => {
|
||||
const telegramId = props?.telegramId;
|
||||
|
||||
return useQuery({
|
||||
queryFn: () => getProfile({ telegramId }),
|
||||
queryKey: telegramId ? ['profile', 'telegramId', telegramId, 'get'] : ['profile', 'get'],
|
||||
});
|
||||
};
|
||||
|
||||
export const useProfileMutation = ({ telegramId }: ProfileProps) => {
|
||||
const { refetch } = useProfileQuery({ telegramId });
|
||||
export const useProfileMutation = () => {
|
||||
const { refetch } = useProfileQuery();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: updateProfile,
|
||||
mutationKey: ['profile', 'telegramId', telegramId, 'update'],
|
||||
mutationKey: ['profile', 'update'],
|
||||
onSuccess: () => refetch(),
|
||||
});
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user