2019-08-26 17:08:32 +00:00
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
import CardContent from "@material-ui/core/CardContent";
|
2019-08-27 12:36:19 +00:00
|
|
|
import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
|
2019-08-26 17:08:32 +00:00
|
|
|
import TextField from "@material-ui/core/TextField";
|
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
2019-08-27 12:36:19 +00:00
|
|
|
import ControlledSwitch from "@saleor/components/ControlledSwitch";
|
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-26 17:08:32 +00:00
|
|
|
import i18n from "../../../i18n";
|
|
|
|
import { FormData } from "../PluginsDetailsPage";
|
|
|
|
|
|
|
|
interface PluginSettingsProps {
|
|
|
|
data: FormData;
|
|
|
|
errors: Partial<{
|
|
|
|
description: string;
|
|
|
|
domain: string;
|
|
|
|
name: string;
|
|
|
|
}>;
|
|
|
|
disabled: boolean;
|
|
|
|
onChange: (event: React.ChangeEvent<any>) => void;
|
|
|
|
}
|
|
|
|
|
2019-08-27 12:36:19 +00:00
|
|
|
const styles = createStyles({
|
|
|
|
item: {
|
2019-08-28 08:29:06 +00:00
|
|
|
paddingBottom: 10,
|
|
|
|
paddingTop: 10
|
2019-08-27 12:36:19 +00:00
|
|
|
}
|
|
|
|
});
|
2019-08-26 17:08:32 +00:00
|
|
|
|
|
|
|
const PluginSettings = withStyles(styles, { name: "PluginSettings" })(
|
|
|
|
({
|
|
|
|
data,
|
|
|
|
disabled,
|
|
|
|
classes,
|
|
|
|
errors,
|
|
|
|
onChange
|
2019-08-27 12:36:19 +00:00
|
|
|
}: PluginSettingsProps & WithStyles<typeof styles>) => {
|
|
|
|
return (
|
2019-08-26 17:08:32 +00:00
|
|
|
<Card>
|
|
|
|
<CardTitle
|
|
|
|
title={i18n.t("Plugin Settings", {
|
|
|
|
context: "plugin configuration"
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
<CardContent>
|
|
|
|
{data.configuration.map((configuration, index) => (
|
2019-08-27 12:36:19 +00:00
|
|
|
<div className={classes.item} key={index}>
|
2019-08-28 13:08:48 +00:00
|
|
|
{configuration.type === ConfigurationTypeFieldEnum.STRING && (
|
2019-08-26 17:08:32 +00:00
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
|
|
|
error={!!errors.name}
|
2019-08-28 13:11:01 +00:00
|
|
|
helperText={configuration.helpText}
|
2019-08-26 17:08:32 +00:00
|
|
|
label={configuration.label}
|
|
|
|
name={configuration.name}
|
|
|
|
fullWidth
|
|
|
|
value={configuration.value}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
)}
|
2019-08-28 13:08:48 +00:00
|
|
|
{configuration.type === ConfigurationTypeFieldEnum.BOOLEAN && (
|
2019-08-26 17:08:32 +00:00
|
|
|
<ControlledSwitch
|
2019-08-28 08:29:06 +00:00
|
|
|
checked={
|
|
|
|
typeof configuration.value !== "boolean"
|
|
|
|
? configuration.value === "true"
|
|
|
|
: configuration.value
|
|
|
|
}
|
2019-08-26 17:08:32 +00:00
|
|
|
label={configuration.label}
|
|
|
|
name={configuration.name}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
2019-08-27 12:36:19 +00:00
|
|
|
}
|
2019-08-26 17:08:32 +00:00
|
|
|
);
|
|
|
|
PluginSettings.displayName = "PluginSettings";
|
|
|
|
export default PluginSettings;
|