Skip to content

Commit

Permalink
fix: conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene028 committed Sep 4, 2024
2 parents bd12241 + 8461887 commit e8af31b
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { createStudyApi } from "apis/study/createStudyApi";
import { routerPath } from "constants/router/routerPath";
import { tags } from "constants/tags";
import { useRouter } from "next/navigation";
import { useState } from "react";
import type { CreateStudyDetailInfoApiRequestDto } from "types/dtos/studyDetailInfo";
import { revalidateTagByName } from "utils/revalidateTagByName";

const useSubmitStudyDetailInfo = (
studyId: number,
studyDetailData: CreateStudyDetailInfoApiRequestDto
) => {
const [isSuccess, setIsSuccess] = useState(false);
const router = useRouter();

const handleSubmitDetailInfo = async () => {
const data = await createStudyApi.postStudyDetailInfo(
studyDetailData,
studyId
);
if (data.success) {
setIsSuccess(true);
revalidateTagByName(tags.curriculums);
const timerId = setTimeout(() => {
router.push(`${routerPath.root.href}/${studyId}`);
}, 500);
return () => clearTimeout(timerId);
} else {
setIsSuccess(false);
window.alert("스터디 상세 정보 저장에 실패했어요.");
router.push(`${routerPath.root.href}`);
}
};

return { isSuccess, handleSubmitDetailInfo };
};

