[SHOPTIME-3555] Search / 검색후 item에서 할인가만 노출됨
Changed files: 1. SearchItemCard.jsx Detail note: 1. Create the parsePrice function and modify the price display condition
This commit is contained in:
@@ -1,26 +1,37 @@
|
||||
import React, { memo, useCallback, useEffect, useState } from "react";
|
||||
import React, { memo, useCallback, useMemo, useState } from "react";
|
||||
|
||||
import { useDispatch } from "react-redux";
|
||||
|
||||
import Spotlight from "@enact/spotlight";
|
||||
import Spottable from "@enact/spotlight/Spottable";
|
||||
import {
|
||||
getContainerId,
|
||||
setContainerLastFocusedElement,
|
||||
} from "@enact/spotlight/src/container";
|
||||
|
||||
import defaultImageItem from "../../../../../assets/images/img-thumb-empty-product@3x.png";
|
||||
import { sendLogSearchClick } from "../../../../actions/logActions";
|
||||
import { pushPanel, updatePanel } from "../../../../actions/panelActions";
|
||||
import CustomImage from "../../../../components/CustomImage/CustomImage";
|
||||
import useScrollTo from "../../../../hooks/useScrollTo";
|
||||
import { LOG_TP_NO, panel_names } from "../../../../utils/Config";
|
||||
import { panel_names } from "../../../../utils/Config";
|
||||
import { getTranslate3dValueByDirection } from "../../../../utils/helperMethods";
|
||||
import { SpotlightIds } from "../../../../utils/SpotlightIds";
|
||||
import css from "./SearchItemCard.module.less";
|
||||
|
||||
const ItemContainer = Spottable("div");
|
||||
|
||||
const parsePrice = (priceString) => {
|
||||
if (!priceString) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// US, GB, DE
|
||||
const formattedPriceCommon = priceString.slice(2).replace(/,/g, ".");
|
||||
|
||||
// RU
|
||||
const formattedPriceRU = priceString.replace(/\s/g, "").replace(",", ".");
|
||||
|
||||
return isNaN(priceString[0])
|
||||
? parseFloat(formattedPriceCommon)
|
||||
: parseFloat(formattedPriceRU);
|
||||
};
|
||||
|
||||
export default memo(function SearchItemCard({
|
||||
contentId,
|
||||
dcPrice,
|
||||
@@ -35,9 +46,12 @@ export default memo(function SearchItemCard({
|
||||
length,
|
||||
...rest
|
||||
}) {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const [firstChk, setFirstChk] = useState(0);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const priceNumber = useMemo(() => parsePrice(price), [price]);
|
||||
const discountPriceNumber = useMemo(() => parsePrice(dcPrice), [dcPrice]);
|
||||
|
||||
const handleItemClick = useCallback(
|
||||
(e) => {
|
||||
@@ -161,7 +175,7 @@ export default memo(function SearchItemCard({
|
||||
}}
|
||||
/>
|
||||
<div className={css.priceWrap}>
|
||||
{price !== dcPrice && parseFloat(price) > parseFloat(dcPrice) && (
|
||||
{priceNumber > discountPriceNumber && (
|
||||
<span className={css.price}>{price}</span>
|
||||
)}
|
||||
<strong className={css.dcPrice}>{dcPrice}</strong>
|
||||
|
||||
Reference in New Issue
Block a user