Skip to content

Instantly share code, notes, and snippets.

@PaulieScanlon
Created June 16, 2024 14:35
Show Gist options
  • Save PaulieScanlon/561469b25830dae797b27ee776a63f59 to your computer and use it in GitHub Desktop.
Save PaulieScanlon/561469b25830dae797b27ee776a63f59 to your computer and use it in GitHub Desktop.
Vote Server Action
// submit-vote.ts
'use server';
import { redirect } from 'next/navigation';
import { doc } from '../services/google-spreadsheet';
export default async function submitVote(id: string) {
if (!id) {
redirect('/?error=true');
}
try {
await doc.loadInfo();
const sheet = doc.sheetsByIndex[0];
const rows = await sheet.getRows();
rows[0].set(id, Number(rows[0].get(id)) + 1);
await rows[0].save();
} catch (error) {
console.error(error);
redirect('/?error=true');
}
redirect('/results');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment