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

feat: 프로필 내 모임추가 #1286

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
53 changes: 53 additions & 0 deletions src/api/endpoint/meetings/getMeetings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import axios from 'axios';
import { z } from 'zod';

// FIXME: 1/28 데모데이 due date가 얼마 남지 않은 이슈로 크루 api와 바로 통신했습니다.
// 플그 서버와 통신하도록 수정 + zod, createEndPoint 사용하도록 변경 필요합니다. 담당자: FE 서지수, BE 이승헌
// 무한스크롤 적용해야합니다.

const MeetingSchema = z.object({
id: z.number(),
isMeetingLeader: z.boolean(),
title: z.string(),
imageUrl: z.string(),
category: z.string(),
isActiveMeeting: z.boolean(),
mstartDate: z.string(),
mendDate: z.string(),
});

const MetaSchema = z.object({
page: z.number(),
take: z.number(),
itemCount: z.number(),
pageCount: z.number(),
hasPreviousPage: z.boolean(),
hasNextPage: z.boolean(),
});

export const CREW_ORIGIN =
process.env.NODE_ENV === 'development' ? `https://crew.api.dev.sopt.org` : `https://crew.api.prod.sopt.org`;

// export const getMeetings = createEndpoint({
// request: (orgUserId: number) => ({
// method: 'GET',
// url: `${CREW_ORIGIN}/meeting/v2/org-user?orgUserId=${orgUserId}`,
// }),
// serverResponseScheme: z.object({
// meetings: z.array(MeetingSchema),
// meta: MetaSchema,
// }),
// });

// export const getMeetings = async (orgUserId: number) => {
// await axios.request({
// method: 'GET',
// baseURL: `${CREW_ORIGIN}/meeting/v2/org-user?orgUserId=${orgUserId}`,
// });
// };

export async function getMeetings(orgUserId: number) {
const data = await axios.get(`https://crew.api.dev.sopt.org/meeting/v2/org-user?orgUserId=${orgUserId}`);

return data.data?.meetings;
}
26 changes: 24 additions & 2 deletions src/components/members/detail/MemberDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from '@emotion/styled';
import { colors } from '@sopt-makers/colors';
import { useQuery } from '@tanstack/react-query';
import dayjs from 'dayjs';
import { uniq } from 'lodash-es';
import Link from 'next/link';
Expand All @@ -10,6 +11,7 @@ import MailIcon from 'public/icons/icon-mail.svg';
import ProfileIcon from 'public/icons/icon-profile.svg';
import { FC, useMemo } from 'react';

