visuddhinanda 2 년 전
부모
커밋
cc67fe0a16

+ 0 - 79
dashboard/src/components/course/AcceptCourse.tsx

@@ -1,79 +0,0 @@
-/**
- * 学生接受课程管理员的邀请 参加课程
- */
-import { Button, message, Modal } from "antd";
-import { useIntl } from "react-intl";
-import { ExclamationCircleFilled } from "@ant-design/icons";
-
-import { put } from "../../request";
-import {
-  ICourseMemberData,
-  ICourseMemberResponse,
-  TCourseJoinMode,
-} from "../api/Course";
-
-const { confirm } = Modal;
-
-interface IWidget {
-  joinMode?: TCourseJoinMode;
-  currUser?: ICourseMemberData;
-  onStatusChanged?: Function;
-}
-const AcceptCourseWidget = ({
-  joinMode,
-  currUser,
-  onStatusChanged,
-}: IWidget) => {
-  const intl = useIntl();
-
-  const statusChange = (status: ICourseMemberData | undefined) => {
-    if (typeof onStatusChanged !== "undefined") {
-      onStatusChanged(status);
-    }
-  };
-  return (
-    <>
-      <Button
-        type="primary"
-        onClick={() => {
-          confirm({
-            title: "参加此课程吗?",
-            icon: <ExclamationCircleFilled />,
-            content: intl.formatMessage({
-              id: `course.join.mode.open.message`,
-            }),
-            onOk() {
-              return put<ICourseMemberData, ICourseMemberResponse>(
-                "/v2/course-member/" + currUser?.id,
-                {
-                  user_id: "",
-                  course_id: "",
-                  status: "accepted",
-                }
-              )
-                .then((json) => {
-                  console.log("leave", json);
-                  if (json.ok) {
-                    console.log("accepted", json.data);
-                    statusChange(json.data);
-                    message.success(
-                      intl.formatMessage({ id: "flashes.success" })
-                    );
-                  } else {
-                    message.error(json.message);
-                  }
-                })
-                .catch((error) => {
-                  message.error(error);
-                });
-            },
-          });
-        }}
-      >
-        参加
-      </Button>
-    </>
-  );
-};
-
-export default AcceptCourseWidget;

+ 0 - 79
dashboard/src/components/course/AcceptNotCourse.tsx

@@ -1,79 +0,0 @@
-/**
- * 学生接受课程管理员的邀请 参加课程
- */
-import { Button, message, Modal } from "antd";
-import { useIntl } from "react-intl";
-import { ExclamationCircleFilled } from "@ant-design/icons";
-
-import { put } from "../../request";
-import {
-  ICourseMemberData,
-  ICourseMemberResponse,
-  TCourseJoinMode,
-} from "../api/Course";
-
-const { confirm } = Modal;
-
-interface IWidget {
-  joinMode?: TCourseJoinMode;
-  currUser?: ICourseMemberData;
-  onStatusChanged?: Function;
-}
-const AcceptNotCourseWidget = ({
-  joinMode,
-  currUser,
-  onStatusChanged,
-}: IWidget) => {
-  const intl = useIntl();
-
-  const statusChange = (status: ICourseMemberData | undefined) => {
-    if (typeof onStatusChanged !== "undefined") {
-      onStatusChanged(status);
-    }
-  };
-  return (
-    <>
-      <Button
-        type="default"
-        onClick={() => {
-          confirm({
-            title: "拒绝参加此课程吗?",
-            icon: <ExclamationCircleFilled />,
-            content: intl.formatMessage({
-              id: "course.rejected.message",
-            }),
-            onOk() {
-              return put<ICourseMemberData, ICourseMemberResponse>(
-                "/v2/course-member/" + currUser?.id,
-                {
-                  user_id: "",
-                  course_id: "",
-                  status: "rejected",
-                }
-              )
-                .then((json) => {
-                  console.log("leave", json);
-                  if (json.ok) {
-                    console.log("rejected", json.data);
-                    statusChange(json.data);
-                    message.success(
-                      intl.formatMessage({ id: "flashes.success" })
-                    );
-                  } else {
-                    message.error(json.message);
-                  }
-                })
-                .catch((error) => {
-                  message.error(error);
-                });
-            },
-          });
-        }}
-      >
-        拒绝
-      </Button>
-    </>
-  );
-};
-
-export default AcceptNotCourseWidget;

+ 0 - 177
dashboard/src/components/course/JoinCourse.tsx

