Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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