Vlad Chikalkin b936a79c2b
feature/profile-page (#8)
* add basic profile page

* apps/web: detect telegram/browser
support browser (dev only)

* apps/web: add dark mode

* apps/web: support dark theme in tma

* apps/web: add loading spinner
remove dev info from page

* apps\web\app\(auth)\page.tsx: remove useState

* app/web: handle update profile name

* move debounce functional to hook

* add role checkbox
2025-01-10 11:51:14 +03:00

45 lines
1.3 KiB
TypeScript

'use server';
import { authOptions } from '@/config/auth';
import { getCustomer, updateCustomerProfile } from '@repo/graphql/api';
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 updateProfile(input: CustomerInput) {
const session = await getServerSession(authOptions);
if (session) {
const { user } = session;
const getCustomerResponse = await getCustomer({ telegramId: user?.telegramId });
const customer = getCustomerResponse.data.customers.at(0);
if (customer) {
await updateCustomerProfile({
data: input,
documentId: customer.documentId,
});
}
}
revalidatePath('/profile');
}
export async function updateRole(role: Enum_Customer_Role) {
const session = await getServerSession(authOptions);
if (session) {
const { user } = session;
const getCustomerResponse = await getCustomer({ telegramId: user?.telegramId });
const customer = getCustomerResponse.data.customers.at(0);
if (customer) {
await updateCustomerProfile({
data: {
role,
},
documentId: customer.documentId,
});
}
}
revalidatePath('/profile');
}