Skip to content

Commit

Permalink
refactor(sponsors): in NewSponsorFormikForm, add different alert when…
Browse files Browse the repository at this point in the history
… the user has added all fields; use MUI button
  • Loading branch information
m2mathew committed Sep 18, 2023
1 parent f228f3b commit 0dc2c04
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/components/sponsors/SponsorsNew/NewSponsorFormikForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from '.';
import { SPONSOR_LEVEL_OPTIONS } from './constants';
import CloudinaryUploadWidget from '../../shared/CloudinaryUploadWidget';
import CtaButton from '../../shared/CtaButton';
import CustomSelect from '../../shared/CustomSelect';
import CustomTextField from '../../shared/CustomTextField';
import EnhancedAlert from '../../shared/EnhancedAlert';
Expand Down Expand Up @@ -73,6 +72,7 @@ const NewSponsorFormikForm: React.FC<Props> = ({
}

const shouldPreventSubmit = hasTouchedForm && (hasErrors || !imageUrl);
const isReadyToSubmit = hasTouchedForm && !shouldPreventSubmit;

return (
<Form onSubmit={onFormikSubmit}>
Expand Down Expand Up @@ -169,26 +169,38 @@ const NewSponsorFormikForm: React.FC<Props> = ({
value={formikValues.honeypot}
/>

<Box
mb={2.5}
mt={1}
width="100%"
>
<EnhancedAlert severity={shouldPreventSubmit ? 'error' : 'info'}>
Please enter a value in each required field and upload a logo image.
</EnhancedAlert>
</Box>
<Collapse in={!isReadyToSubmit}>
<Box
mb={2.5}
mt={1}
width="100%"
>
<EnhancedAlert severity={shouldPreventSubmit ? 'error' : 'info'}>
Please enter a value in each required field and upload a logo image.
</EnhancedAlert>
</Box>
</Collapse>

<Collapse in={isReadyToSubmit}>
<Box
mb={2.5}
mt={1}
width="100%"
>
<EnhancedAlert severity="success">
Data looks good! Press the button below to add this sponsor.
</EnhancedAlert>
</Box>
</Collapse>

<CtaButton
<Button
disabled={shouldPreventSubmit}
fontWeight={600}
rightArrow
size="large"
type="submit"
width={240}
variant="contained"
>
Add Sponsor
</CtaButton>
</Button>
</Form>
);
};
Expand Down

0 comments on commit 0dc2c04

Please sign in to comment.