/******************************************************************************** * Copyright (c) 2020 TypeFox and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import { FunctionComponent, ReactNode, useEffect } from 'react'; import { Dialog, DialogTitle, DialogContent, Button, DialogContentText, DialogActions, Box, Link } from '@mui/material'; import { styled, Theme } from '@mui/material/styles'; const ErrorLink = styled(Link)(({ theme }: { theme: Theme }) => ({ textDecoration: 'underline', color: theme.palette.primary.main })); export const ErrorDialog: FunctionComponent = props => { useEffect(() => { document.addEventListener('keydown', handleEnter); return () => document.removeEventListener('keydown', handleEnter); }, []); const handleEnter = (event: KeyboardEvent): void => { if (event.code === 'Enter') { props.handleCloseDialog(); } }; const getContentForCode = (): ReactNode => { if (!props.errorCode) { return null; } switch (props.errorCode) { case 'eclipse-missing-github-id': return <> Please fill in the “GitHub Username” field in your Eclipse account and try again. ; case 'eclipse-mismatch-github-id': return <> Please edit the “GitHub Username” field in your Eclipse account or log in with a different GitHub account. ; case 'publisher-agreement-problem': return <> Please contact webmaster@eclipse.org if this problem persists. ; default: return null; } }; const codeContent = getContentForCode(); return Error theme.palette.error.main }}> {props.errorMessage} { codeContent ? {codeContent} : null } ; }; export interface ErrorDialogProps { errorMessage: string; errorCode?: number | string; isErrorDialogOpen: boolean; handleCloseDialog: () => void; }