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
dc16c4a2
Commit
dc16c4a2
authored
Aug 19, 2022
by
Yoon, Daeki
😅
Browse files
컨텍스트 루트로 로직 변경
parent
44530f9a
Changes
2
Hide whitespace changes
Inline
Side-by-side
frontend/src/surveys/CreateSurvey.tsx
View file @
dc16c4a2
import
React
from
"
react
"
;
import
{
surveyApi
}
from
"
../apis
"
;
import
{
useSurveys
}
from
"
../layouts
"
;
import
{
ISurvey
}
from
"
../types
"
;
import
{
ModifySurvey
}
from
"
./ModifySurvey
"
;
export
const
CreateSurvey
=
()
=>
{
const
{
error
,
loading
,
create
}
=
useSurveys
();
const
surveyData
=
{
_id
:
""
,
user
:
""
,
...
...
@@ -12,10 +15,10 @@ export const CreateSurvey = () => {
questions
:
[],
};
const
create
=
async
(
surveyData
:
ISurvey
)
=>
{
const
result
=
await
surveyApi
.
createSurvey
(
surveyData
);
return
result
;
};
//
const create = async (surveyData: ISurvey) => {
//
const result = await surveyApi.createSurvey(surveyData);
//
return result;
//
};
return
<
ModifySurvey
surveyData
=
{
surveyData
}
callApi
=
{
create
}
/>;
};
frontend/src/surveys/EditSurvey.tsx
View file @
dc16c4a2
import
React
from
"
react
"
;
import
{
useLocation
}
from
"
react-router-dom
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
Navigate
,
useLocation
,
useParams
}
from
"
react-router-dom
"
;
import
{
surveyApi
}
from
"
../apis
"
;
import
{
ISurvey
}
from
"
../types
"
;
import
{
ModifySurvey
}
from
"
./ModifySurvey
"
;
import
{
useSurvey
}
from
"
../layouts/SurveyLayout
"
;
export
const
EditSurvey
=
()
=>
{
const
location
=
useLocation
();
const
surveyState
=
location
.
state
as
ISurvey
;
console
.
log
(
"
edit survey:
"
,
surveyState
);
const
{
survey
,
update
}
=
useSurvey
();
// const [survey, setSurvey] = useState(surveyData);
cons
t
update
=
async
(
surveyData
:
IS
urvey
)
=>
{
const
result
=
await
surveyApi
.
updateSurvey
(
surveyData
);
return
result
;
}
;
cons
ole
.
log
(
"
survey
"
,
s
urvey
)
;
//
const
location = useLocation(
);
// const surveyState = location.state as ISurvey
;
// console.log("edit survey:", surveyState)
;
return
<
ModifySurvey
surveyData
=
{
surveyState
}
callApi
=
{
update
}
/>;
// const update = async (surveyData: ISurvey) => {
// const result = await surveyApi.updateSurvey(surveyData);
// return result;
// };
if
(
!
survey
)
{
return
<
Navigate
to
=
{
"
/surveys
"
}
/>;
}
return
<
ModifySurvey
surveyData
=
{
survey
}
callApi
=
{
update
}
/>;
};
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