Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/주는 사람 Intro API 연결 #100

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function App() {
<Route path="/" element={<Intro />} />
<Route path="/target/:targetId" element={<Intro />} />
<Route path="/gift/:targetId" element={<Gift />} />
<Route path="/card" element={<Card />} />
<Route path="/card/:targetId" element={<Card />} />
<Route path="/result/:targetId" element={<ProviderResult />} />
<Route path="/confirm/:targetId" element={<Confirm />} />
<Route path="/target/:targetId/gift" element={<GiftForConsumer />} />
Expand Down
2 changes: 2 additions & 0 deletions src/api/consumer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import axios from "axios";
import { GetCardInfo, GetTargetInfo } from "types/remote";

// 타겟 조회
export const getCardInfo = async (targetId: number): Promise<GetCardInfo> => {
const response = await axios.get(
`${process.env.REACT_APP_BASE_URL}/target/${targetId}`,
);
return response.data;
};

// 타겟 최종 결정된 선물 조회
export const getTargetInfo = async (
targetId: number,
): Promise<GetTargetInfo> => {
Expand Down
16 changes: 16 additions & 0 deletions src/api/provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from "axios";
import { PostTarget } from "types/remote";

// 선물 조회
export const getGiftList = async (targetId: number) => {
Expand Down Expand Up @@ -33,3 +34,18 @@ export const putGiftItem = async (formData: FormData) => {
},
);
};

// 타겟 생성
export const postTarget = async ({
consumerName,
providerName,
}: PostTarget) => {
const response = await axios.post(
`${process.env.REACT_APP_BASE_URL}/target`,
{
consumerName,
providerName,
},
);
return response.data;
};
2 changes: 1 addition & 1 deletion src/components/consumer/ConsumerIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function ConsumerIntro() {
/>
</ImageWrapper>
<TextWrapper>
<Text contents={data?.cardMeesage ?? "취업 축하해 타몽~!"} />
<Text contents={data?.cardMessage ?? "취업 축하해 타몽~!"} />
</TextWrapper>
</CardWrapper>
<TextWrapper>
Expand Down
5 changes: 3 additions & 2 deletions src/components/provider/ProviderCard.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { useNavigate } from "react-router-dom";
import { useNavigate, useParams } from "react-router-dom";
import { useRecoilValue } from "recoil";
import styled from "styled-components";
import Icon from "components/common/Icon";
import { imgUrlSelector } from "stores/cardAtom";

function ProviderCard() {
const navigate = useNavigate();
const { targetId } = useParams();
const imgUrl = useRecoilValue(imgUrlSelector);

const handleNextToPage = () => {
navigate("/card");
navigate(`/card/${targetId}`);
};
return (
<CardWrapper>
Expand Down
12 changes: 10 additions & 2 deletions src/components/provider/ProviderIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Button from "components/common/Button";
import Icon from "components/common/Icon";
import Input from "components/common/Input";
import Text from "components/common/Text";
import usePostTarget from "hooks/queries/usePostTarget";
import useInputFormValidation from "hooks/useInputValidation";
import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
Expand All @@ -12,6 +13,7 @@ function ProviderIntro() {
const navigate = useNavigate();
const [form, errors, handleFormChange] = useInputFormValidation();
const [showContent, setShowContent] = useState(false);
const { mutate } = usePostTarget();

useEffect(() => {
const timer = setTimeout(() => {
Expand All @@ -22,14 +24,20 @@ function ProviderIntro() {
}, []);

const handleClick = () => {
if (!form.providerName || !form.consumerName) {
const { providerName, consumerName } = form;
if (!providerName || !consumerName) {
handleFormChange({
...form,
type: "all",
});
return;
}
navigate("/gift");
mutate(
{ consumerName, providerName },
{
onSuccess: data => navigate(`/gift/${data}`),
},
);
};

return (
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/queries/usePostTarget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { postTarget } from "api/provider";
import { useMutation } from "react-query";

export const usePostTarget = () => {
return useMutation(postTarget);
};

export default usePostTarget;
7 changes: 4 additions & 3 deletions src/pages/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, ChangeEvent } from "react";
import { useNavigate } from "react-router-dom";
import { useNavigate, useParams } from "react-router-dom";
import COLOR from "style/color";
import styled from "styled-components";
import Button from "components/common/Button";
Expand All @@ -12,6 +12,7 @@ import CardBasic from "components/provider/CardBasic";

function Card() {
const navigate = useNavigate();
const { targetId } = useParams();
const [toggleType, setToggleType] = useState<"basic" | "custom">("basic");
const [cardTxt, setCardTxt] = useState("");
const [imageURL, setImageURL] = useState<string | null>("");
Expand Down Expand Up @@ -45,11 +46,11 @@ function Card() {
};

const handleCancel = () => {
navigate("/gift");
navigate(`/gift/${targetId}`);
};

const handleSuccess = () => {
navigate("/gift");
navigate(`/gift/${targetId}`);
};

return (
Expand Down
7 changes: 6 additions & 1 deletion src/types/remote.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type GetCardInfo = {
providerName: string;
cardImageUrl: string;
cardMeesage: string;
cardMessage: string;
};

export type GetTargetInfo = {
Expand All @@ -11,3 +11,8 @@ export type GetTargetInfo = {
giftImageUrl: string;
};
};

export type PostTarget = {
providerName: string;
consumerName: string;
};