Skip to content

Commit 1111859

Browse files
committed
support for bangladesh and fixing issues with checkboxes component
1 parent eb12439 commit 1111859

File tree

11 files changed

+83
-54
lines changed

11 files changed

+83
-54
lines changed

frontend/.storybook/main.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ module.exports = {
55
],
66
"addons": [
77
"@storybook/addon-links",
8-
{
9-
name: "@storybook/addon-essentials",
10-
options: { docs: false, controls: false } // disable Controls to avoid @storybook/icons
11-
},
8+
"@storybook/addon-essentials",
129
"@storybook/addon-interactions"
1310
],
1411
"framework": "@storybook/react",

frontend/src/components/areas/private/features/payment-requests/payment-requests-table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const PaymentRequestsTable = ({ paymentRequests, updatePaymentRequest })
9898
<PaymentRequestDrawer
9999
open={!!selectedPaymentRequest}
100100
onClose={handleCloseDrawer}
101-
completed={true}
101+
completed={!processingUpdatePaymentRequest}
102102
onSuccess={handleUpdatePaymentRequest}
103103
paymentRequest={{
104104
completed: !processingUpdatePaymentRequest,

frontend/src/components/areas/private/shared/country-codes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ export const countryCodes = [
33
{ country: 'Australia', code: 'AU', image: 'australia' },
44
{ country: 'Austria', code: 'AT', image: 'austria' },
55
{ country: 'Belgium', code: 'BE', image: 'belgium' },
6-
{ country: 'Brazil ', code: 'BR', image: 'brazil' },
6+
{ country: 'Brazil', code: 'BR', image: 'brazil' },
7+
{ country: 'Bangladesh', code: 'BD', image: 'bangladesh' },
78
{ country: 'Bulgaria', code: 'BG', image: 'bulgaria' },
89
{ country: 'Canada', code: 'CA', image: 'canada' },
910
{ country: 'Colombia', code: 'CO', image: 'colombia' },
@@ -61,6 +62,7 @@ export const countryCurrencies = [
6162
{ currency: 'Australian Dollar', symbol: 'A$', code: 'AUD', countries: ['AU'] },
6263
{ currency: 'Albanian Lek', symbol: 'Lek', code: 'ALL', countries: ['AL'] },
6364
{ currency: 'Euro', symbol: '€', code: 'EUR', countries: ['AT', 'BE', 'CY', 'EE', 'FI', 'FR', 'DE', 'GR', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PT', 'SK', 'SI', 'ES'] },
65+
{ currency: 'Bangladeshi Taka', symbol: '৳', code: 'BDT', countries: ['BD'] },
6466
{ currency: 'Brazilian Real', symbol: 'R$', code: 'BRL', countries: ['BR'] },
6567
{ currency: 'Bulgarian Lev', symbol: 'лв', code: 'BGN', countries: ['BG'] },
6668
{ currency: 'Canadian Dollar', symbol: 'C$', code: 'CAD', countries: ['CA'] },

frontend/src/components/design-library/atoms/inputs/checkboxes/checkboxes.stories.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import Checkboxes from './checkboxes';
3+
import { action } from '@storybook/addon-actions';
34

45
export default {
56
title: 'Design Library/Atoms/Inputs/Checkboxes',
@@ -28,6 +29,19 @@ WithSelectAll.args = {
2829
includeSelectAll: true
2930
};
3031

32+
export const WithOnChange = Template.bind({});
33+
WithOnChange.args = {
34+
completed: true,
35+
checkboxes: [
36+
{ label: 'Option 1', name: 'option1', value: 'option1' },
37+
{ label: 'Option 2', name: 'option2', value: 'option2' },
38+
{ label: 'Option 3', name: 'option3', value: 'option3' }
39+
],
40+
onChange: (selected) => {
41+
action('Selected Checkboxes')(selected);
42+
}
43+
};
44+
3145
export const Loading = Template.bind({});
3246
Loading.args = {
3347
checkboxes: [],

frontend/src/components/design-library/atoms/inputs/fields/user-role-field/user-role-field.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useMemo } from 'react';
22
import { Grid, Tooltip, Typography } from '@mui/material';
33
import { Help } from '@mui/icons-material';
44
import Checkboxes from '../../checkboxes/checkboxes';
@@ -7,11 +7,11 @@ import { FormattedMessage } from 'react-intl';
77
const UserRoleField = ({ roles, onChange }) => {
88
const { data, completed } = roles;
99

10-
const checkBoxes = data.map((role) => ({
10+
const checkBoxes = useMemo(() => data.map((role) => ({
1111
label: role.label,
1212
name: role.name,
1313
value: role.id
14-
}));
14+
})), [data]);
1515

1616
return (
1717
<Grid container spacing={2} alignContent="center" alignItems="center">
@@ -28,6 +28,7 @@ const UserRoleField = ({ roles, onChange }) => {
2828
checkboxes={checkBoxes}
2929
includeSelectAll={true}
3030
onChange={onChange}
31+
completed={completed}
3132
/>
3233
</Grid>
3334
</Grid>

frontend/src/components/design-library/molecules/form-section/login-form/login-form-signup/login-form-signup.stories.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import React from 'react';
2+
import { action } from '@storybook/addon-actions';
23
import LoginFormSignup from './login-form-signup';
34

45
export default {
56
title: 'Design Library/Molecules/FormSection/LoginForm/LoginFormSignup',
6-
component: LoginFormSignup
7+
component: LoginFormSignup,
8+
controls: { expanded: true }
79
};
810

911
const Template = (args) => <LoginFormSignup {...args} />;
1012

1113
export const Default = Template.bind({});
1214
Default.args = {
15+
onSubmit: action('onSubmit'),
1316
roles: {
1417
completed: true,
1518
data: [
16-
{ id: '1', name: 'contributor' },
17-
{ id: '2', name: 'sponsor' },
18-
{ id: '3', name: 'maintainer' }
19+
{ id: 1, name: 'contributor', label: 'Contributor' },
20+
{ id: 2, name: 'sponsor', label: 'Sponsor' },
21+
{ id: 3, name: 'maintainer', label: 'Maintainer' }
1922
]
2023
},
2124
fetchRoles: () => {}

frontend/src/components/design-library/molecules/form-section/login-form/login-form-signup/login-form-signup.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react'
1+
import React, { useCallback, useEffect, useState } from 'react'
22
import { FormattedMessage } from 'react-intl'
33
import {
44
Button,
@@ -42,7 +42,7 @@ const LoginFormSignup = ({
4242
roles,
4343
fetchRoles
4444
}: LoginFormSignupProps) => {
45-
45+
4646
const [openTermsDialog, setOpenTermsDialog] = useState(false)
4747
const [openPrivacyDialog, setOpenPrivacyDialog] = useState(false)
4848
const [validating, setValidating] = useState(false)
@@ -68,9 +68,9 @@ const LoginFormSignup = ({
6868
setState({ ...state, [name]: value })
6969
}
7070

71-
const handleTypesChange = (name) => (checked) => {
72-
setState({ ...state, [name]: checked })
73-
}
71+
const handleTypesChange = useCallback((checked) => {
72+
setState(prev => ({ ...prev, Types: checked }))
73+
}, [])
7474

7575
const handleBlur = () => {
7676
setValidating(true)
@@ -351,12 +351,12 @@ const LoginFormSignup = ({
351351
defaultValue={state.confirmPassword}
352352
/>
353353
</Margins>
354-
<Margins>
354+
<Margins>
355355
<UserRoleField
356356
roles={roles}
357-
onChange={handleTypesChange('Types')}
357+
onChange={handleTypesChange}
358358
/>
359-
</Margins>
359+
</Margins>
360360
<div style={{ display: 'flex', justifyContent: 'flex-start' }}>
361361
<div style={{ display: 'flex', alignItems: 'center' }}>
362362
{state.agreeTermsCheck
@@ -408,16 +408,16 @@ const LoginFormSignup = ({
408408
</Typography>
409409
</div>
410410
}
411-
<Center style={{ marginTop: 20 }}>
411+
<Center style={{ marginTop: 20 }}>
412412
<div>
413413
{noCancelButton ? null : (
414-
<SpacedButton onClick={onClose} size="large" variant="text" color="primary">
414+
<SpacedButton onClick={onClose} size="large" variant="text" color="primary">
415415
<FormattedMessage id="account.login.label.cancel" defaultMessage="Cancel" />
416-
</SpacedButton>
416+
</SpacedButton>
417417
)}
418-
<SpacedButton data-testid="signup-button" type="submit" size="large" variant="contained" color="primary">
418+
<SpacedButton data-testid="signup-button" type="submit" size="large" variant="contained" color="primary">
419419
<FormattedMessage id="account.login.label.signup" defaultMessage="Sign up" />
420-
</SpacedButton>
420+
</SpacedButton>
421421
<div style={{ marginTop: 20, display: 'flex', alignItems: 'baseline' }}>
422422
<Typography variant="body1" component="span">
423423
<FormattedMessage id="account.login.label.or.signup" defaultMessage="Have an account?" />
@@ -427,7 +427,7 @@ const LoginFormSignup = ({
427427
</Button>
428428
</div>
429429
</div>
430-
</Center>
430+
</Center>
431431
<TermsDialog open={openTermsDialog} onClose={closeTermsDialog} />
432432
<PrivacyDialog open={openPrivacyDialog} onClose={closePrivacyDialog} />
433433
</form>

frontend/src/components/design-library/organisms/forms/payment-request-forms/payment-request-form/payment-request-form.tsx

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useRef, forwardRef, useImperativeHandle } from 'react';
1+
import React, { useState, useRef, forwardRef, useImperativeHandle, useCallback, useMemo } from 'react';
22
import { Grid, Typography, TextField, Skeleton } from '@mui/material';
33
import { FormattedMessage } from 'react-intl';
44
import Field from '../../../../atoms/inputs/fields/field/field';
@@ -70,36 +70,46 @@ const PaymentRequestForm = forwardRef<PaymentRequestFormHandle, PaymentRequestFo
7070
onSubmit?.(event, data);
7171
};
7272

73-
const handleCustomAmountChange = (selected: boolean) => {
73+
const handleCustomAmountChange = useCallback((selected: boolean) => {
7474
setCustomAmount(selected);
75-
};
75+
}, []);
76+
77+
const checkboxes = useMemo(() => {
78+
const items = [
79+
{
80+
label: <FormattedMessage id="paymentRequest.form.customAmount" defaultMessage="Custom Amount" />,
81+
name: 'custom_amount',
82+
value: true,
83+
disabled: editMode,
84+
defaultChecked: data?.custom_amount,
85+
onChange: handleCustomAmountChange
86+
},
87+
{
88+
label: <FormattedMessage id="paymentRequest.form.deactivateAfterPayment" defaultMessage="Deactivate after payment" />,
89+
name: 'deactivate_after_payment',
90+
value: true,
91+
defaultChecked: data?.deactivate_after_payment,
92+
disabled: editMode
93+
}
94+
];
7695

77-
const checkboxes = [
78-
{
79-
label: <FormattedMessage id="paymentRequest.form.customAmount" defaultMessage="Custom Amount" />,
80-
name: 'custom_amount',
81-
value: true,
82-
disabled: editMode,
83-
defaultChecked: data?.custom_amount,
84-
onChange: handleCustomAmountChange
85-
},
86-
{
87-
label: <FormattedMessage id="paymentRequest.form.deactivateAfterPayment" defaultMessage="Deactivate after payment" />,
88-
name: 'deactivate_after_payment',
89-
value: true,
90-
defaultChecked: data?.deactivate_after_payment,
91-
disabled: editMode
96+
if (data?.active !== undefined) {
97+
items.unshift({
98+
label: <FormattedMessage id="paymentRequest.form.active" defaultMessage="Active" />,
99+
name: 'active',
100+
value: true,
101+
defaultChecked: data?.active
102+
} as any);
92103
}
93-
]
94104

95-
if(data?.active !== undefined) {
96-
checkboxes.unshift({
97-
label: <FormattedMessage id="paymentRequest.form.active" defaultMessage="Active" />,
98-
name: 'active',
99-
value: true,
100-
defaultChecked: data?.active
101-
} as any);
102-
}
105+
return items;
106+
}, [
107+
editMode,
108+
data?.custom_amount,
109+
data?.deactivate_after_payment,
110+
data?.active,
111+
handleCustomAmountChange
112+
]);
103113

104114
return (
105115
<form onSubmit={handleSubmit} ref={internalFormRef}>
22.3 KB
Loading

modules/util/currency-info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ module.exports = {
9494
sll: { symbol: 'Le', decimalPlaces: 2 }, // Sierra Leonean Leone
9595
gmd: { symbol: 'D', decimalPlaces: 2 }, // Gambian Dalasi
9696
lrd: { symbol: 'L$', decimalPlaces: 2 }, // Liberian Dollar
97+
bdt: { symbol: '৳', decimalPlaces: 2 }, // Bangladeshi Taka
9798
xag: { symbol: 'XAG', decimalPlaces: 2 }, // Silver (troy ounce)
9899
xau: { symbol: 'XAU', decimalPlaces: 2 }, // Gold (troy ounce)
99100
btc: { symbol: '₿', decimalPlaces: 8 }, // Bitcoin

0 commit comments

Comments
 (0)