create generic availability status label component

This commit is contained in:
sektordv 2021-08-04 16:24:14 +02:00
parent c21f76f86e
commit 3233b46aec
9 changed files with 19 additions and 66 deletions

View file

@ -1,2 +0,0 @@
export { default } from "./CollectionAvailabilityStatusLabel";
export * from "./CollectionAvailabilityStatusLabel";

View file

@ -1,16 +0,0 @@
import { defineMessages } from "react-intl";
export const messages = defineMessages({
published: {
defaultMessage: "Published on {date}",
description: "collection publication date"
},
unpublished: {
defaultMessage: "Unpublished",
description: "collection publication date"
},
willBePublished: {
defaultMessage: "Becomes published on {date}",
description: "collection publication date"
}
});

View file

@ -1,6 +1,7 @@
import { TableBody, TableCell, TableFooter, TableRow } from "@material-ui/core"; import { TableBody, TableCell, TableFooter, TableRow } from "@material-ui/core";
import { CollectionListUrlSortField } from "@saleor/collections/urls"; import { CollectionListUrlSortField } from "@saleor/collections/urls";
import { canBeSorted } from "@saleor/collections/views/CollectionList/sort"; import { canBeSorted } from "@saleor/collections/views/CollectionList/sort";
import AvailabilityStatusLabel from "@saleor/components/AvailabilityStatusLabel";
import { ChannelsAvailabilityDropdown } from "@saleor/components/ChannelsAvailabilityDropdown"; import { ChannelsAvailabilityDropdown } from "@saleor/components/ChannelsAvailabilityDropdown";
import Checkbox from "@saleor/components/Checkbox"; import Checkbox from "@saleor/components/Checkbox";
import ResponsiveTable from "@saleor/components/ResponsiveTable"; import ResponsiveTable from "@saleor/components/ResponsiveTable";
@ -16,7 +17,6 @@ import React from "react";
import { FormattedMessage } from "react-intl"; import { FormattedMessage } from "react-intl";
import { CollectionList_collections_edges_node } from "../../types/CollectionList"; import { CollectionList_collections_edges_node } from "../../types/CollectionList";
import CollectionAvailabilityStatusLabel from "../CollectionAvailabilityStatusLabel";
const useStyles = makeStyles( const useStyles = makeStyles(
theme => ({ theme => ({
@ -189,7 +189,10 @@ const CollectionList: React.FC<CollectionListProps> = props => {
{(!collection && <Skeleton />) || {(!collection && <Skeleton />) ||
(!collection?.channelListings?.length && "-") || (!collection?.channelListings?.length && "-") ||
(collection?.channelListings !== undefined && channel ? ( (collection?.channelListings !== undefined && channel ? (
<CollectionAvailabilityStatusLabel channel={channel} /> <AvailabilityStatusLabel
channel={channel}
type="collection"
/>
) : ( ) : (
<ChannelsAvailabilityDropdown <ChannelsAvailabilityDropdown
allChannelsCount={channelsCount} allChannelsCount={channelsCount}

View file

@ -5,7 +5,7 @@ import { useIntl } from "react-intl";
import { messages } from "./messages"; import { messages } from "./messages";
export const CollectionAvailabilityStatusLabel = ({ channel }) => { export const AvailabilityStatusLabel = ({ channel, type }) => {
const intl = useIntl(); const intl = useIntl();
const localizeDate = useDateLocalize(); const localizeDate = useDateLocalize();
@ -18,7 +18,8 @@ export const CollectionAvailabilityStatusLabel = ({ channel }) => {
: messages.willBePublished : messages.willBePublished
: messages.unpublished, : messages.unpublished,
{ {
date: localizeDate(channel.publicationDate, "L") date: localizeDate(channel.publicationDate, "L"),
type: type || ""
} }
)} )}
status={ status={
@ -32,4 +33,4 @@ export const CollectionAvailabilityStatusLabel = ({ channel }) => {
); );
}; };
export default CollectionAvailabilityStatusLabel; export default AvailabilityStatusLabel;

View file

@ -0,0 +1,2 @@
export { default } from "./AvailabilityStatusLabel";
export * from "./AvailabilityStatusLabel";

View file

@ -3,14 +3,14 @@ import { defineMessages } from "react-intl";
export const messages = defineMessages({ export const messages = defineMessages({
published: { published: {
defaultMessage: "Published on {date}", defaultMessage: "Published on {date}",
description: "product publication date" description: "{type} publication date"
}, },
unpublished: { unpublished: {
defaultMessage: "Unpublished", defaultMessage: "Unpublished",
description: "product publication date" description: "{type} publication date"
}, },
willBePublished: { willBePublished: {
defaultMessage: "Becomes published on {date}", defaultMessage: "Becomes published on {date}",
description: "product publication date" description: "{type} publication date"
} }
}); });

View file

@ -1,35 +0,0 @@
import StatusLabel from "@saleor/components/StatusLabel";
import useDateLocalize from "@saleor/hooks/useDateLocalize";
import React from "react";
import { useIntl } from "react-intl";
import { messages } from "./messages";
export const ProductAvailabilityStatusLabel = ({ channel }) => {
const intl = useIntl();
const localizeDate = useDateLocalize();
return (
<StatusLabel
label={intl.formatMessage(
channel.publicationDate
? channel.isPublished
? messages.published
: messages.willBePublished
: messages.unpublished,
{
date: localizeDate(channel.publicationDate, "L")
}
)}
status={
channel.publicationDate
? channel.isPublished
? "success"
: "alert"
: "error"
}
/>
);
};
export default ProductAvailabilityStatusLabel;

View file

@ -1,2 +0,0 @@
export { default } from "./ProductAvailabilityStatusLabel";
export * from "./ProductAvailabilityStatusLabel";

View file

@ -5,6 +5,7 @@ import {
TableRow, TableRow,
Typography Typography
} from "@material-ui/core"; } from "@material-ui/core";
import AvailabilityStatusLabel from "@saleor/components/AvailabilityStatusLabel";
import { ChannelsAvailabilityDropdown } from "@saleor/components/ChannelsAvailabilityDropdown"; import { ChannelsAvailabilityDropdown } from "@saleor/components/ChannelsAvailabilityDropdown";
import Checkbox from "@saleor/components/Checkbox"; import Checkbox from "@saleor/components/Checkbox";
import MoneyRange from "@saleor/components/MoneyRange"; import MoneyRange from "@saleor/components/MoneyRange";
@ -35,8 +36,6 @@ import classNames from "classnames";
import React from "react"; import React from "react";
import { FormattedMessage } from "react-intl"; import { FormattedMessage } from "react-intl";
import ProductAvailabilityStatusLabel from "../ProductAvailabilityStatusLabel";
const useStyles = makeStyles( const useStyles = makeStyles(
theme => ({ theme => ({
[theme.breakpoints.up("lg")]: { [theme.breakpoints.up("lg")]: {
@ -376,7 +375,10 @@ export const ProductList: React.FC<ProductListProps> = props => {
{(!product && <Skeleton />) || {(!product && <Skeleton />) ||
(!product?.channelListings?.length && "-") || (!product?.channelListings?.length && "-") ||
(product?.channelListings !== undefined && channel ? ( (product?.channelListings !== undefined && channel ? (
<ProductAvailabilityStatusLabel channel={channel} /> <AvailabilityStatusLabel
channel={channel}
type="product"
/>
) : ( ) : (
<ChannelsAvailabilityDropdown <ChannelsAvailabilityDropdown
allChannelsCount={channelsCount} allChannelsCount={channelsCount}