Skip to content

Commit

Permalink
refactor(member): 활동 2차 QA 피드백 반영 수정 (#231)
Browse files Browse the repository at this point in the history
* fix(member): 남은 날짜 계산 시 -1일 되어 계산되는 문제 보완

* refactor(member): 활동 내용 공백문자 처리 및 스터디 정보 박스 크기 수정, 공지사항 조회 수정

* refactor(member): 활동 목록에서 category, leader 조회 추가, 선택하지 않은 경우 '미선택' 나타나도록 수정

* refactor(member): 새로고침 하지 않아도 업데이트 된 상태가 바로 반영되도록 수정

* refactor(member): 글자수 제한 설정 및 카테고리명 한국어로 변환

* style(member): 나의 지원 badge 추가, 탭 삭제

* refactor(member): 다중 파일 첨부 및 파일 다운로드, 이미지 조회 기능 추가, board 추가 버튼 위치 조정

* style(member): 활동 정보 모달 크기 조정

* fix(member): export MemberStatusType

* Create happy-clocks-shave.md

---------

Co-authored-by: GwanSik Kim <[email protected]>
  • Loading branch information
Jeong-Ag and gwansikk authored Sep 8, 2024
1 parent 5bc70bd commit 4342f54
Show file tree
Hide file tree
Showing 28 changed files with 382 additions and 185 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-clocks-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clab-platforms/member": patch
---

refactor(member): 활동 2차 QA 피드백 반영 수정
18 changes: 8 additions & 10 deletions apps/member/src/api/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export async function postActivityBoard({
activityGroupId: activityGroupId,
};

let fileUrl: string | null = null;
let fileUrl: Array<string> | null = null;

if (
body.category === ACTIVITY_BOARD_CATEGORY_STATE.ASSIGNMENT &&
Expand All @@ -289,7 +289,7 @@ export async function postActivityBoard({
files,
});

fileUrl = data[0].fileUrl;
fileUrl = data.map((file) => file.fileUrl);
} else if (
body.category === ACTIVITY_BOARD_CATEGORY_STATE.WEEKLY_ACTIVITY &&
memberId &&
Expand All @@ -301,7 +301,7 @@ export async function postActivityBoard({
files,
});

fileUrl = data[0].fileUrl;
fileUrl = data.map((file) => file.fileUrl);
}

const { data } = await server.post<
Expand All @@ -311,7 +311,7 @@ export async function postActivityBoard({
url: createPagination(END_POINT.ACTIVITY_GROUP_BOARD, params),
body: {
...body,
fileUrls: fileUrl ? [fileUrl] : undefined,
fileUrls: fileUrl ? fileUrl : undefined,
},
});

Expand All @@ -328,25 +328,23 @@ export async function patchActivityBoard({
body,
files,
}: PatchActivityBoardParams) {
let fileUrl: string | null = null;
let fileUrl: Array<string> | null = null;

if (groupBoardId === null && groupId && files) {
// 파일이 있을 경우 파일 업로드 진행 (주차별 활동 파일)
const data = await postUploadedFileWeekly({
groupId: groupId,
files,
});

fileUrl = data[0].fileUrl;
fileUrl = data.map((file) => file.fileUrl);
} else if (groupId && groupBoardId && files) {
// 파일이 있을 경우 파일 업로드 진행 (과제 파일)
const data = await postUploadedFileAssignment({
groupId: groupId,
groupBoardId: groupBoardId,
files,
});

fileUrl = data[0].fileUrl;
fileUrl = data.map((file) => file.fileUrl);
}

const { data } = await server.patch<
Expand All @@ -358,7 +356,7 @@ export async function patchActivityBoard({
}),
body: {
...body,
fileUrls: fileUrl ? [fileUrl] : undefined,
fileUrls: fileUrl ? fileUrl : undefined,
},
});

Expand Down
29 changes: 26 additions & 3 deletions apps/member/src/components/common/File/File.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
import { createURL } from '@clab-platforms/utils';

import { SERVER_BASE_URL } from '@constants/api';
import useToast from '@hooks/common/useToast';

interface FileProps extends React.PropsWithChildren {
href: string;
name: string;
}

const File = ({ children, href }: FileProps) => {
const File = ({ href, name }: FileProps) => {
const toast = useToast();

if (!href.startsWith(SERVER_BASE_URL)) {
href = createURL(SERVER_BASE_URL, href);
}

const handleClickImgLink = () => {
fetch(href)
.then((res) => res.blob())
.then((blob) => {
const href = window.URL.createObjectURL(new Blob([blob]));
const a = document.createElement('a');
a.href = href;
a.download = name;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(href);
a.remove();
})
.catch(() => {
toast({ state: 'error', message: '파일 다운로드에 실패했습니다' });
});
};

return (
<a
href={href}
target="_blank"
className="underline-offset-4 hover:underline"
className="text-gray-700 underline-offset-4 hover:underline"
rel="noreferrer"
onClick={handleClickImgLink}
>
{children}
{name}
</a>
);
};
Expand Down
2 changes: 1 addition & 1 deletion apps/member/src/components/common/Notice/Notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Notice = ({
},
)}
>
D-{dDay}
{dDay === 0 ? 'D-Day' : `D-${dDay}`}
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ const ActivityAssignmentEditor = ({ parentId, activityGroupId }: Props) => {
};
const handleAddAssignmentClick = () => {
const formData = new FormData();
const file = uploaderRef.current?.files?.[0];
const files = uploaderRef.current?.files;

if (!board.title || !board.content || !board.dueDateTime)
return toast({
state: 'error',
message: '제목, 내용, 종료 일시는 필수 입력 요소입니다.',
});
if (file) {
formData.append(FORM_DATA_KEY, file);
if (files) {
Array.from(files).forEach((file) => {
formData.append(FORM_DATA_KEY, file);
});
}

activityGroupBoardMutate(
Expand All @@ -60,25 +62,15 @@ const ActivityAssignmentEditor = ({ parentId, activityGroupId }: Props) => {
category: ACTIVITY_BOARD_CATEGORY_STATE.ASSIGNMENT,
...board,
},
files: file ? formData : undefined,
files: files?.length ? formData : undefined,
},
{ onSuccess: () => setBoard(defaultBoard) },
);
};

return (
<Section>
<Section.Header title="과제 관리">
<div className="space-x-2">
<Button
size="sm"
onClick={handleAddAssignmentClick}
disabled={activityGroupBoardIsPending}
>
추가
</Button>
</div>
</Section.Header>
<Section.Header title="과제 관리" />
<Section.Body className="space-y-4">
<div className="space-y-2">
<Input
Expand Down Expand Up @@ -112,10 +104,17 @@ const ActivityAssignmentEditor = ({ parentId, activityGroupId }: Props) => {
<label htmlFor="fileUpload" className="mb-1 ml-1 text-xs">
첨부 파일
</label>
<input ref={uploaderRef} id="fileUpload" type="file" />
<input ref={uploaderRef} id="fileUpload" type="file" multiple />
</div>
</Grid>
</div>
<Button
className="w-full"
onClick={handleAddAssignmentClick}
disabled={activityGroupBoardIsPending}
>
추가
</Button>
</Section.Body>
</Section>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface Props {
groupId: number;
}
interface FileUploaderProps {
uploadedFile: ResponseFile | null;
uploadedFile: Array<ResponseFile> | null;
uploaderRef: React.RefObject<HTMLInputElement>;
handleDeleteFileClick: () => void;
}
Expand All @@ -32,8 +32,8 @@ const ActivityBoardEditModal = ({ prevData, groupId }: Props) => {
const [board, setBoard] = useState<ActivityBoardType>(prevData);

const uploaderRef = useRef<HTMLInputElement>(null);
const [uploadedFile, setUploadedFile] = useState<ResponseFile | null>(
prevData?.files?.[0] || null,
const [uploadedFile, setUploadedFile] = useState<Array<ResponseFile> | null>(
prevData?.files || null,
);
const { activityGroupBoardPatchMutate, activityGroupBoardPatchIsPending } =
useActivityGroupBoardPatchMutation();
Expand All @@ -49,16 +49,18 @@ const ActivityBoardEditModal = ({ prevData, groupId }: Props) => {
};
const handleEditButtonClick = () => {
const formData = new FormData();
const file = uploaderRef.current?.files?.[0];
const files = uploaderRef.current?.files;

if (!board.title || !board.content) {
return toast({
state: 'error',
message: '제목과 내용을 입력해주세요.',
});
}
if (file) {
formData.append(FORM_DATA_KEY, file);
if (files?.length) {
Array.from(files).forEach((file) => {
formData.append(FORM_DATA_KEY, file);
});
}

activityGroupBoardPatchMutate({
Expand All @@ -70,7 +72,7 @@ const ActivityBoardEditModal = ({ prevData, groupId }: Props) => {
content: board.content,
dueDateTime: board.dueDateTime,
},
files: file ? formData : undefined,
files: files?.length ? formData : undefined,
});
closeModal();
};
Expand Down Expand Up @@ -134,22 +136,28 @@ const FileUploader = ({
}: FileUploaderProps) => {
return (
<>
{uploadedFile && (
<div className="space-y-2">
<File key={uploadedFile.fileUrl} href={uploadedFile.fileUrl}>
{uploadedFile.originalFileName}
</File>
{uploadedFile?.length ? (
<div>
{uploadedFile?.map((file) => (
<File
key={file.fileUrl}
href={file.fileUrl}
name={file.originalFileName}
/>
))}
<Button className="w-full" onClick={handleDeleteFileClick}>
첨부파일 변경하기
</Button>
</div>
) : (
<input
ref={uploaderRef}
id="uploader"
type="file"
multiple
className={cn(uploadedFile?.length && 'hidden')}
/>
)}
<input
ref={uploaderRef}
id="uploader"
type="file"
className={cn(uploadedFile && 'hidden')}
/>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ const ActivityDetailSection = ({ data }: ActivityDetailSectionProps) => {
<div className="space-y-4">
<Image
width="w-full"
height="h-[300px]"
height="h-[320px]"
src={data.imageUrl}
alt={data.name}
className="rounded-lg border object-cover"
/>
<Section>
<Section className="flex h-[160px] flex-col justify-between overflow-scroll">
<h1 className="text-xl font-bold">{data.name}</h1>
<p className="my-1 text-sm">{data.content}</p>
<p className="my-1 whitespace-pre-line text-sm ">{data.content}</p>
<div className="flex items-center gap-1 text-sm text-gray-500">
<CertificateSolidOutline />
<span>{data.category}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,7 @@ const ActivityNoticeEditor = ({ groupId, data }: ActivityNoticeEditorProps) => {
return (
<>
<Section>
<Section.Header title="공지 관리">
<div className="space-x-2">
<Button
size="sm"
onClick={handleAddNoticeButtonClick}
disabled={activityGroupBoardIsPending}
>
추가
</Button>
</div>
</Section.Header>
<Section.Header title="공지 관리" />
<Section.Body className="space-y-4">
<div className="space-y-2">
<Input
Expand All @@ -92,6 +82,13 @@ const ActivityNoticeEditor = ({ groupId, data }: ActivityNoticeEditorProps) => {
</div>
<Hr>미리보기</Hr>
<ActivityNoticeSection data={[notice, ...data]} />
<Button
className="w-full"
onClick={handleAddNoticeButtonClick}
disabled={activityGroupBoardIsPending}
>
추가
</Button>
</Section.Body>
</Section>
<ActivityConfigTableSection tableList={data} groupId={groupId} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ActivityNoticeSectionProps {

interface ActivityNoticeSectionItemProps {
className?: string;
onClick: (content: string) => void;
onClick: (content: string, title?: string) => void;
data: ActivityBoardType;
}

Expand All @@ -37,9 +37,9 @@ const ActivityNoticeSection = ({ data }: ActivityNoticeSectionProps) => {
const latestNotice = sortedNotices[0];
const otherNotices = sortedNotices.slice(1);

const onClickAlert = (content: string) => {
const onClickAlert = (content: string, title?: string) => {
openModal({
title: '📣 공지사항',
title: `📣 ${title}`,
content: content,
});
};
Expand Down Expand Up @@ -94,11 +94,13 @@ ActivityNoticeSection.Item = ({
>
<div
className="flex cursor-pointer items-center justify-between gap-2"
onClick={() => onClick(data.content)}
onClick={() => onClick(data.content, data.title)}
>
<p className="w-full truncate">{data.title}</p>
<p className="whitespace-nowrap text-sm text-gray-500">
{formattedDate(toKoreaISOString(data.updatedAt))}
{formattedDate(
data.updatedAt ? toKoreaISOString(data.updatedAt) : String(dayjs()),
)}
</p>
</div>
</div>
Expand Down
Loading

0 comments on commit 4342f54

Please sign in to comment.