2019-08-26 17:08:32 +00:00
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
import CardContent from "@material-ui/core/CardContent";
|
|
|
|
import TextField from "@material-ui/core/TextField";
|
2019-08-30 11:58:48 +00:00
|
|
|
import makeStyles from "@material-ui/styles/makeStyles";
|
2019-08-26 17:08:32 +00:00
|
|
|
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-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-08-30 13:10:07 +00:00
|
|
|
fields: Array<{
|
2019-08-30 11:46:50 +00:00
|
|
|
name: string;
|
|
|
|
type: ConfigurationTypeFieldEnum | null;
|
|
|
|
value: string;
|
|
|
|
helpText: string | null;
|
|
|
|
label: string | null;
|
|
|
|
}>;
|
2019-08-26 17:08:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 11:58:48 +00:00
|
|
|
const useStyles = makeStyles(() => ({
|
2019-08-27 12:36:19 +00:00
|
|
|
item: {
|
2019-08-28 08:29:06 +00:00
|
|
|
paddingBottom: 10,
|
|
|
|
paddingTop: 10
|
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-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>
|
|
|
|
{data.configuration.map((configuration, index) => (
|
|
|
|
<div className={classes.item} key={index}>
|
2019-08-30 13:10:07 +00:00
|
|
|
{fields[index].type === ConfigurationTypeFieldEnum.STRING && (
|
2019-08-30 11:58:48 +00:00
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
|
|
|
error={!!errors.name}
|
2019-08-30 13:10:07 +00:00
|
|
|
helperText={fields[index].helpText}
|
|
|
|
label={fields[index].label}
|
2019-08-30 11:58:48 +00:00
|
|
|
name={configuration.name}
|
|
|
|
fullWidth
|
|
|
|
value={configuration.value}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
)}
|
2019-08-30 13:10:07 +00:00
|
|
|
{fields[index].type === ConfigurationTypeFieldEnum.BOOLEAN && (
|
2019-09-09 09:28:06 +00:00
|
|
|
<ControlledCheckbox
|
|
|
|
name={configuration.name}
|
|
|
|
label={fields[index].label}
|
2019-08-30 11:58:48 +00:00
|
|
|
checked={
|
|
|
|
typeof configuration.value !== "boolean"
|
|
|
|
? configuration.value === "true"
|
|
|
|
: configuration.value
|
|
|
|
}
|
|
|
|
onChange={onChange}
|
2019-09-09 09:28:06 +00:00
|
|
|
disabled={disabled}
|
2019-08-30 11:58:48 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
2019-08-26 17:08:32 +00:00
|
|
|
PluginSettings.displayName = "PluginSettings";
|
|
|
|
export default PluginSettings;
|