Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
disabled: disabledProp,
shouldAddToCart = true,
shouldOpenMinicart = false,
showTooltipOnSkuNotSelected = true,
checkoutUrl,
customToastURL = checkoutUrl,
}) => {
const handles = useCssHandles(CSS_HANDLES)
const [isAddingToCart, setAddingToCart] = useState(false)
const { showToast } = useContext(ToastContext)
const {
skuSelector = {
areAllVariationsSelected: true,
},
} = useProduct()
const dispatch = useProductDispatch()
const { settings = {}, showInstallPrompt } = usePWA() || {}
const { promptOnCustomEvent } = settings
const translateMessage = useCallback(id => intl.formatMessage({ id: id }), [
intl,
])
const orderFormItems = path(['orderForm', 'items'], orderFormContext)
const { utmParams, utmiParams } = useMarketingSessionParams()
const resolveToastMessage = (success, isNewItem) => {
if (!success) return translateMessage(CONSTANTS.ERROR_MESSAGE_ID)
if (!isNewItem) return translateMessage(CONSTANTS.DUPLICATE_CART_ITEM_ID)
const isOffline = window && window.navigator && !window.navigator.onLine
const checkForOffline = !isOffline
? translateMessage(CONSTANTS.SUCCESS_MESSAGE_ID)
: translateMessage(CONSTANTS.OFFLINE_BUY_MESSAGE_ID)
const SKUSelectorWrapper: StorefrontFC = props => {
const valuesFromContext = useProduct()
const dispatch = useProductDispatch()
const { imageHeight, imageWidth } = useResponsiveValues(
pick(['imageHeight', 'imageWidth'], props)
)
const skuItems =
props.skuItems != null
? props.skuItems
: valuesFromContext?.product?.items ?? []
const skuSelected =
props.skuSelected != null
? props.skuSelected
: valuesFromContext.selectedItem
const shouldNotShow =
skuItems.length === 0 ||
const useAllSelectedEvent = (
selectedVariations: SelectedVariations | null,
variationsCount: number
) => {
const dispatch = useProductDispatch()
useEffect(() => {
if (dispatch && selectedVariations) {
const selectedNotNull = filterSelected(selectedVariations)
const selectedCount = keyCount(selectedNotNull)
const allSelected = selectedCount === variationsCount
dispatch({
type: 'SKU_SELECTOR_SET_VARIATIONS_SELECTED',
args: { allSelected },
})
}
}, [dispatch, selectedVariations, variationsCount])
}