Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ContactPageForm.jsx 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import {
  2. Box,
  3. Button,
  4. Container,
  5. Grid,
  6. TextField,
  7. Typography,
  8. } from '@mui/material';
  9. import { useFormik } from 'formik';
  10. import { useTranslation } from 'next-i18next';
  11. import Link from 'next/link';
  12. import PropType from 'prop-types';
  13. import React from 'react';
  14. import { BASE_PAGE } from '../../../constants/pages';
  15. import { contactPageSchema } from '../../../schemas/contactSchema';
  16. const ContactPageForm = () => {
  17. const { t } = useTranslation('forms', 'contact', 'common');
  18. //const [error] = useState({ hasError: false, errorMessage: '' });
  19. const handleSubmit = async (values) => {
  20. console.log(values);
  21. };
  22. const formik = useFormik({
  23. initialValues: {
  24. firstName: '',
  25. lastName: '',
  26. email: '',
  27. message: '',
  28. },
  29. validationSchema: contactPageSchema,
  30. onSubmit: handleSubmit,
  31. validateOnBlur: true,
  32. enableReinitialize: true,
  33. });
  34. return (
  35. <Container component="main" maxWidth="md" sx={{ mb: '60px' }}>
  36. <Box
  37. sx={{
  38. marginTop: 32,
  39. display: 'flex',
  40. flexDirection: 'column',
  41. alignItems: 'center',
  42. }}
  43. >
  44. <Typography fontSize={48}>{t('contact:Title')}</Typography>
  45. <Box
  46. component="form"
  47. onSubmit={formik.handleSubmit}
  48. sx={{ position: 'relative', mt: 1, p: 1 }}
  49. >
  50. <TextField
  51. name="firstName"
  52. label={t('forms:FirstName')}
  53. margin="normal"
  54. value={formik.values.firstName}
  55. onChange={formik.handleChange}
  56. error={formik.touched.firstName && Boolean(formik.errors.firstName)}
  57. helperText={formik.touched.firstName && formik.errors.firstName}
  58. autoFocus
  59. fullWidth
  60. />
  61. <TextField
  62. name="lastName"
  63. label={t('forms:LastName')}
  64. margin="normal"
  65. value={formik.values.lastName}
  66. onChange={formik.handleChange}
  67. error={formik.touched.lastName && Boolean(formik.errors.lastName)}
  68. helperText={formik.touched.lastName && formik.errors.lastName}
  69. autoFocus
  70. fullWidth
  71. />
  72. <TextField
  73. name="email"
  74. label={t('forms:Email')}
  75. margin="normal"
  76. value={formik.values.email}
  77. onChange={formik.handleChange}
  78. error={formik.touched.email && Boolean(formik.errors.email)}
  79. helperText={formik.touched.email && formik.errors.email}
  80. autoFocus
  81. fullWidth
  82. />
  83. <TextField
  84. name="message"
  85. label={t('forms:Message')}
  86. multiline
  87. margin="normal"
  88. value={formik.values.message}
  89. onChange={formik.handleChange}
  90. error={formik.touched.message && Boolean(formik.errors.message)}
  91. helperText={formik.touched.message && formik.errors.message}
  92. rows={4}
  93. autoFocus
  94. fullWidth
  95. />
  96. <Button
  97. type="submit"
  98. variant="contained"
  99. sx={{ mt: 3, mb: 2 }}
  100. fullWidth
  101. >
  102. {t('contact:SendBtn')}
  103. </Button>
  104. <Grid container justifyContent="center">
  105. <Link href={BASE_PAGE}>
  106. <Typography>{t('common:Back')}</Typography>
  107. </Link>
  108. </Grid>
  109. </Box>
  110. </Box>
  111. </Container>
  112. );
  113. };
  114. ContactPageForm.propTypes = {
  115. submitHandler: PropType.func,
  116. };
  117. export default ContactPageForm;