Skip to content
Snippets Groups Projects
Commit 388bd0a0 authored by Felipe D'Abrantes's avatar Felipe D'Abrantes
Browse files

Add a Questions Management table

parent 362401e4
No related branches found
No related tags found
1 merge request!25Add a question management page
import NavBar from '@/components/navigation/NavBar';
import { useQuestions } from '@/hooks/useQuestions';
import { useUser } from '@/hooks/useUser';
import { useState } from 'react';
import NewQuestionForm from '@/components/questions/NewQuestionForm';
import QuestionList from '@/components/questions/QuestionList';
const Questions = () => {
const { user } = useUser();
const { questions, setRehydrateQuestions } = useQuestions();
const [newQuestion, setNewQuestion] = useState('');
const insertNewQuestion = async (newQuestion: String): Promise<void> => {
const JSONdata = JSON.stringify({ questionText: newQuestion });
const endpoint = `${process.env.NEXT_PUBLIC_FEED_SERVICE_URL}question`;
const options = {
method: 'POST',
headers: {
Authorization: `Bearer ${sessionStorage.getItem('token')}`,
'Content-Type': 'application/json'
},
body: JSONdata
};
await fetch(endpoint, options);
};
const onQuestionSubmit = (): void => {
insertNewQuestion(newQuestion);
setRehydrateQuestions(true);
};
return (
<div className="flex flex-col w-full items-center h-screen">
{/* Navigation Bar */}
<div className="w-full">
<NavBar user={user} />
</div>
{/* Question Insert */}
<NewQuestionForm
newQuestion={newQuestion}
setNewQuestion={setNewQuestion}
onSubmit={onQuestionSubmit}
/>
{/* List of Questions */}
<div className="flex flex-col items-center w-full shadow-lg min-h-32 pb-4 overflow-auto">
<h2 className="text-xl font-semibold leading-10 pt-4 text-gray-900">Questions Stored</h2>
{questions === undefined ? <p>Loading</p> : <QuestionList questions={questions} />}
</div>
</div>
);
};
export default Questions;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment