Skip to content

Commit

Permalink
Merge pull request #17 from Repick-official/currentWardrobe
Browse files Browse the repository at this point in the history
[Feat] λ‚ μ§œ 검색 κ΅¬ν˜„ 및 sorttype 필터링
  • Loading branch information
oyatplum authored Nov 10, 2024
2 parents 100837c + 903a4c3 commit 1efe530
Show file tree
Hide file tree
Showing 9 changed files with 566 additions and 214 deletions.
86 changes: 86 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"classnames": "^2.5.1",
"next": "^14.2.5",
"react": "^18",
"react-datepicker": "^7.5.0",
"react-dom": "^18",
"react-dropzone": "^14.3.3",
"recharts": "^2.12.7",
Expand Down
34 changes: 22 additions & 12 deletions src/api/request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,30 @@ export const getUserInfo = async (clothingSalesId: number) => {
};
export const getClothingSalesStatus = async (
page: string,
size: string
// startDate: string,
// endDate: string
size: string,
type: string = "latest", // κΈ°λ³Έκ°’μœΌλ‘œ "latest" μ„€μ •
startDate?: string,
endDate?: string
) => {
try {
const response = await fetch(
process.env.API_URL + `/clothing-sales/status?page=${page}&size=${size}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
// URL에 λ™μ μœΌλ‘œ νŒŒλΌλ―Έν„° μΆ”κ°€
let url = `${process.env.API_URL}/clothing-sales/status?page=${page}&size=${size}&type=${type}`;

if (startDate) {
url += `&startDate=${encodeURIComponent(startDate)}`;
}

if (endDate) {
url += `&endDate=${encodeURIComponent(endDate)}`;
}

const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});

if (response.ok) {
const data = await response.json();
return data;
Expand Down
50 changes: 43 additions & 7 deletions src/app/wardrobe/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,40 @@ function Wardrobe() {
const [users, setUsers] = useState<any>(null);
const [page, setPage] = useState(0); // ν˜„μž¬ νŽ˜μ΄μ§€ μƒνƒœ
const size = 10; // νŽ˜μ΄μ§€λ‹Ή μ•„μ΄ν…œ 수
const [startDate, setStartDate] = useState<string | null>(null); // μ‹œμž‘ λ‚ μ§œ
const [endDate, setEndDate] = useState<string | null>(null); // μ’…λ£Œ λ‚ μ§œ
const [sortType, setSortType] = useState("latest"); // μ •λ ¬ κΈ°μ€€ μƒνƒœ

const fetchItem = async () => {
const userList = await getClothingSalesStatus(
String(page),
String(size),
sortType,
startDate || undefined,
endDate || undefined
);
setUsers(userList);
console.log("userlist", userList);
};

// 데이터 κ°€μ Έμ˜€κΈ° ν•¨μˆ˜
useEffect(() => {
const fetchItem = async () => {
const userList = await getClothingSalesStatus(String(page), String(size));
setUsers(userList);
};
fetchItem();
}, [page]);
}, [page, sortType, startDate, endDate]);

// λ‚ μ§œ 필터링 λ³€κ²½ ν•¨μˆ˜
const handleDateFilter = (dates: {
startDate: string | null;
endDate: string | null;
}) => {
setStartDate(dates.startDate);
setEndDate(dates.endDate);
};

// μ •λ ¬ κΈ°μ€€ λ³€κ²½ ν•¨μˆ˜
const handleSortChange = (sort: string) => {
setSortType(sort);
};

// νŽ˜μ΄μ§€ λ³€κ²½ ν•¨μˆ˜
const handlePageChange = (newPage: number) => {
Expand All @@ -31,8 +56,19 @@ function Wardrobe() {
<div>
<MainTitle mainTitleName="옷μž₯ 정리 ν˜„ν™©" />
<div>
<TopInfo total={users?.result.totalElements} />
<WardrobeContent users={users} />
<TopInfo
total={users?.result.totalElements}
onDateFilter={handleDateFilter}
onSortChange={handleSortChange}
currentSort={sortType}
/>
<WardrobeContent
users={users}
page={page}
size={size}
sortType={sortType}
onUpdate={fetchItem}
/>

{/* νŽ˜μ΄μ§€λ„€μ΄μ…˜ λ²„νŠΌ */}
<div className="pagination mt-16pxr flex justify-center space-x-2">
Expand Down
125 changes: 82 additions & 43 deletions src/components/wardrobe/TopInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,95 @@
import React from "react";
import React, { useState } from "react";
import DateDropdown from "./dropdown/DateDropdown";

export default function TopInfo({ total, onDateFilter, onSortChange }: any) {
const [selectedSort, setSelectedSort] = useState("μ΅œμ‹ μˆœ");
const [isSortDropdownVisible, setIsSortDropdownVisible] = useState(false);
const [isDateVisible, setIsDateVisible] = useState(false);

const handleSortSelection = (sort: string) => {
setSelectedSort(sort);
setIsSortDropdownVisible(false);
onSortChange(sort === "μ΅œμ‹ μˆœ" ? "latest" : "oldest");
};

export default function TopInfo({ total }: any) {
return (
<div className="flex items-center mt-39pxr w-1262pxr">
<div className="text-16pxr font-medium leading-24pxr">
<div className="flex">
전체 <div className="text-text-blue ml-5pxr">{total}</div>개
<div className="relative">
<div className="flex items-center mt-39pxr w-1262pxr">
<div className="text-16pxr font-medium leading-24pxr">
<div className="flex">
전체 <div className="text-text-blue ml-5pxr">{total}</div>개
</div>
</div>
</div>

<div className="flex items-center ml-auto">
<div className="w-208pxr h-36pxr rounded-8pxr border-1pxr border-solid border-box-color">
<div className="ml-174pxr mt-8pxr">
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
viewBox="0 0 20 20"
fill="none"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M14.168 1.66634C14.168 1.2061 13.7949 0.833008 13.3346 0.833008C12.8744 0.833008 12.5013 1.2061 12.5013 1.66634V2.49967H7.5013V1.66634C7.5013 1.2061 7.12821 0.833008 6.66797 0.833008C6.20773 0.833008 5.83464 1.2061 5.83464 1.66634V2.49967H4.16797C2.78726 2.49967 1.66797 3.61896 1.66797 4.99967V16.6663C1.66797 18.0471 2.78726 19.1663 4.16797 19.1663H15.8346C17.2153 19.1663 18.3346 18.0471 18.3346 16.6663V4.99967C18.3346 3.61896 17.2153 2.49967 15.8346 2.49967H14.168V1.66634ZM16.668 7.49967V4.99967C16.668 4.53944 16.2949 4.16634 15.8346 4.16634H14.168V4.99967C14.168 5.45991 13.7949 5.83301 13.3346 5.83301C12.8744 5.83301 12.5013 5.45991 12.5013 4.99967V4.16634H7.5013V4.99967C7.5013 5.45991 7.12821 5.83301 6.66797 5.83301C6.20773 5.83301 5.83464 5.45991 5.83464 4.99967V4.16634H4.16797C3.70773 4.16634 3.33464 4.53944 3.33464 4.99967V7.49967H16.668ZM3.33464 9.16634H16.668V16.6663C16.668 17.1266 16.2949 17.4997 15.8346 17.4997H4.16797C3.70773 17.4997 3.33464 17.1266 3.33464 16.6663V9.16634Z"
fill="#2D3648"
/>
</svg>
<div className="flex items-center ml-auto">
<div
className="w-208pxr h-36pxr rounded-8pxr border-1pxr border-solid border-box-color cursor-pointer"
onClick={() => setIsDateVisible(!isDateVisible)}
>
<div className="ml-174pxr mt-8pxr">
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
viewBox="0 0 20 20"
fill="none"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M14.168 1.66634C14.168 1.2061 13.7949 0.833008 13.3346 0.833008C12.8744 0.833008 12.5013 1.2061 12.5013 1.66634V2.49967H7.5013V1.66634C7.5013 1.2061 7.12821 0.833008 6.66797 0.833008C6.20773 0.833008 5.83464 1.2061 5.83464 1.66634V2.49967H4.16797C2.78726 2.49967 1.66797 3.61896 1.66797 4.99967V16.6663C1.66797 18.0471 2.78726 19.1663 4.16797 19.1663H15.8346C17.2153 19.1663 18.3346 18.0471 18.3346 16.6663V4.99967C18.3346 3.61896 17.2153 2.49967 15.8346 2.49967H14.168V1.66634ZM16.668 7.49967V4.99967C16.668 4.53944 16.2949 4.16634 15.8346 4.16634H14.168V4.99967C14.168 5.45991 13.7949 5.83301 13.3346 5.83301C12.8744 5.83301 12.5013 5.45991 12.5013 4.99967V4.16634H7.5013V4.99967C7.5013 5.45991 7.12821 5.83301 6.66797 5.83301C6.20773 5.83301 5.83464 5.45991 5.83464 4.99967V4.16634H4.16797C3.70773 4.16634 3.33464 4.53944 3.33464 4.99967V7.49967H16.668ZM3.33464 9.16634H16.668V16.6663C16.668 17.1266 16.2949 17.4997 15.8346 17.4997H4.16797C3.70773 17.4997 3.33464 17.1266 3.33464 16.6663V9.16634Z"
fill="#2D3648"
/>
</svg>
</div>
</div>
</div>

<div className="rounded-8pxr bg-nav-color h-36pxr px-12pxr py-10pxr text-background-color text-12pxr leading-18pxr font-medium ml-8pxr">
검색
</div>
<div className="rounded-8pxr bg-nav-color h-36pxr px-12pxr py-10pxr text-background-color text-12pxr leading-18pxr font-medium ml-8pxr">
검색
</div>

<div className=" rounded-5pxr border-1pxr border-solid border-dark-gray py-8pxr px-12pxr flex items-center ml-17pxr">
μ΅œμ‹ μˆœ
<div className="ml-40pxr">
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
viewBox="0 0 20 20"
fill="none"
>
<path
d="M5.59056 6.91107C5.26512 6.58563 4.73748 6.58563 4.41205 6.91107C4.08661 7.23651 4.08661 7.76414 4.41205 8.08958L9.41205 13.0896C9.73748 13.415 10.2651 13.415 10.5906 13.0896L15.5906 8.08958C15.916 7.76414 15.916 7.23651 15.5906 6.91107C15.2651 6.58563 14.7375 6.58563 14.412 6.91107L10.0013 11.3218L5.59056 6.91107Z"
fill="#1D2939"
/>
</svg>
<div
onClick={() => setIsSortDropdownVisible(!isSortDropdownVisible)}
className="rounded-5pxr border-1pxr border-solid border-dark-gray py-8pxr px-12pxr flex items-center ml-17pxr cursor-pointer"
>
{selectedSort}
<div className="ml-40pxr">
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
viewBox="0 0 20 20"
fill="none"
>
<path
d="M5.59056 6.91107C5.26512 6.58563 4.73748 6.58563 4.41205 6.91107C4.08661 7.23651 4.08661 7.76414 4.41205 8.08958L9.41205 13.0896C9.73748 13.415 10.2651 13.415 10.5906 13.0896L15.5906 8.08958C15.916 7.76414 15.916 7.23651 15.5906 6.91107C15.2651 6.58563 14.7375 6.58563 14.412 6.91107L10.0013 11.3218L5.59056 6.91107Z"
fill="#1D2939"
/>
</svg>
</div>
</div>
</div>
</div>
{isDateVisible && (
<div className="absolute">
<DateDropdown onDateFilter={onDateFilter} />
</div>
)}
{isSortDropdownVisible && (
<div className="absoulte ml-1140pxr mt-16pxr">
<div className="absolute w-152pxr h-76pxr rounded-10pxr text-13pxr border-1pxr border-solid bg-white font-medium">
{["μ΅œμ‹ μˆœ", "였래된 순"].map((sort) => (
<div
key={sort}
onClick={() => handleSortSelection(sort)}
className="h-36pxr hover:bg-circle-gray pt-9pxr pl-17pxr cursor-pointer"
>
{sort}
</div>
))}
</div>
</div>
)}
</div>
);
}
Loading

0 comments on commit 1efe530

Please sign in to comment.