Skip to content

Commit

Permalink
Merge pull request #153 from kakao-tech-campus-2nd-step3/feature/foot…
Browse files Browse the repository at this point in the history
…er_리펙토링-#146

Feature/footer 리펙토링 #146
  • Loading branch information
jasper200207 authored Nov 19, 2024
2 parents dc74966 + edff05d commit a90709f
Show file tree
Hide file tree
Showing 53 changed files with 1,112 additions and 513 deletions.
4 changes: 2 additions & 2 deletions src/api/axiosInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const needAuthDefaultApi = axios.create({
baseURL: process.env.REACT_APP_API_URL,
headers: {
"Content-Type": "application/json",
Authorization: JSON.parse(localStorage.getItem("poomasi_user") || "{}")?.token
? `Bearer ${JSON.parse(localStorage.getItem("poomasi_user") || "{}").token}`
Authorization: JSON.parse(localStorage.getItem("poomasi-user") || "{}")?.token
? `Bearer ${JSON.parse(localStorage.getItem("poomasi-user") || "{}").token}`
: undefined,
},
withCredentials: true,
Expand Down
4 changes: 2 additions & 2 deletions src/api/businessApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ const useCreateBusiness = () => {
return useMutation({ mutationFn: fetcher });
};

const useGetBusinessDetail = () => null;
const useGetBusiness = () => null;

export { useCreateBusiness, useGetBusinessDetail };
export { useCreateBusiness, useGetBusiness };
38 changes: 35 additions & 3 deletions src/api/emailApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ type LoginData = {
password: string;
};

type FarmerData = {
type FarmerRegisterData = {
name: string;
address: string;
phone: string;
};

type FarmerData = {
name: string;
email: string;
password: string;
phoneNumber: string;
storeName: string;
storeAddress: string;
};

type AddressData = {
defaultAddress: string;
addressDetail: string;
Expand All @@ -39,7 +49,7 @@ const useLoginEmail = () => {
};

const useCreateFarmer = () => {
const fetcher = (farmerData: FarmerData) =>
const fetcher = (farmerData: FarmerRegisterData) =>
needAuthDefaultApi.put(`/api/members/to-farmer`, farmerData).then(({ data }) => data);
return useMutation({ mutationFn: fetcher });
};
Expand All @@ -58,6 +68,20 @@ const useUpdateEmail = () => {
});
};

const useUpdateFarmer = () => {
const queryClient = useQueryClient();
const fetcher = (updateData: FarmerData) =>
needAuthDefaultApi.put(`/api/members/update/farmer`, updateData).then(({ data }) => data);

return useMutation({
mutationFn: fetcher,
onSuccess: () =>
queryClient.invalidateQueries({
queryKey: ["farmer"],
}),
});
};

const useUpdateAddress = () => {
const queryClient = useQueryClient();
const fetcher = (updateData: AddressData) =>
Expand All @@ -82,4 +106,12 @@ const useDeleteAccount = () => {
});
};

export { useCreateEmail, useLoginEmail, useUpdateEmail, useUpdateAddress, useCreateFarmer, useDeleteAccount };
export {
useCreateEmail,
useLoginEmail,
useUpdateEmail,
useUpdateAddress,
useCreateFarmer,
useUpdateFarmer,
useDeleteAccount,
};
58 changes: 56 additions & 2 deletions src/api/farmApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ type FarmData = {
endTime: string;
};

type ReservationData = {
farmId: number;
startTime: string;
endTime: string;
date: ["startDate", "endDate"];
};

const useGetFarm = () => {
const fetcher = () => defaultApi.get(`/api/farms/{farmId}/detail`).then(({ data }) => data);

return useQuery({
queryKey: ["farms"],
queryFn: fetcher,
});
};

const useGetFarms = () => {
const fetcher = () => defaultApi.get(`/api/farms`).then(({ data }) => data);

Expand All @@ -37,7 +53,7 @@ const useGetFarmDetail = (farmId: number) => {
};

const useCreateFarms = () => {
const fetcher = (farmData: FarmData) => defaultApi.post(`/api/farms`, farmData).then(({ data }) => data);
const fetcher = (farmData: FarmData) => defaultApi.post(`/api/farmer/farms`, farmData).then(({ data }) => data);

return useMutation({ mutationFn: fetcher });
};
Expand All @@ -57,4 +73,42 @@ const useUpdateFarms = (farmId: number) => {
});
};

export { useGetFarms, useGetFarmDetail, useCreateFarms, useUpdateFarms };
const useDeleteFarms = (farmId: number) => {
const queryClient = useQueryClient();

const fetcher = () => defaultApi.delete(`/api/farmer/farms/${farmId}`).then(({ data }) => data);

return useMutation({
mutationFn: fetcher,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["farms"] });
},
});
};

const useCreateReservations = () => {
const fetcher = (reservationData: ReservationData) =>
defaultApi.post(`/api/farms/schedule`, reservationData).then(({ data }) => data);

return useMutation({ mutationFn: fetcher });
};

const useGetReservations = (farmId: number) => {
const fetcher = () => defaultApi.get(`/api/farms/schedule?farmId=17&year=2024&month=10`).then(({ data }) => data);

return useQuery({
queryKey: ["reservations", farmId],
queryFn: fetcher,
});
};

export {
useGetFarm,
useGetFarms,
useGetFarmDetail,
useCreateFarms,
useUpdateFarms,
useDeleteFarms,
useCreateReservations,
useGetReservations,
};
4 changes: 2 additions & 2 deletions src/api/intercepters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const refrechIntercepter = async (response: AxiosResponse): Promise<AxiosRespons
alert("로그아웃 되었습니다. 다시 로그인해주세요.");
window.location.href = "/";
});
const user = JSON.parse(localStorage.getItem("poomasi_user") || "{}");
const user = JSON.parse(localStorage.getItem("poomasi-user") || "{}");

localStorage.setItem(
"poomasi_user",
"poomasi-user",
JSON.stringify({
...user,
token: result,
Expand Down
8 changes: 7 additions & 1 deletion src/api/productApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ type ProductData = {
categoryId: number;
name: string;
description: string;
imageUrl: string;
stock: string;
price: string;
growEnv: string;
shippingFee: string;
phoneNumber: string;
mainTitle: string;
subTitle1: string;
subDesc1: string;
subTitle2: string;
subDesc2: string;
subTitle3: string;
subDesc3: string;
};

const useGetProducts = () => {
Expand Down
80 changes: 80 additions & 0 deletions src/api/reviewApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { defaultApi } from "@api/axiosInstance";

type ReviewData = {
rating: number;
content: string;
product_id?: number;
farm_id?: number;
};

const useGetProductReviews = (reviewId: number) => {
const fetcher = () => defaultApi.get(`/api/products/{product_id}/reviews`).then(({ data }) => data);

return useQuery({
queryKey: ["reviews", reviewId],
queryFn: fetcher,
});
};

const useCreateProductReviews = () => {
const fetcher = (reviewData: ReviewData) =>
defaultApi.post(`/api/products/{product_id}/reviews`, reviewData).then(({ data }) => data);

return useMutation({ mutationFn: fetcher });
};

const useUpdateReviews = (reviewId: number) => {
const queryClient = useQueryClient();

const fetcher = (reviewData: ReviewData) =>
defaultApi.put(`/api/reviews/{review_id}`, reviewData).then(({ data }) => data);

return useMutation({
mutationFn: fetcher,
onSuccess: () =>
queryClient.invalidateQueries({
queryKey: ["reviews", reviewId],
}),
});
};

const useDeleteReviews = (reviewId: number) => {
const queryClient = useQueryClient();

const fetcher = () => defaultApi.delete(`/api/reviews/${reviewId}`).then(({ data }) => data);

return useMutation({
mutationFn: fetcher,
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ["reviews", reviewId],
});
},
});
};

const useGetFarmReviews = (reviewId: number) => {
const fetcher = () => defaultApi.get(`/api/farms/{farm_id}/reviews`).then(({ data }) => data);

return useQuery({
queryKey: ["reviews", reviewId],
queryFn: fetcher,
});
};

const useCreateFarmReviews = () => {
const fetcher = (reviewData: ReviewData) =>
defaultApi.post(`/api/farms/{reservationId}/reviews`, reviewData).then(({ data }) => data);

return useMutation({ mutationFn: fetcher });
};

export {
useGetProductReviews,
useCreateProductReviews,
useUpdateReviews,
useDeleteReviews,
useGetFarmReviews,
useCreateFarmReviews,
};
30 changes: 30 additions & 0 deletions src/api/storeApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { defaultApi } from "@api/axiosInstance";

type StoreData = {
name: string;
address: string;
phone: number;
};

const useCreateStore = () => {
const fetcher = (storeData: StoreData) => defaultApi.post(`/api/stores`, storeData).then(({ data }) => data);

return useMutation({ mutationFn: fetcher });
};

const useUpdateStore = () => {
const queryClient = useQueryClient();

const fetcher = (storeData: StoreData) => defaultApi.put(`/api/stores`, storeData).then(({ data }) => data);

return useMutation({
mutationFn: fetcher,
onSuccess: () =>
queryClient.invalidateQueries({
queryKey: ["store"],
}),
});
};

export { useCreateStore, useUpdateStore };
30 changes: 30 additions & 0 deletions src/api/wishlistApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useQuery, useMutation } from "@tanstack/react-query";
import { defaultApi, needAuthDefaultApi } from "@api/axiosInstance";

type WishlistData = {
product_id: number;
};

const useCreateWishlists = () => {
const fetcher = (wishlistData: WishlistData) =>
defaultApi.post(`/api/v1/wishlist/{product_id}`, wishlistData).then(({ data }) => data);

return useMutation({ mutationFn: fetcher });
};

const useGetWishlists = (type: "product" | "farm") => {
const fetcher = () => needAuthDefaultApi.get(`/api/v1/wishlist`, { params: { type } }).then(({ data }) => data);

return useQuery({
queryKey: ["wishlists"],
queryFn: fetcher,
});
};

const useDeleteWishlists = () => {
const fetcher = (wishlistId: number) => defaultApi.delete(`/api/v1/wishlist/${wishlistId}`).then(({ data }) => data);

return useMutation({ mutationFn: fetcher });
};

export { useCreateWishlists, useGetWishlists, useDeleteWishlists };
4 changes: 2 additions & 2 deletions src/atoms/userAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type UserAtomValue = {
role: string;
};

const userAtom = atom(localStorage.getItem("poomasi_user") ?? "");
const userAtom = atom(localStorage.getItem("poomasi-user") ?? "");

const userAtomWithPersistence = atom(
get => {
Expand All @@ -16,7 +16,7 @@ const userAtomWithPersistence = atom(
},
(_, set, data: UserAtomValue | null) => {
set(userAtom, JSON.stringify(data));
localStorage.setItem("poomasi_user", JSON.stringify(data));
localStorage.setItem("poomasi-user", JSON.stringify(data));
},
);

Expand Down
2 changes: 1 addition & 1 deletion src/components/common/KaKaoLoginButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Image from "@components/common/Image";
type KaKaoLoginButtonProps = ImageProps;

const KaKaoLoginButton = ({ ...props }: KaKaoLoginButtonProps) => {
const link = "https://api.poomasi.shop/oauth2/authentication/kakao";
const link = `${process.env.REACT_APP_API_URL}/oauth2/authentication/kakao`;

return (
<Link href={link} isExternal>
Expand Down
Loading

0 comments on commit a90709f

Please sign in to comment.