@@ -1,177 +0,0 @@
-/**
- * 报名按钮
- * 已经报名显示报名状态
- * 未报名显示报名按钮以及必要的提示
- */
-import { Button, message, Modal, Space, Typography } from "antd";
-import { useEffect, useState } from "react";
-import { useIntl } from "react-intl";
-import { ExclamationCircleFilled } from "@ant-design/icons";
-
-import { useAppSelector } from "../../hooks";
-import { currentUser as _currentUser } from "../../reducers/current-user";
-import { get, post } from "../../request";
-import {
-  ICourseMemberData,
-  ICourseMemberListResponse,
-  ICourseMemberResponse,
-  TCourseExpRequest,
-  TCourseJoinMode,
-} from "../api/Course";
-import LeaveCourse from "./LeaveCourse";
-import AcceptCourse from "./AcceptCourse";
-import AcceptNotCourse from "./AcceptNotCourse";
-
-const { confirm } = Modal;
-const { Text } = Typography;
-
-interface IWidget {
-  courseId: string;
-  startAt?: string;
-  joinMode?: TCourseJoinMode;
-  expRequest?: TCourseExpRequest;
-}
-const JoinCourseWidget = ({
-  courseId,
-  joinMode,
-  startAt,
-  expRequest,
-}: IWidget) => {
-  const user = useAppSelector(_currentUser);
-  const intl = useIntl();
-  const [currMember, setCurrMember] = useState<ICourseMemberData>();
-
-  const today = new Date();
-  const courseStart = new Date(startAt ? startAt : "3000-01-01");
-  /**
-   * 获取该课程报名状态
-   */
-  const loadStatus = () => {
-    const url = `/v2/course-member?view=user&course=${courseId}`;
-    console.log(url);
-    get<ICourseMemberListResponse>(url).then((json) => {
-      console.log("course member", json);
-      if (json.ok) {
-        let role: string[] = [];
-        for (const iterator of json.data.rows) {
-          if (typeof iterator.role !== "undefined") {
-            role.push(iterator.role);
-            setCurrMember(iterator);
-          }
-        }
-      }
-    });
-  };
-  useEffect(loadStatus, [courseId]);
-
-  let button = <></>;
-  let labelStatus = "";
-  if (currMember?.role === "student") {
-    labelStatus = intl.formatMessage({
-      id: `course.member.status.${currMember.status}.label`,
-    });
-    if (currMember.status === "accepted" || currMember.status === "sign_up") {
-      button = (
-        <LeaveCourse
-          joinMode={joinMode}
-          currUser={currMember}
-          onStatusChanged={() => {
-            loadStatus();
-          }}
-        />
-      );
-    } else if (currMember.status === "invited") {
-      button = (
-        <Space>
-          <AcceptCourse
-            joinMode={joinMode}
-            currUser={currMember}
-            onStatusChanged={() => {
-              loadStatus();
-            }}
-          />
-          <AcceptNotCourse
-            joinMode={joinMode}
-            currUser={currMember}
-            onStatusChanged={() => {
-              loadStatus();
-            }}
-          />
-        </Space>
-      );
-    }
-  } else if (currMember?.role === "assistant") {
-    labelStatus = "助理老师";
-  } else {
-    if (courseStart > today) {
-      button = (
-        <Button
-          type="primary"
-          onClick={() => {
-            confirm({
-              title: "你想要报名课程吗?",
-              icon: <ExclamationCircleFilled />,
-              content: (
-                <div>
-                  <div>
-                    {intl.formatMessage({
-                      id: `course.join.mode.${joinMode}.message`,
-                    })}
-                  </div>
-                  <Text type="danger">
-                    {intl.formatMessage({
-                      id: `course.exp.request.${expRequest}.message`,
-                    })}
-                  </Text>
-                </div>
-              ),
-              onOk() {
-                return post<ICourseMemberData, ICourseMemberResponse>(
-                  "/v2/course-member",
-                  {
-                    user_id: user?.id ? user?.id : "",
-                    role: "student",
-                    course_id: courseId ? courseId : "",
-                    operating: "sign_up",
-                  }
-                )
-                  .then((json) => {
-                    console.log("add member", json);
-                    if (json.ok) {
-                      console.log("new", json.data);
-                      setCurrMember({
-                        role: "student",
-                        course_id: courseId,
-                        user_id: json.data.user_id,
-                        status: json.data.status,
-                      });
-                      message.success(
-                        intl.formatMessage({ id: "flashes.success" })
-                      );
-                    } else {
-                      message.error(json.message);
-                    }
-                  })
-                  .catch((error) => {
-                    message.error(error);
-                  });
-              },
-            });
-          }}
-        >
-          报名
-        </Button>
-      );
-    } else {
-      labelStatus = "已经过期";
-    }
-  }
-  return (
-    <div>
-      <Text>{labelStatus}</Text>
-      {button}
-    </div>
-  );
-};
-
-export default JoinCourseWidget;