-
Notifications
You must be signed in to change notification settings - Fork 658
Expand file tree
/
Copy pathElementInputs.tsx
More file actions
45 lines (42 loc) · 1.73 KB
/
ElementInputs.tsx
File metadata and controls
45 lines (42 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React from "react";
import { Button, useDialogs } from "webiny/admin/ui";
import { ElementInputs } from "webiny/admin/website-builder/page/editor";
import { useElementInputs } from "webiny/admin/website-builder/page/editor";
import { useComponent } from "webiny/admin/website-builder/page/editor";
export const ElementInputsDecorator = ElementInputs.createDecorator(Original => {
return function FunnelElementSettings(props) {
const { element } = props;
const { inputs, updateInputs } = useElementInputs(element.id);
const component = useComponent(element.component.name);
const dialogs = useDialogs();
const handleClick = () => {
dialogs.showDialog({
formData: inputs.registry,
title: `Edit ${component.label} Settings`,
content: <pre>{JSON.stringify(inputs, null, 2)}</pre>,
acceptLabel: "Save Field Settings",
cancelLabel: "Cancel",
onAccept: (data: any) => {
console.log(data);
updateInputs(inputs => {
Object.assign(inputs.registry, data);
});
}
});
};
if (props.element.component.name.startsWith("FunnelBuilder/")) {
return (
<>
<Button
variant={"primary"}
text={`Edit ${component.label} Settings`}
className={"w-full"}
onClick={handleClick}
/>
<pre>{JSON.stringify(element, null, 2)}</pre>
</>
);
}
return <Original {...props} />;
};
});