feat(profile): enhance user role checks in subscription and links components
- Added conditional rendering in SubscriptionInfoBar and LinksCard to hide components for users with the Client role. - Updated ProfileDataCard to use Enum_Customer_Role for role management. - Improved error handling in OrdersService to differentiate between master and client order limit errors.
This commit is contained in:
parent
0b188ee5ed
commit
201ccaeea5
@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { BackButton } from './back-button';
|
||||
import { InvitedGrid, InvitedByGrid } from './contacts-grid';
|
||||
import { InvitedByGrid, InvitedGrid } from './contacts-grid';
|
||||
import { DateTimeSelect } from './datetime-select';
|
||||
import { NextButton } from './next-button';
|
||||
import { ErrorPage, SuccessPage } from './result';
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
/* eslint-disable canonical/id-match */
|
||||
'use client';
|
||||
|
||||
import { type ProfileProps } from '../types';
|
||||
import { TextField } from '@/components/shared/data-fields';
|
||||
import { CheckboxWithText, TextField } from '@/components/shared/data-fields';
|
||||
import { CardSectionHeader } from '@/components/ui';
|
||||
import { useCustomerMutation, useCustomerQuery } from '@/hooks/api/customers';
|
||||
import { Enum_Customer_Role } from '@repo/graphql/types';
|
||||
import { Button } from '@repo/ui/components/ui/button';
|
||||
import { Card } from '@repo/ui/components/ui/card';
|
||||
import Link from 'next/link';
|
||||
@ -49,14 +51,14 @@ export function ProfileDataCard() {
|
||||
value={customer?.name ?? ''}
|
||||
/>
|
||||
<TextField disabled id="phone" label="Телефон" readOnly value={customer?.phone ?? ''} />
|
||||
{/* <CheckboxWithText
|
||||
<CheckboxWithText
|
||||
checked={customer.role !== 'client'}
|
||||
description="Разрешить другим пользователям записываться к вам"
|
||||
onChange={(checked) =>
|
||||
updateField('role', checked ? Role.Master : Role.Client)
|
||||
updateField('role', checked ? Enum_Customer_Role.Master : Enum_Customer_Role.Client)
|
||||
}
|
||||
text="Быть мастером"
|
||||
/> */}
|
||||
/>
|
||||
{hasChanges && (
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button disabled={isPending} onClick={cancelChanges} variant="outline">
|
||||
|
||||
@ -1,8 +1,15 @@
|
||||
/* eslint-disable canonical/id-match */
|
||||
'use client';
|
||||
|
||||
import { LinkButton } from './link-button';
|
||||
import { useCustomerQuery } from '@/hooks/api/customers';
|
||||
import { Enum_Customer_Role } from '@repo/graphql/types';
|
||||
|
||||
export function LinksCard() {
|
||||
const { data: { customer } = {} } = useCustomerQuery();
|
||||
|
||||
if (customer?.role === Enum_Customer_Role.Client) return null;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 p-4 py-0">
|
||||
<LinkButton
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
/* eslint-disable canonical/id-match */
|
||||
'use client';
|
||||
|
||||
import { useCustomerQuery } from '@/hooks/api/customers';
|
||||
import { useSubscriptionQuery } from '@/hooks/api/subscriptions';
|
||||
import { Enum_Customer_Role } from '@repo/graphql/types';
|
||||
import { cn } from '@repo/ui/lib/utils';
|
||||
import { getRemainingDays } from '@repo/utils/datetime-format';
|
||||
import { ChevronRight } from 'lucide-react';
|
||||
@ -9,11 +12,15 @@ import Link from 'next/link';
|
||||
export function SubscriptionInfoBar() {
|
||||
const { data, error, isLoading } = useSubscriptionQuery();
|
||||
|
||||
const { data: { customer } = {} } = useCustomerQuery();
|
||||
|
||||
const isActive = data?.subscription?.isActive;
|
||||
const remainingOrdersCount = data?.remainingOrdersCount;
|
||||
const maxOrdersPerMonth = data?.maxOrdersPerMonth;
|
||||
const expiresAt = data?.subscription?.expiresAt;
|
||||
|
||||
if (customer?.role === Enum_Customer_Role.Client) return null;
|
||||
|
||||
if (error) return null;
|
||||
|
||||
const title = isActive ? 'Подписка Pro активна' : 'Подписка неактивна';
|
||||
|
||||
@ -70,9 +70,13 @@ export class OrdersService extends BaseService {
|
||||
slot.master,
|
||||
);
|
||||
|
||||
const isMasterCreating = slot.master.documentId === customer?.documentId;
|
||||
|
||||
// Если у мастера слота нет активной подписки и не осталось доступных заказов
|
||||
if (!subscription?.isActive && remainingOrdersCount <= 0) {
|
||||
throw new Error(ERRORS.ORDER_LIMIT_EXCEEDED_CLIENT);
|
||||
throw new Error(
|
||||
isMasterCreating ? ERRORS.ORDER_LIMIT_EXCEEDED_MASTER : ERRORS.ORDER_LIMIT_EXCEEDED_CLIENT,
|
||||
);
|
||||
}
|
||||
|
||||
const servicesService = new ServicesService(this._user);
|
||||
@ -278,7 +282,7 @@ export class OrdersService extends BaseService {
|
||||
// Получаем мастера слота
|
||||
const slotMaster = slot.master;
|
||||
if (!slotMaster) throw new Error(ERRORS.INVALID_MASTER);
|
||||
if (!slotMaster.active) {
|
||||
if (!slotMaster.active || slotMaster.role !== GQL.Enum_Customer_Role.Master) {
|
||||
throw new Error(ERRORS.INACTIVE_MASTER);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user