import { Menu, MenuItem, Typography } from "@material-ui/core"; import { CollectionList_collections_edges_node_channelListings } from "@saleor/collections/types/CollectionList"; import Hr from "@saleor/components/Hr"; import StatusLabel from "@saleor/components/StatusLabel"; import useDateLocalize from "@saleor/hooks/useDateLocalize"; import React from "react"; import { FormattedMessage, useIntl } from "react-intl"; import { useStyles } from "./styles"; type Channels = Pick< CollectionList_collections_edges_node_channelListings, "isPublished" | "publicationDate" | "channel" >; export interface ChannelsAvailabilityDropdownProps { allChannelsCount: number; channels: Channels[]; currentChannel: Channels; } const isActive = (channelData: Channels) => channelData?.isPublished; export const ChannelsAvailabilityDropdown: React.FC = ({ allChannelsCount, channels, currentChannel }) => { const intl = useIntl(); const classes = useStyles({}); const localizeDate = useDateLocalize(); const [anchorEl, setAnchorEl] = React.useState(null); const handleClick = event => setAnchorEl(event.currentTarget); const handleClose = () => setAnchorEl(null); return (
e.stopPropagation()}>

{channels.map(channelData => { const notPublishedText = intl.formatMessage( { defaultMessage: "Will become available on {date}", description: "product channel publication date" }, { date: localizeDate(channelData.publicationDate, "L") } ); const publishedText = intl.formatMessage( { defaultMessage: "published since {date}", description: "product channel publication date" }, { date: localizeDate(channelData.publicationDate, "L") } ); return (
{channelData.isPublished && channelData.publicationDate ? publishedText : channelData.publicationDate && !channelData.isPublished ? notPublishedText : channelData.isPublished ? "" : intl.formatMessage({ defaultMessage: "hidden", description: "product channel publication status" })}
); })}
); }; ChannelsAvailabilityDropdown.displayName = "ChannelsAvailabilityDropdown"; export default ChannelsAvailabilityDropdown;