Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6410 | Rev 6416 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 6410 Rev 6415
Línea 1... Línea 1...
1
import React, { useState } from 'react'
1
import React, { useEffect, useState } from 'react'
2
import { axios } from '../../../utils'
2
import { axios } from '../../../utils'
3
import { useForm } from 'react-hook-form'
3
import { useForm } from 'react-hook-form'
4
import { connect } from 'react-redux'
4
import { connect } from 'react-redux'
Línea 5... Línea 5...
5
 
5
 
Línea 19... Línea 19...
19
  resultType,
19
  resultType,
20
  voteUrl,
20
  voteUrl,
21
  addNotification, // Redux action
21
  addNotification, // Redux action
22
  updateFeed, // Redux action
22
  updateFeed, // Redux action
23
}) => {
23
}) => {
-
 
24
  const [remainingTime, setRemainingTime] = useState({
-
 
25
    days: 0,
-
 
26
    hours: 0,
-
 
27
    minutes: 0,
-
 
28
  })
24
  const [isActive, setIsActive] = useState(Boolean(active))
29
  const [isActive, setIsActive] = useState(Boolean(active))
25
  const { register, handleSubmit } = useForm()
30
  const { register, handleSubmit } = useForm()
Línea 26... Línea 31...
26
 
31
 
27
  const sendVote = handleSubmit(({ vote }) => {
32
  const sendVote = handleSubmit(({ vote }) => {
Línea 46... Línea 51...
46
        setIsActive(true)
51
        setIsActive(true)
47
        throw new Error(err)
52
        throw new Error(err)
48
      })
53
      })
49
  })
54
  })
Línea -... Línea 55...
-
 
55
 
-
 
56
  function getTimeDiff(segundos) {
-
 
57
    // Obtener la fecha y hora actual
-
 
58
    const currentDate = new Date()
-
 
59
 
-
 
60
    // Calcular la fecha y hora futura sumando los segundos proporcionados
-
 
61
    const futureDate = new Date(fechaActual.getTime() + segundos * 1000)
-
 
62
 
-
 
63
    // Calcular la diferencia entre la fecha futura y la fecha actual
-
 
64
    const diff = futureDate - currentDate
-
 
65
 
-
 
66
    // Calcular los componentes de la diferencia de tiempo
-
 
67
    const days = Math.floor(diff / (1000 * 60 * 60 * 24))
-
 
68
    const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
-
 
69
    const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
-
 
70
 
-
 
71
    // Devolver el resultado
-
 
72
    return { days, hours, minutes }
-
 
73
  }
-
 
74
 
-
 
75
  useEffect(() => {
-
 
76
    const diff = getTimeDiff(time)
-
 
77
    setRemainingTime(diff)
-
 
78
  }, [])
50
 
79
 
51
  return (
80
  return (
52
    <form onChange={sendVote} className={styles.survey_form}>
81
    <form onChange={sendVote} className={styles.survey_form}>
53
      <h3>{question}</h3>
82
      <h3>{question}</h3>
54
      {resultType === 'pu' && (
83
      {resultType === 'pu' && (
Línea 59... Línea 88...
59
      {resultType === 'pr' && (
88
      {resultType === 'pr' && (
60
        <span>
89
        <span>
61
          <LockClockIcon /> Tu voto es privado
90
          <LockClockIcon /> Tu voto es privado
62
        </span>
91
        </span>
63
      )}
92
      )}
-
 
93
      <span>{`${remainingTime.days}:${remainingTime.hours}:${remainingTime.minutes}`}</span>
64
      {answers.map(
94
      {answers.map(
65
        (option, index) =>
95
        (option, index) =>
66
          option && (
96
          option && (
67
            <div
97
            <div
68
              className={
98
              className={