File tree Expand file tree Collapse file tree
src/pods/employee/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5050 "emotion" : " ^10.0.23" ,
5151 "final-form" : " ^4.18.6" ,
5252 "formik" : " ^2.1.4" ,
53+ "immer" : " ^6.0.3" ,
5354 "graphql-request" : " ^1.8.2" ,
5455 "lodash.flowright" : " ^3.5.0" ,
5556 "lodash.get" : " ^4.4.2" ,
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import { Formik , Form } from 'formik' ;
33import { TextFieldComponent , CheckboxComponent } from 'common/components' ;
4+ import produce from 'immer' ;
45import { CommandFooterComponent } from '../../../common-app/command-footer' ;
56import * as classes from './data.styles' ;
67import { cx } from 'emotion' ;
78import { Employee } from '../employee.vm' ;
9+ import { formValidation , validationSchema } from './data.validations' ;
10+ import { Validators } from '@lemoncode/fonk' ;
811
912interface Props {
1013 employee : Employee ;
@@ -21,11 +24,19 @@ export const DataComponent: React.FunctionComponent<Props> = ({
2124 isEditMode,
2225 onCancel,
2326} ) => {
27+ React . useEffect ( ( ) => {
28+ const newValidationSchema = produce ( validationSchema , darft => {
29+ darft . field . temporalPassword = isEditMode ? [ ] : [ Validators . required ] ;
30+ } ) ;
31+ formValidation . updateValidationSchema ( newValidationSchema ) ;
32+ } , [ isEditMode ] ) ;
33+
2434 return (
2535 < Formik
2636 initialValues = { employee }
2737 enableReinitialize = { true }
2838 onSubmit = { onSave }
39+ validate = { formValidation . validateForm }
2940 >
3041 { ( ) => (
3142 < Form className = { cx ( classes . form ( { isEditMode } ) , className ) } >
Original file line number Diff line number Diff line change 1+ import { ValidationSchema , Validators } from '@lemoncode/fonk' ;
2+ import { createFormikValidation } from '@lemoncode/fonk-formik' ;
3+ import { matchField } from '@lemoncode/fonk-match-field-validator' ;
4+
5+ export const validationSchema : ValidationSchema = {
6+ field : {
7+ name : [
8+ {
9+ validator : Validators . required ,
10+ message : 'Campo obligatorio' ,
11+ } ,
12+ ] ,
13+ email : [
14+ {
15+ validator : Validators . email ,
16+ message : 'Introduce un email válido' ,
17+ } ,
18+ {
19+ validator : Validators . required ,
20+ message : 'Campo obligatorio' ,
21+ } ,
22+ ] ,
23+ temporalPassword : [
24+ {
25+ validator : matchField . validator ,
26+ customArgs : { field : 'password' } ,
27+ } ,
28+ ] ,
29+ } ,
30+ } ;
31+
32+ export const formValidation = createFormikValidation ( validationSchema ) ;
You can’t perform that action at this time.
0 commit comments