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/MainRouter.tsx
0 → 100644
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
{
BrowserRouter
,
Route
,
Routes
}
from
"
react-router-dom
"
;
import
{
Login
,
SignUp
}
from
"
./auth
"
;
import
{
NotFound
}
from
"
./commons
"
;
import
{
Profile
,
CreateSurvey
,
Preview
,
EditSurvey
,
AnswerSurvey
,
}
from
"
./surveys
"
;
import
{
AnswerLayout
,
BaseLayout
,
ModifyLayout
}
from
"
./layouts
"
;
import
{
Home
}
from
"
./home
"
;
import
{
RequireAuth
}
from
"
./auth/RequireAuth
"
;
export
const
MainRouter
=
()
=>
{
return
(
<
BrowserRouter
>
<
Routes
>
<
Route
element
=
{
<
BaseLayout
/>
}
>
<
Route
path
=
"/"
element
=
{
<
Home
/>
}
></
Route
>
<
Route
path
=
"/login"
element
=
{
<
Login
/>
}
/>
<
Route
path
=
"/signup"
element
=
{
<
SignUp
/>
}
/>
<
Route
element
=
{
<
AnswerLayout
/>
}
>
<
Route
path
=
"/answers/:surveyId"
element
=
{
<
AnswerSurvey
/>
}
/>
</
Route
>
<
Route
path
=
"/surveys"
element
=
{
<
RequireAuth
>
<
ModifyLayout
/>
</
RequireAuth
>
}
>
<
Route
path
=
"create"
element
=
{
<
CreateSurvey
/>
}
/>
<
Route
path
=
"profile"
element
=
{
<
Profile
/>
}
/>
<
Route
path
=
":surveyId"
element
=
{
<
Preview
/>
}
/>
<
Route
path
=
":surveyId/edit"
element
=
{
<
EditSurvey
/>
}
/>
</
Route
>
<
Route
path
=
"*"
element
=
{
<
NotFound
/>
}
/>
</
Route
>
</
Routes
>
</
BrowserRouter
>
);
};
frontend/src/answers/ACheckboxForm.tsx
View file @
e7ae6d3f
import
React
,
{
useState
}
from
"
react
"
;
import
{
Checkbox
Type
,
AnswerProps
}
from
"
../types
"
;
import
{
I
Checkbox
,
AnswerProps
}
from
"
../types
"
;
interface
Props
extends
AnswerProps
{
element
:
Checkbox
Type
;
element
:
I
Checkbox
;
}
export
const
ACheckboxForm
=
({
element
,
answerQuestion
}:
Props
)
=>
{
...
...
frontend/src/answers/ADropdownForm.tsx
View file @
e7ae6d3f
import
React
,
{
useState
}
from
"
react
"
;
import
{
Dropdown
Type
,
AnswerProps
}
from
"
../types
"
;
import
{
I
Dropdown
,
AnswerProps
}
from
"
../types
"
;
interface
Props
extends
AnswerProps
{
element
:
Dropdown
Type
;
element
:
I
Dropdown
;
}
export
const
ADropdownForm
=
({
element
,
answerQuestion
}:
Props
)
=>
{
...
...
frontend/src/answers/AQuestion.tsx
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
{
Basic
Question
Type
,
AnswerQuestionType
}
from
"
../types
"
;
import
{
I
Question
Data
,
AnswerQuestionType
}
from
"
../types
"
;
import
{
ACheckboxForm
}
from
"
./ACheckboxForm
"
;
import
{
ADateForm
}
from
"
./ADateForm
"
;
import
{
ADropdownForm
}
from
"
./ADropdownForm
"
;
...
...
@@ -9,12 +9,12 @@ import { ARadioForm } from "./ARadioForm";
import
{
ARatingForm
}
from
"
./ARatingForm
"
;
type
Props
=
{
question
:
Basic
Question
Type
;
question
:
I
Question
Data
;
answerQuestion
:
AnswerQuestionType
;
addFiles
:
(
oneFile
:
{
questionId
:
string
;
file
:
File
})
=>
void
;
};
export
const
AQuestion
=
({
question
,
answerQuestion
,
addFiles
}:
Props
)
=>
{
function
getContent
(
question
:
Basic
Question
Type
)
{
function
getContent
(
question
:
I
Question
Data
)
{
switch
(
question
.
type
)
{
case
"
essay
"
:
return
(
...
...
frontend/src/answers/ARadioForm.tsx
View file @
e7ae6d3f
import
React
,
{
useState
}
from
"
react
"
;
import
{
Radio
Type
,
AnswerProps
}
from
"
../types
"
;
import
{
I
Radio
,
AnswerProps
}
from
"
../types
"
;
interface
Props
extends
AnswerProps
{
element
:
Radio
Type
;
element
:
I
Radio
;
}
export
const
ARadioForm
=
({
element
,
answerQuestion
}:
Props
)
=>
{
...
...
frontend/src/answers/ARatingForm.tsx
View file @
e7ae6d3f
import
React
,
{
useState
}
from
"
react
"
;
import
{
Rating
Type
,
AnswerProps
}
from
"
../types
"
;
import
{
I
Rating
,
AnswerProps
}
from
"
../types
"
;
interface
Props
extends
AnswerProps
{
element
:
Rating
Type
;
element
:
I
Rating
;
}
export
const
ARatingForm
=
({
element
,
answerQuestion
}:
Props
)
=>
{
...
...
frontend/src/answers/AnswerSurveyForm.tsx
View file @
e7ae6d3f
...
...
@@ -2,7 +2,7 @@ import React, { FormEvent, useEffect, useRef, useState } from "react";
import
{
useNavigate
,
useParams
}
from
"
react-router-dom
"
;
import
{
surveyApi
,
answerApi
}
from
"
../apis
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
import
{
AnswerSurveyType
,
AnswerType
,
Survey
Type
}
from
"
../types
"
;
import
{
AnswerSurveyType
,
AnswerType
,
I
Survey
}
from
"
../types
"
;
import
{
AQuestion
}
from
"
./AQuestion
"
;
export
const
AnswerSurveyForm
=
()
=>
{
...
...
@@ -12,7 +12,7 @@ export const AnswerSurveyForm = () => {
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
navigate
=
useNavigate
();
const
[
survey
,
setSurvey
]
=
useState
<
Survey
Type
>
({
const
[
survey
,
setSurvey
]
=
useState
<
I
Survey
>
({
_id
:
surveyId
||
""
,
user
:
{},
title
:
""
,
...
...
@@ -48,7 +48,7 @@ export const AnswerSurveyForm = () => {
async
function
ansSurvey
()
{
try
{
if
(
surveyId
)
{
const
getSurvey
:
any
=
await
surveyApi
.
ans
Survey
(
surveyId
);
const
getSurvey
:
any
=
await
surveyApi
.
get
Survey
ById
(
surveyId
);
console
.
log
(
"
survey가져옴ㅎㅎ
"
,
getSurvey
);
if
(
getSurvey
)
{
answerSurvey
.
current
.
_id
=
getSurvey
.
_id
;
...
...
frontend/src/apis/question.api.ts
View file @
e7ae6d3f
import
axios
from
"
axios
"
;
import
{
Basic
Question
Type
}
from
"
../types
"
;
import
{
I
Question
Data
}
from
"
../types
"
;
import
baseUrl
from
"
./baseUrl
"
;
export
const
createQuestion
=
async
(
surveyId
:
string
)
=>
{
...
...
@@ -16,7 +16,7 @@ export const createQuestion = async (surveyId: string) => {
return
data
;
};
export
const
updateQuestion
=
async
(
question
:
Basic
Question
Type
)
=>
{
export
const
updateQuestion
=
async
(
question
:
I
Question
Data
)
=>
{
const
{
data
}
=
await
axios
.
put
(
`
${
baseUrl
}
/questions/update/
${
question
.
_id
}
`
,
question
...
...
frontend/src/apis/survey.api.ts
View file @
e7ae6d3f
import
axios
from
"
axios
"
;
import
{
Survey
Type
}
from
"
../types
"
;
import
{
I
Survey
}
from
"
../types
"
;
import
baseUrl
from
"
./baseUrl
"
;
export
const
createSurvey
=
async
(
survey
:
Survey
Type
)
=>
{
export
const
createSurvey
=
async
(
survey
:
I
Survey
)
=>
{
const
{
data
}
=
await
axios
.
post
(
`
${
baseUrl
}
/surveys`
,
survey
);
return
data
;
};
...
...
@@ -12,7 +12,7 @@ export const getSurvey = async (surveyId: string) => {
return
data
;
};
export
const
ans
Survey
=
async
(
surveyId
:
string
)
=>
{
export
const
get
Survey
ById
=
async
(
surveyId
:
string
)
=>
{
const
{
data
}
=
await
axios
.
get
(
`
${
baseUrl
}
/surveys/
${
surveyId
}
`
);
return
data
;
};
...
...
@@ -22,14 +22,12 @@ export const getSurveys = async () => {
return
data
;
};
export
const
editSurvey
=
async
(
survey
:
SurveyType
)
=>
{
const
{
data
}
=
await
axios
.
put
(
`
${
baseUrl
}
/surveys/
${
survey
.
_id
}
/edit`
,
survey
);
export
const
updateSurvey
=
async
(
survey
:
ISurvey
)
=>
{
const
{
data
}
=
await
axios
.
put
(
`
${
baseUrl
}
/surveys/
${
survey
.
_id
}
`
,
survey
);
return
data
;
};
export
const
resultSurvey
=
async
(
survey
:
SurveyType
)
=>
{
export
const
resultSurvey
=
async
(
survey
:
ISurvey
)
=>
{
const
{
data
}
=
await
axios
.
put
(
`
${
baseUrl
}
/surveys/
${
survey
.
_id
}
/result`
,
survey
...
...
@@ -38,6 +36,6 @@ export const resultSurvey = async (survey: SurveyType) => {
};
export
const
deleteSurvey
=
async
(
surveyId
:
string
)
=>
{
const
{
data
}
=
await
axios
.
delete
(
`
${
baseUrl
}
/surveys/
${
surveyId
}
/delete
`
);
const
{
data
}
=
await
axios
.
delete
(
`
${
baseUrl
}
/surveys/
${
surveyId
}
`
);
return
data
;
};
frontend/src/auth/RequireAuth.tsx
View file @
e7ae6d3f
...
...
@@ -7,6 +7,7 @@ export const RequireAuth: FC<{ children: JSX.Element }> = ({ children }) => {
const
location
=
useLocation
();
if
(
!
user
.
isLoggedIn
)
{
alert
(
"
로그인이 필요합니다.
"
);
return
(
<
Navigate
to
=
{
"
/login
"
}
state
=
{
{
from
:
location
.
pathname
}
}
replace
/>
);
...
...
frontend/src/commons/NotFound.tsx
0 → 100644
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
{
Link
}
from
"
react-router-dom
"
;
export
const
NotFound
=
()
=>
{
return
(
<
div
className
=
"flex flex-col mt-10 justify-center text-center text-5xl"
>
<
h1
className
=
"text-4xl"
>
페이지를 찾을 수 없습니다.
</
h1
>
<
Link
to
=
{
"
/
"
}
className
=
"mt-4"
>
홈으로
</
Link
>
</
div
>
);
};
frontend/src/commons/index.tsx
View file @
e7ae6d3f
export
{
Header
}
from
"
./Header
"
;
export
{
Footer
}
from
"
./Footer
"
;
export
{
NotFound
}
from
"
./NotFound
"
;
export
{
QUESTION_TYPES
}
from
"
./constants
"
;
frontend/src/index.tsx
View file @
e7ae6d3f
...
...
@@ -2,12 +2,14 @@ import React from "react";
import
"
tailwindcss/tailwind.css
"
;
import
{
createRoot
}
from
"
react-dom/client
"
;
import
{
SurveyRouter
}
from
"
./SurveyRouter
"
;
import
{
MainRouter
}
from
"
./MainRouter
"
;
const
container
=
document
.
getElementById
(
"
root
"
);
const
root
=
createRoot
(
container
!
);
root
.
render
(
<
React
.
StrictMode
>
<
SurveyRouter
/>
{
/* <SurveyRouter /> */
}
<
MainRouter
/>
</
React
.
StrictMode
>
);
frontend/src/layouts/AnswerLayout.tsx
0 → 100644
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
{
Outlet
}
from
"
react-router-dom
"
;
export
const
AnswerLayout
=
()
=>
{
return
(
<>
<
Outlet
/>
</>
);
};
frontend/src/layouts/BaseLayout.tsx
0 → 100644
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
{
Outlet
}
from
"
react-router-dom
"
;
import
{
AuthProvider
}
from
"
../auth
"
;
import
{
Header
}
from
"
../commons
"
;
export
const
BaseLayout
=
()
=>
{
return
(
<
AuthProvider
>
<
Header
/>
<
Outlet
/>
</
AuthProvider
>
);
};
frontend/src/layouts/ModifyLayout.tsx
0 → 100644
View file @
e7ae6d3f
import
React
from
"
react
"
;
import
{
Outlet
}
from
"
react-router-dom
"
;
export
const
ModifyLayout
=
()
=>
{
return
(
<>
<
Outlet
/>
</>
);
};
frontend/src/layouts/index.tsx
0 → 100644
View file @
e7ae6d3f
export
{
AnswerLayout
}
from
"
./AnswerLayout
"
;
export
{
BaseLayout
}
from
"
./BaseLayout
"
;
export
{
ModifyLayout
}
from
"
./ModifyLayout
"
;
frontend/src/profile/MySurveyCard.tsx
View file @
e7ae6d3f
import
React
,
{
useState
}
from
"
react
"
;
import
{
useNavigate
}
from
"
react-router-dom
"
;
import
{
surveyApi
}
from
"
../apis
"
;
import
{
Survey
Type
}
from
"
../types
"
;
import
{
I
Survey
}
from
"
../types
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
import
{
DuplicateIcon
}
from
"
../icons
"
;
type
Props
=
{
data
:
Survey
Type
;
data
:
I
Survey
;
};
export
const
MySurveyCard
=
({
data
}:
Props
)
=>
{
...
...
frontend/src/profile/Profile.tsx
View file @
e7ae6d3f
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
{
useNavigate
}
from
"
react-router-dom
"
;
import
{
baseImageUrl
,
surveyApi
}
from
"
../apis
"
;
import
{
Survey
Type
}
from
"
../types
"
;
import
{
I
Survey
}
from
"
../types
"
;
import
{
MySurveyCard
}
from
"
./MySurveyCard
"
;
export
const
Profile
=
()
=>
{
const
navigate
=
useNavigate
();
const
[
survey
,
setSurvey
]
=
useState
<
Survey
Type
>
({
const
[
survey
,
setSurvey
]
=
useState
<
I
Survey
>
({
_id
:
""
,
user
:
{},
title
:
""
,
comment
:
""
,
questions
:
[],
});
const
[
cardDatas
,
setCardDatas
]
=
useState
<
Survey
Type
[]
>
([]);
const
[
cardDatas
,
setCardDatas
]
=
useState
<
I
Survey
[]
>
([]);
useEffect
(()
=>
{
getSurveys
();
},
[]);
async
function
createSurvey
()
{
const
newSurvey
:
Survey
Type
=
await
surveyApi
.
createSurvey
(
survey
);
const
newSurvey
:
I
Survey
=
await
surveyApi
.
createSurvey
(
survey
);
navigate
(
`/surveys/
${
newSurvey
.
_id
}
/create`
,
{
replace
:
true
,
});
}
async
function
getSurveys
()
{
const
surveys
:
Survey
Type
[]
=
await
surveyApi
.
getSurveys
();
const
surveys
:
I
Survey
[]
=
await
surveyApi
.
getSurveys
();
// console.log(surveys);
setCardDatas
(
surveys
);
}
...
...
frontend/src/questions/CheckboxForm.tsx
View file @
e7ae6d3f
import
React
,
{
useState
}
from
"
react
"
;
import
{
Checkbox
Type
}
from
"
../types
"
;
import
{
I
Checkbox
}
from
"
../types
"
;
type
Props
=
{
element
:
Checkbox
Type
;
element
:
I
Checkbox
;
handleQuestion
:
(
id
:
string
)
=>
void
;
isEditing
:
boolean
;
};
...
...
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