-
Notifications
You must be signed in to change notification settings - Fork 2
LC-2857 ADMIN 마그넷 내부화 신청폼 관리 #2142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hyonun321
wants to merge
1
commit into
LC-2838-Sprint-17
Choose a base branch
from
LC-2857-ADMIN-마그넷-내부화-신청폼-관리
base: LC-2838-Sprint-17
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "LC-2857-ADMIN-\uB9C8\uADF8\uB137-\uB0B4\uBD80\uD654-\uC2E0\uCCAD\uD3FC-\uAD00\uB9AC"
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,4 +1,11 @@ | ||
| // TODO: 마그넷 신청 폼 관리 페이지 구현 예정 | ||
| export default function MagnetFormPage() { | ||
| return <div>신청 폼 관리 (준비 중)</div>; | ||
| } | ||
| import { fetchMagnetForm } from '@/domain/admin/blog/magnet/mock'; | ||
| import MagnetFormPage from '@/domain/admin/blog/magnet/MagnetFormPage'; | ||
|
|
||
| const Page = async ({ params }: { params: Promise<{ id: string }> }) => { | ||
| const { id } = await params; | ||
| const initialData = await fetchMagnetForm(Number(id)); | ||
|
|
||
| return <MagnetFormPage magnetId={id} initialData={initialData} />; | ||
| }; | ||
|
|
||
| export default Page; | ||
This file contains hidden or 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,70 @@ | ||
| 'use client'; | ||
|
|
||
| import CloneFormDropdown from '@/domain/admin/blog/magnet/form/CloneFormDropdown'; | ||
| import FormBuilderSection from '@/domain/admin/blog/magnet/form/FormBuilderSection'; | ||
| import { useMagnetFormBuilder } from '@/domain/admin/blog/magnet/hooks/useMagnetFormBuilder'; | ||
| import { MagnetFormData } from '@/domain/admin/blog/magnet/types'; | ||
| import Heading from '@/domain/admin/ui/heading/Heading'; | ||
| import { Button } from '@mui/material'; | ||
|
|
||
| interface MagnetFormPageProps { | ||
| magnetId: string; | ||
| initialData: MagnetFormData; | ||
| } | ||
|
|
||
| const MagnetFormPage = ({ | ||
| magnetId, | ||
| initialData, | ||
| }: MagnetFormPageProps) => { | ||
| const { | ||
| questions, | ||
| addQuestion, | ||
| removeQuestion, | ||
| updateQuestion, | ||
| cloneFromMagnet, | ||
| saveForm, | ||
| navigateToList, | ||
| } = useMagnetFormBuilder({ magnetId, initialData }); | ||
|
|
||
| return ( | ||
| <div className="mx-6 mb-40 mt-6"> | ||
| <header className="mb-6 flex items-center justify-between"> | ||
| <Heading>신청폼 관리</Heading> | ||
| <CloneFormDropdown | ||
| currentMagnetId={Number(magnetId)} | ||
| hasExistingQuestions={questions.length > 0} | ||
| onClone={cloneFromMagnet} | ||
| /> | ||
| </header> | ||
|
|
||
| <main className="max-w-screen-xl"> | ||
| <FormBuilderSection | ||
| questions={questions} | ||
| onUpdateQuestion={updateQuestion} | ||
| onRemoveQuestion={removeQuestion} | ||
| onAddQuestion={addQuestion} | ||
| /> | ||
|
|
||
| <div className="mt-8 flex items-center justify-end gap-4"> | ||
| <Button | ||
| variant="outlined" | ||
| type="button" | ||
| onClick={navigateToList} | ||
| > | ||
| 취소 | ||
| </Button> | ||
| <Button | ||
| variant="contained" | ||
| color="primary" | ||
| type="button" | ||
| onClick={saveForm} | ||
| > | ||
| 저장하기 | ||
| </Button> | ||
| </div> | ||
| </main> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default MagnetFormPage; |
This file contains hidden or 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,82 @@ | ||
| import { | ||
| fetchMagnetForm, | ||
| fetchMagnetsWithForm, | ||
| } from '@/domain/admin/blog/magnet/mock'; | ||
| import { FormQuestion } from '@/domain/admin/blog/magnet/types'; | ||
| import { Button, Menu, MenuItem } from '@mui/material'; | ||
| import { Copy } from 'lucide-react'; | ||
| import { MouseEvent, useMemo, useState } from 'react'; | ||
|
|
||
| interface CloneFormDropdownProps { | ||
| currentMagnetId: number; | ||
| hasExistingQuestions: boolean; | ||
| onClone: (questions: FormQuestion[]) => void; | ||
| } | ||
|
|
||
| const CloneFormDropdown = ({ | ||
| currentMagnetId, | ||
| hasExistingQuestions, | ||
| onClone, | ||
| }: CloneFormDropdownProps) => { | ||
| const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null); | ||
|
|
||
| const magnetsWithForm = useMemo(() => { | ||
| return fetchMagnetsWithForm().filter( | ||
| (m) => m.id !== currentMagnetId, | ||
| ); | ||
| }, [currentMagnetId]); | ||
|
|
||
| const handleOpen = (e: MouseEvent<HTMLButtonElement>) => { | ||
| setAnchorEl(e.currentTarget); | ||
| }; | ||
|
|
||
| const handleClose = () => { | ||
| setAnchorEl(null); | ||
| }; | ||
|
|
||
| const handleClone = async (magnetId: number) => { | ||
| handleClose(); | ||
|
|
||
| if (hasExistingQuestions) { | ||
| const confirmed = window.confirm( | ||
| '기존 질문이 모두 대체됩니다. 계속하시겠습니까?', | ||
| ); | ||
| if (!confirmed) return; | ||
| } | ||
|
|
||
| const data = await fetchMagnetForm(magnetId); | ||
| onClone(data.questions); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <Button | ||
| variant="outlined" | ||
| startIcon={<Copy size={16} />} | ||
| onClick={handleOpen} | ||
| > | ||
| 신청폼 복제 | ||
| </Button> | ||
| <Menu | ||
| anchorEl={anchorEl} | ||
| open={Boolean(anchorEl)} | ||
| onClose={handleClose} | ||
| > | ||
| {magnetsWithForm.length === 0 ? ( | ||
| <MenuItem disabled>복제할 수 있는 폼이 없습니다</MenuItem> | ||
| ) : ( | ||
| magnetsWithForm.map((m) => ( | ||
| <MenuItem | ||
| key={m.id} | ||
| onClick={() => handleClone(m.id)} | ||
| > | ||
| [{m.id}] {m.title} ({m.questionCount}개 질문) | ||
| </MenuItem> | ||
| )) | ||
| )} | ||
| </Menu> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default CloneFormDropdown; |
This file contains hidden or 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,51 @@ | ||
| import QuestionCard from '@/domain/admin/blog/magnet/form/QuestionCard'; | ||
| import { FormQuestion } from '@/domain/admin/blog/magnet/types'; | ||
| import { Button } from '@mui/material'; | ||
| import { Plus } from 'lucide-react'; | ||
|
|
||
| interface FormBuilderSectionProps { | ||
| questions: FormQuestion[]; | ||
| onUpdateQuestion: ( | ||
| questionId: string, | ||
| patch: Partial<FormQuestion>, | ||
| ) => void; | ||
| onRemoveQuestion: (questionId: string) => void; | ||
| onAddQuestion: () => void; | ||
| } | ||
|
|
||
| const FormBuilderSection = ({ | ||
| questions, | ||
| onUpdateQuestion, | ||
| onRemoveQuestion, | ||
| onAddQuestion, | ||
| }: FormBuilderSectionProps) => { | ||
| return ( | ||
| <div> | ||
| <div className="flex flex-col gap-4"> | ||
| {questions.map((question, index) => ( | ||
| <QuestionCard | ||
| key={question.questionId} | ||
| questionNumber={index + 1} | ||
| question={question} | ||
| onUpdate={(patch) => | ||
| onUpdateQuestion(question.questionId, patch) | ||
| } | ||
| onRemove={() => onRemoveQuestion(question.questionId)} | ||
| /> | ||
| ))} | ||
| </div> | ||
|
|
||
| <div className="mt-4"> | ||
| <Button | ||
| variant="contained" | ||
| startIcon={<Plus size={16} />} | ||
| onClick={onAddQuestion} | ||
| > | ||
| 질문 추가 | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default FormBuilderSection; |
This file contains hidden or 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,165 @@ | ||
| import QuestionItemList from '@/domain/admin/blog/magnet/form/QuestionItemList'; | ||
| import { | ||
| FormQuestion, | ||
| FormQuestionItem, | ||
| FormQuestionType, | ||
| FormResponseRequired, | ||
| FormSelectionMethod, | ||
| } from '@/domain/admin/blog/magnet/types'; | ||
| import { | ||
| FormControlLabel, | ||
| IconButton, | ||
| Radio, | ||
| RadioGroup, | ||
| TextField, | ||
| } from '@mui/material'; | ||
| import { Trash } from 'lucide-react'; | ||
|
|
||
| interface QuestionCardProps { | ||
| questionNumber: number; | ||
| question: FormQuestion; | ||
| onUpdate: (patch: Partial<FormQuestion>) => void; | ||
| onRemove: () => void; | ||
| } | ||
|
|
||
| const QuestionCard = ({ | ||
| questionNumber, | ||
| question, | ||
| onUpdate, | ||
| onRemove, | ||
| }: QuestionCardProps) => { | ||
| const handleQuestionTypeChange = (value: string) => { | ||
| onUpdate({ questionType: value as FormQuestionType }); | ||
| }; | ||
|
|
||
| const handleRequiredChange = (value: string) => { | ||
| onUpdate({ isRequired: value as FormResponseRequired }); | ||
| }; | ||
|
|
||
| const handleSelectionMethodChange = (value: string) => { | ||
| onUpdate({ selectionMethod: value as FormSelectionMethod }); | ||
| }; | ||
|
|
||
| const handleItemsChange = (items: FormQuestionItem[]) => { | ||
| onUpdate({ items }); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="rounded-lg border border-neutral-200 bg-white p-6"> | ||
| <div className="mb-5 flex items-center justify-between"> | ||
| <span className="text-lg font-semibold"> | ||
| 질문 {questionNumber} | ||
| </span> | ||
| <IconButton size="small" onClick={onRemove}> | ||
| <Trash size={18} /> | ||
| </IconButton> | ||
| </div> | ||
|
|
||
| <div className="flex flex-col gap-5"> | ||
| {/* 질문 유형 */} | ||
| <div> | ||
| <label className="mb-1 block text-sm font-medium"> | ||
| 질문 유형 | ||
| </label> | ||
| <RadioGroup | ||
| row | ||
| value={question.questionType} | ||
| onChange={(e) => handleQuestionTypeChange(e.target.value)} | ||
| > | ||
| <FormControlLabel | ||
| value="SUBJECTIVE" | ||
| control={<Radio size="small" />} | ||
| label="주관식" | ||
| /> | ||
| <FormControlLabel | ||
| value="OBJECTIVE" | ||
| control={<Radio size="small" />} | ||
| label="객관식" | ||
| /> | ||
| </RadioGroup> | ||
| </div> | ||
|
|
||
| {/* 응답 설정 */} | ||
| <div> | ||
| <label className="mb-1 block text-sm font-medium"> | ||
| 응답 설정 | ||
| </label> | ||
| <RadioGroup | ||
| row | ||
| value={question.isRequired} | ||
| onChange={(e) => handleRequiredChange(e.target.value)} | ||
| > | ||
| <FormControlLabel | ||
| value="REQUIRED" | ||
| control={<Radio size="small" />} | ||
| label="필수" | ||
| /> | ||
| <FormControlLabel | ||
| value="OPTIONAL" | ||
| control={<Radio size="small" />} | ||
| label="선택" | ||
| /> | ||
| </RadioGroup> | ||
| </div> | ||
|
|
||
| {/* 질문 */} | ||
| <TextField | ||
| label="질문 *" | ||
| placeholder="질문을 입력하세요" | ||
| fullWidth | ||
| size="small" | ||
| value={question.question} | ||
| onChange={(e) => onUpdate({ question: e.target.value })} | ||
| /> | ||
|
|
||
| {/* 설명 */} | ||
| <TextField | ||
| label="설명" | ||
| placeholder="질문에 대한 설명을 입력하세요 (선택사항)" | ||
| fullWidth | ||
| size="small" | ||
| multiline | ||
| minRows={2} | ||
| value={question.description} | ||
| onChange={(e) => onUpdate({ description: e.target.value })} | ||
| /> | ||
|
|
||
| {/* 객관식 전용 영역 */} | ||
| {question.questionType === 'OBJECTIVE' && ( | ||
| <> | ||
| <div> | ||
| <label className="mb-1 block text-sm font-medium"> | ||
| 선택 방식 | ||
| </label> | ||
| <RadioGroup | ||
| row | ||
| value={question.selectionMethod} | ||
| onChange={(e) => | ||
| handleSelectionMethodChange(e.target.value) | ||
| } | ||
| > | ||
| <FormControlLabel | ||
| value="SINGLE" | ||
| control={<Radio size="small" />} | ||
| label="단일선택" | ||
| /> | ||
| <FormControlLabel | ||
| value="MULTIPLE" | ||
| control={<Radio size="small" />} | ||
| label="다중선택" | ||
| /> | ||
| </RadioGroup> | ||
| </div> | ||
|
|
||
| <QuestionItemList | ||
| items={question.items} | ||
| onUpdateItems={handleItemsChange} | ||
| /> | ||
| </> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default QuestionCard; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next.js 페이지 컴포넌트의
paramsprop 타입과 사용법이 잘못되었습니다.params는 Promise가 아니라 객체이며,await없이 직접 접근해야 합니다. 현재 코드는 런타임 오류를 발생시킬 수 있습니다.