2020-04-17 21:43:03 +00:00
|
|
|
import PageContentBlock from '@/components/elements/PageContentBlock';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2020-07-04 22:40:41 +00:00
|
|
|
import { faArrowLeft, faSyncAlt } from '@fortawesome/free-solid-svg-icons';
|
2022-11-25 20:25:03 +00:00
|
|
|
import styled, { keyframes } from 'styled-components';
|
2020-07-03 21:19:05 +00:00
|
|
|
import tw from 'twin.macro';
|
2020-07-05 02:01:49 +00:00
|
|
|
import Button from '@/components/elements/Button';
|
2021-01-31 02:01:32 +00:00
|
|
|
import NotFoundSvg from '@/assets/images/not_found.svg';
|
|
|
|
import ServerErrorSvg from '@/assets/images/server_error.svg';
|
2020-04-17 21:43:03 +00:00
|
|
|
|
|
|
|
interface BaseProps {
|
|
|
|
title: string;
|
|
|
|
image: string;
|
|
|
|
message: string;
|
|
|
|
onRetry?: () => void;
|
|
|
|
onBack?: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface PropsWithRetry extends BaseProps {
|
|
|
|
onRetry?: () => void;
|
2021-01-31 02:01:32 +00:00
|
|
|
onBack?: never;
|
2020-04-17 21:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface PropsWithBack extends BaseProps {
|
|
|
|
onBack?: () => void;
|
2021-01-31 02:01:32 +00:00
|
|
|
onRetry?: never;
|
2020-04-17 21:43:03 +00:00
|
|
|
}
|
|
|
|
|
2021-01-31 02:01:32 +00:00
|
|
|
export type ScreenBlockProps = PropsWithBack | PropsWithRetry;
|
2020-04-17 21:43:03 +00:00
|
|
|
|
2020-07-04 22:40:41 +00:00
|
|
|
const spin = keyframes`
|
|
|
|
to { transform: rotate(360deg) }
|
|
|
|
`;
|
|
|
|
|
2020-07-05 02:01:49 +00:00
|
|
|
const ActionButton = styled(Button)`
|
2020-12-27 18:56:07 +00:00
|
|
|
${tw`rounded-full w-8 h-8 flex items-center justify-center p-0`};
|
2020-04-17 21:43:03 +00:00
|
|
|
|
|
|
|
&.hover\\:spin:hover {
|
2020-07-04 22:40:41 +00:00
|
|
|
animation: ${spin} 2s linear infinite;
|
2020-04-17 21:43:03 +00:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2021-01-31 02:01:32 +00:00
|
|
|
const ScreenBlock = ({ title, image, message, onBack, onRetry }: ScreenBlockProps) => (
|
2020-04-17 21:43:03 +00:00
|
|
|
<PageContentBlock>
|
2020-07-03 21:19:05 +00:00
|
|
|
<div css={tw`flex justify-center`}>
|
2022-06-26 19:13:52 +00:00
|
|
|
<div
|
|
|
|
css={tw`w-full sm:w-3/4 md:w-1/2 p-12 md:p-20 bg-neutral-100 rounded-lg shadow-lg text-center relative`}
|
|
|
|
>
|
|
|
|
{(typeof onBack === 'function' || typeof onRetry === 'function') && (
|
|
|
|
<div css={tw`absolute left-0 top-0 ml-4 mt-4`}>
|
|
|
|
<ActionButton
|
|
|
|
onClick={() => (onRetry ? onRetry() : onBack ? onBack() : null)}
|
|
|
|
className={onRetry ? 'hover:spin' : undefined}
|
|
|
|
>
|
|
|
|
<FontAwesomeIcon icon={onRetry ? faSyncAlt : faArrowLeft} />
|
|
|
|
</ActionButton>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<img src={image} css={tw`w-2/3 h-auto select-none mx-auto`} />
|
2020-08-23 02:01:29 +00:00
|
|
|
<h2 css={tw`mt-10 text-neutral-900 font-bold text-4xl`}>{title}</h2>
|
2022-06-26 19:13:52 +00:00
|
|
|
<p css={tw`text-sm text-neutral-700 mt-2`}>{message}</p>
|
2020-04-17 21:43:03 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</PageContentBlock>
|
|
|
|
);
|
2021-01-31 02:01:32 +00:00
|
|
|
|
|
|
|
type ServerErrorProps = (Omit<PropsWithBack, 'image' | 'title'> | Omit<PropsWithRetry, 'image' | 'title'>) & {
|
|
|
|
title?: string;
|
2022-06-26 19:13:52 +00:00
|
|
|
};
|
2021-01-31 02:01:32 +00:00
|
|
|
|
|
|
|
const ServerError = ({ title, ...props }: ServerErrorProps) => (
|
2022-06-26 19:13:52 +00:00
|
|
|
<ScreenBlock title={title || 'Something went wrong'} image={ServerErrorSvg} {...props} />
|
2021-01-31 02:01:32 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const NotFound = ({ title, message, onBack }: Partial<Pick<ScreenBlockProps, 'title' | 'message' | 'onBack'>>) => (
|
|
|
|
<ScreenBlock
|
|
|
|
title={title || '404'}
|
|
|
|
image={NotFoundSvg}
|
|
|
|
message={message || 'The requested resource was not found.'}
|
|
|
|
onBack={onBack}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
export { ServerError, NotFound };
|
|
|
|
export default ScreenBlock;
|