Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.

Commit caa1401

Browse files
committed
proposed fix for optionsgroup
1 parent db6f43c commit caa1401

1 file changed

Lines changed: 27 additions & 40 deletions

File tree

components/PublicPiggybankPage/EditPiggybankModal/PaymentMethodsInput.tsx

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ type Props = {
4242
fieldArrayName: string,
4343
};
4444

45+
const OptionsGroup = ({ category, selectedPaymentMethodIds }: { category: Category, selectedPaymentMethodIds: string[] }) => {
46+
const optgroupLabels: Record<Category, string> = {
47+
"digital-wallet": 'Wallets',
48+
"digital-asset": "Cryptocurrencies",
49+
"subscription-platform": "Platforms",
50+
};
51+
return (
52+
<optgroup label={optgroupLabels[category]}>
53+
{paymentMethods
54+
.filter(paymentMethod => paymentMethod.category === category)
55+
.sort((a, b) => (a.id < b.id ? -1 : 1))
56+
.map(({ id, displayName }) => (
57+
<option
58+
key={id}
59+
value={id}
60+
style={{display: selectedPaymentMethodIds.includes(id) ? "none" : undefined }}
61+
>
62+
{displayName}
63+
</option>
64+
))}
65+
</optgroup>
66+
);
67+
};
68+
4569
const PaymentMethodsInput: FC<Props> = ({ fieldArrayName, fields, control, register, remove, append }) => {
4670
const { colors } = useTheme();
4771
const paymentMethodsDataWatch: PaymentMethod[] = useWatch({
@@ -59,30 +83,6 @@ const PaymentMethodsInput: FC<Props> = ({ fieldArrayName, fields, control, regis
5983
}, [paymentMethodsDataWatch]);
6084
const containsInvalidAddress = paymentMethodsDataWatch.some(paymentMethod => !paymentMethod.address);
6185
const { isAddressTouched, setIsAddressTouched } = useContext(AdditionalValidation);
62-
// optgroup not compatible with Chakra dark mode: https://github.com/chakra-ui/chakra-ui/issues/2853
63-
// const optionsGroup = (category: Category) => {
64-
// const optgroupLabels: Record<Category, string> = {
65-
// "digital-wallet": 'Digital Wallets',
66-
// "digital-asset": "Digital Assets",
67-
// "subscription-platform": "Subscription Platforms",
68-
// };
69-
// return (
70-
// <optgroup label={optgroupLabels[category]}>
71-
// {paymentMethods
72-
// .filter(paymentMethod => paymentMethod.category === category)
73-
// .sort((a, b) => (a.id < b.id ? -1 : 1))
74-
// .map(({ id, displayName }) => (
75-
// <option
76-
// key={id}
77-
// value={id}
78-
// style={{display: paymentMethodsDataWatch.map(paymentMethodDataWatch => paymentMethodDataWatch.paymentMethodId).includes(id) ? "none" : undefined }}
79-
// >
80-
// {displayName}
81-
// </option>
82-
// ))}
83-
// </optgroup>
84-
// );
85-
// };
8686
return (
8787
<>
8888
{fields.length < 1
@@ -155,22 +155,9 @@ const PaymentMethodsInput: FC<Props> = ({ fieldArrayName, fields, control, regis
155155
onChange={() => setIsAddressTouched(false)}
156156
>
157157
<option hidden disabled value="default-blank">Select...</option>
158-
{/* optgroup not compatible with Chakra dark mode: https://github.com/chakra-ui/chakra-ui/issues/2853 */}
159-
{Object.entries(paymentMethodNames)
160-
.sort((a, b) => {
161-
const [aId] = a;
162-
const [bId] = b;
163-
return aId < bId ? -1 : 1;
164-
})
165-
.map(([paymentMethodId, paymentMethodDisplayName]) => (
166-
<option
167-
key={paymentMethodId}
168-
value={paymentMethodId}
169-
style={{display: paymentMethodsDataWatch.map(paymentMethod => paymentMethod.paymentMethodId).includes(paymentMethodId) ? "none" : undefined }}
170-
>
171-
{paymentMethodDisplayName}
172-
</option>
173-
))}
158+
<OptionsGroup category="digital-asset" selectedPaymentMethodIds={paymentMethodsDataWatch.map(pm => pm.paymentMethodId)} />
159+
<OptionsGroup category="digital-wallet" selectedPaymentMethodIds={paymentMethodsDataWatch.map(pm => pm.paymentMethodId)} />
160+
<OptionsGroup category="subscription-platform" selectedPaymentMethodIds={paymentMethodsDataWatch.map(pm => pm.paymentMethodId)} />
174161
</Select>
175162
</Box>
176163
<Box

0 commit comments

Comments
 (0)