-
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
9 changed files
with
262 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,142 @@ | ||
import { ChangeEvent, FormEvent, useMemo, useState } from "react"; | ||
import Check from "../../assets/icons/check.svg?react"; | ||
import Closed from "../../assets/icons/closed.svg?react"; | ||
import CategoryChip from "./CategoryChip"; | ||
import { StoryForm } from "../../types/common/backlog"; | ||
import useStoryEmitEvent from "../../hooks/pages/backlog/useStoryEmitEvent"; | ||
import { Socket } from "socket.io-client"; | ||
import { useOutletContext } from "react-router-dom"; | ||
// import useShowDetail from "../../hooks/pages/backlog/useShowDetail"; | ||
import EpicDropdown from "./EpicDropdown"; | ||
import { EpicCategoryDTO } from "../../types/DTO/backlogDTO"; | ||
import useDropdownState from "../../hooks/common/dropdown/useDropdownState"; | ||
|
||
const StoryCreateForm = () => ( | ||
<div className="flex items-center gap-5 py-1 border-t border-b"> | ||
<div className="w-[5rem]"> | ||
<CategoryChip content="프로젝트" bgColor="green" /> | ||
</div> | ||
<input className="w-[38.75rem]" type="text" /> | ||
<div className="flex items-center "> | ||
<input className="w-14" type="number" id="point-number" /> | ||
<label htmlFor="point-number" className=""> | ||
POINT | ||
</label> | ||
</div> | ||
<div className="flex items-center gap-2"> | ||
<button | ||
className="flex items-center justify-center w-6 h-6 rounded-md bg-confirm-green" | ||
type="button" | ||
> | ||
<Check width={20} height={20} stroke="white" /> | ||
</button> | ||
<button | ||
className="flex items-center justify-center w-6 h-6 rounded-md bg-error-red" | ||
type="button" | ||
interface StoryCreateFormProps { | ||
onCloseClick: () => void; | ||
epicList: EpicCategoryDTO[]; | ||
} | ||
|
||
const StoryCreateForm = ({ onCloseClick, epicList }: StoryCreateFormProps) => { | ||
const { socket }: { socket: Socket } = useOutletContext(); | ||
const [{ title, point, epicId, status }, setStoryFormData] = | ||
useState<StoryForm>({ | ||
title: "", | ||
point: undefined, | ||
status: "시작전", | ||
epicId: undefined, | ||
}); | ||
const { open, handleClose, handleOpen, dropdownRef } = useDropdownState(); | ||
const { emitStoryCreateEvent } = useStoryEmitEvent(socket); | ||
|
||
const handleTitleChange = ({ target }: ChangeEvent<HTMLInputElement>) => { | ||
const { value } = target; | ||
setStoryFormData({ title: value, point, epicId, status }); | ||
}; | ||
|
||
const handlePointChange = ({ target }: ChangeEvent<HTMLInputElement>) => { | ||
const { value } = target; | ||
setStoryFormData({ title, point: Number(value), epicId, status }); | ||
}; | ||
|
||
const handleSubmit = (event: FormEvent) => { | ||
event.preventDefault(); | ||
if (epicId === undefined) { | ||
alert("에픽을 지정해주세요."); | ||
return; | ||
} | ||
|
||
if (!title) { | ||
alert("제목을 입력해주세요."); | ||
return; | ||
} | ||
|
||
if (point === undefined) { | ||
alert("포인트를 입력해주세요."); | ||
return; | ||
} | ||
|
||
emitStoryCreateEvent({ title, status, epicId, point }); | ||
onCloseClick(); | ||
}; | ||
|
||
const handleEpicChange = (selectedEpicId: number) => { | ||
setStoryFormData({ title, status, point, epicId: selectedEpicId }); | ||
handleClose(); | ||
}; | ||
|
||
const handleEpicColumnClick = () => { | ||
if (!open) { | ||
handleOpen(); | ||
} | ||
}; | ||
|
||
const selectedEpic = useMemo( | ||
() => epicList.filter(({ id }) => id === epicId)[0], | ||
[epicId] | ||
); | ||
return ( | ||
<form | ||
className="flex items-center w-full py-1 border-t border-b" | ||
onSubmit={handleSubmit} | ||
> | ||
<div | ||
className="w-[5rem] min-h-[1.75rem] bg-light-gray rounded-md mr-7 hover:cursor-pointer relative" | ||
onClick={handleEpicColumnClick} | ||
ref={dropdownRef} | ||
> | ||
<Closed stroke="white" /> | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
{epicId && ( | ||
<CategoryChip | ||
content={selectedEpic.name} | ||
bgColor={selectedEpic.color} | ||
/> | ||
)} | ||
{open && ( | ||
<EpicDropdown | ||
selectedEpic={selectedEpic} | ||
epicList={epicList} | ||
onEpicSelect={handleEpicChange} | ||
/> | ||
)} | ||
</div> | ||
<input | ||
className="w-[34.7rem] h-[1.75rem] mr-[1.5rem] bg-light-gray rounded-md focus:outline-none" | ||
type="text" | ||
value={title} | ||
onChange={handleTitleChange} | ||
/> | ||
<div className="flex items-center mr-[2.8rem] "> | ||
<input | ||
className="w-24 h-[1.75rem] mr-1 text-right rounded-md bg-light-gray no-arrows focus:outline-none" | ||
type="number" | ||
id="point-number" | ||
value={point} | ||
onChange={handlePointChange} | ||
/> | ||
<label htmlFor="point-number" className=""> | ||
POINT | ||
</label> | ||
</div> | ||
<div className="w-[4rem] mr-[2.76rem] text-right"> | ||
<span>0%</span> | ||
</div> | ||
<div className="flex items-center gap-2"> | ||
<button | ||
className="flex items-center justify-center w-6 h-6 rounded-md bg-confirm-green" | ||
type="button" | ||
onClick={handleSubmit} | ||
> | ||
<Check width={20} height={20} stroke="white" /> | ||
</button> | ||
<button | ||
className="flex items-center justify-center w-6 h-6 rounded-md bg-error-red" | ||
type="button" | ||
onClick={onCloseClick} | ||
> | ||
<Closed stroke="white" /> | ||
</button> | ||
</div> | ||
</form> | ||
); | ||
}; | ||
|
||
export default StoryCreateForm; |
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,27 @@ | ||
import { Socket } from "socket.io-client"; | ||
import { StoryForm } from "../../../types/common/backlog"; | ||
import { BacklogStatusType } from "../../../types/DTO/backlogDTO"; | ||
|
||
const useStoryEmitEvent = (socket: Socket) => { | ||
const emitStoryCreateEvent = (content: StoryForm) => { | ||
socket.emit("story", { action: "create", content }); | ||
}; | ||
|
||
const emitStoryDeleteEvent = (content: { id: number }) => { | ||
socket.emit("story", { action: "delete", content }); | ||
}; | ||
|
||
const emitStoryUpdateEvent = (content: { | ||
id: number; | ||
title?: string; | ||
status?: BacklogStatusType; | ||
epicId?: number; | ||
point?: number; | ||
}) => { | ||
socket.emit("story", { action: "update", content }); | ||
}; | ||
|
||
return { emitStoryCreateEvent, emitStoryDeleteEvent, emitStoryUpdateEvent }; | ||
}; | ||
|
||
export default useStoryEmitEvent; |
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
Oops, something went wrong.