Reac front end for psicometric app

resume.jsx 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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, handleClose } = 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,mail
  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. mail,
  68. idContrasenia: password_id,
  69. nombrepuesto,
  70. nombreEmpresa
  71. }
  72. candiMutation.mutate(candidatoBody, {
  73. onSuccess: (data) => {
  74. toast.success("Contraseña agregada exitosamente!!")
  75. setTimeout(() => {
  76. console.log("OK LETS GO >> ", data,pwdID)
  77. setLoading(false);
  78. handleClose();
  79. }, 2000)
  80. },
  81. onError: () => {
  82. toast.error("Ups!! error al crear el candidato")
  83. setLoading(false);
  84. }
  85. })
  86. },
  87. onError: () => {
  88. console.log("No se pudo guardar pwd")
  89. setLoading(false);
  90. toast.error("Ups!! Ocurrio un error, inténtalo más tarde")
  91. }
  92. })
  93. }
  94. return (
  95. <React.Fragment>
  96. <ThemeProvider theme={theme}>
  97. {loading ? (
  98. <Box sx={{ paddingBottom: 3 }}>
  99. <LinearProgress color="inherit" />
  100. </Box>
  101. ) : null}
  102. <Table>
  103. <thead>
  104. <tr>
  105. <th>{key.pwd} ✅</th>
  106. <th></th>
  107. </tr>
  108. </thead>
  109. <tbody>
  110. <tr>
  111. <td className="title_td">{"Candidato"}</td>
  112. <td colSpan={2}>{key.nombres + " " + key.apellidos} - {key.mail}</td>
  113. </tr>
  114. <tr>
  115. <td className="title_td">{"Puesto"}</td>
  116. <td colSpan={2}>{key.puesto[0].nombrepuesto}</td>
  117. </tr>
  118. <tr>
  119. <td className="title_td">{"Empresa"}</td>
  120. <td colSpan={2}>{key.nombreEmpresa}</td>
  121. </tr>
  122. <tr>
  123. <td className="title_td">{"Fecha Activación"}</td>
  124. <td colSpan={2}>{new Date(key.dateToActived).toLocaleDateString('es-GT', fmt.current)}</td>
  125. </tr>
  126. <tr>
  127. <td className="title_td">{"Fecha de Vencimiento"}</td>
  128. <td colSpan={2}>{new Date(key.deadpwd).toLocaleDateString('es-GT', fmt.current)}</td>
  129. </tr>
  130. </tbody>
  131. </Table>
  132. <Box sx={{ mb: 2 }}>
  133. <div style={{ paddingTop: 15 }}>
  134. <Button
  135. disabled={loading}
  136. style={{
  137. color: loading ? 'white' : ''
  138. }}
  139. onClick={saveStepper}
  140. className="registerBtn"
  141. variant="contained"
  142. sx={{ mt: 1, mr: 1 }}
  143. >
  144. {'Guardar'}
  145. </Button>
  146. <Button
  147. disabled={loading}
  148. onClick={handleBack}
  149. sx={{ mt: 1, mr: 1 }}
  150. >
  151. Regresar
  152. </Button>
  153. </div>
  154. </Box>
  155. </ThemeProvider>
  156. <Backdrop
  157. sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
  158. open={loading}
  159. onClick={() => console.log("close fetching")} >
  160. <CircularProgress color="inherit" />
  161. </Backdrop>
  162. <Toaster position="bottom-right" />
  163. </React.Fragment>
  164. )
  165. }