import { getMeetings } from '@/api/endpoint/meetings/getMeetings';
import { useGetMemberOfMe } from '@/api/endpoint/members/getMemberOfMe';
import { useGetMemberProfileById } from '@/api/endpoint_LEGACY/hooks';
import { isProjectCategory } from '@/api/endpoint_LEGACY/projects/type';
Expand All @@ -21,9 +23,11 @@ import EmptyProfile from '@/components/members/detail/EmptyProfile';
import InfoItem from '@/components/members/detail/InfoItem';
import InterestSection from '@/components/members/detail/InterestSection';
import MemberDetailSection from '@/components/members/detail/MemberDetailSection';
import MemberMeetingCard from '@/components/members/detail/MemberMeetingCard';
import MemberProjectCard from '@/components/members/detail/MemberProjectCard';
import MessageSection from '@/components/members/detail/MessageSection';
import PartItem from '@/components/members/detail/PartItem';
import { MeetingType } from '@/components/members/detail/types';
import { DEFAULT_DATE } from '@/components/members/upload/constants';
import { Category } from '@/components/projects/types';
import { playgroundLink } from '@/constants/links';
Expand Down Expand Up @@ -51,7 +55,11 @@ const MemberDetail: FC<MemberDetailProps> = ({ memberId }) => {
const router = useRouter();
const { data: profile, isLoading, error } = useGetMemberProfileById(safeParseInt(memberId) ?? undefined);
const { data: me } = useGetMemberOfMe();

const { data: meetingList } = useQuery({
queryKey: ['getMeetings'],
queryFn: () => getMeetings(Number(memberId) ?? undefined),
});
console.log(meetingList);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { data: meetingList } = useQuery({
queryKey: ['getMeetings'],
queryFn: () => getMeetings(Number(memberId) ?? undefined),
});
console.log(meetingList);
const { data: meetingList } = useQuery({
queryKey: ['getMeetings', memberId], // 1. 쿼리키에 추가가 필요할 것 같아요!
queryFn: () => getMeetings(Number(memberId) ?? undefined),
});
  1. memberId 도 string을 number로 캐스팅 하고(이게 타입 안맞거나 하면 NaN 되어버리거나 하는 위험이 있어서..!) 저걸 다시 어차피 getMeetings에서 string으로 바꿔서 쓰니까 애초에 getMeetings에 string으로 받아도 좋을 것 같아요!

쿼리키는 꼭 넣어주시구 이대로도 잘 동작한다면 2번은 나중에 반영해도 될 것 같아요!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. console.log 도 지우기

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

급하게 하느라 꼼꼼하지 못했는데.. 챙겨주셔서 넘 감사합니다ㅜㅜ

const sortedSoptActivities = useMemo(() => {
if (!profile?.soptActivities) {
return [];
Expand Down Expand Up @@ -253,6 +261,20 @@ const MemberDetail: FC<MemberDetailProps> = ({ memberId }) => {
</>
)}
</ProjectContainer>
<ProjectContainer>
<ProjectTitle>{profile.name}님이 참여한 모임</ProjectTitle>
{meetingList && meetingList?.length > 0 && (
<>
<ProjectSub>{meetingList.length}개의 프로젝트에 참여</ProjectSub>
<ProjectDisplay>
{meetingList.map((meeting: MeetingType) => (
<MemberMeetingCard key={meeting.id} userName={profile.name} {...meeting} />
))}
</ProjectDisplay>
</>
)}
{meetingList?.length === 0 && <ProjectSub>아직 참여한 프로젝트가 없어요</ProjectSub>}
</ProjectContainer>
</Wrapper>
</Container>
);
Expand Down Expand Up @@ -508,7 +530,7 @@ const ProjectDisplay = styled.div`
row-gap: 20px;
column-gap: 29px;
margin-top: 32px;

@media ${MOBILE_MEDIA_QUERY} {
display: flex;
flex-direction: column;
Expand Down
69 changes: 67 additions & 2 deletions src/components/members/detail/MemberMeetingCard.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,68 @@
export default function MemberMeetingCard() {
return <div>MemberGroupCard</div>;
import styled from '@emotion/styled';
import { colors } from '@sopt-makers/colors';
import dayjs from 'dayjs';
import Link from 'next/link';

import ContentsCard from '@/components/common/ContentsCard';
import { playgroundLink } from '@/constants/links';

interface Meeting {
id: number;
isMeetingLeader: boolean;
title: string;
category: string;
imageUrl: string;
isActiveMeeting: boolean;
mstartDate: string;
mendDate: string;
}

interface MeetingProps extends Meeting {
userName: string;
}

export default function MemberMeetingCard({
id,
isMeetingLeader,
title,
category,
imageUrl,
mstartDate,
mendDate,
isActiveMeeting,
userName,
}: MeetingProps) {
const meetingCategory = isMeetingLeader ? `${category} | ${userName}님이 만든 모임` : category;
const startDate = dayjs(mstartDate).format('YYYY.MM.DD');
const endDate = dayjs(mendDate).format('YYYY.MM.DD');
const date = startDate === endDate ? startDate : `${startDate} - ${endDate}`;

return (
<Link href={playgroundLink.groupDetail(id)}>
<ContentsCard
thumbnail={imageUrl}
title={title}
top={meetingCategory}
bottom={
<Bottom>
<Circle isActiveMeeting={isActiveMeeting} />
{date}
</Bottom>
}
/>
</Link>
);
}

const Circle = styled.div<{ isActiveMeeting: boolean }>`
border-radius: 50%;
background-color: ${({ isActiveMeeting }) => (isActiveMeeting ? '#CDF47C' : colors.gray300)};
width: 6px;
height: 6px;
`;

const Bottom = styled.footer`
display: flex;
gap: 8px;
align-items: center;
`;
11 changes: 11 additions & 0 deletions src/components/members/detail/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ export type Career =
endDate: string;
isCurrent: false;
};

export type MeetingType = {
id: number;
isMeetingLeader: boolean;
title: string;
imageUrl: string;
category: string;
isActiveMeeting: boolean;
mstartDate: string;
mendDate: string;
};
1 change: 1 addition & 0 deletions src/constants/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const playgroundLink = {
projectUpload: () => `/projects/upload`,
projectEdit: (id: string | number) => `/projects/edit/${id}`,
groupList: () => '/group',
groupDetail: (id: string | number) => `/group/detail?id=${id}`,
intro: () => `/intro`,
login: () => `/auth/login`,
register: () => `/auth/verify`,
Expand Down
Loading