2019-06-19 14:40:52 +00:00
|
|
|
|
import Button from "@material-ui/core/Button";
|
|
|
|
|
import Dialog from "@material-ui/core/Dialog";
|
|
|
|
|
import DialogActions from "@material-ui/core/DialogActions";
|
|
|
|
|
import DialogContent from "@material-ui/core/DialogContent";
|
|
|
|
|
import DialogTitle from "@material-ui/core/DialogTitle";
|
|
|
|
|
import {
|
|
|
|
|
createStyles,
|
|
|
|
|
Theme,
|
|
|
|
|
withStyles,
|
|
|
|
|
WithStyles
|
|
|
|
|
} from "@material-ui/core/styles";
|
|
|
|
|
import TextField from "@material-ui/core/TextField";
|
|
|
|
|
import Typography from "@material-ui/core/Typography";
|
2019-08-09 10:26:22 +00:00
|
|
|
|
import React from "react";
|
2019-08-26 21:43:29 +00:00
|
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
|
|
import ConfirmButton, {
|
|
|
|
|
ConfirmButtonTransitionState
|
|
|
|
|
} from "@saleor/components/ConfirmButton";
|
|
|
|
|
import { ControlledCheckbox } from "@saleor/components/ControlledCheckbox";
|
|
|
|
|
import Form from "@saleor/components/Form";
|
|
|
|
|
import FormSpacer from "@saleor/components/FormSpacer";
|
2019-08-26 21:43:29 +00:00
|
|
|
|
import { buttonMessages, commonMessages } from "@saleor/intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
import { UserError } from "../../../types";
|
|
|
|
|
|
|
|
|
|
export interface FormData {
|
|
|
|
|
email: string;
|
|
|
|
|
firstName: string;
|
|
|
|
|
fullAccess: boolean;
|
|
|
|
|
lastName: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const initialForm: FormData = {
|
|
|
|
|
email: "",
|
|
|
|
|
firstName: "",
|
|
|
|
|
fullAccess: false,
|
|
|
|
|
lastName: ""
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const styles = (theme: Theme) =>
|
|
|
|
|
createStyles({
|
|
|
|
|
hr: {
|
|
|
|
|
backgroundColor: "#eaeaea",
|
|
|
|
|
border: "none",
|
|
|
|
|
height: 1,
|
|
|
|
|
marginBottom: 0
|
|
|
|
|
},
|
|
|
|
|
sectionTitle: {
|
|
|
|
|
fontWeight: 600 as 600,
|
|
|
|
|
marginBottom: theme.spacing.unit,
|
|
|
|
|
marginTop: theme.spacing.unit * 2
|
|
|
|
|
},
|
|
|
|
|
textFieldGrid: {
|
|
|
|
|
display: "grid",
|
|
|
|
|
gridColumnGap: `${theme.spacing.unit * 2}px`,
|
|
|
|
|
gridTemplateColumns: "1fr 1fr"
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
interface StaffAddMemberDialogProps extends WithStyles<typeof styles> {
|
|
|
|
|
confirmButtonState: ConfirmButtonTransitionState;
|
|
|
|
|
errors: UserError[];
|
|
|
|
|
open: boolean;
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
onConfirm: (data: FormData) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const StaffAddMemberDialog = withStyles(styles, {
|
|
|
|
|
name: "StaffAddMemberDialog"
|
|
|
|
|
})(
|
|
|
|
|
({
|
|
|
|
|
classes,
|
|
|
|
|
confirmButtonState,
|
|
|
|
|
errors,
|
|
|
|
|
open,
|
|
|
|
|
onClose,
|
|
|
|
|
onConfirm
|
2019-08-26 21:43:29 +00:00
|
|
|
|
}: StaffAddMemberDialogProps) => {
|
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dialog onClose={onClose} open={open}>
|
|
|
|
|
<Form errors={errors} initial={initialForm} onSubmit={onConfirm}>
|
|
|
|
|
{({ change, data, errors: formErrors, hasChanged }) => (
|
|
|
|
|
<>
|
|
|
|
|
<DialogTitle>
|
|
|
|
|
<FormattedMessage
|
|
|
|
|
defaultMessage="Add Staff Member"
|
|
|
|
|
description="dialog header"
|
|
|
|
|
/>
|
|
|
|
|
</DialogTitle>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<div className={classes.textFieldGrid}>
|
|
|
|
|
<TextField
|
|
|
|
|
error={!!formErrors.firstName}
|
|
|
|
|
helperText={formErrors.firstName}
|
|
|
|
|
label={intl.formatMessage(commonMessages.firstName)}
|
|
|
|
|
name="firstName"
|
|
|
|
|
type="text"
|
|
|
|
|
value={data.firstName}
|
|
|
|
|
onChange={change}
|
|
|
|
|
/>
|
|
|
|
|
<TextField
|
|
|
|
|
error={!!formErrors.lastName}
|
|
|
|
|
helperText={formErrors.lastName}
|
|
|
|
|
label={intl.formatMessage(commonMessages.lastName)}
|
|
|
|
|
name="lastName"
|
|
|
|
|
type="text"
|
|
|
|
|
value={data.lastName}
|
|
|
|
|
onChange={change}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<FormSpacer />
|
2019-06-19 14:40:52 +00:00
|
|
|
|
<TextField
|
2019-08-26 21:43:29 +00:00
|
|
|
|
error={!!formErrors.email}
|
|
|
|
|
fullWidth
|
|
|
|
|
helperText={formErrors.email}
|
|
|
|
|
label={intl.formatMessage(commonMessages.email)}
|
|
|
|
|
name="email"
|
|
|
|
|
type="email"
|
|
|
|
|
value={data.email}
|
2019-06-19 14:40:52 +00:00
|
|
|
|
onChange={change}
|
|
|
|
|
/>
|
2019-08-26 21:43:29 +00:00
|
|
|
|
</DialogContent>
|
|
|
|
|
<hr className={classes.hr} />
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<Typography className={classes.sectionTitle}>
|
|
|
|
|
<FormattedMessage defaultMessage="Permissions" />
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography>
|
|
|
|
|
<FormattedMessage defaultMessage="Expand or restrict user’s permissions to access certain part of saleor system." />
|
|
|
|
|
</Typography>
|
|
|
|
|
<ControlledCheckbox
|
|
|
|
|
checked={data.fullAccess}
|
|
|
|
|
label={intl.formatMessage({
|
|
|
|
|
defaultMessage: "User has full access"
|
|
|
|
|
})}
|
|
|
|
|
name="fullAccess"
|
2019-06-19 14:40:52 +00:00
|
|
|
|
onChange={change}
|
|
|
|
|
/>
|
2019-08-26 21:43:29 +00:00
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<Button onClick={onClose}>
|
|
|
|
|
<FormattedMessage {...buttonMessages.cancel} />
|
|
|
|
|
</Button>
|
|
|
|
|
<ConfirmButton
|
|
|
|
|
color="primary"
|
|
|
|
|
disabled={!hasChanged}
|
|
|
|
|
variant="contained"
|
|
|
|
|
type="submit"
|
|
|
|
|
transitionState={confirmButtonState}
|
|
|
|
|
>
|
|
|
|
|
<FormattedMessage
|
|
|
|
|
defaultMessage="Send invite"
|
|
|
|
|
description="button"
|
|
|
|
|
/>
|
|
|
|
|
</ConfirmButton>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Form>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
|
);
|
|
|
|
|
StaffAddMemberDialog.displayName = "StaffAddMemberDialog";
|
|
|
|
|
export default StaffAddMemberDialog;
|