|
@@ -15,14 +15,6 @@ const ROLE = {
|
15
|
15
|
CANDIDATO: 3,
|
16
|
16
|
}
|
17
|
17
|
|
18
|
|
-function Marked({ step }) {
|
19
|
|
- return (<strong className="important_marked">{step}</strong>)
|
20
|
|
-}
|
21
|
|
-
|
22
|
|
-function Title({ title, step }) {
|
23
|
|
- return (<p className="titleMarked"><Marked /> {title}</p>)
|
24
|
|
-}
|
25
|
|
-
|
26
|
18
|
function PasswordInfoForm({ setUser, user }) {
|
27
|
19
|
|
28
|
20
|
return (
|
|
@@ -178,22 +170,16 @@ export function TypePwd(props) {
|
178
|
170
|
"pwd": body.password,
|
179
|
171
|
"idEmpresa": profile.id,
|
180
|
172
|
}
|
181
|
|
- let response = await rest.post(req,auth.token)
|
182
|
|
- if(response.status === 200){
|
183
|
|
- return response.data.id
|
184
|
|
- }else{
|
185
|
|
- return 0
|
186
|
|
- }
|
187
|
|
- console.log(response)
|
|
173
|
+ let response = await rest.post(req, auth.token)
|
|
174
|
+ return response.id || 0;
|
188
|
175
|
} catch (e) {
|
189
|
|
- console.log(e)
|
|
176
|
+ console.log('CATCH:', e)
|
190
|
177
|
return 0;
|
191
|
178
|
}
|
192
|
179
|
}
|
193
|
180
|
|
194
|
181
|
const saveUser = async () => {
|
195
|
182
|
//TODO: trigger form submit
|
196
|
|
-
|
197
|
183
|
if (user === null || !user || user === undefined) return toast.error('Falta informacion del usuario')
|
198
|
184
|
|
199
|
185
|
let { email, password } = user
|
|
@@ -206,16 +192,30 @@ export function TypePwd(props) {
|
206
|
192
|
|
207
|
193
|
if (userType === ROLE.ASISTENTE && selectedRole.length === 0) return toast.error('Selecciona al menos un rol')
|
208
|
194
|
|
209
|
|
- console.log('saveUser:', user)
|
210
|
195
|
let id = await postUser(user)
|
211
|
|
- if(id === 0) return toast.error('Ocurrio un error al crear el usuario')
|
|
196
|
+ if (id === 0) return toast.error('Ocurrio un error al crear el usuario')
|
212
|
197
|
toast.success('Usuario creado con exito')
|
213
|
198
|
console.log("id:", id)
|
|
199
|
+ if (userType === ROLE.ASISTENTE) postResources(id)
|
|
200
|
+ clearForm()
|
214
|
201
|
|
215
|
|
- //TODO: save roles
|
|
202
|
+ }
|
216
|
203
|
|
|
204
|
+ const postResources = (user_id) => {
|
|
205
|
+ let rest = new Service('/rolAdd/' + user_id)
|
|
206
|
+ let selected = selectedRole.map(id => ({ id: id, path: "" }))
|
|
207
|
+ console.log('selected:', selected)
|
|
208
|
+ let saved = rest.post(selected, auth.token)
|
|
209
|
+ console.log('saved:', saved)
|
217
|
210
|
}
|
218
|
211
|
|
|
212
|
+ const clearForm = () => {
|
|
213
|
+ setUser(null)
|
|
214
|
+ setSelectedRole([])
|
|
215
|
+ setUserType(ROLE.CANDIDATO)
|
|
216
|
+ }
|
|
217
|
+
|
|
218
|
+
|
219
|
219
|
useEffect(() => {
|
220
|
220
|
|
221
|
221
|
const getRecursos = () => {
|