2019-08-26 17:08:32 +00:00
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
import CardContent from "@material-ui/core/CardContent";
|
2019-10-28 16:16:49 +00:00
|
|
|
import makeStyles from "@material-ui/core/styles/makeStyles";
|
2019-08-26 17:08:32 +00:00
|
|
|
import TextField from "@material-ui/core/TextField";
|
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
2019-09-09 09:28:06 +00:00
|
|
|
import ControlledCheckbox from "@saleor/components/ControlledCheckbox";
|
2019-08-29 14:16:16 +00:00
|
|
|
import { FormErrors } from "@saleor/types";
|
2019-08-28 13:08:48 +00:00
|
|
|
import { ConfigurationTypeFieldEnum } from "@saleor/types/globalTypes";
|
2019-08-27 12:36:19 +00:00
|
|
|
import React from "react";
|
2019-08-30 13:10:07 +00:00
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
2019-11-07 15:54:05 +00:00
|
|
|
import { Plugin_plugin_configuration } from "@saleor/plugins/types/Plugin";
|
2019-08-26 17:08:32 +00:00
|
|
|
import { FormData } from "../PluginsDetailsPage";
|
|
|
|
|
|
|
|
interface PluginSettingsProps {
|
|
|
|
data: FormData;
|
2019-08-29 14:16:16 +00:00
|
|
|
errors: FormErrors<"name" | "configuration">;
|
2019-08-26 17:08:32 +00:00
|
|
|
disabled: boolean;
|
|
|
|
onChange: (event: React.ChangeEvent<any>) => void;
|
2019-11-07 15:54:05 +00:00
|
|
|
fields: Plugin_plugin_configuration[];
|
2019-08-26 17:08:32 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 15:54:05 +00:00
|
|
|
const useStyles = makeStyles(theme => ({
|
|
|
|
authItem: {
|
|
|
|
display: "flex"
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
marginRight: theme.spacing()
|
|
|
|
},
|
2019-08-27 12:36:19 +00:00
|
|
|
item: {
|
2019-11-07 15:54:05 +00:00
|
|
|
"&:not(:last-child)": {
|
|
|
|
marginBottom: theme.spacing(3)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
itemLabel: {
|
|
|
|
fontWeight: 500
|
|
|
|
},
|
|
|
|
spacer: {
|
|
|
|
flex: 1
|
2019-08-27 12:36:19 +00:00
|
|
|
}
|
2019-08-30 11:58:48 +00:00
|
|
|
}));
|
2019-08-26 17:08:32 +00:00
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const PluginSettings: React.FC<PluginSettingsProps> = ({
|
2019-08-30 11:58:48 +00:00
|
|
|
data,
|
|
|
|
disabled,
|
|
|
|
errors,
|
|
|
|
onChange,
|
2019-08-30 13:10:07 +00:00
|
|
|
fields
|
2019-08-30 11:58:48 +00:00
|
|
|
}) => {
|
|
|
|
const classes = useStyles({});
|
2019-08-30 13:10:07 +00:00
|
|
|
const intl = useIntl();
|
2019-11-07 15:54:05 +00:00
|
|
|
|
2019-08-30 11:58:48 +00:00
|
|
|
return (
|
|
|
|
<Card>
|
|
|
|
<CardTitle
|
2019-08-30 13:10:07 +00:00
|
|
|
title={intl.formatMessage({
|
|
|
|
defaultMessage: "Plugin Settings",
|
2019-08-30 14:15:32 +00:00
|
|
|
description: "section header"
|
2019-08-30 11:58:48 +00:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
<CardContent>
|
2019-11-07 15:54:05 +00:00
|
|
|
{data.configuration.map(field => {
|
|
|
|
const fieldData = fields.find(
|
|
|
|
configField => configField.name === field.name
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classes.item} key={field.name}>
|
|
|
|
{fieldData.type === ConfigurationTypeFieldEnum.BOOLEAN ? (
|
|
|
|
<ControlledCheckbox
|
|
|
|
name={field.name}
|
|
|
|
label={fieldData.label}
|
|
|
|
checked={
|
|
|
|
typeof field.value !== "boolean"
|
|
|
|
? field.value === "true"
|
|
|
|
: field.value
|
|
|
|
}
|
|
|
|
onChange={onChange}
|
|
|
|
disabled={disabled}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
|
|
|
error={!!errors.name}
|
|
|
|
helperText={fieldData.helpText}
|
|
|
|
label={fieldData.label}
|
|
|
|
name={field.name}
|
|
|
|
fullWidth
|
|
|
|
value={field.value}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
2019-08-30 11:58:48 +00:00
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
2019-08-26 17:08:32 +00:00
|
|
|
PluginSettings.displayName = "PluginSettings";
|
|
|
|
export default PluginSettings;
|