saleor-dashboard/src/orders/components/OrderHistory/ExtendedDiscountTimelineEvent/ExtendedDiscountTimelineEvent.tsx
Dominik Żegleń 7d9441a7ec
Use esbuild-loader (#1983)
* Minor fixes for intl messages

* Add esbuild-loader
* switch from babel to esbuild-loader
* use formatjs enforce-id linter

* Generate ids for intl messages

* id format defined by idInterpolationPattern

* Modify intl messages extraction

* remove react-intl-translations-manager
* remove transpile-tx.js
* use formatjs cli

* Modify defaultMessages.json

* modify ids in defaultMessages.json with defined idInterpolationPattern

* Fix errors

* Fix page crash

* Use babel to transpile tests

* Fix useStateFromProps

* Improve render count

* Add test to useStateFromProps

* Fix reloading state buh

* Do not check if form with channels is dirty

* Stop blocking save if form has not changed

* Remove debug code

* Fix form disabling

* Fix variant selection checkbox onClick

* Update translations

* Update messages

* Use esbuild to build storybook

Co-authored-by: Bartłomiej Wiaduch <tukan2can@gmail.com>
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2022-05-05 09:54:28 +02:00

106 lines
2.8 KiB
TypeScript

import { Typography } from "@material-ui/core";
import HorizontalSpacer from "@saleor/apps/components/HorizontalSpacer";
import CardSpacer from "@saleor/components/CardSpacer";
import { TimelineEvent } from "@saleor/components/Timeline";
import { TitleElement } from "@saleor/components/Timeline/TimelineEventHeader";
import { OrderEventFragment, OrderEventsEnum } from "@saleor/graphql";
import { makeStyles } from "@saleor/macaw-ui";
import React from "react";
import { defineMessages, useIntl } from "react-intl";
import Label from "../Label";
import MoneySection, { MoneySectionType } from "./MoneySection";
const useStyles = makeStyles(
() => ({
horizontalContainer: {
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
alignItems: "baseline",
width: "100%"
}
}),
{ name: "ExtendedDiscountTimelineEvent" }
);
export const messages = defineMessages({
reasonLabel: {
id: "kVOslW",
defaultMessage: "Reason for discount",
description: "reason for discount label"
}
});
interface ExtendedTimelineEventProps {
event: OrderEventFragment;
titleElements: TitleElement[];
}
const ExtendedDiscountTimelineEvent: React.FC<ExtendedTimelineEventProps> = ({
event,
titleElements
}) => {
const classes = useStyles({});
const intl = useIntl();
const { lines, date, type } = event;
const parsedDiscount =
type === OrderEventsEnum.ORDER_LINE_DISCOUNT_UPDATED
? lines[0].discount
: event.discount;
const {
valueType: calculationMode,
value,
reason,
amount: moneyData,
oldValueType: oldCalculationMode,
oldValue,
oldAmount: oldMoneyData
} = parsedDiscount;
const shouldDisplayOldNewSections = !!oldValue;
return (
<TimelineEvent date={date} titleElements={titleElements}>
{shouldDisplayOldNewSections && (
<div className={classes.horizontalContainer}>
<MoneySection
sectionType={MoneySectionType.NEW}
value={value}
moneyData={moneyData}
calculationMode={calculationMode}
/>
<HorizontalSpacer spacing={4} />
<MoneySection
sectionType={MoneySectionType.OLD}
value={oldValue}
moneyData={oldMoneyData}
calculationMode={oldCalculationMode}
/>
</div>
)}
{!shouldDisplayOldNewSections && (
<MoneySection
sectionType={MoneySectionType.ONLY}
value={value}
moneyData={moneyData}
calculationMode={calculationMode}
/>
)}
<CardSpacer />
{!!reason && (
<>
<Label text={intl.formatMessage(messages.reasonLabel)} />
<Typography>{reason}</Typography>
</>
)}
</TimelineEvent>
);
};
export default ExtendedDiscountTimelineEvent;