Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3013 Rev 3014
Línea 74... Línea 74...
74
        return curr + next
74
        return curr + next
75
      }, 0),
75
      }, 0),
76
    [votes]
76
    [votes]
77
  )
77
  )
Línea -... Línea 78...
-
 
78
 
-
 
79
  const sendVote = handleSubmit(({ vote }) => {
-
 
80
    setIsActive(false)
-
 
81
 
-
 
82
    const formData = new FormData()
-
 
83
    formData.append('vote', vote)
-
 
84
 
-
 
85
    axios
-
 
86
      .post(voteUrl, formData)
-
 
87
      .then(({ data: response }) => {
-
 
88
        const { success, data } = response
-
 
89
 
-
 
90
        if (!success) {
-
 
91
          const errorMessage =
-
 
92
            typeof data === 'string'
-
 
93
              ? data
-
 
94
              : 'Error interno, por favor intente mas tarde.'
-
 
95
          throw new Error(errorMessage)
-
 
96
        }
-
 
97
 
-
 
98
        updateFeed({ feed: data, uuid: data.feed_uuid })
-
 
99
        addNotification({ style: 'success', msg: 'Voto emitido con exito' })
-
 
100
      })
-
 
101
      .catch((err) => {
-
 
102
        setIsActive(true)
-
 
103
        addNotification({ style: 'danger', msg: err.message })
-
 
104
      })
-
 
105
  })
-
 
106
 
-
 
107
  function getTimeDiff(segundos) {
-
 
108
    const currentDate = new Date()
-
 
109
    const futureDate = new Date(currentDate.getTime() + segundos * 1000)
-
 
110
    const diff = futureDate - currentDate
-
 
111
 
-
 
112
    const days = Math.floor(diff / (1000 * 60 * 60 * 24))
-
 
113
    const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
-
 
114
    const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
-
 
115
 
-
 
116
    return `${addZero(days)}d ${addZero(hours)}h ${addZero(minutes)}m`
-
 
117
  }
-
 
118
 
-
 
119
  function addZero(unit) {
-
 
120
    return String(unit).padStart(2, '0')
-
 
121
  }
-
 
122
 
-
 
123
  function getPorcentage(n, total) {
-
 
124
    return (n / total) * 100
-
 
125
  }
-
 
126
 
-
 
127
  useEffect(() => {
-
 
128
    setIsActive(!!active)
-
 
129
  }, [active])
78
 
130
 
79
  return (
131
  return (
80
    <form onChange={handleSubmit} className={styles.survey_form}>
132
    <form onChange={sendVote} className={styles.survey_form}>
81
      <h3>{question}</h3>
133
      <h3>{question}</h3>
82
      {resultType === 'pu' && (
134
      {resultType === 'pu' && (
83
        <span
135
        <span
84
          className='mb-2'
136
          className='mb-2'
Línea 106... Línea 158...
106
                disabled={!isActive}
158
                disabled={!isActive}
107
                ref={register({ required: true })}
159
                ref={register({ required: true })}
108
                value={index + 1}
160
                value={index + 1}
109
              />
161
              />
110
              <label htmlFor={`vote-${index + 1}`}>{option}</label>
162
              <label htmlFor={`vote-${index + 1}`}>{option}</label>
-
 
163
              {!!totalVotes && (
111
              {!!totalVotes && <span className='mb-0'>1</span>}
164
                <span className='mb-0'>
-
 
165
                  {getPorcentage(votes[index], totalVotes)}%
-
 
166
                </span>
-
 
167
              )}
112
            </RadioButton>
168
            </RadioButton>
113
          )
169
          )
114
      )}
170
      )}
115
      <span>Tiempo restante: {remainingTime}</span>
171
      <span>Tiempo restante: {remainingTime}</span>
116
      {!isActive && <VoteTag>Tu voto ya fue emitido</VoteTag>}
172
      {!isActive && <VoteTag>Tu voto ya fue emitido</VoteTag>}