62 lines
2.3 KiB
TypeScript
Raw Normal View History

2020-12-27 16:37:10 -08:00
import React from "react";
2021-01-27 17:27:19 -08:00
import { Button, DialogContentText } from "@material-ui/core";
import { FormattedMessage, useIntl } from "react-intl";
2021-01-13 19:46:45 -08:00
import { ErrorInfo } from "../../../../services/Service";
2021-01-25 10:39:53 -08:00
import { StyledDialog, StyledDialogActions, StyledDialogContent, StyledDialogTitle } from "./style";
2021-01-13 19:46:45 -08:00
import GlobalError from "../../../form/global-error";
2020-12-27 16:37:10 -08:00
export type DialogProps = {
onClose: () => void;
2021-01-14 01:14:07 -08:00
onSubmit?: (event: React.FormEvent<HTMLFormElement>) => void;
2020-12-27 16:37:10 -08:00
open: boolean;
children: any;
error?: ErrorInfo;
2020-12-27 18:18:57 -08:00
2021-01-27 17:27:19 -08:00
title: string;
description?: string;
submitButton?: string;
2020-12-27 16:37:10 -08:00
}
2021-01-13 19:46:45 -08:00
const BaseDialog = (props: DialogProps) => {
2020-12-27 16:37:10 -08:00
const intl = useIntl();
const handleOnClose = props.onClose;
const isOpen = props.open;
const handleOnSubmit = props.onSubmit;
2021-01-27 17:27:19 -08:00
const description = props.description ? (<DialogContentText>{props.description}</DialogContentText>) : null;
2020-12-27 18:18:57 -08:00
2020-12-27 16:37:10 -08:00
return (
<div>
2021-01-13 19:46:45 -08:00
<StyledDialog
2020-12-27 16:37:10 -08:00
open={isOpen}
2021-01-13 19:46:45 -08:00
onClose={handleOnClose}
maxWidth="sm"
fullWidth={true}>
2020-12-27 16:37:10 -08:00
<form autoComplete="off" onSubmit={handleOnSubmit}>
2021-01-13 19:46:45 -08:00
<StyledDialogTitle>
2021-01-27 17:27:19 -08:00
{props.title}
2021-01-13 19:46:45 -08:00
</StyledDialogTitle>
2020-12-27 16:37:10 -08:00
2021-01-13 19:46:45 -08:00
<StyledDialogContent>
2020-12-27 18:18:57 -08:00
{description}
2020-12-27 16:37:10 -08:00
<GlobalError error={props.error} />
{props.children}
2021-01-13 19:46:45 -08:00
</StyledDialogContent>
2020-12-27 16:37:10 -08:00
2021-01-13 19:46:45 -08:00
<StyledDialogActions>
2021-01-25 10:39:53 -08:00
<Button color="primary" size="medium" onClick={handleOnClose} >
{handleOnSubmit ? (<FormattedMessage id="action.cancel-button" defaultMessage="Cancel" />) : (<FormattedMessage id="action.close-button" defaultMessage="Close" />)}
</Button>
2021-01-14 01:14:07 -08:00
{handleOnSubmit ? (
2021-01-25 10:39:53 -08:00
<Button color="primary" size="medium" variant="contained" type="submit" disableElevation={true}>
2021-01-27 17:27:19 -08:00
{props.title}
2021-01-25 10:39:53 -08:00
</Button>) : null
2021-01-14 01:14:07 -08:00
}
2021-01-13 19:46:45 -08:00
</StyledDialogActions>
2020-12-27 16:37:10 -08:00
</form>
2021-01-13 19:46:45 -08:00
</StyledDialog>
2020-12-27 16:37:10 -08:00
</div>
);
}
2021-01-13 19:46:45 -08:00
export default BaseDialog;