-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from simonyiszk/dev
v4.0
- Loading branch information
Showing
14 changed files
with
355 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div className='flex flex-col px-4 sm:px-6 xl:px-0 max-w-6xl w-full overflow-hidden'> | ||
<h1 className='mb-16 mt-8'>Kérdezz az elődóktól!</h1> | ||
<QuestionPageBody presentations={presentations} delay={delay ?? 0} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { Dialog } from '@headlessui/react'; | ||
import { useEffect, useState } from 'react'; | ||
import { useGoogleReCaptcha } from 'react-google-recaptcha-v3'; | ||
import { FaCheckCircle } from 'react-icons/fa'; | ||
|
||
import { sendQuestion } from '@/app/actions'; | ||
import { WhiteButton } from '@/components/white-button'; | ||
import { AllowedQuestionCount, getQuestionCount, getUserId, incrementQuestionCount } from '@/utils/questionHelpers'; | ||
|
||
interface PresentationQuestionFormProps { | ||
slug: string; | ||
} | ||
|
||
export function PresentationQuestionForm({ slug }: PresentationQuestionFormProps) { | ||
const { executeRecaptcha } = useGoogleReCaptcha(); | ||
const [isSuccessOpen, setIsSuccessOpen] = useState(false); | ||
|
||
const [error, setError] = useState(''); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [question, setQuestion] = useState(''); | ||
const [questionCount, setQuestionCount] = useState(0); | ||
|
||
const canAskQuestions = questionCount < AllowedQuestionCount; | ||
|
||
useEffect(() => { | ||
setQuestionCount(getQuestionCount(slug)); | ||
}, []); | ||
|
||
const onSend = async () => { | ||
if (!executeRecaptcha) return; | ||
const recaptchaToken = await executeRecaptcha('presentation_question'); | ||
if (question.trim() && canAskQuestions) { | ||
setIsLoading(true); | ||
const status = await sendQuestion({ question, slug, recaptchaToken, userId: getUserId() }); | ||
setIsLoading(false); | ||
switch (status) { | ||
case 201: | ||
incrementQuestionCount(slug); | ||
setQuestionCount(questionCount + 1); | ||
setIsSuccessOpen(true); | ||
setQuestion(''); | ||
setError(''); | ||
break; | ||
case 400: | ||
setError('Hibás formátum!'); | ||
break; | ||
default: | ||
setError('Ismeretlen hiba!'); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<div className='mt-10 w-full'> | ||
{canAskQuestions ? ( | ||
<> | ||
<div className='relative'> | ||
<textarea | ||
className='w-full rounded-md p-2 bg-transparent border-white border-[0.5px]' | ||
value={question} | ||
onChange={(e) => setQuestion(e.target.value)} | ||
rows={4} | ||
placeholder='Ide írd a kérdésed!' | ||
/> | ||
<p className='absolute right-0 bottom-0 p-4'> | ||
{questionCount}/{AllowedQuestionCount} Kérdés feltéve | ||
</p> | ||
</div> | ||
{error && <p className='text-red-500 my-2'>{error}</p>} | ||
<div className='w-full my-4 flex justify-center'> | ||
<WhiteButton onClick={onSend} disabled={!question.trim() || isLoading || !executeRecaptcha}> | ||
Kérdés küldése | ||
</WhiteButton> | ||
</div> | ||
</> | ||
) : ( | ||
<div className='w-full my-4 flex justify-center'> | ||
<WhiteButton disabled={true} onClick={() => {}}> | ||
Elfogytak a feltehető kérdések! | ||
</WhiteButton> | ||
</div> | ||
)} | ||
<Dialog open={isSuccessOpen} onClose={() => setIsSuccessOpen(false)} className='relative z-50'> | ||
<div className='fixed inset-0 bg-black/80' aria-hidden='true' /> | ||
|
||
<div className='fixed inset-0 flex w-screen items-center justify-center p-4'> | ||
<Dialog.Panel className='mx-auto max-w-lg rounded bg-[#0f181c] p-8 flex flex-col items-center gap-5'> | ||
<div className='text-8xl text-white'> | ||
<FaCheckCircle /> | ||
</div> | ||
<Dialog.Title className='font-bold text-2xl mb-5 text-center'> | ||
A kérdésed megkaptuk és moderálás után a felolvasandó kérdések közé kerül. Köszönjük! | ||
</Dialog.Title> | ||
|
||
<WhiteButton onClick={() => setIsSuccessOpen(false)}>Rendben</WhiteButton> | ||
</Dialog.Panel> | ||
</div> | ||
</Dialog> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use client'; | ||
|
||
import { GoogleReCaptchaProvider } from 'react-google-recaptcha-v3'; | ||
|
||
import { RoomQuestion } from '@/components/tiles/question-tile'; | ||
import { PresentationWithDates } from '@/models/models'; | ||
|
||
export function QuestionPageBody({ | ||
presentations, | ||
delay, | ||
}: { | ||
presentations: PresentationWithDates[] | undefined; | ||
delay: number; | ||
}) { | ||
return ( | ||
<GoogleReCaptchaProvider reCaptchaKey={process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY ?? ''}> | ||
<div className='grid grid-cols-1 sm:grid-cols-2 gap-6'> | ||
<div className='order-1'> | ||
<h2 className='text-4xl text-center'>IB028</h2> | ||
</div> | ||
<div className='order-3 sm:order-2 mt-16 sm:mt-0'> | ||
<h2 className='text-4xl text-center'>IB025</h2> | ||
</div> | ||
<div className='order-2 sm:order-3'> | ||
<RoomQuestion presentations={presentations ?? []} room='IB028' delay={delay} /> | ||
</div> | ||
<div className='order-4'> | ||
<RoomQuestion presentations={presentations ?? []} room='IB025' delay={delay} /> | ||
</div> | ||
</div> | ||
</GoogleReCaptchaProvider> | ||
); | ||
} |
Oops, something went wrong.