при переходе на страницу личных данных пользователя идер рендер компонента
'use client'
import { zodResolver } from '@hookform/resolvers/zod'
import { useForm } from 'react-hook-form'
import {
Button,
Card,
CardContent,
CardHeader,
CardTitle,
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
Input
} from '@/shared/components/ui'
import { useUpdProfileMutation } from '../../hooks/useUpdProfileMutation'
import { PrivacySchema, TypePrivacySchema } from '../../schemes'
import { useSearchParams } from 'next/navigation'
import { useEffect } from 'react'
import { EnumTokens, saveTokenStorage } from '@/shared/services'
import { DateTimePicker } from '@/shared/components/datapicker/Datapicker'
import { useGetPrivacy } from '../../hooks'
import { useAppSelector } from '@/shared/hooks'
import { ImageUpload } from '../image-upload/ImageUpload'
import TextEditor from '@/shared/components/ui/TextEditor'
export function Privacy() {
const searchParams = useSearchParams()
useEffect(() => {
const accessToken = searchParams.get(EnumTokens.ACCESS_TOKEN)
if (accessToken) saveTokenStorage(accessToken)
}, [searchParams])
const { data: user, isLoading, error } = useAppSelector(state => state.reducer.user)
const { privacy, isFetching } = useGetPrivacy()
const form = useForm<TypePrivacySchema>({
resolver: zodResolver(PrivacySchema),
values: {
email: user?.email || '',
about_my: privacy?.about_my || ''
}
})
const { updProfile, isPending } = useUpdProfileMutation()
const onSubmit = (values: TypePrivacySchema) => {
updProfile(values)
}
return (
<Card className='md:w-[800px] w-full mx-5 md:mx-0'>
<CardHeader className='flex flex-row items-center justify-between'>
<CardTitle>Данные профиля</CardTitle>
</CardHeader>
<CardContent>
{<Form {...form}>
<form
onSubmit={form.handleSubmit(onSubmit)}
className='grid gap-2 space-y-2'
>
<FormField
control={form.control}
name='email'
render={({ field }) => (
<FormItem>
<FormLabel>Почта</FormLabel>
<FormControl>
<Input
placeholder='ivan@example.com'
disabled={isFetching}
type='email'
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name='about_my'
render={({ field }) => (
<FormItem>
<FormLabel>About my</FormLabel>
<FormControl>
<TextEditor description={field.value} onChange={field.onChange} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button type='submit' disabled={isFetching}>
Salva
</Button>
</form>
</Form>
}
</CardContent>
</Card>
)
}
где загружаются данные из хука const { privacy, isFetching } = useGetPrivacy()
но при переходе на страницу резюме (где пользователь создает свое резюме) мне снова нужно получить личные данные пользователя используя хук const { privacy, isFetching } = useGetPrivacy()
import { Card, CardContent } from "@/shared/components";
import Image from 'next/image'
import { formatDate } from "@/shared/utils"
import styles from './previews.module.scss'
import { useGetPrivacy, useEducation, useExperience, useSkills, useLanguages, useHobbies } from "@/features/candidat/hooks";
import { useCourses } from "@/features/candidat/hooks/useCourses";
import { useGetLifeStatus } from "@/features/candidat/hooks/useLifeStatus"
export function PreviewsPortfolio() {
const { privacy, isFetching: IFPrivacy } = useGetPrivacy()
const { education } = useEducation()
const { courses } = useCourses()
const { experience } = useExperience()
const { skills } = useSkills()
const { languages } = useLanguages()
const { hobbies } = useHobbies()
const { lifestatus } = useGetLifeStatus()
return (
<Card>
<CardContent>
{formatDate(privacy!.birthday)}
{privacy?.firstname} {privacy?.surname}
{privacy?.phone}
{privacy?.resident}
<hr />
{privacy!.about_my && <span dangerouslySetInnerHTML={{ __html: privacy!.about_my }}></span>}
<div>
{education?.map(item => item.school)}
</div>
<div>
{experience?.map(item => item.contract)}
</div>
<div>
{courses?.map(item => item.course)}
</div>
<div>
{languages?.map(item => item.language)}
</div>
<div>
{skills?.map(item => item.skill)}
</div>
<div>
{hobbies?.map(item => item.hobbie)}
</div>
<div>
{lifestatus?.availabilityTransport && 'I have car'}
</div>
<div>{lifestatus?.maritalStatus}</div>
<div>{lifestatus?.driverCategory.map(patent => <span>{patent}</span>)}</div>
</CardContent>
</Card>
)
}
вопрос в том что на странице резюме хук useGetPrivacy() не исполняет queryFn
hook
import { useQuery } from "@tanstack/react-query";
import { userService } from "../services";
import { useMemo } from "react";
export function useGetPrivacy() {
const { data: privacy, isFetching } = useQuery({
queryKey: ['get candidat privacy'],
queryFn: () => userService.getPrivacy()
})
return useMemo(() => ({
privacy,
isFetching
}), [privacy, isFetching])
}
class UserService {
public async getPrivacy() {
const { data } = await axiosPrivate.get<IPrivacy>(API_URL.candidatProfile())
return data
}
}
export const userService = new UserService()