components] TItemCard, usePriceInfo 적용
Detail Notes : 1. 기존의 parsePriceInfo함수 hook으로 변경, usePriceInfo 적용
This commit is contained in:
@@ -4,6 +4,7 @@ import classNames from "classnames";
|
||||
|
||||
import Spottable from "@enact/spotlight/Spottable";
|
||||
|
||||
import usePriceInfo from "../../hooks/usePriceInfo";
|
||||
import { $L } from "../../utils/helperMethods";
|
||||
import { SpotlightIds } from "../../utils/SpotlightIds";
|
||||
import css from "./TItemCard.module.less";
|
||||
@@ -30,6 +31,9 @@ export default memo(function TItemCard({
|
||||
type = TYPE_VERTICAL,
|
||||
...rest
|
||||
}) {
|
||||
const { originalPrice, discountedPrice, discountRate } =
|
||||
usePriceInfo(priceInfo);
|
||||
|
||||
const handleClick = useCallback(
|
||||
(productId) => {
|
||||
onCardClick && onCardClick(productId);
|
||||
@@ -37,34 +41,6 @@ export default memo(function TItemCard({
|
||||
[onCardClick, productId]
|
||||
);
|
||||
|
||||
const parsePriceInfo = useCallback(
|
||||
(priceInfo) => {
|
||||
const priceParts = priceInfo
|
||||
.split("|")
|
||||
.filter((part) => part !== "N")
|
||||
.map((item) => item.trim());
|
||||
|
||||
let originalPrice, discountedPrice, discountRate;
|
||||
|
||||
if (priceParts.length === 4) {
|
||||
[originalPrice, discountedPrice, , discountRate] = priceParts;
|
||||
} else if (priceParts.length === 2) {
|
||||
[originalPrice, discountedPrice] = priceParts;
|
||||
discountRate = null;
|
||||
} else {
|
||||
originalPrice = null;
|
||||
discountedPrice = null;
|
||||
discountRate = null;
|
||||
}
|
||||
|
||||
return { originalPrice, discountedPrice, discountRate };
|
||||
},
|
||||
[priceInfo]
|
||||
);
|
||||
|
||||
const { originalPrice, discountedPrice, discountRate } =
|
||||
parsePriceInfo(priceInfo);
|
||||
|
||||
return (
|
||||
<SpottableComponent
|
||||
{...rest}
|
||||
|
||||
Reference in New Issue
Block a user