From 8ec5c6083be603ca32ec1ae878fdbb8600bbcd35 Mon Sep 17 00:00:00 2001 From: rudtj Date: Tue, 19 Nov 2024 20:33:53 +0900 Subject: [PATCH 1/5] refactor --- src/components/features/MyPage/Category.tsx | 2 +- src/pages/MyPage/ProductWishlistPage.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/features/MyPage/Category.tsx b/src/components/features/MyPage/Category.tsx index e34c8bf..ed49546 100644 --- a/src/components/features/MyPage/Category.tsx +++ b/src/components/features/MyPage/Category.tsx @@ -13,7 +13,7 @@ const Category = () => ( ( - + ); From c689457b203ea3bf0ca177173ceab6553999a559 Mon Sep 17 00:00:00 2001 From: rudtj Date: Tue, 19 Nov 2024 21:46:53 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=EA=B8=80=EC=9E=90=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/features/StorePage/StoreBanner.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/features/StorePage/StoreBanner.tsx b/src/components/features/StorePage/StoreBanner.tsx index 22c9f44..d0a64df 100644 --- a/src/components/features/StorePage/StoreBanner.tsx +++ b/src/components/features/StorePage/StoreBanner.tsx @@ -8,7 +8,7 @@ const StoreBanner = () => ( - 믿고 먹는 건간한 먹거리,{" "} + 믿고 먹는 건강한 먹거리,{" "} 품앗이 {" "} From 71f34525c224a3d527f135d4033771c50d5249ba Mon Sep 17 00:00:00 2001 From: rudtj Date: Tue, 19 Nov 2024 21:51:17 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/emailApi.ts | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/api/emailApi.ts b/src/api/emailApi.ts index b633852..71ba09f 100644 --- a/src/api/emailApi.ts +++ b/src/api/emailApi.ts @@ -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; @@ -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 }); }; @@ -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) => @@ -82,4 +106,12 @@ const useDeleteAccount = () => { }); }; -export { useCreateEmail, useLoginEmail, useUpdateEmail, useUpdateAddress, useCreateFarmer, useDeleteAccount }; +export { + useCreateEmail, + useLoginEmail, + useUpdateEmail, + useUpdateAddress, + useCreateFarmer, + useUpdateFarmer, + useDeleteAccount, +}; From ba3f938fdbc024ad636f15ca17872b75e9959594 Mon Sep 17 00:00:00 2001 From: rudtj Date: Tue, 19 Nov 2024 21:52:14 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20api=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/productApi.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/productApi.ts b/src/api/productApi.ts index 49b315a..3e91d80 100644 --- a/src/api/productApi.ts +++ b/src/api/productApi.ts @@ -20,7 +20,7 @@ type ProductData = { }; const useGetProducts = () => { - const fetcher = () => defaultApi.get(`/products`).then(({ data }) => data); + const fetcher = () => defaultApi.get(`/api/products`).then(({ data }) => data); return useQuery({ queryKey: ["products"], @@ -29,7 +29,7 @@ const useGetProducts = () => { }; const useGetProductDetail = (productId: number) => { - const fetcher = () => defaultApi.get(`/products/${productId}`).then(({ data }) => data); + const fetcher = () => defaultApi.get(`/api/products/${productId}`).then(({ data }) => data); return useQuery({ queryKey: ["products", productId], queryFn: fetcher, @@ -38,7 +38,7 @@ const useGetProductDetail = (productId: number) => { }; const useCreateProducts = () => { - const fetcher = (productData: ProductData) => defaultApi.post(`/products`, productData).then(({ data }) => data); + const fetcher = (productData: ProductData) => defaultApi.post(`/api/products`, productData).then(({ data }) => data); return useMutation({ mutationFn: fetcher }); }; @@ -47,7 +47,7 @@ const useUpdateProducts = (productId: number) => { const queryClient = useQueryClient(); const fetcher = (productData: ProductData) => - defaultApi.put(`/products/${productId}`, productData).then(({ data }) => data); + defaultApi.put(`/api/products/${productId}`, productData).then(({ data }) => data); return useMutation({ mutationFn: fetcher, From 8c22d65256cfa919682d19177c4b0373193e4cb2 Mon Sep 17 00:00:00 2001 From: rudtj Date: Wed, 20 Nov 2024 00:07:53 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20farm=20list=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/MyPage/Order/FarmList.tsx | 12 ++++---- src/mocks/mockItem/mockFarms.ts | 14 +++++++++ src/pages/MyPage/FarmListPage.tsx | 30 ++++++++++++------- src/types/index.ts | 2 ++ 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/components/features/MyPage/Order/FarmList.tsx b/src/components/features/MyPage/Order/FarmList.tsx index 55a57d5..77f4fd5 100644 --- a/src/components/features/MyPage/Order/FarmList.tsx +++ b/src/components/features/MyPage/Order/FarmList.tsx @@ -2,10 +2,11 @@ import { useState } from "react"; import { Flex, Button, Text } from "@chakra-ui/react"; import farm1 from "@assets/Image/Farm/Farm1.png"; import Image from "@components/common/Image"; +import { Farm } from "@type/index"; import ContactNumberModal from "./ContactNumberModal"; import ReviewModal from "./ReviewModal"; -const FarmList = () => { +const FarmList = ({ item }: { item: Farm }) => { const [isReviewModalOpen, setIsReviewModalOpen] = useState(false); const [isContactModalOpen, setIsContactModalOpen] = useState(false); @@ -27,11 +28,8 @@ const FarmList = () => { return ( - - 2024.09.14 - - 지민이네 복숭아 농장 + {item.name} Farm image @@ -41,7 +39,7 @@ const FarmList = () => { 주소 :  - 부산대학교 금정구 중앙대로 1616 + {item.address} @@ -49,7 +47,7 @@ const FarmList = () => { 한 줄 소개 - 가끔 지민은 학교에서 심각하게 집에 가고싶을 때마다 달달한 복숭아 아이스티를 마시며 향수병을 달랩니다. + {item.description} diff --git a/src/mocks/mockItem/mockFarms.ts b/src/mocks/mockItem/mockFarms.ts index b725c57..ba0df62 100644 --- a/src/mocks/mockItem/mockFarms.ts +++ b/src/mocks/mockItem/mockFarms.ts @@ -5,26 +5,40 @@ const mockFarms: Farm[] = [ id: 1, name: "건호 농장", address: "부산진구 개금동", + description: + "가끔 지민은 학교에서 심각하게 집에 가고싶을 때마다 달달한 복숭아 아이스티를 마시며 향수병을 달랩니다.", + date: "2024.09.14", }, { id: 2, name: "토마토 농장", address: "부산 장전동", + description: + "가끔 지민은 학교에서 심각하게 집에 가고싶을 때마다 달달한 복숭아 아이스티를 마시며 향수병을 달랩니다.", + date: "2024.10.14", }, { id: 3, name: "지민 농장", address: "경남 양산시 덕게동", + description: + "가끔 지민은 학교에서 심각하게 집에 가고싶을 때마다 달달한 복숭아 아이스티를 마시며 향수병을 달랩니다.", + date: "2024.09.24", }, { id: 4, name: "할로윈 농장", address: "청담 에이프릴 영어학원", + description: + "가끔 지민은 학교에서 심각하게 집에 가고싶을 때마다 달달한 복숭아 아이스티를 마시며 향수병을 달랩니다.", + date: "2024.09.12", }, { id: 5, name: "가지싫어 농장", address: "부산 해운대구 반송동", + description: "가끔 지민은 학교에서 심각하게 집에 가고싶을 때마다 가지를 먹으며 향수병을 달랩니다.", + date: "2024.09.04", }, ]; diff --git a/src/pages/MyPage/FarmListPage.tsx b/src/pages/MyPage/FarmListPage.tsx index e89e018..35d75ae 100644 --- a/src/pages/MyPage/FarmListPage.tsx +++ b/src/pages/MyPage/FarmListPage.tsx @@ -1,22 +1,32 @@ -import farm6 from "@assets/Image/Farm/Farm6.png"; +import { Flex, Text } from "@chakra-ui/react"; import ListView from "@components/ItemView/ListView"; import Card from "@components/common/Card"; import FarmList from "@components/features/MyPage/Order/FarmList"; import mockFarms from "@mocks/mockItem/mockFarms"; import { Farm } from "@type/index"; -const farmListData: Farm[] = mockFarms.map((farm, index) => ({ - id: farm.id, - date: `2024.09.${index + 14}`, - name: farm.name, - address: farm.address, - description: "기본 설명입니다.", - profile: farm6, -})); +const sortedFarms = mockFarms.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); + +const groupedFarms = sortedFarms.reduce((acc, cur) => { + const last = acc[acc.length - 1]; + if (!last || last[0].date !== cur.date) { + acc.push([cur]); + } else { + last.push(cur); + } + return acc; +}, []); const FarmListPage = () => ( - + {groupedFarms.map(farms => ( + + + {farms[0].date} + + + + ))} ); diff --git a/src/types/index.ts b/src/types/index.ts index d810f3d..ca29c5f 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,6 +6,8 @@ export type Farm = Item & { name: string; address: string; profile?: string; + description: string; + date: string; }; export type Product = Item & {