|
@@ -0,0 +1,164 @@
|
|
1
|
+import { useEffect, useState } from 'react'
|
|
2
|
+import { Service } from '../../../Utils/HTTP.js'
|
|
3
|
+import { useSelector } from 'react-redux'
|
|
4
|
+import {
|
|
5
|
+ FormControl, RadioGroup, FormControlLabel, Radio, FormLabel, Checkbox,
|
|
6
|
+ TextField, Box
|
|
7
|
+} from '@mui/material'
|
|
8
|
+
|
|
9
|
+import { Simple as Loading } from '../../Generics/loading.jsx'
|
|
10
|
+
|
|
11
|
+function Marked({ step }) {
|
|
12
|
+ return (<strong className="important_marked">{step}</strong>)
|
|
13
|
+}
|
|
14
|
+
|
|
15
|
+function Title({ title, step }) {
|
|
16
|
+ return (<h5 className="titleMarked">{title}</h5>)
|
|
17
|
+}
|
|
18
|
+
|
|
19
|
+function PasswordInfoForm() {
|
|
20
|
+ return (
|
|
21
|
+ <Box
|
|
22
|
+ component="form"
|
|
23
|
+ sx={{
|
|
24
|
+ '& > :not(style)': { m: 1, width: '25ch' },
|
|
25
|
+ }}
|
|
26
|
+ noValidate
|
|
27
|
+ autoComplete="off"
|
|
28
|
+ >
|
|
29
|
+ <TextField id="outlined-basic" label="Outlined" variant="outlined" />
|
|
30
|
+ <TextField id="filled-basic" label="Filled" variant="filled" />
|
|
31
|
+ <TextField id="standard-basic" label="Standard" variant="standard" />
|
|
32
|
+ </Box>
|
|
33
|
+ );
|
|
34
|
+}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+export default function PermisosList(props) {
|
|
39
|
+ return (
|
|
40
|
+ <FormControl className="rolelist" >
|
|
41
|
+ <FormLabel id="demo-radio-buttons-group-label">{props.label}</FormLabel>
|
|
42
|
+ <RadioGroup
|
|
43
|
+ aria-labelledby="demo-radio-buttons-group-label"
|
|
44
|
+ defaultValue="female"
|
|
45
|
+ name="radio-buttons-group"
|
|
46
|
+ >
|
|
47
|
+ {
|
|
48
|
+
|
|
49
|
+ props.data.length === 0 ? <Loading /> :
|
|
50
|
+ props.data.map((r) => {
|
|
51
|
+ console.log(r)
|
|
52
|
+ return (
|
|
53
|
+ <FormControlLabel value={r.id} control={<Checkbox />} label={r.nombre} />
|
|
54
|
+ )
|
|
55
|
+ })
|
|
56
|
+ }
|
|
57
|
+ </RadioGroup>
|
|
58
|
+ </FormControl>
|
|
59
|
+ );
|
|
60
|
+}
|
|
61
|
+
|
|
62
|
+function TipoUsuarios(props) {
|
|
63
|
+ let { type, setType } = props
|
|
64
|
+ const handleChange = (event) => {
|
|
65
|
+ setType(event.target.value);
|
|
66
|
+ };
|
|
67
|
+
|
|
68
|
+ return (
|
|
69
|
+ <FormControl>
|
|
70
|
+ <FormLabel id="demo-radio-buttons-group-label">Nivel de Acceso</FormLabel>
|
|
71
|
+ <RadioGroup
|
|
72
|
+ className="seluser_type"
|
|
73
|
+ row
|
|
74
|
+ aria-labelledby="demo-row-radio-buttons-group-label"
|
|
75
|
+ name="row-radio-buttons-group"
|
|
76
|
+ value={type}
|
|
77
|
+ onChange={handleChange}
|
|
78
|
+ >
|
|
79
|
+ <FormControlLabel value={0} control={<Checkbox />} label="Administrador" />
|
|
80
|
+ <FormControlLabel value={1} control={<Checkbox />} label="Asistente" />
|
|
81
|
+ <FormControlLabel value={2} control={<Checkbox />} label="Candidato" />
|
|
82
|
+ </RadioGroup>
|
|
83
|
+ </FormControl>
|
|
84
|
+ );
|
|
85
|
+}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+export function TypePwd(props) {
|
|
89
|
+
|
|
90
|
+ let auth = useSelector(state => state.token)
|
|
91
|
+ let [recursos, setRecursos] = useState(null)
|
|
92
|
+ let [userType, setUserType] = useState(1)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+ useEffect(() => {
|
|
96
|
+
|
|
97
|
+ const getRecursos = () => {
|
|
98
|
+ let rest = new Service('/recursos/allow')
|
|
99
|
+ return rest.getQuery(auth.token);
|
|
100
|
+ }
|
|
101
|
+ const groupRecursos = (recursos) => {
|
|
102
|
+ let groups = {};
|
|
103
|
+ recursos.forEach((r) => {
|
|
104
|
+ if (groups[r.grupo]) {
|
|
105
|
+ groups[r.grupo].push(r)
|
|
106
|
+ } else {
|
|
107
|
+ groups[r.grupo] = [r]
|
|
108
|
+ }
|
|
109
|
+ })
|
|
110
|
+
|
|
111
|
+ assignRecursos(groups)
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ const assignRecursos = (recursos_api) => {
|
|
115
|
+ let templete = {
|
|
116
|
+ 1: { "label": 'Puestos', data: [] },
|
|
117
|
+ 2: { "label": 'Varios', data: [] },
|
|
118
|
+ 3: { "label": 'General', data: [] }
|
|
119
|
+ }
|
|
120
|
+
|
|
121
|
+ Object.keys(recursos_api)
|
|
122
|
+ .forEach((k) => {
|
|
123
|
+ templete[k].data = recursos_api[k];
|
|
124
|
+ })
|
|
125
|
+ console.log('BUILD:', templete)
|
|
126
|
+ setRecursos(templete)
|
|
127
|
+ }
|
|
128
|
+
|
|
129
|
+ getRecursos()
|
|
130
|
+ .then(({ data }) => groupRecursos(data))
|
|
131
|
+ .catch((err) => console.log('ERROR:', err))
|
|
132
|
+
|
|
133
|
+ }, [auth.token])
|
|
134
|
+
|
|
135
|
+ console.log("USER TYPE:", userType)
|
|
136
|
+
|
|
137
|
+ return (
|
|
138
|
+ <div class="gapwdrole">
|
|
139
|
+ <Title title="Seleciona el tipo de contraseña" step={"A"} />
|
|
140
|
+
|
|
141
|
+ <div className="typepwdlist">
|
|
142
|
+ <TipoUsuarios type={userType} setType={setUserType} />
|
|
143
|
+ </div>
|
|
144
|
+
|
|
145
|
+ {
|
|
146
|
+ parseInt(userType) === 1 && (
|
|
147
|
+ <div>
|
|
148
|
+ <div className="typepwdlist">
|
|
149
|
+ <Title title="Informacion de la contraseña" step={"B"} />
|
|
150
|
+ <PasswordInfoForm />
|
|
151
|
+ </div>
|
|
152
|
+
|
|
153
|
+ <div className="typepwdlist">
|
|
154
|
+ <Title title="Selecciona los privilegios" step={"C"} />
|
|
155
|
+ {recursos && Object.keys(recursos).map((k) => PermisosList( recursos[k] )) }
|
|
156
|
+ </div>
|
|
157
|
+ </div>
|
|
158
|
+ )
|
|
159
|
+ }
|
|
160
|
+
|
|
161
|
+ </div>
|
|
162
|
+ )
|
|
163
|
+
|
|
164
|
+}
|