Reac front end for psicometric app

resume.jsx 6.1KB

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