Skip to content

Commit

Permalink
[Feat] 서버와 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
jyeongpark committed Jun 29, 2024
1 parent 4d5dfd1 commit 00b43bb
Show file tree
Hide file tree
Showing 30 changed files with 343 additions and 426 deletions.
4 changes: 0 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
http-equiv="Content-Security-Policy"
content="upgrade-insecure-requests"
/>
<title>Vite + React + TS</title>
</head>
<body>
Expand Down
34 changes: 34 additions & 0 deletions src/components/List/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";
import { styled } from "styled-components";

interface Props {
title: string;
onClick: () => void;
}
const List = ({ title, onClick }: Props) => {
return (
<>
<ListDiv onClick={onClick}>
<StyledH3>{title}</StyledH3>
</ListDiv>
</>
);
};

export default List;

export const ListDiv = styled.div`
width: 100%;
height: 100px;
border-bottom: ${({ theme }) => theme.boxBorder.bookBorder};
display: flex;
align-items: center;
justify-content: center;
`;

const StyledH3 = styled.div`
display: flex;
justify-content: center;
align-items: center;
font-size: 30pt;
`;
1 change: 0 additions & 1 deletion src/components/common/FriendBook/FriendBook.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const Default = () => {
return (
<div style={{ width: "300px", height: "500px" }}>
<FriendBook
friendId={0}
title="지영과 수경의 교환일기"
onClick={() => alert("눌렸습니다")}
></FriendBook>
Expand Down
11 changes: 7 additions & 4 deletions src/components/common/FriendBook/FriendBook.styled.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import styled from "styled-components";

export const FriendDiv = styled.div`
width: 60%;
width: 100%;
height: 200px;
background-color: white;
border: 1px solid #eaeaea;
box-shadow: ${({ theme }) => theme.boxShadow.bookShadow};
border-radius: 4px;
display: flex;
justify-content: center;
position: relative;
align-items: center;
cursor: pointer;
`;

export const FriendLCoverDiv = styled.div`
width: 30%;
height: 200px;
height: 100%;
background-color: ${({ theme }) => theme.color.point};
border-radius: 4px;
display: flax;
Expand All @@ -27,9 +28,11 @@ export const FriendRCoverDiv = styled.div`
height: 20px;
background-color: ${({ theme }) => theme.color.point};
border-radius: 4px;
display: flax;
display: flex;
flex-direction: center;
align-items: center;
position: absolute;
right: 0;
`;

export const FriendTextDiv = styled.div`
Expand Down
5 changes: 1 addition & 4 deletions src/components/common/FriendBook/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React from "react";
import styled from "styled-components";
import * as S from "./FriendBook.styled";
export interface Props {
friendId: number;
title: string;
onClick: () => void;
}
const FriendBook = ({ friendId, title, onClick }: Props) => {
const FriendBook = ({ title, onClick }: Props) => {
return (
<S.FriendDiv onClick={onClick}>
<S.FriendLCoverDiv></S.FriendLCoverDiv>
Expand Down
4 changes: 4 additions & 0 deletions src/components/common/Input/Input/Input.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export const InputArea = styled.input<{ inputWidth: string }>`
border: none;
outline: none;
font-size: ${({ theme }) => theme.fontSize.large};
&:disabled {
background-color: ${({ theme }) => theme.color.background};
}
`;

export const InputLabel = styled.span<{
Expand Down
4 changes: 4 additions & 0 deletions src/components/common/Input/TextArea/TextArea.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export const TextArea = styled.textarea<{ inputWidth: string }>`
font-size: ${({ theme }) => theme.fontSize.large};
resize: none;
height: 100%;
&:disabled {
background-color: ${({ theme }) => theme.color.background};
}
`;

export const InputLabel = styled.span<{
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/api/auth/usePostLogin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useToast } from "@/hooks/useToast";
import { instance, post } from "@/libs/api";
import { queryClient } from "@/libs/queryClient";
import { UserState } from "@/store";

import { LoginRequest, LoginResponse } from "@/types/user";
Expand All @@ -26,8 +27,8 @@ export const useLogin = () => {
mutationFn: (params: LoginRequest) => postLogin(params),

onSuccess: ({ res }) => {
console.log("res", res);
toastOpen("환영합니다");
queryClient.clear();
setTimeout(() => {
setUser(res.data);
// 토큰 저장
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/api/auth/usePostSignUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useSignUp = () => {

onSuccess: ({ res }) => {
console.log("res", res);
toastOpen("생성되었습니다");
toastOpen("가입되었습니다.");

setTimeout(() => {
navigate("/auth/login", {
Expand Down
20 changes: 20 additions & 0 deletions src/hooks/api/diary/useGetListByFriendId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { get } from "@/libs/api";
import { DiaryContent } from "@/types/diary";
import { queryKeys } from "@/utils/constants";
import { useQuery } from "@tanstack/react-query";

const getDiaryByFriendId = async (friendId: number) => {
const res = await get<{ data: DiaryContent[] }>(
`/apis/v1/diary/read/friend/${friendId}?page=100&size=100`
);

return { data: res.data };
};
export const useGetListByFriendId = (friendId: number) => {
const { data } = useQuery({
queryFn: () => getDiaryByFriendId(friendId),
queryKey: [queryKeys.diaryList, friendId],
});

return { data };
};
42 changes: 42 additions & 0 deletions src/hooks/api/diary/useSubmitDiary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import useCurrentUser from "@/hooks/useAuth";
import { useToast } from "@/hooks/useToast";
import { post } from "@/libs/api";
import { queryClient } from "@/libs/queryClient";
import { useMutation } from "@tanstack/react-query";
import { useNavigate } from "react-router-dom";

interface ISubmitDiary {
title: string;
content: string;
sing: "";
friendId: number;
}
const submitDiary = async (id: number, params: ISubmitDiary) => {
const res = await post(`/apis/v1/diary/create?id=${id}`, params);
console.log("res");
return { res }; // 성공적인 경우 데이터 반환
};

export const useSubmitDiary = () => {
const { toastOpen, toastClose, toastMessage } = useToast();
const navigate = useNavigate();
const { currentUser } = useCurrentUser();

const { mutate } = useMutation({
mutationFn: (params: ISubmitDiary) =>
submitDiary(currentUser.senderId, params),

onSuccess: ({ res }) => {
console.log("res", res);
toastOpen("일기 작성에 성공했습니다");
queryClient.clear();
setTimeout(() => {
navigate("/");
}, 1000);
},
onError: () => {
toastOpen("오류가 발생했습니다");
},
});
return { mutate, toastClose, toastMessage };
};
6 changes: 3 additions & 3 deletions src/hooks/api/main/useGetFriend.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { get } from "@/libs/api";
import { FriendList } from "@/types/friend";
import { FriendInfo } from "@/types/friend";
import { queryKeys } from "@/utils/constants";
import { useQuery } from "@tanstack/react-query";

const getFriendList = async (memberId: number) => {
const res = await get<{ data: FriendList }>(
const res = await get<{ data: FriendInfo[] }>(
`/apis/v1/friends/list?memberId=${memberId}`
);

return { res: res.data };
return { data: res.data };
};

export const useGetFriend = (memberId: number) => {
Expand Down
21 changes: 0 additions & 21 deletions src/hooks/api/mypage/useGetFriendAccept.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/hooks/api/request/useRequestFriend.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import useCurrentUser from "@/hooks/useAuth";
import { useToast } from "@/hooks/useToast";
import { post } from "@/libs/api";
import { queryClient } from "@/libs/queryClient";
import { FriendRequest } from "@/types/request";
import { useMutation } from "@tanstack/react-query";
import { useNavigate } from "react-router-dom";
Expand All @@ -23,6 +24,7 @@ export const useRequestFriend = () => {
onSuccess: ({ res }) => {
console.log("res", res);
toastOpen("친구 요청 성공했습니다");
queryClient.clear();
setTimeout(() => {
navigate("/");
}, 1000);
Expand Down
3 changes: 1 addition & 2 deletions src/libs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ const interceptorRequestFulfilled = (config: AxiosRequestConfig) => {
...config,
headers: {
"Content-Type": "application/json",
// Authorization: `Bearer ${TOKEN}`,
// Cookie: `token=${TOKEN}`,
Authorization: `${TOKEN}`,
} as AxiosRequestHeaders,
};
} else {
Expand Down
22 changes: 3 additions & 19 deletions src/pages/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import PasswrodIcon from "@/assets/svg/icon-auth-password.svg";
import PasswordShowIcon from "@/assets/svg/icon-auth-passwordShow.svg";
import Button from "@/components/common/Button";
import styled from "styled-components";
import { StyledDiv, StyledH1 } from "@/styles/common";

const Login = () => {
const location = useLocation();
Expand Down Expand Up @@ -43,15 +44,14 @@ const Login = () => {

return (
<>
<LoginDiv>
<StyledDiv>
<StyledH1>로그인</StyledH1>
<StyledInput
value={name}
placeholder="name"
onChangeValue={onChangeName}
leftIcon={NameIcon}
/>
<br />
<StyledInput
type={password.type}
value={password.value}
Expand All @@ -67,7 +67,6 @@ const Login = () => {
})),
}}
/>
<br />
<StyledButton
buttonColor="main"
buttonStyle="gradient"
Expand All @@ -89,23 +88,13 @@ const Login = () => {
<Toast isOpen={toastMessage.isOpen} onClose={toastClose}>
{toastMessage.message}
</Toast>
</LoginDiv>
</StyledDiv>
</>
);
};

export default Login;

export const LoginDiv = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100dvh;
gap: 10px;
`;

const StyledInput = styled(Input)`
padding: 10px;
margin: 10px;
Expand All @@ -115,11 +104,6 @@ const StyledButton = styled(Button)`
margin: 20px;
`;

const StyledH1 = styled.div`
padding: 100px;
font-size: 60pt;
`;

const P = styled.p`
cursor: pointer;
`;
Loading

0 comments on commit 00b43bb

Please sign in to comment.