|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import clsx from 'clsx'; |
| 4 | + |
| 5 | +import { |
| 6 | + Box, |
| 7 | + Container, |
| 8 | + Typography, |
| 9 | + makeStyles, |
| 10 | + Grid, |
| 11 | + Button, |
| 12 | + CircularProgress |
| 13 | +} from '@material-ui/core'; |
| 14 | +import { TextValidator, ValidatorForm } from 'react-material-ui-form-validator'; |
| 15 | + |
| 16 | +const useStyles = makeStyles(theme => ({ |
| 17 | + root: { |
| 18 | + minHeight: '300px', |
| 19 | + color: '#FFF', |
| 20 | + padding: '100px 70px', |
| 21 | + [theme.breakpoints.down('md')]: { |
| 22 | + paddingLeft: 15, |
| 23 | + paddingRight: 15 |
| 24 | + } |
| 25 | + }, |
| 26 | + main: { |
| 27 | + display: 'flex', |
| 28 | + flexDirection: 'column', |
| 29 | + justifyContent: 'center', |
| 30 | + padding: '0px', |
| 31 | + color: '#FFF' |
| 32 | + }, |
| 33 | + btn: { |
| 34 | + backgroundColor: '#A60000', |
| 35 | + color: '#ffffff', |
| 36 | + textTransform: 'capitalize', |
| 37 | + [theme.breakpoints.down('sm')]: { |
| 38 | + width: '100%' |
| 39 | + }, |
| 40 | + '&:hover': { |
| 41 | + backgroundColor: 'rgba(166, 0, 0, 0.8)' |
| 42 | + } |
| 43 | + }, |
| 44 | + textField: { |
| 45 | + marginBottom: '20px', |
| 46 | + marginTop: '8px', |
| 47 | + backgroundColor: '#ECECEC', |
| 48 | + borderBlockColor: 'green', |
| 49 | + borderColor: 'green', |
| 50 | + '& .MuiOutlinedInput-notchedOutline': { |
| 51 | + borderColor: '#ECECEC' |
| 52 | + }, |
| 53 | + [theme.breakpoints.down('sm')]: { |
| 54 | + marginBottom: '0px' |
| 55 | + } |
| 56 | + }, |
| 57 | + extraPadding: { |
| 58 | + [theme.breakpoints.down('md')]: { |
| 59 | + marginTop: '12px' |
| 60 | + } |
| 61 | + } |
| 62 | +})); |
| 63 | + |
| 64 | +function Hero({ |
| 65 | + title, |
| 66 | + subtitle, |
| 67 | + subtitleDesign, |
| 68 | + className, // className |
| 69 | + backgroundImage = null, // Link to the background image if any |
| 70 | + component = null, // The Button or any component provided |
| 71 | + ...rest |
| 72 | +}) { |
| 73 | + const classes = useStyles(); |
| 74 | + |
| 75 | + return ( |
| 76 | + <div> |
| 77 | + <div |
| 78 | + className={clsx(classes.root, className)} |
| 79 | + style={{ |
| 80 | + backgroundImage: `url(${backgroundImage})`, |
| 81 | + backgroundSize: 'cover', |
| 82 | + backgroundRepeat: 'no-repeat' |
| 83 | + }} |
| 84 | + {...rest} |
| 85 | + > |
| 86 | + <Container maxWidth="lg"> |
| 87 | + <div className={classes.main}> |
| 88 | + <Typography variant="h2">{title}</Typography> |
| 89 | + <Box mt={2}> |
| 90 | + <Typography className={subtitleDesign} variant="body1"> |
| 91 | + {subtitle} |
| 92 | + </Typography> |
| 93 | + </Box> |
| 94 | + <Box mt={2}>{component != null ? component : <></>}</Box> |
| 95 | + </div> |
| 96 | + <Form /> |
| 97 | + <Typography |
| 98 | + display="block" |
| 99 | + className={classes.extraPadding} |
| 100 | + variant="caption" |
| 101 | + > |
| 102 | + By clicking ‘subscribe’ , I agree to Code For Cause’s Terms & |
| 103 | + Privacy Policy. |
| 104 | + </Typography> |
| 105 | + </Container> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + ); |
| 109 | +} |
| 110 | + |
| 111 | +function Form() { |
| 112 | + const classes = useStyles(); |
| 113 | + const [formData, updateFormData] = useState({}); |
| 114 | + const [submitting, setSubmitting] = useState(0); |
| 115 | + |
| 116 | + // const { enqueueSnackbar } = useSnackbar(); |
| 117 | + |
| 118 | + const handleChange = event => { |
| 119 | + updateFormData({ |
| 120 | + ...formData, |
| 121 | + [event.target.name]: event.target.value |
| 122 | + }); |
| 123 | + }; |
| 124 | + |
| 125 | + const handleSubmit = e => { |
| 126 | + setSubmitting(1); |
| 127 | + e.preventDefault(); |
| 128 | + }; |
| 129 | + |
| 130 | + return ( |
| 131 | + <ValidatorForm onSubmit={handleSubmit}> |
| 132 | + <Typography variant="caption">Email Id</Typography> |
| 133 | + <Grid container spacing={3} xs={12} sm={12} md={12}> |
| 134 | + <Grid item sm={10} xs={12}> |
| 135 | + <TextValidator |
| 136 | + key="email" |
| 137 | + className={classes.textField} |
| 138 | + variant="outlined" |
| 139 | + value={formData.email} |
| 140 | + fullWidth |
| 141 | + name="email" |
| 142 | + onChange={handleChange} |
| 143 | + validators={['required', 'isEmail']} |
| 144 | + errorMessages={['This is a required field', 'Ender a valid Email']} |
| 145 | + /> |
| 146 | + </Grid> |
| 147 | + <Grid item sm={2} xs={12}> |
| 148 | + {submitting === 0 ? ( |
| 149 | + <Button |
| 150 | + fullWidth |
| 151 | + type="submit" |
| 152 | + variant="contained" |
| 153 | + color="secondary" |
| 154 | + size="large" |
| 155 | + style={{ |
| 156 | + marginTop: '7px', |
| 157 | + textTransform: 'capitalize', |
| 158 | + padding: '16.8px' |
| 159 | + }} |
| 160 | + > |
| 161 | + <Typography variant="h6" style={{ fontWeight: 600 }}> |
| 162 | + Subscribe |
| 163 | + </Typography> |
| 164 | + </Button> |
| 165 | + ) : ( |
| 166 | + <div className={classes.submissions}> |
| 167 | + <CircularProgress /> |
| 168 | + </div> |
| 169 | + )} |
| 170 | + </Grid> |
| 171 | + </Grid> |
| 172 | + </ValidatorForm> |
| 173 | + ); |
| 174 | +} |
| 175 | + |
| 176 | +Hero.propTypes = { |
| 177 | + title: PropTypes.string, |
| 178 | + subtitle: PropTypes.string, |
| 179 | + subtitleDesign: PropTypes.string, |
| 180 | + className: PropTypes.string, |
| 181 | + backgroundImage: PropTypes.string, |
| 182 | + component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]) |
| 183 | +}; |
| 184 | + |
| 185 | +export default Hero; |
0 commit comments