@anker-in/campaign-ui 0.5.0-beta.13 → 0.5.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/memberPopup/MemberPopup.js +1 -1
- package/dist/cjs/components/memberPopup/MemberPopup.js.map +3 -3
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/index.js +1 -1
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/index.js.map +2 -2
- package/dist/esm/components/memberPopup/MemberPopup.js +1 -1
- package/dist/esm/components/memberPopup/MemberPopup.js.map +3 -3
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/index.js +1 -1
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/index.js.map +2 -2
- package/package.json +1 -1
- package/src/components/memberPopup/MemberPopup.tsx +14 -7
- package/src/components/memberPopup/panels/ConsumeCredits/index.tsx +1 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";"use client";var L=Object.create;var
|
|
1
|
+
"use strict";"use client";var L=Object.create;var P=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var G=(e,i)=>{for(var p in i)P(e,p,{get:i[p],enumerable:!0})},O=(e,i,p,c)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of B(i))!q.call(e,n)&&n!==p&&P(e,n,{get:()=>i[n],enumerable:!(c=U(i,n))||c.enumerable});return e};var u=(e,i,p)=>(p=e!=null?L(W(e)):{},O(i||!e||!e.__esModule?P(p,"default",{value:e,enumerable:!0}):p,e)),J=e=>O(P({},"__esModule",{value:!0}),e);var ie={};G(ie,{MemberPopup:()=>se});module.exports=J(ie);var t=require("react/jsx-runtime"),o=require("react"),A=require("@anker-in/headless-ui"),C=require("@anker-in/lib"),s=require("./type"),V=require("./context/provider"),R=require("./context/provider"),E=require("./context/viewStack"),a=require("./icons"),H=require("../../constants");const K=(0,o.lazy)(()=>import("./panels/EarnCredits")),Q=(0,o.lazy)(()=>import("./panels/ConsumeCredits")),X=(0,o.lazy)(()=>import("./panels/Referral")),Y=(0,o.lazy)(()=>import("./panels/EarnCredits/CompleteProfilePanel")),Z=(0,o.lazy)(()=>import("./panels/ActivitiesSubscribePanel")),$=(0,o.lazy)(()=>import("./panels/EarnCredits/SubscribeEmailPanel")),ee=(0,o.lazy)(()=>import("./panels/EarnCredits/ActivatePanel")),te=(0,o.lazy)(()=>import("./panels/ConsumeCredits/RedeemCouponPanel"));function se({copy:e,bottomOffset:i="24px",...p}){const[c,n]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{const d=e.pageConfig;if(!d){n(!0);return}const f=window.location.pathname,b=d.pages.some(v=>f===v||f.startsWith(v+"/"));switch(d.scope){case s.MemberPopupPageScope.Include:n(b);break;case s.MemberPopupPageScope.Exclude:n(!b);break;default:n(!0)}},[e.pageConfig]),console.log("isVisible",c),c?(0,t.jsx)(V.MemberPopupProvider,{...p,earnCreditsCopy:e.earnCredits,children:(0,t.jsx)(oe,{copy:e,bottomOffset:i})}):null}function oe({copy:e,bottomOffset:i}){const{profile:p,openSignInPopup:c,openSignUpPopup:n}=(0,R.useMemberPopupContext)(),{brand:d,storeDomain:f}=(0,C.useHeadlessContext)(),b=H.ROUNDED_BRANDS.includes(d),v=!!p,[h,N]=(0,o.useState)(!1),[w,S]=(0,o.useState)([]),[z,y]=(0,o.useState)(!1),[I,T]=(0,o.useState)(!1),[j,_]=(0,o.useState)(!1),[D,k]=(0,o.useState)(!1),r=w[w.length-1]??null,g=(0,o.useCallback)(l=>{S(x=>[...x,l])},[]),m=(0,o.useCallback)(()=>{S(l=>l.slice(0,-1))},[]);function F(l,x){switch(l){case s.MemberPopupActionType.ExternalLink:x&&window.open(x,"_blank","noopener,noreferrer");break;case s.MemberPopupActionType.OpenEarnCredits:g({type:s.MemberPopupPanelType.EarnCredits});break;case s.MemberPopupActionType.OpenConsumeCredits:g({type:s.MemberPopupPanelType.ConsumeCredits});break;case s.MemberPopupActionType.OpenReferral:g({type:s.MemberPopupPanelType.Referral});break;case s.MemberPopupActionType.OpenSubscribe:g({type:s.MemberPopupPanelType.Subscribe});break}}function M(){N(!1),S([]),k(!1)}return(0,t.jsxs)(E.ViewStackContext.Provider,{value:{pushView:g,popView:m},children:[h&&(0,t.jsx)("div",{className:"fixed inset-0 z-[998]",onClick:M}),(0,t.jsxs)("div",{className:"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0",style:{bottom:i},children:[h&&(0,t.jsxs)("div",{className:(0,C.classNames)("relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]",b?"rounded-[12px]":"rounded-none"),style:{maxHeight:"min(80vh, 606px)"},onClick:l=>l.stopPropagation(),children:[(0,t.jsx)("div",{className:"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white"}),(0,t.jsxs)("div",{className:"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]",children:[r!==null&&(0,t.jsx)("button",{className:"mr-auto flex size-[24px] cursor-pointer items-center justify-center",onClick:m,"aria-label":"Back",children:(0,t.jsx)(a.IconSwitch,{})}),(0,t.jsx)("button",{className:"flex size-[24px] cursor-pointer items-center justify-center",onClick:M,"aria-label":"Close",children:(0,t.jsx)(a.IconClose,{})})]}),(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]",children:[r===null&&(0,t.jsxs)(t.Fragment,{children:[(e.title||e.subtitle)&&(0,t.jsxs)("div",{className:"flex flex-col gap-[4px]",children:[e.title&&(0,t.jsx)("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:e.title}),e.subtitle&&(0,t.jsx)("p",{className:"text-[16px] font-[700] leading-snug text-[#4a4c56]",children:e.subtitle})]}),e.list.map((l,x)=>(0,t.jsx)(re,{item:l,onAction:F,rounded:b},x))]}),r!==null&&(0,t.jsxs)(o.Suspense,{fallback:(0,t.jsx)("div",{className:"flex items-center justify-center py-[32px]",children:(0,t.jsx)("div",{className:"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent"})}),children:[r.type===s.MemberPopupPanelType.EarnCredits&&e.earnCredits&&(0,t.jsx)(K,{copy:e.earnCredits,onClose:m,isProfileCompleteSuccess:j,isSubscribeSuccess:z,isActivateSuccess:I}),r.type===s.MemberPopupPanelType.ConsumeCredits&&e.consumeCredits&&(0,t.jsx)(Q,{copy:e.consumeCredits,onClose:m,isActivateSuccess:I}),r.type===s.MemberPopupPanelType.Referral&&e.referral&&(0,t.jsx)(X,{copy:e.referral,onClose:m}),r.type===s.MemberPopupPanelType.CompleteProfile&&e.earnCredits&&(0,t.jsx)(Y,{copy:e.earnCredits.completeProfile,shopifyStoreDomain:f,onClose:m,onSuccess:()=>_(!0)}),r.type===s.MemberPopupPanelType.Subscribe&&e.activitiesSubscribe&&(0,t.jsx)(Z,{copy:e.activitiesSubscribe,email:p?.email,onSuccess:()=>y(!0),hideForm:D,onHideForm:()=>k(!0)}),r.type===s.MemberPopupPanelType.SubscribeEmail&&e.earnCredits&&(0,t.jsx)($,{copy:e.earnCredits.subscribe,email:p?.email,onClose:m,onSuccess:()=>y(!0)}),r.type===s.MemberPopupPanelType.Activate&&e.earnCredits&&(0,t.jsx)(ee,{copy:e.earnCredits.authCodeActivate,onClose:m,onSuccess:()=>{T(!0)}}),r.type===s.MemberPopupPanelType.RedeemCoupon&&r.props&&e.consumeCredits&&(0,t.jsx)(te,{itemTitle:r.props.itemTitle,itemCredits:r.props.itemCredits,itemImage:r.props.itemImage,itemValue:r.props.itemValue,itemOff:r.props.itemOff,itemRules:r.props.itemRules,redeemId:r.props.redeemId,userId:r.props.userId,alpcConfig:r.props.alpcConfig,copy:e.consumeCredits.redeemModal,pointUnit:e.consumeCredits.creditUnit,onClose:m})]})]}),e.footer&&!v&&(0,t.jsx)("div",{className:"border-t border-[#dadce0] p-[16px]",children:(0,t.jsxs)("div",{className:"flex items-center justify-between gap-[16px]",children:[(0,t.jsxs)("div",{className:"flex items-center gap-[4px]",children:[(0,t.jsx)("span",{className:"text-[14px] font-[700] text-[#080a0f]",children:e.footer.loginHint}),(0,t.jsx)("button",{className:"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline",onClick:c,children:e.footer.loginLabel})]}),(0,t.jsx)("div",{className:"flex shrink-0 items-center gap-[8px]",children:(0,t.jsx)("button",{className:(0,C.classNames)("cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]",b?"rounded-[4px]":"rounded-none"),onClick:n,children:e.footer.joinLabel})})]})})]}),(0,t.jsx)("button",{className:"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]",onClick:()=>N(l=>!l),"aria-label":e.triggerImg.alt??"Open member popup",children:(0,t.jsx)(A.Picture,{source:e.triggerImg.url,alt:e.triggerImg.alt??"",className:"size-[58px]"})})]})]})}function re({item:e,onAction:i,rounded:p}){const c={[s.MemberPopupActionType.OpenEarnCredits]:a.IconCredit,[s.MemberPopupActionType.OpenConsumeCredits]:a.IconBag,[s.MemberPopupActionType.OpenReferral]:a.IconReferral,[s.MemberPopupActionType.OpenSubscribe]:a.IconSubscription};return(0,t.jsxs)("div",{className:(0,C.classNames)("flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]",p?"rounded-[8px]":"rounded-none"),children:[(0,t.jsxs)("div",{className:"flex flex-col gap-[4px]",children:[(0,t.jsx)("h3",{className:"text-[20px] font-[700] leading-[1.2] text-[#1e2024]",children:e.title}),e.description&&(0,t.jsx)("p",{className:"text-[14px] font-[700] leading-[1.43] text-[#1e2024]",children:e.description})]}),(0,t.jsx)("div",{className:"flex flex-col gap-[16px]",children:e.links.map((n,d)=>{const f=c[n.type];return(0,t.jsxs)("div",{children:[d>0&&(0,t.jsx)("div",{className:"mb-[16px] h-px bg-[#dadce0]"}),(0,t.jsxs)("button",{className:"flex w-full cursor-pointer items-center gap-[12px]",onClick:()=>i(n.type,n.url),children:[f&&(0,t.jsx)(f,{className:"size-[24px] shrink-0"}),(0,t.jsx)("span",{className:"flex-1 text-left text-[14px] font-[700] text-[#1e2024]",children:n.label}),(0,t.jsx)(a.IconArrow,{className:"size-[16px] shrink-0"})]})]},d)})})]})}
|
|
2
2
|
//# sourceMappingURL=MemberPopup.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/memberPopup/MemberPopup.tsx"],
|
|
4
|
-
"sourcesContent": ["'use client'\n\nimport { lazy, Suspense, useState, useCallback, useMemo, useEffect } from 'react'\nimport { Picture } from '@anker-in/headless-ui'\nimport { type HeadlessConfig, useHeadlessContext, classNames as cn } from '@anker-in/lib'\nimport {\n MemberPopupActionType,\n MemberPopupPageScope,\n MemberPopupPanelType,\n type MemberPopupCopy,\n type MemberPopupContextValue,\n type MemberPopupItem,\n} from './type'\nimport { MemberPopupProvider } from './context/provider'\nimport { useMemberPopupContext } from './context/provider'\nimport { ViewStackContext, type ViewPayload } from './context/viewStack'\nimport { IconClose, IconArrow, IconCredit, IconBag, IconReferral, IconSwitch, IconSubscription } from './icons'\nimport { ROUNDED_BRANDS } from '../../constants'\n\nconst EarnCredits = lazy(() => import('./panels/EarnCredits'))\nconst ConsumeCredits = lazy(() => import('./panels/ConsumeCredits'))\nconst Referral = lazy(() => import('./panels/Referral'))\nconst CompleteProfile = lazy(() => import('./panels/EarnCredits/CompleteProfilePanel'))\nconst ActivitiesSubscribe = lazy(() => import('./panels/ActivitiesSubscribePanel'))\nconst SubscribeEmail = lazy(() => import('./panels/EarnCredits/SubscribeEmailPanel'))\nconst Activate = lazy(() => import('./panels/EarnCredits/ActivatePanel'))\nconst RedeemCoupon = lazy(() => import('./panels/ConsumeCredits/RedeemCouponPanel'))\n\ntype MemberPopupProps = MemberPopupContextValue & {\n headlessConfig: HeadlessConfig\n copy: MemberPopupCopy\n bottomOffset?: string\n}\n\nexport function MemberPopup({ copy, bottomOffset = '24px', ...providerProps }: MemberPopupProps) {\n const isVisible = useMemo(() => {\n const config = copy.pageConfig\n if (!config) return true\n const pathname = typeof window !== 'undefined' ? window.location.pathname : ''\n const matches = config.pages.some(page => pathname === page || pathname.startsWith(page + '/'))\n switch (config.scope) {\n case MemberPopupPageScope.Include:\n return matches\n case MemberPopupPageScope.Exclude:\n return !matches\n default:\n return true\n }\n }, [copy.pageConfig])\n\n console.log('isVisible', isVisible)\n\n return isVisible ? (\n <MemberPopupProvider {...providerProps} earnCreditsCopy={copy.earnCredits}>\n <MemberPopupContent copy={copy} bottomOffset={bottomOffset} />\n </MemberPopupProvider>\n ) : null\n}\n\ntype MemberPopupContentProps = {\n copy: MemberPopupCopy\n bottomOffset: string\n}\n\nfunction MemberPopupContent({ copy, bottomOffset }: MemberPopupContentProps) {\n const { profile, openSignInPopup, openSignUpPopup } = useMemberPopupContext()\n const { brand, storeDomain } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n const isLogin = !!profile\n const [isOpen, setIsOpen] = useState(false)\n const [viewStack, setViewStack] = useState<ViewPayload[]>([])\n const [isSubscribeSuccess, setIsSubscribeSuccess] = useState(false)\n const [isActivateSuccess, setIsActivateSuccess] = useState(false)\n const [isProfileCompleteSuccess, setIsProfileCompleteSuccess] = useState(false)\n const [isSubscribeFormHidden, setIsSubscribeFormHidden] = useState(false)\n\n const currentView = viewStack[viewStack.length - 1] ?? null\n\n const pushView = useCallback((view: ViewPayload) => {\n setViewStack(prev => [...prev, view])\n }, [])\n\n const popView = useCallback(() => {\n setViewStack(prev => prev.slice(0, -1))\n }, [])\n\n function handleAction(type: MemberPopupActionType, url?: string) {\n switch (type) {\n case MemberPopupActionType.ExternalLink:\n if (url) window.open(url, '_blank', 'noopener,noreferrer')\n break\n case MemberPopupActionType.OpenEarnCredits:\n pushView({ type: MemberPopupPanelType.EarnCredits })\n break\n case MemberPopupActionType.OpenConsumeCredits:\n pushView({ type: MemberPopupPanelType.ConsumeCredits })\n break\n case MemberPopupActionType.OpenReferral:\n pushView({ type: MemberPopupPanelType.Referral })\n break\n case MemberPopupActionType.OpenSubscribe:\n pushView({ type: MemberPopupPanelType.Subscribe })\n break\n }\n }\n\n function handleClose() {\n setIsOpen(false)\n setViewStack([])\n setIsSubscribeFormHidden(false)\n }\n\n return (\n <ViewStackContext.Provider value={{ pushView, popView }}>\n {isOpen && <div className=\"fixed inset-0 z-[998]\" onClick={handleClose} />}\n <div\n className=\"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0\"\n style={{ bottom: bottomOffset }}\n >\n {isOpen && (\n <div\n className={cn(\n 'relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]',\n rounded ? 'rounded-[12px]' : 'rounded-none'\n )}\n style={{ maxHeight: 'min(80vh, 606px)' }}\n onClick={e => e.stopPropagation()}\n >\n <div className=\"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white\" />\n <div className=\"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]\">\n {currentView !== null && (\n <button\n className=\"mr-auto flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={popView}\n aria-label=\"Back\"\n >\n <IconSwitch />\n </button>\n )}\n <button\n className=\"flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={handleClose}\n aria-label=\"Close\"\n >\n <IconClose />\n </button>\n </div>\n\n <div className=\"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]\">\n {currentView === null && (\n <>\n {(copy.title || copy.subtitle) && (\n <div className=\"flex flex-col gap-[4px]\">\n {copy.title && (\n <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>\n )}\n {copy.subtitle && (\n <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n )}\n {copy.list.map((item, i) => (\n <HomeCard key={i} item={item} onAction={handleAction} rounded={rounded} />\n ))}\n </>\n )}\n\n {currentView !== null && (\n <Suspense\n fallback={\n <div className=\"flex items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n }\n >\n {currentView.type === MemberPopupPanelType.EarnCredits && copy.earnCredits && (\n <EarnCredits\n copy={copy.earnCredits}\n onClose={popView}\n isProfileCompleteSuccess={isProfileCompleteSuccess}\n isSubscribeSuccess={isSubscribeSuccess}\n isActivateSuccess={isActivateSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.ConsumeCredits && copy.consumeCredits && (\n <ConsumeCredits\n copy={copy.consumeCredits}\n onClose={popView}\n isActivateSuccess={isActivateSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Referral && copy.referral && (\n <Referral copy={copy.referral} onClose={popView} />\n )}\n {currentView.type === MemberPopupPanelType.CompleteProfile && copy.earnCredits && (\n <CompleteProfile\n copy={copy.earnCredits.completeProfile}\n shopifyStoreDomain={storeDomain}\n onClose={popView}\n onSuccess={() => setIsProfileCompleteSuccess(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.Subscribe && copy.activitiesSubscribe && (\n <ActivitiesSubscribe\n copy={copy.activitiesSubscribe}\n email={profile?.email}\n onSuccess={() => setIsSubscribeSuccess(true)}\n hideForm={isSubscribeFormHidden}\n onHideForm={() => setIsSubscribeFormHidden(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.SubscribeEmail && copy.earnCredits && (\n <SubscribeEmail\n copy={copy.earnCredits.subscribe}\n email={profile?.email}\n onClose={popView}\n onSuccess={() => setIsSubscribeSuccess(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.Activate && copy.earnCredits && (\n <Activate\n copy={copy.earnCredits.authCodeActivate}\n onClose={popView}\n onSuccess={() => {\n setIsActivateSuccess(true)\n }}\n />\n )}\n {currentView.type === MemberPopupPanelType.RedeemCoupon &&\n currentView.props &&\n copy.consumeCredits && (\n <RedeemCoupon\n itemTitle={currentView.props.itemTitle}\n itemCredits={currentView.props.itemCredits}\n itemImage={currentView.props.itemImage}\n itemValue={currentView.props.itemValue}\n itemOff={currentView.props.itemOff}\n itemRules={currentView.props.itemRules}\n redeemId={currentView.props.redeemId}\n userId={currentView.props.userId}\n alpcConfig={currentView.props.alpcConfig}\n copy={copy.consumeCredits.redeemModal}\n pointUnit={copy.consumeCredits.creditUnit}\n onClose={popView}\n />\n )}\n </Suspense>\n )}\n </div>\n\n {copy.footer && !isLogin && (\n <div className=\"border-t border-[#dadce0] p-[16px]\">\n <div className=\"flex items-center justify-between gap-[16px]\">\n <div className=\"flex items-center gap-[4px]\">\n <span className=\"text-[14px] font-[700] text-[#080a0f]\">{copy.footer.loginHint}</span>\n <button\n className=\"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={openSignInPopup}\n >\n {copy.footer.loginLabel}\n </button>\n </div>\n <div className=\"flex shrink-0 items-center gap-[8px]\">\n <button\n className={cn(\n 'cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n onClick={openSignUpPopup}\n >\n {copy.footer.joinLabel}\n </button>\n </div>\n </div>\n </div>\n )}\n </div>\n )}\n\n <button\n className=\"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]\"\n onClick={() => setIsOpen(prev => !prev)}\n aria-label={copy.triggerImg.alt ?? 'Open member popup'}\n >\n <Picture source={copy.triggerImg.url} alt={copy.triggerImg.alt ?? ''} className=\"size-[58px]\" />\n </button>\n </div>\n </ViewStackContext.Provider>\n )\n}\n\ntype HomeCardProps = {\n item: MemberPopupItem\n onAction: (type: MemberPopupActionType, url?: string) => void\n rounded: boolean\n}\n\nfunction HomeCard({ item, onAction, rounded }: HomeCardProps) {\n const ACTION_ICON: Partial<Record<MemberPopupActionType, typeof IconCredit>> = {\n [MemberPopupActionType.OpenEarnCredits]: IconCredit,\n [MemberPopupActionType.OpenConsumeCredits]: IconBag,\n [MemberPopupActionType.OpenReferral]: IconReferral,\n [MemberPopupActionType.OpenSubscribe]: IconSubscription,\n }\n\n return (\n <div className={cn('flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]', rounded ? 'rounded-[8px]' : 'rounded-none')}>\n <div className=\"flex flex-col gap-[4px]\">\n <h3 className=\"text-[20px] font-[700] leading-[1.2] text-[#1e2024]\">{item.title}</h3>\n {item.description && <p className=\"text-[14px] font-[700] leading-[1.43] text-[#1e2024]\">{item.description}</p>}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {item.links.map((link, i) => {\n const IconComponent = ACTION_ICON[link.type]\n return (\n <div key={i}>\n {i > 0 && <div className=\"mb-[16px] h-px bg-[#dadce0]\" />}\n <button\n className=\"flex w-full cursor-pointer items-center gap-[12px]\"\n onClick={() => onAction(link.type, link.url)}\n >\n {IconComponent && <IconComponent className=\"size-[24px] shrink-0\" />}\n <span className=\"flex-1 text-left text-[14px] font-[700] text-[#1e2024]\">{link.label}</span>\n <IconArrow className=\"size-[16px] shrink-0\" />\n </button>\n </div>\n )\n })}\n </div>\n </div>\n )\n}\n"],
|
|
5
|
-
"mappings": "ukBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,iBAAAE,KAAA,eAAAC,EAAAH,
|
|
6
|
-
"names": ["MemberPopup_exports", "__export", "MemberPopup", "__toCommonJS", "import_jsx_runtime", "import_react", "import_headless_ui", "import_lib", "import_type", "import_provider", "import_viewStack", "import_icons", "import_constants", "EarnCredits", "ConsumeCredits", "Referral", "CompleteProfile", "ActivitiesSubscribe", "SubscribeEmail", "Activate", "RedeemCoupon", "copy", "bottomOffset", "providerProps", "isVisible", "config", "pathname", "matches", "page", "MemberPopupContent", "profile", "openSignInPopup", "openSignUpPopup", "brand", "storeDomain", "rounded", "isLogin", "isOpen", "setIsOpen", "viewStack", "setViewStack", "isSubscribeSuccess", "setIsSubscribeSuccess", "isActivateSuccess", "setIsActivateSuccess", "isProfileCompleteSuccess", "setIsProfileCompleteSuccess", "isSubscribeFormHidden", "setIsSubscribeFormHidden", "currentView", "pushView", "view", "prev", "popView", "handleAction", "type", "url", "handleClose", "cn", "e", "item", "i", "HomeCard", "onAction", "ACTION_ICON", "link", "IconComponent"]
|
|
4
|
+
"sourcesContent": ["'use client'\n\nimport { lazy, Suspense, useState, useCallback, useEffect } from 'react'\nimport { Picture } from '@anker-in/headless-ui'\nimport { type HeadlessConfig, useHeadlessContext, classNames as cn } from '@anker-in/lib'\nimport {\n MemberPopupActionType,\n MemberPopupPageScope,\n MemberPopupPanelType,\n type MemberPopupCopy,\n type MemberPopupContextValue,\n type MemberPopupItem,\n} from './type'\nimport { MemberPopupProvider } from './context/provider'\nimport { useMemberPopupContext } from './context/provider'\nimport { ViewStackContext, type ViewPayload } from './context/viewStack'\nimport { IconClose, IconArrow, IconCredit, IconBag, IconReferral, IconSwitch, IconSubscription } from './icons'\nimport { ROUNDED_BRANDS } from '../../constants'\n\nconst EarnCredits = lazy(() => import('./panels/EarnCredits'))\nconst ConsumeCredits = lazy(() => import('./panels/ConsumeCredits'))\nconst Referral = lazy(() => import('./panels/Referral'))\nconst CompleteProfile = lazy(() => import('./panels/EarnCredits/CompleteProfilePanel'))\nconst ActivitiesSubscribe = lazy(() => import('./panels/ActivitiesSubscribePanel'))\nconst SubscribeEmail = lazy(() => import('./panels/EarnCredits/SubscribeEmailPanel'))\nconst Activate = lazy(() => import('./panels/EarnCredits/ActivatePanel'))\nconst RedeemCoupon = lazy(() => import('./panels/ConsumeCredits/RedeemCouponPanel'))\n\ntype MemberPopupProps = MemberPopupContextValue & {\n headlessConfig: HeadlessConfig\n copy: MemberPopupCopy\n bottomOffset?: string\n}\n\nexport function MemberPopup({ copy, bottomOffset = '24px', ...providerProps }: MemberPopupProps) {\n const [isVisible, setIsVisible] = useState(false)\n\n useEffect(() => {\n const config = copy.pageConfig\n if (!config) {\n setIsVisible(true)\n return\n }\n const pathname = window.location.pathname\n const matches = config.pages.some(page => pathname === page || pathname.startsWith(page + '/'))\n switch (config.scope) {\n case MemberPopupPageScope.Include:\n setIsVisible(matches)\n break\n case MemberPopupPageScope.Exclude:\n setIsVisible(!matches)\n break\n default:\n setIsVisible(true)\n }\n }, [copy.pageConfig])\n\n console.log('isVisible', isVisible)\n\n return isVisible ? (\n <MemberPopupProvider {...providerProps} earnCreditsCopy={copy.earnCredits}>\n <MemberPopupContent copy={copy} bottomOffset={bottomOffset} />\n </MemberPopupProvider>\n ) : null\n}\n\ntype MemberPopupContentProps = {\n copy: MemberPopupCopy\n bottomOffset: string\n}\n\nfunction MemberPopupContent({ copy, bottomOffset }: MemberPopupContentProps) {\n const { profile, openSignInPopup, openSignUpPopup } = useMemberPopupContext()\n const { brand, storeDomain } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n const isLogin = !!profile\n const [isOpen, setIsOpen] = useState(false)\n const [viewStack, setViewStack] = useState<ViewPayload[]>([])\n const [isSubscribeSuccess, setIsSubscribeSuccess] = useState(false)\n const [isActivateSuccess, setIsActivateSuccess] = useState(false)\n const [isProfileCompleteSuccess, setIsProfileCompleteSuccess] = useState(false)\n const [isSubscribeFormHidden, setIsSubscribeFormHidden] = useState(false)\n\n const currentView = viewStack[viewStack.length - 1] ?? null\n\n const pushView = useCallback((view: ViewPayload) => {\n setViewStack(prev => [...prev, view])\n }, [])\n\n const popView = useCallback(() => {\n setViewStack(prev => prev.slice(0, -1))\n }, [])\n\n function handleAction(type: MemberPopupActionType, url?: string) {\n switch (type) {\n case MemberPopupActionType.ExternalLink:\n if (url) window.open(url, '_blank', 'noopener,noreferrer')\n break\n case MemberPopupActionType.OpenEarnCredits:\n pushView({ type: MemberPopupPanelType.EarnCredits })\n break\n case MemberPopupActionType.OpenConsumeCredits:\n pushView({ type: MemberPopupPanelType.ConsumeCredits })\n break\n case MemberPopupActionType.OpenReferral:\n pushView({ type: MemberPopupPanelType.Referral })\n break\n case MemberPopupActionType.OpenSubscribe:\n pushView({ type: MemberPopupPanelType.Subscribe })\n break\n }\n }\n\n function handleClose() {\n setIsOpen(false)\n setViewStack([])\n setIsSubscribeFormHidden(false)\n }\n\n return (\n <ViewStackContext.Provider value={{ pushView, popView }}>\n {isOpen && <div className=\"fixed inset-0 z-[998]\" onClick={handleClose} />}\n <div\n className=\"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0\"\n style={{ bottom: bottomOffset }}\n >\n {isOpen && (\n <div\n className={cn(\n 'relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]',\n rounded ? 'rounded-[12px]' : 'rounded-none'\n )}\n style={{ maxHeight: 'min(80vh, 606px)' }}\n onClick={e => e.stopPropagation()}\n >\n <div className=\"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white\" />\n <div className=\"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]\">\n {currentView !== null && (\n <button\n className=\"mr-auto flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={popView}\n aria-label=\"Back\"\n >\n <IconSwitch />\n </button>\n )}\n <button\n className=\"flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={handleClose}\n aria-label=\"Close\"\n >\n <IconClose />\n </button>\n </div>\n\n <div className=\"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]\">\n {currentView === null && (\n <>\n {(copy.title || copy.subtitle) && (\n <div className=\"flex flex-col gap-[4px]\">\n {copy.title && (\n <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>\n )}\n {copy.subtitle && (\n <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n )}\n {copy.list.map((item, i) => (\n <HomeCard key={i} item={item} onAction={handleAction} rounded={rounded} />\n ))}\n </>\n )}\n\n {currentView !== null && (\n <Suspense\n fallback={\n <div className=\"flex items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n }\n >\n {currentView.type === MemberPopupPanelType.EarnCredits && copy.earnCredits && (\n <EarnCredits\n copy={copy.earnCredits}\n onClose={popView}\n isProfileCompleteSuccess={isProfileCompleteSuccess}\n isSubscribeSuccess={isSubscribeSuccess}\n isActivateSuccess={isActivateSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.ConsumeCredits && copy.consumeCredits && (\n <ConsumeCredits\n copy={copy.consumeCredits}\n onClose={popView}\n isActivateSuccess={isActivateSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Referral && copy.referral && (\n <Referral copy={copy.referral} onClose={popView} />\n )}\n {currentView.type === MemberPopupPanelType.CompleteProfile && copy.earnCredits && (\n <CompleteProfile\n copy={copy.earnCredits.completeProfile}\n shopifyStoreDomain={storeDomain}\n onClose={popView}\n onSuccess={() => setIsProfileCompleteSuccess(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.Subscribe && copy.activitiesSubscribe && (\n <ActivitiesSubscribe\n copy={copy.activitiesSubscribe}\n email={profile?.email}\n onSuccess={() => setIsSubscribeSuccess(true)}\n hideForm={isSubscribeFormHidden}\n onHideForm={() => setIsSubscribeFormHidden(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.SubscribeEmail && copy.earnCredits && (\n <SubscribeEmail\n copy={copy.earnCredits.subscribe}\n email={profile?.email}\n onClose={popView}\n onSuccess={() => setIsSubscribeSuccess(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.Activate && copy.earnCredits && (\n <Activate\n copy={copy.earnCredits.authCodeActivate}\n onClose={popView}\n onSuccess={() => {\n setIsActivateSuccess(true)\n }}\n />\n )}\n {currentView.type === MemberPopupPanelType.RedeemCoupon &&\n currentView.props &&\n copy.consumeCredits && (\n <RedeemCoupon\n itemTitle={currentView.props.itemTitle}\n itemCredits={currentView.props.itemCredits}\n itemImage={currentView.props.itemImage}\n itemValue={currentView.props.itemValue}\n itemOff={currentView.props.itemOff}\n itemRules={currentView.props.itemRules}\n redeemId={currentView.props.redeemId}\n userId={currentView.props.userId}\n alpcConfig={currentView.props.alpcConfig}\n copy={copy.consumeCredits.redeemModal}\n pointUnit={copy.consumeCredits.creditUnit}\n onClose={popView}\n />\n )}\n </Suspense>\n )}\n </div>\n\n {copy.footer && !isLogin && (\n <div className=\"border-t border-[#dadce0] p-[16px]\">\n <div className=\"flex items-center justify-between gap-[16px]\">\n <div className=\"flex items-center gap-[4px]\">\n <span className=\"text-[14px] font-[700] text-[#080a0f]\">{copy.footer.loginHint}</span>\n <button\n className=\"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={openSignInPopup}\n >\n {copy.footer.loginLabel}\n </button>\n </div>\n <div className=\"flex shrink-0 items-center gap-[8px]\">\n <button\n className={cn(\n 'cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n onClick={openSignUpPopup}\n >\n {copy.footer.joinLabel}\n </button>\n </div>\n </div>\n </div>\n )}\n </div>\n )}\n\n <button\n className=\"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]\"\n onClick={() => setIsOpen(prev => !prev)}\n aria-label={copy.triggerImg.alt ?? 'Open member popup'}\n >\n <Picture source={copy.triggerImg.url} alt={copy.triggerImg.alt ?? ''} className=\"size-[58px]\" />\n </button>\n </div>\n </ViewStackContext.Provider>\n )\n}\n\ntype HomeCardProps = {\n item: MemberPopupItem\n onAction: (type: MemberPopupActionType, url?: string) => void\n rounded: boolean\n}\n\nfunction HomeCard({ item, onAction, rounded }: HomeCardProps) {\n const ACTION_ICON: Partial<Record<MemberPopupActionType, typeof IconCredit>> = {\n [MemberPopupActionType.OpenEarnCredits]: IconCredit,\n [MemberPopupActionType.OpenConsumeCredits]: IconBag,\n [MemberPopupActionType.OpenReferral]: IconReferral,\n [MemberPopupActionType.OpenSubscribe]: IconSubscription,\n }\n\n return (\n <div className={cn('flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]', rounded ? 'rounded-[8px]' : 'rounded-none')}>\n <div className=\"flex flex-col gap-[4px]\">\n <h3 className=\"text-[20px] font-[700] leading-[1.2] text-[#1e2024]\">{item.title}</h3>\n {item.description && <p className=\"text-[14px] font-[700] leading-[1.43] text-[#1e2024]\">{item.description}</p>}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {item.links.map((link, i) => {\n const IconComponent = ACTION_ICON[link.type]\n return (\n <div key={i}>\n {i > 0 && <div className=\"mb-[16px] h-px bg-[#dadce0]\" />}\n <button\n className=\"flex w-full cursor-pointer items-center gap-[12px]\"\n onClick={() => onAction(link.type, link.url)}\n >\n {IconComponent && <IconComponent className=\"size-[24px] shrink-0\" />}\n <span className=\"flex-1 text-left text-[14px] font-[700] text-[#1e2024]\">{link.label}</span>\n <IconArrow className=\"size-[16px] shrink-0\" />\n </button>\n </div>\n )\n })}\n </div>\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": "ukBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,iBAAAE,KAAA,eAAAC,EAAAH,IA6DM,IAAAI,EAAA,6BA3DNC,EAAiE,iBACjEC,EAAwB,iCACxBC,EAA0E,yBAC1EC,EAOO,kBACPC,EAAoC,8BACpCA,EAAsC,8BACtCC,EAAmD,+BACnDC,EAAsG,mBACtGC,EAA+B,2BAE/B,MAAMC,KAAc,QAAK,IAAM,OAAO,sBAAsB,CAAC,EACvDC,KAAiB,QAAK,IAAM,OAAO,yBAAyB,CAAC,EAC7DC,KAAW,QAAK,IAAM,OAAO,mBAAmB,CAAC,EACjDC,KAAkB,QAAK,IAAM,OAAO,2CAA2C,CAAC,EAChFC,KAAsB,QAAK,IAAM,OAAO,mCAAmC,CAAC,EAC5EC,KAAiB,QAAK,IAAM,OAAO,0CAA0C,CAAC,EAC9EC,MAAW,QAAK,IAAM,OAAO,oCAAoC,CAAC,EAClEC,MAAe,QAAK,IAAM,OAAO,2CAA2C,CAAC,EAQ5E,SAASlB,GAAY,CAAE,KAAAmB,EAAM,aAAAC,EAAe,OAAQ,GAAGC,CAAc,EAAqB,CAC/F,KAAM,CAACC,EAAWC,CAAY,KAAI,YAAS,EAAK,EAEhD,sBAAU,IAAM,CACd,MAAMC,EAASL,EAAK,WACpB,GAAI,CAACK,EAAQ,CACXD,EAAa,EAAI,EACjB,MACF,CACA,MAAME,EAAW,OAAO,SAAS,SAC3BC,EAAUF,EAAO,MAAM,KAAKG,GAAQF,IAAaE,GAAQF,EAAS,WAAWE,EAAO,GAAG,CAAC,EAC9F,OAAQH,EAAO,MAAO,CACpB,KAAK,uBAAqB,QACxBD,EAAaG,CAAO,EACpB,MACF,KAAK,uBAAqB,QACxBH,EAAa,CAACG,CAAO,EACrB,MACF,Q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AU,sDAAuD,SAAAyB,EAAK,MAAM,EAC/EA,EAAK,gBAAe,OAAC,KAAE,UAAU,uDAAwD,SAAAA,EAAK,YAAY,GAC7G,KAEA,OAAC,OAAI,UAAU,2BACZ,SAAAA,EAAK,MAAM,IAAI,CAACK,EAAMJ,IAAM,CAC3B,MAAMK,EAAgBF,EAAYC,EAAK,IAAI,EAC3C,SACE,QAAC,OACE,UAAAJ,EAAI,MAAK,OAAC,OAAI,UAAU,8BAA8B,KACvD,QAAC,UACC,UAAU,qDACV,QAAS,IAAME,EAASE,EAAK,KAAMA,EAAK,GAAG,EAE1C,UAAAC,MAAiB,OAACA,EAAA,CAAc,UAAU,uBAAuB,KAClE,OAAC,QAAK,UAAU,yDAA0D,SAAAD,EAAK,MAAM,KACrF,OAAC,aAAU,UAAU,uBAAuB,GAC9C,IATQJ,CAUV,CAEJ,CAAC,EACH,GACF,CAEJ",
|
|
6
|
+
"names": ["MemberPopup_exports", "__export", "MemberPopup", "__toCommonJS", "import_jsx_runtime", "import_react", "import_headless_ui", "import_lib", "import_type", "import_provider", "import_viewStack", "import_icons", "import_constants", "EarnCredits", "ConsumeCredits", "Referral", "CompleteProfile", "ActivitiesSubscribe", "SubscribeEmail", "Activate", "RedeemCoupon", "copy", "bottomOffset", "providerProps", "isVisible", "setIsVisible", "config", "pathname", "matches", "page", "MemberPopupContent", "profile", "openSignInPopup", "openSignUpPopup", "brand", "storeDomain", "rounded", "isLogin", "isOpen", "setIsOpen", "viewStack", "setViewStack", "isSubscribeSuccess", "setIsSubscribeSuccess", "isActivateSuccess", "setIsActivateSuccess", "isProfileCompleteSuccess", "setIsProfileCompleteSuccess", "isSubscribeFormHidden", "setIsSubscribeFormHidden", "currentView", "pushView", "view", "prev", "popView", "handleAction", "type", "url", "handleClose", "cn", "e", "item", "i", "HomeCard", "onAction", "ACTION_ICON", "link", "IconComponent"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var y=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var J=(a,r)=>{for(var p in r)y(a,p,{get:r[p],enumerable:!0})},K=(a,r,p,
|
|
1
|
+
"use strict";var y=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var J=(a,r)=>{for(var p in r)y(a,p,{get:r[p],enumerable:!0})},K=(a,r,p,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of H(r))!q.call(a,i)&&i!==p&&y(a,i,{get:()=>r[i],enumerable:!(l=G(r,i))||l.enumerable});return a};var Q=a=>K(y({},"__esModule",{value:!0}),a);var Y={};J(Y,{default:()=>X});module.exports=Q(Y);var t=require("react/jsx-runtime"),x=require("react"),v=require("@anker-in/headless-ui"),o=require("@anker-in/lib"),B=require("../../context/provider"),D=require("../../context/viewStack"),A=require("./hooks/useRedeemableList"),S=require("./hooks/useRedeemAndBuy"),n=require("../../type"),m=require("../../../credits/context/utils"),L=require("../../../../constants");function W({copy:a,isActivateSuccess:r,onClose:p}){const{profile:l,creditInfo:i,openSignUpPopup:U,alpcConfig:b}=(0,B.useMemberPopupContext)(),{pushView:I}=(0,D.useViewStack)(),{brand:M}=(0,o.useHeadlessContext)(),N=L.ROUNDED_BRANDS.includes(M),[P,R]=(0,x.useState)(""),[O,w]=(0,x.useState)(null),c=!!l,{redeemableList:_,listLoading:E}=(0,A.useRedeemableList)(b),{trigger:$}=(0,S.useRedeemAndBuy)(b),z=a.list.map(e=>e.product?.handle).filter(Boolean),{data:k}=(0,o.useProductsByHandles)({handles:z}),F=(0,x.useMemo)(()=>a.list.map(e=>{const s=_.find(f=>String(f.id)===String(e.redeemId));if(!s)return null;const d=Number(i?.available_credit??0),C=c&&!!l?.activated&&s.consume_credits>d,g=s.is_limited&&(!s.remaining_inventory||s.remaining_inventory<=0);let u,h;return(e.type===n.ConsumeCreditsItemType.RedeemAndBuy||e.type===n.ConsumeCreditsItemType.Product)&&e.product&&(u=k?.find(f=>f.handle===e.product.handle),h=u?.variants?.find(f=>f.sku===e.product.sku)??u?.variants?.[0],e.type===n.ConsumeCreditsItemType.RedeemAndBuy&&(!u||!h))?null:{...e,alpcData:s,insufficient:C,soldOut:g,product:u,variant:h}}).filter(Boolean),[a.list,_,i,l,c,k]);function T(e){return c?e.soldOut?a.soldOut:a.btnRedeem:a.unlockRewards}function V(e){return e.type===n.ConsumeCreditsItemType.GiftCard||e.type===n.ConsumeCreditsItemType.Product?e.insufficient:e.soldOut||e.insufficient}async function j(e){if(!c){U();return}if(!l?.activated&&!r){I({type:n.MemberPopupPanelType.Activate,props:{}});return}if(e.type===n.ConsumeCreditsItemType.GiftCard||e.type===n.ConsumeCreditsItemType.Product){a.creditsPage?.url&&window.open(a.creditsPage.url,"_blank","noopener,noreferrer");return}if(e.type===n.ConsumeCreditsItemType.Coupon)I({type:n.MemberPopupPanelType.RedeemCoupon,props:{itemTitle:e.title,itemCredits:e.alpcData.consume_credits,itemImage:a.imageMapping?.[e.type]?{url:a.imageMapping[e.type].url,alt:e.image?.alt}:e.image,itemValue:e.value,itemOff:a.off,itemRules:e.rules,redeemId:Number(e.redeemId),userId:l?.user_id,alpcConfig:b}});else{R(""),w(e.redeemId);try{await $({productVariant:e.variant,redeemId:Number(e.redeemId),userId:l?.user_id})}catch(s){R(s?.message??a.redeemModal.commonError)}finally{w(null)}}}return(0,t.jsx)(t.Fragment,{children:(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[12px]",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-[8px]",children:[a.title&&(0,t.jsx)("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:a.title}),a.subtitle&&(0,t.jsx)("p",{className:"text-[16px] font-[700] leading-snug text-[#4a4c56]",children:a.subtitle})]}),c&&(0,t.jsxs)("div",{className:(0,o.classNames)("flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]",N?"rounded-[8px]":"rounded-none"),children:[(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[4px]",children:[(0,t.jsx)("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:a.balanceLabel??"AnkerCredits Balance"}),(0,t.jsxs)("div",{className:"flex items-end gap-[4px]",children:[(0,t.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,m.numberFormat)(i?.available_credit||0)}),(0,t.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??"ankercredits"})]})]}),(0,t.jsx)("div",{className:"h-full w-px bg-[#dadce0]"}),(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[4px]",children:[(0,t.jsx)("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:a.comingSoonLabel??"Coming Soon"}),(0,t.jsxs)("div",{className:"flex items-end gap-[4px]",children:[(0,t.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,m.numberFormat)(i?.pending_credit||0)}),(0,t.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??"ankercredits"})]})]})]}),P&&(0,t.jsx)("div",{className:"text-[14px] font-[700] text-[#f84d4f]",children:P}),E?(0,t.jsx)("div",{className:"flex flex-1 items-center justify-center py-[32px]",children:(0,t.jsx)("div",{className:"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent"})}):(0,t.jsx)("div",{className:"flex flex-col",children:F.map((e,s)=>{const d=!!e.product;return(0,t.jsxs)("div",{className:"relative py-[16px]",children:[s>0&&(0,t.jsx)("div",{className:"absolute inset-x-0 top-0 h-px bg-[#dadce0]"}),(0,t.jsxs)("div",{className:"flex items-center gap-[12px]",children:[(()=>{const C=a.imageMapping?.[e.type]?.url,g=d?e.variant?.image?.url??e.product?.images?.[0]?.url??e.image?.url:C??e.image?.url,u=d?e.variant?.image?.altText??e.product?.images?.[0]?.alt??e.image?.alt??"":e.image?.alt??"";return g?(0,t.jsxs)("div",{className:(0,o.classNames)("relative size-[64px] shrink-0 overflow-hidden",N?"rounded-[4px]":"rounded-none"),children:[(0,t.jsx)(v.Picture,{source:g,alt:u,className:"flex size-full items-center justify-center",imgClassName:d?"object-cover":"h-full w-auto object-contain"}),!d&&e.value&&(0,t.jsxs)("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:[e.value," ",a.off]})]}):null})(),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("div",{className:"text-[16px] font-[700] text-[#1e2024] line-clamp-2",children:d&&e.product?.title?e.product.title:e.title}),(0,t.jsx)("div",{className:"mt-[4px] text-[14px] text-[#666]",children:d&&e.price!=null?`${(0,m.numberFormat)(e.alpcData.consume_credits)} ${a.creditUnit??""} + $${Number(e.price).toFixed(2)}`:`${(0,m.numberFormat)(e.alpcData.consume_credits)} ${a.creditUnit??""}`})]}),(0,t.jsxs)("div",{className:"relative group",children:[(0,t.jsx)(v.Button,{className:(0,o.classNames)("bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white",N?"rounded-[4px]":"rounded-none"),disabled:V(e),loading:O===e.redeemId,onClick:()=>j(e),children:T(e)}),e.insufficient&&(0,t.jsx)("div",{className:"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block",children:(0,t.jsxs)("div",{className:"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow",children:[(0,t.jsx)("p",{className:"text-pretty tracking-[-0.02em] text-[14px]",children:a.insufficientCredits}),(0,t.jsx)("div",{className:"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]"})]})})]})]})]},s)})}),a.creditsPage?.url&&(0,t.jsx)("a",{href:a.creditsPage.url,target:"_blank",rel:"noopener noreferrer",className:"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline",children:a.creditsPage.label??"Go to Credits Page"})]})})}var X=W;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/ConsumeCredits/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { classNames as cn, useProductsByHandles, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useRedeemableList } from './hooks/useRedeemableList'\nimport { useRedeemAndBuy } from './hooks/useRedeemAndBuy'\nimport {\n ConsumeCreditsItemType,\n MemberPopupPanelType,\n type ConsumeCreditsopy,\n type ConsumeCreditsItem,\n} from '../../type'\nimport { numberFormat } from '../../../credits/context/utils'\nimport type { ConsumeCreditRuleResponse } from '../../../credits/context/response'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype EnrichedItem = ConsumeCreditsItem & {\n alpcData: ConsumeCreditRuleResponse\n insufficient: boolean\n soldOut: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n onClose: () => void\n isActivateSuccess: boolean\n}\n\nfunction ConsumeCredits({ copy, isActivateSuccess, onClose }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [redeemAndBuyError, setRedeemAndBuyError] = useState('')\n const [loadingId, setLoadingId] = useState<string | number | null>(null)\n\n const isLogin = !!profile\n const { redeemableList, listLoading } = useRedeemableList(alpcConfig)\n const { trigger: redeemAndBuy } = useRedeemAndBuy(alpcConfig)\n\n const handles = copy.list.map(item => item.product?.handle).filter(Boolean) as string[]\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const alpcData = redeemableList.find(r => String(r.id) === String(item.redeemId))\n if (!alpcData) return null\n\n const availableCredit = Number(creditInfo?.available_credit ?? 0)\n const insufficient = isLogin && !!profile?.activated && alpcData.consume_credits > availableCredit\n const soldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n let product\n let variant\n if (\n (item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product) &&\n item.product\n ) {\n product = products?.find((p: any) => p.handle === item.product!.handle)\n variant = product?.variants?.find((v: any) => v.sku === item.product!.sku) ?? product?.variants?.[0]\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && (!product || !variant)) return null\n }\n\n return { ...item, alpcData, insufficient, soldOut, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin) return copy.unlockRewards\n if (item.soldOut) return copy.soldOut\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n return item.insufficient\n }\n return item.soldOut || item.insufficient\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!profile?.activated && !isActivateSuccess) {\n pushView({\n type: MemberPopupPanelType.Activate,\n props: {},\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n window.open(copy.creditsPage.url, '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n pushView({\n type: MemberPopupPanelType.RedeemCoupon,\n props: {\n itemTitle: item.title,\n itemCredits: item.alpcData.consume_credits,\n itemImage: copy.imageMapping?.[item.type]\n ? { url: copy.imageMapping[item.type]!.url, alt: item.image?.alt }\n : item.image,\n itemValue: item.value,\n itemOff: copy.off,\n itemRules: item.rules,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n alpcConfig,\n },\n })\n } else {\n setRedeemAndBuyError('')\n setLoadingId(item.redeemId)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n } catch (e: any) {\n setRedeemAndBuyError(e?.message ?? copy.redeemModal.commonError)\n } finally {\n setLoadingId(null)\n }\n }\n }\n\n return (\n <>\n <div className=\"flex flex-1 flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n {copy.subtitle && <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n {redeemAndBuyError && <div className=\"text-[14px] font-[700] text-[#f84d4f]\">{redeemAndBuyError}</div>}\n\n {listLoading ? (\n <div className=\"flex flex-1 items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n ) : (\n <div className=\"flex flex-col\">\n {list.map((item, idx) => {\n const hasProduct = !!item.product\n return (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute inset-x-0 top-0 h-px bg-[#dadce0]\" />}\n <div className=\"flex items-center gap-[12px]\">\n {(() => {\n const mappedImgUrl = copy.imageMapping?.[item.type]?.url\n const imgUrl = hasProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : (mappedImgUrl ?? item.image?.url)\n const imgAlt = hasProduct\n ? (item.variant?.image?.altText ?? item.product?.images?.[0]?.alt ?? item.image?.alt ?? '')\n : (item.image?.alt ?? '')\n if (!imgUrl) return null\n return (\n <div\n className={cn(\n 'relative size-[64px] shrink-0 overflow-hidden',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n >\n <Picture\n source={imgUrl}\n alt={imgAlt}\n className=\"flex size-full items-center justify-center\"\n imgClassName={hasProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {!hasProduct && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value} {copy.off}\n </div>\n )}\n </div>\n )\n })()}\n <div className=\"min-w-0 flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024] line-clamp-2\">\n {hasProduct && item.product?.title ? item.product.title : item.title}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {hasProduct && item.price != null\n ? `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''} + $${Number(item.price).toFixed(2)}`\n : `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''}`}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n className={cn(\n 'bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && (\n <div className=\"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block\">\n <div className=\"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow\">\n <p className=\"text-pretty tracking-[-0.02em] text-[14px]\">{copy.insufficientCredits}</p>\n <div className=\"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]\" />\n </div>\n </div>\n )}\n </div>\n </div>\n </div>\n )\n })}\n </div>\n )}\n\n {copy.creditsPage?.url && (\n <a\n href={copy.creditsPage.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.creditsPage.label ?? 'Go to Credits Page'}\n </a>\n )}\n </div>\n </>\n )\n}\n\nexport default ConsumeCredits\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GA2II,IAAAI,EAAA,6BA3IJC,EAAkC,iBAClCC,EAAgC,iCAChCC,EAA2E,yBAC3EC,EAAsC,kCACtCC,EAA6B,mCAC7BC,EAAkC,qCAClCC,EAAgC,mCAChCC,EAKO,sBACPC,EAA6B,0CAE7BC,EAA+B,iCAgB/B,SAASC,EAAe,CAAE,KAAAC,EAAM,kBAAAC,EAAmB,QAAAC,CAAQ,EAAU,CACnE,KAAM,CAAE,QAAAC,EAAS,WAAAC,EAAY,gBA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,eAAgBE,EAAK,QACrB,SAAU,OAAOA,EAAK,QAAQ,EAC9B,OAAQhB,GAAS,OACnB,CAAC,CACH,OAAS+B,EAAQ,CACfvB,EAAqBuB,GAAG,SAAWlC,EAAK,YAAY,WAAW,CACjE,QAAE,CACAa,EAAa,IAAI,CACnB,CACF,CACF,CAEA,SACE,mBACE,oBAAC,OAAI,UAAU,kCACb,qBAAC,OAAI,UAAU,0BACZ,UAAAb,EAAK,UAAS,OAAC,MAAG,UAAU,sDAAuD,SAAAA,EAAK,MAAM,EAC9FA,EAAK,aAAY,OAAC,KAAE,UAAU,qDAAsD,SAAAA,EAAK,SAAS,GACrG,EAECc,MACC,QAAC,OACC,aAAW,EAAAqB,YACT,qDACA1B,EAAU,gBAAkB,cAC9B,EAEA,qBAAC,OAAI,UAAU,iCACb,oBAAC,OAAI,UAAU,wCAAyC,SAAAT,EAAK,cAAgB,uBAAuB,KACpG,QAAC,OAAI,UAAU,2BACb,oBAAC,QAAK,UAAU,sDACb,4BAAaI,GAAY,kBAAoB,CAAC,EACjD,KACA,OAAC,QAAK,UAAU,sDACb,SAAAJ,EAAK,
|
|
4
|
+
"sourcesContent": ["import { useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { classNames as cn, useProductsByHandles, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useRedeemableList } from './hooks/useRedeemableList'\nimport { useRedeemAndBuy } from './hooks/useRedeemAndBuy'\nimport {\n ConsumeCreditsItemType,\n MemberPopupPanelType,\n type ConsumeCreditsopy,\n type ConsumeCreditsItem,\n} from '../../type'\nimport { numberFormat } from '../../../credits/context/utils'\nimport type { ConsumeCreditRuleResponse } from '../../../credits/context/response'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype EnrichedItem = ConsumeCreditsItem & {\n alpcData: ConsumeCreditRuleResponse\n insufficient: boolean\n soldOut: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n onClose: () => void\n isActivateSuccess: boolean\n}\n\nfunction ConsumeCredits({ copy, isActivateSuccess, onClose }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [redeemAndBuyError, setRedeemAndBuyError] = useState('')\n const [loadingId, setLoadingId] = useState<string | number | null>(null)\n\n const isLogin = !!profile\n const { redeemableList, listLoading } = useRedeemableList(alpcConfig)\n const { trigger: redeemAndBuy } = useRedeemAndBuy(alpcConfig)\n\n const handles = copy.list.map(item => item.product?.handle).filter(Boolean) as string[]\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const alpcData = redeemableList.find(r => String(r.id) === String(item.redeemId))\n if (!alpcData) return null\n\n const availableCredit = Number(creditInfo?.available_credit ?? 0)\n const insufficient = isLogin && !!profile?.activated && alpcData.consume_credits > availableCredit\n const soldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n let product\n let variant\n if (\n (item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product) &&\n item.product\n ) {\n product = products?.find((p: any) => p.handle === item.product!.handle)\n variant = product?.variants?.find((v: any) => v.sku === item.product!.sku) ?? product?.variants?.[0]\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && (!product || !variant)) return null\n }\n\n return { ...item, alpcData, insufficient, soldOut, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin) return copy.unlockRewards\n if (item.soldOut) return copy.soldOut\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n return item.insufficient\n }\n return item.soldOut || item.insufficient\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!profile?.activated && !isActivateSuccess) {\n pushView({\n type: MemberPopupPanelType.Activate,\n props: {},\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n window.open(copy.creditsPage.url, '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n pushView({\n type: MemberPopupPanelType.RedeemCoupon,\n props: {\n itemTitle: item.title,\n itemCredits: item.alpcData.consume_credits,\n itemImage: copy.imageMapping?.[item.type]\n ? { url: copy.imageMapping[item.type]!.url, alt: item.image?.alt }\n : item.image,\n itemValue: item.value,\n itemOff: copy.off,\n itemRules: item.rules,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n alpcConfig,\n },\n })\n } else {\n setRedeemAndBuyError('')\n setLoadingId(item.redeemId)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n } catch (e: any) {\n setRedeemAndBuyError(e?.message ?? copy.redeemModal.commonError)\n } finally {\n setLoadingId(null)\n }\n }\n }\n\n return (\n <>\n <div className=\"flex flex-1 flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n {copy.subtitle && <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n {redeemAndBuyError && <div className=\"text-[14px] font-[700] text-[#f84d4f]\">{redeemAndBuyError}</div>}\n\n {listLoading ? (\n <div className=\"flex flex-1 items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n ) : (\n <div className=\"flex flex-col\">\n {list.map((item, idx) => {\n const hasProduct = !!item.product\n return (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute inset-x-0 top-0 h-px bg-[#dadce0]\" />}\n <div className=\"flex items-center gap-[12px]\">\n {(() => {\n const mappedImgUrl = copy.imageMapping?.[item.type]?.url\n const imgUrl = hasProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : (mappedImgUrl ?? item.image?.url)\n const imgAlt = hasProduct\n ? (item.variant?.image?.altText ?? item.product?.images?.[0]?.alt ?? item.image?.alt ?? '')\n : (item.image?.alt ?? '')\n if (!imgUrl) return null\n return (\n <div\n className={cn(\n 'relative size-[64px] shrink-0 overflow-hidden',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n >\n <Picture\n source={imgUrl}\n alt={imgAlt}\n className=\"flex size-full items-center justify-center\"\n imgClassName={hasProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {!hasProduct && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value} {copy.off}\n </div>\n )}\n </div>\n )\n })()}\n <div className=\"min-w-0 flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024] line-clamp-2\">\n {hasProduct && item.product?.title ? item.product.title : item.title}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {hasProduct && item.price != null\n ? `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''} + $${Number(item.price).toFixed(2)}`\n : `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''}`}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n className={cn(\n 'bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && (\n <div className=\"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block\">\n <div className=\"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow\">\n <p className=\"text-pretty tracking-[-0.02em] text-[14px]\">{copy.insufficientCredits}</p>\n <div className=\"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]\" />\n </div>\n </div>\n )}\n </div>\n </div>\n </div>\n )\n })}\n </div>\n )}\n\n {copy.creditsPage?.url && (\n <a\n href={copy.creditsPage.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.creditsPage.label ?? 'Go to Credits Page'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AAclB,EAAK,SAAS,MAAQA,EAAK,QAAQ,MAAQA,EAAK,MACjE,KACA,OAAC,OAAI,UAAU,mCACZ,SAAAkB,GAAclB,EAAK,OAAS,KACzB,MAAG,gBAAaA,EAAK,SAAS,eAAe,CAAC,IAAInB,EAAK,YAAc,EAAE,OAAO,OAAOmB,EAAK,KAAK,EAAE,QAAQ,CAAC,CAAC,GAC3G,MAAG,gBAAaA,EAAK,SAAS,eAAe,CAAC,IAAInB,EAAK,YAAc,EAAE,GAC7E,GACF,KACA,QAAC,OAAI,UAAU,iBACb,oBAAC,UACC,aAAW,EAAAmC,YACT,6FACA1B,EAAU,gBAAkB,cAC9B,EACA,SAAUuB,EAAWb,CAAI,EACzB,QAASP,IAAcO,EAAK,SAC5B,QAAS,IAAMc,EAAad,CAAI,EAE/B,SAAAY,EAAeZ,CAAI,EACtB,EACCA,EAAK,iBACJ,OAAC,OAAI,UAAU,qGACb,oBAAC,OAAI,UAAU,0EACb,oBAAC,KAAE,UAAU,6CAA8C,SAAAnB,EAAK,oBAAoB,KACpF,OAAC,OAAI,UAAU,oGAAoG,GACrH,EACF,GAEJ,GACF,IAhEQoC,CAiEV,CAEJ,CAAC,EACH,EAGDpC,EAAK,aAAa,QACjB,OAAC,KACC,KAAMA,EAAK,YAAY,IACvB,OAAO,SACP,IAAI,sBACJ,UAAU,qEAET,SAAAA,EAAK,YAAY,OAAS,qBAC7B,GAEJ,EACF,CAEJ,CAEA,IAAOd,EAAQa",
|
|
6
6
|
"names": ["ConsumeCredits_exports", "__export", "ConsumeCredits_default", "__toCommonJS", "import_jsx_runtime", "import_react", "import_headless_ui", "import_lib", "import_provider", "import_viewStack", "import_useRedeemableList", "import_useRedeemAndBuy", "import_type", "import_utils", "import_constants", "ConsumeCredits", "copy", "isActivateSuccess", "onClose", "profile", "creditInfo", "openSignUpPopup", "alpcConfig", "pushView", "brand", "rounded", "redeemAndBuyError", "setRedeemAndBuyError", "loadingId", "setLoadingId", "isLogin", "redeemableList", "listLoading", "redeemAndBuy", "handles", "item", "products", "list", "alpcData", "r", "availableCredit", "insufficient", "soldOut", "product", "variant", "p", "v", "getButtonLabel", "isDisabled", "handleRedeem", "e", "cn", "idx", "hasProduct", "mappedImgUrl", "imgUrl", "imgAlt"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{Fragment as ae,jsx as t,jsxs as o}from"react/jsx-runtime";import{lazy as
|
|
1
|
+
"use client";import{Fragment as ae,jsx as t,jsxs as o}from"react/jsx-runtime";import{lazy as c,Suspense as j,useState as u,useCallback as O,useEffect as _}from"react";import{Picture as D}from"@anker-in/headless-ui";import{useHeadlessContext as F,classNames as S}from"@anker-in/lib";import{MemberPopupActionType as a,MemberPopupPageScope as A,MemberPopupPanelType as r}from"./type";import{MemberPopupProvider as L}from"./context/provider";import{useMemberPopupContext as U}from"./context/provider";import{ViewStackContext as B}from"./context/viewStack";import{IconClose as W,IconArrow as q,IconCredit as G,IconBag as J,IconReferral as K,IconSwitch as Q,IconSubscription as X}from"./icons";import{ROUNDED_BRANDS as Y}from"../../constants";const Z=c(()=>import("./panels/EarnCredits")),$=c(()=>import("./panels/ConsumeCredits")),ee=c(()=>import("./panels/Referral")),te=c(()=>import("./panels/EarnCredits/CompleteProfilePanel")),se=c(()=>import("./panels/ActivitiesSubscribePanel")),oe=c(()=>import("./panels/EarnCredits/SubscribeEmailPanel")),re=c(()=>import("./panels/EarnCredits/ActivatePanel")),ie=c(()=>import("./panels/ConsumeCredits/RedeemCouponPanel"));function ge({copy:e,bottomOffset:C="24px",...m}){const[f,i]=u(!1);return _(()=>{const l=e.pageConfig;if(!l){i(!0);return}const d=window.location.pathname,b=l.pages.some(v=>d===v||d.startsWith(v+"/"));switch(l.scope){case A.Include:i(b);break;case A.Exclude:i(!b);break;default:i(!0)}},[e.pageConfig]),console.log("isVisible",f),f?t(L,{...m,earnCreditsCopy:e.earnCredits,children:t(ne,{copy:e,bottomOffset:C})}):null}function ne({copy:e,bottomOffset:C}){const{profile:m,openSignInPopup:f,openSignUpPopup:i}=U(),{brand:l,storeDomain:d}=F(),b=Y.includes(l),v=!!m,[h,N]=u(!1),[w,P]=u([]),[V,y]=u(!1),[I,R]=u(!1),[E,H]=u(!1),[z,k]=u(!1),s=w[w.length-1]??null,g=O(n=>{P(x=>[...x,n])},[]),p=O(()=>{P(n=>n.slice(0,-1))},[]);function T(n,x){switch(n){case a.ExternalLink:x&&window.open(x,"_blank","noopener,noreferrer");break;case a.OpenEarnCredits:g({type:r.EarnCredits});break;case a.OpenConsumeCredits:g({type:r.ConsumeCredits});break;case a.OpenReferral:g({type:r.Referral});break;case a.OpenSubscribe:g({type:r.Subscribe});break}}function M(){N(!1),P([]),k(!1)}return o(B.Provider,{value:{pushView:g,popView:p},children:[h&&t("div",{className:"fixed inset-0 z-[998]",onClick:M}),o("div",{className:"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0",style:{bottom:C},children:[h&&o("div",{className:S("relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]",b?"rounded-[12px]":"rounded-none"),style:{maxHeight:"min(80vh, 606px)"},onClick:n=>n.stopPropagation(),children:[t("div",{className:"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white"}),o("div",{className:"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]",children:[s!==null&&t("button",{className:"mr-auto flex size-[24px] cursor-pointer items-center justify-center",onClick:p,"aria-label":"Back",children:t(Q,{})}),t("button",{className:"flex size-[24px] cursor-pointer items-center justify-center",onClick:M,"aria-label":"Close",children:t(W,{})})]}),o("div",{className:"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]",children:[s===null&&o(ae,{children:[(e.title||e.subtitle)&&o("div",{className:"flex flex-col gap-[4px]",children:[e.title&&t("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:e.title}),e.subtitle&&t("p",{className:"text-[16px] font-[700] leading-snug text-[#4a4c56]",children:e.subtitle})]}),e.list.map((n,x)=>t(pe,{item:n,onAction:T,rounded:b},x))]}),s!==null&&o(j,{fallback:t("div",{className:"flex items-center justify-center py-[32px]",children:t("div",{className:"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent"})}),children:[s.type===r.EarnCredits&&e.earnCredits&&t(Z,{copy:e.earnCredits,onClose:p,isProfileCompleteSuccess:E,isSubscribeSuccess:V,isActivateSuccess:I}),s.type===r.ConsumeCredits&&e.consumeCredits&&t($,{copy:e.consumeCredits,onClose:p,isActivateSuccess:I}),s.type===r.Referral&&e.referral&&t(ee,{copy:e.referral,onClose:p}),s.type===r.CompleteProfile&&e.earnCredits&&t(te,{copy:e.earnCredits.completeProfile,shopifyStoreDomain:d,onClose:p,onSuccess:()=>H(!0)}),s.type===r.Subscribe&&e.activitiesSubscribe&&t(se,{copy:e.activitiesSubscribe,email:m?.email,onSuccess:()=>y(!0),hideForm:z,onHideForm:()=>k(!0)}),s.type===r.SubscribeEmail&&e.earnCredits&&t(oe,{copy:e.earnCredits.subscribe,email:m?.email,onClose:p,onSuccess:()=>y(!0)}),s.type===r.Activate&&e.earnCredits&&t(re,{copy:e.earnCredits.authCodeActivate,onClose:p,onSuccess:()=>{R(!0)}}),s.type===r.RedeemCoupon&&s.props&&e.consumeCredits&&t(ie,{itemTitle:s.props.itemTitle,itemCredits:s.props.itemCredits,itemImage:s.props.itemImage,itemValue:s.props.itemValue,itemOff:s.props.itemOff,itemRules:s.props.itemRules,redeemId:s.props.redeemId,userId:s.props.userId,alpcConfig:s.props.alpcConfig,copy:e.consumeCredits.redeemModal,pointUnit:e.consumeCredits.creditUnit,onClose:p})]})]}),e.footer&&!v&&t("div",{className:"border-t border-[#dadce0] p-[16px]",children:o("div",{className:"flex items-center justify-between gap-[16px]",children:[o("div",{className:"flex items-center gap-[4px]",children:[t("span",{className:"text-[14px] font-[700] text-[#080a0f]",children:e.footer.loginHint}),t("button",{className:"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline",onClick:f,children:e.footer.loginLabel})]}),t("div",{className:"flex shrink-0 items-center gap-[8px]",children:t("button",{className:S("cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]",b?"rounded-[4px]":"rounded-none"),onClick:i,children:e.footer.joinLabel})})]})})]}),t("button",{className:"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]",onClick:()=>N(n=>!n),"aria-label":e.triggerImg.alt??"Open member popup",children:t(D,{source:e.triggerImg.url,alt:e.triggerImg.alt??"",className:"size-[58px]"})})]})]})}function pe({item:e,onAction:C,rounded:m}){const f={[a.OpenEarnCredits]:G,[a.OpenConsumeCredits]:J,[a.OpenReferral]:K,[a.OpenSubscribe]:X};return o("div",{className:S("flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]",m?"rounded-[8px]":"rounded-none"),children:[o("div",{className:"flex flex-col gap-[4px]",children:[t("h3",{className:"text-[20px] font-[700] leading-[1.2] text-[#1e2024]",children:e.title}),e.description&&t("p",{className:"text-[14px] font-[700] leading-[1.43] text-[#1e2024]",children:e.description})]}),t("div",{className:"flex flex-col gap-[16px]",children:e.links.map((i,l)=>{const d=f[i.type];return o("div",{children:[l>0&&t("div",{className:"mb-[16px] h-px bg-[#dadce0]"}),o("button",{className:"flex w-full cursor-pointer items-center gap-[12px]",onClick:()=>C(i.type,i.url),children:[d&&t(d,{className:"size-[24px] shrink-0"}),t("span",{className:"flex-1 text-left text-[14px] font-[700] text-[#1e2024]",children:i.label}),t(q,{className:"size-[16px] shrink-0"})]})]},l)})})]})}export{ge as MemberPopup};
|
|
2
2
|
//# sourceMappingURL=MemberPopup.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/memberPopup/MemberPopup.tsx"],
|
|
4
|
-
"sourcesContent": ["'use client'\n\nimport { lazy, Suspense, useState, useCallback, useMemo, useEffect } from 'react'\nimport { Picture } from '@anker-in/headless-ui'\nimport { type HeadlessConfig, useHeadlessContext, classNames as cn } from '@anker-in/lib'\nimport {\n MemberPopupActionType,\n MemberPopupPageScope,\n MemberPopupPanelType,\n type MemberPopupCopy,\n type MemberPopupContextValue,\n type MemberPopupItem,\n} from './type'\nimport { MemberPopupProvider } from './context/provider'\nimport { useMemberPopupContext } from './context/provider'\nimport { ViewStackContext, type ViewPayload } from './context/viewStack'\nimport { IconClose, IconArrow, IconCredit, IconBag, IconReferral, IconSwitch, IconSubscription } from './icons'\nimport { ROUNDED_BRANDS } from '../../constants'\n\nconst EarnCredits = lazy(() => import('./panels/EarnCredits'))\nconst ConsumeCredits = lazy(() => import('./panels/ConsumeCredits'))\nconst Referral = lazy(() => import('./panels/Referral'))\nconst CompleteProfile = lazy(() => import('./panels/EarnCredits/CompleteProfilePanel'))\nconst ActivitiesSubscribe = lazy(() => import('./panels/ActivitiesSubscribePanel'))\nconst SubscribeEmail = lazy(() => import('./panels/EarnCredits/SubscribeEmailPanel'))\nconst Activate = lazy(() => import('./panels/EarnCredits/ActivatePanel'))\nconst RedeemCoupon = lazy(() => import('./panels/ConsumeCredits/RedeemCouponPanel'))\n\ntype MemberPopupProps = MemberPopupContextValue & {\n headlessConfig: HeadlessConfig\n copy: MemberPopupCopy\n bottomOffset?: string\n}\n\nexport function MemberPopup({ copy, bottomOffset = '24px', ...providerProps }: MemberPopupProps) {\n const isVisible = useMemo(() => {\n const config = copy.pageConfig\n if (!config) return true\n const pathname = typeof window !== 'undefined' ? window.location.pathname : ''\n const matches = config.pages.some(page => pathname === page || pathname.startsWith(page + '/'))\n switch (config.scope) {\n case MemberPopupPageScope.Include:\n return matches\n case MemberPopupPageScope.Exclude:\n return !matches\n default:\n return true\n }\n }, [copy.pageConfig])\n\n console.log('isVisible', isVisible)\n\n return isVisible ? (\n <MemberPopupProvider {...providerProps} earnCreditsCopy={copy.earnCredits}>\n <MemberPopupContent copy={copy} bottomOffset={bottomOffset} />\n </MemberPopupProvider>\n ) : null\n}\n\ntype MemberPopupContentProps = {\n copy: MemberPopupCopy\n bottomOffset: string\n}\n\nfunction MemberPopupContent({ copy, bottomOffset }: MemberPopupContentProps) {\n const { profile, openSignInPopup, openSignUpPopup } = useMemberPopupContext()\n const { brand, storeDomain } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n const isLogin = !!profile\n const [isOpen, setIsOpen] = useState(false)\n const [viewStack, setViewStack] = useState<ViewPayload[]>([])\n const [isSubscribeSuccess, setIsSubscribeSuccess] = useState(false)\n const [isActivateSuccess, setIsActivateSuccess] = useState(false)\n const [isProfileCompleteSuccess, setIsProfileCompleteSuccess] = useState(false)\n const [isSubscribeFormHidden, setIsSubscribeFormHidden] = useState(false)\n\n const currentView = viewStack[viewStack.length - 1] ?? null\n\n const pushView = useCallback((view: ViewPayload) => {\n setViewStack(prev => [...prev, view])\n }, [])\n\n const popView = useCallback(() => {\n setViewStack(prev => prev.slice(0, -1))\n }, [])\n\n function handleAction(type: MemberPopupActionType, url?: string) {\n switch (type) {\n case MemberPopupActionType.ExternalLink:\n if (url) window.open(url, '_blank', 'noopener,noreferrer')\n break\n case MemberPopupActionType.OpenEarnCredits:\n pushView({ type: MemberPopupPanelType.EarnCredits })\n break\n case MemberPopupActionType.OpenConsumeCredits:\n pushView({ type: MemberPopupPanelType.ConsumeCredits })\n break\n case MemberPopupActionType.OpenReferral:\n pushView({ type: MemberPopupPanelType.Referral })\n break\n case MemberPopupActionType.OpenSubscribe:\n pushView({ type: MemberPopupPanelType.Subscribe })\n break\n }\n }\n\n function handleClose() {\n setIsOpen(false)\n setViewStack([])\n setIsSubscribeFormHidden(false)\n }\n\n return (\n <ViewStackContext.Provider value={{ pushView, popView }}>\n {isOpen && <div className=\"fixed inset-0 z-[998]\" onClick={handleClose} />}\n <div\n className=\"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0\"\n style={{ bottom: bottomOffset }}\n >\n {isOpen && (\n <div\n className={cn(\n 'relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]',\n rounded ? 'rounded-[12px]' : 'rounded-none'\n )}\n style={{ maxHeight: 'min(80vh, 606px)' }}\n onClick={e => e.stopPropagation()}\n >\n <div className=\"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white\" />\n <div className=\"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]\">\n {currentView !== null && (\n <button\n className=\"mr-auto flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={popView}\n aria-label=\"Back\"\n >\n <IconSwitch />\n </button>\n )}\n <button\n className=\"flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={handleClose}\n aria-label=\"Close\"\n >\n <IconClose />\n </button>\n </div>\n\n <div className=\"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]\">\n {currentView === null && (\n <>\n {(copy.title || copy.subtitle) && (\n <div className=\"flex flex-col gap-[4px]\">\n {copy.title && (\n <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>\n )}\n {copy.subtitle && (\n <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n )}\n {copy.list.map((item, i) => (\n <HomeCard key={i} item={item} onAction={handleAction} rounded={rounded} />\n ))}\n </>\n )}\n\n {currentView !== null && (\n <Suspense\n fallback={\n <div className=\"flex items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n }\n >\n {currentView.type === MemberPopupPanelType.EarnCredits && copy.earnCredits && (\n <EarnCredits\n copy={copy.earnCredits}\n onClose={popView}\n isProfileCompleteSuccess={isProfileCompleteSuccess}\n isSubscribeSuccess={isSubscribeSuccess}\n isActivateSuccess={isActivateSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.ConsumeCredits && copy.consumeCredits && (\n <ConsumeCredits\n copy={copy.consumeCredits}\n onClose={popView}\n isActivateSuccess={isActivateSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Referral && copy.referral && (\n <Referral copy={copy.referral} onClose={popView} />\n )}\n {currentView.type === MemberPopupPanelType.CompleteProfile && copy.earnCredits && (\n <CompleteProfile\n copy={copy.earnCredits.completeProfile}\n shopifyStoreDomain={storeDomain}\n onClose={popView}\n onSuccess={() => setIsProfileCompleteSuccess(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.Subscribe && copy.activitiesSubscribe && (\n <ActivitiesSubscribe\n copy={copy.activitiesSubscribe}\n email={profile?.email}\n onSuccess={() => setIsSubscribeSuccess(true)}\n hideForm={isSubscribeFormHidden}\n onHideForm={() => setIsSubscribeFormHidden(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.SubscribeEmail && copy.earnCredits && (\n <SubscribeEmail\n copy={copy.earnCredits.subscribe}\n email={profile?.email}\n onClose={popView}\n onSuccess={() => setIsSubscribeSuccess(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.Activate && copy.earnCredits && (\n <Activate\n copy={copy.earnCredits.authCodeActivate}\n onClose={popView}\n onSuccess={() => {\n setIsActivateSuccess(true)\n }}\n />\n )}\n {currentView.type === MemberPopupPanelType.RedeemCoupon &&\n currentView.props &&\n copy.consumeCredits && (\n <RedeemCoupon\n itemTitle={currentView.props.itemTitle}\n itemCredits={currentView.props.itemCredits}\n itemImage={currentView.props.itemImage}\n itemValue={currentView.props.itemValue}\n itemOff={currentView.props.itemOff}\n itemRules={currentView.props.itemRules}\n redeemId={currentView.props.redeemId}\n userId={currentView.props.userId}\n alpcConfig={currentView.props.alpcConfig}\n copy={copy.consumeCredits.redeemModal}\n pointUnit={copy.consumeCredits.creditUnit}\n onClose={popView}\n />\n )}\n </Suspense>\n )}\n </div>\n\n {copy.footer && !isLogin && (\n <div className=\"border-t border-[#dadce0] p-[16px]\">\n <div className=\"flex items-center justify-between gap-[16px]\">\n <div className=\"flex items-center gap-[4px]\">\n <span className=\"text-[14px] font-[700] text-[#080a0f]\">{copy.footer.loginHint}</span>\n <button\n className=\"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={openSignInPopup}\n >\n {copy.footer.loginLabel}\n </button>\n </div>\n <div className=\"flex shrink-0 items-center gap-[8px]\">\n <button\n className={cn(\n 'cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n onClick={openSignUpPopup}\n >\n {copy.footer.joinLabel}\n </button>\n </div>\n </div>\n </div>\n )}\n </div>\n )}\n\n <button\n className=\"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]\"\n onClick={() => setIsOpen(prev => !prev)}\n aria-label={copy.triggerImg.alt ?? 'Open member popup'}\n >\n <Picture source={copy.triggerImg.url} alt={copy.triggerImg.alt ?? ''} className=\"size-[58px]\" />\n </button>\n </div>\n </ViewStackContext.Provider>\n )\n}\n\ntype HomeCardProps = {\n item: MemberPopupItem\n onAction: (type: MemberPopupActionType, url?: string) => void\n rounded: boolean\n}\n\nfunction HomeCard({ item, onAction, rounded }: HomeCardProps) {\n const ACTION_ICON: Partial<Record<MemberPopupActionType, typeof IconCredit>> = {\n [MemberPopupActionType.OpenEarnCredits]: IconCredit,\n [MemberPopupActionType.OpenConsumeCredits]: IconBag,\n [MemberPopupActionType.OpenReferral]: IconReferral,\n [MemberPopupActionType.OpenSubscribe]: IconSubscription,\n }\n\n return (\n <div className={cn('flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]', rounded ? 'rounded-[8px]' : 'rounded-none')}>\n <div className=\"flex flex-col gap-[4px]\">\n <h3 className=\"text-[20px] font-[700] leading-[1.2] text-[#1e2024]\">{item.title}</h3>\n {item.description && <p className=\"text-[14px] font-[700] leading-[1.43] text-[#1e2024]\">{item.description}</p>}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {item.links.map((link, i) => {\n const IconComponent = ACTION_ICON[link.type]\n return (\n <div key={i}>\n {i > 0 && <div className=\"mb-[16px] h-px bg-[#dadce0]\" />}\n <button\n className=\"flex w-full cursor-pointer items-center gap-[12px]\"\n onClick={() => onAction(link.type, link.url)}\n >\n {IconComponent && <IconComponent className=\"size-[24px] shrink-0\" />}\n <span className=\"flex-1 text-left text-[14px] font-[700] text-[#1e2024]\">{link.label}</span>\n <IconArrow className=\"size-[16px] shrink-0\" />\n </button>\n </div>\n )\n })}\n </div>\n </div>\n )\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["Fragment", "jsx", "jsxs", "lazy", "Suspense", "useState", "useCallback", "
|
|
4
|
+
"sourcesContent": ["'use client'\n\nimport { lazy, Suspense, useState, useCallback, useEffect } from 'react'\nimport { Picture } from '@anker-in/headless-ui'\nimport { type HeadlessConfig, useHeadlessContext, classNames as cn } from '@anker-in/lib'\nimport {\n MemberPopupActionType,\n MemberPopupPageScope,\n MemberPopupPanelType,\n type MemberPopupCopy,\n type MemberPopupContextValue,\n type MemberPopupItem,\n} from './type'\nimport { MemberPopupProvider } from './context/provider'\nimport { useMemberPopupContext } from './context/provider'\nimport { ViewStackContext, type ViewPayload } from './context/viewStack'\nimport { IconClose, IconArrow, IconCredit, IconBag, IconReferral, IconSwitch, IconSubscription } from './icons'\nimport { ROUNDED_BRANDS } from '../../constants'\n\nconst EarnCredits = lazy(() => import('./panels/EarnCredits'))\nconst ConsumeCredits = lazy(() => import('./panels/ConsumeCredits'))\nconst Referral = lazy(() => import('./panels/Referral'))\nconst CompleteProfile = lazy(() => import('./panels/EarnCredits/CompleteProfilePanel'))\nconst ActivitiesSubscribe = lazy(() => import('./panels/ActivitiesSubscribePanel'))\nconst SubscribeEmail = lazy(() => import('./panels/EarnCredits/SubscribeEmailPanel'))\nconst Activate = lazy(() => import('./panels/EarnCredits/ActivatePanel'))\nconst RedeemCoupon = lazy(() => import('./panels/ConsumeCredits/RedeemCouponPanel'))\n\ntype MemberPopupProps = MemberPopupContextValue & {\n headlessConfig: HeadlessConfig\n copy: MemberPopupCopy\n bottomOffset?: string\n}\n\nexport function MemberPopup({ copy, bottomOffset = '24px', ...providerProps }: MemberPopupProps) {\n const [isVisible, setIsVisible] = useState(false)\n\n useEffect(() => {\n const config = copy.pageConfig\n if (!config) {\n setIsVisible(true)\n return\n }\n const pathname = window.location.pathname\n const matches = config.pages.some(page => pathname === page || pathname.startsWith(page + '/'))\n switch (config.scope) {\n case MemberPopupPageScope.Include:\n setIsVisible(matches)\n break\n case MemberPopupPageScope.Exclude:\n setIsVisible(!matches)\n break\n default:\n setIsVisible(true)\n }\n }, [copy.pageConfig])\n\n console.log('isVisible', isVisible)\n\n return isVisible ? (\n <MemberPopupProvider {...providerProps} earnCreditsCopy={copy.earnCredits}>\n <MemberPopupContent copy={copy} bottomOffset={bottomOffset} />\n </MemberPopupProvider>\n ) : null\n}\n\ntype MemberPopupContentProps = {\n copy: MemberPopupCopy\n bottomOffset: string\n}\n\nfunction MemberPopupContent({ copy, bottomOffset }: MemberPopupContentProps) {\n const { profile, openSignInPopup, openSignUpPopup } = useMemberPopupContext()\n const { brand, storeDomain } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n const isLogin = !!profile\n const [isOpen, setIsOpen] = useState(false)\n const [viewStack, setViewStack] = useState<ViewPayload[]>([])\n const [isSubscribeSuccess, setIsSubscribeSuccess] = useState(false)\n const [isActivateSuccess, setIsActivateSuccess] = useState(false)\n const [isProfileCompleteSuccess, setIsProfileCompleteSuccess] = useState(false)\n const [isSubscribeFormHidden, setIsSubscribeFormHidden] = useState(false)\n\n const currentView = viewStack[viewStack.length - 1] ?? null\n\n const pushView = useCallback((view: ViewPayload) => {\n setViewStack(prev => [...prev, view])\n }, [])\n\n const popView = useCallback(() => {\n setViewStack(prev => prev.slice(0, -1))\n }, [])\n\n function handleAction(type: MemberPopupActionType, url?: string) {\n switch (type) {\n case MemberPopupActionType.ExternalLink:\n if (url) window.open(url, '_blank', 'noopener,noreferrer')\n break\n case MemberPopupActionType.OpenEarnCredits:\n pushView({ type: MemberPopupPanelType.EarnCredits })\n break\n case MemberPopupActionType.OpenConsumeCredits:\n pushView({ type: MemberPopupPanelType.ConsumeCredits })\n break\n case MemberPopupActionType.OpenReferral:\n pushView({ type: MemberPopupPanelType.Referral })\n break\n case MemberPopupActionType.OpenSubscribe:\n pushView({ type: MemberPopupPanelType.Subscribe })\n break\n }\n }\n\n function handleClose() {\n setIsOpen(false)\n setViewStack([])\n setIsSubscribeFormHidden(false)\n }\n\n return (\n <ViewStackContext.Provider value={{ pushView, popView }}>\n {isOpen && <div className=\"fixed inset-0 z-[998]\" onClick={handleClose} />}\n <div\n className=\"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0\"\n style={{ bottom: bottomOffset }}\n >\n {isOpen && (\n <div\n className={cn(\n 'relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]',\n rounded ? 'rounded-[12px]' : 'rounded-none'\n )}\n style={{ maxHeight: 'min(80vh, 606px)' }}\n onClick={e => e.stopPropagation()}\n >\n <div className=\"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white\" />\n <div className=\"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]\">\n {currentView !== null && (\n <button\n className=\"mr-auto flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={popView}\n aria-label=\"Back\"\n >\n <IconSwitch />\n </button>\n )}\n <button\n className=\"flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={handleClose}\n aria-label=\"Close\"\n >\n <IconClose />\n </button>\n </div>\n\n <div className=\"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]\">\n {currentView === null && (\n <>\n {(copy.title || copy.subtitle) && (\n <div className=\"flex flex-col gap-[4px]\">\n {copy.title && (\n <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>\n )}\n {copy.subtitle && (\n <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n )}\n {copy.list.map((item, i) => (\n <HomeCard key={i} item={item} onAction={handleAction} rounded={rounded} />\n ))}\n </>\n )}\n\n {currentView !== null && (\n <Suspense\n fallback={\n <div className=\"flex items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n }\n >\n {currentView.type === MemberPopupPanelType.EarnCredits && copy.earnCredits && (\n <EarnCredits\n copy={copy.earnCredits}\n onClose={popView}\n isProfileCompleteSuccess={isProfileCompleteSuccess}\n isSubscribeSuccess={isSubscribeSuccess}\n isActivateSuccess={isActivateSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.ConsumeCredits && copy.consumeCredits && (\n <ConsumeCredits\n copy={copy.consumeCredits}\n onClose={popView}\n isActivateSuccess={isActivateSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Referral && copy.referral && (\n <Referral copy={copy.referral} onClose={popView} />\n )}\n {currentView.type === MemberPopupPanelType.CompleteProfile && copy.earnCredits && (\n <CompleteProfile\n copy={copy.earnCredits.completeProfile}\n shopifyStoreDomain={storeDomain}\n onClose={popView}\n onSuccess={() => setIsProfileCompleteSuccess(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.Subscribe && copy.activitiesSubscribe && (\n <ActivitiesSubscribe\n copy={copy.activitiesSubscribe}\n email={profile?.email}\n onSuccess={() => setIsSubscribeSuccess(true)}\n hideForm={isSubscribeFormHidden}\n onHideForm={() => setIsSubscribeFormHidden(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.SubscribeEmail && copy.earnCredits && (\n <SubscribeEmail\n copy={copy.earnCredits.subscribe}\n email={profile?.email}\n onClose={popView}\n onSuccess={() => setIsSubscribeSuccess(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.Activate && copy.earnCredits && (\n <Activate\n copy={copy.earnCredits.authCodeActivate}\n onClose={popView}\n onSuccess={() => {\n setIsActivateSuccess(true)\n }}\n />\n )}\n {currentView.type === MemberPopupPanelType.RedeemCoupon &&\n currentView.props &&\n copy.consumeCredits && (\n <RedeemCoupon\n itemTitle={currentView.props.itemTitle}\n itemCredits={currentView.props.itemCredits}\n itemImage={currentView.props.itemImage}\n itemValue={currentView.props.itemValue}\n itemOff={currentView.props.itemOff}\n itemRules={currentView.props.itemRules}\n redeemId={currentView.props.redeemId}\n userId={currentView.props.userId}\n alpcConfig={currentView.props.alpcConfig}\n copy={copy.consumeCredits.redeemModal}\n pointUnit={copy.consumeCredits.creditUnit}\n onClose={popView}\n />\n )}\n </Suspense>\n )}\n </div>\n\n {copy.footer && !isLogin && (\n <div className=\"border-t border-[#dadce0] p-[16px]\">\n <div className=\"flex items-center justify-between gap-[16px]\">\n <div className=\"flex items-center gap-[4px]\">\n <span className=\"text-[14px] font-[700] text-[#080a0f]\">{copy.footer.loginHint}</span>\n <button\n className=\"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={openSignInPopup}\n >\n {copy.footer.loginLabel}\n </button>\n </div>\n <div className=\"flex shrink-0 items-center gap-[8px]\">\n <button\n className={cn(\n 'cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n onClick={openSignUpPopup}\n >\n {copy.footer.joinLabel}\n </button>\n </div>\n </div>\n </div>\n )}\n </div>\n )}\n\n <button\n className=\"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]\"\n onClick={() => setIsOpen(prev => !prev)}\n aria-label={copy.triggerImg.alt ?? 'Open member popup'}\n >\n <Picture source={copy.triggerImg.url} alt={copy.triggerImg.alt ?? ''} className=\"size-[58px]\" />\n </button>\n </div>\n </ViewStackContext.Provider>\n )\n}\n\ntype HomeCardProps = {\n item: MemberPopupItem\n onAction: (type: MemberPopupActionType, url?: string) => void\n rounded: boolean\n}\n\nfunction HomeCard({ item, onAction, rounded }: HomeCardProps) {\n const ACTION_ICON: Partial<Record<MemberPopupActionType, typeof IconCredit>> = {\n [MemberPopupActionType.OpenEarnCredits]: IconCredit,\n [MemberPopupActionType.OpenConsumeCredits]: IconBag,\n [MemberPopupActionType.OpenReferral]: IconReferral,\n [MemberPopupActionType.OpenSubscribe]: IconSubscription,\n }\n\n return (\n <div className={cn('flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]', rounded ? 'rounded-[8px]' : 'rounded-none')}>\n <div className=\"flex flex-col gap-[4px]\">\n <h3 className=\"text-[20px] font-[700] leading-[1.2] text-[#1e2024]\">{item.title}</h3>\n {item.description && <p className=\"text-[14px] font-[700] leading-[1.43] text-[#1e2024]\">{item.description}</p>}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {item.links.map((link, i) => {\n const IconComponent = ACTION_ICON[link.type]\n return (\n <div key={i}>\n {i > 0 && <div className=\"mb-[16px] h-px bg-[#dadce0]\" />}\n <button\n className=\"flex w-full cursor-pointer items-center gap-[12px]\"\n onClick={() => onAction(link.type, link.url)}\n >\n {IconComponent && <IconComponent className=\"size-[24px] shrink-0\" />}\n <span className=\"flex-1 text-left text-[14px] font-[700] text-[#1e2024]\">{link.label}</span>\n <IconArrow className=\"size-[16px] shrink-0\" />\n </button>\n </div>\n )\n })}\n </div>\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": "aA6DM,OAgGU,YAAAA,GAhGV,OAAAC,EA2EM,QAAAC,MA3EN,oBA3DN,OAAS,QAAAC,EAAM,YAAAC,EAAU,YAAAC,EAAU,eAAAC,EAAa,aAAAC,MAAiB,QACjE,OAAS,WAAAC,MAAe,wBACxB,OAA8B,sBAAAC,EAAoB,cAAcC,MAAU,gBAC1E,OACE,yBAAAC,EACA,wBAAAC,EACA,wBAAAC,MAIK,SACP,OAAS,uBAAAC,MAA2B,qBACpC,OAAS,yBAAAC,MAA6B,qBACtC,OAAS,oBAAAC,MAA0C,sBACnD,OAAS,aAAAC,EAAW,aAAAC,EAAW,cAAAC,EAAY,WAAAC,EAAS,gBAAAC,EAAc,cAAAC,EAAY,oBAAAC,MAAwB,UACtG,OAAS,kBAAAC,MAAsB,kBAE/B,MAAMC,EAActB,EAAK,IAAM,OAAO,sBAAsB,CAAC,EACvDuB,EAAiBvB,EAAK,IAAM,OAAO,yBAAyB,CAAC,EAC7DwB,GAAWxB,EAAK,IAAM,OAAO,mBAAmB,CAAC,EACjDyB,GAAkBzB,EAAK,IAAM,OAAO,2CAA2C,CAAC,EAChF0B,GAAsB1B,EAAK,IAAM,OAAO,mCAAmC,CAAC,EAC5E2B,GAAiB3B,EAAK,IAAM,OAAO,0CAA0C,CAAC,EAC9E4B,GAAW5B,EAAK,IAAM,OAAO,oCAAoC,CAAC,EAClE6B,GAAe7B,EAAK,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AU,yDAA0D,SAAA6E,EAAK,MAAM,EACrF7E,EAACiB,EAAA,CAAU,UAAU,uBAAuB,GAC9C,IATQwD,CAUV,CAEJ,CAAC,EACH,GACF,CAEJ",
|
|
6
|
+
"names": ["Fragment", "jsx", "jsxs", "lazy", "Suspense", "useState", "useCallback", "useEffect", "Picture", "useHeadlessContext", "cn", "MemberPopupActionType", "MemberPopupPageScope", "MemberPopupPanelType", "MemberPopupProvider", "useMemberPopupContext", "ViewStackContext", "IconClose", "IconArrow", "IconCredit", "IconBag", "IconReferral", "IconSwitch", "IconSubscription", "ROUNDED_BRANDS", "EarnCredits", "ConsumeCredits", "Referral", "CompleteProfile", "ActivitiesSubscribe", "SubscribeEmail", "Activate", "RedeemCoupon", "MemberPopup", "copy", "bottomOffset", "providerProps", "isVisible", "setIsVisible", "config", "pathname", "matches", "page", "MemberPopupContent", "profile", "openSignInPopup", "openSignUpPopup", "brand", "storeDomain", "rounded", "isLogin", "isOpen", "setIsOpen", "viewStack", "setViewStack", "isSubscribeSuccess", "setIsSubscribeSuccess", "isActivateSuccess", "setIsActivateSuccess", "isProfileCompleteSuccess", "setIsProfileCompleteSuccess", "isSubscribeFormHidden", "setIsSubscribeFormHidden", "currentView", "pushView", "view", "prev", "popView", "handleAction", "type", "url", "handleClose", "e", "item", "i", "HomeCard", "onAction", "ACTION_ICON", "link", "IconComponent"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Fragment as Q,jsx as a,jsxs as n}from"react/jsx-runtime";import{useMemo as $,useState as R}from"react";import{Picture as z,Button as F}from"@anker-in/headless-ui";import{classNames as b,useProductsByHandles as T,useHeadlessContext as V}from"@anker-in/lib";import{useMemberPopupContext as j}from"../../context/provider";import{useViewStack as G}from"../../context/viewStack";import{useRedeemableList as H}from"./hooks/useRedeemableList";import{useRedeemAndBuy as q}from"./hooks/useRedeemAndBuy";import{ConsumeCreditsItemType as i,MemberPopupPanelType as
|
|
1
|
+
import{Fragment as Q,jsx as a,jsxs as n}from"react/jsx-runtime";import{useMemo as $,useState as R}from"react";import{Picture as z,Button as F}from"@anker-in/headless-ui";import{classNames as b,useProductsByHandles as T,useHeadlessContext as V}from"@anker-in/lib";import{useMemberPopupContext as j}from"../../context/provider";import{useViewStack as G}from"../../context/viewStack";import{useRedeemableList as H}from"./hooks/useRedeemableList";import{useRedeemAndBuy as q}from"./hooks/useRedeemAndBuy";import{ConsumeCreditsItemType as i,MemberPopupPanelType as w}from"../../type";import{numberFormat as f}from"../../../credits/context/utils";import{ROUNDED_BRANDS as J}from"../../../../constants";function K({copy:t,isActivateSuccess:_,onClose:W}){const{profile:d,creditInfo:p,openSignUpPopup:k,alpcConfig:m}=j(),{pushView:N}=G(),{brand:B}=V(),x=J.includes(B),[C,h]=R(""),[D,y]=R(null),o=!!d,{redeemableList:I,listLoading:A}=H(m),{trigger:S}=q(m),L=t.list.map(e=>e.product?.handle).filter(Boolean),{data:P}=T({handles:L}),U=$(()=>t.list.map(e=>{const r=I.find(u=>String(u.id)===String(e.redeemId));if(!r)return null;const s=Number(p?.available_credit??0),g=o&&!!d?.activated&&r.consume_credits>s,c=r.is_limited&&(!r.remaining_inventory||r.remaining_inventory<=0);let l,v;return(e.type===i.RedeemAndBuy||e.type===i.Product)&&e.product&&(l=P?.find(u=>u.handle===e.product.handle),v=l?.variants?.find(u=>u.sku===e.product.sku)??l?.variants?.[0],e.type===i.RedeemAndBuy&&(!l||!v))?null:{...e,alpcData:r,insufficient:g,soldOut:c,product:l,variant:v}}).filter(Boolean),[t.list,I,p,d,o,P]);function M(e){return o?e.soldOut?t.soldOut:t.btnRedeem:t.unlockRewards}function O(e){return e.type===i.GiftCard||e.type===i.Product?e.insufficient:e.soldOut||e.insufficient}async function E(e){if(!o){k();return}if(!d?.activated&&!_){N({type:w.Activate,props:{}});return}if(e.type===i.GiftCard||e.type===i.Product){t.creditsPage?.url&&window.open(t.creditsPage.url,"_blank","noopener,noreferrer");return}if(e.type===i.Coupon)N({type:w.RedeemCoupon,props:{itemTitle:e.title,itemCredits:e.alpcData.consume_credits,itemImage:t.imageMapping?.[e.type]?{url:t.imageMapping[e.type].url,alt:e.image?.alt}:e.image,itemValue:e.value,itemOff:t.off,itemRules:e.rules,redeemId:Number(e.redeemId),userId:d?.user_id,alpcConfig:m}});else{h(""),y(e.redeemId);try{await S({productVariant:e.variant,redeemId:Number(e.redeemId),userId:d?.user_id})}catch(r){h(r?.message??t.redeemModal.commonError)}finally{y(null)}}}return a(Q,{children:n("div",{className:"flex flex-1 flex-col gap-[12px]",children:[n("div",{className:"flex flex-col gap-[8px]",children:[t.title&&a("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:t.title}),t.subtitle&&a("p",{className:"text-[16px] font-[700] leading-snug text-[#4a4c56]",children:t.subtitle})]}),o&&n("div",{className:b("flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]",x?"rounded-[8px]":"rounded-none"),children:[n("div",{className:"flex flex-1 flex-col gap-[4px]",children:[a("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:t.balanceLabel??"AnkerCredits Balance"}),n("div",{className:"flex items-end gap-[4px]",children:[a("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:f(p?.available_credit||0)}),a("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:t.creditUnit??"ankercredits"})]})]}),a("div",{className:"h-full w-px bg-[#dadce0]"}),n("div",{className:"flex flex-1 flex-col gap-[4px]",children:[a("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:t.comingSoonLabel??"Coming Soon"}),n("div",{className:"flex items-end gap-[4px]",children:[a("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:f(p?.pending_credit||0)}),a("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:t.creditUnit??"ankercredits"})]})]})]}),C&&a("div",{className:"text-[14px] font-[700] text-[#f84d4f]",children:C}),A?a("div",{className:"flex flex-1 items-center justify-center py-[32px]",children:a("div",{className:"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent"})}):a("div",{className:"flex flex-col",children:U.map((e,r)=>{const s=!!e.product;return n("div",{className:"relative py-[16px]",children:[r>0&&a("div",{className:"absolute inset-x-0 top-0 h-px bg-[#dadce0]"}),n("div",{className:"flex items-center gap-[12px]",children:[(()=>{const g=t.imageMapping?.[e.type]?.url,c=s?e.variant?.image?.url??e.product?.images?.[0]?.url??e.image?.url:g??e.image?.url,l=s?e.variant?.image?.altText??e.product?.images?.[0]?.alt??e.image?.alt??"":e.image?.alt??"";return c?n("div",{className:b("relative size-[64px] shrink-0 overflow-hidden",x?"rounded-[4px]":"rounded-none"),children:[a(z,{source:c,alt:l,className:"flex size-full items-center justify-center",imgClassName:s?"object-cover":"h-full w-auto object-contain"}),!s&&e.value&&n("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:[e.value," ",t.off]})]}):null})(),n("div",{className:"min-w-0 flex-1",children:[a("div",{className:"text-[16px] font-[700] text-[#1e2024] line-clamp-2",children:s&&e.product?.title?e.product.title:e.title}),a("div",{className:"mt-[4px] text-[14px] text-[#666]",children:s&&e.price!=null?`${f(e.alpcData.consume_credits)} ${t.creditUnit??""} + $${Number(e.price).toFixed(2)}`:`${f(e.alpcData.consume_credits)} ${t.creditUnit??""}`})]}),n("div",{className:"relative group",children:[a(F,{className:b("bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white",x?"rounded-[4px]":"rounded-none"),disabled:O(e),loading:D===e.redeemId,onClick:()=>E(e),children:M(e)}),e.insufficient&&a("div",{className:"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block",children:n("div",{className:"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow",children:[a("p",{className:"text-pretty tracking-[-0.02em] text-[14px]",children:t.insufficientCredits}),a("div",{className:"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]"})]})})]})]})]},r)})}),t.creditsPage?.url&&a("a",{href:t.creditsPage.url,target:"_blank",rel:"noopener noreferrer",className:"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline",children:t.creditsPage.label??"Go to Credits Page"})]})})}var le=K;export{le as default};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/ConsumeCredits/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { classNames as cn, useProductsByHandles, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useRedeemableList } from './hooks/useRedeemableList'\nimport { useRedeemAndBuy } from './hooks/useRedeemAndBuy'\nimport {\n ConsumeCreditsItemType,\n MemberPopupPanelType,\n type ConsumeCreditsopy,\n type ConsumeCreditsItem,\n} from '../../type'\nimport { numberFormat } from '../../../credits/context/utils'\nimport type { ConsumeCreditRuleResponse } from '../../../credits/context/response'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype EnrichedItem = ConsumeCreditsItem & {\n alpcData: ConsumeCreditRuleResponse\n insufficient: boolean\n soldOut: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n onClose: () => void\n isActivateSuccess: boolean\n}\n\nfunction ConsumeCredits({ copy, isActivateSuccess, onClose }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [redeemAndBuyError, setRedeemAndBuyError] = useState('')\n const [loadingId, setLoadingId] = useState<string | number | null>(null)\n\n const isLogin = !!profile\n const { redeemableList, listLoading } = useRedeemableList(alpcConfig)\n const { trigger: redeemAndBuy } = useRedeemAndBuy(alpcConfig)\n\n const handles = copy.list.map(item => item.product?.handle).filter(Boolean) as string[]\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const alpcData = redeemableList.find(r => String(r.id) === String(item.redeemId))\n if (!alpcData) return null\n\n const availableCredit = Number(creditInfo?.available_credit ?? 0)\n const insufficient = isLogin && !!profile?.activated && alpcData.consume_credits > availableCredit\n const soldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n let product\n let variant\n if (\n (item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product) &&\n item.product\n ) {\n product = products?.find((p: any) => p.handle === item.product!.handle)\n variant = product?.variants?.find((v: any) => v.sku === item.product!.sku) ?? product?.variants?.[0]\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && (!product || !variant)) return null\n }\n\n return { ...item, alpcData, insufficient, soldOut, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin) return copy.unlockRewards\n if (item.soldOut) return copy.soldOut\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n return item.insufficient\n }\n return item.soldOut || item.insufficient\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!profile?.activated && !isActivateSuccess) {\n pushView({\n type: MemberPopupPanelType.Activate,\n props: {},\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n window.open(copy.creditsPage.url, '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n pushView({\n type: MemberPopupPanelType.RedeemCoupon,\n props: {\n itemTitle: item.title,\n itemCredits: item.alpcData.consume_credits,\n itemImage: copy.imageMapping?.[item.type]\n ? { url: copy.imageMapping[item.type]!.url, alt: item.image?.alt }\n : item.image,\n itemValue: item.value,\n itemOff: copy.off,\n itemRules: item.rules,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n alpcConfig,\n },\n })\n } else {\n setRedeemAndBuyError('')\n setLoadingId(item.redeemId)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n } catch (e: any) {\n setRedeemAndBuyError(e?.message ?? copy.redeemModal.commonError)\n } finally {\n setLoadingId(null)\n }\n }\n }\n\n return (\n <>\n <div className=\"flex flex-1 flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n {copy.subtitle && <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n {redeemAndBuyError && <div className=\"text-[14px] font-[700] text-[#f84d4f]\">{redeemAndBuyError}</div>}\n\n {listLoading ? (\n <div className=\"flex flex-1 items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n ) : (\n <div className=\"flex flex-col\">\n {list.map((item, idx) => {\n const hasProduct = !!item.product\n return (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute inset-x-0 top-0 h-px bg-[#dadce0]\" />}\n <div className=\"flex items-center gap-[12px]\">\n {(() => {\n const mappedImgUrl = copy.imageMapping?.[item.type]?.url\n const imgUrl = hasProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : (mappedImgUrl ?? item.image?.url)\n const imgAlt = hasProduct\n ? (item.variant?.image?.altText ?? item.product?.images?.[0]?.alt ?? item.image?.alt ?? '')\n : (item.image?.alt ?? '')\n if (!imgUrl) return null\n return (\n <div\n className={cn(\n 'relative size-[64px] shrink-0 overflow-hidden',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n >\n <Picture\n source={imgUrl}\n alt={imgAlt}\n className=\"flex size-full items-center justify-center\"\n imgClassName={hasProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {!hasProduct && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value} {copy.off}\n </div>\n )}\n </div>\n )\n })()}\n <div className=\"min-w-0 flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024] line-clamp-2\">\n {hasProduct && item.product?.title ? item.product.title : item.title}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {hasProduct && item.price != null\n ? `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''} + $${Number(item.price).toFixed(2)}`\n : `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''}`}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n className={cn(\n 'bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && (\n <div className=\"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block\">\n <div className=\"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow\">\n <p className=\"text-pretty tracking-[-0.02em] text-[14px]\">{copy.insufficientCredits}</p>\n <div className=\"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]\" />\n </div>\n </div>\n )}\n </div>\n </div>\n </div>\n )\n })}\n </div>\n )}\n\n {copy.creditsPage?.url && (\n <a\n href={copy.creditsPage.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.creditsPage.label ?? 'Go to Credits Page'}\n </a>\n )}\n </div>\n </>\n )\n}\n\nexport default ConsumeCredits\n"],
|
|
5
|
-
"mappings": "AA2II,mBAAAA,EAGqB,OAAAC,EADjB,QAAAC,MAFJ,oBA3IJ,OAAS,WAAAC,EAAS,YAAAC,MAAgB,QAClC,OAAS,WAAAC,EAAS,UAAAC,MAAc,wBAChC,OAAS,cAAcC,EAAI,wBAAAC,EAAsB,sBA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AAK,SAAS,gBAC3B,UAAWnB,EAAK,eAAemB,EAAK,IAAI,EACpC,CAAE,IAAKnB,EAAK,aAAamB,EAAK,IAAI,EAAG,IAAK,IAAKA,EAAK,OAAO,GAAI,EAC/DA,EAAK,MACT,UAAWA,EAAK,MAChB,QAASnB,EAAK,IACd,UAAWmB,EAAK,MAChB,SAAU,OAAOA,EAAK,QAAQ,EAC9B,OAAQhB,GAAS,QACjB,WAAAG,CACF,CACF,CAAC,MACI,CACLK,EAAqB,EAAE,EACvBE,EAAaM,EAAK,QAAQ,EAC1B,GAAI,CACF,MAAMF,EAAa,CACjB,eAAgBE,EAAK,QACrB,SAAU,OAAOA,EAAK,QAAQ,EAC9B,OAAQhB,GAAS,OACnB,CAAC,CACH,OAAS+B,EAAQ,CACfvB,EAAqBuB,GAAG,SAAWlC,EAAK,YAAY,WAAW,CACjE,QAAE,CACAa,EAAa,IAAI,CACnB,CACF,CACF,CAEA,OACE/B,EAAAD,EAAA,CACE,SAAAE,EAAC,OAAI,UAAU,kCACb,UAAAA,EAAC,OAAI,UAAU,0BACZ,UAAAiB,EAAK,OAASlB,EAAC,MAAG,UAAU,sDAAuD,SAAAkB,EAAK,MAAM,EAC9FA,EAAK,UAAYlB,EAAC,KAAE,UAAU,qDAAsD,SAAAkB,EAAK,SAAS,GACrG,EAECc,GACC/B,EAAC,OACC,UAAWK,EACT,qDACAqB,EAAU,gBAAkB,cAC9B,EAEA,UAAA1B,EAAC,OAAI,UAAU,iCACb,UAAAD,EAAC,OAAI,UAAU,wCAAyC,SAAAkB,EAAK,cAAgB,uBAAuB,EACpGjB,EAAC,OAAI,UAAU,2BACb,UAAAD,EAAC,QAAK,UAAU,sDACb,SAAAe,EAAaO,GAAY,kBAAoB,CAAC,EACjD,EACAtB,EAAC,QAAK,UAAU,sDACb,SAAAkB,EAAK,
|
|
4
|
+
"sourcesContent": ["import { useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { classNames as cn, useProductsByHandles, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useRedeemableList } from './hooks/useRedeemableList'\nimport { useRedeemAndBuy } from './hooks/useRedeemAndBuy'\nimport {\n ConsumeCreditsItemType,\n MemberPopupPanelType,\n type ConsumeCreditsopy,\n type ConsumeCreditsItem,\n} from '../../type'\nimport { numberFormat } from '../../../credits/context/utils'\nimport type { ConsumeCreditRuleResponse } from '../../../credits/context/response'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype EnrichedItem = ConsumeCreditsItem & {\n alpcData: ConsumeCreditRuleResponse\n insufficient: boolean\n soldOut: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n onClose: () => void\n isActivateSuccess: boolean\n}\n\nfunction ConsumeCredits({ copy, isActivateSuccess, onClose }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [redeemAndBuyError, setRedeemAndBuyError] = useState('')\n const [loadingId, setLoadingId] = useState<string | number | null>(null)\n\n const isLogin = !!profile\n const { redeemableList, listLoading } = useRedeemableList(alpcConfig)\n const { trigger: redeemAndBuy } = useRedeemAndBuy(alpcConfig)\n\n const handles = copy.list.map(item => item.product?.handle).filter(Boolean) as string[]\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const alpcData = redeemableList.find(r => String(r.id) === String(item.redeemId))\n if (!alpcData) return null\n\n const availableCredit = Number(creditInfo?.available_credit ?? 0)\n const insufficient = isLogin && !!profile?.activated && alpcData.consume_credits > availableCredit\n const soldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n let product\n let variant\n if (\n (item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product) &&\n item.product\n ) {\n product = products?.find((p: any) => p.handle === item.product!.handle)\n variant = product?.variants?.find((v: any) => v.sku === item.product!.sku) ?? product?.variants?.[0]\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && (!product || !variant)) return null\n }\n\n return { ...item, alpcData, insufficient, soldOut, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin) return copy.unlockRewards\n if (item.soldOut) return copy.soldOut\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n return item.insufficient\n }\n return item.soldOut || item.insufficient\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!profile?.activated && !isActivateSuccess) {\n pushView({\n type: MemberPopupPanelType.Activate,\n props: {},\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n window.open(copy.creditsPage.url, '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n pushView({\n type: MemberPopupPanelType.RedeemCoupon,\n props: {\n itemTitle: item.title,\n itemCredits: item.alpcData.consume_credits,\n itemImage: copy.imageMapping?.[item.type]\n ? { url: copy.imageMapping[item.type]!.url, alt: item.image?.alt }\n : item.image,\n itemValue: item.value,\n itemOff: copy.off,\n itemRules: item.rules,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n alpcConfig,\n },\n })\n } else {\n setRedeemAndBuyError('')\n setLoadingId(item.redeemId)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n } catch (e: any) {\n setRedeemAndBuyError(e?.message ?? copy.redeemModal.commonError)\n } finally {\n setLoadingId(null)\n }\n }\n }\n\n return (\n <>\n <div className=\"flex flex-1 flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n {copy.subtitle && <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n {redeemAndBuyError && <div className=\"text-[14px] font-[700] text-[#f84d4f]\">{redeemAndBuyError}</div>}\n\n {listLoading ? (\n <div className=\"flex flex-1 items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n ) : (\n <div className=\"flex flex-col\">\n {list.map((item, idx) => {\n const hasProduct = !!item.product\n return (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute inset-x-0 top-0 h-px bg-[#dadce0]\" />}\n <div className=\"flex items-center gap-[12px]\">\n {(() => {\n const mappedImgUrl = copy.imageMapping?.[item.type]?.url\n const imgUrl = hasProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : (mappedImgUrl ?? item.image?.url)\n const imgAlt = hasProduct\n ? (item.variant?.image?.altText ?? item.product?.images?.[0]?.alt ?? item.image?.alt ?? '')\n : (item.image?.alt ?? '')\n if (!imgUrl) return null\n return (\n <div\n className={cn(\n 'relative size-[64px] shrink-0 overflow-hidden',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n >\n <Picture\n source={imgUrl}\n alt={imgAlt}\n className=\"flex size-full items-center justify-center\"\n imgClassName={hasProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {!hasProduct && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value} {copy.off}\n </div>\n )}\n </div>\n )\n })()}\n <div className=\"min-w-0 flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024] line-clamp-2\">\n {hasProduct && item.product?.title ? item.product.title : item.title}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {hasProduct && item.price != null\n ? `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''} + $${Number(item.price).toFixed(2)}`\n : `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''}`}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n className={cn(\n 'bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && (\n <div className=\"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block\">\n <div className=\"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow\">\n <p className=\"text-pretty tracking-[-0.02em] text-[14px]\">{copy.insufficientCredits}</p>\n <div className=\"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]\" />\n </div>\n </div>\n )}\n </div>\n </div>\n </div>\n )\n })}\n </div>\n )}\n\n {copy.creditsPage?.url && (\n <a\n href={copy.creditsPage.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.creditsPage.label ?? 'Go to Credits Page'}\n </a>\n )}\n </div>\n </>\n )\n}\n\nexport default ConsumeCredits\n"],
|
|
5
|
+
"mappings": "AA2II,mBAAAA,EAGqB,OAAAC,EADjB,QAAAC,MAFJ,oBA3IJ,OAAS,WAAAC,EAAS,YAAAC,MAAgB,QAClC,OAAS,WAAAC,EAAS,UAAAC,MAAc,wBAChC,OAAS,cAAcC,EAAI,wBAAAC,EAAsB,sBAAAC,MAA0B,gBAC3E,OAAS,yBAAAC,MAA6B,yBACtC,OAAS,gBAAAC,MAAoB,0BAC7B,OAAS,qBAAAC,MAAyB,4BAClC,OAAS,mBAAAC,MAAuB,0BAChC,OACE,0BAAAC,EACA,wBAAAC,MAGK,aACP,OAAS,gBAAAC,MAAoB,iCAE7B,OAAS,kBAAAC,MAAsB,wBAgB/B,SAASC,EAAe,CAAE,KAAAC,EAAM,kBAAAC,EAAmB,QAAAC,CAAQ,EAAU,CACnE,KAAM,CAAE,QAAAC,EAAS,WAAAC,EAAY,gBAAAC,EAAiB,WAAAC,CAAW,EAAIf,EAAsB,EAC7E,CAAE,SAAAgB,CAAS,EAAIf,EAAa,EAC5B,CAAE,MAAAgB,CAAM,EAAIlB,EAAmB,EAC/BmB,EAAUX,EAAe,SAASU,CAAK,EAEvC,CAACE,EAAmBC,CAAoB,EAAI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,QAAS,IAAMc,EAAad,CAAI,EAE/B,SAAAY,EAAeZ,CAAI,EACtB,EACCA,EAAK,cACJrC,EAAC,OAAI,UAAU,qGACb,SAAAC,EAAC,OAAI,UAAU,0EACb,UAAAD,EAAC,KAAE,UAAU,6CAA8C,SAAAkB,EAAK,oBAAoB,EACpFlB,EAAC,OAAI,UAAU,oGAAoG,GACrH,EACF,GAEJ,GACF,IAhEQqD,CAiEV,CAEJ,CAAC,EACH,EAGDnC,EAAK,aAAa,KACjBlB,EAAC,KACC,KAAMkB,EAAK,YAAY,IACvB,OAAO,SACP,IAAI,sBACJ,UAAU,qEAET,SAAAA,EAAK,YAAY,OAAS,qBAC7B,GAEJ,EACF,CAEJ,CAEA,IAAOwC,GAAQzC",
|
|
6
6
|
"names": ["Fragment", "jsx", "jsxs", "useMemo", "useState", "Picture", "Button", "cn", "useProductsByHandles", "useHeadlessContext", "useMemberPopupContext", "useViewStack", "useRedeemableList", "useRedeemAndBuy", "ConsumeCreditsItemType", "MemberPopupPanelType", "numberFormat", "ROUNDED_BRANDS", "ConsumeCredits", "copy", "isActivateSuccess", "onClose", "profile", "creditInfo", "openSignUpPopup", "alpcConfig", "pushView", "brand", "rounded", "redeemAndBuyError", "setRedeemAndBuyError", "loadingId", "setLoadingId", "isLogin", "redeemableList", "listLoading", "redeemAndBuy", "handles", "item", "products", "list", "alpcData", "r", "availableCredit", "insufficient", "soldOut", "product", "variant", "p", "v", "getButtonLabel", "isDisabled", "handleRedeem", "e", "idx", "hasProduct", "mappedImgUrl", "imgUrl", "imgAlt", "ConsumeCredits_default"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { lazy, Suspense, useState, useCallback,
|
|
3
|
+
import { lazy, Suspense, useState, useCallback, useEffect } from 'react'
|
|
4
4
|
import { Picture } from '@anker-in/headless-ui'
|
|
5
5
|
import { type HeadlessConfig, useHeadlessContext, classNames as cn } from '@anker-in/lib'
|
|
6
6
|
import {
|
|
@@ -33,18 +33,25 @@ type MemberPopupProps = MemberPopupContextValue & {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function MemberPopup({ copy, bottomOffset = '24px', ...providerProps }: MemberPopupProps) {
|
|
36
|
-
const isVisible =
|
|
36
|
+
const [isVisible, setIsVisible] = useState(false)
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
37
39
|
const config = copy.pageConfig
|
|
38
|
-
if (!config)
|
|
39
|
-
|
|
40
|
+
if (!config) {
|
|
41
|
+
setIsVisible(true)
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
const pathname = window.location.pathname
|
|
40
45
|
const matches = config.pages.some(page => pathname === page || pathname.startsWith(page + '/'))
|
|
41
46
|
switch (config.scope) {
|
|
42
47
|
case MemberPopupPageScope.Include:
|
|
43
|
-
|
|
48
|
+
setIsVisible(matches)
|
|
49
|
+
break
|
|
44
50
|
case MemberPopupPageScope.Exclude:
|
|
45
|
-
|
|
51
|
+
setIsVisible(!matches)
|
|
52
|
+
break
|
|
46
53
|
default:
|
|
47
|
-
|
|
54
|
+
setIsVisible(true)
|
|
48
55
|
}
|
|
49
56
|
}, [copy.pageConfig])
|
|
50
57
|
|
|
@@ -158,7 +158,7 @@ function ConsumeCredits({ copy, isActivateSuccess, onClose }: Props) {
|
|
|
158
158
|
{numberFormat(creditInfo?.available_credit || 0)}
|
|
159
159
|
</span>
|
|
160
160
|
<span className="text-[14px] font-[700] leading-[1.4] text-[#1e2024]">
|
|
161
|
-
{copy.creditUnit ??
|
|
161
|
+
{copy.creditUnit ?? 'ankercredits'}
|
|
162
162
|
</span>
|
|
163
163
|
</div>
|
|
164
164
|
</div>
|
|
@@ -172,9 +172,6 @@ function ConsumeCredits({ copy, isActivateSuccess, onClose }: Props) {
|
|
|
172
172
|
<span className="text-[14px] font-[700] leading-[1.4] text-[#1e2024]">
|
|
173
173
|
{copy.creditUnit ?? 'ankercredits'}
|
|
174
174
|
</span>
|
|
175
|
-
<span className="text-[14px] font-[700] leading-[1.4] text-[#1e2024]">
|
|
176
|
-
{copy.creditUnit ?? 'ankercredits'}
|
|
177
|
-
</span>
|
|
178
175
|
</div>
|
|
179
176
|
</div>
|
|
180
177
|
</div>
|