amenpunk 1 год назад
Родитель
Сommit
4b17b3cad3
3 измененных файлов с 122 добавлено и 59 удалено
  1. 0 1
      src/App.css
  2. 121 57
      src/Components/Password/Steps/TypePwd.jsx
  3. 1 1
      src/Components/Password/Steps/puesto.js

+ 0 - 1
src/App.css

459
   display: flex;
459
   display: flex;
460
   flex-direction: column;
460
   flex-direction: column;
461
   flex-wrap: wrap;
461
   flex-wrap: wrap;
462
-  gap: 10px;
463
 }
462
 }

+ 121 - 57
src/Components/Password/Steps/TypePwd.jsx

3
 import { useSelector } from 'react-redux'
3
 import { useSelector } from 'react-redux'
4
 import {
4
 import {
5
   FormControl, RadioGroup, FormControlLabel, FormLabel, Checkbox,
5
   FormControl, RadioGroup, FormControlLabel, FormLabel, Checkbox,
6
-  TextField, Box, FormGroup, Button, Stack
6
+  TextField, Box, FormGroup, Button, Stack, Collapse
7
 } from '@mui/material'
7
 } from '@mui/material'
8
 
8
 
9
+import { useForm } from "react-hook-form";
10
+
9
 import { Simple as Loading } from '../../Generics/loading.jsx'
11
 import { Simple as Loading } from '../../Generics/loading.jsx'
10
 
12
 
13
+const ROLE = {
14
+  ADMIN: 1,
15
+  ASISTENTE: 2,
16
+  CANDIDATO: 3,
17
+}
18
+
11
 function Marked({ step }) {
19
 function Marked({ step }) {
12
   return (<strong className="important_marked">{step}</strong>)
20
   return (<strong className="important_marked">{step}</strong>)
13
 }
21
 }
14
 
22
 
15
 function Title({ title, step }) {
23
 function Title({ title, step }) {
16
-  return (<h5 className="titleMarked">{title}</h5>)
24
+  return (<p className="titleMarked">{title}</p>)
17
 }
25
 }
18
 
26
 
19
-function PasswordInfoForm() {
27
+function PasswordInfoForm({ setUser, user }) {
28
+
20
   return (
29
   return (
21
     <Stack >
30
     <Stack >
22
       <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2} >
31
       <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2} >
23
-        <TextField fullWidth id="outlined-basic" label="Correo" variant="outlined" />
24
-        <TextField fullWidth id="outlined-basic" label="Contraseña" variant="outlined" />
32
+
33
+        <TextField
34
+          value={user?.email}
35
+          onChange={(event) => {
36
+            let value = event.target.value
37
+            setUser({ ...user, ...{ email: value } })
38
+          }
39
+          }
40
+          fullWidth
41
+          id="outlined-basic"
42
+          label="Correo"
43
+          variant="outlined"
44
+        />
45
+
46
+        <TextField
47
+          value={user?.password}
48
+          onChange={(event) => {
49
+            let value = event.target.value
50
+            setUser({ ...user, ...{ password: value } })
51
+          }
52
+          }
53
+          fullWidth
54
+          id="outlined-basic"
55
+          label="Contraseña"
56
+          variant="outlined"
57
+        />
58
+
25
       </Stack>
59
       </Stack>
26
     </Stack>
60
     </Stack>
27
   );
61
   );
29
 
63
 
30
 
64
 
31
 
65
 
