浏览代码

add candi and pwd

amenpunk 2 年之前
父节点
当前提交
a38f09a38c
共有 3 个文件被更改,包括 177 次插入56 次删除
  1. 3 1
      src/App.css
  2. 2 1
      src/Components/Modal/PasswordModal.jsx
  3. 172 54
      src/Components/Password/Steps/resume.jsx

+ 3 - 1
src/App.css

@@ -261,6 +261,8 @@
261 261
 
262 262
 .name_header{
263 263
     max-width:20px;
264
-    background-color:whitesmoke;
265 264
     font-weight:bold;
266 265
 }
266
+.title_td{
267
+    font-weight: bold;
268
+}

+ 2 - 1
src/Components/Modal/PasswordModal.jsx

@@ -93,6 +93,7 @@ export function HelpModal(props) {
93 93
                 <Resume
94 94
                     handleBack={handleBack}
95 95
                     password={password}
96
+                    handleClose={handleClose}
96 97
                 />
97 98
         },
98 99
     ];
@@ -144,7 +145,7 @@ export function HelpModal(props) {
144 145
                     ) : (
145 146
                         <React.Fragment>
146 147
 
147
-                            <Box style={{ padding: 18, marginTop: 10 }}>
148
+                            <Box style={{ padding: 18, marginTop: 2 }}>
148 149
                                 {steps[activeStep].operation}
149 150
                             </Box>
150 151
 

+ 172 - 54
src/Components/Password/Steps/resume.jsx

@@ -1,66 +1,184 @@
1 1
 import * as React from 'react';
2
+
2 3
 import { Table } from 'react-bootstrap';
4
+import {
5
+    Box, Button, LinearProgress,
6
+    Backdrop, CircularProgress
7
+} from '@mui/material';
8
+
9
+import toast, { Toaster } from 'react-hot-toast';
10
+
11
+import { useMutation } from 'react-query';
12
+import { Service } from '../../../Utils/HTTP.js'
13
+import useAuth from '../../../Auth/useAuth.js'
3 14
 
4
-import { Box, Button } from '@mui/material';
15
+import { createTheme, ThemeProvider } from '@mui/material/styles';
16
+
17
+let theme = createTheme({
18
+    status: {
19
+        success: '#fd4b4b'
20
+    },
21
+    palette: {
22
+        primary: {
23
+            main: '#fd4b4b',
24
+        },
25
+        secondary: {
26
+            main: '#fd4b4b',
27
+        },
28
+    },
29
+});
5 30
 
6 31
 export function Resume(props) {
7 32
 
8
-    let {handleBack, password: key } = props
33
+    let { handleBack, password: key } = props
9 34
     const fmt = React.useRef({ weekday: 'long', year: 'numeric', month: 'short', day: 'numeric' })
35
+    const [pwdID, setPwdID] = React.useState(null);
36
+    const [loading, setLoading] = React.useState(false);
37
+    const auth = useAuth();
38
+    const token = auth.getToken();
39
+
40
+    const savePassword = async (body) => {
41
+        let rest = new Service('/contrasenia/create')
42
+        return await rest.postQuery(body, token)
43
+    }
44
+
45
+    const saveCandidato = async (body) => {
46
+        let rest = new Service('/passwordcandidato/candidato')
47
+        return await rest.postQuery(body, token)
48
+    }
49
+
50
+    const pwdMutation = useMutation('password', savePassword);
51
+    const candiMutation = useMutation('candidato', saveCandidato);
52
+
53
+    const saveStepper = () => {
54
+
55
+        setLoading(true);
56
+
57
+        let {
58
+            deadpwd, dateToActived, puesto, pwd,
59
+            nombres, apellidos, sendmail, nombrepuesto, nombreEmpresa
60
+        } = key;
61
+        console.log("KEY: ", key)
10 62
 
11
-    return(
63
+        let pwdBody = {
64
+            id: -1,
65
+            pwd,
66
+            link: "www.psicoadmin.com",
67
+            deadpwd: new Date(deadpwd).toISOString(),
68
+            state: 1,
69
+            dateToActived: new Date(dateToActived).toISOString(),
70
+            plaza_id: puesto[0].id
71
+        }
72
+
73
+        pwdMutation.mutate(pwdBody, {
74
+            onSuccess: (data) => {
75
+
76
+                let { id: password_id } = data.data;
77
+                setPwdID(password_id);
78
+
79
+                let candidatoBody = {
80
+                    id: -1,
81
+                    nombres,
82
+                    apellidos,
83
+                    sendmail: sendmail ? 1 : 0,
84
+                    idContrasenia: password_id,
85
+                    nombrepuesto,
86
+                    nombreEmpresa
87
+                }
88
+
89
+                candiMutation.mutate(candidatoBody, {
90
+                    onSuccess: (data) => {
91
+                        console.log("OK LETS GO >> ", data)
92
+                        toast.success("Contraseña agregada exitosamente!!")
93
+                        setLoading(false);
94
+                    },
95
+                    onError: () => {
96
+                        toast.error("Ups!! error al crear el candidato")
97
+                        setLoading(false);
98
+                    }
99
+                })
100
+
101
+
102
+            },
103
+            onError: () => {
104
+                console.log("No se pudo guardar pwd")
105
+                setLoading(false);
106
+                toast.error("Ups!! Ocurrio un error, inténtalo más tarde")
107
+            }
108
+        })
109
+    }
110
+
111
+    return (
12 112
         <React.Fragment>
13
-            <Table>
14
-                <thead>
15
-                    <tr>
16
-                        <th>{key.pwd}</th>
17
-                        <th></th>
18
-                    </tr>
19
-                </thead>
20
-                <tbody>
21
-                    <tr>
22
-                        <td>{"Candidato"}</td>
23
-                        <td colSpan={2}>{key.nombres + " " + key.apellidos} - {key.mail}</td>
24
-                    </tr>
25
-                    <tr>
26
-                        <td>{"Puesto"}</td>
27
-                        <td colSpan={2}>{key.puesto[0].nombrepuesto}</td>
28
-                    </tr>
29
-                    <tr>
30
-                        <td>{"Empresa"}</td>
31
-                        <td colSpan={2}>{key.nombreEmpresa}</td>
32
-                    </tr>
33
-                    <tr>
34
-                        <td>{"Fecha Activación"}</td>
35
-                        <td colSpan={2}>{new Date( key.dateToActived ).toLocaleDateString('es-GT',fmt.current )}</td>
36
-                    </tr>
37
-                    <tr>
38
-                        <td>{"Fecha de Vencimiento"}</td>
39
-                        <td colSpan={2}>{new Date( key.deadpwd ).toLocaleDateString('es-GT',fmt.current )}</td>
40
-                    </tr>
41
-                </tbody>
42
-            </Table>
43
-
44
-
45
-            <Box sx={{ mb: 2 }}>
46
-                <div style={{ paddingTop: 15 }}>
47
-                    <Button
48
-                        type="submit"
49
-                        className="registerBtn"
50
-                        variant="contained"
51
-                        sx={{ mt: 1, mr: 1 }}
52
-                    >
53
-                        {'Guardar'}
54
-                    </Button>
55
-                    <Button
56
-                        disabled={false}
57
-                        onClick={handleBack}
58
-                        sx={{ mt: 1, mr: 1 }}
59
-                    >
60
-                        Regresar
61
-                    </Button>
62
-                </div>
63
-            </Box>
113
+            <ThemeProvider theme={theme}>
114
+                {loading ? (
115
+                    <Box sx={{ paddingBottom: 3 }}>
116
+                        <LinearProgress color="inherit" />
117
+                    </Box>
118
+                ) : null}
119
+                <Table>
120
+                    <thead>
121
+                        <tr>
122
+                            <th>{key.pwd} ✅</th>
123
+                            <th></th>
124
+                        </tr>
125
+                    </thead>
126
+                    <tbody>
127
+                        <tr>
128
+                            <td className="title_td">{"Candidato"}</td>
129
+                            <td colSpan={2}>{key.nombres + " " + key.apellidos} - {key.mail}</td>
130
+                        </tr>
131
+                        <tr>
132
+                            <td className="title_td">{"Puesto"}</td>
133
+                            <td colSpan={2}>{key.puesto[0].nombrepuesto}</td>
134
+                        </tr>
135
+                        <tr>
136
+                            <td className="title_td">{"Empresa"}</td>
137
+                            <td colSpan={2}>{key.nombreEmpresa}</td>
138
+                        </tr>
139
+                        <tr>
140
+                            <td className="title_td">{"Fecha Activación"}</td>
141
+                            <td colSpan={2}>{new Date(key.dateToActived).toLocaleDateString('es-GT', fmt.current)}</td>
142
+                        </tr>
143
+                        <tr>
144
+                            <td className="title_td">{"Fecha de Vencimiento"}</td>
145
+                            <td colSpan={2}>{new Date(key.deadpwd).toLocaleDateString('es-GT', fmt.current)}</td>
146
+                        </tr>
147
+                    </tbody>
148
+                </Table>
149
+
150
+
151
+                <Box sx={{ mb: 2 }}>
152
+                    <div style={{ paddingTop: 15 }}>
153
+                        <Button
154
+                            disabled={loading}
155
+                            style={{
156
+                                color: loading ? 'white' : ''
157
+                            }}
158
+                            onClick={saveStepper}
159
+                            className="registerBtn"
160
+                            variant="contained"
161
+                            sx={{ mt: 1, mr: 1 }}
162
+                        >
163
+                            {'Guardar'}
164
+                        </Button>
165
+                        <Button
166
+                            disabled={loading}
167
+                            onClick={handleBack}
168
+                            sx={{ mt: 1, mr: 1 }}
169
+                        >
170
+                            Regresar
171
+                        </Button>
172
+                    </div>
173
+                </Box>
174
+            </ThemeProvider>
175
+            <Backdrop
176
+                sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
177
+                open={loading}
178
+                onClick={() => console.log("close fetching")} >
179
+                <CircularProgress color="inherit" />
180
+            </Backdrop>
181
+            <Toaster position="bottom-right" />
64 182
         </React.Fragment>
65 183
     )
66 184
 }