From 6267b412facc362e3b168882e622657a4a265ee8 Mon Sep 17 00:00:00 2001 From: stCarolas Date: Thu, 16 May 2024 19:34:44 +0300 Subject: [PATCH] refactor custom properties --- .../ConfigurationPage/css/WidgetList.css | 1 + .../ConfigurationPage/css/WidgetSettings.css | 3 +- .../settings/BaseSettings.tsx | 7 -- .../settings/DonatersTopListSettings.tsx | 44 --------- .../DonatersTopListLayoutProperty.tsx | 60 ++++++++++++ .../DonationGoalProperty.module.css | 5 + .../widgetproperties/DonationGoalProperty.tsx | 21 +++- .../ReelItemBackgroundProperty.module.css | 16 ++++ .../ReelItemBackgroundProperty.tsx | 70 ++++++++++++++ .../ReelItemListProperty.module.css | 50 ++++++++++ .../widgetproperties/ReelItemListProperty.tsx | 74 +++++++++++++++ .../widgetsettings/AbstractWidgetSettings.tsx | 7 +- .../DonatersTopListWidgetSettings.tsx | 19 +--- .../DonationGoalWidgetSettings.module.css | 4 - .../DonationGoalWidgetSettings.tsx | 37 +------- .../widgetsettings/ReelWidgetSettings.tsx | 26 ++--- .../MediaWidget/PaymentPageConfig.ts | 4 +- .../PaymentPageConfig.module.css | 2 + .../PaymentPageConfigComponent.tsx | 11 ++- src/components/Tabs/Tabs.module.css | 1 + src/components/Tabs/Tabs.tsx | 47 +++++---- src/pages/Reel/ReelWidgetSettings.tsx | 95 +------------------ 22 files changed, 349 insertions(+), 255 deletions(-) create mode 100644 src/components/ConfigurationPage/widgetproperties/DonatersTopListLayoutProperty.tsx create mode 100644 src/components/ConfigurationPage/widgetproperties/ReelItemBackgroundProperty.module.css create mode 100644 src/components/ConfigurationPage/widgetproperties/ReelItemBackgroundProperty.tsx create mode 100644 src/components/ConfigurationPage/widgetproperties/ReelItemListProperty.module.css create mode 100644 src/components/ConfigurationPage/widgetproperties/ReelItemListProperty.tsx diff --git a/src/components/ConfigurationPage/css/WidgetList.css b/src/components/ConfigurationPage/css/WidgetList.css index ead3694..e185ab9 100644 --- a/src/components/ConfigurationPage/css/WidgetList.css +++ b/src/components/ConfigurationPage/css/WidgetList.css @@ -2,6 +2,7 @@ margin-left: 300px; margin-right: 100px; padding-top: 20px; + padding-bottom: 50px; flex: 1 1 auto; } diff --git a/src/components/ConfigurationPage/css/WidgetSettings.css b/src/components/ConfigurationPage/css/WidgetSettings.css index 12eb4f9..d3f33d0 100644 --- a/src/components/ConfigurationPage/css/WidgetSettings.css +++ b/src/components/ConfigurationPage/css/WidgetSettings.css @@ -1,9 +1,9 @@ -/* @import url("https://fonts.googleapis.com/css2?family=Amatic+SC&family=Protest+Strike&display=swap"); */ @import url("https://fonts.googleapis.com/css2?family=Martian+Mono:wght@100..800&display=swap"); .configuration-container { height: 100%; display: flex; + flex-direction: column; } .widget-settings { @@ -12,7 +12,6 @@ padding-left: 15px; padding-right: 15px; padding-bottom: 20px; - margin-bottom: 5px; } .widget-settings-item { diff --git a/src/components/ConfigurationPage/settings/BaseSettings.tsx b/src/components/ConfigurationPage/settings/BaseSettings.tsx index 5a6e817..4477b12 100644 --- a/src/components/ConfigurationPage/settings/BaseSettings.tsx +++ b/src/components/ConfigurationPage/settings/BaseSettings.tsx @@ -1,24 +1,17 @@ import { useContext } from "react"; import { WidgetsContext } from "../WidgetsContext"; import { log } from "../../../logging"; -import { WidgetProperty } from "../widgetproperties/WidgetProperty"; export default function BaseSettings({ id, - propertyFilter, }: { id: string; - customHandler?: Function; - propertyFilter?: (prop: WidgetProperty) => boolean; }) { const { config, updateConfig } = useContext(WidgetsContext); log.debug( { settings: config.get(id) }, "creating layout for widget settings", ); - log.debug({ properties: config.get(id)?.properties }, "use properties"); - - const filter = (prop) => (propertyFilter ? propertyFilter(prop) : true); return config.get(id)?.markup(updateConfig); } diff --git a/src/components/ConfigurationPage/settings/DonatersTopListSettings.tsx b/src/components/ConfigurationPage/settings/DonatersTopListSettings.tsx index c58afb6..c43a7a3 100644 --- a/src/components/ConfigurationPage/settings/DonatersTopListSettings.tsx +++ b/src/components/ConfigurationPage/settings/DonatersTopListSettings.tsx @@ -13,51 +13,7 @@ export default function DonatersTopListSettings({ id }: { id: string }) { .get(id) ?.properties ?.map((prop) => { - if (prop.name === "type" || prop.name === "period") { - return prop.markup(updateConfig); - } if (prop.name === "layout") { - return ( -
- -
- - -
-
- ); } })} diff --git a/src/components/ConfigurationPage/widgetproperties/DonatersTopListLayoutProperty.tsx b/src/components/ConfigurationPage/widgetproperties/DonatersTopListLayoutProperty.tsx new file mode 100644 index 0000000..6963349 --- /dev/null +++ b/src/components/ConfigurationPage/widgetproperties/DonatersTopListLayoutProperty.tsx @@ -0,0 +1,60 @@ +import { ReactNode } from "react"; +import { DefaultWidgetProperty } from "./WidgetProperty"; + +export class DonatersTopListLayoutProperty extends DefaultWidgetProperty { + constructor(widgetId: string, value: string) { + super(widgetId, "layout", "predefined", value, "Компоновка", "content"); + } + + copy(): DonatersTopListLayoutProperty { + return new DonatersTopListLayoutProperty(this.widgetId, this.value); + } + + markup(updateConfig: Function): ReactNode { + return ( + <> +
+ +
+ + +
+
+ + ); + } +} diff --git a/src/components/ConfigurationPage/widgetproperties/DonationGoalProperty.module.css b/src/components/ConfigurationPage/widgetproperties/DonationGoalProperty.module.css index 950a81c..8790a58 100644 --- a/src/components/ConfigurationPage/widgetproperties/DonationGoalProperty.module.css +++ b/src/components/ConfigurationPage/widgetproperties/DonationGoalProperty.module.css @@ -3,3 +3,8 @@ position: relative; padding: 10px; } + +.button { + width: unset!important; + margin-bottom: 10px; +} diff --git a/src/components/ConfigurationPage/widgetproperties/DonationGoalProperty.tsx b/src/components/ConfigurationPage/widgetproperties/DonationGoalProperty.tsx index 13a41a9..dd33f41 100644 --- a/src/components/ConfigurationPage/widgetproperties/DonationGoalProperty.tsx +++ b/src/components/ConfigurationPage/widgetproperties/DonationGoalProperty.tsx @@ -32,7 +32,7 @@ export class DonationGoalProperty extends DefaultWidgetProperty { }, ], "Цель", - undefined, + "goals", ); } @@ -52,6 +52,19 @@ export class DonationGoalProperty extends DefaultWidgetProperty { updateConfig(this.widgetId, "goal", this.value); } + addGoal(updateConfig: Function) { + log.debug({ settings: this }, "adding goal to"); + (this.value as Goal[]).push({ + id: uuidv7(), + briefDescription: "Название", + fullDescription: "Полное описание", + requiredAmount: { major: 100, currency: "RUB" }, + accumulatedAmount: { major: 0, currency: "RUB" }, + }); + updateConfig(this.widgetId, "goal", this.value); + log.debug({ settings: this }, "updated goals"); + } + copy(): DonationGoalProperty { return new DonationGoalProperty(this.widgetId, this.value); } @@ -59,6 +72,12 @@ export class DonationGoalProperty extends DefaultWidgetProperty { markup(updateConfig: Function): ReactNode { return ( <> + {this.value.map((goal: Goal, index: number) => (
Цель:
diff --git a/src/components/ConfigurationPage/widgetproperties/ReelItemBackgroundProperty.module.css b/src/components/ConfigurationPage/widgetproperties/ReelItemBackgroundProperty.module.css new file mode 100644 index 0000000..97c54bc --- /dev/null +++ b/src/components/ConfigurationPage/widgetproperties/ReelItemBackgroundProperty.module.css @@ -0,0 +1,16 @@ +.itembackcontainer{ + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + width: 100%; +} + +.itembacklabel{ + flex: 0 0 auto; + font-family: "Martian Mono", monospace; +} + +.itembackuploadbutton{ + flex: 0 0 auto; +} diff --git a/src/components/ConfigurationPage/widgetproperties/ReelItemBackgroundProperty.tsx b/src/components/ConfigurationPage/widgetproperties/ReelItemBackgroundProperty.tsx new file mode 100644 index 0000000..5e21940 --- /dev/null +++ b/src/components/ConfigurationPage/widgetproperties/ReelItemBackgroundProperty.tsx @@ -0,0 +1,70 @@ +import { ChangeEvent, ReactNode } from "react"; +import { DefaultWidgetProperty } from "./WidgetProperty"; +import axios from "axios"; +import classes from "./ReelItemBackgroundProperty.module.css"; + +export class ReelItemBackgroundProperty extends DefaultWidgetProperty { + constructor(widgetId: string, value: string) { + super( + widgetId, + "backgroundImage", + "predefined", + value, + "Фон карточек", + "prizes", + ); + } + + uploadFile(file: File) { + return axios.put( + `${process.env.REACT_APP_FILE_API_ENDPOINT}/files/${file.name}`, + { file: file }, + { + headers: { + "Content-Type": "multipart/form-data", + }, + }, + ); + } + + handleBackgroundImageChange( + e: ChangeEvent, + updateConfig: Function, + ) { + if (e.target.files) { + const file = e.target.files[0]; + this.uploadFile(file).then((ignore) => { + updateConfig(this.widgetId, "backgroundImage", file.name); + }); + } + } + + copy(): ReelItemBackgroundProperty { + return new ReelItemBackgroundProperty(this.widgetId, this.value); + } + + markup(updateConfig: Function): ReactNode { + return ( + <> +
+
Фон карточек
+ +
+ {this.value && ( + + )} + + ); + } +} diff --git a/src/components/ConfigurationPage/widgetproperties/ReelItemListProperty.module.css b/src/components/ConfigurationPage/widgetproperties/ReelItemListProperty.module.css new file mode 100644 index 0000000..230a22d --- /dev/null +++ b/src/components/ConfigurationPage/widgetproperties/ReelItemListProperty.module.css @@ -0,0 +1,50 @@ +.testbutton { + width: 150px; + margin-bottom: 10px; +} + +.optionscontainer { + width: 100%; + display: flex; + flex-direction: column; + align-items: end; + padding-bottom: 20px; +} + +.itembackcontainer{ + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + width: 100%; +} + +.itembacklabel{ + flex: 0 0 auto; + font-family: "Martian Mono", monospace; +} + +.itembackuploadbutton{ + flex: 0 0 auto; +} + +.backgroundimage{ + border: 1px solid #674afd; + margin-top: 5px; +} + +.addbuttoncontainer { + width: 60%; + text-align: center; + padding-top: 20px; +} + +.option { + width: 60%; + display: flex; + align-items: center; +} + +.option .widget-settings-value { + width: unset; +} diff --git a/src/components/ConfigurationPage/widgetproperties/ReelItemListProperty.tsx b/src/components/ConfigurationPage/widgetproperties/ReelItemListProperty.tsx new file mode 100644 index 0000000..08e89f9 --- /dev/null +++ b/src/components/ConfigurationPage/widgetproperties/ReelItemListProperty.tsx @@ -0,0 +1,74 @@ +import { ReactNode } from "react"; +import { DefaultWidgetProperty } from "./WidgetProperty"; +import classes from "./ReelItemListProperty.module.css"; + +export class ReelItemListProperty extends DefaultWidgetProperty { + constructor(widgetId: string, value: string[]) { + super(widgetId, "optionList", "predefined", value, "Призы", "prizes"); + } + + addOption(updateConfig: Function) { + this.value.push(""); + updateConfig(this.widgetId, "optionList", this.value); + } + + updateOption(index: number, value: string, updateConfig: Function) { + const updated = this.value.toSpliced(index, 1, value); + updateConfig(this.widgetId, "optionList", updated); + } + + removeOption(index: number, updateConfig: Function) { + const updated = this.value.toSpliced(index, 1); + updateConfig(this.widgetId, "optionList", updated); + } + + copy(){ + return new ReelItemListProperty(this.widgetId, this.value); + } + + markup(updateConfig: Function): ReactNode { + console.log(this.value); + return ( +
+ +
+ {this.value && + this.value.map((option, number) => ( + <> +
+