Skip to content

Commit

Permalink
Merge pull request #265 from mash-up-kr/develop
Browse files Browse the repository at this point in the history
Main Release/1.4.2
  • Loading branch information
sanoopark committed Feb 27, 2023
2 parents f2a5b03 + 2db105f commit 6994fe5
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 59 deletions.
85 changes: 60 additions & 25 deletions src/components/common/Table/Table.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { SORT_TYPE, PATH } from '@/constants';
import { ToastType } from '../Toast/Toast.component';
import { useToast } from '@/hooks';
import { $profile } from '@/store';
import { Team as TeamNames } from '@/components/common/UserProfile/UserProfile.component';
import { Team as TeamNames, TeamType } from '@/components/common/UserProfile/UserProfile.component';

export type TextAlign = 'start' | 'center' | 'end';

Expand All @@ -32,12 +32,17 @@ export interface TableColumn<T extends object> {
idAccessor?: NestedKeyOf<T>;
widthRatio: string;
textAlign?: TextAlign;
renderCustomCell?: (
cellValue: unknown,
id: string,
handleClickLink?: MouseEventHandler<HTMLButtonElement>,
applicationParams?: ApplicationRequest,
) => ReactNode;
renderCustomCell?: ({
cellValue,
id,
handleClickLink,
applicationParams,
}: {
cellValue: unknown;
id: string;
handleClickLink?: MouseEventHandler<HTMLButtonElement>;
applicationParams?: ApplicationRequest;
}) => ReactNode;
}

