79 lines
2.7 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-02-01 22:15:32 -08:00
import { ErrorInfo } from "../../../../client";
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
children: any;
error?: ErrorInfo;
2020-12-27 18:18:57 -08:00
2021-01-27 17:27:19 -08:00
title: string;
description?: string;
2021-02-10 18:03:51 -08:00
2021-02-02 00:20:35 -08:00
submitButton?: string;
2021-02-10 18:03:51 -08:00
actionUrl?: 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();
2021-02-10 18:03:51 -08:00
const { onClose, onSubmit, actionUrl = "" } = props;
2021-02-02 00:20:35 -08:00
const handleOnSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (onSubmit) {
onSubmit(e);
}
}
2020-12-27 16:37:10 -08:00
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
2021-02-05 16:35:39 -08:00
open={true}
2021-02-08 11:30:32 -08:00
onClose={onClose}
2021-01-13 19:46:45 -08:00
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-02-02 00:20:35 -08:00
<Button
type="button"
color="primary"
size="medium"
2021-02-08 11:30:32 -08:00
onClick={onClose} >
2021-02-02 00:20:35 -08:00
{onSubmit ? (<FormattedMessage id="action.cancel-button" defaultMessage="Cancel" />) :
(<FormattedMessage id="action.close-button" defaultMessage="Close" />)
}
2021-01-25 10:39:53 -08:00
</Button>
2021-02-06 00:45:33 -08:00
{onSubmit &&
2021-02-02 00:20:35 -08:00
<Button
color="primary"
size="medium"
variant="contained"
type="submit"
disableElevation={true}>
2021-02-02 10:54:37 -08:00
{props.submitButton}
2021-02-06 00:45:33 -08:00
</Button>
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;