-
Notifications
You must be signed in to change notification settings - Fork 3
[fix] FAQ 수정, 삭제 버그 해결 #1024
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
Merged
Merged
[fix] FAQ 수정, 삭제 버그 해결 #1024
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a515df9
refactor: divisions, categories 객체 위치 함수바깥으로 이동
seongwon030 8ae4163
refactor: clubIntroTab에서 clubIntroEditTab으로 이름변경
seongwon030 5b53bdc
refactor: 아이콘 제거
seongwon030 2c7efbf
refactor: AwardEditor import 경로 수정 및 라벨 텍스트 정리
seongwon030 0a527fe
fix: FAQEditor에 ID 관리 로직 추가 및 타입 안정성 개선
seongwon030 d580fce
feat: FAQ 타입에 id 필드 추가
seongwon030 59be431
refactor: 상세페이지 수상 이모지 제거
seongwon030 b5fe060
fix: \ 제거
seongwon030 35b0104
feat: FAQ 답변 줄바꿈 처리
seongwon030 3474c49
feat: 에브리타임 링크 허용
seongwon030 7f74963
feat: 소개 수정 페이지 이벤트명 변경
seongwon030 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
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
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
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
123 changes: 123 additions & 0 deletions
123
frontend/src/pages/AdminPage/tabs/ClubIntroEditTab/components/FAQEditor/FAQEditor.tsx
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,123 @@ | ||
| import { useEffect, useRef, useState } from 'react'; | ||
| import deleteButton from '@/assets/images/icons/delete_button_icon.svg'; | ||
| import { FAQ } from '@/types/club'; | ||
| import * as Styled from './FAQEditor.styles'; | ||
|
|
||
| interface FAQEditorProps { | ||
| faqs: FAQ[]; | ||
| onChange: (faqs: FAQ[]) => void; | ||
| } | ||
|
|
||
| const FAQEditor = ({ faqs, onChange }: FAQEditorProps) => { | ||
| const [shouldFocusLast, setShouldFocusLast] = useState(false); | ||
| const questionInputRefs = useRef<Record<string, HTMLInputElement | null>>({}); | ||
|
|
||
| useEffect(() => { | ||
| const hasAnyMissingId = faqs.some((faq) => !faq.id); | ||
| if (hasAnyMissingId) { | ||
| const faqsWithIds = faqs.map((faq) => ({ | ||
| ...faq, | ||
| id: faq.id || `faq-${Date.now()}-${Math.random()}`, | ||
| })); | ||
| onChange(faqsWithIds); | ||
| } | ||
| }, [faqs, onChange]); | ||
|
|
||
| const handleAddFAQ = () => { | ||
| const newFAQ: FAQ = { | ||
| id: `faq-${Date.now()}-${Math.random()}`, | ||
| question: '', | ||
| answer: '', | ||
| }; | ||
| onChange([...faqs, newFAQ]); | ||
| setShouldFocusLast(true); | ||
| }; | ||
|
|
||
| const handleRemoveFAQ = (id: string) => { | ||
| onChange(faqs.filter((faq) => faq.id !== id)); | ||
| }; | ||
|
|
||
| const handleUpdateQuestion = (id: string, value: string) => { | ||
| const updatedFAQs = faqs.map((faq) => | ||
| faq.id === id ? { ...faq, question: value } : faq, | ||
| ); | ||
| onChange(updatedFAQs); | ||
| }; | ||
|
|
||
| const handleUpdateAnswer = (id: string, value: string) => { | ||
| const updatedFAQs = faqs.map((faq) => | ||
| faq.id === id ? { ...faq, answer: value } : faq, | ||
| ); | ||
| onChange(updatedFAQs); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| if (shouldFocusLast && faqs.length > 0) { | ||
| const lastFAQ = faqs[faqs.length - 1]; | ||
| if (lastFAQ.id) { | ||
| const inputRef = questionInputRefs.current[lastFAQ.id]; | ||
| if (inputRef) { | ||
| inputRef.focus(); | ||
| } | ||
| } | ||
| setShouldFocusLast(false); | ||
| } | ||
| }, [faqs, shouldFocusLast]); | ||
|
|
||
| return ( | ||
| <Styled.Container> | ||
| <Styled.Label>자주 묻는 질문 (FAQ)</Styled.Label> | ||
|
|
||
| <Styled.AddButton onClick={handleAddFAQ}>+ FAQ 추가</Styled.AddButton> | ||
|
|
||
| {faqs.length === 0 ? ( | ||
| <Styled.EmptyState> | ||
| FAQ를 추가하여 지원자들의 자주 묻는 질문에 답변해보세요. | ||
| </Styled.EmptyState> | ||
| ) : ( | ||
| <Styled.FAQList> | ||
| {faqs | ||
| .filter((faq): faq is FAQ & { id: string } => !!faq.id) | ||
| .map((faq, index) => ( | ||
| <Styled.FAQItem key={faq.id}> | ||
| <Styled.FAQHeader> | ||
| <Styled.FAQNumber>Q{index + 1}</Styled.FAQNumber> | ||
| <Styled.RemoveButton onClick={() => handleRemoveFAQ(faq.id)}> | ||
| <img src={deleteButton} alt='삭제' /> | ||
| </Styled.RemoveButton> | ||
| </Styled.FAQHeader> | ||
|
|
||
| <Styled.QuestionInput | ||
| ref={(element) => { | ||
| questionInputRefs.current[faq.id] = element; | ||
| }} | ||
| placeholder='질문을 입력하세요' | ||
| value={faq.question} | ||
| onChange={(event) => | ||
| handleUpdateQuestion(faq.id, event.target.value) | ||
| } | ||
| maxLength={100} | ||
| /> | ||
|
|
||
| <Styled.AnswerTextArea | ||
| placeholder='답변을 입력하세요' | ||
| value={faq.answer} | ||
| onChange={(event) => | ||
| handleUpdateAnswer(faq.id, event.target.value) | ||
| } | ||
| maxLength={300} | ||
| /> | ||
|
|
||
| <Styled.CharCount> | ||
| 질문: {faq.question.length}/100 | 답변: {faq.answer.length} | ||
| /300 | ||
| </Styled.CharCount> | ||
| </Styled.FAQItem> | ||
| ))} | ||
| </Styled.FAQList> | ||
| )} | ||
| </Styled.Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default FAQEditor; |
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.
Uh oh!
There was an error while loading. Please reload this page.