Skip to content

Commit 2a58e93

Browse files
authored
fix: BallotForm trigger onChange on initial render (#40)
* fix: ballot form first render handling this is used to be able to predict the allocation on first render
1 parent 269645d commit 2a58e93

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

.changeset/witty-plants-kneel.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@gitcoin/ui": patch
3+
---
4+
5+
fix: ballot form first render handling

packages/ui/src/features/retrofunding/components/BallotForm/BallotForm.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,22 @@ export const BallotForm: React.FC<BallotFormProps> = ({
7272
...acc,
7373
[item.metricId]: { ...item, locked: true },
7474
}),
75-
{},
75+
{} as BallotItemsMap,
7676
);
7777
setItems(submittedItems);
78+
if (onChange) {
79+
onChange(Object.values(submittedItems));
80+
}
7881
setAlreadyVoted(true);
7982
return;
8083
}
8184

8285
getValue<BallotItemsMap>(persistKey).then((savedItems) => {
8386
if (savedItems) {
8487
setItems(savedItems);
88+
if (onChange) {
89+
onChange(Object.values(savedItems));
90+
}
8591
} else {
8692
const equalShare = Math.floor(maxAllocation / availableMetrics.length);
8793
const remainder = maxAllocation % availableMetrics.length;
@@ -96,10 +102,13 @@ export const BallotForm: React.FC<BallotFormProps> = ({
96102
locked: false,
97103
},
98104
}),
99-
{},
105+
{} as BallotItemsMap,
100106
);
101107
setItems(initialItems);
102108
setValue(persistKey, initialItems);
109+
if (onChange) {
110+
onChange(Object.values(initialItems));
111+
}
103112
}
104113
});
105114
}

0 commit comments

Comments
 (0)