Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 KB | None | 0 0
  1. /* eslint-disable no-template-curly-in-string */
  2. import React, { Component } from 'react';
  3. import { Formik } from 'formik';
  4. import * as Yup from 'yup';
  5. import { setLocale } from 'yup';
  6. import './AuthForm.css';
  7. import { Form, Col, Button, Container } from 'react-bootstrap';
  8. import FormInput from "../../../components/Form/Input";
  9.  
  10. setLocale({
  11. mixed: {
  12. default: 'Não é válido',
  13. required: '${path} é necessário',
  14. },
  15. number: {
  16. min: 'Deve ser maior que ${min}',
  17. },
  18. string: {
  19. min: 'Mínimo de ${min} caracteres'
  20. }
  21. });
  22.  
  23. export default class AuthForm extends Component {
  24. schema = Yup.object().shape({
  25. name: Yup.string().min(3).required().label("Nome"),
  26. email: Yup.string().email().required().label("Email"),
  27. password: Yup.string().min(6).required().label("Senha"),
  28. passwordConfirmation: Yup.string().required().label("Confirmação de Senha")
  29. .oneOf([Yup.ref('password')], 'Senhas devem coincidir')
  30. })
  31.  
  32. render() {
  33. return (
  34. <Formik
  35. initialValues={{
  36. name: '',
  37. email: '',
  38. password: '',
  39. passwordConfirmation: ''
  40. }}
  41. validationSchema={this.schema}
  42. onSubmit={(values, actions) => {
  43. // same shape as initial values
  44. console.log(values);
  45. actions.setSubmitting(false);
  46. }}
  47. >
  48. {({ handleSubmit,
  49. isSubmitting,
  50. ...formik }) => (
  51. <Form onSubmit={handleSubmit}>
  52. <Container style={{ width: "100%", margin: "auto" }}>
  53. <Form.Row bsPrefix="row justify-content-center">
  54. <Form.Group as={Col} md={8} controlId="validationName">
  55. <Form.Label>Nome</Form.Label>
  56. <FormInput feedback="Belo Nome!" formik={formik}>
  57. <Form.Control
  58. type="text"
  59. name="name"
  60. placeholder="Seu Nome"
  61. />
  62. </FormInput>
  63. </Form.Group>
  64. </Form.Row>
  65. <Form.Row bsPrefix="row justify-content-center">
  66. <Form.Group as={Col} md={8} controlId="validationEmail">
  67. <Form.Label>Email</Form.Label>
  68. <FormInput feedback="Email Bonito!" formik={formik}>
  69. <Form.Control
  70. type="email"
  71. name="email"
  72. placeholder="Seu melhor Email"
  73. />
  74. </FormInput>
  75. </Form.Group>
  76. </Form.Row>
  77. <Form.Row bsPrefix="row justify-content-center">
  78. <Form.Group as={Col} md={4} controlId="validationPassword">
  79. <Form.Label>Senha</Form.Label>
  80. <FormInput feedback="Deveras Seguro!" formik={formik}>
  81. <Form.Control
  82. type="password"
  83. name="password"
  84. placeholder="Sua senha"
  85. />
  86. </FormInput>
  87. </Form.Group>
  88. <Form.Group as={Col} md={4} controlId="validationPasswordConfirmation">
  89. <Form.Label>Confirmar Senha</Form.Label>
  90. <FormInput feedback="Já vi isso antes!" formik={formik}>
  91. <Form.Control
  92. type="password"
  93. name="passwordConfirmation"
  94. placeholder="Sua senha - O Retorno"
  95. />
  96. </FormInput>
  97. </Form.Group>
  98. </Form.Row>
  99. <Form.Row bsPrefix="row justify-content-center">
  100. <Form.Group as={Col} md={8} controlId="authSubmissionButton">
  101. <Button
  102. block
  103. size="lg"
  104. variant="success"
  105. type="submit"
  106. disabled={isSubmitting}
  107. >
  108. Enviar
  109. </Button>
  110. </Form.Group>
  111. </Form.Row>
  112. </Container>
  113. </Form>
  114. )}
  115. </Formik>
  116. )
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement