Skip to content

Commit

Permalink
add new live indicator page
Browse files Browse the repository at this point in the history
  • Loading branch information
visrut-at-incubyte committed Sep 4, 2023
1 parent edfbf65 commit ebf9e39
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
14 changes: 0 additions & 14 deletions __tests__/create-survey/page.spec.tsx

This file was deleted.

1 change: 0 additions & 1 deletion app/create-survey/components/SingleChoice/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const SingleChoice = ({ choices, setChoices, setAnswer }: SingleChoiceProps) =>
<label className='flex gap-x-3'>
<input
onChange={() => {
console.log('hi')
setAnswer && setAnswer(choice)
}}
type='radio'
Expand Down
16 changes: 13 additions & 3 deletions app/create-survey/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import QuestionsSlide from './components/QuestionSlide'
import './style.css'
import { Question, QuestionType } from '../models/types'
import { useAppContext } from '../context/AppContext'
import { useRouter } from 'next/navigation'

export default function CreateSurvey() {
const router = useRouter()

const emptyQuestion = { question: '', type: QuestionType.NOT_DECIDED }
const {
addNewQuestion,
Expand Down Expand Up @@ -52,7 +55,8 @@ export default function CreateSurvey() {
})
})
const data = await res.json()
console.log(data)
const surveyId = data['survey-id']
if (surveyId !== undefined && surveyId !== null) router.push(`/survey/live/${surveyId}`)
}

const editSurveyName = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -62,7 +66,13 @@ export default function CreateSurvey() {
return (
<main className='flex flex-col h-screen'>
<nav className='flex justify-center p-3'>
<input type='text' className='text-2xl bg-transparent outline-none text-center' value={name} onChange={editSurveyName} data-testid="survey-name-input" />
<input
type='text'
className='text-2xl bg-transparent outline-none text-center'
value={name}
onChange={editSurveyName}
data-testid='survey-name-input'
/>
</nav>
<section className='flex justify-between items-center h-full'>
<button
Expand All @@ -83,4 +93,4 @@ export default function CreateSurvey() {
</footer>
</main>
)
}
}
6 changes: 2 additions & 4 deletions app/survey/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
'use client'
import { useParams } from 'next/navigation'
import { useEffect } from 'react'
import AnswerForm from './components/AnswerForm'
import LoadingSpinner from '@/app/components/LoadingSpinner'
import { useAppContext } from '@/app/context/AppContext'

export default function FillSurvey() {
export default function FillSurvey({ params }: { params: { id: string } }) {
const { setName, setQuestions, questions, name, currentQuestionNumber } = useAppContext()
const { id } = useParams()

const getSurvey = async () => {
const res = await fetch(`/survey/${id}/api`)
const res = await fetch(`/survey/${params.id}/api`)
const data = await res.json()
setName(data.surveyName)
setQuestions([...data.questions])
Expand Down
12 changes: 12 additions & 0 deletions app/survey/live/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Link from 'next/link'

export default function SurveyLivePage({ params }: { params: { id: string } }) {
return (
<main className='h-screen flex flex-col gap-y-5 items-center justify-center'>
<h1 className='text-white text-5xl'>Your survey is Live</h1>
<Link href={`/survey/${params.id}`} className='btn-primary'>
Here
</Link>
</main>
)
}

0 comments on commit ebf9e39

Please sign in to comment.