Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform otherAmount select to input field #1581

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion public/locales/bg/one-time-donation.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"amount": "Каква сума желаете да дарите?",
"other": "Друга сума",
"BGN": "лв.",
"transaction-limit": "Дарението не може да надхвърля сумата от"
"only-number": "Полето може да съдържа само цифри.",
"transaction-limit": "Дарението не може да надхвърля сумата от {{limit}}"
},
"second-step": {
"login": "Влизане в профил",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/en/one-time-donation.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"amount": "How much would you like to donate?",
"other": "Other amount",
"BGN": "BGN",
"transaction-limit": "Donation can't exceed the sum of "
"only-number": "This field can contain only numbers.",
"transaction-limit": "Donation can't exceed the sum of {{limit}}"
},
"second-step": {
"login": "Log in",
Expand Down
15 changes: 9 additions & 6 deletions src/components/client/one-time-donation/steps/FirstStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useContext, useEffect } from 'react'
import { styled } from '@mui/material/styles'
import { Trans, useTranslation } from 'next-i18next'
import { useField, useFormikContext } from 'formik'
import { Box, Collapse, Divider, Grid, List, Typography } from '@mui/material'
import { Box, Collapse, Divider, Fade, Grid, List, Typography } from '@mui/material'
import EventRepeatIcon from '@mui/icons-material/EventRepeat'
import theme from 'common/theme'
import RadioButtonGroup from 'components/common/form/RadioButtonGroup'
Expand Down Expand Up @@ -240,25 +240,28 @@ export default function FirstStep() {
label: moneyPublic(Number(v)),
value: String(Number(v)),
}))
.concat({ label: t('first-step.other'), value: 'other' }) || []
.concat({
label: t('first-step.other'),
value: 'other',
hidden: amount.value === 'other',
} as { label: string; value: string; hidden?: boolean }) || []
}
/>
<Collapse unmountOnExit in={amount.value === 'other'} timeout="auto">
<Fade unmountOnExit in={amount.value === 'other'} exit={false} timeout={200}>
<Grid
item
xs={12}
style={
!mobile
? {
float: 'right',
marginTop: -50,
paddingTop: 16,
width: '49%',
}
: { marginTop: theme.spacing(2) }
}>
<NumberInputField limit={STRIPE_LIMIT_BGN} />
</Grid>
</Collapse>
</Fade>
{amount.value ? (
<Box sx={{ mt: 4 }}>
<Grid container>
Expand Down
11 changes: 9 additions & 2 deletions src/components/common/form/NumberInputField.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useEffect } from 'react'

import { InputAdornment } from '@mui/material'
import FormTextField from './FormTextField'

Expand All @@ -18,6 +20,10 @@ export default function NumberInputField({
const [, meta, { setValue, setError }] = useField(name)
const decimalSeparator = (1.1).toLocaleString(i18n.lang).charAt(1)

useEffect(() => {
setValue(1)
Copy link
Contributor Author

@dphilipov dphilipov Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm setting the value to 1, because currently there is brief moment where the validation gets triggered and the Минималната сума която може да дарите с карта е 1лв. error message gets shown. This was kinda hidden by the Collapse animation.

}, [])

return (
<FormTextField
name={name}
Expand Down Expand Up @@ -74,7 +80,7 @@ export default function NumberInputField({
return
}
if (Number(amount) > limit) {
setError(`${t('first-step.transaction-limit')} ${moneyPublic(limit, 'BGN', 1)}`)
setError(t('first-step.transaction-limit', { limit: moneyPublic(limit, 'BGN', 1) }))
return
} else if (Number(amount) < 1) {
setValue(1)
Expand All @@ -89,13 +95,14 @@ export default function NumberInputField({
max: limit,
inputMode: 'decimal',
},
style: { padding: 7 },
style: { padding: 5 },
endAdornment: (
<InputAdornment variant="filled" position="end">
{t('first-step.BGN')}
</InputAdornment>
),
}}
autoFocus
/>
)
}
Loading