TimeLine.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { Timeline } from "antd";
  2. import { useEffect, useState } from "react";
  3. import { useIntl } from "react-intl";
  4. import { StartUpIcon, TermIcon2 } from "../../assets/icon";
  5. import { get } from "../../request";
  6. import TimeShow from "../general/TimeShow";
  7. interface IMilestone {
  8. date: string;
  9. event: string;
  10. }
  11. interface IUserMilestoneResponse {
  12. ok: boolean;
  13. message: string;
  14. data: IMilestone[];
  15. }
  16. interface IWidget {
  17. studioName?: string;
  18. }
  19. const TimeLineWidget = ({ studioName }: IWidget) => {
  20. const [milestone, setMilestone] = useState<IMilestone[]>([]);
  21. const intl = useIntl();
  22. useEffect(() => {
  23. if (typeof studioName === "undefined") {
  24. return;
  25. }
  26. get<IUserMilestoneResponse>(`/v2/user-milestone/${studioName}`).then(
  27. (json) => {
  28. if (json.ok) {
  29. setMilestone(
  30. json.data.sort((a, b) => {
  31. if (a.date > b.date) {
  32. return -1;
  33. } else {
  34. return 1;
  35. }
  36. })
  37. );
  38. }
  39. }
  40. );
  41. }, [studioName]);
  42. return (
  43. <>
  44. <Timeline mode="left" style={{ width: "100%" }}>
  45. {milestone.map((item, id) => {
  46. let icon = <></>;
  47. switch (item.event) {
  48. case "sign-in":
  49. icon = (
  50. <StartUpIcon style={{ fontSize: "2em", background: "unset" }} />
  51. );
  52. break;
  53. case "first-term":
  54. icon = <TermIcon2 style={{ fontSize: "2em" }} />;
  55. break;
  56. default:
  57. break;
  58. }
  59. return (
  60. <Timeline.Item
  61. style={{ backgroundColor: "unset" }}
  62. key={id}
  63. dot={icon}
  64. label={
  65. <TimeShow
  66. createdAt={item.date}
  67. showIcon={false}
  68. showLabel={false}
  69. />
  70. }
  71. >
  72. {intl.formatMessage({
  73. id: `labels.${item.event}`,
  74. })}
  75. </Timeline.Item>
  76. );
  77. })}
  78. </Timeline>
  79. </>
  80. );
  81. };
  82. export default TimeLineWidget;