import React, {FC, useState} from "react"; import {EmulatedButton} from "../EmulatedButton"; import {useSetAtom} from "jotai"; import {BuyXGetYNotInCartNotificationWindowStateAtom} from "../atoms"; import {NotInCartNotification} from "./BuyXGetY"; import {__, CouponsPlus} from "../../globals"; export type WhenNotInCartCustomFieldsProps = { notification?: NotInCartNotification onUpdate: (notification: NotInCartNotification) => void } export const WhenNotInCartCustomFields: FC = ({notification, onUpdate}) => { const openPopup = useSetAtom(BuyXGetYNotInCartNotificationWindowStateAtom) return { openPopup({ notification: notification!, onClose: (status, notification) => { if (status === 'success') { onUpdate(notification!) // a parenthesis of excitement! } } }) }}>

{notification?.message}

{notification?.button.text}
{notification?.button.url.type === 'url'? notification?.button.url.value : findUrlTypelabel(notification?.button.url.type)}
; } function findUrlTypelabel(type: string | undefined) { let urlTypesDict = CouponsPlus.components.offers.BuyXGetY.fields.whenNotInCart.notification.button.url.type.meta._allowed; for (let key in urlTypesDict) { if (urlTypesDict[key] === type) { return key; } } return __('unknown') }