saleor-dashboard/src/channels/components/ChannelAllocationStrategy/ChannelAllocationStrategy.tsx
Dawid e610aefcfa
Add allocation strategies with sortable warehouses (#2258)
* Add allocation strategy options in channel view

* Update schema with channel allocation strategy

* Reorder channel warehouses after channel saving

* Refactor and clean code of allocation strategy options

* Update schema with allocation strategy

* Trigger CI

* Update allocation starategy options UI

* Update allocation strategy messages

* Trigger CI

* Fix shipping zones and warehouses cards style

* Fix message

* Fix snapshots

Co-authored-by: Michał Droń <dron.official@yahoo.com>
2022-08-29 13:35:55 +02:00

106 lines
3.3 KiB
TypeScript

import { Card, CardContent, Typography } from "@material-ui/core";
import HelpOutline from "@material-ui/icons/HelpOutline";
import CardTitle from "@saleor/components/CardTitle";
import PreviewPill from "@saleor/components/PreviewPill";
import RadioGroupField from "@saleor/components/RadioGroupField";
import { AllocationStrategyEnum, StockSettingsInput } from "@saleor/graphql";
import { Tooltip } from "@saleor/macaw-ui";
import React from "react";
import { FormattedMessage } from "react-intl";
import { messages } from "./messages";
import { useStyles } from "./styles";
const strategyOptions = [
{
title: messages.prioritizeBySortOrder,
subtitle: messages.prioritizeBySortOrderDescription,
type: AllocationStrategyEnum.PRIORITIZE_SORTING_ORDER,
},
{
title: messages.prioritizeByHighestStock,
subtitle: messages.prioritizeByHighestStockDescription,
type: AllocationStrategyEnum.PRIORITIZE_HIGH_STOCK,
},
];
interface ChannelAllocationStrategyProps {
data?: StockSettingsInput;
disabled: boolean;
onChange: (event: React.ChangeEvent<any>) => void;
}
const ChannelAllocationStrategy: React.FC<ChannelAllocationStrategyProps> = ({
data,
disabled,
onChange,
}) => {
const classes = useStyles();
return (
<Card>
<CardTitle
title={
<div className={classes.preview}>
<FormattedMessage {...messages.allocationStrategy} />
<PreviewPill />
</div>
}
/>
<CardContent>
<RadioGroupField
label={
<Typography>
<FormattedMessage {...messages.allocationStrategyDescription} />
<Tooltip
title={
<>
<FormattedMessage {...messages.allocaationMayOccur} />
<ul>
<li>
<FormattedMessage
{...messages.allocaationMayOccurWithTrackInventory}
/>
</li>
<li>
<FormattedMessage
{...messages.allocaationMayOccurWithReservationTime}
/>
</li>
</ul>
</>
}
>
<HelpOutline className={classes.tooltipIcon} />
</Tooltip>
</Typography>
}
choices={strategyOptions.map(option => ({
label: (
<div
className={classes.option}
data-test-id={`channel-allocation-strategy-option-${option.type}`}
>
<Typography variant="body1">
<FormattedMessage {...option.title} />
</Typography>
{option.subtitle && (
<Typography color="textSecondary" variant="caption">
<FormattedMessage {...option.subtitle} />
</Typography>
)}
</div>
),
value: option.type,
}))}
disabled={disabled}
name="allocationStrategy"
value={data?.allocationStrategy}
onChange={onChange}
/>
</CardContent>
</Card>
);
};
ChannelAllocationStrategy.displayName = "ChannelAllocationStrategy";
export default ChannelAllocationStrategy;