AddToAnthology.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { Button, message } from "antd";
  2. import React from "react";
  3. import { post } from "../../request";
  4. import AnthologyModal from "../anthology/AnthologyModal";
  5. import { IArticleMapAddRequest, IArticleMapAddResponse } from "../api/Article";
  6. interface IWidget {
  7. trigger?: React.ReactNode;
  8. studioName?: string;
  9. articleIds?: string[];
  10. onFinally?: Function;
  11. }
  12. const Widget = ({ trigger, studioName, articleIds, onFinally }: IWidget) => {
  13. return (
  14. <AnthologyModal
  15. studioName={studioName}
  16. trigger={trigger ? trigger : <Button type="link">加入文集</Button>}
  17. onSelect={(id: string) => {
  18. if (typeof articleIds !== "undefined") {
  19. post<IArticleMapAddRequest, IArticleMapAddResponse>(
  20. "/v2/article-map",
  21. {
  22. anthology_id: id,
  23. article_id: articleIds,
  24. operation: "add",
  25. }
  26. )
  27. .finally(() => {
  28. if (typeof onFinally !== "undefined") {
  29. onFinally();
  30. }
  31. })
  32. .then((json) => {
  33. if (json.ok) {
  34. message.success(json.data);
  35. } else {
  36. message.error(json.message);
  37. }
  38. })
  39. .catch((e) => console.error(e));
  40. }
  41. }}
  42. />
  43. );
  44. };
  45. export default Widget;