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
1865b708
Commit
1865b708
authored
Jul 22, 2022
by
Yoon, Daeki
😅
Browse files
answer type 배열로 변경
parent
fb053bba
Changes
10
Hide whitespace changes
Inline
Side-by-side
frontend/src/commons/ACheckboxForm.tsx
View file @
1865b708
...
@@ -3,7 +3,7 @@ import { CheckboxType, AnswersType } from "../types";
...
@@ -3,7 +3,7 @@ import { CheckboxType, AnswersType } from "../types";
type
Props
=
{
type
Props
=
{
element
:
CheckboxType
;
element
:
CheckboxType
;
answers
:
AnswersType
;
answers
:
AnswersType
|
undefined
;
handleAnswer
:
()
=>
void
;
handleAnswer
:
()
=>
void
;
};
};
...
@@ -17,7 +17,7 @@ export const ACheckboxForm = ({ element, answers, handleAnswer }: Props) => {
...
@@ -17,7 +17,7 @@ export const ACheckboxForm = ({ element, answers, handleAnswer }: Props) => {
// a.answer = value;
// a.answer = value;
// }
// }
// });
// });
answers
[
element
.
_id
]
=
value
;
answers
&&
(
answers
.
answer
=
value
)
;
setAnswer
(
value
);
setAnswer
(
value
);
handleAnswer
();
handleAnswer
();
};
};
...
...
frontend/src/commons/ADateForm.tsx
View file @
1865b708
...
@@ -2,7 +2,7 @@ import React, { useState } from "react";
...
@@ -2,7 +2,7 @@ import React, { useState } from "react";
import
{
DateType
,
AnswersType
}
from
"
../types
"
;
import
{
DateType
,
AnswersType
}
from
"
../types
"
;
type
Props
=
{
type
Props
=
{
element
:
DateType
;
element
:
DateType
;
answers
:
AnswersType
;
answers
:
AnswersType
|
undefined
;
handleAnswer
:
()
=>
void
;
handleAnswer
:
()
=>
void
;
};
};
export
const
ADateForm
=
({
element
,
answers
,
handleAnswer
}:
Props
)
=>
{
export
const
ADateForm
=
({
element
,
answers
,
handleAnswer
}:
Props
)
=>
{
...
@@ -14,7 +14,7 @@ export const ADateForm = ({ element, answers, handleAnswer }: Props) => {
...
@@ -14,7 +14,7 @@ export const ADateForm = ({ element, answers, handleAnswer }: Props) => {
// a.answer = value;
// a.answer = value;
// }
// }
// });
// });
answers
[
element
.
_id
]
=
value
;
answers
&&
(
answers
.
answer
=
value
)
;
setAnswer
(
value
);
setAnswer
(
value
);
handleAnswer
();
handleAnswer
();
};
};
...
...
frontend/src/commons/ADropdownForm.tsx
View file @
1865b708
...
@@ -3,7 +3,7 @@ import { DropdownType, AnswersType } from "../types";
...
@@ -3,7 +3,7 @@ import { DropdownType, AnswersType } from "../types";
type
Props
=
{
type
Props
=
{
element
:
DropdownType
;
element
:
DropdownType
;
answers
:
AnswersType
;
answers
:
AnswersType
|
undefined
;
handleAnswer
:
()
=>
void
;
handleAnswer
:
()
=>
void
;
};
};
...
@@ -17,7 +17,7 @@ export const ADropdownForm = ({ element, handleAnswer, answers }: Props) => {
...
@@ -17,7 +17,7 @@ export const ADropdownForm = ({ element, handleAnswer, answers }: Props) => {
// a.answer = value;
// a.answer = value;
// }
// }
// });
// });
answers
[
element
.
_id
]
=
value
;
answers
&&
(
answers
.
answer
=
value
)
;
setAnswer
(
value
);
setAnswer
(
value
);
handleAnswer
();
handleAnswer
();
};
};
...
...
frontend/src/commons/AEssayForm.tsx
View file @
1865b708
...
@@ -3,15 +3,11 @@ import { EssayType, AnswersType } from "../types";
...
@@ -3,15 +3,11 @@ import { EssayType, AnswersType } from "../types";
type
Props
=
{
type
Props
=
{
element
:
EssayType
;
element
:
EssayType
;
answers
:
AnswersType
;
answers
:
AnswersType
|
undefined
;
handleAnswer
:
()
=>
void
;
handleAnswer
:
()
=>
void
;
};
};
export
const
AEssayForm
=
({
export
const
AEssayForm
=
({
element
,
handleAnswer
,
answers
}:
Props
)
=>
{
element
,
handleAnswer
,
answers
:
answers
,
}:
Props
)
=>
{
const
[
answer
,
setAnswer
]
=
useState
(
""
);
const
[
answer
,
setAnswer
]
=
useState
(
""
);
const
handleChange
=
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
handleChange
=
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
...
@@ -21,7 +17,7 @@ export const AEssayForm = ({
...
@@ -21,7 +17,7 @@ export const AEssayForm = ({
// a.answer = value;
// a.answer = value;
// }
// }
// });
// });
answers
[
element
.
_id
]
=
value
;
answers
&&
(
answers
.
answer
=
value
)
;
setAnswer
(
value
);
setAnswer
(
value
);
handleAnswer
();
handleAnswer
();
};
};
...
...
frontend/src/commons/AFileForm.tsx
View file @
1865b708
...
@@ -3,7 +3,7 @@ import { FileType, AnswersType } from "../types";
...
@@ -3,7 +3,7 @@ import { FileType, AnswersType } from "../types";
type
Props
=
{
type
Props
=
{
element
:
FileType
;
element
:
FileType
;
answers
:
AnswersType
;
answers
:
AnswersType
|
undefined
;
handleAnswer
:
()
=>
void
;
handleAnswer
:
()
=>
void
;
addFiles
:
(
oneFile
:
{
questionId
:
string
;
file
:
File
})
=>
void
;
addFiles
:
(
oneFile
:
{
questionId
:
string
;
file
:
File
})
=>
void
;
};
};
...
@@ -23,7 +23,7 @@ export const AFileForm = ({
...
@@ -23,7 +23,7 @@ export const AFileForm = ({
// a.answer = uploadFile.name;
// a.answer = uploadFile.name;
// }
// }
// });
// });
answers
[
element
.
_id
]
=
uploadFile
.
name
;
answers
&&
(
answers
.
answer
=
uploadFile
.
name
)
;
handleAnswer
();
handleAnswer
();
}
}
};
};
...
...
frontend/src/commons/AQuestion.tsx
View file @
1865b708
...
@@ -10,14 +10,14 @@ import { ARatingForm } from "./ARatingForm";
...
@@ -10,14 +10,14 @@ import { ARatingForm } from "./ARatingForm";
type
Props
=
{
type
Props
=
{
question
:
BasicQuestionType
;
question
:
BasicQuestionType
;
answer
s
:
AnswersType
;
answer
:
AnswersType
|
undefined
;
handleAnswer
:
()
=>
void
;
handleAnswer
:
()
=>
void
;
addFiles
:
(
oneFile
:
{
questionId
:
string
;
file
:
File
})
=>
void
;
addFiles
:
(
oneFile
:
{
questionId
:
string
;
file
:
File
})
=>
void
;
};
};
export
const
AQuestion
=
({
export
const
AQuestion
=
({
question
,
question
,
handleAnswer
,
handleAnswer
,
answer
s
:
answers
,
answer
,
addFiles
,
addFiles
,
}:
Props
)
=>
{
}:
Props
)
=>
{
function
getContent
(
question
:
BasicQuestionType
)
{
function
getContent
(
question
:
BasicQuestionType
)
{
...
@@ -26,7 +26,7 @@ export const AQuestion = ({
...
@@ -26,7 +26,7 @@ export const AQuestion = ({
return
(
return
(
<
AEssayForm
<
AEssayForm
element
=
{
question
}
element
=
{
question
}
answers
=
{
answer
s
}
answers
=
{
answer
}
handleAnswer
=
{
handleAnswer
}
handleAnswer
=
{
handleAnswer
}
/>
/>
);
);
...
@@ -34,7 +34,7 @@ export const AQuestion = ({
...
@@ -34,7 +34,7 @@ export const AQuestion = ({
return
(
return
(
<
ARadioForm
<
ARadioForm
element
=
{
question
}
element
=
{
question
}
answers
=
{
answer
s
}
answers
=
{
answer
}
handleAnswer
=
{
handleAnswer
}
handleAnswer
=
{
handleAnswer
}
/>
/>
);
);
...
@@ -42,7 +42,7 @@ export const AQuestion = ({
...
@@ -42,7 +42,7 @@ export const AQuestion = ({
return
(
return
(
<
ACheckboxForm
<
ACheckboxForm
element
=
{
question
}
element
=
{
question
}
answers
=
{
answer
s
}
answers
=
{
answer
}
handleAnswer
=
{
handleAnswer
}
handleAnswer
=
{
handleAnswer
}
/>
/>
);
);
...
@@ -50,7 +50,7 @@ export const AQuestion = ({
...
@@ -50,7 +50,7 @@ export const AQuestion = ({
return
(
return
(
<
ADropdownForm
<
ADropdownForm
element
=
{
question
}
element
=
{
question
}
answers
=
{
answer
s
}
answers
=
{
answer
}
handleAnswer
=
{
handleAnswer
}
handleAnswer
=
{
handleAnswer
}
/>
/>
);
);
...
@@ -58,7 +58,7 @@ export const AQuestion = ({
...
@@ -58,7 +58,7 @@ export const AQuestion = ({
return
(
return
(
<
AFileForm
<
AFileForm
element
=
{
question
}
element
=
{
question
}
answers
=
{
answer
s
}
answers
=
{
answer
}
handleAnswer
=
{
handleAnswer
}
handleAnswer
=
{
handleAnswer
}
addFiles
=
{
addFiles
}
addFiles
=
{
addFiles
}
/>
/>
...
@@ -67,7 +67,7 @@ export const AQuestion = ({
...
@@ -67,7 +67,7 @@ export const AQuestion = ({
return
(
return
(
<
ARatingForm
<
ARatingForm
element
=
{
question
}
element
=
{
question
}
answers
=
{
answer
s
}
answers
=
{
answer
}
handleAnswer
=
{
handleAnswer
}
handleAnswer
=
{
handleAnswer
}
/>
/>
);
);
...
@@ -75,7 +75,7 @@ export const AQuestion = ({
...
@@ -75,7 +75,7 @@ export const AQuestion = ({
return
(
return
(
<
ADateForm
<
ADateForm
element
=
{
question
}
element
=
{
question
}
answers
=
{
answer
s
}
answers
=
{
answer
}
handleAnswer
=
{
handleAnswer
}
handleAnswer
=
{
handleAnswer
}
/>
/>
);
);
...
...
frontend/src/commons/ARadioForm.tsx
View file @
1865b708
...
@@ -3,7 +3,7 @@ import { RadioType, AnswersType } from "../types";
...
@@ -3,7 +3,7 @@ import { RadioType, AnswersType } from "../types";
type
Props
=
{
type
Props
=
{
element
:
RadioType
;
element
:
RadioType
;
answers
:
AnswersType
;
answers
:
AnswersType
|
undefined
;
handleAnswer
:
()
=>
void
;
handleAnswer
:
()
=>
void
;
};
};
...
@@ -17,7 +17,7 @@ export const ARadioForm = ({ element, answers, handleAnswer }: Props) => {
...
@@ -17,7 +17,7 @@ export const ARadioForm = ({ element, answers, handleAnswer }: Props) => {
// a.answer = value;
// a.answer = value;
// }
// }
// });
// });
answers
[
element
.
_id
]
=
value
;
answers
&&
(
answers
.
answer
=
value
)
;
setAnswer
(
value
);
setAnswer
(
value
);
handleAnswer
();
handleAnswer
();
};
};
...
...
frontend/src/commons/ARatingForm.tsx
View file @
1865b708
...
@@ -3,7 +3,7 @@ import { RatingType, AnswersType } from "../types";
...
@@ -3,7 +3,7 @@ import { RatingType, AnswersType } from "../types";
type
Props
=
{
type
Props
=
{
element
:
RatingType
;
element
:
RatingType
;
answers
:
AnswersType
;
answers
:
AnswersType
|
undefined
;
handleAnswer
:
()
=>
void
;
handleAnswer
:
()
=>
void
;
};
};
...
@@ -19,7 +19,7 @@ export const ARatingForm = ({ element, answers, handleAnswer }: Props) => {
...
@@ -19,7 +19,7 @@ export const ARatingForm = ({ element, answers, handleAnswer }: Props) => {
// a.answer = name;
// a.answer = name;
// }
// }
// });
// });
answers
[
element
.
_id
]
=
name
;
answers
&&
(
answers
.
answer
=
name
)
;
setAnswer
(
name
);
setAnswer
(
name
);
setSelectedchoice
(
event
.
currentTarget
.
name
);
setSelectedchoice
(
event
.
currentTarget
.
name
);
handleAnswer
();
handleAnswer
();
...
...
frontend/src/commons/SurveyForm.tsx
View file @
1865b708
...
@@ -22,25 +22,22 @@ export const SurveyForm = () => {
...
@@ -22,25 +22,22 @@ export const SurveyForm = () => {
const
answer
=
useRef
<
AnswerType
>
({
const
answer
=
useRef
<
AnswerType
>
({
surveyId
:
"
surveyId
"
,
surveyId
:
"
surveyId
"
,
guestId
:
""
,
guestId
:
""
,
answers
:
{}
,
answers
:
[]
,
});
});
useEffect
(()
=>
{
ansSurvey
();
},
[
surveyId
]);
const
addFiles
=
(
oneFile
:
{
questionId
:
string
;
file
:
File
})
=>
{
const
addFiles
=
(
oneFile
:
{
questionId
:
string
;
file
:
File
})
=>
{
if
(
!
files
.
find
((
a
)
=>
a
.
questionId
===
oneFile
.
questionId
))
{
if
(
!
files
.
find
((
a
)
=>
a
.
questionId
===
oneFile
.
questionId
))
{
setFiles
([...
files
,
oneFile
]);
setFiles
([...
files
,
oneFile
]);
}
}
};
};
async
function
ansSurvey
()
{
async
function
ansSurvey
()
{
try
{
try
{
if
(
surveyId
)
{
if
(
surveyId
)
{
const
answersurvey
:
any
=
await
surveyApi
.
ansSurvey
(
surveyId
);
const
answersurvey
:
any
=
await
surveyApi
.
ansSurvey
(
surveyId
);
console
.
log
(
answersurvey
);
console
.
log
(
answersurvey
);
const
questionIds
=
answersurvey
.
questions
.
map
((
el
:
any
)
=>
{
const
questionIds
=
answersurvey
.
questions
.
map
((
el
:
any
)
=>
{
return
{
questionId
:
el
.
_id
,
answer
:
""
};
return
{
questionId
:
el
.
_id
,
type
:
el
.
type
,
answer
:
""
};
});
});
console
.
log
(
questionIds
);
console
.
log
(
questionIds
);
if
(
answersurvey
)
{
if
(
answersurvey
)
{
...
@@ -49,6 +46,10 @@ export const SurveyForm = () => {
...
@@ -49,6 +46,10 @@ export const SurveyForm = () => {
// surveyId: answersurvey._id,
// surveyId: answersurvey._id,
// answers: questionIds,
// answers: questionIds,
// });
// });
answer
.
current
.
surveyId
=
answersurvey
.
_id
;
answer
.
current
.
guestId
=
answersurvey
.
guestId
;
answer
.
current
.
answers
=
questionIds
;
setSurvey
(
answersurvey
);
setSurvey
(
answersurvey
);
setSuccess
(
true
);
setSuccess
(
true
);
setError
(
""
);
setError
(
""
);
...
@@ -63,6 +64,10 @@ export const SurveyForm = () => {
...
@@ -63,6 +64,10 @@ export const SurveyForm = () => {
}
}
}
}
useEffect
(()
=>
{
ansSurvey
();
},
[
surveyId
]);
async
function
handleSubmit
(
event
:
FormEvent
)
{
async
function
handleSubmit
(
event
:
FormEvent
)
{
event
.
preventDefault
();
event
.
preventDefault
();
try
{
try
{
...
@@ -104,7 +109,9 @@ export const SurveyForm = () => {
...
@@ -104,7 +109,9 @@ export const SurveyForm = () => {
return
(
return
(
<
AQuestion
<
AQuestion
question
=
{
question
}
question
=
{
question
}
answers
=
{
answer
.
current
.
answers
}
answer
=
{
answer
.
current
.
answers
.
find
(
(
ans
)
=>
ans
.
questionId
===
question
.
_id
)
}
addFiles
=
{
addFiles
}
addFiles
=
{
addFiles
}
handleAnswer
=
{
handleAnswer
}
handleAnswer
=
{
handleAnswer
}
></
AQuestion
>
></
AQuestion
>
...
...
frontend/src/types/index.ts
View file @
1865b708
...
@@ -83,11 +83,13 @@ export interface RatingType extends BasicQuestionType {
...
@@ -83,11 +83,13 @@ export interface RatingType extends BasicQuestionType {
}
}
export
interface
AnswersType
{
export
interface
AnswersType
{
[
questionId
:
string
]:
any
;
questionId
:
string
;
type
:
string
;
answer
:
any
;
}
}
export
interface
AnswerType
{
export
interface
AnswerType
{
surveyId
:
string
;
surveyId
:
string
;
guestId
:
string
;
guestId
:
string
;
answers
:
AnswersType
;
answers
:
AnswersType
[]
;
}
}
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