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.tsx 4.1KB

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