2
0

SentAdd.tsx 1.3 KB

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