Skip to content

Commit

Permalink
feat: Modify PostCard when fetching Dormitory Posts (kookmin-sw#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjeongmin committed May 13, 2024
1 parent 0b82611 commit b6e4299
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/app/pages/shared-post-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,11 @@ export function SharedPostPage({ postId }: { postId: number }) {
enabled: auth?.accessToken !== undefined,
});

const { data: userData } = useUserData(auth?.accessToken !== undefined);
const { data: userData } = useUserData(auth?.accessToken != null);
const [userId, setUserId] = useState<string>('');

useEffect(() => {
if (userData !== undefined) {
if (userData != null) {
setUserId(userData.memberId);
}
}, [userData]);
Expand Down Expand Up @@ -565,7 +565,7 @@ export function SharedPostPage({ postId }: { postId: number }) {
</div>
<div>
<span>희망 월 분담금</span>
<span>{sharedPost.data.roomInfo.expectedPayment}</span>
<span>{sharedPost.data.roomInfo.expectedPayment}만원</span>
</div>
</styles.dealInfoContainer>
<styles.roomInfoContainer>
Expand Down
14 changes: 10 additions & 4 deletions src/app/pages/writing-post-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,11 @@ export function WritingPostPage() {
location: address?.roadAddress,
features: derivedFeatures,
},
participationMemberIds:
auth?.user != null ? [auth.user.memberId] : [],
participationData: {
recruitmentCapacity: mateLimit,
participationMemberIds:
auth?.user != null ? [auth.user.memberId] : [],
},
},
{
onSuccess: () => {
Expand Down Expand Up @@ -705,8 +708,11 @@ export function WritingPostPage() {
location: address?.roadAddress,
features: derivedFeatures,
},
participationMemberIds:
auth?.user != null ? [auth.user.memberId] : [],
participationData: {
recruitmentCapacity: mateLimit,
participationMemberIds:
auth?.user != null ? [auth.user.memberId] : [],
},
},
},
{
Expand Down
27 changes: 17 additions & 10 deletions src/components/shared-posts/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ export function PostCard({
post: SharedPostListItem | DormitorySharedPostListItem;
onClick: () => void;
}) {
const recruitmentCapacity =
'roomInfo' in post
? post.roomInfo.expectedPayment
: post.recruitmentCapacity;

return (
<div>
<styles.container onClick={onClick}>
Expand All @@ -139,16 +144,18 @@ export function PostCard({
<h1>{post.title}</h1>
<h2>{post.address.roadAddress}</h2>
</div>
{'roomInfo' in post && (
<div>
<p>모집 {post.roomInfo.recruitmentCapacity}</p>
<p>
{post.roomInfo.roomType} · 방 {post.roomInfo.numberOfRoom} ·
화장실 {post.roomInfo.numberOfBathRoom}
</p>
<p>희망 월 분담금 {post.roomInfo.expectedPayment}만원</p>
</div>
)}
<div>
<p>모집 {recruitmentCapacity}</p>
{'roomInfo' in post && (
<>
<p>
{post.roomInfo.roomType} · 방 {post.roomInfo.numberOfRoom} ·
화장실 {post.roomInfo.numberOfBathRoom}
</p>
<p>희망 월 분담금 {post.roomInfo.expectedPayment}만원</p>
</>
)}
</div>
</styles.content>
<styles.writer>
<img alt="" src={post.publisherAccount.profileImageFileName} />
Expand Down
21 changes: 13 additions & 8 deletions src/components/shared-posts/SharedPostsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import styled from 'styled-components';

import { type SharedPostsType } from '@/entities/shared-posts-filter';
import { useAuthValue } from '@/features/auth';

const styles = {
container: styled.div`
Expand Down Expand Up @@ -55,6 +56,8 @@ export function SharedPostsMenu({
handleSelect,
className,
}: Props & React.ComponentProps<'div'>) {
const auth = useAuthValue();

return (
<styles.container className={className}>
<styles.item
Expand All @@ -73,14 +76,16 @@ export function SharedPostsMenu({
>
방 없는 메이트
</styles.item>
<styles.item
onClick={() => {
handleSelect('dormitory');
}}
className={selected === 'dormitory' ? 'selected' : ''}
>
기숙사 메이트
</styles.item>
{auth?.user?.univCertified === true ?? (
<styles.item
onClick={() => {
handleSelect('dormitory');
}}
className={selected === 'dormitory' ? 'selected' : ''}
>
기숙사 메이트
</styles.item>
)}
</styles.container>
);
}
5 changes: 4 additions & 1 deletion src/entities/user/user.type.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export interface User {
memberId: string;
email: string;
name: string;
birthYear: string;
gender: string;
email: string;
phoneNumber: string;
initialized: boolean;
myCardId: number;
mateCardId: number;
univCertified: boolean;
}
1 change: 1 addition & 0 deletions src/features/auth/auth.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface GetUserDataDTO extends SuccessBaseDTO {
initialized: boolean;
myCardId: number;
mateCardId: number;
univCertified: boolean;
};
}

Expand Down
5 changes: 4 additions & 1 deletion src/features/shared/shared.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,8 @@ export interface SharedPostProps {
options: string;
};
};
participationMemberIds: string[];
participationData: {
recruitmentCapacity: number;
participationMemberIds: string[];
};
}

0 comments on commit b6e4299

Please sign in to comment.