2025-01-29 17:14:10 +03:00

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