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
9ab6dda5
Commit
9ab6dda5
authored
Jul 22, 2022
by
Lee SeoYeon
Browse files
제출 시localstorage정보저장
parent
eaf39470
Changes
1
Hide whitespace changes
Inline
Side-by-side
frontend/src/commons/SurveyForm.tsx
View file @
9ab6dda5
import
React
,
{
FormEvent
,
useEffect
,
useRef
,
useState
}
from
"
react
"
;
import
{
Link
,
useNavigate
}
from
"
react-router-dom
"
;
import
{
useParams
}
from
"
react-router-dom
"
;
import
{
surveyApi
,
answerApi
}
from
"
../apis
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
...
...
@@ -11,6 +12,7 @@ export const SurveyForm = () => {
const
[
error
,
setError
]
=
useState
(
""
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
navigate
=
useNavigate
();
const
[
survey
,
setSurvey
]
=
useState
<
SurveyType
>
({
_id
:
surveyId
,
user
:
{},
...
...
@@ -25,6 +27,13 @@ export const SurveyForm = () => {
answers
:
[],
});
const
isSurvey
=
localStorage
.
getItem
(
`survey_
${
surveyId
}
`
);
if
(
isSurvey
)
{
console
.
log
(
"
object
"
,
isSurvey
);
alert
(
"
제출한 설문조사입니다
"
);
navigate
(
"
/
"
);
}
const
addFiles
=
(
oneFile
:
{
questionId
:
string
;
file
:
File
})
=>
{
if
(
!
files
.
find
((
a
)
=>
a
.
questionId
===
oneFile
.
questionId
))
{
setFiles
([...
files
,
oneFile
]);
...
...
@@ -79,6 +88,9 @@ export const SurveyForm = () => {
formData
.
append
(
"
files
"
,
f
.
file
);
});
const
newAnswer
:
AnswerType
=
await
answerApi
.
saveAnswers
(
formData
);
localStorage
.
setItem
(
`survey_
${
surveyId
}
`
,
surveyId
??
""
);
alert
(
"
제출되었습니다
"
);
navigate
(
`/`
);
// console.log(newAnswer);
setSuccess
(
true
);
setError
(
""
);
...
...
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