Skip to content

Commit

Permalink
πŸš€ Deploy #59
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaem03 authored Nov 14, 2024
2 parents c2d0600 + c3e18ef commit 514c5ee
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 40 deletions.
28 changes: 28 additions & 0 deletions src/apis/nuguPatch.js
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;
}
};
2 changes: 1 addition & 1 deletion src/components/common/navigateBar/NavigateBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const NavigateBar = () => {
path = `/nugu/${Cookies.get("uuid")}`;
break;
case 2:
path = `/intro/${Cookies.get("uuid")}`;
path = `/nuguIntro/${Cookies.get("uuid")}`;
break;
case 3:
path = isTokenAvailable ? "/test" : "/challenge";
Expand Down
8 changes: 6 additions & 2 deletions src/pages/nugu/Nugu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { Layout } from "@components/common/layout/Layout";
import { NavigateBar } from "@components/common/navigateBar/NavigateBar";
import { Chip } from "@components/chip/Chip";

import { useParams } from "react-router-dom";
import { useParams, useNavigate } from "react-router-dom";
import { useNuguInfo } from "./_hooks/useNuguInfo";

export const Nugu = () => {
const { uuid } = useParams();
const { data, isAdmin } = useNuguInfo(uuid);
const navigate = useNavigate();
const moveOnPatch = () => {
navigate(`/nugu/patch/${uuid}`);
};
return (
<Layout
$backgroundColor={"blue200"}
Expand Down Expand Up @@ -42,7 +46,7 @@ export const Nugu = () => {
{isAdmin && (
<S.AdminWrapper>
<S.ShareBtn>λˆ„κ΅¬ κ³΅μœ ν•˜κΈ°</S.ShareBtn>
<S.EditBtn>μˆ˜μ •ν•˜κΈ°</S.EditBtn>
<S.EditBtn onClick={() => moveOnPatch()}>μˆ˜μ •ν•˜κΈ°</S.EditBtn>
</S.AdminWrapper>
)}
</S.Wrapper>
Expand Down
81 changes: 44 additions & 37 deletions src/pages/nuguIntro/WriteIntro.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Input } from "@components/input/Input";
import { Button } from "@components/common/button/Button";
import { Chip } from "@components/chip/Chip";
import { CHIP_DATA } from "@constants/chip";
import { Layout } from "@components/common/layout/Layout";

import { useNavigate } from "react-router-dom";
import { useIntroForm } from "./_hooks/useIntroForm";
Expand Down Expand Up @@ -34,49 +35,55 @@ export const WriteIntro = () => {
keyword3,
uuid,
});

navigate(-1);
return response;
} catch (err) {
throw err;
}
};
return (
<S.IntroContainer>
<ProgressBar title={"λˆ„κ΅¬ μ†Œκ°œν•˜κΈ°"} $now={4} $total={4} />
<S.InfoWrapper>
<Input
title={"λˆ„κ΅¬λ₯Ό μ†Œκ°œν•˜μžλ©΄?"}
name="content"
placeholder={"λˆ„κ΅¬ μ†Œκ°œλ₯Ό μž…λ ₯ν•΄ μ£Όμ„Έμš” (150자 이내)"}
value={content}
onChange={handleChangeContent}
/>
<Layout
$backgroundColor={"gray200"}
$margin="3rem 0 0 0"
$justifyContent="start"
>
<S.IntroContainer>
<ProgressBar title={"λˆ„κ΅¬ μ†Œκ°œν•˜κΈ°"} $now={4} $total={4} />
<S.InfoWrapper>
<Input
title={"λˆ„κ΅¬λ₯Ό μ†Œκ°œν•˜μžλ©΄?"}
name="content"
placeholder={"λˆ„κ΅¬ μ†Œκ°œλ₯Ό μž…λ ₯ν•΄ μ£Όμ„Έμš” (150자 이내)"}
value={content}
onChange={handleChangeContent}
/>

<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.InfoWrapper>
<Button
disabled={selectedCount !== 3 || content.length === 0}
onClick={handleSubmit}
>
μ €μž₯ν•˜κΈ°
</Button>
</S.IntroContainer>
<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.InfoWrapper>
<Button
disabled={selectedCount !== 3 || content.length === 0}
onClick={handleSubmit}
>
μ €μž₯ν•˜κΈ°
</Button>
</S.IntroContainer>
</Layout>
);
};
73 changes: 73 additions & 0 deletions src/pages/nuguPatch/NuguPatch.jsx
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>
);
};
41 changes: 41 additions & 0 deletions src/pages/nuguPatch/_hooks/useNuguPatch.js
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 };
};
39 changes: 39 additions & 0 deletions src/pages/nuguPatch/_hooks/usePatchChip.js
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 };
};
48 changes: 48 additions & 0 deletions src/pages/nuguPatch/styled.js
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;
`;
5 changes: 5 additions & 0 deletions src/router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NuguTestPage } from "@pages/nuguTest/NuguTest";
import { MakeNuguTest } from "@pages/nuguTest/MakeNuguTest";
import { NuguChallenge } from "@pages/nuguTest/NuguChallenge";
import { ChallengerTest } from "@pages/nuguTest/ChallengerTest";
import { NuguPatch } from "@pages/nuguPatch/NuguPatch";
const router = createBrowserRouter([
{
path: "/",
Expand Down Expand Up @@ -69,6 +70,10 @@ const router = createBrowserRouter([
path: "/nugu/:uuid",
element: <Nugu />,
},
{
path: "/nugu/patch/:uuid",
element: <NuguPatch />,
},
],
},
]);
Expand Down

0 comments on commit 514c5ee

Please sign in to comment.