Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ContactPageForm.tsx 3.9KB

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