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 Spottable from "@enact/spotlight/Spottable";
|
||||||
|
|
||||||
|
import usePriceInfo from "../../hooks/usePriceInfo";
|
||||||
import { $L } from "../../utils/helperMethods";
|
import { $L } from "../../utils/helperMethods";
|
||||||
import { SpotlightIds } from "../../utils/SpotlightIds";
|
import { SpotlightIds } from "../../utils/SpotlightIds";
|
||||||
import css from "./TItemCard.module.less";
|
import css from "./TItemCard.module.less";
|
||||||
@@ -30,6 +31,9 @@ export default memo(function TItemCard({
|
|||||||
type = TYPE_VERTICAL,
|
type = TYPE_VERTICAL,
|
||||||
...rest
|
...rest
|
||||||
}) {
|
}) {
|
||||||
|
const { originalPrice, discountedPrice, discountRate } =
|
||||||
|
usePriceInfo(priceInfo);
|
||||||
|
|
||||||
const handleClick = useCallback(
|
const handleClick = useCallback(
|
||||||
(productId) => {
|
(productId) => {
|
||||||
onCardClick && onCardClick(productId);
|
onCardClick && onCardClick(productId);
|
||||||
@@ -37,34 +41,6 @@ export default memo(function TItemCard({
|
|||||||
[onCardClick, productId]
|
[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 (
|
return (
|
||||||
<SpottableComponent
|
<SpottableComponent
|
||||||
{...rest}
|
{...rest}
|
||||||
|
|||||||
Reference in New Issue
Block a user