Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
survey
Commits
e7ae6d3f
Commit
e7ae6d3f
authored
Aug 15, 2022
by
Yoon, Daeki
😅
Browse files
verion 0.1 시작
parent
1ea0c555
Changes
50
Show whitespace changes
Inline
Side-by-side
frontend/src/questions/DropdownForm.tsx
View file @
e7ae6d3f
import
React
,
{
useState
}
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
Dropdown
Type
}
from
"
../types
"
;
import
{
I
Dropdown
}
from
"
../types
"
;
type
Props
=
{
type
Props
=
{
element
:
Dropdown
Type
;
element
:
I
Dropdown
;
handleQuestion
:
(
id
:
string
)
=>
void
;
handleQuestion
:
(
id
:
string
)
=>
void
;
isEditing
:
boolean
;
isEditing
:
boolean
;
};
};
...
...
frontend/src/questions/EssayForm.tsx
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
{
Essay
Type
}
from
"
../types
"
;
import
{
I
Essay
}
from
"
../types
"
;
type
Props
=
{
type
Props
=
{
element
:
Essay
Type
;
element
:
I
Essay
;
isEditing
:
boolean
;
isEditing
:
boolean
;
};
};
...
...
frontend/src/questions/FileForm.tsx
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
{
File
Type
}
from
"
../types
"
;
import
{
I
File
}
from
"
../types
"
;
type
Props
=
{
type
Props
=
{
element
:
File
Type
;
element
:
I
File
;
isEditing
:
boolean
;
isEditing
:
boolean
;
};
};
...
...
frontend/src/questions/Question.tsx
View file @
e7ae6d3f
import
React
,
{
useState
}
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
Basic
Question
Type
}
from
"
../types
"
;
import
{
I
Question
Data
}
from
"
../types
"
;
import
{
questionApi
}
from
"
../apis
"
;
import
{
questionApi
}
from
"
../apis
"
;
import
{
EssayForm
}
from
"
./EssayForm
"
;
import
{
EssayForm
}
from
"
./EssayForm
"
;
import
{
CheckboxForm
}
from
"
./CheckboxForm
"
;
import
{
CheckboxForm
}
from
"
./CheckboxForm
"
;
...
@@ -11,10 +11,10 @@ import { DateForm } from "./DateForm";
...
@@ -11,10 +11,10 @@ import { DateForm } from "./DateForm";
import
{
QUESTION_TYPES
}
from
"
../commons
"
;
import
{
QUESTION_TYPES
}
from
"
../commons
"
;
type
Props
=
{
type
Props
=
{
element
:
Basic
Question
Type
;
element
:
I
Question
Data
;
isEditing
:
boolean
;
isEditing
:
boolean
;
handleEditing
:
(
qid
:
string
,
isEditing
:
boolean
)
=>
void
;
handleEditing
:
(
qid
:
string
,
isEditing
:
boolean
)
=>
void
;
handleQuestion
:
(
element
:
Basic
Question
Type
)
=>
void
;
handleQuestion
:
(
element
:
I
Question
Data
)
=>
void
;
deleteQuestion
:
(
id
:
string
)
=>
void
;
deleteQuestion
:
(
id
:
string
)
=>
void
;
};
};
...
@@ -33,7 +33,7 @@ export const Question = ({
...
@@ -33,7 +33,7 @@ export const Question = ({
async
function
handleEditComplete
()
{
async
function
handleEditComplete
()
{
try
{
try
{
console
.
log
(
question
);
console
.
log
(
question
);
const
newQuestion
:
Basic
Question
Type
=
await
questionApi
.
updateQuestion
(
const
newQuestion
:
I
Question
Data
=
await
questionApi
.
updateQuestion
(
question
question
);
);
// console.log(newQuestion);
// console.log(newQuestion);
...
@@ -84,7 +84,7 @@ export const Question = ({
...
@@ -84,7 +84,7 @@ export const Question = ({
setQuestion
({
...
question
,
[
name
]:
value
});
setQuestion
({
...
question
,
[
name
]:
value
});
}
}
function
getContent
(
element
:
Basic
Question
Type
)
{
function
getContent
(
element
:
I
Question
Data
)
{
switch
(
element
.
type
)
{
switch
(
element
.
type
)
{
case
"
essay
"
:
case
"
essay
"
:
return
<
EssayForm
element
=
{
element
}
isEditing
=
{
isEditing
}
/>;
return
<
EssayForm
element
=
{
element
}
isEditing
=
{
isEditing
}
/>;
...
...
frontend/src/questions/RadioForm.tsx
View file @
e7ae6d3f
import
React
,
{
useState
}
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
Radio
Type
}
from
"
../types
"
;
import
{
I
Radio
}
from
"
../types
"
;
type
Props
=
{
type
Props
=
{
element
:
Radio
Type
;
element
:
I
Radio
;
handleQuestion
:
(
id
:
string
)
=>
void
;
handleQuestion
:
(
id
:
string
)
=>
void
;
isEditing
:
boolean
;
isEditing
:
boolean
;
};
};
...
...
frontend/src/questions/RatingForm.tsx
View file @
e7ae6d3f
import
React
,
{
useState
}
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
Rating
Type
}
from
"
../types
"
;
import
{
I
Rating
}
from
"
../types
"
;
type
Props
=
{
type
Props
=
{
element
:
Rating
Type
;
element
:
I
Rating
;
handleQuestion
:
(
id
:
string
)
=>
void
;
handleQuestion
:
(
id
:
string
)
=>
void
;
isEditing
:
boolean
;
isEditing
:
boolean
;
};
};
...
...
frontend/src/results/Accordion.tsx
View file @
e7ae6d3f
import
React
,
{
useState
,
useRef
,
useEffect
}
from
"
react
"
;
import
React
,
{
useState
,
useRef
,
useEffect
}
from
"
react
"
;
import
{
Basic
Question
Type
}
from
"
../types
"
;
import
{
I
Question
Data
}
from
"
../types
"
;
import
{
REssayForm
}
from
"
./REssayForm
"
;
import
{
REssayForm
}
from
"
./REssayForm
"
;
import
{
RCheckboxForm
}
from
"
./RCheckboxForm
"
;
import
{
RCheckboxForm
}
from
"
./RCheckboxForm
"
;
import
{
RRadioForm
}
from
"
./RRadioForm
"
;
import
{
RRadioForm
}
from
"
./RRadioForm
"
;
...
@@ -9,7 +9,7 @@ import { RRatingForm } from "./RRatingForm";
...
@@ -9,7 +9,7 @@ import { RRatingForm } from "./RRatingForm";
import
{
RDateForm
}
from
"
./RDateForm
"
;
import
{
RDateForm
}
from
"
./RDateForm
"
;
type
AccordionProps
=
{
type
AccordionProps
=
{
question
:
Basic
Question
Type
;
question
:
I
Question
Data
;
};
};
export
const
Accordion
=
({
question
}:
AccordionProps
)
=>
{
export
const
Accordion
=
({
question
}:
AccordionProps
)
=>
{
...
@@ -21,7 +21,7 @@ export const Accordion = ({ question }: AccordionProps) => {
...
@@ -21,7 +21,7 @@ export const Accordion = ({ question }: AccordionProps) => {
setOpened
(
!
isOpened
);
setOpened
(
!
isOpened
);
setHeight
(
!
isOpened
?
`
${
contentElement
.
current
?.
scrollHeight
}
px`
:
"
0px
"
);
setHeight
(
!
isOpened
?
`
${
contentElement
.
current
?.
scrollHeight
}
px`
:
"
0px
"
);
};
};
function
getContent
(
question
:
Basic
Question
Type
)
{
function
getContent
(
question
:
I
Question
Data
)
{
switch
(
question
.
type
)
{
switch
(
question
.
type
)
{
case
"
essay
"
:
case
"
essay
"
:
return
<
REssayForm
question
=
{
question
}
/>;
return
<
REssayForm
question
=
{
question
}
/>;
...
...
frontend/src/results/RCheckboxForm.tsx
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
{
Basic
Question
Type
}
from
"
../types
"
;
import
{
I
Question
Data
}
from
"
../types
"
;
type
Props
=
{
type
Props
=
{
question
:
Basic
Question
Type
;
question
:
I
Question
Data
;
};
};
export
const
RCheckboxForm
=
({
question
}:
Props
)
=>
{
export
const
RCheckboxForm
=
({
question
}:
Props
)
=>
{
...
...
frontend/src/results/RDateForm.tsx
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
{
Basic
Question
Type
}
from
"
../types
"
;
import
{
I
Question
Data
}
from
"
../types
"
;
type
Props
=
{
type
Props
=
{
question
:
Basic
Question
Type
;
question
:
I
Question
Data
;
};
};
export
const
RDateForm
=
({
question
}:
Props
)
=>
{
export
const
RDateForm
=
({
question
}:
Props
)
=>
{
...
...
frontend/src/results/RDropdownForm.tsx
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
{
Basic
Question
Type
}
from
"
../types
"
;
import
{
I
Question
Data
}
from
"
../types
"
;
type
Props
=
{
type
Props
=
{
question
:
Basic
Question
Type
;
question
:
I
Question
Data
;
};
};
export
const
RDropdownForm
=
({
question
}:
Props
)
=>
{
export
const
RDropdownForm
=
({
question
}:
Props
)
=>
{
...
...
frontend/src/results/REssayForm.tsx
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
{
Basic
Question
Type
}
from
"
../types
"
;
import
{
I
Question
Data
}
from
"
../types
"
;
type
Props
=
{
type
Props
=
{
question
:
Basic
Question
Type
;
question
:
I
Question
Data
;
};
};
export
const
REssayForm
=
({
question
}:
Props
)
=>
{
export
const
REssayForm
=
({
question
}:
Props
)
=>
{
...
...
frontend/src/results/RRadioForm.tsx
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
{
Basic
Question
Type
}
from
"
../types
"
;
import
{
I
Question
Data
}
from
"
../types
"
;
type
Props
=
{
type
Props
=
{
question
:
Basic
Question
Type
;
question
:
I
Question
Data
;
};
};
export
const
RRadioForm
=
({
question
}:
Props
)
=>
{
export
const
RRadioForm
=
({
question
}:
Props
)
=>
{
...
...
frontend/src/results/RRatingForm.tsx
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
{
Basic
Question
Type
}
from
"
../types
"
;
import
{
I
Question
Data
}
from
"
../types
"
;
type
Props
=
{
type
Props
=
{
question
:
Basic
Question
Type
;
question
:
I
Question
Data
;
};
};
export
const
RRatingForm
=
({
question
}:
Props
)
=>
{
export
const
RRatingForm
=
({
question
}:
Props
)
=>
{
...
...
frontend/src/survey/CreateSurvey.tsx
View file @
e7ae6d3f
...
@@ -3,7 +3,7 @@ import { useParams, useLocation, useNavigate } from "react-router-dom";
...
@@ -3,7 +3,7 @@ import { useParams, useLocation, useNavigate } from "react-router-dom";
import
{
questionApi
,
surveyApi
}
from
"
../apis
"
;
import
{
questionApi
,
surveyApi
}
from
"
../apis
"
;
import
{
SpinnerIcon
}
from
"
../icons
"
;
import
{
SpinnerIcon
}
from
"
../icons
"
;
import
{
Question
}
from
"
../questions
"
;
import
{
Question
}
from
"
../questions
"
;
import
{
Basic
Question
Type
,
Survey
Type
}
from
"
../types
"
;
import
{
I
Question
Data
,
I
Survey
}
from
"
../types
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
export
const
CreateSurvey
=
()
=>
{
export
const
CreateSurvey
=
()
=>
{
...
@@ -15,7 +15,7 @@ export const CreateSurvey = () => {
...
@@ -15,7 +15,7 @@ export const CreateSurvey = () => {
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
navigate
=
useNavigate
();
const
navigate
=
useNavigate
();
const
[
survey
,
setSurvey
]
=
useState
<
Survey
Type
>
({
const
[
survey
,
setSurvey
]
=
useState
<
I
Survey
>
({
_id
:
surveyId
||
""
,
_id
:
surveyId
||
""
,
user
:
{},
user
:
{},
title
:
""
,
title
:
""
,
...
@@ -30,7 +30,7 @@ export const CreateSurvey = () => {
...
@@ -30,7 +30,7 @@ export const CreateSurvey = () => {
async
function
getSurvey
()
{
async
function
getSurvey
()
{
try
{
try
{
if
(
surveyId
)
{
if
(
surveyId
)
{
const
thisSurvey
:
Survey
Type
=
await
surveyApi
.
getSurvey
(
surveyId
);
const
thisSurvey
:
I
Survey
=
await
surveyApi
.
getSurvey
(
surveyId
);
const
initEditing
=
thisSurvey
.
questions
.
map
((
question
)
=>
{
const
initEditing
=
thisSurvey
.
questions
.
map
((
question
)
=>
{
return
{
qid
:
question
.
_id
,
isEditing
:
false
};
return
{
qid
:
question
.
_id
,
isEditing
:
false
};
...
@@ -60,7 +60,7 @@ export const CreateSurvey = () => {
...
@@ -60,7 +60,7 @@ export const CreateSurvey = () => {
}
}
};
};
const
handleQuestion
=
(
element
:
Basic
Question
Type
)
=>
{
const
handleQuestion
=
(
element
:
I
Question
Data
)
=>
{
const
index
=
survey
.
questions
.
findIndex
(
const
index
=
survey
.
questions
.
findIndex
(
(
question
)
=>
question
.
_id
===
element
.
_id
(
question
)
=>
question
.
_id
===
element
.
_id
);
);
...
@@ -82,7 +82,7 @@ export const CreateSurvey = () => {
...
@@ -82,7 +82,7 @@ export const CreateSurvey = () => {
alert
(
"
아직 수정이 완료되지 않은 질문이 존재합니다.
"
);
alert
(
"
아직 수정이 완료되지 않은 질문이 존재합니다.
"
);
}
else
{
}
else
{
try
{
try
{
const
newSurvey
:
Survey
Type
=
await
surveyApi
.
editSurvey
(
survey
);
const
newSurvey
:
I
Survey
=
await
surveyApi
.
editSurvey
(
survey
);
console
.
log
(
newSurvey
);
console
.
log
(
newSurvey
);
setSuccess
(
true
);
setSuccess
(
true
);
alert
(
"
저장되었습니다
"
);
alert
(
"
저장되었습니다
"
);
...
@@ -103,7 +103,7 @@ export const CreateSurvey = () => {
...
@@ -103,7 +103,7 @@ export const CreateSurvey = () => {
// surveyId
// surveyId
// );
// );
// console.log(questions);
// console.log(questions);
const
question
:
Basic
Question
Type
=
await
questionApi
.
createQuestion
(
const
question
:
I
Question
Data
=
await
questionApi
.
createQuestion
(
surveyId
surveyId
);
);
console
.
log
(
question
);
console
.
log
(
question
);
...
@@ -126,11 +126,9 @@ export const CreateSurvey = () => {
...
@@ -126,11 +126,9 @@ export const CreateSurvey = () => {
}
}
async
function
deleteQuestion
(
id
:
string
)
{
async
function
deleteQuestion
(
id
:
string
)
{
const
newList
:
Basic
Question
Type
[]
=
[...
survey
.
questions
];
const
newList
:
I
Question
Data
[]
=
[...
survey
.
questions
];
try
{
try
{
const
newQuestion
:
BasicQuestionType
=
await
questionApi
.
deleteQuestion
(
const
newQuestion
:
IQuestionData
=
await
questionApi
.
deleteQuestion
(
id
);
id
);
setSurvey
({
...
survey
,
questions
:
newList
.
filter
((
a
)
=>
a
.
_id
!==
id
)
});
setSurvey
({
...
survey
,
questions
:
newList
.
filter
((
a
)
=>
a
.
_id
!==
id
)
});
setSuccess
(
true
);
setSuccess
(
true
);
setError
(
""
);
setError
(
""
);
...
...
frontend/src/survey/EditSurvey.tsx
View file @
e7ae6d3f
...
@@ -3,7 +3,7 @@ import { useParams, useLocation, useNavigate } from "react-router-dom";
...
@@ -3,7 +3,7 @@ import { useParams, useLocation, useNavigate } from "react-router-dom";
import
{
questionApi
,
surveyApi
}
from
"
../apis
"
;
import
{
questionApi
,
surveyApi
}
from
"
../apis
"
;
import
{
SpinnerIcon
}
from
"
../icons
"
;
import
{
SpinnerIcon
}
from
"
../icons
"
;
import
{
Question
}
from
"
../questions
"
;
import
{
Question
}
from
"
../questions
"
;
import
{
Basic
Question
Type
,
Survey
Type
}
from
"
../types
"
;
import
{
I
Question
Data
,
I
Survey
}
from
"
../types
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
export
const
EditSurvey
=
()
=>
{
export
const
EditSurvey
=
()
=>
{
...
@@ -17,7 +17,7 @@ export const EditSurvey = () => {
...
@@ -17,7 +17,7 @@ export const EditSurvey = () => {
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
navigate
=
useNavigate
();
const
navigate
=
useNavigate
();
const
[
survey
,
setSurvey
]
=
useState
<
Survey
Type
>
({
const
[
survey
,
setSurvey
]
=
useState
<
I
Survey
>
({
_id
:
surveyId
||
""
,
_id
:
surveyId
||
""
,
user
:
{},
user
:
{},
title
:
""
,
title
:
""
,
...
@@ -32,7 +32,7 @@ export const EditSurvey = () => {
...
@@ -32,7 +32,7 @@ export const EditSurvey = () => {
async
function
getSurvey
()
{
async
function
getSurvey
()
{
try
{
try
{
if
(
surveyId
)
{
if
(
surveyId
)
{
const
thisSurvey
:
Survey
Type
=
await
surveyApi
.
getSurvey
(
surveyId
);
const
thisSurvey
:
I
Survey
=
await
surveyApi
.
getSurvey
(
surveyId
);
const
initEditing
=
thisSurvey
.
questions
.
map
((
question
)
=>
{
const
initEditing
=
thisSurvey
.
questions
.
map
((
question
)
=>
{
return
{
qid
:
question
.
_id
,
isEditing
:
false
};
return
{
qid
:
question
.
_id
,
isEditing
:
false
};
...
@@ -62,7 +62,7 @@ export const EditSurvey = () => {
...
@@ -62,7 +62,7 @@ export const EditSurvey = () => {
}
}
};
};
const
handleQuestion
=
(
element
:
Basic
Question
Type
)
=>
{
const
handleQuestion
=
(
element
:
I
Question
Data
)
=>
{
const
index
=
survey
.
questions
.
findIndex
(
const
index
=
survey
.
questions
.
findIndex
(
(
question
)
=>
question
.
_id
===
element
.
_id
(
question
)
=>
question
.
_id
===
element
.
_id
);
);
...
@@ -84,7 +84,7 @@ export const EditSurvey = () => {
...
@@ -84,7 +84,7 @@ export const EditSurvey = () => {
alert
(
"
아직 수정이 완료되지 않은 질문이 존재합니다.
"
);
alert
(
"
아직 수정이 완료되지 않은 질문이 존재합니다.
"
);
}
else
{
}
else
{
try
{
try
{
const
newSurvey
:
Survey
Type
=
await
surveyApi
.
editSurvey
(
survey
);
const
newSurvey
:
I
Survey
=
await
surveyApi
.
editSurvey
(
survey
);
console
.
log
(
newSurvey
);
console
.
log
(
newSurvey
);
setSuccess
(
true
);
setSuccess
(
true
);
alert
(
"
저장되었습니다
"
);
alert
(
"
저장되었습니다
"
);
...
@@ -105,7 +105,7 @@ export const EditSurvey = () => {
...
@@ -105,7 +105,7 @@ export const EditSurvey = () => {
// surveyId
// surveyId
// );
// );
// console.log(questions);
// console.log(questions);
const
question
:
Basic
Question
Type
=
await
questionApi
.
createQuestion
(
const
question
:
I
Question
Data
=
await
questionApi
.
createQuestion
(
surveyId
surveyId
);
);
console
.
log
(
question
);
console
.
log
(
question
);
...
@@ -132,11 +132,9 @@ export const EditSurvey = () => {
...
@@ -132,11 +132,9 @@ export const EditSurvey = () => {
}
}
async
function
deleteQuestion
(
id
:
string
)
{
async
function
deleteQuestion
(
id
:
string
)
{
const
newList
:
Basic
Question
Type
[]
=
[...
survey
.
questions
];
const
newList
:
I
Question
Data
[]
=
[...
survey
.
questions
];
try
{
try
{
const
newQuestion
:
BasicQuestionType
=
await
questionApi
.
deleteQuestion
(
const
newQuestion
:
IQuestionData
=
await
questionApi
.
deleteQuestion
(
id
);
id
);
setSurvey
({
...
survey
,
questions
:
newList
.
filter
((
a
)
=>
a
.
_id
!==
id
)
});
setSurvey
({
...
survey
,
questions
:
newList
.
filter
((
a
)
=>
a
.
_id
!==
id
)
});
setSuccess
(
true
);
setSuccess
(
true
);
setError
(
""
);
setError
(
""
);
...
...
frontend/src/survey/ResultSurvey.tsx
View file @
e7ae6d3f
...
@@ -3,14 +3,14 @@ import { answerApi, surveyApi } from "../apis";
...
@@ -3,14 +3,14 @@ import { answerApi, surveyApi } from "../apis";
import
{
catchErrors
}
from
"
../helpers
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
import
{
Accordion
}
from
"
../results
"
;
import
{
Accordion
}
from
"
../results
"
;
import
{
useParams
}
from
"
react-router-dom
"
;
import
{
useParams
}
from
"
react-router-dom
"
;
import
{
Survey
Type
}
from
"
../types
"
;
import
{
I
Survey
}
from
"
../types
"
;
export
const
ResultSurvey
=
()
=>
{
export
const
ResultSurvey
=
()
=>
{
let
{
surveyId
}
=
useParams
<
{
surveyId
:
string
}
>
();
let
{
surveyId
}
=
useParams
<
{
surveyId
:
string
}
>
();
const
[
error
,
setError
]
=
useState
(
""
);
const
[
error
,
setError
]
=
useState
(
""
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
[
survey
,
setSurvey
]
=
useState
<
Survey
Type
>
({
const
[
survey
,
setSurvey
]
=
useState
<
I
Survey
>
({
_id
:
surveyId
||
""
,
_id
:
surveyId
||
""
,
user
:
{},
user
:
{},
title
:
""
,
title
:
""
,
...
...
frontend/src/surveys/AnswerSurvey.tsx
0 → 100644
View file @
e7ae6d3f
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
{
useParams
}
from
"
react-router-dom
"
;
import
{
surveyApi
}
from
"
../apis
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
import
{
SpinnerIcon
}
from
"
../icons
"
;
import
{
ISurvey
}
from
"
../types
"
;
export
const
AnswerSurvey
=
()
=>
{
let
{
surveyId
}
=
useParams
<
{
surveyId
:
string
}
>
();
const
[
survey
,
setSurvey
]
=
useState
<
ISurvey
>
();
const
[
error
,
setError
]
=
useState
(
""
);
useEffect
(()
=>
{
surveyId
&&
getSurvey
(
surveyId
);
},
[
surveyId
]);
const
handleSubmit
=
()
=>
{};
async
function
getSurvey
(
surveyId
:
string
)
{
try
{
setError
(
""
);
const
survey
:
any
=
await
surveyApi
.
getSurveyById
(
surveyId
);
console
.
log
(
"
survey가져옴ㅎㅎ
"
,
survey
);
// answerSurvey.current._id = survey._id;
// answerSurvey.current.questions = survey.questions;
setSurvey
(
survey
);
// setSuccess(true);
}
catch
(
error
)
{
catchErrors
(
error
,
setError
);
}
finally
{
// setLoading(false);
}
}
if
(
!
survey
)
{
return
(
<
div
className
=
"flex justify-center mt-5"
>
<
SpinnerIcon
className
=
"animate-spin h-10 w-10 mr-1 bg-white text-slate-500"
/>
</
div
>
);
}
return
(
<
form
onSubmit
=
{
handleSubmit
}
>
<
div
className
=
"flex flex-col place-items-center"
>
<
div
className
=
"flex flex-col container place-items-center mt-4"
>
<
p
className
=
"font-bold text-4xl text-center m-2"
>
{
survey
.
title
}
</
p
>
<
p
className
=
"font-bold text-1xl text-center m-2"
>
{
survey
.
comment
}
</
p
>
{
/* {survey.questions.map((question, index) => {
return (
<AQuestion
key={question._id}
question={question}
answerQuestion={answerSurvey.current.questions[index]}
addFiles={addFiles}
></AQuestion>
);
})} */
}
<
div
>
<
button
type
=
"submit"
className
=
"rounded bg-themeColor my-5 py-2 px-5 font-bold text-white"
>
제출하기
</
button
>
</
div
>
</
div
>
</
div
>
</
form
>
);
};
frontend/src/surveys/CreateSurvey.tsx
0 → 100644
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
{
surveyApi
}
from
"
../apis
"
;
import
{
ISurvey
}
from
"
../types
"
;
import
{
ModifySurvey
}
from
"
./ModifySurvey
"
;
export
const
CreateSurvey
=
()
=>
{
const
surveyData
=
{
_id
:
""
,
user
:
""
,
title
:
""
,
comment
:
""
,
questions
:
[],
};
const
create
=
async
(
surveyData
:
ISurvey
)
=>
{
const
result
=
await
surveyApi
.
createSurvey
(
surveyData
);
return
result
;
};
return
<
ModifySurvey
surveyData
=
{
surveyData
}
callApi
=
{
create
}
/>;
};
frontend/src/surveys/EditSurvey.tsx
0 → 100644
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
{
useLocation
}
from
"
react-router-dom
"
;
import
{
surveyApi
}
from
"
../apis
"
;
import
{
ISurvey
}
from
"
../types
"
;
import
{
ModifySurvey
}
from
"
./ModifySurvey
"
;
export
const
EditSurvey
=
()
=>
{
const
location
=
useLocation
();
const
surveyState
=
location
.
state
as
ISurvey
;
console
.
log
(
"
edit survey:
"
,
surveyState
);
const
update
=
async
(
surveyData
:
ISurvey
)
=>
{
const
result
=
await
surveyApi
.
updateSurvey
(
surveyData
);
return
result
;
};
return
<
ModifySurvey
surveyData
=
{
surveyState
}
callApi
=
{
update
}
/>;
};
frontend/src/surveys/ModifySurvey.tsx
0 → 100644
View file @
e7ae6d3f
import
React
,
{
ChangeEvent
,
FormEvent
,
useState
}
from
"
react
"
;
import
{
useNavigate
}
from
"
react-router-dom
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
import
{
SpinnerIcon
}
from
"
../icons
"
;
import
{
CreateQuestionData
,
ISurvey
}
from
"
../types
"
;
import
{
QuestionsList
}
from
"
./QuestionsList
"
;
type
Props
=
{
surveyData
:
ISurvey
;
callApi
:
(
surveyData
:
ISurvey
)
=>
Promise
<
any
>
;
};
export
const
ModifySurvey
=
({
surveyData
,
callApi
}:
Props
)
=>
{
const
[
error
,
setError
]
=
useState
(
""
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
survey
,
setSurvey
]
=
useState
<
ISurvey
>
(
surveyData
);
const
[
questions
,
setQuestions
]
=
useState
<
CreateQuestionData
[]
>
(()
=>
{
const
questions
=
survey
.
questions
;
return
questions
.
map
((
question
)
=>
({
...
question
,
isEditing
:
false
}));
});
const
navigate
=
useNavigate
();
const
handleChange
=
(
e
:
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
{
name
,
value
}
=
e
.
target
;
setSurvey
({
...
survey
,
[
name
]:
value
});
};
const
hasIncompleteEditing
=
()
=>
{
if
(
questions
.
length
<=
0
)
{
return
true
;
}
const
incompleted
=
questions
.
some
((
question
)
=>
question
.
isEditing
);
return
incompleted
;
};
const
handleQuestion
=
(
question
:
CreateQuestionData
)
=>
{
const
index
=
questions
.
findIndex
((
q
)
=>
q
.
_id
===
question
.
_id
);
if
(
index
<
0
)
{
return
;
}
questions
[
index
]
=
question
;
console
.
log
(
"
handle question questions:
"
,
questions
);
setQuestions
([...
questions
]);
};
const
handleSubmit
=
async
(
e
:
FormEvent
)
=>
{
e
.
preventDefault
();
survey
.
questions
=
questions
;
try
{
setLoading
(
true
);
const
result
=
await
callApi
(
survey
);
console
.
log
(
"
result:
"
,
result
);
navigate
(
"
/surveys/profile
"
,
{
replace
:
true
});
}
catch
(
error
)
{
setLoading
(
false
);
catchErrors
(
error
,
setError
);
}
};
const
addQuestion
=
()
=>
{
const
question
:
CreateQuestionData
=
{
_id
:
Math
.
random
().
toString
(),
order
:
questions
.
length
,
type
:
"
singletext
"
,
title
:
""
,
comment
:
""
,
isRequired
:
false
,
content
:
{
choices
:
[]
},
isEditing
:
true
,
};
setQuestions
([...
questions
,
question
]);
};
async
function
deleteQuestion
(
id
:
string
)
{
const
delQuestions
=
questions
.
filter
((
question
)
=>
question
.
_id
!==
id
);
setQuestions
(
delQuestions
);
}
const
disabled
=
hasIncompleteEditing
();
return
(
<>
{
loading
&&
(
<
SpinnerIcon
className
=
"animate-spin h-5 w-5 mr-1 text-slate"
/>
)
}
<
form
onSubmit
=
{
handleSubmit
}
>
<
div
className
=
"flex flex-col place-items-center"
>
<
div
className
=
"flex flex-col container place-items-center mt-4"
>
<
input
type
=
"text"
name
=
"title"
className
=
"font-bold text-4xl text-center m-2 border-b-2"
placeholder
=
"설문지 제목"
autoComplete
=
"on"
value
=
{
survey
.
title
}
onChange
=
{
handleChange
}
></
input
>
<
input
type
=
"text"
name
=
"comment"
className
=
"font-bold text-1xl text-center m-2 border-b-2 resize-none"
placeholder
=
"설문조사에 대한 설명을 입력해주세요"
autoComplete
=
"on"
size
=
{
50
}
value
=
{
survey
.
comment
}
onChange
=
{
handleChange
}
></
input
>
</
div
>
<
QuestionsList
questions
=
{
questions
}
handleQuestion
=
{
handleQuestion
}
deleteQuestion
=
{
deleteQuestion
}
/>
<
button
type
=
"button"
onClick
=
{
addQuestion
}
className
=
"flex w-4/5 content-center justify-center border-2 border-black h-8 mt-3"
>
질문 추가
</
button
>
{
error
&&
(
<
div
className
=
"text-red-500 text-sm mt-3"
>
<
p
>
{
error
}
</
p
>
</
div
>
)
}
<
button
type
=
"submit"
disabled
=
{
disabled
}
title
=
{
`
${
disabled
?
"
완성되지 않은 부분이 존재합니다
"
:
""
}
`
}
className
=
"border bg-themeColor my-5 py-2 px-3 disabled:opacity-60 font-bold text-white"
>
저장
</
button
>
</
div
>
</
form
>
</>
);
};
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment