2
0

CopyToModal.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { useEffect, useState } from "react";
  2. import { Modal } from "antd";
  3. import CopyToStep from "./CopyToStep";
  4. import type { IChannel } from "./Channel";
  5. interface IWidget {
  6. trigger?: JSX.Element | string;
  7. channel?: IChannel;
  8. sentencesId?: string[];
  9. open?: boolean;
  10. important?: boolean;
  11. onClose?: Function;
  12. }
  13. const CopyToModal = ({
  14. trigger,
  15. channel,
  16. sentencesId,
  17. open,
  18. important = false,
  19. onClose,
  20. }: IWidget) => {
  21. const [isModalOpen, setIsModalOpen] = useState(open);
  22. const [initStep, setInitStep] = useState(0);
  23. useEffect(() => setIsModalOpen(open), [open]);
  24. const showModal = () => {
  25. setIsModalOpen(true);
  26. setInitStep(0);
  27. };
  28. const modalClose = () => {
  29. setIsModalOpen(false);
  30. if (typeof onClose !== "undefined") {
  31. onClose();
  32. }
  33. };
  34. const handleOk = () => {
  35. modalClose();
  36. };
  37. const handleCancel = () => {
  38. modalClose();
  39. };
  40. return (
  41. <>
  42. <span onClick={showModal}>{trigger}</span>
  43. <Modal
  44. width={"95%"}
  45. style={{ maxWidth: 1500 }}
  46. title="版本间复制"
  47. open={isModalOpen}
  48. onOk={handleOk}
  49. onCancel={handleCancel}
  50. destroyOnHidden={true}
  51. footer={[]}
  52. >
  53. <CopyToStep
  54. initStep={initStep}
  55. channel={channel}
  56. sentencesId={sentencesId}
  57. important={important}
  58. onClose={() => {
  59. setIsModalOpen(false);
  60. Modal.destroyAll();
  61. }}
  62. />
  63. </Modal>
  64. </>
  65. );
  66. };
  67. export default CopyToModal;