add hooks/profile

This commit is contained in:
vchikalkin 2025-02-08 20:48:13 +03:00
parent b94c898962
commit 5958fb443e
4 changed files with 19 additions and 22 deletions

View File

@ -2,17 +2,14 @@
import { type ProfileProps } from '../types';
import { CheckboxWithText, DataField, ProfileCardHeader } from './components';
import { updateRole } from './lib/actions';
import { getProfile, updateProfile } from '@/actions/profile';
import { updateProfile } from '@/actions/profile';
import { useProfile } from '@/hooks/profile';
import { Button } from '@repo/ui/components/ui/button';
import { Card } from '@repo/ui/components/ui/card';
import { useQuery } from '@tanstack/react-query';
import Link from 'next/link';
export function ContactDataCard({ telegramId }: Readonly<ProfileProps>) {
const { data: customer } = useQuery({
queryFn: () => getProfile({ telegramId }),
queryKey: ['profile', 'telegramId', telegramId],
});
const { data: customer } = useProfile({ telegramId });
if (!customer) return null;
@ -33,10 +30,7 @@ export function ContactDataCard({ telegramId }: Readonly<ProfileProps>) {
}
export function ProfileDataCard() {
const { data: customer } = useQuery({
queryFn: () => getProfile(),
queryKey: ['profile'],
});
const { data: customer } = useProfile({});
if (!customer) return null;

View File

@ -2,15 +2,11 @@
'use client';
import { type ProfileProps } from '../types';
import { LinkButton } from './components';
import { getProfile } from '@/actions/profile';
import { useProfile } from '@/hooks/profile';
import { Enum_Customer_Role } from '@repo/graphql/types';
import { useQuery } from '@tanstack/react-query';
export function LinksCard({ telegramId }: Readonly<ProfileProps>) {
const { data: customer } = useQuery({
queryFn: () => getProfile({ telegramId }),
queryKey: telegramId ? ['profile', 'telegramId', telegramId] : ['profile'],
});
const { data: customer } = useProfile({ telegramId });
const isMaster = customer?.role === Enum_Customer_Role.Master;

View File

@ -1,15 +1,11 @@
'use client';
import { type ProfileProps } from '../types';
import { getProfile } from '@/actions/profile';
import { useProfile } from '@/hooks/profile';
import { Avatar, AvatarFallback, AvatarImage } from '@repo/ui/components/ui/avatar';
import { Card } from '@repo/ui/components/ui/card';
import { useQuery } from '@tanstack/react-query';
export function PersonCard({ telegramId }: Readonly<ProfileProps>) {
const { data: customer } = useQuery({
queryFn: () => getProfile({ telegramId }),
queryKey: telegramId ? ['profile', 'telegramId', telegramId] : ['profile'],
});
const { data: customer } = useProfile({ telegramId });
if (!customer) return null;

View File

@ -0,0 +1,11 @@
'use client';
import { getProfile } from '@/actions/profile';
import { type ProfileProps } from '@/components/profile/types';
import { useQuery } from '@tanstack/react-query';
export const useProfile = ({ telegramId }: ProfileProps) => {
return useQuery({
queryFn: () => getProfile({ telegramId }),
queryKey: telegramId ? ['profile', 'telegramId', telegramId] : ['profile'],
});
};