Skip to content

Commit

Permalink
add default property to goal settings
Browse files Browse the repository at this point in the history
  • Loading branch information
stCarolas committed May 26, 2024
1 parent 73b5c64 commit 959d964
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function BooleanPropertyInput({
<input
type="checkbox"
checked={true === prop.value}
onChange={(e) => onChange()}
onChange={(e) => onChange(e)}
/>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DefaultWidgetProperty } from "./WidgetProperty";
import classes from "./DonationGoalProperty.module.css";
import { log } from "../../../logging";
import { uuidv7 } from "uuidv7";
import BooleanPropertyInput from "../settings/properties/BooleanPropertyInput";

export interface Amount {
major: number;
Expand All @@ -13,6 +14,7 @@ export interface Goal {
id: string;
briefDescription: string;
fullDescription: string;
default: boolean;
requiredAmount: Amount;
accumulatedAmount: Amount;
}
Expand All @@ -28,6 +30,7 @@ export class DonationGoalProperty extends DefaultWidgetProperty {
id: uuidv7(),
briefDescription: "test",
fullDescription: "full",
default: false,
requiredAmount: { major: 100, currency: "RUB" },
},
],
Expand All @@ -47,9 +50,13 @@ export class DonationGoalProperty extends DefaultWidgetProperty {
{ goals: this.value, updated: goal, index: index },
"goals before update",
);
(this.value as Goal[]).splice(index, 1, goal);
const updated = (this.value as Goal[]).map((it) => {
it.default = false;
return it;
});
updated.splice(index, 1, goal);
log.debug({ goals: this.value }, "goals after update");
updateConfig(this.widgetId, "goal", this.value);
updateConfig(this.widgetId, "goal", updated);
}

addGoal(updateConfig: Function) {
Expand All @@ -58,6 +65,7 @@ export class DonationGoalProperty extends DefaultWidgetProperty {
id: uuidv7(),
briefDescription: "Название",
fullDescription: "Полное описание",
default: false,
requiredAmount: { major: 100, currency: "RUB" },
accumulatedAmount: { major: 0, currency: "RUB" },
});
Expand All @@ -80,7 +88,7 @@ export class DonationGoalProperty extends DefaultWidgetProperty {
</button>
{this.value.map((goal: Goal, index: number) => (
<div key={index} className={`${classes.goalcontainer}`}>
<div style={{ fontStyle: "italic", fontWeight: "900"}}>Цель:</div>
<div style={{ fontStyle: "italic", fontWeight: "900" }}>Цель:</div>
<div className="widget-settings-item">
<label
htmlFor={`${this.widgetId}_${index}`}
Expand Down Expand Up @@ -134,16 +142,41 @@ export class DonationGoalProperty extends DefaultWidgetProperty {
value={goal.requiredAmount.major}
onChange={(e) => {
const updated = structuredClone(goal);
updated.requiredAmount.major = Number.parseInt(e.target.value);
updated.requiredAmount.major = Number.parseInt(
e.target.value,
);
this.updateGoal(updateConfig, updated, index);
}}
/>
</div>
</div>
<div className="widget-settings-item">
<label
htmlFor={`${this.widgetId}_${this.name}`}
className="widget-settings-name"
>
По-умолчанию
</label>
<div className="textarea-container">
<BooleanPropertyInput
onChange={(e) => {
console.log(e.target.value);
const updated = structuredClone(goal);
updated.default = !updated.default;
this.updateGoal(updateConfig, updated, index);
}}
prop={{
name: "test",
type: "predefined",
value: goal.default,
}}
/>
</div>
</div>
<div style={{ textAlign: "right" }}>
<button
className="widget-button"
onClick={(e) => {
onClick={() => {
this.deleteGoal(updateConfig, index);
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export class ReelItemListProperty extends DefaultWidgetProperty {
}

markup(updateConfig: Function): ReactNode {
console.log(this.value);
return (
<div className="widget-settings-item">
<label className="widget-settings-name">Призы</label>
Expand Down

0 comments on commit 959d964

Please sign in to comment.