saleor-dashboard/src/plugins/components/PluginsDetailsPage/PluginsDetailsPage.tsx

130 lines
4.1 KiB
TypeScript
Raw Normal View History

2019-08-26 17:08:32 +00:00
import Typography from "@material-ui/core/Typography";
import AppHeader from "@saleor/components/AppHeader";
import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
import Container from "@saleor/components/Container";
import Form from "@saleor/components/Form";
import Grid from "@saleor/components/Grid";
import PageHeader from "@saleor/components/PageHeader";
import SaveButtonBar from "@saleor/components/SaveButtonBar";
2019-08-27 12:36:19 +00:00
import { maybe } from "@saleor/misc";
import { UserError } from "@saleor/types";
import React from "react";
2019-08-26 17:08:32 +00:00
import i18n from "../../../i18n";
import { Plugin_plugin } from "../../types/Plugin";
2019-08-26 17:08:32 +00:00
import PluginInfo from "../PluginInfo";
import PluginSettings from "../PluginSettings";
export interface FormData {
2019-08-27 12:36:19 +00:00
name?: string;
description?: string;
2019-08-26 17:08:32 +00:00
active: boolean;
2019-08-27 12:36:19 +00:00
configuration: Array<{
name: string;
value: string;
type: string;
helpText: string;
label: string;
}>;
2019-08-26 17:08:32 +00:00
}
2019-08-28 13:02:45 +00:00
export interface PluginsDetailsPageProps {
2019-08-26 17:08:32 +00:00
disabled: boolean;
errors: UserError[];
plugin: Plugin_plugin;
2019-08-26 17:08:32 +00:00
saveButtonBarState: ConfirmButtonTransitionState;
onBack: () => void;
onSubmit: (data: FormData) => void;
}
2019-08-28 13:02:45 +00:00
const PluginsDetailsPage: React.StatelessComponent<PluginsDetailsPageProps> = ({
2019-08-26 17:08:32 +00:00
disabled,
errors,
plugin,
saveButtonBarState,
onBack,
onSubmit
}) => {
const initialForm: FormData = {
active: maybe(() => plugin.active, false),
2019-08-27 12:36:19 +00:00
configuration: maybe(() => plugin.configuration, []),
description: maybe(() => plugin.description, ""),
name: maybe(() => plugin.name, "")
2019-08-26 17:08:32 +00:00
};
2019-08-28 08:29:06 +00:00
2019-08-26 17:08:32 +00:00
return (
<Form errors={errors} initial={initialForm} onSubmit={onSubmit}>
2019-08-27 12:36:19 +00:00
{({ data, errors, hasChanged, submit, set, triggerChange }) => {
2019-08-26 17:08:32 +00:00
const onChange = event => {
const newData = {
active: data.active,
configuration: data.configuration
};
2019-08-26 17:08:32 +00:00
const { name, value } = event.target;
name === "active"
? (newData.active = value)
: (newData.active = data.active);
if (newData.configuration) {
2019-08-29 11:23:23 +00:00
newData.configuration.map(item => {
if (item.name === name) {
item.value = value;
}
});
}
2019-08-26 17:08:32 +00:00
triggerChange();
set(newData);
};
return (
<Container>
<AppHeader onBack={onBack}>{i18n.t("Plugins")}</AppHeader>
<PageHeader
title={`${maybe(() => plugin.name, "")} ${i18n.t("Details")}`}
/>
<Grid variant="inverted">
<div>
<Typography variant="h6">
{i18n.t("Plugin Information and Status")}
</Typography>
<Typography>
{i18n.t(
"These are general information about your store. They define what is the URL of your store and what is shown in brow sers taskbar."
)}
</Typography>
</div>
2019-08-27 12:36:19 +00:00
<PluginInfo data={data} onChange={onChange} />
2019-08-26 17:08:32 +00:00
{data.configuration && (
<>
<div>
<Typography variant="h6">
{i18n.t("Plugin Settings")}
</Typography>
<Typography>
{i18n.t(
"This adress will be used to generate invoices and calculate shipping rates. Email adress you provide here will be used as a contact adress for your customers."
)}
</Typography>
</div>
<PluginSettings
data={data}
errors={errors}
disabled={disabled}
onChange={onChange}
/>
</>
)}
</Grid>
<SaveButtonBar
disabled={disabled || !hasChanged}
state={saveButtonBarState}
onCancel={onBack}
onSave={submit}
/>
</Container>
);
}}
</Form>
);
};
2019-08-28 13:02:45 +00:00
PluginsDetailsPage.displayName = "PluginsDetailsPage";
export default PluginsDetailsPage;