-
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.
[Feature]/#58- 누구 수정 페이지 UI 구현 및 API 연결
- Loading branch information
Showing
9 changed files
with
285 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { instance } from "./instance"; | ||
export const patchNuguInfo = async ({ | ||
nickname, | ||
mbti, | ||
org, | ||
insta_url, | ||
intro, | ||
keyword1, | ||
keyword2, | ||
keyword3, | ||
}) => { | ||
try { | ||
const response = await instance.patch("/user", { | ||
nickname, | ||
mbti, | ||
org, | ||
insta_url, | ||
intro, | ||
keyword1, | ||
keyword2, | ||
keyword3, | ||
}); | ||
console.log("patch된 정보", response); | ||
return response; | ||
} catch (err) { | ||
throw err; | ||
} | ||
}; |
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,73 @@ | ||
import * as S from "./styled"; | ||
import { useRecoilState } from "recoil"; | ||
import { Layout } from "@components/common/layout/Layout"; | ||
import { ProgressBar } from "@components/progressBar/ProgreesBar"; | ||
import { SIGN_UP_FIELDS } from "@constants/signUp"; | ||
import { Input } from "@components/input/Input"; | ||
import { theme } from "@styles/theme"; | ||
import { signUpState } from "@atoms/signUpState"; | ||
import { usePatchChip } from "./_hooks/usePatchChip"; | ||
import { Chip } from "@components/chip/Chip"; | ||
import { CHIP_DATA } from "@constants/chip"; | ||
import { Button } from "@components/common/button/Button"; | ||
import { useNuguPatch } from "./_hooks/useNuguPatch"; | ||
export const NuguPatch = () => { | ||
const [updateData, setUpdateData] = useRecoilState(signUpState); | ||
const { handleSubmit, isFormValid } = useNuguPatch(); | ||
const { selectedChip, handleClickStatus, selectedCount } = usePatchChip(); | ||
|
||
const handleInputChange = (name, value) => { | ||
setUpdateData((prevData) => ({ | ||
...prevData, | ||
[name]: value, | ||
})); | ||
}; | ||
|
||
return ( | ||
<Layout | ||
$backgroundColor={"gray200"} | ||
$margin="0 0 0 0" | ||
$justifyContent="start" | ||
> | ||
<S.PatchWrapper> | ||
<S.TopWrapper> | ||
<ProgressBar title={"누구 수정하기"} $now={4} $total={4} /> | ||
{[...SIGN_UP_FIELDS[1], ...SIGN_UP_FIELDS[2]].map((data, index) => ( | ||
<Input | ||
title={data.title} | ||
key={index} | ||
value={updateData[data.name] || ""} | ||
onChange={(e) => handleInputChange(data.name, e.target.value)} | ||
type={data.type} | ||
/> | ||
))} | ||
|
||
<S.TitleWrapper> | ||
<S.Title>나를 표현하는 키워드</S.Title> | ||
<S.SubTitle>나와 어울리는 키워드 3개를 선택해주세요</S.SubTitle> | ||
<S.ChipWrapper> | ||
{CHIP_DATA.map((text, index) => ( | ||
<Chip | ||
key={index} | ||
$index={index} | ||
onClick={() => handleClickStatus(index)} | ||
$backgroundColor={ | ||
selectedChip[index] ? theme.colors.blue200 : "white" | ||
} | ||
> | ||
{text} | ||
</Chip> | ||
))} | ||
</S.ChipWrapper> | ||
</S.TitleWrapper> | ||
</S.TopWrapper> | ||
<Button | ||
disabled={selectedCount !== 3 || !isFormValid()} | ||
onClick={handleSubmit} | ||
> | ||
저장하기 | ||
</Button> | ||
</S.PatchWrapper> | ||
</Layout> | ||
); | ||
}; |
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,41 @@ | ||
import { patchNuguInfo } from "@apis/nuguPatch"; | ||
import { useRecoilState } from "recoil"; | ||
import { signUpState } from "@atoms/signUpState"; | ||
|
||
export const useNuguPatch = () => { | ||
const [updateData, setUpdateData] = useRecoilState(signUpState); | ||
const handleSubmit = async () => { | ||
console.log(updateData); | ||
try { | ||
const response = await patchNuguInfo({ | ||
nickname: updateData.nickname, | ||
mbti: updateData.mbti, | ||
org: updateData.org, | ||
insta_url: updateData.insta_url, | ||
intro: updateData.intro, | ||
keyword1: updateData.keyword1, | ||
keyword2: updateData.keyword2, | ||
keyword3: updateData.keyword3, | ||
}); | ||
// navigate(-1); | ||
return response; | ||
} catch (err) { | ||
throw err; | ||
} | ||
}; | ||
|
||
const isFormValid = () => { | ||
const requiredFields = [ | ||
updateData.nickname, | ||
updateData.mbti, | ||
updateData.org, | ||
updateData.insta_url, | ||
updateData.intro, | ||
updateData.keyword1, | ||
updateData.keyword2, | ||
updateData.keyword3, | ||
]; | ||
return requiredFields.every((field) => field !== ""); | ||
}; | ||
return { handleSubmit, isFormValid }; | ||
}; |
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,39 @@ | ||
import { useState } from "react"; | ||
import { useRecoilState } from "recoil"; | ||
import { signUpState } from "@atoms/signUpState"; | ||
import { CHIP_DATA } from "@constants/chip"; | ||
export const usePatchChip = () => { | ||
const [updateData, setUpdateData] = useRecoilState(signUpState); | ||
const [selectedChip, setSelectedChip] = useState( | ||
CHIP_DATA.map( | ||
(chip) => | ||
updateData.keyword1 === chip || | ||
updateData.keyword2 === chip || | ||
updateData.keyword3 === chip | ||
) | ||
); | ||
const selectedCount = selectedChip.filter((chip) => chip).length; | ||
|
||
const handleClickStatus = (index) => { | ||
const updatedChip = [...selectedChip]; | ||
updatedChip[index] = !updatedChip[index]; | ||
if (updatedChip.filter((chip) => chip).length > 3) { | ||
return; | ||
} | ||
setSelectedChip(updatedChip); | ||
const selectedKeywords = updatedChip | ||
.map((isSelected, idx) => (isSelected ? CHIP_DATA[idx] : null)) | ||
.filter((keyword) => keyword !== null); | ||
|
||
if (selectedKeywords.length === 3) { | ||
setUpdateData((prevData) => ({ | ||
...prevData, | ||
keyword1: selectedKeywords[0], | ||
keyword2: selectedKeywords[1], | ||
keyword3: selectedKeywords[2], | ||
})); | ||
} | ||
}; | ||
|
||
return { selectedChip, handleClickStatus, selectedCount }; | ||
}; |
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,48 @@ | ||
import styled from "styled-components"; | ||
export const PatchWrapper = styled.div` | ||
display: flex; | ||
width: 100%; | ||
padding: 2rem 0 4rem 0; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: space-between; | ||
gap: 2rem; | ||
`; | ||
|
||
export const TopWrapper = styled.div` | ||
width: 90%; | ||
display: flex; | ||
align-items: center; | ||
flex-direction: column; | ||
gap: 1.875rem; | ||
`; | ||
export const TitleWrapper = styled.div` | ||
width: 304px; | ||
display: flex; | ||
flex-direction: column; | ||
`; | ||
|
||
export const Title = styled.p` | ||
color: ${({ theme }) => theme.colors.blue300}; | ||
${({ theme }) => theme.fonts.pretendardB4}; | ||
`; | ||
|
||
export const SubTitle = styled.p` | ||
color: ${({ theme }) => theme.colors.blue300}; | ||
${({ theme }) => theme.fonts.pretendardB1}; | ||
`; | ||
|
||
export const ChipWrapper = styled.div` | ||
width: 100%; | ||
display: grid; | ||
grid-template-rows: repeat(3, 1fr); | ||
grid-template-columns: repeat(3, 1fr); | ||
justify-content: center; | ||
place-items: center; | ||
row-gap: 0.625rem; | ||
column-gap: 1rem; | ||
margin-top: 1rem; | ||
`; |
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