Skip to content

Commit 7d42c20

Browse files
authored
[Refactor] : 어드민 서비스 미들웨어 로직 추가 및 스터디 리스트 레이아웃 조정 (#94)
* chore: middleware 캐시 로직 추가 * fix: 오타 수정 * fix: 커리큘럼을 스터디로 변경해요 * feat: Navbar 클릭하면 메인페이지로 이동 * fix: 절대경로 변경 * fix: 스터디 상세 레이아웃 수정 * fix: url constants로 분리 * fix: error처리 삭제, 이름 변경 * fix: 어드민 전용으로 쿠키 이름 변경 * fix: 만료 시간 제거
1 parent 83eac0f commit 7d42c20

File tree

10 files changed

+64
-24
lines changed

10 files changed

+64
-24
lines changed

apps/admin/app/studies/[studyId]/layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const StudyLayout = ({
1414
};
1515

1616
const MainLayoutStyle = {
17-
height: "100vh",
17+
height: "100%",
1818
overflow: "auto",
1919
};
2020

apps/admin/app/studies/_components/StudyListItem.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ const StudyListItem = async ({ study }: { study: StudyListApiResponseDto }) => {
3030
{academicYear}-{semesterType === "FIRST" ? "1" : "2"}
3131
</Text>
3232
<Flex alignItems="center" gap="xs">
33-
<Text typo="h3">{title}</Text>
33+
<Text style={StudyNameStyle} typo="h3">
34+
{title}
35+
</Text>
3436
<Tag color={studyTypeColorMap[studyType]} variant="solid1">
3537
{studyType}
3638
</Tag>
@@ -70,8 +72,8 @@ const studyTypeColorMap: Record<
7072
ComponentProps<typeof Tag>["color"]
7173
> = {
7274
"과제 스터디": "green",
73-
"온라인 커리큘럼": "blue",
74-
"오프라인 커리큘럼": "yellow",
75+
"온라인 스터디": "blue",
76+
"오프라인 스터디": "yellow",
7577
};
7678

7779
const LinkStyle = {
@@ -83,12 +85,21 @@ const LinkStyle = {
8385

8486
const TableLeftStyle = {
8587
display: "flex",
88+
flex: 2,
8689
alignItems: "center",
8790
gap: "31px",
8891
};
8992

9093
const TableRightStyle = {
9194
display: "flex",
95+
flex: 3,
9296
alignItems: "center",
9397
gap: "64px",
9498
};
99+
100+
const StudyNameStyle = {
101+
whiteSpace: "nowrap",
102+
overflow: "hidden",
103+
textOverflow: "ellipsis",
104+
maxWidth: "150px",
105+
};

apps/admin/app/studies/create-study/_components/StudyBasicInformation/StudyFormatSelect.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const StudyFormatSelect = () => {
2323
value="OFFLINE"
2424
text={
2525
<Flex alignItems="center" gap="md">
26-
<Text typo="body1">오프라인 커리큘럼</Text>
26+
<Text typo="body1">오프라인 스터디</Text>
2727
<Text color="sub" typo="body2">
2828
오프라인으로 진행해요.
2929
</Text>
@@ -34,7 +34,7 @@ const StudyFormatSelect = () => {
3434
value="ONLINE"
3535
text={
3636
<Flex alignItems="center" gap="md">
37-
<Text typo="body1">온라인 커리큘럼</Text>
37+
<Text typo="body1">온라인 스터디</Text>
3838
<Text color="sub" typo="body2">
3939
온라인으로 진행해요.
4040
</Text>

apps/admin/constants/cookieKey.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const enum cookieKey {
2+
accessToken = "accessToken",
3+
"admin-middleware-executed" = "admin-middleware-executed",
4+
}

apps/admin/constants/url.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const clientUrl =
2+
process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
3+
? process.env.NEXT_PUBLIC_CLIENT_PROD_URL
4+
: process.env.NEXT_PUBLIC_CLIENT_DEV_URL;

apps/admin/hooks/useForm.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const useForm = () => {};
2+
3+
export default useForm;

apps/admin/middleware.ts

+25-14
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
11
import { dashboardApi } from "apis/auth/dashboardApi";
2+
import { cookieKey } from "constants/cookieKey";
3+
import { clientUrl } from "constants/url";
24
import { cookies } from "next/headers";
3-
import type { NextRequest } from "next/server";
45
import { NextResponse } from "next/server";
5-
6+
import setExpireTime from "utils/setExpireTime";
67
export const config = {
78
matcher: ["/studies/:path*", "/participants/:path*"],
89
};
910

10-
const middleware = async (req: NextRequest) => {
11+
const middleware = async () => {
1112
const cookieStore = cookies();
12-
const accessToken = cookieStore.get("accessToken")?.value;
13+
const accessToken = cookieStore.get(cookieKey.accessToken)?.value;
14+
const middlewareExecuted = cookieStore.get(
15+
cookieKey["admin-middleware-executed"]
16+
)?.value;
1317

1418
if (!accessToken) {
15-
return NextResponse.redirect(new URL("/not-found", req.url));
19+
return NextResponse.redirect(new URL("/auth", clientUrl));
1620
}
1721

18-
const { studyRole, manageRole } = await dashboardApi.getDashboardInfo();
19-
20-
if (studyRole === "STUDENT" && manageRole === "NONE") {
21-
const url =
22-
process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
23-
? process.env.NEXT_PUBLIC_CLIENT_PROD_URL
24-
: process.env.NEXT_PUBLIC_CLIENT_DEV_URL;
25-
26-
return NextResponse.redirect(new URL("/auth", url));
22+
if (!middlewareExecuted) {
23+
try {
24+
const { manageRole, studyRole } = await dashboardApi.getDashboardInfo();
25+
if (studyRole === "STUDENT" && manageRole === "NONE") {
26+
return NextResponse.redirect(new URL("/auth", clientUrl));
27+
}
28+
const response = NextResponse.next();
29+
response.cookies.set(cookieKey["admin-middleware-executed"], "true", {
30+
httpOnly: true,
31+
secure: true,
32+
sameSite: "lax",
33+
});
34+
return response;
35+
} catch (error) {
36+
return NextResponse.next();
37+
}
2738
}
2839

2940
return NextResponse.next();

apps/admin/types/entities/study.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export type StudyType = "ASSIGNMENT" | "ONLINE" | "OFFLINE";
1111

1212
export type StudyKoreanType =
1313
| "과제 스터디"
14-
| "온라인 커리큘럼"
15-
| "오프라인 커리큘럼";
14+
| "온라인 스터디"
15+
| "오프라인 스터디";
1616

1717
export type StudyCurriculumType = {
1818
studyDetailId: number;

apps/admin/utils/setExpireTime.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const setExpireTime = (hour: number) => {
2+
const expires = new Date();
3+
expires.setTime(expires.getTime() + hour * 60 * 60 * 1000);
4+
5+
return expires;
6+
};
7+
8+
export default setExpireTime;

packages/ui/src/components/NavItem/index.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ const NavItem = ({ href, imageUrl, alt, name, items }: NavItemProps) => {
5555
href={`${href}`}
5656
tabIndex={0}
5757
className={navItemStyle({
58-
type:
59-
!segment[1] && `/${segment[0]}` === href ? "active" : "inactive",
58+
type: !segment[1] && `${segment[0]}` === href ? "active" : "inactive",
6059
})}
6160
onClick={handleClickNavItem}
6261
>

0 commit comments

Comments
 (0)