diff --git a/apps/web/actions/profile.ts b/apps/web/actions/profile.ts index dd59307..07e9c09 100644 --- a/apps/web/actions/profile.ts +++ b/apps/web/actions/profile.ts @@ -1,7 +1,8 @@ +/* eslint-disable canonical/id-match */ '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 { type CustomerInput, Enum_Customer_Role } from '@repo/graphql/types'; import { getServerSession } from 'next-auth/next'; import { revalidatePath } from 'next/cache'; @@ -36,21 +37,8 @@ export async function updateProfile(input: CustomerInput) { revalidatePath('/profile'); } -export async function updateRole(role: Enum_Customer_Role) { - const session = await getServerSession(authOptions); - - if (session) { - const { user } = session; - const customer = await getCustomer({ telegramId: user?.telegramId }); - if (customer) { - await updateCustomerProfile({ - data: { - role, - }, - documentId: customer.documentId, - }); - } - } - - revalidatePath('/profile'); +export async function updateRole(checked: boolean) { + return updateProfile({ + role: checked ? Enum_Customer_Role.Master : Enum_Customer_Role.Client, + }); } diff --git a/apps/web/components/profile/checkbox-with-text.tsx b/apps/web/components/profile/checkbox-with-text.tsx index 91ac194..522301b 100644 --- a/apps/web/components/profile/checkbox-with-text.tsx +++ b/apps/web/components/profile/checkbox-with-text.tsx @@ -1,14 +1,12 @@ -/* eslint-disable canonical/id-match */ /* eslint-disable promise/prefer-await-to-then */ 'use client'; -import { Enum_Customer_Role } from '@repo/graphql/types'; import { Checkbox, type CheckboxProps } from '@repo/ui/components/ui/checkbox'; import { useState } from 'react'; import { useDebouncedCallback } from 'use-debounce'; type Props = Pick & { readonly description?: string; - readonly onChange?: (value: Enum_Customer_Role) => Promise | void; + readonly onChange?: (value: boolean) => Promise | void; readonly text: string; }; @@ -39,7 +37,7 @@ export function CheckboxWithText({ checked: initialValue, description, onChange, } function useDebouncedOnChangeCallback( - callback: ((value: Enum_Customer_Role) => Promise | void) | undefined, + callback: ((value: boolean) => Promise | void) | undefined, ) { const [isPending, setIsPending] = useState(false); @@ -47,7 +45,7 @@ function useDebouncedOnChangeCallback( if (!callback) return; setIsPending(true); - const result = callback(checked ? Enum_Customer_Role.Master : Enum_Customer_Role.Client); + const result = callback(checked); if (result instanceof Promise) { result.finally(() => setIsPending(false));