Commit 0293a649 authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

DateForm, RatingForm

parent 4f17e307
import React from "react"; import React, { useState } from "react";
import { DateType, AnswerType } from "../types";
export const ADateForm = () => { type Props = {
element: DateType;
response: AnswerType;
handleAnswer: () => void;
};
export const ADateForm = ({ element, response, handleAnswer }: Props) => {
const [answer, setAnswer] = useState("");
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.currentTarget;
response.answers.map((a) => {
if (a.questionId === element._id) {
a.answer = value;
}
});
setAnswer(value);
handleAnswer();
};
return ( return (
<div className="justify-start w-11/12 m-3 py-4"> <div className="justify-start w-11/12 m-3 py-4">
<input type="date"></input> <input
type="date"
onChange={handleChange}
required={element.isRequired}
></input>
</div> </div>
); );
}; };
...@@ -64,18 +64,22 @@ export const AQuestion = ({ ...@@ -64,18 +64,22 @@ export const AQuestion = ({
addFiles={addFiles} addFiles={addFiles}
/> />
); );
// case "rating":
// return (
// <ARatingForm
// handleQuestion={handleQuestion}
// element={element}
// currentId={currentId}
// />
// );
case "rating": case "rating":
return <ARatingForm element={question} />; return (
<ARatingForm
element={question}
response={response}
handleAnswer={handleAnswer}
/>
);
case "date": case "date":
return <ADateForm />; return (
<ADateForm
element={question}
response={response}
handleAnswer={handleAnswer}
/>
);
default: default:
return <></>; return <></>;
} }
......
import React, { useState } from "react"; import React, { useState } from "react";
import { RatingType } from "../types"; import { RatingType, AnswerType } from "../types";
type Props = { type Props = {
element: RatingType; element: RatingType;
response: AnswerType;
handleAnswer: () => void;
}; };
export const ARatingForm = ({ element }: Props) => { export const ARatingForm = ({ element, response, handleAnswer }: Props) => {
const [selectedchoice, setSelectedchoice] = useState(""); const [selectedchoice, setSelectedchoice] = useState("");
const [answer, setAnswer] = useState("");
function buttonClick(event: React.MouseEvent<HTMLButtonElement>) { function buttonClick(event: React.MouseEvent<HTMLButtonElement>) {
event.preventDefault(); event.preventDefault();
const { name } = event.currentTarget;
response.answers.map((a) => {
if (a.questionId === element._id) {
a.answer = name;
}
});
setAnswer(name);
setSelectedchoice(event.currentTarget.name); setSelectedchoice(event.currentTarget.name);
handleAnswer();
} }
return ( return (
<div className="flex w-full justify-center space-x-12 my-3"> <div className="flex w-full justify-center space-x-12 my-3">
......
...@@ -31,6 +31,7 @@ export interface BasicQuestionType { ...@@ -31,6 +31,7 @@ export interface BasicQuestionType {
} }
export interface EssayType extends BasicQuestionType {} export interface EssayType extends BasicQuestionType {}
export interface DateType extends BasicQuestionType {}
export interface RadioType extends BasicQuestionType { export interface RadioType extends BasicQuestionType {
content: { content: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment