saleor-dashboard/src/channels/ChannelsWithVariantsAvailabilityCard/ChannelWithVariantAvailabilityItemWrapper.tsx
Dominik Żegleń 62817568a7
Use MacawUI (#1229)
* Replace withStyleswith useStyles (#1100)

* Replace withStyleswith useStyles

* Update messages

* Use rem as a spacing unit (#1101)

* Use rems as spacing units

* Fix visual bugs

* Update stories

* Use macaw-ui as theme provider (#1108)

* Use macaw ui as a theme provider

* Add react-dom to aliases

* Fix jest module resolution

* Update useTheme hook usage

* Fix test wrapper

* Use macaw from git repo

* Fix CI

* Update stories

* Fix aliasing

* Extract savebar to macaw ui (#1146)

* wip

* Use savebar from macaw

* Use confirm button from macaw

* Improve file structure

* Use sidebar context from macaw

* Update macaw

* Update macaw version

* Remove savebar from storybook

* Update stories

* Use alerts and notifications from macaw (#1166)

* Use alerts from macaw

* Add notifications from macaw

* Update stories

* Pin macaw version

* Encapsulate limit reached in one component

* Remove unused imports

* Use backlinks from macaw (#1183)

* Use backlink from macaw

* Update macaw version

* Use macaw sidebar (#1148)

* Use sidebar from macaw

* Use shipped logo

* Use lowercase

* Update stories

* Use user chip from macaw (#1191)

* Use user chip from macaw

* Use dedicated components for menu items

* Simplify code

* Bump version and fix types (#1210)

* Rename onBack to onClick

* Rename UserChip to UserChipMenu

* Rename IMenuItem to SidebarMenuItem

* Update macaw version

* Fix tables after changes in macaw (#1220)

* Update macaw version

* Update changelog

* Update stories

* Fix after rebase

* Update to macaw 0.2.0

* Lint files

* Update macaw to 0.2.2
2021-07-21 10:59:52 +02:00

137 lines
3.5 KiB
TypeScript

import {
ExpansionPanel,
ExpansionPanelSummary,
Typography
} from "@material-ui/core";
import { ChannelData } from "@saleor/channels/utils";
import { Messages } from "@saleor/components/ChannelsAvailabilityCard/types";
import IconChevronDown from "@saleor/icons/ChevronDown";
import { makeStyles } from "@saleor/macaw-ui";
import Label from "@saleor/orders/components/OrderHistory/Label";
import { getById } from "@saleor/orders/components/OrderReturnPage/utils";
import { ProductDetails_product_variants } from "@saleor/products/types/ProductDetails";
import { ChannelsWithVariantsData } from "@saleor/products/views/ProductUpdate/types";
import { areAllChannelVariantsSelected } from "@saleor/products/views/ProductUpdate/utils";
import React from "react";
import { useIntl } from "react-intl";
import { defineMessages } from "react-intl";
const useExpanderStyles = makeStyles(
theme => ({
expanded: {},
root: {
boxShadow: "none",
margin: 0,
padding: 0,
paddingBottom: theme.spacing(2),
"&:before": {
content: "none"
},
"&$expanded": {
margin: 0,
border: "none"
}
}
}),
{ name: "ChannelWithVariantAvailabilityItemWrapperExpander" }
);
const useSummaryStyles = makeStyles(
theme => ({
expanded: {},
root: {
width: "100%",
border: "none",
margin: 0,
padding: 0,
minHeight: 0,
paddingTop: theme.spacing(2),
"&$expanded": {
minHeight: 0
}
},
content: {
margin: 0,
"&$expanded": {
margin: 0
}
}
}),
{ name: "ChannelWithVariantAvailabilityItemWrapperSummary" }
);
const useStyles = makeStyles(
() => ({
container: {
display: "flex",
flexDirection: "column"
}
}),
{ name: "ChannelWithVariantAvailabilityItemWrapper" }
);
const messages = defineMessages({
variantCountLabel: {
defaultMessage: "{variantsCount} variants",
description: "variants count label"
},
allVariantsLabel: {
defaultMessage: "All variants",
description: "all variants label"
}
});
interface ChannelAvailabilityItemWrapperProps {
variants: ProductDetails_product_variants[];
channelId: string;
channels: ChannelData[];
channelsWithVariantsData: ChannelsWithVariantsData;
messages: Messages;
}
const ChannelWithVariantsAvailabilityItemWrapper: React.FC<ChannelAvailabilityItemWrapperProps> = ({
channels,
channelsWithVariantsData,
channelId,
variants,
messages: commonChannelMessages,
children
}) => {
const expanderClasses = useExpanderStyles({});
const summaryClasses = useSummaryStyles({});
const classes = useStyles({});
const intl = useIntl();
const { name } = channels.find(getById(channelId));
const { selectedVariantsIds } = channelsWithVariantsData[channelId];
const variantsCount = selectedVariantsIds.length;
const variantsLabel = areAllChannelVariantsSelected(variants, {
selectedVariantsIds
})
? messages.allVariantsLabel
: messages.variantCountLabel;
return (
<ExpansionPanel classes={expanderClasses}>
<ExpansionPanelSummary
expandIcon={<IconChevronDown />}
classes={summaryClasses}
>
<div className={classes.container}>
<Typography>{name}</Typography>
<Label text={intl.formatMessage(variantsLabel, { variantsCount })} />
<Label text={commonChannelMessages.availableDateText} />
</div>
</ExpansionPanelSummary>
{children}
</ExpansionPanel>
);
};
export default ChannelWithVariantsAvailabilityItemWrapper;