32
-export default function PermisosList(props) {
66
+function PermisosList(props) {
67
+
68
+  let { recursos,selectedRole, setSelectedRole } = props
69
+
33
   return (
70
   return (
34
     <FormControl className="rolelist" >
71
     <FormControl className="rolelist" >
35
-      <FormLabel id="demo-radio-buttons-group-label">{props.label}</FormLabel>
72
+      <FormLabel id="demo-radio-buttons-group-label">{recursos.label}</FormLabel>
36
       <RadioGroup
73
       <RadioGroup
37
         aria-labelledby="demo-radio-buttons-group-label"
74
         aria-labelledby="demo-radio-buttons-group-label"
38
         defaultValue="female"
75
         defaultValue="female"
40
       >
77
       >
41
         {
78
         {
42
 
79
 
43
-          props.data.length === 0 ? <Loading /> :
44
-            props.data.map((r) => {
45
-              console.log(r)
80
+          recursos.data.length === 0 ? <Loading /> :
81
+            recursos.data.map((r) => {
46
               return (
82
               return (
47
-                <FormControlLabel value={r.id} control={<Checkbox />} label={r.nombre} />
83
+                <FormControlLabel
84
+                  value={r.id}
85
+                  onChange={(event) => {
86
+                    let { checked } = event.target
87
+                    setSelectedRole((prev) => {
88
+                      if (checked) {
89
+                        return [...prev, r.id]
90
+                      } else {
91
+                        return prev.filter((p) => p !== r.id)
92
+                      }
93
+                    })
94
+                  }}
95
+                  checked={selectedRole.includes(r.id)}
96
+                  control={<Checkbox />}
97
+                  label={r.nombre}
98
+                />
48
               )
99
               )
49
             })
100
             })
50
         }
101
         }
57
 
108
 
58
   let { type, setType } = props
109
   let { type, setType } = props
59
 
110
 
60
-  const handleChange = (event) => {
61
-    let { value, checked } = event.target
62
-    console.log({ value, checked })
63
-    // let value = event.target.checked ? event.target.value : 0
64
-    setType(parseInt(value));
65
-  };
111
+  const handleChange = (event) => setType(parseInt(event.target.value));
66
 
112
 
67
   return (
113
   return (
68
     <FormControl>
114
     <FormControl>
75
         value={type}
121
         value={type}
76
         onChange={handleChange}
122
         onChange={handleChange}
77
       >
123
       >
78
-        <FormControlLabel value={1} onChange={handleChange} checked={type === 1} control={<Checkbox />} label="Administrador" />
79
-        <FormControlLabel value={2} onChange={handleChange} checked={type === 2} control={<Checkbox />} label="Asistente" />
80
-        <FormControlLabel value={3} onChange={handleChange} checked={type === 3} control={<Checkbox />} label="Candidato" />
124
+        <FormControlLabel
125
+          value={ROLE.CANDIDATO}
126
+          onChange={handleChange}
127
+          checked={type === ROLE.CANDIDATO}
128
+          control={<Checkbox />}
129
+          label="Candidato"
130
+        />
131
+        <FormControlLabel
132
+          value={ROLE.ADMIN}
133
+          onChange={handleChange}
134
+          checked={type === 1}
135
+          control={<Checkbox />}
136
+          label="Administrador"
137
+        />
138
+        <FormControlLabel
139
+          value={ROLE.ASISTENTE}
140
+          onChange={handleChange}
141
+          checked={type === 2}
142
+          control={<Checkbox />}
143
+          label="Asistente"
144
+        />
81
       </FormGroup>
145
       </FormGroup>
82
     </FormControl>
146
     </FormControl>
83
   );
147
   );
85
 
149
 
86
 
150
 
87
 export function TypePwd(props) {
151
 export function TypePwd(props) {
152
+  // console.log(props)
88
 
153
 
89
-  let auth = useSelector(state => state.token)
90
-  let [recursos, setRecursos] = useState(null)
91
-  let [userType, setUserType] = useState(1)
154
+  const auth = useSelector(state => state.token)
155
+  const [recursos, setRecursos] = useState(null)
156
+  const [selectedRole, setSelectedRole] = useState([])
157
+  const [userType, setUserType] = useState(ROLE.CANDIDATO)
158
+  const [user, setUser] = useState(null)
92
 
159
 
160
+  const saveUser = () => {
161
+    //TODO: trigger form submit
162
+    console.log(user, selectedRole)
163
+  }
93
 
164
 
94
   useEffect(() => {
165
   useEffect(() => {
95
 
166
 
121
         .forEach((k) => {
192
         .forEach((k) => {
122
           templete[k].data = recursos_api[k];
193
           templete[k].data = recursos_api[k];
123
         })
194
         })
124
-      console.log('BUILD:', templete)
195
+
125
       setRecursos(templete)
196
       setRecursos(templete)
126
     }
197
     }
127
 
198
 
135
     <div class="gapwdrole">
206
     <div class="gapwdrole">
136
 
207
 
137
       <div className="typepwdlist">
208
       <div className="typepwdlist">
138
-        <Title title="Seleciona el tipo de contraseña" step={"A"} />
139
-      </div>
140
-
141
-      <div className="typepwdlist">
142
         <TipoUsuarios type={userType} setType={setUserType} />
209
         <TipoUsuarios type={userType} setType={setUserType} />
143
       </div>
210
       </div>
144
 
211
 
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
-          </div>
153
-        )
154
-
155
-      }
156
-
157
-      {
158
-        parseInt(userType) === 2 && (
159
-          <div>
160
-            <div className="typepwdlist">
161
-              <Title title="Informacion de la contraseña" step={"B"} />
162
-              <PasswordInfoForm />
163
-            </div>
164
-
165
-            <div className="typepwdlist">
166
-              <Title title="Selecciona los privilegios" step={"C"} />
167
-              {recursos && Object.keys(recursos).map((k) => PermisosList(recursos[k]))}
168
-            </div>
169
-          </div>
170
-        )
171
-      }
212
+      <Collapse orientation="vertical" in={parseInt(userType) === ROLE.ADMIN} >
213
+        <div className="typepwdlist">
214
+          <Title title="Informacion de la contraseña" step={"B"} />
215
+          <PasswordInfoForm setUser={setUser} user={user} />
216
+        </div>
217
+      </Collapse>
172
 
218
 
219
+      <Collapse orientation="vertical" in={parseInt(userType) === ROLE.ASISTENTE} >
220
+        <div className="typepwdlist">
221
+          <Title title="Informacion de la contraseña" step={"B"} />
222
+          <PasswordInfoForm setUser={setUser} user={user} />
223
+        </div>
173
 
224
 
225
+        <div className="typepwdlist">
226
+          <Title title="Selecciona los privilegios" step={"C"} />
227
+          {
228
+            recursos &&
229
+            Object.keys(recursos).map((k) =>
230
+              <PermisosList
231
+                recursos={recursos[k]}
232
+                selectedRole={selectedRole}
233
+                setSelectedRole={setSelectedRole}
234
+              />
235
+            )}
236
+        </div>
237
+      </Collapse>
174
 
238
 
175
       <Box sx={{ mb: 2 }}>
239
       <Box sx={{ mb: 2 }}>
176
         <div style={{ paddingTop: 15 }}>
240
         <div style={{ paddingTop: 15 }}>
177
           <Button
241
           <Button
178
-            type="submit"
242
+            onClick={parseInt(userType) === ROLE.CANDIDATO ? props.handleNext : saveUser}
179
             className="registerBtn"
243
             className="registerBtn"
180
             variant="contained"
244
             variant="contained"
181
             sx={{ mt: 1, mr: 1 }}
245
             sx={{ mt: 1, mr: 1 }}
182
           >
246
           >
183
-            {'Siguiente'}
247
+            {parseInt(userType) === ROLE.CANDIDATO ? 'Siguiente' : 'Guardar'}
184
           </Button>
248
           </Button>
185
           <Button
249
           <Button
186
             disabled={true}
250
             disabled={true}

+ 1 - 1
src/Components/Password/Steps/puesto.js

114
                 {'Siguiente'}
114
                 {'Siguiente'}
115
               </Button>
115
               </Button>
116
               <Button
116
               <Button
117
-                disabled={true}
117
+                disabled={false}
118
                 onClick={handleBack}
118
                 onClick={handleBack}
119
                 sx={{ mt: 1, mr: 1 }}
119
                 sx={{ mt: 1, mr: 1 }}
120
               >
120
               >