diff --git a/.env.local.example b/.env.local.example index 3b09280..3c27ffe 100644 --- a/.env.local.example +++ b/.env.local.example @@ -4,3 +4,5 @@ JWT_SCOPE="" GROUP_KEY="" BACKEND_URL="https://..." NEXT_PUBLIC_PLAUSIBLE_URL="" +NEXT_PUBLIC_RECAPTCHA_SITE_KEY="<>" +RECAPTCHA_SECRET="<>" diff --git a/package.json b/package.json index cc71a4a..cf23f25 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "react-markdown": "^9.0.1", "react-snap-carousel": "^0.4.0", "remark-gfm": "^4.0.0", - "yet-another-react-lightbox": "^3.16.0" + "yet-another-react-lightbox": "^3.16.0", + "react-google-recaptcha-v3": "^1.10.1" }, "devDependencies": { "@types/node": "^20", diff --git a/src/app/actions.ts b/src/app/actions.ts index e7833e9..a68e559 100644 --- a/src/app/actions.ts +++ b/src/app/actions.ts @@ -34,3 +34,46 @@ export async function addToGroup({ email }: { email: string }) { return 500; } } + +export async function sendQuestion({ + question, + slug, + recaptchaToken, + userId, +}: { + question: string; + slug: string; + recaptchaToken: string; + userId: string; +}) { + const isRecaptchaValid = await validateRecaptcha(recaptchaToken); + if (!isRecaptchaValid) { + console.error('Recaptcha validation failed'); + return 400; + } + if (!question || !slug) { + return 400; + } + const res = await fetch(`https://konf-qna.kir-dev.hu/api/presentation/${slug}/question`, { + method: 'POST', + body: JSON.stringify({ content: question, userId }), + }); + if (res.status === 200) { + return 201; + } else if (res.status === 400) { + return 400; + } + return 500; +} + +async function validateRecaptcha(token: string) { + const res = await fetch('https://www.google.com/recaptcha/api/siteverify', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: `secret=${process.env.RECAPTCHA_SECRET}&response=${token}`, + }); + const data = await res.json(); + return data.success; +} diff --git a/src/app/questions/page.tsx b/src/app/questions/page.tsx new file mode 100644 index 0000000..90ee20f --- /dev/null +++ b/src/app/questions/page.tsx @@ -0,0 +1,14 @@ +import { QuestionPageBody } from '@/components/questions/question-page-body'; +import { getDelayData } from '@/models/get-delay-data'; +import { getPresentationData } from '@/models/get-presentation-data'; + +export default async function questionsPage() { + const presentations = await getPresentationData(); + const delay = await getDelayData(); + return ( +
+

Kérdezz az elődóktól!

+ +
+ ); +} diff --git a/src/components/navbar/desktop-navbar.tsx b/src/components/navbar/desktop-navbar.tsx index 5791dd7..3aeab29 100644 --- a/src/components/navbar/desktop-navbar.tsx +++ b/src/components/navbar/desktop-navbar.tsx @@ -25,7 +25,7 @@ export function DesktopNavbar() { }, []); return ( -