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/CK-149] 골룸 인증피드 내부 전체 인증피드 도출 로직을 구현한다 #102

Merged
merged 3 commits into from
Aug 15, 2023
Merged
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
9 changes: 9 additions & 0 deletions client/src/apis/goalRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
newTodoPayload,
GoalRoomInfoResponse,
GoalRoomTodoChangeStatusRequest,
GoalRoomCertificationFeedsResponse,
} from '@/myTypes/goalRoom/remote';
import client from '@apis/axios/client';
import { GoalRoomRecruitmentStatus, MyPageGoalRoom } from '@myTypes/goalRoom/internal';
Expand Down Expand Up @@ -84,3 +85,11 @@ export const postCreateNewCertificationFeed = (
export const postJoinGoalRoom = (goalRoomId: string) => {
return client.post(`/goal-rooms/${goalRoomId}/join`);
};

export const getCertificationFeeds = async (goalRoomId: string) => {
const { data } = await client.get<GoalRoomCertificationFeedsResponse>(
`/goal-rooms/${goalRoomId}/checkFeeds`
);

return data;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import InputField from '@components/roadmapCreatePage/input/inputField/InputFiel
import { useValidateInput } from '@hooks/_common/useValidateInput';
import { CERTIFICATION_FEED } from '@constants/goalRoom/regex';
import TextCount from '@components/roadmapCreatePage/input/textCount/TextCount';
import { useCreateCertificationFeed } from '@hooks/queries/goalRoom';
import {
useCertificationFeeds,
useCreateCertificationFeed,
} from '@hooks/queries/goalRoom';
import { useGoalRoomDashboardContext } from '@/context/goalRoomDashboardContext';
import { BASE_URL } from '@apis/axios/client';

const CertificationFeedModal = () => {
const { goalroomId } = useGoalRoomDashboardContext();
const { certificationFeeds } = useCertificationFeeds(goalroomId);

const [imagePreview, setImagePreview] = useState<string | null>('');
const [imageFile, setImageFile] = useState<File | null>(null); // add this state for file
const [imageFile, setImageFile] = useState<File | null>(null);
const { handleInputChange, validateInput, errorMessage, resetErrorMessage, value } =
useValidateInput(CERTIFICATION_FEED);

Expand Down Expand Up @@ -52,42 +57,68 @@ const CertificationFeedModal = () => {
<S.CertificationModalWrapper>
<S.CertificationHeader>인증피드</S.CertificationHeader>
<S.CertificationText>새로운 인증피드 등록</S.CertificationText>
{imagePreview && (
<S.PreviewWrapper>
<S.PreviewImage src={imagePreview} alt='업로드한 인증 피드 이미지' />
<S.PreviewDeleteButton onClick={handleRemoveImage}>X</S.PreviewDeleteButton>
</S.PreviewWrapper>
)}

<form action='' onSubmit={handleFormSubmit}>
{!imagePreview && (
<S.FileUploadCard htmlFor='fileInput'>
<S.PlusButton>인증피드 사진 업로드</S.PlusButton>
<input
id='fileInput'
type='file'
onChange={handleImageChange}
style={{ display: 'none' }}
<S.CertificationFeedsWrapper>
<form onSubmit={handleFormSubmit}>
{imagePreview && (
<S.PreviewWrapper>
<S.PreviewImage src={imagePreview} alt='업로드한 인증 피드 이미지' />
<S.PreviewDeleteButton onClick={handleRemoveImage}>X</S.PreviewDeleteButton>
</S.PreviewWrapper>
)}
{!imagePreview && (
<S.FileUploadCard htmlFor='fileInput'>
<S.PlusButton>인증피드 사진 업로드</S.PlusButton>
<input
id='fileInput'
type='file'
onChange={handleImageChange}
style={{ display: 'none' }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

으으 이거 진짜진짜 어떤 느낌인지 아는데ㅠㅠ
그래도 스타일은 styled component에서 주는걸로 통일시키는 것은 어떨까요?

/>
</S.FileUploadCard>
)}
<S.InputFieldWrapper>
<InputField
placeholder='컨텐츠를 소개하는 문장을 작성해주세요'
handleInputChange={handleInputChange}
maxLength={250}
validateInput={validateInput}
resetErrorMessage={resetErrorMessage}
name='introduction'
data-valid={validateInput}
/>
</S.FileUploadCard>
)}
<S.InputFieldWrapper>
<InputField
placeholder='컨텐츠를 소개하는 문장을 작성해주세요'
handleInputChange={handleInputChange}
maxLength={250}
validateInput={validateInput}
resetErrorMessage={resetErrorMessage}
name='introduction'
data-valid={validateInput}
/>
</S.InputFieldWrapper>
<TextCount maxCount={250} currentCount={value.length} />
<S.ErrorMessage>{errorMessage}</S.ErrorMessage>
<S.CertificationSubmitButton type='submit'>
인증피드 등록
</S.CertificationSubmitButton>
</form>
</S.InputFieldWrapper>
<TextCount maxCount={250} currentCount={value.length} />
<S.ErrorMessage>{errorMessage}</S.ErrorMessage>
<S.CertificationSubmitButton type='submit'>
Copy link
Collaborator

Choose a reason for hiding this comment

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

type='submit'은 없어도 무방할 것 같아요🤩

인증피드 등록
</S.CertificationSubmitButton>
</form>

{certificationFeeds.map((feed) => {
return (
<S.CertificationFeedCard key={feed.checkFeed.id}>
<S.CertificationFeedImage
src={BASE_URL + feed.checkFeed.imageUrl}
alt='인증피드 이미지'
/>
<S.CertificationFeedDescription>
{feed.checkFeed.description}
</S.CertificationFeedDescription>
<S.CertificationFeedsUserInfo>
<S.CertificationFeedsUserImage
src={BASE_URL + feed.member.imageUrl}
alt='유저 이미지'
/>
<S.CertificationFeedsUserName>
{feed.member.nickname}
</S.CertificationFeedsUserName>
</S.CertificationFeedsUserInfo>
<S.CreatedAtText>{feed.checkFeed.createdAt}</S.CreatedAtText>
</S.CertificationFeedCard>
);
})}
</S.CertificationFeedsWrapper>
</S.CertificationModalWrapper>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const CertificationHeader = styled(ModalHeader)``;
export const CertificationText = styled(NewTodoText)``;

export const PreviewImage = styled.img`
width: 20rem;
height: 25rem;
width: 19rem;
height: 20rem;

object-fit: cover;
border-radius: 10px;
Expand All @@ -29,8 +29,8 @@ export const FileUploadCard = styled.label`
align-items: center;
justify-content: center;

width: 20rem;
height: 25rem;
width: 19rem;
height: 20rem;

border: dashed 0.2rem ${({ theme }) => theme.colors.gray200};
border-radius: 10px;
Expand All @@ -43,8 +43,8 @@ export const PlusButton = styled.span`

export const PreviewWrapper = styled.div`
position: relative;
width: 20rem;
height: 25rem;
width: 19rem;
height: 20rem;
margin-top: 2rem;
`;

Expand Down Expand Up @@ -76,7 +76,7 @@ export const ErrorMessage = styled.div`
`;

export const InputFieldWrapper = styled.div`
width: 20rem;
width: 19rem;
margin-top: 1rem;
padding: 1rem;

Expand All @@ -85,8 +85,68 @@ export const InputFieldWrapper = styled.div`
`;

export const CertificationSubmitButton = styled.button`
width: 20rem;
width: 19rem;
padding: 1rem;
background: ${({ theme }) => theme.colors.main_middle};
border-radius: 10px;
`;

export const CertificationFeedsWrapper = styled.div`
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
justify-content: flex-start;
`;

export const CertificationFeedCard = styled.div`
overflow: hidden;
flex: 0 0 calc(33.33% - 1.5rem);

width: 20rem;
height: 35rem;

border-radius: 10px;
box-shadow: ${({ theme }) => theme.shadows.threeD};

transition: transform 0.2s;

&:hover {
transform: translateY(-5px);
}
`;

export const CertificationFeedImage = styled.img`
width: 100%;
height: 20rem;
object-fit: cover;
`;

export const CertificationFeedDescription = styled.p`
padding: 0.5rem 1rem;
font-size: 0.9rem;
color: ${({ theme }) => theme.colors.gray600};
`;

export const CertificationFeedsUserInfo = styled.div`
display: flex;
align-items: center;
padding: 0.5rem 1rem;
`;

export const CertificationFeedsUserImage = styled.img`
width: 4rem;
height: 4rem;
margin-right: 0.5rem;
border-radius: 50%;
`;

export const CertificationFeedsUserName = styled.span`
${({ theme }) => theme.fonts.h2}
color: ${({ theme }) => theme.colors.black};
`;

export const CreatedAtText = styled.span`
font-size: 0.8rem;
color: ${({ theme }) => theme.colors.gray300};
text-align: center;
`;
3 changes: 3 additions & 0 deletions client/src/constants/@queryKeys/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const QUERY_KEYS = {
list: 'roadmapList',
detail: 'roadmapDetail',
},
goalRoom: {
certificationFeeds: 'certificationFeeds',
},
} as const;

export default QUERY_KEYS;
13 changes: 13 additions & 0 deletions client/src/hooks/queries/goalRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import {
postToChangeTodoCheckStatus,
postJoinGoalRoom,
getMyGoalRoomList,
getCertificationFeeds,
} from '@apis/goalRoom';
import { useSuspendedQuery } from '@hooks/queries/useSuspendedQuery';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import useToast from '@hooks/_common/useToast';
import { GoalRoomRecruitmentStatus } from '@myTypes/goalRoom/internal';
import { useNavigate } from 'react-router-dom';
import QUERY_KEYS from '@constants/@queryKeys/queryKeys';

export const useGoalRoomList = (params: GoalRoomListRequest) => {
const { data } = useSuspendedQuery(['goalRoomList', params.roadmapId], () =>
Expand Down Expand Up @@ -160,3 +162,14 @@ export const useJoinGoalRoom = ({ goalRoomId, roadmapId }: JoinGoalRoomRequest)
joinGoalRoom: mutate,
};
};

export const useCertificationFeeds = (goalRoomId: string) => {
const { data } = useSuspendedQuery(
[QUERY_KEYS.goalRoom.certificationFeeds, goalRoomId],
() => getCertificationFeeds(goalRoomId)
);

return {
certificationFeeds: data,
};
};
20 changes: 20 additions & 0 deletions client/src/myTypes/goalRoom/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,23 @@ export type JoinGoalRoomRequest = {
goalRoomId: string;
roadmapId: string;
};

export type UserType = {
id: number;
nickname: string;
imageUrl: string;
};

export type CheckFeedType = {
id: number;
imageUrl: string;
description: string;
createdAt: string;
};

export type CertificationFeedType = {
member: UserType;
checkFeed: CheckFeedType;
};

export type GoalRoomCertificationFeedsResponse = Array<CertificationFeedType>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Array<CertificationFeedType>
CertificationFeedType[]
둘 중 어떻게 작성할지 팀 컨벤션으로 이야기해봐도 좋을 것 같아요!

현재는 CertificationFeedType[]와 같이 작성된 타입이 많은데, 이걸로 통일시키는 것은 어떨까요?