mirror of
https://github.com/System-End/site.git
synced 2026-04-19 19:45:07 +00:00
fix voting api check
This commit is contained in:
parent
3c3233a774
commit
7ed91c7e51
2 changed files with 21 additions and 8 deletions
|
|
@ -22,7 +22,8 @@ export default async function handler(req, res) {
|
|||
?.replace('Bearer ', '')
|
||||
.replace(/[^a-zA-Z0-9-]/g, '')
|
||||
|
||||
const { Overall, Technical, Creative } = req.body
|
||||
console.log(req.body)
|
||||
const { overall, technical, creative } = req.body
|
||||
|
||||
const pointsDistribution = [5, 4, 3, 2, 1]
|
||||
|
||||
|
|
@ -37,6 +38,8 @@ export default async function handler(req, res) {
|
|||
const userID = users[0].id
|
||||
|
||||
const userRecord = await usersTable.find(userID)
|
||||
|
||||
console.log(userRecord)
|
||||
const voted = userRecord.fields.Voted
|
||||
|
||||
if (voted) {
|
||||
|
|
@ -45,8 +48,8 @@ export default async function handler(req, res) {
|
|||
|
||||
let jobs = []
|
||||
|
||||
for (let i = 0; i < Overall.length; i++) {
|
||||
const project = Overall[i]
|
||||
for (let i = 0; i < overall.length; i++) {
|
||||
const project = overall[i]
|
||||
const points = pointsDistribution[i]
|
||||
|
||||
jobs.push(addVote(project, points, userID, 'Overall'))
|
||||
|
|
@ -56,8 +59,8 @@ export default async function handler(req, res) {
|
|||
|
||||
jobs = []
|
||||
|
||||
for (let i = 0; i < Technical.length; i++) {
|
||||
const project = Technical[i]
|
||||
for (let i = 0; i < technical.length; i++) {
|
||||
const project = technical[i]
|
||||
const points = pointsDistribution[i]
|
||||
|
||||
await addVote(project, points, userID, 'Technical')
|
||||
|
|
@ -67,8 +70,8 @@ export default async function handler(req, res) {
|
|||
|
||||
jobs = []
|
||||
|
||||
for (let i = 0; i < Creative.length; i++) {
|
||||
const project = Creative[i]
|
||||
for (let i = 0; i < creative.length; i++) {
|
||||
const project = creative[i]
|
||||
const points = pointsDistribution[i]
|
||||
|
||||
await addVote(project, points, userID, 'Creative')
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ const Vote = () => {
|
|||
const [openProject, setOpenProject] = useState([])
|
||||
|
||||
/* status variables */
|
||||
const [loadStatus, setLoadStatus] = useState('success') // change
|
||||
const [loadStatus, setLoadStatus] = useState('loading')
|
||||
const [status, setStatus] = useState('loading')
|
||||
const [submitStatus, setSubmitStatus] = useState('loading')
|
||||
|
||||
|
|
@ -270,6 +270,7 @@ const Vote = () => {
|
|||
console.error(e)
|
||||
setLoadStatus('error')
|
||||
})
|
||||
setLoadStatus('loading')
|
||||
const data = await response.json()
|
||||
if (data.error) {
|
||||
setLoadStatus('error')
|
||||
|
|
@ -609,6 +610,7 @@ const Vote = () => {
|
|||
})
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (data.error) {
|
||||
console.error('Error submitting vote:', data.error)
|
||||
setSubmitStatus('error')
|
||||
|
|
@ -677,6 +679,14 @@ const Vote = () => {
|
|||
? 'Thanks for voting!'
|
||||
: 'Ran into an error sending your votes'}
|
||||
</Text>
|
||||
|
||||
<Text
|
||||
variant="caption"
|
||||
className="gaegu"
|
||||
sx={{ textAlign: 'center', maxWidth: '800px' }}
|
||||
>
|
||||
{submitStatus == 'loading' ? 'It takes a while' : ''}
|
||||
</Text>
|
||||
<Button
|
||||
as="a"
|
||||
href="/arcade/showcase/my"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue