- Added `isCustomerBanned` function to determine if a customer is banned based on the `bannedUntil` field. - Updated the `BaseService` to throw an error if a banned customer attempts to access certain functionalities. - Enhanced the GraphQL operations to include the `bannedUntil` field in customer queries and mutations, improving data integrity and user experience. - Integrated the `CheckBanned` component in the layout to manage banned customer states effectively.
21 lines
509 B
TypeScript
21 lines
509 B
TypeScript
/* eslint-disable sonarjs/function-return-type */
|
|
'use client';
|
|
|
|
import { useIsBanned } from '@/hooks/api/customers';
|
|
import { redirect, RedirectType } from 'next/navigation';
|
|
import { type PropsWithChildren, useEffect } from 'react';
|
|
|
|
export function CheckBanned({ children }: Readonly<PropsWithChildren>) {
|
|
const isBanned = useIsBanned();
|
|
|
|
useEffect(() => {
|
|
if (isBanned) {
|
|
redirect('/banned', RedirectType.replace);
|
|
}
|
|
}, [isBanned]);
|
|
|
|
if (isBanned) return null;
|
|
|
|
return children;
|
|
}
|