
* Use generated hooks in apps * Remove unused files * Use proper types in apps * Use generated hooks in attributes * Use generated hooks in auth module * Use generated hooks in categories * Use generated hooks in channels * Use generated types in collections * Remove legacy types from background tasks * Use generated hooks in customers * Use generated hooks in discounts * Use generated hook in file upload * Use generated types in gift cards * Use generated types in home * Use generated hooks in navigation * Use generated hooks in orders * Use generated hooks in pages * Use generated hooks in page types * Use generated hooks in permission groups * Use generated hooks in plugins * Use generated hooks in products * Use fragment to mark product variants * Improve code a bit * Use generated hooks in page types * Use generated types in searches * Use generated hooks in shipping * Use generated hooks in site settings * Use generated hooks in staff members * Use generated hooks in taxes * Place all gql generated files in one directory * Use generated hooks in translations * Use global types from new generated module * Use generated hooks in warehouses * Use generated hooks in webhooks * Use generated fragment types * Unclutter types * Remove hoc components * Split hooks and types * Fetch introspection file * Delete obsolete schema file * Fix rebase artifacts * Fix autoreplace * Fix auth provider tests * Fix urls * Remove leftover types * Fix rebase artifacts
105 lines
2.6 KiB
TypeScript
105 lines
2.6 KiB
TypeScript
import { Typography } from "@material-ui/core";
|
|
import HorizontalSpacer from "@saleor/apps/components/HorizontalSpacer";
|
|
import { DiscountValueTypeEnum, MoneyFragment } from "@saleor/graphql";
|
|
import { makeStyles } from "@saleor/macaw-ui";
|
|
import React from "react";
|
|
import { defineMessages, useIntl } from "react-intl";
|
|
|
|
import Label from "../Label";
|
|
|
|
const useStyles = makeStyles(
|
|
() => ({
|
|
container: {
|
|
display: "flex",
|
|
flexDirection: "column"
|
|
},
|
|
horizontalContainer: {
|
|
display: "flex",
|
|
flexDirection: "row",
|
|
alignItems: "baseline"
|
|
}
|
|
}),
|
|
{ name: "MoneySection" }
|
|
);
|
|
|
|
export const messages = defineMessages({
|
|
discount: {
|
|
defaultMessage: "discount",
|
|
description: "discount value",
|
|
id: "discount value id"
|
|
},
|
|
fixedAmount: {
|
|
defaultMessage: "Fixed amount",
|
|
description: "Fixed amount subtitle",
|
|
id: "fixed amount subtitle id"
|
|
},
|
|
|
|
newDiscountSectionTitle: {
|
|
defaultMessage: "New discount value",
|
|
description: "new discount label",
|
|
id: "new discount label id"
|
|
},
|
|
oldDiscountSectionTitle: {
|
|
defaultMessage: "Previous discount value",
|
|
description: "Previous discount label",
|
|
id: "Previous discount label id"
|
|
},
|
|
onlyDiscountSectionTitle: {
|
|
defaultMessage: "discount value",
|
|
description: "discount value label",
|
|
id: "discount value label id"
|
|
}
|
|
});
|
|
|
|
export enum MoneySectionType {
|
|
OLD = "old",
|
|
NEW = "new",
|
|
ONLY = "only"
|
|
}
|
|
|
|
interface MoneySectionProps {
|
|
value?: number;
|
|
calculationMode?: DiscountValueTypeEnum;
|
|
moneyData?: MoneyFragment;
|
|
sectionType?: MoneySectionType;
|
|
}
|
|
|
|
const MoneySection: React.FC<MoneySectionProps> = ({
|
|
value,
|
|
calculationMode,
|
|
moneyData,
|
|
sectionType = MoneySectionType.ONLY
|
|
}) => {
|
|
const classes = useStyles({});
|
|
const intl = useIntl();
|
|
|
|
if (!value) {
|
|
return null;
|
|
}
|
|
|
|
const getDiscountSubitle = () => {
|
|
const isDiscountedByPercent =
|
|
calculationMode === DiscountValueTypeEnum.PERCENTAGE;
|
|
|
|
if (isDiscountedByPercent) {
|
|
return `${value}% ${intl.formatMessage(messages.discount)}`;
|
|
}
|
|
|
|
return intl.formatMessage(messages.fixedAmount);
|
|
};
|
|
|
|
const sectionTitleMessageKey = `${sectionType}DiscountSectionTitle`;
|
|
|
|
return (
|
|
<div className={classes.container}>
|
|
<Label text={intl.formatMessage(messages[sectionTitleMessageKey])} />
|
|
<div className={classes.horizontalContainer}>
|
|
<Typography>{`${moneyData.amount} ${moneyData.currency}`}</Typography>
|
|
<HorizontalSpacer />
|
|
<Label text={getDiscountSubitle()} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default MoneySection;
|