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

Allocate delete button to disable endpoint

parent a5784fce
No related branches found
No related tags found
1 merge request!25Add a question management page
...@@ -5,9 +5,10 @@ import styles from '../../styles/Scrollbox.module.css'; ...@@ -5,9 +5,10 @@ import styles from '../../styles/Scrollbox.module.css';
type QuestionListProps = { type QuestionListProps = {
questions: QuestionRecord[]; questions: QuestionRecord[];
onDeleteClick: (questionId: string) => void;
}; };
const QuestionList: FC<QuestionListProps> = ({ questions }) => ( const QuestionList: FC<QuestionListProps> = ({ questions, onDeleteClick }) => (
<ul <ul
role="list" role="list"
className={ className={
...@@ -21,7 +22,7 @@ const QuestionList: FC<QuestionListProps> = ({ questions }) => ( ...@@ -21,7 +22,7 @@ const QuestionList: FC<QuestionListProps> = ({ questions }) => (
className="flex flex-row items-center justify-between gap-x-6 py-5 px-4 " className="flex flex-row items-center justify-between gap-x-6 py-5 px-4 "
> >
<p className="text-base font-semibold leading-6 text-gray-900">{question.content}</p> <p className="text-base font-semibold leading-6 text-gray-900">{question.content}</p>
<TrashIcon className="shrink-0 h-6 w-6" /> <TrashIcon className="shrink-0 h-6 w-6 cursor-pointer" type='button' onClick={() => onDeleteClick(question.id)} />
</li> </li>
))} ))}
</ul> </ul>
......
...@@ -14,7 +14,7 @@ const Questions = () => { ...@@ -14,7 +14,7 @@ const Questions = () => {
const insertNewQuestion = async (newQuestion: String): Promise<void> => { const insertNewQuestion = async (newQuestion: String): Promise<void> => {
const JSONdata = JSON.stringify({ questionText: newQuestion }); const JSONdata = JSON.stringify({ questionText: newQuestion });
const endpoint = `${process.env.NEXT_PUBLIC_FEED_SERVICE_URL}question`; const endpoint = `${process.env.NEXT_PUBLIC_FEED_SERVICE_URL}insertQuestion`;
const options = { const options = {
method: 'POST', method: 'POST',
headers: { headers: {
...@@ -46,12 +46,30 @@ const Questions = () => { ...@@ -46,12 +46,30 @@ const Questions = () => {
} }
}; };
const onQuestionSubmit = async (): Promise<void> => { const deleteQuestion = async (questionId: String): Promise<void> => {
const endpoint = `${process.env.NEXT_PUBLIC_FEED_SERVICE_URL}disableQuestion?questionId=${questionId}`;
const options = {
method: 'POST',
headers: {
Authorization: `Bearer ${sessionStorage.getItem('token')}`,
'Content-Type': 'application/json'
}
};
await fetch(endpoint, options);
};
const onQuestionInsert = async (): Promise<void> => {
await insertNewQuestion(newQuestion); await insertNewQuestion(newQuestion);
setNewQuestion(''); setNewQuestion('');
setRehydrateQuestions(true); setRehydrateQuestions(true);
}; };
const onQuestionDelete = async (questionId: string): Promise<void> => {
await deleteQuestion(questionId);
setRehydrateQuestions(true);
};
return ( return (
<div className="flex flex-col w-full items-center h-screen"> <div className="flex flex-col w-full items-center h-screen">
{/* Navigation Bar */} {/* Navigation Bar */}
...@@ -63,14 +81,14 @@ const Questions = () => { ...@@ -63,14 +81,14 @@ const Questions = () => {
<NewQuestionForm <NewQuestionForm
newQuestion={newQuestion} newQuestion={newQuestion}
setNewQuestion={setNewQuestion} setNewQuestion={setNewQuestion}
onSubmit={onQuestionSubmit} onSubmit={onQuestionInsert}
statusMessage={statusMessage} statusMessage={statusMessage}
/> />
{/* List of Questions */} {/* List of Questions */}
<div className="flex flex-col items-center w-full shadow-lg min-h-32 pb-4 overflow-auto"> <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> <h2 className="text-xl font-semibold leading-10 pt-4 text-gray-900">Questions Stored</h2>
{questions === undefined ? <p>Loading</p> : <QuestionList questions={questions} />} {questions === undefined ? <p>Loading</p> : <QuestionList questions={questions} onDeleteClick={onQuestionDelete}/>}
</div> </div>
</div> </div>
); );
......
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