first
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { Dialog, DialogContent, DialogDescription } from '@/components/ui/dialog';
|
||||
import { DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Ban } from 'lucide-react';
|
||||
import type { ErrorDialogsProps } from './index';
|
||||
|
||||
export const CustomErrorDialog = ({ apiError, setApiError }: ErrorDialogsProps) => {
|
||||
const onOpenChange = (value: boolean) => {
|
||||
if (!value) {
|
||||
setApiError(null);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Dialog open={true} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-10">
|
||||
<Ban className="h-12 w-12 text-red-500" />
|
||||
Server Error
|
||||
</DialogTitle>
|
||||
<DialogDescription className="flex flex-col gap-4 py-5">{apiError?.uuid}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<p>{apiError?.message}</p>
|
||||
<DialogFooter>
|
||||
<Button type="submit" onClick={() => onOpenChange(false)}>
|
||||
Ok
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Dialog, DialogContent, DialogDescription } from '@/components/ui/dialog';
|
||||
import { DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Ban } from 'lucide-react';
|
||||
import type { ErrorDialogsProps } from './index';
|
||||
|
||||
export const ForbiddenDialog = ({ setApiError }: ErrorDialogsProps) => {
|
||||
const onOpenChange = (value: boolean) => {
|
||||
if (!value) {
|
||||
setApiError(null);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Dialog open={true} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-10">
|
||||
<Ban className="h-12 w-12 text-red-500" />
|
||||
Unauthorized Access
|
||||
</DialogTitle>
|
||||
<DialogDescription className="flex flex-col gap-4 py-5">
|
||||
Your are not authorized to perform this action.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<p>If you think this is an error, please contact your manager.</p>
|
||||
<DialogFooter>
|
||||
<Button type="submit" onClick={() => onOpenChange(false)}>
|
||||
Ok
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Dialog, DialogContent, DialogDescription } from '@/components/ui/dialog';
|
||||
import { DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Ban } from 'lucide-react';
|
||||
import type { ErrorDialogsProps } from './index';
|
||||
|
||||
export const ServerErrorDialog = ({ apiError, setApiError }: ErrorDialogsProps) => {
|
||||
const onOpenChange = (value: boolean) => {
|
||||
if (!value) {
|
||||
setApiError(null);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Dialog open={true} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-10">
|
||||
<Ban className="h-12 w-12 text-red-500" />
|
||||
Server Error
|
||||
</DialogTitle>
|
||||
<DialogDescription className="flex flex-col gap-4 py-5">{apiError?.uuid}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<p>{apiError?.message}</p>
|
||||
<DialogFooter>
|
||||
<Button type="submit" onClick={() => onOpenChange(false)}>
|
||||
Ok
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Dialog, DialogContent, DialogDescription } from '@/components/ui/dialog';
|
||||
import { DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Ban } from 'lucide-react';
|
||||
import { useAuth } from 'hooks/useAuth';
|
||||
import type { ErrorDialogsProps } from './index';
|
||||
|
||||
export const UnauthorizedDialog = ({ setApiError }: ErrorDialogsProps) => {
|
||||
const { signout } = useAuth();
|
||||
const onOpenChange = (value: boolean) => {
|
||||
if (!value) {
|
||||
setApiError(null);
|
||||
signout();
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Dialog open={true} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-10">
|
||||
<Ban className="h-12 w-12 text-red-500" />
|
||||
Invalid Credentials
|
||||
</DialogTitle>
|
||||
<DialogDescription className="flex flex-col gap-4 py-5">Your access token has expired</DialogDescription>
|
||||
</DialogHeader>
|
||||
<p>Please Signin again</p>
|
||||
<DialogFooter>
|
||||
<Button type="submit" onClick={() => onOpenChange(false)}>
|
||||
Ok
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
import { ForbiddenDialog } from './ForbiddenDialog';
|
||||
import { UnauthorizedDialog } from './UnauthorizedDialog';
|
||||
import { ServerErrorDialog } from './ServerError';
|
||||
import { CustomErrorDialog } from './CustomError';
|
||||
|
||||
export type ApiError = {
|
||||
status: number;
|
||||
message?: string;
|
||||
uuid?: string;
|
||||
};
|
||||
|
||||
export type ErrorDialogsProps = {
|
||||
apiError: ApiError | null;
|
||||
setApiError: (error: ApiError | null) => void;
|
||||
};
|
||||
|
||||
export const ErrorDialogs = ({ apiError, setApiError }: ErrorDialogsProps) => {
|
||||
if (window.location.pathname.startsWith('/auth')) return null;
|
||||
if (!apiError) return null;
|
||||
|
||||
const { status } = apiError;
|
||||
|
||||
return (
|
||||
<>
|
||||
{status === 401 && <UnauthorizedDialog apiError={apiError} setApiError={setApiError} />}
|
||||
{status === 403 && <ForbiddenDialog apiError={apiError} setApiError={setApiError} />}
|
||||
{status >= 500 && status < 511 && <ServerErrorDialog apiError={apiError} setApiError={setApiError} />}
|
||||
{status >= 511 && <CustomErrorDialog apiError={apiError} setApiError={setApiError} />}
|
||||
</>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user