-
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 #121 from KUIT-Space/feat#96-space-home
feat : ๋ฉค๋ฒ ์ด๋ ๊ธฐ๋ฅ ์ถ๊ฐ
- Loading branch information
Showing
4 changed files
with
251 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,209 @@ | ||
import { ChangeEvent, useEffect, useState } from "react"; | ||
import { useLocation, useNavigate, useParams } from "react-router-dom"; | ||
import styled from "styled-components"; | ||
|
||
import { SpaceInfo as SpaceInfoType } from "@/apis/Space/SpaceSelectApi"; | ||
import { SpaceUserJoinApi } from "@/apis/Space/SpaceUserJoinApi"; | ||
import { CharacterImgs } from "@/assets/Characters"; | ||
import ChatroomImg from "@/assets/ChatPage/btn_chatroom_img.svg"; | ||
import back from "@/assets/icon_back.svg"; | ||
import { BottomBtn } from "@/components/BottomBtn"; | ||
import { Input } from "@/components/Input"; | ||
import { getUserDefaultImageURL } from "@/utils/getUserDefaultImageURL"; | ||
import { svgComponentToFile } from "@/utils/svgComponentToFile"; | ||
|
||
import { ChatroomAddImgBtn } from "../ChatPage/ChatCreatePage/ChatCreatePage.styled"; | ||
import { SpaceJoinInfo, SpaceJoinInfoApi } from "@/apis"; | ||
|
||
const TopBarContainer = styled.div` | ||
display: flex; | ||
height: 52px; | ||
align-items: center; | ||
`; | ||
|
||
const BackBtn = styled.img` | ||
width: 36px; | ||
height: 36px; | ||
cursor: pointer; | ||
`; | ||
|
||
const InfoContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
margin-top: 132px; | ||
`; | ||
|
||
const SpaceImage = styled.img` | ||
width: 160px; | ||
height: 160px; | ||
border-radius: 12px; | ||
margin-bottom: 20px; | ||
`; | ||
|
||
const SpaceTitle = styled.span` | ||
font-size: 24px; | ||
font-weight: semi-bold; | ||
margin-bottom: 20px; | ||
`; | ||
const SpaceInfo = styled.span` | ||
height: 22px; | ||
font-size: 16px; | ||
color: ${({ theme }) => theme.colors.BG500}; | ||
`; | ||
|
||
const Count = styled.span` | ||
position: absolute; | ||
right: 1rem; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
font-size: 16px; | ||
color: ${({ theme }) => theme.colors.BG500}; | ||
`; | ||
|
||
const NameInput = styled(Input)` | ||
padding-right: 4rem; /* Count๋ฅผ ์ํ ์ฌ์ ๊ณต๊ฐ */ | ||
margin-top: 8px; | ||
`; | ||
|
||
const SpaceJoinBottomBtn = styled(BottomBtn)` | ||
display: fixed; | ||
bottom: 1; | ||
margin: 0; | ||
`; | ||
|
||
const InviteSpace2 = () => { | ||
const navigate = useNavigate(); | ||
const { spaceId } = useParams(); | ||
|
||
const [spaceInfo, setSpaceInfo] = useState<SpaceJoinInfo>(); | ||
const [currentStep, setCurrentStep] = useState(1); | ||
const [spacename, setSpacename] = useState(""); | ||
const [spaceUserMsg, setSpaceUserMsg] = useState(""); | ||
const maxChars = 12; | ||
|
||
const [uploadedImage, setUploadedImage] = useState<File | null>(null); | ||
const defaultImage: File = svgComponentToFile( | ||
CharacterImgs[Math.floor(Math.random() * CharacterImgs.length)], | ||
); | ||
|
||
useEffect(() => { | ||
//TODO: spaceInfo๊ฐ ์์ ๋์ ๋๋ฏธ ๋ฐ์ดํฐ | ||
console.log(spaceId); | ||
const response = SpaceJoinInfoApi(Number.parseInt(spaceId!)).then((data) => { | ||
setSpaceInfo(data?.result); | ||
}); | ||
}, []); | ||
|
||
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
const value = e.target.value; | ||
if (value.length <= maxChars) { | ||
setSpacename(value); | ||
} | ||
}; | ||
|
||
const handleNextButtonClick = () => { | ||
if (currentStep === 2) { | ||
//TODO: ๊ฐ์ ํ๊ธฐ API ํธ์ถ / userImg, userName | ||
SpaceUserJoinApi( | ||
Number.parseInt(spaceId!), | ||
uploadedImage ?? defaultImage, | ||
spacename, | ||
spaceUserMsg, | ||
).then((res) => { | ||
if (res) navigate("/"); | ||
}); | ||
} | ||
setCurrentStep((prevStep) => prevStep + 1); | ||
}; | ||
|
||
const handlePreviousButtonClick = () => { | ||
setCurrentStep((prevStep) => prevStep - 1); | ||
}; | ||
|
||
const handleImageImport = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const image = e.target.files?.[0]; | ||
image && setUploadedImage(image); | ||
}; | ||
|
||
return ( | ||
<div> | ||
{currentStep === 1 && ( | ||
<InfoContainer> | ||
<SpaceImage | ||
src={spaceInfo?.spaceProfileImg ?? getUserDefaultImageURL(Number.parseInt(spaceId!))} | ||
/> | ||
<SpaceTitle>{spaceInfo?.spaceName}</SpaceTitle> | ||
<div> | ||
<div style={{ marginBottom: "0.5rem" }}> | ||
<SpaceInfo style={{ marginRight: "0.75rem" }}>๊ฐ์ค์ผ</SpaceInfo> | ||
<SpaceInfo> | ||
{isNaN(Date.parse(spaceInfo?.createdAt ?? "")) | ||
? spaceInfo?.createdAt | ||
: spaceInfo?.createdAt && | ||
new Date(spaceInfo?.createdAt).toLocaleDateString("ko-KR")} | ||
</SpaceInfo> | ||
</div> | ||
<div> | ||
<SpaceInfo style={{ marginRight: "0.75rem" }}>๋ฉค๋ฒ</SpaceInfo> | ||
<SpaceInfo>{spaceInfo?.memberNum}๋ช </SpaceInfo> | ||
</div> | ||
</div> | ||
</InfoContainer> | ||
)} | ||
{currentStep === 2 && ( | ||
<div> | ||
<TopBarContainer> | ||
<BackBtn src={back} onClick={handlePreviousButtonClick} /> | ||
</TopBarContainer> | ||
|
||
<ChatroomAddImgBtn $backgroundImage={URL.createObjectURL(uploadedImage ?? defaultImage)}> | ||
<img src={ChatroomImg} alt="Chatroom Image" /> | ||
<input type="file" accept="image/*" onChange={handleImageImport} /> | ||
</ChatroomAddImgBtn> | ||
|
||
<div style={{ marginTop: "16px" }}> | ||
์ด๋ฆ | ||
<div style={{ position: "relative" }}> | ||
<NameInput | ||
value={spacename} | ||
onChange={handleInputChange} | ||
placeholder="์คํ์ด์ค์์ ์ฌ์ฉํ ์ด๋ฆ" | ||
/> | ||
<Count> | ||
{spacename.length}/{maxChars} | ||
</Count> | ||
</div> | ||
</div> | ||
|
||
<div style={{ marginTop: "16px" }}> | ||
์ํ ๋ฉ์ธ์ง | ||
<div style={{ position: "relative" }}> | ||
<NameInput | ||
value={spaceUserMsg} | ||
onChange={(e) => { | ||
const value = e.target.value; | ||
if (value.length <= maxChars * 5) { | ||
setSpaceUserMsg(value); | ||
} | ||
}} | ||
placeholder="์คํ์ด์ค ์ํ ๋ฉ์ธ์ง" | ||
/> | ||
<Count> | ||
{spaceUserMsg.length}/{maxChars * 5} | ||
</Count> | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
<SpaceJoinBottomBtn | ||
disabled={currentStep === 2 && spacename === "" ? true : false} | ||
onClick={handleNextButtonClick} | ||
> | ||
๊ฐ์ ํ๊ธฐ | ||
</SpaceJoinBottomBtn> | ||
</div> | ||
); | ||
}; | ||
|
||
export default InviteSpace2; |