Skip to content

Commit

Permalink
chore: dev 머지
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene028 committed Aug 27, 2024
2 parents 025d11e + a987977 commit 8aa44f3
Show file tree
Hide file tree
Showing 55 changed files with 1,113 additions and 322 deletions.
14 changes: 13 additions & 1 deletion apps/admin/apis/auth/dashboardApi.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { fetcher } from "@wow-class/utils";
import { apiPath } from "constants/apiPath";
import { apiPath, mentorApiPath } from "constants/apiPath";
import { tags } from "constants/tags";
import type { DashboardApiResponseDto } from "types/dtos/auth";
import type { MyStudyListApiResponseDto } from "types/dtos/studyList";

export const dashboardApi = {
getDashboardInfo: async () => {
const response = await fetcher.get<DashboardApiResponseDto>(
apiPath.dashboard,
{
next: { tags: [tags.dashboard] },
cache: "no-store",
}
);

Expand All @@ -17,4 +19,14 @@ export const dashboardApi = {

return { studyRole, manageRole };
},
getMyStudyList: async () => {
const response = await fetcher.get<MyStudyListApiResponseDto[]>(
mentorApiPath.studyList,
{
next: { tags: [tags.dashboard] },
cache: "force-cache",
}
);
return response.data;
},
};
38 changes: 38 additions & 0 deletions apps/admin/apis/study/studyApi.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { fetcher } from "@wow-class/utils";
import { apiPath, mentorApiPath } from "constants/apiPath";
import { tags } from "constants/tags";
import type { AnnouncementApiResponseDto } from "types/dtos/announcement";
import type { AssignmentApiResponseDto } from "types/dtos/assignmentList";
import type { SessionApiResponseDto } from "types/dtos/sessionList";
import type { StudyBasicInfoApiResponseDto } from "types/dtos/studyBasicInfo";
import type { StudyAnnouncementType } from "types/entities/study";

import type { StudyListApiResponseDto } from "../../types/dtos/studyList";

Expand Down Expand Up @@ -56,4 +58,40 @@ export const studyApi = {
);
return response.data;
},
publishStudyAnnouncement: async (
studyId: number,
announcement: StudyAnnouncementType
) => {
const response = await fetcher.post(
`/mentor/studies/${studyId}/announcements`,
announcement
);
return { success: response.ok };
},
getStudyAnnouncement: async (studyId: number) => {
const response = await fetcher.get<AnnouncementApiResponseDto[]>(
`/common/studies/${studyId}/announcements`,
{
next: { tags: [tags.announcements] },
cache: "force-cache",
}
);
return response.data;
},
modifyStudyAnnouncement: async (
studyAnnouncementId: number,
announcement: StudyAnnouncementType
) => {
const response = await fetcher.put(
`/mentor/studies/announcements/${studyAnnouncementId}`,
announcement
);
return { success: response.ok };
},
deleteStudyAnnouncement: async (studyAnnouncementId: number) => {
const response = await fetcher.delete(
`/mentor/studies/announcements/${studyAnnouncementId}`
);
return { success: response.ok };
},
};
1 change: 0 additions & 1 deletion apps/admin/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import "wowds-ui/styles.css";
import "@wow-class/ui/styles.css";

import { JotaiProvider } from "components/JotaiProvider";
import Navbar from "components/Navbar";
import type { Metadata } from "next";
import type { ReactNode } from "react";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"use client";

import { Flex } from "@styled-system/jsx";
import { Modal, Space, Text } from "@wow-class/ui";
import { useModalRoute } from "@wow-class/ui/hooks";
import { studyApi } from "apis/study/studyApi";
import { tags } from "constants/tags";
import { useSearchParams } from "next/navigation";
import { revalidateTagByName } from "utils/revalidateTagByName";
import Button from "wowds-ui/Button";

const AnnouncementDeleteModal = () => {
const searchParams = useSearchParams();

const studyAnnouncementId = searchParams.get("studyAnnouncementId");

const { closeModal } = useModalRoute();

const handleClickDeleteButton = async () => {
const result = await studyApi.deleteStudyAnnouncement(
Number(studyAnnouncementId)
);
if (result.success) {
await revalidateTagByName(tags.announcements);
closeModal();
}
};

return (
<Modal>
<Flex direction="column" textAlign="center" width="21rem">
<Text typo="h1">공지를 삭제하시겠어요?</Text>
<Space height={33} />

<Flex gap="sm">
<Button variant="outline" onClick={closeModal}>
취소
</Button>
<Button onClick={handleClickDeleteButton}>삭제하기</Button>
</Flex>
</Flex>
</Modal>
);
};

