2025-01-29 17:31:42 +03:00

65 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import { type ProfileProps } from '../types';
import { CheckboxWithText, DataField, ProfileCardHeader } from './components';
import { updateRole } from './lib/actions';
import { getProfile, updateProfile } from '@/actions/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],
});
if (!customer) return null;
return (
<Card className="p-4">
<div className="flex flex-col gap-4">
<Link href={customer?.phone ? `tel:${customer?.phone}` : ''}>
<DataField id="phone" label="Телефон" readOnly value={customer?.phone ?? ''} />
</Link>
<Button asChild className="w-full bg-foreground">
<Link href={`https://t.me/${customer?.phone}`} rel="noopener noreferrer" target="_blank">
Написать в Telegram
</Link>
</Button>
</div>
</Card>
);
}
export function ProfileDataCard() {
const { data: customer } = useQuery({
queryFn: () => getProfile(),
queryKey: ['profile'],
});
if (!customer) return null;
return (
<Card className="p-4">
<div className="flex flex-col gap-4">
<ProfileCardHeader title="Ваши данные" />
<DataField
fieldName="name"
id="name"
label="Имя"
onChange={updateProfile}
value={customer?.name ?? ''}
/>
<DataField disabled id="phone" label="Телефон" readOnly value={customer?.phone ?? ''} />
<CheckboxWithText
checked={customer.role !== 'client'}
description="Разрешить другим пользователям записываться к вам"
onChange={updateRole}
text="Быть мастером"
/>
</div>
</Card>
);
}