Skip to content

Commit

Permalink
Merge pull request #1047 from academic-relations/dev
Browse files Browse the repository at this point in the history
merge dev into main
  • Loading branch information
pbc1017 authored Sep 6, 2024
2 parents a37d7c9 + 79db416 commit 7214e5f
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 45 deletions.
30 changes: 19 additions & 11 deletions packages/api/src/drizzle/schema/division.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
int,
mysqlTable,
timestamp,
unique,
varchar,
} from "drizzle-orm/mysql-core";

Expand Down Expand Up @@ -44,14 +45,21 @@ export const DivisionPresidentD = mysqlTable("division_president_d", {
deletedAt: timestamp("deleted_at"),
});

export const DivisionPermanentClubD = mysqlTable("division_permanent_club_d", {
id: int("id").autoincrement().primaryKey(),
clubId: int("club_id")
.unique()
.notNull()
.references(() => Club.id), // Assuming Club table exists
startTerm: date("start_term").notNull(),
endTerm: date("end_term"),
createdAt: timestamp("created_at").defaultNow(),
deletedAt: timestamp("deleted_at"),
});
export const DivisionPermanentClubD = mysqlTable(
"division_permanent_club_d",
{
id: int("id").autoincrement().primaryKey(),
clubId: int("club_id")
.notNull()
.references(() => Club.id), // Assuming Club table exists
startTerm: date("start_term").notNull(),
endTerm: date("end_term"),
createdAt: timestamp("created_at").defaultNow(),
deletedAt: timestamp("deleted_at"),
},
table => ({
DivisionPermanentClubDClubIdFk: unique(
"division_permanent_club_d_club_id_start_term_unique",
).on(table.clubId, table.startTerm),
}),
);
17 changes: 14 additions & 3 deletions packages/api/src/feature/club/repository/club.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default class ClubRepository {
id: Club.id,
name_kr: Club.name_kr,
name_en: Club.name_en,
isPermanent: sql`COALESCE(MAX(CASE WHEN ${DivisionPermanentClubD.id} IS NOT NULL THEN TRUE ELSE FALSE END), FALSE)`,
isPermanent: DivisionPermanentClubD.id,
characteristic: ClubT.characteristicKr,
representative: Student.name,
advisor: Professor.name,
Expand Down Expand Up @@ -143,7 +143,14 @@ export default class ClubRepository {
.leftJoin(Student, eq(ClubDelegateD.studentId, Student.id))
.leftJoin(
DivisionPermanentClubD,
eq(Club.id, DivisionPermanentClubD.clubId),
and(
eq(DivisionPermanentClubD.clubId, Club.id),
lte(DivisionPermanentClubD.startTerm, crt),
or(
gte(DivisionPermanentClubD.endTerm, crt),
isNull(DivisionPermanentClubD.endTerm),
),
),
)
.groupBy(
Division.id,
Expand All @@ -155,6 +162,7 @@ export default class ClubRepository {
ClubT.characteristicKr,
Student.name,
Professor.name,
DivisionPermanentClubD.id,
);
const record = rows.reduce<Record<number, IClubs>>((acc, row) => {
const divId = row.id;
Expand All @@ -167,7 +175,10 @@ export default class ClubRepository {
}

if (club) {
acc[divId].clubs.push({ ...club, isPermanent: club.isPermanent === 1 });
acc[divId].clubs.push({
...club,
isPermanent: club.isPermanent !== null,
});
}
return acc;
}, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
lt,
lte,
or,
sql,
} from "drizzle-orm";
import { MySql2Database } from "drizzle-orm/mysql2";

Expand Down Expand Up @@ -139,7 +138,7 @@ export class MemberRegistrationRepository {
clubId: RegistrationApplicationStudent.clubId,
clubNameKr: Club.name_kr,
type: ClubT.clubStatusEnumId,
isPermanent: sql<boolean>`COALESCE(MAX(CASE WHEN ${DivisionPermanentClubD.id} IS NOT NULL THEN TRUE ELSE FALSE END), FALSE)`,
isPermanent: DivisionPermanentClubD.id,
divisionName: Division.name,
applyStatusEnumId:
RegistrationApplicationStudent.registrationApplicationStudentEnumId,
Expand All @@ -159,7 +158,14 @@ export class MemberRegistrationRepository {
)
.leftJoin(
DivisionPermanentClubD,
eq(Club.id, DivisionPermanentClubD.clubId),
and(
eq(DivisionPermanentClubD.clubId, Club.id),
lte(DivisionPermanentClubD.startTerm, crt),
or(
gte(DivisionPermanentClubD.endTerm, crt),
isNull(DivisionPermanentClubD.endTerm),
),
),
)
.leftJoin(Division, eq(Division.id, Club.divisionId))
.where(
Expand All @@ -178,7 +184,13 @@ export class MemberRegistrationRepository {
isNull(RegistrationApplicationStudent.deletedAt),
),
);
return { applies: result };

return {
applies: result.map(item => ({
...item,
isPermanent: item.isPermanent !== null,
})),
};
}

async deleteMemberRegistration(
Expand Down
5 changes: 5 additions & 0 deletions packages/web/src/app/manage-club/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { useEffect, useState } from "react";
import AsyncBoundary from "@sparcs-clubs/web/common/components/AsyncBoundary";
import LoginRequired from "@sparcs-clubs/web/common/frames/LoginRequired";
import NoManageClub from "@sparcs-clubs/web/common/frames/NoManageClub";
import NoManageClubForProfessor from "@sparcs-clubs/web/common/frames/NoManageClubForProfessor";
import { useAuth } from "@sparcs-clubs/web/common/providers/AuthContext";
import ManageClubFrame from "@sparcs-clubs/web/features/manage-club/frames/ManageClubFrame";

Expand All @@ -26,6 +27,10 @@ const ManageClub: React.FC = () => {
return <LoginRequired login={login} />;
}

if (profile?.type === "professor") {
return <NoManageClubForProfessor />;
}

if (profile?.type !== "undergraduate") {
return <NoManageClub />;
}
Expand Down
59 changes: 59 additions & 0 deletions packages/web/src/common/frames/NoManageClubForProfessor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use client";

import { useRouter } from "next/navigation";

import styled from "styled-components";

import ErrorPageTemplate from "@sparcs-clubs/web/common/frames/ErrorPageTemplate";

import type { NextPage } from "next";

const ErrorMessage = styled.div`
color: ${({ theme }) => theme.colors.BLACK};
text-align: center;
font-family: ${({ theme }) => theme.fonts.FAMILY.PRETENDARD};
font-size: 32px;
font-weight: ${({ theme }) => theme.fonts.WEIGHT.MEDIUM};
line-height: 48px;
word-break: keep-all;
@media (max-width: ${({ theme }) => theme.responsive.BREAKPOINT.sm}) {
font-size: 28px;
}
@media (max-width: ${({ theme }) => theme.responsive.BREAKPOINT.xs}) {
font-size: 20px;
line-height: 32px;
}
`;

const NoManageClubForProfessor: NextPage = () => {
const router = useRouter();

const Message = (
<ErrorMessage>
지도교수는 동아리 대표자가 될 수 없습니다.
<br />
지도 동아리 확인은 마이페이지에서 가능합니다.
</ErrorMessage>
);

const goToMain = () => {
router.push("/");
};

const goToMy = () => {
router.push("/my");
};

return (
<ErrorPageTemplate
message={Message}
buttons={[
{ text: "메인 바로가기", onClick: goToMain },
{ text: "마이페이지 바로가기", onClick: goToMy },
]}
/>
);
};

export default NoManageClubForProfessor;
19 changes: 16 additions & 3 deletions packages/web/src/constants/tableTagList.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ActivityTypeEnum } from "@sparcs-clubs/interface/common/enum/activity.enum";
import {
ActivityStatusEnum,
ActivityTypeEnum,
} from "@sparcs-clubs/interface/common/enum/activity.enum";
import { ActivityCertificateOrderStatusEnum } from "@sparcs-clubs/interface/common/enum/activityCertificate.enum";
import { CommonSpaceUsageOrderStatusEnum } from "@sparcs-clubs/interface/common/enum/commonSpace.enum";
import { PromotionalPrintingOrderStatusEnum } from "@sparcs-clubs/interface/common/enum/promotionalPrinting.enum";
Expand All @@ -13,7 +16,6 @@ import { DivisionType } from "@sparcs-clubs/web/types/divisions.types";
import { TagColor } from "../common/components/Tag";
import {
ActivityProfessorApprovalEnum,
ActivityStatusEnum,
FundingStatusEnum,
MemberStatusEnum,
} from "../features/manage-club/services/_mock/mockManageClub";
Expand Down Expand Up @@ -98,10 +100,11 @@ const FundingTagList: {
[FundingStatusEnum.Rejected]: { text: "반려", color: "RED" },
};

// TODO: interface enum 사용
const ApplyTagList: {
[key in ActivityStatusEnum]: StatusDetail;
} = {
[ActivityStatusEnum.Committee]: { text: "운위", color: "ORANGE" },
// [ActivityStatusEnum.Committee]: { text: "운위", color: "ORANGE" },
[ActivityStatusEnum.Applied]: { text: "신청", color: "BLUE" },
[ActivityStatusEnum.Approved]: { text: "승인", color: "GREEN" },
[ActivityStatusEnum.Rejected]: { text: "반려", color: "RED" },
Expand Down Expand Up @@ -139,6 +142,15 @@ const ActTypeTagList: {
color: "PURPLE",
},
};

const ActStatusTagList: {
[key in ActivityStatusEnum]: StatusDetail;
} = {
[ActivityStatusEnum.Applied]: { text: "대기", color: "GRAY" },
[ActivityStatusEnum.Approved]: { text: "승인", color: "GREEN" },
[ActivityStatusEnum.Rejected]: { text: "반려", color: "RED" },
};

const RegistrationStatusTagList: {
[key in RegistrationStatusEnum]: StatusDetail;
} = {
Expand Down Expand Up @@ -180,6 +192,7 @@ export {
RntTagList,
MemTagList,
ApplyTagList,
ActStatusTagList,
ProfessorApprovalTagList,
ProfessorIsApprovedTagList,
ActTypeTagList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface ActivityReportListProps {
data: PastActivityReport[];
profile: string;
showItemCount?: boolean;
refetch?: () => void;
}

const columnHelper = createColumnHelper<PastActivityReport>();
Expand Down Expand Up @@ -69,6 +70,7 @@ const PastActivityReportList: React.FC<ActivityReportListProps> = ({
data,
profile,
showItemCount = true,
refetch = () => {},
}) => {
const table = useReactTable({
columns,
Expand All @@ -83,7 +85,10 @@ const PastActivityReportList: React.FC<ActivityReportListProps> = ({
profile={profile}
activityId={activityId}
isOpen={isOpen}
close={close}
close={() => {
close();
refetch();
}}
/>
));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ import React, { useEffect, useState } from "react";

import {
createColumnHelper,
FilterFn,
getCoreRowModel,
getFilteredRowModel,
getSortedRowModel,
Row,
RowSelectionState,
useReactTable,
} from "@tanstack/react-table";
import { hangulIncludes } from "es-hangul";
import styled from "styled-components";

import Card from "@sparcs-clubs/web/common/components/Card";
Expand Down Expand Up @@ -76,19 +73,7 @@ const columns = [
}),
];

const containsTextFilter: FilterFn<Participant> = (
row: Row<Participant>,
_: string,
filterValue: string,
) => {
const name = row.getValue<string>("name").toLowerCase();
const studentNumber = row.getValue<string>("studentNumber").toLowerCase();
const filterText = filterValue.toLowerCase();
return (
hangulIncludes(name, filterText) || studentNumber.startsWith(filterText)
);
};

// TODO: es hangul 검색 달기
const SelectParticipant: React.FC<SelectParticipantProps> = ({
data,
value = [],
Expand Down Expand Up @@ -136,7 +121,6 @@ const SelectParticipant: React.FC<SelectParticipantProps> = ({
handleRowClick(updaterOrValue);
}
},
globalFilterFn: containsTextFilter,
initialState: {
sorting: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import apiAct004, {
ApiAct004RequestParam,
} from "@sparcs-clubs/interface/api/activity/endpoint/apiAct004";
import { useMutation } from "@tanstack/react-query";
import { z } from "zod";

import {
axiosClientWithAuth,
UnexpectedAPIResponseError,
} from "@sparcs-clubs/web/lib/axios";

type ISuccessResponseType = z.infer<(typeof apiAct004.responseBodyMap)[200]>;

// TODO: (@dora) need new endpoint instead of ACT004

export const useDeleteActivityReportProvisional = () =>
useMutation<
ISuccessResponseType,
Error,
{ requestParam: ApiAct004RequestParam }
>({
mutationFn: async ({ requestParam }): Promise<ISuccessResponseType> => {
const { data, status } = await axiosClientWithAuth.delete(
`${apiAct004.url(requestParam.activityId)}/provisional`,
{},
);

switch (status) {
case 200:
return apiAct004.responseBodyMap[200].parse(data);
default:
throw new UnexpectedAPIResponseError();
}
},
});
Loading

0 comments on commit 7214e5f

Please sign in to comment.