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.

ContactForm.tsx 3.4KB

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 { BASE_PAGE } from '../../../constants/pages';
  13. import { contactSchema } from '../../../schemas/contactSchema';
  14. interface FormValues {
  15. firstName: string;
  16. lastName: string;
  17. email: string;
  18. message: string;
  19. }
  20. const ContactForm = () => {
  21. const { t } = useTranslation(['forms', 'contact', 'common']);
  22. const handleSubmit = (values: FormValues) => {
  23. console.log('Values', values);
  24. };
  25. const formik = useFormik({
  26. initialValues: {
  27. firstName: '',
  28. lastName: '',
  29. email: '',
  30. message: '',
  31. },
  32. validationSchema: contactSchema,
  33. onSubmit: handleSubmit,
  34. validateOnBlur: true,
  35. enableReinitialize: true,
  36. });
  37. return (
  38. <Container component="main" maxWidth="md">
  39. <Box
  40. sx={{
  41. marginTop: 32,
  42. display: 'flex',
  43. flexDirection: 'column',
  44. alignItems: 'center',
  45. }}
  46. >
  47. <Typography component="h1" variant="h5">
  48. {t('contact:Title')}
  49. </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}>{t('common:Back')}</Link>
  111. </Grid>
  112. </Box>
  113. </Box>
  114. </Container>
  115. );
  116. };
  117. export default ContactForm;