-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from hufs-sports-live/fix/not-found-gameTeas
[FIX] 팀 정보 없을 시 화면이 다운되는 에러 해결
- Loading branch information
Showing
11 changed files
with
129 additions
and
42 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
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
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 |
---|---|---|
@@ -1,54 +1,83 @@ | ||
import { UseMutateFunction } from '@tanstack/react-query'; | ||
import { FormEvent, useState } from 'react'; | ||
import { ChangeEvent, FormEvent, useState } from 'react'; | ||
|
||
import { MatchCommentPayload } from '@/types/match'; | ||
import { MatchCommentPayload, MatchTeamType } from '@/types/match'; | ||
|
||
type CommentFormProps = { | ||
matchId: string; | ||
matchTeams: MatchTeamType[]; | ||
mutate: UseMutateFunction<void, Error, MatchCommentPayload, unknown>; | ||
scrollToBottom: () => void; | ||
}; | ||
|
||
export default function CommentForm({ | ||
matchId, | ||
matchTeams, | ||
mutate, | ||
scrollToBottom, | ||
}: CommentFormProps) { | ||
const [inputValue, setInputValue] = useState(''); | ||
const [selectedTeamId, setSelectedTeamId] = useState<number>(1); | ||
const [isOpen, toggleOpen] = useState(false); | ||
|
||
const handleCommentSubmit = ( | ||
e: FormEvent<HTMLFormElement>, | ||
payload: MatchCommentPayload, | ||
) => { | ||
e.preventDefault(); | ||
mutate(payload); | ||
mutate({ ...payload, gameTeamId: selectedTeamId }); | ||
setInputValue(''); | ||
scrollToBottom(); | ||
}; | ||
|
||
const handleRadioClick = (e: ChangeEvent<HTMLInputElement>) => { | ||
setSelectedTeamId(Number(e.target.value)); | ||
}; | ||
|
||
return ( | ||
<form | ||
className="h-70px absolute -bottom-1 left-0 w-full" | ||
onSubmit={e => | ||
handleCommentSubmit(e, { | ||
gameTeamId: Number(matchId), | ||
content: inputValue, | ||
}) | ||
} | ||
> | ||
<div | ||
className="grid items-center rounded-lg bg-gray-2" | ||
style={{ gridTemplateColumns: '1fr auto' }} | ||
<> | ||
<form | ||
className="h-70px absolute -bottom-1 left-0 w-full" | ||
onSubmit={e => | ||
handleCommentSubmit(e, { | ||
gameTeamId: Number(matchId), | ||
content: inputValue, | ||
}) | ||
} | ||
> | ||
<input | ||
className="bg-inherit px-5 text-gray-5 outline-none" | ||
value={inputValue} | ||
onChange={e => setInputValue(e.target.value)} | ||
placeholder="응원하는 팀에 댓글을 남겨보세요!" | ||
/> | ||
<button className="rounded-xl bg-primary px-5 py-3 text-white"> | ||
댓글 | ||
</button> | ||
</div> | ||
</form> | ||
{isOpen && ( | ||
<fieldset className="absolute top-0 flex w-full -translate-y-full items-center justify-start gap-2 rounded-lg bg-white px-5 py-3 shadow-md"> | ||
{matchTeams.map(team => ( | ||
<label key={team.gameTeamId} className="flex items-center"> | ||
<input | ||
type="radio" | ||
checked={selectedTeamId === team.gameTeamId} | ||
value={team.gameTeamId} | ||
onChange={handleRadioClick} | ||
className="dark:border-gray-6 dark:bg-gray-6 h-4 w-4 border-gray-3 bg-gray-1 text-primary focus:ring-2 focus:ring-primary dark:ring-offset-black dark:focus:ring-primary" | ||
/> | ||
{team.gameTeamName} | ||
</label> | ||
))} | ||
</fieldset> | ||
)} | ||
|
||
<div | ||
className="z-10 grid items-center rounded-lg bg-gray-2" | ||
style={{ gridTemplateColumns: '1fr auto' }} | ||
> | ||
<input | ||
className="bg-inherit px-5 text-gray-5 outline-none" | ||
value={inputValue} | ||
onChange={e => setInputValue(e.target.value)} | ||
placeholder="응원하는 팀에 댓글을 남겨보세요!" | ||
onFocus={() => toggleOpen(true)} | ||
/> | ||
<button className="rounded-xl bg-primary px-5 py-3 text-white"> | ||
댓글 | ||
</button> | ||
</div> | ||
</form> | ||
</> | ||
); | ||
} |
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
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