Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
77 lines
2.2 KiB
JavaScript
77 lines
2.2 KiB
JavaScript
import * as React from 'react';
|
|
import FormControl from '@mui/joy/FormControl';
|
|
import FormLabel from '@mui/joy/FormLabel';
|
|
import FormHelperText from '@mui/joy/FormHelperText';
|
|
import Input from '@mui/joy/Input';
|
|
import Button from '@mui/joy/Button';
|
|
|
|
export default function InputSubscription() {
|
|
const [data, setData] = React.useState({
|
|
email: '',
|
|
status: 'initial',
|
|
});
|
|
|
|
const handleSubmit = (event) => {
|
|
event.preventDefault();
|
|
setData((current) => ({ ...current, status: 'loading' }));
|
|
try {
|
|
// Replace timeout with real backend operation
|
|
setTimeout(() => {
|
|
setData({ email: '', status: 'sent' });
|
|
}, 1500);
|
|
} catch (error) {
|
|
setData((current) => ({ ...current, status: 'failure' }));
|
|
}
|
|
};
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit} id="demo">
|
|
<FormControl>
|
|
<FormLabel
|
|
sx={(theme) => ({
|
|
'--FormLabel-color': theme.vars.palette.primary.plainColor,
|
|
})}
|
|
>
|
|
MUI Newsletter
|
|
</FormLabel>
|
|
<Input
|
|
sx={{ '--Input-decoratorChildHeight': '45px' }}
|
|
placeholder="mail@mui.com"
|
|
type="email"
|
|
required
|
|
value={data.email}
|
|
onChange={(event) =>
|
|
setData({ email: event.target.value, status: 'initial' })
|
|
}
|
|
error={data.status === 'failure'}
|
|
endDecorator={
|
|
<Button
|
|
variant="solid"
|
|
color="primary"
|
|
loading={data.status === 'loading'}
|
|
type="submit"
|
|
sx={{ borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }}
|
|
>
|
|
Subscribe
|
|
</Button>
|
|
}
|
|
/>
|
|
{data.status === 'failure' && (
|
|
<FormHelperText
|
|
sx={(theme) => ({ color: theme.vars.palette.danger[400] })}
|
|
>
|
|
Oops! something went wrong, please try again later.
|
|
</FormHelperText>
|
|
)}
|
|
{data.status === 'sent' && (
|
|
<FormHelperText
|
|
sx={(theme) => ({ color: theme.vars.palette.primary[400] })}
|
|
>
|
|
You are all set!
|
|
</FormHelperText>
|
|
)}
|
|
</FormControl>
|
|
</form>
|
|
);
|
|
}
|