| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- import React, { useEffect, useState } from "react";
- import { Modal } from "antd";
- import type { ArticleType } from "../article/Article";
- import ChannelTable, { type IChapter } from "./ChannelTable";
- import { useAppSelector } from "../../hooks";
- import { currentUser as _currentUser } from "../../reducers/current-user";
- import type { IChannel } from "./Channel";
- import type { TChannelType } from "../../api/Channel";
- import { useIntl } from "react-intl";
- interface IWidget {
- trigger?: React.ReactNode;
- channelType?: TChannelType;
- type?: ArticleType | "editable";
- articleId?: string;
- multiSelect?: boolean;
- disableChannels?: string[];
- open?: boolean;
- chapter?: IChapter;
- onClose?: () => void;
- onSelect?: (channel: IChannel) => void;
- }
- const ChannelTableModalWidget = ({
- trigger,
- type,
- disableChannels,
- channelType,
- open = false,
- chapter,
- onClose,
- onSelect,
- }: IWidget) => {
- const [isModalOpen, setIsModalOpen] = useState(open);
- const intl = useIntl();
- const user = useAppSelector(_currentUser);
- useEffect(() => {
- setIsModalOpen(open);
- }, [open]);
- const showModal = () => {
- setIsModalOpen(true);
- };
- const handleOk = () => {
- setIsModalOpen(false);
- if (typeof onClose !== "undefined") {
- onClose();
- }
- };
- const handleCancel = () => {
- setIsModalOpen(false);
- if (typeof onClose !== "undefined") {
- onClose();
- }
- };
- return (
- <>
- <span onClick={showModal}>{trigger}</span>
- <Modal
- width={"90%"}
- title={intl.formatMessage({
- id: "buttons.select.channel",
- })}
- destroyOnClose
- footer={false}
- open={isModalOpen}
- onOk={handleOk}
- onCancel={handleCancel}
- >
- <div style={{ overflowX: "scroll" }}>
- <ChannelTable
- studioName={user?.realName}
- type={type}
- chapter={chapter}
- channelType={channelType}
- disableChannels={disableChannels}
- onSelect={(channel: IChannel) => {
- handleCancel();
- if (typeof onClose !== "undefined") {
- onClose();
- }
- if (typeof onSelect !== "undefined") {
- onSelect(channel);
- }
- }}
- />
- </div>
- </Modal>
- </>
- );
- };
- export default ChannelTableModalWidget;
|