-
Notifications
You must be signed in to change notification settings - Fork 4
[feat] 내 프로필 페이지 구현 (/profile) #52
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
829f163
feat: ProfilePage 페이지 컴포넌트 구현
cozy-ito e2de7fd
Merge branch 'dev' of https://github.com/CodeitPart3/thejulge into PR…
cozy-ito e35c079
refactor: MainLayout props 임시 수정
cozy-ito 06b4b98
feat: 레이아웃 스타일 변경 및 ProfilePage 로직 추가
cozy-ito c758e8a
feat: hook 추가, loader 추가
cozy-ito 2ec6e77
feat: UseApplicationTableSkeleton 컴포넌트 구현, tailwind 스켈레톤 애니메이션 유틸리티 구현
cozy-ito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,77 @@ | ||
| import { useLoaderData, useNavigate } from "react-router-dom"; | ||
|
|
||
| import ProfileCard from "./components/ProfileCard"; | ||
| import UserApplicationTable from "./components/UserApplicationTable"; | ||
| import UserApplicationTableSkeleton from "./components/UserApplicationTableSkeleton"; | ||
| import useUserApplications from "./hooks/useUserApplications"; | ||
|
|
||
| import EmptyStateCard from "@/components/EmptyStateCard"; | ||
| import { ROUTES } from "@/constants/router"; | ||
| import { UserApplicationList } from "@/types/application"; | ||
| import { UserItem } from "@/types/user"; | ||
|
|
||
| const LIMIT = 5; | ||
| const PAGE_LIMIT = 7; | ||
|
|
||
| export default function ProfilePage() { | ||
| return <div>ProfilePage</div>; | ||
| const { userInfo } = useLoaderData<{ | ||
| userInfo: UserItem; | ||
| count: number; | ||
| userApplications: UserApplicationList[]; | ||
| }>(); | ||
| const navigate = useNavigate(); | ||
| const { isLoading, totalCount, userApplications } = useUserApplications(); | ||
|
|
||
| return ( | ||
| <> | ||
| <section> | ||
| <div className="xl:w-[60.25rem] mx-auto px-6 py-[3.75rem]"> | ||
| <div className="flex lg:flex-row flex-col lg:gap-[11.25rem] gap-6 w-full mb-6"> | ||
| <h2 className="text-[1.75rem] font-bold">내 프로필</h2> | ||
| {userInfo && ( | ||
| <ProfileCard | ||
| {...userInfo} | ||
| className="flex-1" | ||
| onClick={() => navigate(ROUTES.PROFILE.EDIT)} | ||
| /> | ||
| )} | ||
| </div> | ||
| {!userInfo && ( | ||
| <EmptyStateCard | ||
| description="내 프로필을 등록하고 원하는 가게에 지원해 보세요" | ||
| buttonName="내 프로필 등록하기" | ||
| onClick={() => navigate(ROUTES.PROFILE.REGISTER)} | ||
| /> | ||
| )} | ||
| </div> | ||
| </section> | ||
|
|
||
| {userInfo && ( | ||
| <section className="flex-1 bg-gray-5"> | ||
| <div className="xl:w-[60.25rem] mx-auto px-6 pt-[3.75rem]"> | ||
| <h3 className="mb-8 text-[1.75rem] font-bold">신청 내역</h3> | ||
|
|
||
| {isLoading && <UserApplicationTableSkeleton />} | ||
|
|
||
| {!isLoading && userApplications.length === 0 && ( | ||
| <EmptyStateCard | ||
| description="아직 신청 내역이 없어요" | ||
| buttonName="공고 보러 가기" | ||
| onClick={() => navigate(ROUTES.NOTICE.ROOT)} | ||
| /> | ||
| )} | ||
|
|
||
| {!isLoading && userApplications.length > 0 && ( | ||
| <UserApplicationTable | ||
| data={userApplications} | ||
| pageCount={totalCount} | ||
| itemCountPerPage={LIMIT} | ||
| pageLimit={PAGE_LIMIT} | ||
| /> | ||
| )} | ||
| </div> | ||
| </section> | ||
| )} | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/pages/ProfilePage/components/UserApplicationTableSkeleton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| function UserApplicationTableSkeleton() { | ||
| return ( | ||
| <div className="w-full"> | ||
| <div className="md:h-[3.125rem] h-[2.5rem] mb-3 animate-skeleton rounded-lg" /> | ||
| <div className="md:h-[24.875rem] h-[19.625rem] w-full animate-skeleton rounded-lg" /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default UserApplicationTableSkeleton; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| import { useSearchParams } from "react-router-dom"; | ||
|
|
||
| import { getUserApplications } from "@/apis/services/applicationService"; | ||
| import { UserApplicationList } from "@/types/application"; | ||
|
|
||
| interface UseUserApplicationsParams { | ||
| offset?: number; | ||
| limit?: number; | ||
| } | ||
|
|
||
| const useUserApplications = (params?: UseUserApplicationsParams) => { | ||
| const { offset = 5, limit = 7 } = params ?? {}; | ||
|
|
||
| const [searchParams] = useSearchParams(); | ||
| const [isLoading, setIsLoading] = useState(false); | ||
| const [totalCount, setTotalCount] = useState<number>(0); | ||
| const [userApplications, setUserApplications] = useState< | ||
| UserApplicationList[] | ||
| >([]); | ||
| const page = Number(searchParams.get("page")) || 1; | ||
|
|
||
| const fetchUserApplication = async () => { | ||
| setIsLoading(true); | ||
| const userApplications = await getUserApplications( | ||
| "42859259-b879-408c-8edd-bbaa3a79c674", | ||
| (page - 1) * offset, | ||
| limit, | ||
| ); | ||
|
|
||
| const nextUserApplications = userApplications.data.items.map( | ||
| ({ item }) => item, | ||
| ); | ||
|
|
||
| setTotalCount(userApplications.data.count); | ||
| setUserApplications(nextUserApplications); | ||
| setIsLoading(false); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| fetchUserApplication(); | ||
| }, [page]); | ||
|
|
||
| return { userApplications, isLoading, totalCount }; | ||
| }; | ||
|
|
||
| export default useUserApplications; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { getUser } from "@/apis/services/userService"; | ||
|
|
||
| const profileLoader = async () => { | ||
| const userInfo = await getUser("42859259-b879-408c-8edd-bbaa3a79c674"); | ||
|
|
||
| if (userInfo.status === 200) { | ||
| return { | ||
| userInfo: userInfo.data.item, | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| export default profileLoader; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MainLayout에서는isLoggedIn을 필수화하는 게 안전한 방식이라고 생각했는데 옵셔널로 바꾸신 이유가 궁금합니다 🧐Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 optional로 변경을 한 것은 임시로 변경한 것입니다
optional로 변경하지 않으면,
Router.tsx에서 타입 에러가 발생해서요 😅나중에 로그인 상태는 결국 전역상태로 관리될 수 밖에 없다고 생각해서
MainLayoutprops들은 결국 없어질 것이라 예상합니다.