-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
139 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 46 additions & 2 deletions
48
src/app/(authed)/admin/answer/[answerId]/_components/AnswerDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,49 @@ | ||
const AnswerDetails = () => { | ||
return <></>; | ||
import Grid from '@mui/material/Grid'; | ||
import Typography from '@mui/material/Typography'; | ||
import { formatString } from '@/generic/DateFormatter'; | ||
import type { | ||
GetAnswerResponse, | ||
GetQuestionsResponse, | ||
} from '@/app/api/_schemas/ResponseSchemas'; | ||
|
||
const AnswerDetails = (props: { | ||
answers: GetAnswerResponse; | ||
questions: GetQuestionsResponse; | ||
}) => { | ||
console.log(props.answers, props.questions); | ||
|
||
return ( | ||
<Grid container spacing={2}> | ||
<Grid item xs={12}> | ||
{props.answers.title} | ||
</Grid> | ||
{/* TODO: 回答者をユーザー名埋め込みに変える */} | ||
<Grid item xs={6}> | ||
<Typography sx={{ fontWeight: 'bold' }}>回答者</Typography> | ||
{props.answers.uuid} | ||
</Grid> | ||
<Grid item xs={6}> | ||
<Typography sx={{ fontWeight: 'bold' }}>回答日時</Typography> | ||
{formatString(props.answers.timestamp)} | ||
</Grid> | ||
{props.answers.answers.map((answer, index) => ( | ||
<Grid item xs={12} key={index}> | ||
<Grid container spacing={2}> | ||
<Grid item xs={12} sx={{ fontWeight: 'bold' }}> | ||
{ | ||
props.questions.find( | ||
(question) => question.id == answer.question_id | ||
)?.title | ||
} | ||
</Grid> | ||
<Grid item xs={12}> | ||
{answer.answer} | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
))} | ||
</Grid> | ||
); | ||
}; | ||
|
||
export default AnswerDetails; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use server'; | ||
|
||
import { NextResponse } from 'next/server'; | ||
import { BACKEND_SERVER_URL } from '@/env'; | ||
import { getCachedToken } from '@/user-token/mcToken'; | ||
import { redirectByResponse } from '../../util/responseOrErrorResponse'; | ||
import type { NextRequest } from 'next/server'; | ||
|
||
export async function GET( | ||
req: NextRequest, | ||
{ params }: { params: { answerId: string } } | ||
) { | ||
const token = await getCachedToken(); | ||
if (!token) { | ||
return NextResponse.redirect('/'); | ||
} | ||
|
||
const response = await fetch( | ||
`${BACKEND_SERVER_URL}/forms/answers/${params.answerId}`, | ||
{ | ||
method: 'GET', | ||
headers: { | ||
Accept: 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
cache: 'no-cache', | ||
} | ||
); | ||
|
||
redirectByResponse(req, response); | ||
|
||
return NextResponse.json(await response.json()); | ||
} |