add action getProfile
This commit is contained in:
parent
af128f42c5
commit
0a7d9c75c0
@ -5,6 +5,20 @@ import { type CustomerInput, type Enum_Customer_Role } from '@repo/graphql/types
|
||||
import { getServerSession } from 'next-auth/next';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
|
||||
export async function getProfile() {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
if (session) {
|
||||
const { user } = session;
|
||||
const customer = await getCustomer({ telegramId: user?.telegramId });
|
||||
if (customer) {
|
||||
return customer;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function updateProfile(input: CustomerInput) {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
|
||||
@ -1,27 +1,23 @@
|
||||
import { updateProfile, updateRole } from '@/actions/profile';
|
||||
import { getProfile, updateProfile, updateRole } from '@/actions/profile';
|
||||
import { CheckboxWithText } from '@/components/profile/checkbox-with-text';
|
||||
import { ProfileField } from '@/components/profile/profile-field';
|
||||
import { authOptions } from '@/config/auth';
|
||||
import { getCustomer } from '@repo/graphql/api';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@repo/ui/components/ui/avatar';
|
||||
import { Card, CardContent, CardHeader } from '@repo/ui/components/ui/card';
|
||||
import { getServerSession } from 'next-auth/next';
|
||||
|
||||
export default async function ProfilePage() {
|
||||
const session = await getServerSession(authOptions);
|
||||
const user = await getCustomer({ telegramId: session?.user?.telegramId });
|
||||
const photoUrl = user?.photoUrl ?? 'https://github.com/shadcn.png';
|
||||
const customer = await getProfile();
|
||||
const photoUrl = customer?.photoUrl ?? 'https://github.com/shadcn.png';
|
||||
|
||||
if (!user) return 'Профиль не найден';
|
||||
if (!customer) return 'Пользователь не найден. Зарегистрируйтесь с помощью бота.';
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center space-x-4 pb-2">
|
||||
<Avatar className="size-12">
|
||||
<AvatarImage alt={user?.name} src={photoUrl} />
|
||||
<AvatarFallback>{user?.name.charAt(0)}</AvatarFallback>
|
||||
<AvatarImage alt={customer?.name} src={photoUrl} />
|
||||
<AvatarFallback>{customer?.name.charAt(0)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<h2 className="text-2xl font-bold">{user?.name}</h2>
|
||||
<h2 className="text-2xl font-bold">{customer?.name}</h2>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<ProfileField
|
||||
@ -29,11 +25,11 @@ export default async function ProfilePage() {
|
||||
id="name"
|
||||
label="Имя"
|
||||
onChange={updateProfile}
|
||||
value={user?.name ?? ''}
|
||||
value={customer?.name ?? ''}
|
||||
/>
|
||||
<ProfileField disabled id="phone" label="Телефон" value={user?.phone ?? ''} />
|
||||
<ProfileField disabled id="phone" label="Телефон" value={customer?.phone ?? ''} />
|
||||
<CheckboxWithText
|
||||
checked={user.role !== 'client'}
|
||||
checked={customer.role !== 'client'}
|
||||
description="Разрешить другим пользователям записываться к вам"
|
||||
onChange={updateRole}
|
||||
text="Быть мастером"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user