1+ // import from 3rd party
2+ import React from "react" ;
3+ import PropTypes from "prop-types" ;
4+
5+ // import from application dependency
6+ import { Button , FormLayout } from "Components" ;
7+ import { useTranslate , useTranslateState } from "Translate" ;
8+ import { withRouter } from "Services" ;
9+ import {
10+ DynamicForm ,
11+ useDynamicForm ,
12+ withDynamicForm ,
13+ } from "@wavelop/dynamic-form" ;
14+
15+ import { form as formConfig } from "./config.js" ;
16+
17+ function MultipleForm1 ( props ) {
18+
19+ const { language } = useTranslateState ( )
20+
21+ const dynamicForm = useDynamicForm ( ) ;
22+
23+ // Custom Hooks
24+ const i18n = useTranslate ( ) ;
25+ const { t } = i18n ;
26+
27+ const onSubmit = ( kind ) => event => {
28+
29+ event . preventDefault ( ) ;
30+
31+ try {
32+ const { state, stateCrypted, stateFull, stateGroupedByRows } = dynamicForm . submit ( ) ;
33+
34+ console . log ( kind , state , stateCrypted , stateFull , stateGroupedByRows ) ;
35+
36+ props . update ( { state} ) ;
37+
38+ } catch ( { errors} ) {
39+ props . update ( { errors} ) ;
40+ }
41+ } ;
42+
43+ return (
44+ < section style = { {
45+ maxWidth : "1024px" ,
46+ margin : "0 auto"
47+ } } >
48+
49+ < form onSubmit = { onSubmit ( 0 ) } >
50+ < DynamicForm
51+ config = { formConfig ( {
52+ t,
53+ dynamics : {
54+ locale : language
55+ }
56+ } ) }
57+ updateErrorAtBlur = { true }
58+ layout = { FormLayout }
59+ />
60+
61+ < Button
62+ type = "submit"
63+ fullWidth
64+ variant = "contained"
65+ color = "primary"
66+ >
67+ { t ( "Signup.confirm" ) }
68+ </ Button >
69+ </ form >
70+ </ section >
71+ ) ;
72+ }
73+
74+ MultipleForm1 . propTypes = {
75+ classes : PropTypes . object
76+ } ;
77+
78+ const Form1 = withDynamicForm ( { encryption : ( value ) => {
79+ return window . btoa ( value ) ;
80+ } } ) ( MultipleForm1 ) ;
81+
82+ function MultipleForm2 ( props ) {
83+
84+ const { language } = useTranslateState ( )
85+
86+ const dynamicForm = useDynamicForm ( ) ;
87+
88+ // Custom Hooks
89+ const i18n = useTranslate ( ) ;
90+ const { t } = i18n ;
91+
92+ const onSubmit = ( kind ) => event => {
93+
94+ event . preventDefault ( ) ;
95+
96+ try {
97+ const { state, stateCrypted, stateFull, stateGroupedByRows } = dynamicForm . submit ( ) ;
98+
99+ console . log ( kind , state , stateCrypted , stateFull , stateGroupedByRows ) ;
100+
101+ props . update ( { state} ) ;
102+
103+ } catch ( { errors} ) {
104+ props . update ( { errors} ) ;
105+ }
106+ } ;
107+
108+ return (
109+ < section style = { {
110+ maxWidth : "1024px" ,
111+ margin : "0 auto"
112+ } } >
113+
114+ < form onSubmit = { onSubmit ( 1 ) } >
115+ < DynamicForm
116+ config = { formConfig ( {
117+ t,
118+ dynamics : {
119+ locale : language
120+ }
121+ } ) }
122+ updateErrorAtBlur = { true }
123+ layout = { FormLayout }
124+ />
125+
126+ < Button
127+ type = "submit"
128+ fullWidth
129+ variant = "contained"
130+ color = "primary"
131+ >
132+ { t ( "Signup.confirm" ) }
133+ </ Button >
134+ </ form >
135+ </ section >
136+ ) ;
137+ }
138+
139+ MultipleForm2 . propTypes = {
140+ classes : PropTypes . object
141+ } ;
142+
143+ const Form2 = withDynamicForm ( { encryption : ( value ) => {
144+ return window . btoa ( value ) ;
145+ } } ) ( MultipleForm2 ) ;
146+
147+ function Signup ( ) {
148+
149+ return (
150+ < section style = { {
151+ maxWidth : "1024px" ,
152+ margin : "0 auto"
153+ } } >
154+
155+ < Form1 update = { ( result ) => {
156+ console . log ( result ) ;
157+ } } />
158+
159+ < Form2 update = { ( result ) => {
160+ console . log ( result ) ;
161+ } } />
162+
163+ </ section >
164+ ) ;
165+ }
166+
167+ Signup . propTypes = {
168+ classes : PropTypes . object
169+ } ;
170+
171+ export default withRouter ( ) ( Signup ) ;
0 commit comments