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 1 commit
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
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
9 changes: 8 additions & 1 deletion 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 @@ -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