diff --git a/apps/web/actions/profile.ts b/apps/web/actions/profile.ts index 7d6043b..b400e59 100644 --- a/apps/web/actions/profile.ts +++ b/apps/web/actions/profile.ts @@ -3,7 +3,6 @@ import { authOptions } from '@/config/auth'; import { getCustomer, updateCustomerProfile } from '@repo/graphql/api'; import { type CustomerInput, type GetCustomerQueryVariables } from '@repo/graphql/types'; import { getServerSession } from 'next-auth/next'; -import { revalidatePath } from 'next/cache'; export async function getProfile(input?: GetCustomerQueryVariables) { const session = await getServerSession(authOptions); @@ -30,6 +29,4 @@ export async function updateProfile(input: CustomerInput) { data: input, documentId: customer.documentId, }); - - revalidatePath('/profile'); } diff --git a/apps/web/components/profile/cards/data-card.tsx b/apps/web/components/profile/cards/data-card.tsx index 25aef48..08c6058 100644 --- a/apps/web/components/profile/cards/data-card.tsx +++ b/apps/web/components/profile/cards/data-card.tsx @@ -2,8 +2,7 @@ import { type ProfileProps } from '../types'; import { CheckboxWithText, DataField, ProfileCardHeader } from './components'; import { updateRole } from './lib/actions'; -import { updateProfile } from '@/actions/profile'; -import { useProfile } from '@/hooks/profile'; +import { useProfile, useProfileMutation } from '@/hooks/profile'; import { Button } from '@repo/ui/components/ui/button'; import { Card } from '@repo/ui/components/ui/card'; import Link from 'next/link'; @@ -31,6 +30,7 @@ export function ContactDataCard({ telegramId }: Readonly) { export function ProfileDataCard() { const { data: customer } = useProfile({}); + const { mutate: updateProfile } = useProfileMutation({}); if (!customer) return null; diff --git a/apps/web/hooks/profile/index.ts b/apps/web/hooks/profile/index.ts index 093632b..8db3e0b 100644 --- a/apps/web/hooks/profile/index.ts +++ b/apps/web/hooks/profile/index.ts @@ -1,7 +1,7 @@ 'use client'; -import { getProfile } from '@/actions/profile'; +import { getProfile, updateProfile } from '@/actions/profile'; import { type ProfileProps } from '@/components/profile/types'; -import { useQuery } from '@tanstack/react-query'; +import { useMutation, useQuery } from '@tanstack/react-query'; export const useProfile = ({ telegramId }: ProfileProps) => { return useQuery({ @@ -9,3 +9,13 @@ export const useProfile = ({ telegramId }: ProfileProps) => { queryKey: telegramId ? ['profile', 'telegramId', telegramId] : ['profile'], }); }; + +export const useProfileMutation = ({ telegramId }: ProfileProps) => { + const { refetch } = useProfile({ telegramId }); + + return useMutation({ + mutationFn: updateProfile, + mutationKey: ['profile', 'telegramId', telegramId, 'update'], + onSuccess: () => refetch(), + }); +};