export interface SortType<T extends object> {
Expand All @@ -55,7 +60,7 @@ export interface TableProps<T extends object> {
prefix: string;
topStickyHeight?: number;
columns: TableColumn<T>[];
rows: T[] | (T & { team: Team })[];
rows: T[] | (T & { team: Team; platform: TeamType })[];
isLoading?: boolean;
selectableRow?: {
selectedCount: number;
Expand Down Expand Up @@ -286,6 +291,16 @@ const Table = <T extends object>({
[currentPath],
);

const checkIsCurrentRowAccessible = (rowTeamName: string) => {
const myTeamNameAsLowercase = myTeamName.toLowerCase();
return (
myTeamName === TeamNames.mashUp ||
myTeamName === TeamNames.branding ||
rowTeamName === myTeamNameAsLowercase ||
rowTeamName === myTeamNameAsLowercase
);
};

const handleSelectRow: (index: number) => ChangeEventHandler<HTMLInputElement> =
(index) => (e) => {
if (e.target.checked) {
Expand Down Expand Up @@ -386,33 +401,53 @@ const Table = <T extends object>({
)
: getOwnValueByKey(row, accessor as any);

const normalContents = renderCustomCell
? renderCustomCell({
cellValue,
id,
handleClickLink: undefined,
applicationParams,
})
: cellValue;

const blockContents = renderCustomCell
? renderCustomCell({
cellValue,
id,
handleClickLink: () => {
handleAddToast({
type: ToastType.error,
message: '접근 권한이 없는 플랫폼입니다.',
});
},
})
: cellValue;

if (!isCurrentPageIncludingPrivacy) {
return (
<Styled.TableCell key={`cell-${columnIndex}`} textAlign={textAlign}>
{normalContents}
</Styled.TableCell>
);
}

const rowTeamName =
('team' in row && row.team.name.toLowerCase()) ||
('platform' in row && row.platform.toLowerCase());

const isCurrentRowAccessible =
!isCurrentPageIncludingPrivacy ||
myTeamName === TeamNames.mashUp ||
myTeamName === TeamNames.branding ||
('team' in row &&
row.team.name.toLowerCase() === myTeamName.toLowerCase());
rowTeamName && checkIsCurrentRowAccessible(rowTeamName);

if (isCurrentRowAccessible) {
return (
<Styled.TableCell key={`cell-${columnIndex}`} textAlign={textAlign}>
{renderCustomCell
? renderCustomCell(cellValue, id, undefined, applicationParams)
: cellValue}
{normalContents}
</Styled.TableCell>
);
}

return (
<Styled.TableCell key={`cell-${columnIndex}`} textAlign={textAlign}>
{renderCustomCell
? renderCustomCell(cellValue, id, () => {
handleAddToast({
type: ToastType.error,
message: '접근 불가능한 지원서입니다.',
});
})
: cellValue}
{blockContents}
</Styled.TableCell>
);
})}
Expand Down
10 changes: 6 additions & 4 deletions src/components/common/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const columnsWithCustomCell: TableColumn<ApplicationFormResponse>[] = [
accessor: 'name',
idAccessor: 'applicationFormId',
widthRatio: '28%',
renderCustomCell: (cellValue) => (
renderCustomCell: ({ cellValue }) => (
<Styled.FormTitleWrapper title={cellValue as string}>
<Styled.FormTitle>{cellValue as string}</Styled.FormTitle>
</Styled.FormTitleWrapper>
Expand All @@ -66,7 +66,7 @@ const columnsWithCustomCell: TableColumn<ApplicationFormResponse>[] = [
title: '작성자',
accessor: 'createdBy',
widthRatio: '14%',
renderCustomCell: (cellValue) => {
renderCustomCell: ({ cellValue }) => {
const [team, role] = (cellValue as string).split('_') as [TeamType, RoleType];
return (
<Styled.CustomUserProfile>
Expand All @@ -79,13 +79,15 @@ const columnsWithCustomCell: TableColumn<ApplicationFormResponse>[] = [
title: '작성일시',
accessor: 'createdAt',
widthRatio: '21%',
renderCustomCell: (cellValue) => formatDate(cellValue as string, 'YYYY년 M월 D일 A h시 m분'),
renderCustomCell: ({ cellValue }) =>
formatDate(cellValue as string, 'YYYY년 M월 D일 A h시 m분'),
},
{
title: '수정일시',
accessor: 'updatedAt',
widthRatio: '21%',
renderCustomCell: (cellValue) => formatDate(cellValue as string, 'YYYY년 M월 D일 A h시 m분'),
renderCustomCell: ({ cellValue }) =>
formatDate(cellValue as string, 'YYYY년 M월 D일 A h시 m분'),
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const columns: TableColumn<EmailRequest>[] = [
title: '발송여부',
accessor: 'status',
widthRatio: '20%',
renderCustomCell: (cellValue) => (
renderCustomCell: ({ cellValue }) => (
<Styled.StatusWrapper status={cellValue as string}>
{EMAIL_STATUS[cellValue as KeyOf<typeof EMAIL_STATUS>]}
</Styled.StatusWrapper>
Expand Down
12 changes: 6 additions & 6 deletions src/pages/ActivityScoreDetail/ActivityScoreDetail.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ActivityScoreDetail = () => {
title: '',
widthRatio: '7%',
accessor: 'scoreType',
renderCustomCell: (cellValue) => (
renderCustomCell: ({ cellValue }) => (
<Styled.IconWrapper>
<Icon type={cellValue as ValueOf<typeof ScoreType>} />
</Styled.IconWrapper>
Expand All @@ -59,7 +59,7 @@ const ActivityScoreDetail = () => {
'scoreName',
'scoreType',
],
renderCustomCell: (cellValue) => {
renderCustomCell: ({ cellValue }) => {
const [
accumulatedScore,
date,
Expand Down Expand Up @@ -111,7 +111,7 @@ const ActivityScoreDetail = () => {
title: '세미나 정보',
widthRatio: '20%',
accessor: ['scheduleName', 'isCanceled'],
renderCustomCell: (cellValue) => {
renderCustomCell: ({ cellValue }) => {
const [scheduleName, isCanceled] = cellValue as [string, boolean];

return (
Expand All @@ -125,7 +125,7 @@ const ActivityScoreDetail = () => {
title: '일시',
widthRatio: '20%',
accessor: ['date', 'isCanceled'],
renderCustomCell: (cellValue) => {
renderCustomCell: ({ cellValue }) => {
const [date, isCanceled] = cellValue as [string, boolean];

return (
Expand All @@ -139,7 +139,7 @@ const ActivityScoreDetail = () => {
title: '메모',
widthRatio: '20%',
accessor: ['memo', 'isCanceled'],
renderCustomCell: (cellValue) => {
renderCustomCell: ({ cellValue }) => {
const [memo, isCanceled] = cellValue as [string, boolean];

return (
Expand All @@ -153,7 +153,7 @@ const ActivityScoreDetail = () => {
title: '점수',
widthRatio: '7%',
accessor: ['score', 'isCanceled'],
renderCustomCell: (cellValue) => {
renderCustomCell: ({ cellValue }) => {
const [score, isCanceled] = cellValue as [number, boolean];

return (
Expand Down
6 changes: 3 additions & 3 deletions src/pages/ActivityScoreList/ActivityScoreList.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const ActivityScoreList = () => {

const { pageOptions, handleChangePage, handleChangeSize } = usePagination({
totalCount,
pagingSize: 10,
pagingSize: 20,
});

const columns: TableColumn<MemberResponse>[] = [
Expand All @@ -63,7 +63,7 @@ const ActivityScoreList = () => {
widthRatio: '25%',
accessor: 'name',
idAccessor: 'memberId',
renderCustomCell: (cellValue, id, handleClickLink) => (
renderCustomCell: ({ cellValue, id, handleClickLink }) => (
<Styled.FormTitleWrapper title={cellValue as string}>
<Styled.FormTitle>{cellValue as string}</Styled.FormTitle>
{handleClickLink ? (
Expand Down Expand Up @@ -101,7 +101,7 @@ const ActivityScoreList = () => {
<TeamNavigationTabs />
<SearchOptionBar placeholder="이름 검색" />
</Styled.StickyContainer>
<Table
<Table<MemberResponse>
prefix="activity-score"
topStickyHeight={14.1}
columns={columns}
Expand Down
12 changes: 7 additions & 5 deletions src/pages/ApplicationFormList/ApplicationFormList.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const ApplicationFormList = () => {
accessor: 'name',
idAccessor: 'applicationFormId',
widthRatio: '28%',
renderCustomCell: (cellValue, id) => (
renderCustomCell: ({ cellValue, id }) => (
<Styled.FormTitleWrapper title={cellValue as string}>
<Styled.FormTitle>{cellValue as string}</Styled.FormTitle>
<Styled.TitleLink
Expand All @@ -120,7 +120,7 @@ const ApplicationFormList = () => {
title: '작성자',
accessor: 'createdBy',
widthRatio: '14%',
renderCustomCell: (cellValue) => {
renderCustomCell: ({ cellValue }) => {
const [team, role] = (cellValue as string).split('_') as [TeamType, RoleType];
return (
<Styled.CustomUserProfile>
Expand All @@ -133,18 +133,20 @@ const ApplicationFormList = () => {
title: '작성일시',
accessor: 'createdAt',
widthRatio: '21%',
renderCustomCell: (cellValue) => formatDate(cellValue as string, 'YYYY년 M월 D일 A h시 m분'),
renderCustomCell: ({ cellValue }) =>
formatDate(cellValue as string, 'YYYY년 M월 D일 A h시 m분'),
},
{
title: '수정일시',
accessor: 'updatedAt',
widthRatio: '21%',
renderCustomCell: (cellValue) => formatDate(cellValue as string, 'YYYY년 M월 D일 A h시 m분'),
renderCustomCell: ({ cellValue }) =>
formatDate(cellValue as string, 'YYYY년 M월 D일 A h시 m분'),
},
{
title: '미리보기',
accessor: 'questions',
renderCustomCell: (cellValue) => (
renderCustomCell: ({ cellValue }) => (
<ApplicationFormPreview questions={cellValue as Question[]} />
),
widthRatio: '7%',
Expand Down
15 changes: 10 additions & 5 deletions src/pages/ApplicationList/ApplicationList.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ const ApplicationList = () => {
accessor: 'applicant.name',
idAccessor: 'applicationId',
widthRatio: '12%',
renderCustomCell: (cellValue, id, handleClickLink, applicationParamStates) => (
renderCustomCell: ({
cellValue,
id,
handleClickLink,
applicationParams: applicationParamStates,
}) => (
<Styled.FormTitleWrapper title={cellValue as string}>
<Styled.FormTitle>{cellValue as string}</Styled.FormTitle>
{handleClickLink ? (
Expand Down Expand Up @@ -198,21 +203,21 @@ const ApplicationList = () => {
title: '지원일시',
accessor: 'submittedAt',
widthRatio: '20%',
renderCustomCell: (cellValue) =>
renderCustomCell: ({ cellValue }) =>
cellValue ? formatDate(cellValue as string, 'YYYY년 M월 D일 A h시 m분') : '-',
},
{
title: '면접일시',
accessor: 'result.interviewStartedAt',
widthRatio: '20%',
renderCustomCell: (cellValue) =>
renderCustomCell: ({ cellValue }) =>
cellValue ? formatDate(cellValue as string, 'YYYY년 M월 D일 A h시 m분') : '-',
},
{
title: '사용자확인여부',
accessor: 'confirmationStatus',
widthRatio: '13%',
renderCustomCell: (cellValue) => (
renderCustomCell: ({ cellValue }) => (
<Styled.Center>
<ApplicationStatusBadge
text={ApplicationConfirmationStatus[cellValue as ApplicationConfirmationStatusKeyType]}
Expand All @@ -224,7 +229,7 @@ const ApplicationList = () => {
title: '합격여부',
accessor: 'result.status',
widthRatio: '13%',
renderCustomCell: (cellValue) => (
renderCustomCell: ({ cellValue }) => (
<Styled.Center>
<ApplicationStatusBadge
text={ApplicationResultStatus[cellValue as ApplicationResultStatusKeyType]}
Expand Down
10 changes: 5 additions & 5 deletions src/pages/EmailSendingList/EmailSendingList.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const EmailSendingList = () => {
accessor: 'name',
idAccessor: 'emailNotificationId',
widthRatio: '35%',
renderCustomCell: (cellValue, id) => (
renderCustomCell: ({ cellValue, id }) => (
<Styled.TitleButton
onClick={async () => {
const { data: email } = await api.getEmailById({ notificationId: id });
Expand All @@ -96,13 +96,13 @@ const EmailSendingList = () => {
title: '발송유형',
accessor: 'type',
widthRatio: '15%',
renderCustomCell: (cellValue) => EmailTypes[cellValue as EmailType],
renderCustomCell: ({ cellValue }) => EmailTypes[cellValue as EmailType],
},
{
title: '발송자',
accessor: 'sender',
widthRatio: '15%',
renderCustomCell: (cellValue) => {
renderCustomCell: ({ cellValue }) => {
const [team, role] = (cellValue as string).split('_') as [TeamType, RoleType];
return (
<Styled.CustomUserProfile>
Expand All @@ -115,14 +115,14 @@ const EmailSendingList = () => {
title: '발송일시',
accessor: 'sendAt',
widthRatio: '20%',
renderCustomCell: (cellValue) =>
renderCustomCell: ({ cellValue }) =>
formatDate(cellValue as string, 'YYYY년 M월 D일 A h시 m분'),
},
{
title: '발송여부\n(성공/실패/전체)',
accessor: ['successCount', 'failureCount', 'totalCount'],
widthRatio: '10%',
renderCustomCell: (cellValue) => {
renderCustomCell: ({ cellValue }) => {
const [successCount, failureCount, totalCount] = cellValue as string[];
return (
<Styled.SendingStatus>
Expand Down
Loading

0 comments on commit 6994fe5

Please sign in to comment.