瀏覽代碼

select role and set user

amenpunk 1 年之前
父節點
當前提交
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,5 +459,4 @@
459 459
   display: flex;
460 460
   flex-direction: column;
461 461
   flex-wrap: wrap;
462
-  gap: 10px;
463 462
 }

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

@@ -3,25 +3,59 @@ import { Service } from '../../../Utils/HTTP.js'
3 3
 import { useSelector } from 'react-redux'
4 4
 import {
5 5
   FormControl, RadioGroup, FormControlLabel, FormLabel, Checkbox,
6
-  TextField, Box, FormGroup, Button, Stack
6
+  TextField, Box, FormGroup, Button, Stack, Collapse
7 7
 } from '@mui/material'
8 8
 
9
+import { useForm } from "react-hook-form";
10
+
9 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 19
 function Marked({ step }) {
12 20
   return (<strong className="important_marked">{step}</strong>)
13 21
 }
14 22
 
15 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 29
   return (
21 30
     <Stack >
22 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 59
       </Stack>
26 60
     </Stack>
27 61
   );
@@ -29,10 +63,13 @@ function PasswordInfoForm() {
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 70
   return (
34 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 73
       <RadioGroup
37 74
         aria-labelledby="demo-radio-buttons-group-label"
38 75
         defaultValue="female"
@@ -40,11 +77,25 @@ export default function PermisosList(props) {
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 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,12 +108,7 @@ function TipoUsuarios(props) {
57 108
 
58 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 113
   return (
68 114
     <FormControl>
@@ -75,9 +121,27 @@ function TipoUsuarios(props) {
75 121
         value={type}
76 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 145
       </FormGroup>
82 146
     </FormControl>
83 147
   );
@@ -85,11 +149,18 @@ function TipoUsuarios(props) {
85 149
 
86 150
 
87 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 165
   useEffect(() => {
95 166
 
@@ -121,7 +192,7 @@ export function TypePwd(props) {
121 192
         .forEach((k) => {
122 193
           templete[k].data = recursos_api[k];
123 194
         })
124
-      console.log('BUILD:', templete)
195
+
125 196
       setRecursos(templete)
126 197
     }
127 198
 
@@ -135,52 +206,45 @@ export function TypePwd(props) {
135 206
     <div class="gapwdrole">
136 207
 
137 208
       <div className="typepwdlist">
138
-        <Title title="Seleciona el tipo de contraseña" step={"A"} />
139
-      </div>
140
-
141
-      <div className="typepwdlist">
142 209
         <TipoUsuarios type={userType} setType={setUserType} />
143 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 239
       <Box sx={{ mb: 2 }}>
176 240
         <div style={{ paddingTop: 15 }}>
177 241
           <Button
178
-            type="submit"
242
+            onClick={parseInt(userType) === ROLE.CANDIDATO ? props.handleNext : saveUser}
179 243
             className="registerBtn"
180 244
             variant="contained"
181 245
             sx={{ mt: 1, mr: 1 }}
182 246
           >
183
-            {'Siguiente'}
247
+            {parseInt(userType) === ROLE.CANDIDATO ? 'Siguiente' : 'Guardar'}
184 248
           </Button>
185 249
           <Button
186 250
             disabled={true}

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

@@ -114,7 +114,7 @@ export function Puesto(props) {
114 114
                 {'Siguiente'}
115 115
               </Button>
116 116
               <Button
117
-                disabled={true}
117
+                disabled={false}
118 118
                 onClick={handleBack}
119 119
                 sx={{ mt: 1, mr: 1 }}
120 120
               >