import React, { FC, ReactNode } from 'react';
import { Button, Result } from 'antd';

type WithErrorProps = {
    children?: ReactNode;
    errorData?: any;
    refresh?: () => void;
};

export const WithError: FC<WithErrorProps> = ({
    children,
    errorData,
    refresh
}) => {
    if (errorData) {
        return (
            <Result
                status="error"
                title="Submission Failed"
                subTitle="Please check and modify the following information before resubmitting."
                extra={refresh ? (
                    <Button type="primary" onClick={refresh}>
                        Refresh page
                    </Button>
                ) : undefined}
            />
        );
    }

    return children;
};
