Skip to content

MPDX-8678 - Improve AddDonation#1369

Open
zweatshirt wants to merge 6 commits intomainfrom
MPDX-8678-improve-add-donation
Open

MPDX-8678 - Improve AddDonation#1369
zweatshirt wants to merge 6 commits intomainfrom
MPDX-8678-improve-add-donation

Conversation

@zweatshirt
Copy link
Copy Markdown
Contributor

@zweatshirt zweatshirt commented Jul 15, 2025

Description

Jira ticket

  • Standardizes the AddDonation form, since many of the errors across fields were inconsistent.
  • For consistency, I tried to make my changes relatively similar to the changes made in MPDX-8679

Checklist:

  • I have given my PR a title with the format "MPDX-(JIRA#) (summary sentence max 80 chars)"
  • I have applied the appropriate labels. (Add the label "On Staging" to get the branch automatically merged into staging.)
  • I have requested a review from another person on the project

@zweatshirt zweatshirt added the Preview Environment Add this label to create an Amplify Preview label Jul 15, 2025
@github-actions
Copy link
Copy Markdown
Contributor

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jul 15, 2025

Bundle sizes [mpdx-react]

Compared against f62263d

No significant changes found

@zweatshirt zweatshirt requested a review from wjames111 July 15, 2025 14:54
Copy link
Copy Markdown
Contributor

@wjames111 wjames111 left a comment

Choose a reason for hiding this comment

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

Looks great! thanks for improving this form. The only issue I had was getting the DateField working.

@wjames111
Copy link
Copy Markdown
Contributor

wjames111 commented Jul 15, 2025

So right now we are essentially hacking the touched state by either leaving out the check for touched or forcing it to trigger on load onBlur={handleBlur('fieldValue')}. instead we could ensure Formik is properly updating the touched value by using formik's setFieldTouched.

 onChange={(_, value) => {
   setFieldValue('fieldValue', value);
   setFieldTouched('fieldValue', true, false);
}}
onBlur={() => {
  setFieldTouched('fieldValue', true);
}}

I think this is the best way to handle the form validation, it also works on the CustomDateField. CC @kegrimes

@zweatshirt
Copy link
Copy Markdown
Contributor Author

So right now we are essentially hacking the touched state by either leaving out the check for touched or forcing it to trigger on load onBlur={handleBlur('fieldValue')}. instead we could ensure Formik is properly updating the touched value by using formik's setFieldTouched.

 onChange={(_, value) => {
   setFieldValue('fieldValue', value);
   setFieldTouched('fieldValue', true, false);
}}
onBlur={() => {
  setFieldTouched('fieldValue', true);
}}

I think this is the best way to handle the form validation, it also works on the CustomDateField. CC @kegrimes

@wjames111 Is this a change that should be made on all form fields or just the DateField one?

@wjames111
Copy link
Copy Markdown
Contributor

@zweatshirt Ideally all of them if possible.

@zweatshirt zweatshirt requested a review from wjames111 July 16, 2025 17:05
Copy link
Copy Markdown
Contributor

@wjames111 wjames111 left a comment

Choose a reason for hiding this comment

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

Looks great!

useMediaQuery,
} from '@mui/material';
import { FastField, Field, FieldProps, Form, Formik } from 'formik';
import i18n from 'i18next';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I noticed this one of Daniel's reviews, it looks like we should be importing from src/lib/i18n.

Suggested change
import i18n from 'i18next';
import i18n from 'src/lib/i18n';

Comment on lines +59 to +78
.typeError(i18n.t('Appeal amount must be a valid number'))
.nullable()
.test(
'Is appeal amount in valid currency format?',
'Appeal amount must be in valid currency format',
i18n.t('Appeal amount must be in valid currency format'),
(amount) =>
!amount || /\$?[0-9][0-9.,]*/.test(amount as unknown as string),
)
.test(
'Is positive?',
'Must use a positive number for appeal amount',
i18n.t('Must use a positive number for appeal amount'),
(value) => !value || parseFloat(value as unknown as string) > 0,
),
appealId: yup.string().nullable(),
currency: yup.string().required(),
designationAccountId: yup.string().required(),
donationDate: requiredDateTime(),
donorAccountId: yup.string().required(),
currency: yup.string().required(i18n.t('Currency is required')),
designationAccountId: yup
.string()
.required(i18n.t('Designation account is required')),
donationDate: requiredDateTime(i18n.t('Date is required')),
donorAccountId: yup.string().required(i18n.t('Partner Account is required')),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this will be a lot more helpful to the user!

Comment on lines +214 to +218
onChange={(e) => {
setFieldValue('amount', e.target.value);
setFieldTouched('amount', true, false);
}}
onBlur={() => setFieldTouched('amount', true)}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for using the setFieldTouched on these!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for making these changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Preview Environment Add this label to create an Amplify Preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants