-
Notifications
You must be signed in to change notification settings - Fork 3
feat: 새 사건 버튼 — POST /api/rooms 연결 및 roomId 전달 #73
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
Changes from all commits
6eb7ed6
f98f8f3
d959392
5a6643e
a04b781
6ab4d7e
24aed23
f67c9e9
2b194f9
e5188f7
f2154c6
47e7138
a31fe0e
f02cec2
e92b35f
804f450
fd1b1f3
8561f05
cca1afc
2afe223
cff2117
28c7139
200262e
692170e
80b320a
c5eed1d
b6f81f0
7937e2c
12871f4
9408df5
d10f250
889d131
6aa97cf
f63d464
ed7b7df
55e3268
cd5dfc5
83440e7
0c0faa6
5d2c535
9962e7b
7485cea
3d13b90
b41e750
76101ed
770ae62
63d2c96
f9ace36
c0ca4cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,16 +16,39 @@ const CATEGORY_ITEMS: { category: CategoryGroup; label: string }[] = [ | |||||
|
|
||||||
| export default function NewCaseButton() { | ||||||
| const [isOpen, setIsOpen] = useState(false) | ||||||
| const [isCreating, setIsCreating] = useState(false) | ||||||
| const [errorMessage, setErrorMessage] = useState<string | null>(null) | ||||||
| const router = useRouter() | ||||||
|
|
||||||
| useEffect(() => { | ||||||
| document.body.style.overflow = isOpen ? 'hidden' : '' | ||||||
| return () => { document.body.style.overflow = '' } | ||||||
| }, [isOpen]) | ||||||
|
|
||||||
| const handleCategoryClick = (category: CategoryGroup) => { | ||||||
| const handleCategoryClick = async (category: CategoryGroup) => { | ||||||
| if (isCreating) return | ||||||
| setIsOpen(false) | ||||||
| router.push(`/disputes/test/statement?category=${category}`) | ||||||
| setIsCreating(true) | ||||||
| setErrorMessage(null) | ||||||
| const controller = new AbortController() | ||||||
| const timeout = setTimeout(() => controller.abort(), 5000) | ||||||
| try { | ||||||
| const res = await fetch('/api/rooms', { | ||||||
| method: 'POST', | ||||||
| headers: { 'Content-Type': 'application/json' }, | ||||||
| body: JSON.stringify({ categoryGroup: category }), | ||||||
| signal: controller.signal, | ||||||
| }) | ||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||
| const json = await res.json() | ||||||
| if (!json.success) throw new Error(json.error?.message) | ||||||
| router.push(`/disputes/${json.data.id}/statement?category=${category}`) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 성공 시 이동 경로가 PR 목표( 현재는 제안 패치- router.push(`/disputes/${json.data.id}/statement?category=${category}`)
+ router.push(`/disputes/${json.data.id}/`)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| } catch (err) { | ||||||
| setErrorMessage(err instanceof Error && err.message ? err.message : '사건 생성에 실패했습니다. 다시 시도해주세요.') | ||||||
| setIsOpen(true) | ||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||
| } finally { | ||||||
| clearTimeout(timeout) | ||||||
| setIsCreating(false) | ||||||
| } | ||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||
| } | ||||||
|
|
||||||
| return ( | ||||||
|
|
@@ -39,8 +62,11 @@ export default function NewCaseButton() { | |||||
| > | ||||||
| <div className={styles.panel} onClick={(e) => e.stopPropagation()}> | ||||||
| <div className={styles.categoryBox}> | ||||||
| {errorMessage && ( | ||||||
| <p className={styles.errorMessage}>{errorMessage}</p> | ||||||
| )} | ||||||
| {CATEGORY_ITEMS.map(({ category, label }) => ( | ||||||
| <button key={category} className={styles.item} onClick={() => handleCategoryClick(category)}> | ||||||
| <button key={category} className={styles.item} onClick={() => handleCategoryClick(category)} disabled={isCreating}> | ||||||
| <CategoryIcon category={category} /> | ||||||
| <span className={styles.itemLabel}>{label}</span> | ||||||
| </button> | ||||||
|
|
||||||
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.
앜 여기 /test/ 말고 /[id] 로 변경해줘요