Skip to content

Commit

Permalink
Merge pull request #1283 from academic-relations/act-professor-approval
Browse files Browse the repository at this point in the history
활동 보고서 페이지에 지도교수 승인 여부 정보 추가
  • Loading branch information
babycroc authored Dec 28, 2024
2 parents 7cb26a8 + 92d2185 commit 1f1f7e8
Show file tree
Hide file tree
Showing 23 changed files with 343 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,7 @@ export default class ActivityActivityTermService {
id: row.id,
name: row.name,
activityTypeEnumId: row.activityTypeEnumId,
startTerm: duration.reduce(
(prev, curr) => (prev < curr.startTerm ? prev : curr.startTerm),
duration[0].startTerm,
),
endTerm: duration.reduce(
(prev, curr) => (prev > curr.endTerm ? prev : curr.endTerm),
duration[0].endTerm,
),
durations: duration,
};
}),
);
Expand Down
12 changes: 2 additions & 10 deletions packages/api/src/feature/activity/service/activity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,7 @@ export default class ActivityService {
await this.activityRepository.selectDurationByActivityId(row.id);
return {
...row,
startTerm: duration.reduce(
(prev, curr) => (prev < curr.startTerm ? prev : curr.startTerm),
duration[0].startTerm,
),
endTerm: duration.reduce(
(prev, curr) => (prev > curr.endTerm ? prev : curr.endTerm),
duration[0].endTerm,
),
durations: duration,
};
}),
);
Expand All @@ -231,8 +224,7 @@ export default class ActivityService {
activityStatusEnumId: row.activityStatusEnumId,
name: row.name,
activityTypeEnumId: row.activityTypeEnumId,
startTerm: row.startTerm,
endTerm: row.endTerm,
durations: row.durations,
professorApprovedAt: row.professorApprovedAt,
}));
}
Expand Down
8 changes: 6 additions & 2 deletions packages/interface/src/api/activity/endpoint/apiAct005.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ const responseBodyMap = {
activityStatusEnumId: z.nativeEnum(ActivityStatusEnum),
name: z.string().max(255),
activityTypeEnumId: z.nativeEnum(ActivityTypeEnum),
startTerm: z.coerce.date(),
endTerm: z.coerce.date(),
durations: z.array(
z.object({
startTerm: z.coerce.date(),
endTerm: z.coerce.date(),
}),
),
professorApprovedAt: z.coerce.date().nullable(),
})
.array(),
Expand Down
8 changes: 6 additions & 2 deletions packages/interface/src/api/activity/endpoint/apiAct006.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ const responseBodyMap = {
id: z.coerce.number().int().min(1),
name: z.string().max(255),
activityTypeEnumId: z.nativeEnum(ActivityTypeEnum),
startTerm: z.coerce.date(),
endTerm: z.coerce.date(),
durations: z.array(
z.object({
startTerm: z.coerce.date(),
endTerm: z.coerce.date(),
}),
),
}),
),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {

import { ActivityProfessorApprovalEnum } from "@sparcs-clubs/web/features/manage-club/services/_mock/mockManageClub";

export const mockProfessorActivityReportData = [
export const mockActivityReportData = [
{
id: 1,
name: "2024 가을학기 신입생 프로그래밍 교육",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,27 @@ import {
} from "@tanstack/react-table";
import { useRouter } from "next/navigation";

import AsyncBoundary from "@sparcs-clubs/web/common/components/AsyncBoundary";
import Table from "@sparcs-clubs/web/common/components/Table";
import Tag from "@sparcs-clubs/web/common/components/Tag";

import {
ActTypeTagList,
ApplyTagList,
ProfessorApprovalTagList,
} from "@sparcs-clubs/web/constants/tableTagList";

import { formatDate } from "@sparcs-clubs/web/utils/Date/formatDate";
import { getTagDetail } from "@sparcs-clubs/web/utils/getTagDetail";

import { type NewActivityReport } from "../types/activityReport";
import useGetCurrentActivityReportList from "../hooks/useGetCurrentActivityReportList";
import { ActivityReportTableData } from "../types/table";

interface ActivityReportListProps {
data?: NewActivityReport[];
interface CurrentActivityReportTableProps {
clubId: number;
}

const columnHelper = createColumnHelper<NewActivityReport>();
// TODO(ym). 지도교수 승인이 활보 정책 문서 보면 필요없을 것 같지만 혹시 몰라 동연측에 문의 중(결과 확인 후 삭제 예정)
// const getProfessorApprovalTagColor = (professorApproval: string): TagColor => {
// switch (professorApproval) {
// case "대기":
// return "GRAY";
// case "완료":
// return "GREEN";
// case "반려":
// return "RED";
// default:
// return "GRAY";
// }
// };

const columnHelper = createColumnHelper<ActivityReportTableData>();
const columns = [
columnHelper.accessor("activityStatusEnumId", {
header: "상태",
Expand All @@ -46,17 +37,18 @@ const columns = [
},
size: 0,
}),
// TODO(ym). 지도교수 승인이 활보 정책 문서 보면 필요없을 것 같지만 혹시 몰라 동연측에 문의 중(결과 확인 후 삭제 예정)
// columnHelper.accessor("professorApproval", {
// id: "professorApproval",
// header: "지도교수",
// cell: info => (
// <Tag color={getProfessorApprovalTagColor(info.getValue())}>
// {info.getValue()}
// </Tag>
// ),
// size: 0,
// }),
columnHelper.accessor("professorApproval", {
id: "professorApproval",
header: "지도교수",
cell: info => {
const { color, text } = getTagDetail(
info.getValue(),
ProfessorApprovalTagList,
);
return <Tag color={color}>{text}</Tag>;
},
size: 0,
}),
columnHelper.accessor("name", {
id: "activity",
header: "활동명",
Expand All @@ -72,7 +64,8 @@ const columns = [
size: 32,
}),
columnHelper.accessor(
row => `${formatDate(row.startTerm)} ~ ${formatDate(row.endTerm)}`,
row =>
`${formatDate(row.durations[0].startTerm)} ~ ${formatDate(row.durations[0].endTerm)}${row.durations.length > 1 ? ` 외 ${row.durations.length - 1}개` : ""}`,
{
id: "date-range",
header: "활동 기간",
Expand All @@ -82,23 +75,29 @@ const columns = [
),
];

const NewActivityReportList: React.FC<ActivityReportListProps> = ({
data = [],
const CurrentActivityReportTable: React.FC<CurrentActivityReportTableProps> = ({
clubId,
}) => {
const router = useRouter();

const { data, isLoading, isError } = useGetCurrentActivityReportList(clubId);

const table = useReactTable({
columns,
data,
getCoreRowModel: getCoreRowModel(),
enableSorting: false,
});

return (
<Table
table={table}
count={data.length}
onClick={row => router.push(`/manage-club/activity-report/${row.id}`)}
/>
<AsyncBoundary isLoading={isLoading} isError={isError}>
<Table
table={table}
count={data.length}
onClick={row => router.push(`/manage-club/activity-report/${row.id}`)}
/>
</AsyncBoundary>
);
};

export default NewActivityReportList;
export default CurrentActivityReportTable;
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";

import { ApiAct006ResponseOk } from "@sparcs-clubs/interface/api/activity/endpoint/apiAct006";
import {
createColumnHelper,
getCoreRowModel,
Expand All @@ -16,20 +15,18 @@ import Tag from "@sparcs-clubs/web/common/components/Tag";
import { ActTypeTagList } from "@sparcs-clubs/web/constants/tableTagList";

import { formatDate } from "@sparcs-clubs/web/utils/Date/formatDate";

import { getTagDetail } from "@sparcs-clubs/web/utils/getTagDetail";

import useGetPastActivityReportList from "../services/useGetPastActivityReportList";
import { ActivityTerm } from "../types/activityReport";
import useGetActivityTerm from "../hooks/useGetActivityTerm";
import useGetPastActivityReportList from "../hooks/useGetPastActivityReportList";
import { PastActivityReportTableData } from "../types/table";

interface ActivityReportListProps {
term: ActivityTerm;
interface PastActivityReportTableProps {
termId: number;
clubId: number;
}

const columnHelper =
createColumnHelper<ApiAct006ResponseOk["activities"][number]>();

const columnHelper = createColumnHelper<PastActivityReportTableData>();
const columns = [
columnHelper.accessor("name", {
id: "activity",
Expand All @@ -46,7 +43,8 @@ const columns = [
size: 32,
}),
columnHelper.accessor(
row => `${formatDate(row.startTerm)} ~ ${formatDate(row.endTerm)}`,
row =>
`${formatDate(row.durations[0].startTerm)} ~ ${formatDate(row.durations[0].endTerm)}${row.durations.length > 1 ? ` 외 ${row.durations.length - 1}개` : ""}`,
{
id: "date-range",
header: "활동 기간",
Expand All @@ -56,35 +54,39 @@ const columns = [
),
];

const PastActivityReportList: React.FC<ActivityReportListProps> = ({
term,
const PastActivityReportTable: React.FC<PastActivityReportTableProps> = ({
termId,
clubId,
}) => {
const router = useRouter();
const { data, isLoading, isError } = useGetPastActivityReportList(term.id, {

const { data: activityTerm } = useGetActivityTerm(clubId, termId);
const { data, isLoading, isError } = useGetPastActivityReportList(
termId,
clubId,
});
);

const table = useReactTable({
columns,
data: data?.activities ?? [],
data,
getCoreRowModel: getCoreRowModel(),
enableSorting: false,
});

return (
<AsyncBoundary isLoading={isLoading} isError={isError}>
<FoldableSection
key={term.id}
title={`${term.year}${term.name}학기 (총 ${data?.activities.length}개)`}
>
<FoldableSection
key={activityTerm.id}
title={`${activityTerm.year}${activityTerm.name}학기 (총 ${data.length}개)`}
>
<AsyncBoundary isLoading={isLoading} isError={isError}>
<Table
table={table}
onClick={row => router.push(`/manage-club/activity-report/${row.id}`)}
count={data?.activities.length}
count={data.length}
/>
</FoldableSection>
</AsyncBoundary>
</AsyncBoundary>
</FoldableSection>
);
};

export default PastActivityReportList;
export default PastActivityReportTable;
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import {
} from "@sparcs-clubs/web/constants/tableTagList";

import useGetProfessorActivityReportList from "@sparcs-clubs/web/features/activity-report/hooks/useGetProfessorActivityReportList";
import useProfessorApproveActivityReport from "@sparcs-clubs/web/features/activity-report/services/useProfessorApproveActivityReport";
import { ProfessorActivityReportTableData } from "@sparcs-clubs/web/features/activity-report/types/table";
import usePostProfessorApproveActivityReport from "@sparcs-clubs/web/features/activity-report/services/useProfessorApproveActivityReport";

import { ActivityReportTableData } from "@sparcs-clubs/web/features/activity-report/types/table";

import ProfessorApprovalEnum from "@sparcs-clubs/web/types/professorApproval";

Expand All @@ -36,7 +37,7 @@ interface ProfessorActivityReportTableProps {
clubId: number;
}

const columnHelper = createColumnHelper<ProfessorActivityReportTableData>();
const columnHelper = createColumnHelper<ActivityReportTableData>();
const columns = [
columnHelper.accessor("activityStatusEnumId", {
header: "상태",
Expand Down Expand Up @@ -87,18 +88,19 @@ const columns = [
const ProfessorActivityReportTable: React.FC<
ProfessorActivityReportTableProps
> = ({ clubId }) => {
const router = useRouter();

const { data, isLoading, isError } =
useGetProfessorActivityReportList(clubId);

const { mutate: approveActivityReport } = useProfessorApproveActivityReport();
const { mutate: approveActivityReport } =
usePostProfessorApproveActivityReport();

const table = useReactTable({
columns,
data,
getCoreRowModel: getCoreRowModel(),
enableSorting: false,
});
const router = useRouter();

const hasActivitiesToApprove = data.some(
activity => activity.professorApproval === ProfessorApprovalEnum.Pending,
Expand Down Expand Up @@ -128,8 +130,6 @@ const ProfessorActivityReportTable: React.FC<
));
};

if (!data) return null;

return (
<AsyncBoundary isLoading={isLoading} isError={isError}>
<FlexWrapper direction="row" gap={16} style={{ alignItems: "center" }}>
Expand Down
Loading

0 comments on commit 1f1f7e8

Please sign in to comment.