export default AnnouncementDeleteModal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"use client";

import { Flex } from "@styled-system/jsx";
import { Modal, Space, Text } from "@wow-class/ui";
import { useModalRoute } from "@wow-class/ui/hooks";
import { studyApi } from "apis/study/studyApi";
import { tags } from "constants/tags";
import { useSearchParams } from "next/navigation";
import { useState } from "react";
import type { StudyAnnouncementType } from "types/entities/study";
import { revalidateTagByName } from "utils/revalidateTagByName";
import Button from "wowds-ui/Button";
import TextField from "wowds-ui/TextField";

const AnnouncementModifyModal = () => {
const searchParams = useSearchParams();
const [studyAnnouncement, setStudyAnnouncement] =
useState<StudyAnnouncementType>({
title: "",
link: "",
});

const studyAnnouncementId = searchParams.get("studyAnnouncementId");

const { closeModal } = useModalRoute();

const handleClickModifyButton = async () => {
const result = await studyApi.modifyStudyAnnouncement(
Number(studyAnnouncementId),
studyAnnouncement
);
if (result.success) {
await revalidateTagByName(tags.announcements);
closeModal();
}
};

return (
<Modal>
<Flex direction="column" textAlign="center" width="21rem">
<Text typo="h1">공지를 수정해주세요</Text>
<Space height={29} />
<Flex direction="column" gap="1.125rem">
<TextField
label="공지 제목"
placeholder="입력해주세요"
onChange={(value) => {
setStudyAnnouncement({ ...studyAnnouncement, title: value });
}}
/>
<TextField
label="공지 링크"
placeholder="http://example.com"
onChange={(value) => {
setStudyAnnouncement({ ...studyAnnouncement, link: value });
}}
/>
</Flex>
<Space height={28} />
<Flex gap="sm">
<Button variant="outline" onClick={closeModal}>
취소
</Button>
<Button onClick={handleClickModifyButton}>수정하기</Button>
</Flex>
</Flex>
</Modal>
);
};

export default AnnouncementModifyModal;
5 changes: 5 additions & 0 deletions apps/admin/app/studies/[studyId]/@modal/default.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Default = () => {
return null;
};

export default Default;
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"use client";

import { css } from "@styled-system/css";
import { Flex } from "@styled-system/jsx";
import { Text } from "@wow-class/ui";
import { studyApi } from "apis/study/studyApi";
import { tags } from "constants/tags";
import { useState } from "react";
import type { StudyAnnouncementType } from "types/entities/study";
import { revalidateTagByName } from "utils/revalidateTagByName";
import Button from "wowds-ui/Button";
import TextField from "wowds-ui/TextField";

const CreateStudyAnnouncement = ({ studyId }: { studyId: string }) => {
const [studyAnnouncement, setStudyAnnouncement] =
useState<StudyAnnouncementType>({
title: "",
link: "",
});

const handlePublishAnnouncement = async (studyId: string) => {
const { success } = await studyApi.publishStudyAnnouncement(
parseInt(studyId, 10),
studyAnnouncement
);
if (success) {
revalidateTagByName(tags.announcements);
setStudyAnnouncement({
title: "",
link: "",
});
} else {
console.log("공지 생성 실패");
}
};
return (
<div className={StudyAnnouncementBoxStyle}>
<Text typo="h2">공지를 작성해주세요.</Text>
<Flex gap="xl" justify="space-between" width="100%">
<Flex gap="sm" justifyContent="stretch" width="100%">
<TextField
label="공지 제목"
placeholder="입력해주세요"
style={{ width: "100%" }}
value={studyAnnouncement.title}
onChange={(value) => {
setStudyAnnouncement({ ...studyAnnouncement, title: value });
}}
/>
<TextField
label="공지 링크"
placeholder="http://example.com"
style={{ width: "100%" }}
value={studyAnnouncement.link}
onChange={(value) => {
setStudyAnnouncement({ ...studyAnnouncement, link: value });
}}
/>
</Flex>
<Button
size="sm"
style={{ minWidth: "92px", maxHeight: "38px", marginTop: "23px" }}
variant="solid"
disabled={
studyAnnouncement.link === "" || studyAnnouncement.title === ""
}
onClick={() => handlePublishAnnouncement(studyId)}
>
공지 발행
</Button>
</Flex>
</div>
);
};

export default CreateStudyAnnouncement;

const StudyAnnouncementBoxStyle = css({
width: "100%",
height: "171px",
backgroundColor: "backgroundAlternative",
borderRadius: "md",
display: "flex",
flexDirection: "column",
gap: "24px",
padding: "30px",
});
Loading

0 comments on commit 8aa44f3

Please sign in to comment.