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.6KB

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