export default useSubmitStudyDetailInfo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
"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 useParseSearchParams from "hooks/useParseSearchParams";
import { useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
import type { CreateStudyDetailInfoApiRequestDto } from "types/dtos/studyDetailInfo";
import Button from "wowds-ui/Button";

import useSubmitStudyDetailInfo from "./_hooks/useSubmitStudyDetailInfo";

const StudyDetailInfoCheckModal = () => {
const [studyName, setStudyName] = useState("");
const { onClose } = useModalRoute();
const { parseQueryString } = useParseSearchParams();
const searchParams = useSearchParams();
const { studyId, ...formData } = parseQueryString<
CreateStudyDetailInfoApiRequestDto & { studyId: string }
>(searchParams.toString());

const { isSuccess, handleSubmitDetailInfo } = useSubmitStudyDetailInfo(
parseInt(studyId, 10),
formData
);

useEffect(() => {
const fetchStudyData = async () => {
const response = await studyApi.getStudyBasicInfo(parseInt(studyId, 10));
if (response) setStudyName(response.title);
};
fetchStudyData();
}, [studyId]);

return (
<Modal>
<SubmitSuccessMessage studyName={studyName} success={isSuccess} />
<SubmitConfirmMessage
closeModal={onClose}
handleSubmitDetailInfo={handleSubmitDetailInfo}
studyName={studyName}
success={isSuccess}
/>
</Modal>
);
};

export default StudyDetailInfoCheckModal;

const SubmitSuccessMessage = ({
success,
studyName,
}: {
success: boolean;
studyName: string;
}) => {
return (
<>
{success && (
<Flex alignItems="center" direction="column" gap="4px">
<Text as="h1" color="primary" typo="h1">
{studyName}
</Text>
<Text as="h1" color="textBlack" typo="h1">
상세 정보가 저장되었어요.
</Text>
</Flex>
)}
</>
);
};

const SubmitConfirmMessage = ({
success,
studyName,
closeModal,
handleSubmitDetailInfo,
}: {
success: boolean;
studyName: string;
closeModal: () => void;
handleSubmitDetailInfo: () => void;
}) => {
if (!success) {
return (
<Flex alignItems="center" direction="column" padding="24px" width="100%">
<Flex alignItems="center" justify="center" marginBottom="2px">
<Text as="p" color="primary" typo="h1">
{studyName}
</Text>
<Text as="p" typo="h1">
의 상세정보
</Text>
</Flex>
<Text as="p" typo="h1">
입력 내용을 저장하시겠어요?
</Text>
<Space height={28} />
<Flex gap="sm" justify="center" width="21rem">
<Button variant="outline" onClick={closeModal}>
취소
</Button>
<Button onClick={handleSubmitDetailInfo}>저장하기</Button>
</Flex>
</Flex>
);
} else {
return;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Default = () => {
return null;
};

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

export default Default;
Empty file added apps/admin/constants/date.ts
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"use client";

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

const RepositoryUrlConfirmationModal = () => {
const searchParams = useSearchParams();
const url = searchParams.get("repositoryUrl");
//const studyHistoryId = useMatchedStudyHistoryId();

const handleClickSubmitButton = async () => {
//await studyHistoryApi.putRepository(studyHistoryId, url);
//TODO: 제출 후에 RepositoryBox 를 SUBMITTED 로 상태로 바꿔줘야함.
revalidateTagByName(tags.studyDetailDashboard);
};
return (
<Modal>
<Flex alignItems="center" direction="column" width="21rem">
<Text typo="h1">레포지토리를 입력하시겠어요?</Text>
<Space height={12} />
<Text color="sub">최초 과제 제출 전까지 수정이 가능해요.</Text>
<Space height={8} />
<div className={urlBoxStyle}>{url}</div>
<Space height={28} />
<Button onClick={handleClickSubmitButton}>입력하기</Button>
</Flex>
</Modal>
);
};

export default RepositoryUrlConfirmationModal;

const urlBoxStyle = css({
backgroundColor: "backgroundAlternative",
borderRadius: "5px",
color: "sub",
paddingX: "lg",
paddingY: "md",
textStyle: "h2",
});
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,5 @@
const Default = () => {
return null;
};

export default Default;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { routePath } from "constants/routePath";
import { redirect } from "next/navigation";

const RepositoryUrlConfirmationPage = () => {
return redirect(routePath["my-assignment"]);
};

export default RepositoryUrlConfirmationPage;
12 changes: 12 additions & 0 deletions apps/client/constants/assignmentSubmissionStatusMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { ComponentProps } from "react";
import type { AssignmentSubmissionStatusType } from "types/entities/common/assignment";
import type Tag from "wowds-ui/Tag";

export const assignmentSubmissionStatusMap: Record<
AssignmentSubmissionStatusType,
{ label: string; color: ComponentProps<typeof Tag>["color"] }
> = {
SUCCESS: { label: "제출 완료", color: "blue" },
FAILURE: { label: "제출 실패", color: "red" },
PENDING: { label: "과제 휴강", color: "grey" },
};
45 changes: 45 additions & 0 deletions apps/client/hooks/useFetchAttendanceCheckModalInfoData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { myStudyApi } from "apis/myStudyApi";
import { useEffect, useState } from "react";

const useFetchAttendanceCheckModalInfoData = () => {
const [studyInfo, setStudyInfo] = useState({
currentWeek: 0,
studyName: "",
});

useEffect(() => {
const fetchAttendanceCheckModalInfoData = async () => {
const myOngoingStudyData = await myStudyApi.getMyOngoingStudyInfo();

if (!myOngoingStudyData?.studyId) {
return null;
}

const dailyTaskListData = await myStudyApi.getDailyTaskList(
myOngoingStudyData?.studyId
);
const basicStudyInfoData = await myStudyApi.getBasicStudyInfo(
myOngoingStudyData?.studyId
);

const attendanceDailyTask = dailyTaskListData?.find(
(dailyTask) => dailyTask.todoType === "ATTENDANCE"
);

if (!attendanceDailyTask?.week || !basicStudyInfoData?.title) {
return null;
}

setStudyInfo({
currentWeek: attendanceDailyTask?.week,
studyName: basicStudyInfoData?.title,
});
};

fetchAttendanceCheckModalInfoData();
}, []);

return { studyInfo };
};

export default useFetchAttendanceCheckModalInfoData;
33 changes: 33 additions & 0 deletions apps/client/hooks/useMatchedStudyHistoryId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use client";

import { studyDetailApi } from "apis/studyDetailApi";
import { studyHistoryApi } from "apis/studyHistoryApi";
import { history, studyDashBoardData } from "constants/assignmentMockData";
import { useEffect, useState } from "react";

export default function useMatchedStudyHistoryId() {
const [matchedStudyHistoryId, setMatchedStudyHistoryId] = useState<number>();
useEffect(() => {
const fetchData = async () => {
//TODO: 수강 중인 스터디 api 호출
//const studyId = await myStudyApi.getMyOngoingStudyInfo();
//const studyHistories = await studyHistoryApi.getStudyHistory(studyId);
const studyHistories = history;
// const studyDashboard =
// await studyDetailApi.getStudyDetailDashboard(studyId);
const studyDashboard = studyDashBoardData;
if (studyHistories && studyDashboard) {
const submittableWeek = studyDashboard.submittableAssignments[0]?.week;
const matchedHistory = studyHistories.find(
(item) => item.week === submittableWeek
);

setMatchedStudyHistoryId(matchedHistory?.assignmentHistoryId);
}
};

fetchData();
}, []);

return { matchedStudyHistoryId };
}
1 change: 1 addition & 0 deletions apps/client/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as isDeadlinePassed } from "./isDeadlinePassed";

0 comments on commit e8af31b

Please sign in to comment.