SentAdd.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Button } from "antd";
  2. import { useState } from "react";
  3. import { PlusOutlined } from "@ant-design/icons";
  4. import { IChannel } from "../../channel/Channel";
  5. import ChannelTableModal from "../../channel/ChannelTableModal";
  6. import { TChannelType } from "../../api/Channel";
  7. interface IWidget {
  8. disableChannels?: string[];
  9. type?: TChannelType;
  10. onSelect?: Function;
  11. }
  12. const Widget = ({
  13. disableChannels,
  14. type = "translation",
  15. onSelect,
  16. }: IWidget) => {
  17. const [channelPickerOpen, setChannelPickerOpen] = useState(false);
  18. return (
  19. <ChannelTableModal
  20. disableChannels={disableChannels}
  21. channelType={type}
  22. trigger={
  23. <Button
  24. type="dashed"
  25. style={{ width: 300 }}
  26. icon={<PlusOutlined />}
  27. onClick={() => {
  28. setChannelPickerOpen(true);
  29. }}
  30. >
  31. Add
  32. </Button>
  33. }
  34. open={channelPickerOpen}
  35. onClose={() => setChannelPickerOpen(false)}
  36. onSelect={(channel: IChannel) => {
  37. setChannelPickerOpen(false);
  38. if (typeof onSelect !== "undefined") {
  39. onSelect(channel);
  40. }
  41. }}
  42. />
  43. );
  44. };
  45. export default Widget;