|
@@ -1,9 +1,9 @@
|
1
|
|
-import { useState } from 'react'
|
2
|
|
-import { useFormik, Form, FormikProvider } from 'formik';
|
|
1
|
+import { useState } from 'react'
|
|
2
|
+import { useFormik, Form, FormikProvider } from 'formik';
|
3
|
3
|
import { useNavigate } from 'react-router-dom';
|
4
|
|
-import {
|
5
|
|
- Stack, TextField,Box, Button,
|
6
|
|
- Backdrop, CircularProgress,
|
|
4
|
+import {
|
|
5
|
+ Stack, TextField, Box, Button,
|
|
6
|
+ Backdrop, CircularProgress,
|
7
|
7
|
} from '@mui/material';
|
8
|
8
|
import toast, { Toaster } from 'react-hot-toast';
|
9
|
9
|
import * as Yup from 'yup';
|
|
@@ -13,165 +13,165 @@ import { Service } from '../../Utils/HTTP';
|
13
|
13
|
|
14
|
14
|
export function PersonalInfo(props) {
|
15
|
15
|
|
16
|
|
- let { handleBack, setClient, client } = props
|
17
|
|
-
|
18
|
|
- let navigate = useNavigate()
|
19
|
|
-
|
20
|
|
- const RegisterSchema = Yup.object().shape({
|
21
|
|
- nit: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nit es requerido'),
|
22
|
|
- cui: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('Tu CUI/DPI es requerido'),
|
23
|
|
- direccion: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('La direccion es requerida'),
|
24
|
|
- nacimiento: Yup.date().required('Tu fecha nacimiento es requerida'),
|
25
|
|
- telefono: Yup.number('Ingresa únicamente números').required('Tu numero de telefono es requerido')
|
26
|
|
- });
|
27
|
|
-
|
28
|
|
- let [open, setOpen] = useState(false);
|
29
|
|
-
|
30
|
|
- const formik = useFormik({
|
31
|
|
- initialValues: {
|
32
|
|
- nit: client.nit,
|
33
|
|
- cui: client.cui,
|
34
|
|
- direccion: client.direccion,
|
35
|
|
- nacimiento: client.nacimiento,
|
36
|
|
- telefono: client.telefono
|
37
|
|
- },
|
38
|
|
- validationSchema: RegisterSchema,
|
39
|
|
- onSubmit: (values) => {
|
40
|
|
- setOpen(true);
|
41
|
|
-
|
42
|
|
- let new_client = {
|
43
|
|
- ...client, ...values
|
44
|
|
- }
|
45
|
|
- setClient(new_client)
|
46
|
|
-
|
47
|
|
- let body = {
|
48
|
|
- "nombre" : new_client.firstName,
|
49
|
|
- "apelidos" : new_client.lastName,
|
50
|
|
- "telefono" : new_client.telefono,
|
51
|
|
- "direccio": new_client.direccion,
|
52
|
|
- "fechacumple": new_client.nacimiento,
|
53
|
|
- "nit": new_client.nit,
|
54
|
|
- "cui": new_client.cui,
|
55
|
|
- "email": new_client.email,
|
56
|
|
- "username": new_client.email,
|
57
|
|
- "pwd": new_client.password
|
58
|
|
- }
|
59
|
|
-
|
60
|
|
-
|
61
|
|
- let req = new Service('/registro');
|
62
|
|
-
|
63
|
|
- req
|
64
|
|
- .post(body)
|
65
|
|
- .then( data => {
|
66
|
|
-
|
67
|
|
- setTimeout(() => {
|
68
|
|
- setOpen(false);
|
69
|
|
- return navigate('/')
|
70
|
|
- }, 2000)
|
71
|
|
-
|
72
|
|
- console.log("DATA ::", data)
|
73
|
|
- let nombre = client.firstName + " " + client.lastName
|
74
|
|
- toast.success(`Bienvenido ${nombre} !!`)
|
75
|
|
-
|
76
|
|
-
|
77
|
|
- })
|
78
|
|
- .catch(error => {
|
79
|
|
- console.log("ERROR ::", error)
|
80
|
|
- toast.error(`Ups ocurrió un error puede que tu usuario yo exista o sea un error interno, intenta nuevamente más tarde o ponte en contacto con nosotros`)
|
81
|
|
- return setOpen(false);
|
82
|
|
- })
|
83
|
|
-
|
84
|
|
- }
|
85
|
|
- });
|
86
|
|
-
|
87
|
|
-
|
88
|
|
- const { errors, touched, handleSubmit, getFieldProps } = formik;
|
89
|
|
-
|
90
|
|
- return(
|
91
|
|
- <FormikProvider style={{ padding : 15}} value={formik}>
|
92
|
|
- <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
|
93
|
|
- <Stack spacing={3}>
|
94
|
|
- <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
95
|
|
- <TextField
|
96
|
|
- label="Numero de Nit"
|
97
|
|
- fullWidth
|
98
|
|
- {...getFieldProps('nit')}
|
99
|
|
- error={Boolean(touched.nit && errors.nit)}
|
100
|
|
- helperText={touched.nit && errors.nit}
|
101
|
|
- />
|
102
|
|
-
|
103
|
|
- <TextField
|
104
|
|
- label="CUI/DPI"
|
105
|
|
- fullWidth
|
106
|
|
- {...getFieldProps('cui')}
|
107
|
|
- error={Boolean(touched.cui && errors.cui)}
|
108
|
|
- helperText={touched.cui && errors.cui}
|
109
|
|
- />
|
110
|
|
- </Stack>
|
111
|
|
-
|
112
|
|
- <TextField
|
113
|
|
- fullWidth
|
114
|
|
- type="text"
|
115
|
|
- label="Dirección"
|
116
|
|
- {...getFieldProps('direccion')}
|
117
|
|
- error={Boolean(touched.direccion && errors.direccion)}
|
118
|
|
- helperText={touched.direccion && errors.direccion}
|
119
|
|
- />
|
120
|
|
-
|
121
|
|
- <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
122
|
|
- <TextField
|
123
|
|
- type="date"
|
124
|
|
- label="Fecha de nacimiento"
|
125
|
|
- fullWidth
|
126
|
|
- InputLabelProps={{ required: true }}
|
127
|
|
- {...getFieldProps('nacimiento')}
|
128
|
|
- error={Boolean(touched.nacimiento && errors.nacimiento)}
|
129
|
|
- helperText={touched.nacimiento && errors.nacimiento}
|
130
|
|
- />
|
131
|
|
-
|
132
|
|
- <TextField
|
133
|
|
- label="Telefono"
|
134
|
|
- fullWidth
|
135
|
|
- {...getFieldProps('telefono')}
|
136
|
|
- error={Boolean(touched.telefono && errors.telefono)}
|
137
|
|
- helperText={touched.telefono && errors.telefono}
|
138
|
|
- />
|
139
|
|
- </Stack>
|
140
|
|
-
|
141
|
|
- <Box sx={{ mb: 2 }}>
|
142
|
|
- <div style={{ paddingTop: 15 }}>
|
143
|
|
- <Button
|
144
|
|
- type="submit"
|
145
|
|
- className="registerBtn"
|
146
|
|
- variant="contained"
|
147
|
|
- // onClick={handleNext}
|
148
|
|
- sx={{ mt: 1, mr: 1 }}
|
149
|
|
- >
|
150
|
|
- {'Registrarme'}
|
151
|
|
- </Button>
|
152
|
|
- <Button
|
153
|
|
- onClick={handleBack}
|
154
|
|
- sx={{ mt: 1, mr: 1 }}
|
155
|
|
- >
|
156
|
|
- Regresar
|
157
|
|
- </Button>
|
158
|
|
- </div>
|
159
|
|
- </Box>
|
160
|
|
-
|
161
|
|
- </Stack>
|
162
|
|
-
|
163
|
|
- </Form>
|
164
|
|
- <Toaster
|
165
|
|
- position="top-center"
|
166
|
|
- reverseOrder={false}
|
|
16
|
+ let { handleBack, setClient, client } = props
|
|
17
|
+
|
|
18
|
+ let navigate = useNavigate()
|
|
19
|
+
|
|
20
|
+ const RegisterSchema = Yup.object().shape({
|
|
21
|
+ nit: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nit es requerido'),
|
|
22
|
+ cui: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('Tu CUI/DPI es requerido'),
|
|
23
|
+ direccion: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('La direccion es requerida'),
|
|
24
|
+ nacimiento: Yup.date().required('Tu fecha nacimiento es requerida'),
|
|
25
|
+ telefono: Yup.number('Ingresa únicamente números').required('Tu numero de telefono es requerido')
|
|
26
|
+ });
|
|
27
|
+
|
|
28
|
+ let [open, setOpen] = useState(false);
|
|
29
|
+
|
|
30
|
+ const formik = useFormik({
|
|
31
|
+ initialValues: {
|
|
32
|
+ nit: client.nit,
|
|
33
|
+ cui: client.cui,
|
|
34
|
+ direccion: client.direccion,
|
|
35
|
+ nacimiento: client.nacimiento,
|
|
36
|
+ telefono: client.telefono
|
|
37
|
+ },
|
|
38
|
+ validationSchema: RegisterSchema,
|
|
39
|
+ onSubmit: (values) => {
|
|
40
|
+ setOpen(true);
|
|
41
|
+
|
|
42
|
+ let new_client = {
|
|
43
|
+ ...client, ...values
|
|
44
|
+ }
|
|
45
|
+ setClient(new_client)
|
|
46
|
+
|
|
47
|
+ let body = {
|
|
48
|
+ "nombre": new_client.firstName,
|
|
49
|
+ "apelidos": new_client.lastName,
|
|
50
|
+ "telefono": new_client.telefono,
|
|
51
|
+ "direccio": new_client.direccion,
|
|
52
|
+ "fechacumple": new_client.nacimiento,
|
|
53
|
+ "nit": new_client.nit,
|
|
54
|
+ "cui": new_client.cui,
|
|
55
|
+ "email": new_client.email,
|
|
56
|
+ "username": new_client.email,
|
|
57
|
+ "pwd": new_client.password,
|
|
58
|
+ "empresa": new_client.empresa
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ let req = new Service('/registro');
|
|
62
|
+
|
|
63
|
+ req
|
|
64
|
+ .post(body)
|
|
65
|
+ .then(data => {
|
|
66
|
+
|
|
67
|
+ setTimeout(() => {
|
|
68
|
+ setOpen(false);
|
|
69
|
+ return navigate('/')
|
|
70
|
+ }, 2000)
|
|
71
|
+
|
|
72
|
+ console.log("DATA ::", data)
|
|
73
|
+ let nombre = client.firstName + " " + client.lastName
|
|
74
|
+ toast.success(`Bienvenido ${nombre} !!`)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+ })
|
|
78
|
+ .catch(error => {
|
|
79
|
+ console.log("ERROR ::", error)
|
|
80
|
+ toast.error(`Ups ocurrió un error puede que tu usuario yo exista o sea un error interno, intenta nuevamente más tarde o ponte en contacto con nosotros`)
|
|
81
|
+ return setOpen(false);
|
|
82
|
+ })
|
|
83
|
+
|
|
84
|
+ }
|
|
85
|
+ });
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+ const { errors, touched, handleSubmit, getFieldProps } = formik;
|
|
89
|
+
|
|
90
|
+ return (
|
|
91
|
+ <FormikProvider style={{ padding: 15 }} value={formik}>
|
|
92
|
+ <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
|
|
93
|
+ <Stack spacing={3}>
|
|
94
|
+ <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
|
95
|
+ <TextField
|
|
96
|
+ label="Numero de Nit"
|
|
97
|
+ fullWidth
|
|
98
|
+ {...getFieldProps('nit')}
|
|
99
|
+ error={Boolean(touched.nit && errors.nit)}
|
|
100
|
+ helperText={touched.nit && errors.nit}
|
167
|
101
|
/>
|
168
|
|
- <Backdrop
|
169
|
|
- sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
|
170
|
|
- open={open}
|
171
|
|
- onClick={() => false}
|
172
|
|
- >
|
173
|
|
- <CircularProgress color="inherit" />
|
174
|
|
- </Backdrop>
|
175
|
|
- </FormikProvider>
|
176
|
|
- )
|
|
102
|
+
|
|
103
|
+ <TextField
|
|
104
|
+ label="CUI/DPI"
|
|
105
|
+ fullWidth
|
|
106
|
+ {...getFieldProps('cui')}
|
|
107
|
+ error={Boolean(touched.cui && errors.cui)}
|
|
108
|
+ helperText={touched.cui && errors.cui}
|
|
109
|
+ />
|
|
110
|
+ </Stack>
|
|
111
|
+
|
|
112
|
+ <TextField
|
|
113
|
+ fullWidth
|
|
114
|
+ type="text"
|
|
115
|
+ label="Dirección"
|
|
116
|
+ {...getFieldProps('direccion')}
|
|
117
|
+ error={Boolean(touched.direccion && errors.direccion)}
|
|
118
|
+ helperText={touched.direccion && errors.direccion}
|
|
119
|
+ />
|
|
120
|
+
|
|
121
|
+ <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
|
122
|
+ <TextField
|
|
123
|
+ type="date"
|
|
124
|
+ label="Fecha de nacimiento"
|
|
125
|
+ fullWidth
|
|
126
|
+ InputLabelProps={{ required: true }}
|
|
127
|
+ {...getFieldProps('nacimiento')}
|
|
128
|
+ error={Boolean(touched.nacimiento && errors.nacimiento)}
|
|
129
|
+ helperText={touched.nacimiento && errors.nacimiento}
|
|
130
|
+ />
|
|
131
|
+
|
|
132
|
+ <TextField
|
|
133
|
+ label="Telefono"
|
|
134
|
+ fullWidth
|
|
135
|
+ {...getFieldProps('telefono')}
|
|
136
|
+ error={Boolean(touched.telefono && errors.telefono)}
|
|
137
|
+ helperText={touched.telefono && errors.telefono}
|
|
138
|
+ />
|
|
139
|
+ </Stack>
|
|
140
|
+
|
|
141
|
+ <Box sx={{ mb: 2 }}>
|
|
142
|
+ <div style={{ paddingTop: 15 }}>
|
|
143
|
+ <Button
|
|
144
|
+ type="submit"
|
|
145
|
+ className="registerBtn"
|
|
146
|
+ variant="contained"
|
|
147
|
+ // onClick={handleNext}
|
|
148
|
+ sx={{ mt: 1, mr: 1 }}
|
|
149
|
+ >
|
|
150
|
+ {'Registrarme'}
|
|
151
|
+ </Button>
|
|
152
|
+ <Button
|
|
153
|
+ onClick={handleBack}
|
|
154
|
+ sx={{ mt: 1, mr: 1 }}
|
|
155
|
+ >
|
|
156
|
+ Regresar
|
|
157
|
+ </Button>
|
|
158
|
+ </div>
|
|
159
|
+ </Box>
|
|
160
|
+
|
|
161
|
+ </Stack>
|
|
162
|
+
|
|
163
|
+ </Form>
|
|
164
|
+ <Toaster
|
|
165
|
+ position="top-center"
|
|
166
|
+ reverseOrder={false}
|
|
167
|
+ />
|
|
168
|
+ <Backdrop
|
|
169
|
+ sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
|
|
170
|
+ open={open}
|
|
171
|
+ onClick={() => false}
|
|
172
|
+ >
|
|
173
|
+ <CircularProgress color="inherit" />
|
|
174
|
+ </Backdrop>
|
|
175
|
+ </FormikProvider>
|
|
176
|
+ )
|
177
|
177
|
}
|