@anker-in/campaign-ui 0.5.0-beta.26 → 0.5.0-beta.27
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/panels/ConsumeCredits/index.js +1 -1
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/index.js.map +2 -2
- package/dist/cjs/components/memberPopup/panels/EarnCredits/index.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/index.js.map +2 -2
- package/dist/cjs/components/memberPopup/panels/Referral/index.js +1 -1
- package/dist/cjs/components/memberPopup/panels/Referral/index.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/index.js +1 -1
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/index.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/EarnCredits/index.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/index.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/Referral/index.js +1 -1
- package/dist/esm/components/memberPopup/panels/Referral/index.js.map +2 -2
- package/package.json +1 -1
- package/src/components/memberPopup/panels/ConsumeCredits/index.tsx +1 -1
- package/src/components/memberPopup/panels/EarnCredits/index.tsx +1 -6
- package/src/components/memberPopup/panels/Referral/index.tsx +1 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var y=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var X=(a,n)=>{for(var d in n)y(a,d,{get:n[d],enumerable:!0})},Y=(a,n,d,f)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of K(n))!Q.call(a,o)&&o!==d&&y(a,o,{get:()=>n[o],enumerable:!(f=J(n,o))||f.enumerable});return a};var Z=a=>Y(y({},"__esModule",{value:!0}),a);var ae={};X(ae,{default:()=>te});module.exports=Z(ae);var t=require("react/jsx-runtime"),u=require("react"),N=require("@anker-in/headless-ui"),i=require("@anker-in/lib"),D=require("../../context/provider"),S=require("../../context/viewStack"),L=require("./hooks/useRedeemableList"),E=require("./hooks/useRedeemAndBuy"),r=require("../../type"),m=require("../../../credits/context/utils"),M=require("../../../../constants");function ee({copy:a}){const{profile:n,creditInfo:d,openSignUpPopup:f,alpcConfig:o,isActivateSuccess:U,fetchCreditInfo:$,pageHandle:x}=(0,D.useMemberPopupContext)(),{pushView:P}=(0,S.useViewStack)(),{brand:F}=(0,i.useHeadlessContext)(),w=M.ROUNDED_BRANDS.includes(F),[R,I]=(0,u.useState)(""),[z,k]=(0,u.useState)(null);(0,u.useEffect)(()=>{n?.user_id&&$(n.user_id)},[]);const c=!!n,{redeemableList:B,listLoading:T}=(0,L.useRedeemableList)(o),{trigger:O}=(0,E.useRedeemAndBuy)(o),G=a.list.map(e=>e.product?.handle).filter(Boolean),{data:A}=(0,i.useProductsByHandles)({handles:G}),V=(0,u.useMemo)(()=>a.list.map(e=>{const s=B.find(p=>String(p.id)===String(e.redeemId));if(!s)return null;const l=Number(d?.available_credit??0),g=s.consume_credits>l,h=s.is_limited&&(!s.remaining_inventory||s.remaining_inventory<=0),q=e.type===r.ConsumeCreditsItemType.RedeemAndBuy||e.type===r.ConsumeCreditsItemType.Product,b=A?.find(p=>p.handle===e.product?.handle),C=b?.variants?.find(p=>p.sku===e.product?.sku)??b?.variants?.[0];return q&&(!b||!C||!C?.availableForSale||h)||e.type===r.ConsumeCreditsItemType.RedeemAndBuy&&e.price==null?null:{...e,alpcData:s,insufficient:g,product:b,variant:C}}).filter(Boolean),[a.list,B,d,n,c,A]),v=n?.activated||U;function j(e){return!c||!v?a.unlockRewards:e.soldOut?a.soldOut:a.btnRedeem}function H(e){return!c||!v?!1:e.insufficient}function _(e){(0,i.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"consume_credits",button_name:"redeem",info:"Member Floating Window"}})}async function W(e){if(!c){f();return}if(!v){P({type:r.MemberPopupPanelType.Activate});return}if(e.type===r.ConsumeCreditsItemType.GiftCard||e.type===r.ConsumeCreditsItemType.Product){if(a.creditsPage?.url){const s=a.creditsPage.redeemListSectionId??"creditsRedeemList",l=new URL(a.creditsPage.url,window.location.href);l.searchParams.set("section",s),l.hash=s,x&&l.searchParams.set("ref",`${x}_consume_credits`),_(e.title),window.open(l.toString(),"_blank","noopener,noreferrer")}return}if(e.type===r.ConsumeCreditsItemType.Coupon)_(e.title),P({type:r.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,itemRules:e.rules,redeemId:Number(e.redeemId),userId:n?.user_id,alpcConfig:o}});else{I(""),k(e.redeemId),_(e.title);try{await O({productVariant:e.variant,redeemId:Number(e.redeemId),userId:n?.user_id}),(0,i.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"consume_credits",button_name:"redeem_success",info:"Member Floating Window"}})}catch(s){I(s?.message??a.redeemModal.commonError)}finally{k(null)}}}return(0,t.jsx)(t.Fragment,{children:(0,t.jsxs)("div",{className:"flex flex-1 flex-col",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] mt-[8px] font-[700] leading-snug text-[#4a4c56]",children:a.subtitle})]}),c&&(0,t.jsxs)("div",{className:(0,i.classNames)("flex items-center mt-[16px] gap-[12px] bg-[#f5f6f7] p-[16px]",w?"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)(d?.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)(d?.pending_credit||0)}),(0,t.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??"ankercredits"})]})]})]}),R&&(0,t.jsx)("div",{className:"text-[14px] mt-[8px] font-[700] text-[#f84d4f]",children:R}),T?(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 mt-[16px] flex-col",children:V.map((e,s)=>(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 l=e.type===r.ConsumeCreditsItemType.Product||e.type===r.ConsumeCreditsItemType.RedeemAndBuy,g=l?e.variant?.image?.url??e.product?.images?.[0]?.url??e.image?.url:e.image?.url||a.imageMapping?.[e.type]?.url,h=l?e.variant?.image?.altText??e.product?.images?.[0]?.alt??e.image?.alt??"":e.image?.alt??"";return g?(0,t.jsxs)("div",{className:(0,i.classNames)("relative size-[64px] shrink-0 overflow-hidden",w?"rounded-[4px]":"rounded-none"),children:[(0,t.jsx)(N.Picture,{source:g,alt:h,className:"flex size-full items-center justify-center",imgClassName:l?"object-cover":"h-full w-auto object-contain"}),e.type===r.ConsumeCreditsItemType.Coupon&&e.value&&(0,t.jsx)("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:e.value&&`${e.value} ${a.off}`}),e.type===r.ConsumeCreditsItemType.GiftCard&&e.value&&(0,t.jsx)("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:e.value&&`${e.value} ${a.giftCard||"Gift Card"}`})]}):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:e.product
|
|
1
|
+
"use strict";var y=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var X=(a,n)=>{for(var d in n)y(a,d,{get:n[d],enumerable:!0})},Y=(a,n,d,f)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of K(n))!Q.call(a,o)&&o!==d&&y(a,o,{get:()=>n[o],enumerable:!(f=J(n,o))||f.enumerable});return a};var Z=a=>Y(y({},"__esModule",{value:!0}),a);var ae={};X(ae,{default:()=>te});module.exports=Z(ae);var t=require("react/jsx-runtime"),u=require("react"),N=require("@anker-in/headless-ui"),i=require("@anker-in/lib"),D=require("../../context/provider"),S=require("../../context/viewStack"),L=require("./hooks/useRedeemableList"),E=require("./hooks/useRedeemAndBuy"),r=require("../../type"),m=require("../../../credits/context/utils"),M=require("../../../../constants");function ee({copy:a}){const{profile:n,creditInfo:d,openSignUpPopup:f,alpcConfig:o,isActivateSuccess:U,fetchCreditInfo:$,pageHandle:x}=(0,D.useMemberPopupContext)(),{pushView:P}=(0,S.useViewStack)(),{brand:F}=(0,i.useHeadlessContext)(),w=M.ROUNDED_BRANDS.includes(F),[R,I]=(0,u.useState)(""),[z,k]=(0,u.useState)(null);(0,u.useEffect)(()=>{n?.user_id&&$(n.user_id)},[]);const c=!!n,{redeemableList:B,listLoading:T}=(0,L.useRedeemableList)(o),{trigger:O}=(0,E.useRedeemAndBuy)(o),G=a.list.map(e=>e.product?.handle).filter(Boolean),{data:A}=(0,i.useProductsByHandles)({handles:G}),V=(0,u.useMemo)(()=>a.list.map(e=>{const s=B.find(p=>String(p.id)===String(e.redeemId));if(!s)return null;const l=Number(d?.available_credit??0),g=s.consume_credits>l,h=s.is_limited&&(!s.remaining_inventory||s.remaining_inventory<=0),q=e.type===r.ConsumeCreditsItemType.RedeemAndBuy||e.type===r.ConsumeCreditsItemType.Product,b=A?.find(p=>p.handle===e.product?.handle),C=b?.variants?.find(p=>p.sku===e.product?.sku)??b?.variants?.[0];return q&&(!b||!C||!C?.availableForSale||h)||e.type===r.ConsumeCreditsItemType.RedeemAndBuy&&e.price==null?null:{...e,alpcData:s,insufficient:g,product:b,variant:C}}).filter(Boolean),[a.list,B,d,n,c,A]),v=n?.activated||U;function j(e){return!c||!v?a.unlockRewards:e.soldOut?a.soldOut:a.btnRedeem}function H(e){return!c||!v?!1:e.insufficient}function _(e){(0,i.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"consume_credits",button_name:"redeem",info:"Member Floating Window"}})}async function W(e){if(!c){f();return}if(!v){P({type:r.MemberPopupPanelType.Activate});return}if(e.type===r.ConsumeCreditsItemType.GiftCard||e.type===r.ConsumeCreditsItemType.Product){if(a.creditsPage?.url){const s=a.creditsPage.redeemListSectionId??"creditsRedeemList",l=new URL(a.creditsPage.url,window.location.href);l.searchParams.set("section",s),l.hash=s,x&&l.searchParams.set("ref",`${x}_consume_credits`),_(e.title),window.open(l.toString(),"_blank","noopener,noreferrer")}return}if(e.type===r.ConsumeCreditsItemType.Coupon)_(e.title),P({type:r.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,itemRules:e.rules,redeemId:Number(e.redeemId),userId:n?.user_id,alpcConfig:o}});else{I(""),k(e.redeemId),_(e.title);try{await O({productVariant:e.variant,redeemId:Number(e.redeemId),userId:n?.user_id}),(0,i.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"consume_credits",button_name:"redeem_success",info:"Member Floating Window"}})}catch(s){I(s?.message??a.redeemModal.commonError)}finally{k(null)}}}return(0,t.jsx)(t.Fragment,{children:(0,t.jsxs)("div",{className:"flex flex-1 flex-col",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] mt-[8px] font-[700] leading-snug text-[#4a4c56]",children:a.subtitle})]}),c&&(0,t.jsxs)("div",{className:(0,i.classNames)("flex items-center mt-[16px] gap-[12px] bg-[#f5f6f7] p-[16px]",w?"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)(d?.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)(d?.pending_credit||0)}),(0,t.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??"ankercredits"})]})]})]}),R&&(0,t.jsx)("div",{className:"text-[14px] mt-[8px] font-[700] text-[#f84d4f]",children:R}),T?(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 mt-[16px] flex-col",children:V.map((e,s)=>(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 l=e.type===r.ConsumeCreditsItemType.Product||e.type===r.ConsumeCreditsItemType.RedeemAndBuy,g=l?e.variant?.image?.url??e.product?.images?.[0]?.url??e.image?.url:e.image?.url||a.imageMapping?.[e.type]?.url,h=l?e.variant?.image?.altText??e.product?.images?.[0]?.alt??e.image?.alt??"":e.image?.alt??"";return g?(0,t.jsxs)("div",{className:(0,i.classNames)("relative size-[64px] shrink-0 overflow-hidden",w?"rounded-[4px]":"rounded-none"),children:[(0,t.jsx)(N.Picture,{source:g,alt:h,className:"flex size-full items-center justify-center",imgClassName:l?"object-cover":"h-full w-auto object-contain"}),e.type===r.ConsumeCreditsItemType.Coupon&&e.value&&(0,t.jsx)("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:e.value&&`${e.value} ${a.off}`}),e.type===r.ConsumeCreditsItemType.GiftCard&&e.value&&(0,t.jsx)("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:e.value&&`${e.value} ${a.giftCard||"Gift Card"}`})]}):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:e.product?.title??e.title??e.alpcData?.name}),(0,t.jsx)("div",{className:"mt-[4px] text-[14px] text-[#666]",children:e.type===r.ConsumeCreditsItemType.RedeemAndBuy?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{children:[(0,m.numberFormat)(e.alpcData.consume_credits)," ",a.creditUnit??""," + $",Number(e.price).toFixed(2)]}),e.variant?.price?.amount&&(0,t.jsxs)("div",{className:"text-[12px] ml-1 text-[#999] line-through",children:["$",Number(e.variant.price.amount).toFixed(2)]})]}):`${(0,m.numberFormat)(e.alpcData.consume_credits)} ${a.creditUnit??""}`})]}),(0,t.jsxs)("div",{className:"relative group",children:[(0,t.jsx)(N.Button,{size:"base",disabled:H(e),loading:z===e.redeemId,onClick:()=>W(e),children:j(e)}),e.insufficient&&c&&v&&(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:(()=>{if(!x)return a.creditsPage.url;try{const e=new URL(a.creditsPage.url,window.location.href);return e.searchParams.set("ref",`${x}_consume_credits`),e.toString()}catch{return a.creditsPage.url}})(),target:"_blank",rel:"noopener noreferrer",className:"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline",onClick:()=>(0,i.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"consume_credits",button_name:"credits_page_link",info:"Member Floating Window"}}),children:a.creditsPage.label??"Go to Credits Page"})]})})}var te=ee;
|
|
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 { useEffect, useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { gaTrack, 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 disabled: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n}\n\nfunction ConsumeCredits({ copy }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig, isActivateSuccess, fetchCreditInfo, pageHandle } =\n 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 useEffect(() => {\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n }, [])\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 = alpcData.consume_credits > availableCredit\n const alpcSoldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n const isPhysicalProduct =\n item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product\n const product = products?.find((p: any) => p.handle === item.product?.handle)\n const variant = product?.variants?.find((v: any) => v.sku === item.product?.sku) ?? product?.variants?.[0]\n if (isPhysicalProduct && (!product || !variant || !variant?.availableForSale || alpcSoldOut)) {\n return null\n }\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && item.price == null) {\n return null\n }\n return { ...item, alpcData, insufficient, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n const isActivate = profile?.activated || isActivateSuccess\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin || !isActivate) {\n return copy.unlockRewards\n }\n if (item.soldOut) {\n return copy.soldOut\n }\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (!isLogin || !isActivate) {\n return false\n }\n return item.insufficient\n }\n\n function trackRedeemButton(itemTitle: string) {\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'redeem',\n info: 'Member Floating Window',\n },\n })\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!isActivate) {\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n const sectionId = copy.creditsPage.redeemListSectionId ?? 'creditsRedeemList'\n const targetUrl = new URL(copy.creditsPage.url, window.location.href)\n targetUrl.searchParams.set('section', sectionId)\n targetUrl.hash = sectionId\n if (pageHandle) {\n targetUrl.searchParams.set('ref', `${pageHandle}_consume_credits`)\n }\n trackRedeemButton(item.title)\n window.open(targetUrl.toString(), '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n trackRedeemButton(item.title)\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 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 trackRedeemButton(item.title)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'redeem_success',\n info: 'Member Floating Window',\n },\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\">\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 && (\n <p className=\"text-[16px] mt-[8px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center mt-[16px] 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] mt-[8px] 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 mt-[16px] flex-col\">\n {list.map((item, idx) => {\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 phsicalProduct =\n item.type === ConsumeCreditsItemType.Product ||\n item.type === ConsumeCreditsItemType.RedeemAndBuy\n const imgUrl = phsicalProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : item.image?.url || copy.imageMapping?.[item.type]?.url\n const imgAlt = phsicalProduct\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={phsicalProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {item.type === ConsumeCreditsItemType.Coupon && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value && `${item.value} ${copy.off}`}\n </div>\n )}\n {item.type === ConsumeCreditsItemType.GiftCard && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value && `${item.value} ${copy.giftCard || 'Gift Card'}`}\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 {item.product.title ?? item.title ?? item.alpcData?.name}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {item.type === ConsumeCreditsItemType.RedeemAndBuy ? (\n <>\n <div>\n {numberFormat(item.alpcData.consume_credits)} {copy.creditUnit ?? ''} + $\n {Number(item.price).toFixed(2)}\n </div>\n {item.variant?.price?.amount && (\n <div className=\"text-[12px] ml-1 text-[#999] line-through\">\n ${Number(item.variant.price.amount).toFixed(2)}\n </div>\n )}\n </>\n ) : (\n `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''}`\n )}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n size=\"base\"\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && isLogin && isActivate && (\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={(() => {\n if (!pageHandle) return copy.creditsPage!.url\n try {\n const url = new URL(copy.creditsPage!.url, window.location.href)\n url.searchParams.set('ref', `${pageHandle}_consume_credits`)\n return url.toString()\n } catch {\n return copy.creditsPage!.url\n }\n })()}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={() =>\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'credits_page_link',\n info: 'Member Floating Window',\n },\n })\n }\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,GAAA,GAAAC,EAAAD,GAAA,aAAAE,KAAA,eAAAC,EAAAH,IAmLQ,IAAAI,EAAA,6BAnLRC,EAA6C,iBAC7CC,EAAgC,iCAChCC,EAAoF,yBACpFC,EAAsC,kCACtCC,EAA6B,mCAC7BC,EAAkC,qCAClCC,EAAgC,mCAChCC,EAKO,sBACPC,EAA6B,0CAE7BC,EAA+B,iCAe/B,SAASC,GAAe,CAAE,KAAAC,CAAK,EAAU,CACvC,KAAM,CAAE,QAAAC,EAAS,WAAAC,EAAY,gBAAAC,EAAiB,WAAAC,EAAY,kBAAAC,EAAmB,gBAAAC,EAAiB,WAAAC,CAAW,KACvG,yBAAsB,EAClB,CAAE,SAAAC,CAAS,KAAI,gBAAa,EAC5B,CAAE,MAAAC,CAAM,KAAI,sBAAmB,EAC/BC,EAAU,iBAAe,SAASD,CAAK,EAEvC,CAACE,EAAmBC,CAAoB,KAAI,YAAS,EAAE,EACvD,CAACC,EAAWC,CAAY,KAAI,YAAiC,IAAI,KAEvE,aAAU,IAAM,CACVb,GAAS,SAASK,EAAgBL,EAAQ,OAAO,CACvD,EAAG,CAAC,CAAC,EAEL,MAAMc,EAAU,CAAC,CAACd,EACZ,CAAE,eAAAe,EAAgB,YAAAC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anker-in/headless-ui'\nimport { gaTrack, 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 disabled: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n}\n\nfunction ConsumeCredits({ copy }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig, isActivateSuccess, fetchCreditInfo, pageHandle } =\n 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 useEffect(() => {\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n }, [])\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 = alpcData.consume_credits > availableCredit\n const alpcSoldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n const isPhysicalProduct =\n item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product\n const product = products?.find((p: any) => p.handle === item.product?.handle)\n const variant = product?.variants?.find((v: any) => v.sku === item.product?.sku) ?? product?.variants?.[0]\n if (isPhysicalProduct && (!product || !variant || !variant?.availableForSale || alpcSoldOut)) {\n return null\n }\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && item.price == null) {\n return null\n }\n return { ...item, alpcData, insufficient, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n const isActivate = profile?.activated || isActivateSuccess\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin || !isActivate) {\n return copy.unlockRewards\n }\n if (item.soldOut) {\n return copy.soldOut\n }\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (!isLogin || !isActivate) {\n return false\n }\n return item.insufficient\n }\n\n function trackRedeemButton(itemTitle: string) {\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'redeem',\n info: 'Member Floating Window',\n },\n })\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!isActivate) {\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n const sectionId = copy.creditsPage.redeemListSectionId ?? 'creditsRedeemList'\n const targetUrl = new URL(copy.creditsPage.url, window.location.href)\n targetUrl.searchParams.set('section', sectionId)\n targetUrl.hash = sectionId\n if (pageHandle) {\n targetUrl.searchParams.set('ref', `${pageHandle}_consume_credits`)\n }\n trackRedeemButton(item.title)\n window.open(targetUrl.toString(), '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n trackRedeemButton(item.title)\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 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 trackRedeemButton(item.title)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'redeem_success',\n info: 'Member Floating Window',\n },\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\">\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 && (\n <p className=\"text-[16px] mt-[8px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center mt-[16px] 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] mt-[8px] 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 mt-[16px] flex-col\">\n {list.map((item, idx) => {\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 phsicalProduct =\n item.type === ConsumeCreditsItemType.Product ||\n item.type === ConsumeCreditsItemType.RedeemAndBuy\n const imgUrl = phsicalProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : item.image?.url || copy.imageMapping?.[item.type]?.url\n const imgAlt = phsicalProduct\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={phsicalProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {item.type === ConsumeCreditsItemType.Coupon && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value && `${item.value} ${copy.off}`}\n </div>\n )}\n {item.type === ConsumeCreditsItemType.GiftCard && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value && `${item.value} ${copy.giftCard || 'Gift Card'}`}\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 {item.product?.title ?? item.title ?? item.alpcData?.name}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {item.type === ConsumeCreditsItemType.RedeemAndBuy ? (\n <>\n <div>\n {numberFormat(item.alpcData.consume_credits)} {copy.creditUnit ?? ''} + $\n {Number(item.price).toFixed(2)}\n </div>\n {item.variant?.price?.amount && (\n <div className=\"text-[12px] ml-1 text-[#999] line-through\">\n ${Number(item.variant.price.amount).toFixed(2)}\n </div>\n )}\n </>\n ) : (\n `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''}`\n )}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n size=\"base\"\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && isLogin && isActivate && (\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={(() => {\n if (!pageHandle) return copy.creditsPage!.url\n try {\n const url = new URL(copy.creditsPage!.url, window.location.href)\n url.searchParams.set('ref', `${pageHandle}_consume_credits`)\n return url.toString()\n } catch {\n return copy.creditsPage!.url\n }\n })()}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={() =>\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'credits_page_link',\n info: 'Member Floating Window',\n },\n })\n }\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,GAAA,GAAAC,EAAAD,GAAA,aAAAE,KAAA,eAAAC,EAAAH,IAmLQ,IAAAI,EAAA,6BAnLRC,EAA6C,iBAC7CC,EAAgC,iCAChCC,EAAoF,yBACpFC,EAAsC,kCACtCC,EAA6B,mCAC7BC,EAAkC,qCAClCC,EAAgC,mCAChCC,EAKO,sBACPC,EAA6B,0CAE7BC,EAA+B,iCAe/B,SAASC,GAAe,CAAE,KAAAC,CAAK,EAAU,CACvC,KAAM,CAAE,QAAAC,EAAS,WAAAC,EAAY,gBAAAC,EAAiB,WAAAC,EAAY,kBAAAC,EAAmB,gBAAAC,EAAiB,WAAAC,CAAW,KACvG,yBAAsB,EAClB,CAAE,SAAAC,CAAS,KAAI,gBAAa,EAC5B,CAAE,MAAAC,CAAM,KAAI,sBAAmB,EAC/BC,EAAU,iBAAe,SAASD,CAAK,EAEvC,CAACE,EAAmBC,CAAoB,KAAI,YAAS,EAAE,EACvD,CAACC,EAAWC,CAAY,KAAI,YAAiC,IAAI,KAEvE,aAAU,IAAM,CACVb,GAAS,SAASK,EAAgBL,EAAQ,OAAO,CACvD,EAAG,CAAC,CAAC,EAEL,MAAMc,EAAU,CAAC,CAACd,EACZ,CAAE,eAAAe,EAAgB,YAAAC,CAAY,KAAI,qBAAkBb,CAAU,EAC9D,CAAE,QAASc,CA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CAEJ,CAEA,IAAOd,GAAQa",
|
|
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", "profile", "creditInfo", "openSignUpPopup", "alpcConfig", "isActivateSuccess", "fetchCreditInfo", "pageHandle", "pushView", "brand", "rounded", "redeemAndBuyError", "setRedeemAndBuyError", "loadingId", "setLoadingId", "isLogin", "redeemableList", "listLoading", "redeemAndBuy", "handles", "item", "products", "list", "alpcData", "r", "availableCredit", "insufficient", "alpcSoldOut", "isPhysicalProduct", "product", "variant", "v", "isActivate", "getButtonLabel", "isDisabled", "trackRedeemButton", "itemTitle", "handleRedeem", "sectionId", "targetUrl", "e", "cn", "idx", "phsicalProduct", "imgUrl", "imgAlt", "url"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var b=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var D=(
|
|
1
|
+
"use strict";var b=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var D=(i,t)=>{for(var n in t)b(i,n,{get:t[n],enumerable:!0})},F=(i,t,n,f)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of R(t))!y.call(i,r)&&r!==n&&b(i,r,{get:()=>t[r],enumerable:!(f=M(t,r))||f.enumerable});return i};var O=i=>F(b({},"__esModule",{value:!0}),i);var j={};D(j,{default:()=>W});module.exports=O(j);var e=require("react/jsx-runtime"),p=require("react"),d=require("@anker-in/lib"),_=require("../../context/provider"),E=require("../../context/viewStack"),P=require("./hooks/useSubscribed"),s=require("../../type"),c=require("../../icons"),v=require("../../../credits/context/utils"),L=require("../../../../constants"),g=require("@anker-in/headless-ui");function V({id:i,className:t}){switch(i){case s.EarnCreditsTaskType.Activate:return(0,e.jsx)(c.IconLock,{className:t});case s.EarnCreditsTaskType.Subscribe:return(0,e.jsx)(c.IconSubscription,{className:t});case s.EarnCreditsTaskType.Shop:return(0,e.jsx)(c.IconBag,{className:t});case s.EarnCreditsTaskType.CompleteProfile:return(0,e.jsx)(c.IconOrders,{className:t})}}function z({copy:i}){const{profile:t,openSignUpPopup:n,alpcConfig:f,creditInfo:r,fetchCreditInfo:B,isSubscribeSuccess:C,isActivateSuccess:k,isProfileCompleteSuccess:x}=(0,_.useMemberPopupContext)(),{pushView:u}=(0,E.useViewStack)(),{locale:A}=f,{brand:N}=(0,d.useHeadlessContext)(),w=L.ROUNDED_BRANDS.includes(N);(0,p.useEffect)(()=>{t?.user_id&&B(t.user_id)},[]);const o=!!t,h=(0,P.useSubscribed)({userId:t?.user_id,brand:N,email:t?.email,locale:A,apiBaseUrl:f.apiBaseUrl}),S=(0,p.useMemo)(()=>x||!!(t?.first_name||t?.last_name)&&!!t?.phone_number&&!!t?.dob,[t,x]);function m(a){const l={[s.EarnCreditsTaskType.Activate]:"activate",[s.EarnCreditsTaskType.CompleteProfile]:"complete_profile",[s.EarnCreditsTaskType.Subscribe]:"subscribe",[s.EarnCreditsTaskType.Shop]:"shop"};(0,d.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"earn_credits",button_name:l[a],info:"Member Floating Window"}})}const T=(0,p.useMemo)(()=>({[s.EarnCreditsTaskType.Activate]:{finished:!!t?.activated||k,onClick:o?()=>{m(s.EarnCreditsTaskType.Activate),u({type:s.MemberPopupPanelType.Activate})}:n},[s.EarnCreditsTaskType.CompleteProfile]:{finished:S,onClick:o?()=>{m(s.EarnCreditsTaskType.CompleteProfile),u({type:s.MemberPopupPanelType.CompleteProfile})}:n},[s.EarnCreditsTaskType.Subscribe]:{finished:h||C,onClick:o?()=>{m(s.EarnCreditsTaskType.Subscribe),u({type:s.MemberPopupPanelType.SubscribeEmail})}:n},[s.EarnCreditsTaskType.Shop]:{finished:!1,link:i.goShopLink,onClick:o?()=>m(s.EarnCreditsTaskType.Shop):n}}),[t,o,k,x,S,h,C,n,u,i.goShopLink]),I=(0,p.useMemo)(()=>i.list.map(a=>{const l=T[a.id];if(!l)return null;const U=l.finished?i.completed:o?H(a.id,i):i.joinNow;return{...a,...l,buttonLabel:U}}).filter(Boolean),[i,T,o]);return(0,e.jsxs)("div",{className:"flex flex-col gap-[16px]",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-[16px]",children:[(0,e.jsx)("div",{className:"flex flex-col gap-[8px]",children:i.title&&(0,e.jsx)("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:i.title})}),o&&(0,e.jsxs)("div",{className:(0,d.classNames)("flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]",w?"rounded-[8px]":"rounded-none"),children:[(0,e.jsxs)("div",{className:"flex flex-1 flex-col gap-[4px]",children:[(0,e.jsx)("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:i.balanceLabel??"AnkerCredits Balance"}),(0,e.jsxs)("div",{className:"flex items-end gap-[4px]",children:[(0,e.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,v.numberFormat)(r?.available_credit??0)}),(0,e.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:i.creditUnit??"ankercredits"})]})]}),(0,e.jsx)("div",{className:"h-full w-px bg-[#dadce0]"}),(0,e.jsxs)("div",{className:"flex flex-1 flex-col gap-[4px]",children:[(0,e.jsx)("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:i.comingSoonLabel??"Coming Soon"}),(0,e.jsxs)("div",{className:"flex items-end gap-[4px]",children:[(0,e.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,v.numberFormat)(r?.pending_credit??0)}),(0,e.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:i.creditUnit??"ankercredits"})]})]})]})]}),(0,e.jsxs)("div",{className:"flex flex-col gap-[16px]",children:[i.subtitle&&(0,e.jsx)("p",{className:"text-[16px] font-[700] text-[#1e2024]",children:i.subtitle}),(0,e.jsx)("div",{className:"flex flex-col",children:I.map((a,l)=>(0,e.jsxs)("div",{className:"relative py-[16px]",children:[l>0&&(0,e.jsx)("div",{className:"absolute left-0 right-0 top-0 h-px bg-[#dadce0]"}),(0,e.jsxs)("div",{className:(0,d.classNames)("flex items-center gap-[12px]"),children:[(0,e.jsx)(V,{id:a.id,className:"size-[24px] shrink-0"}),(0,e.jsxs)("div",{className:"flex-1",children:[(0,e.jsx)("div",{className:"text-[16px] font-[700] text-[#1e2024]",children:a.title}),a.credits&&(0,e.jsx)("div",{className:"mt-[4px] text-[14px] font-bold text-[#4A4C56]",children:a.credits})]}),!a.finished&&a.link&&o?(0,e.jsx)(g.Button,{as:"a",href:a.link,target:"_blank",rel:"noopener noreferrer",onClick:()=>m(a.id),children:a.buttonLabel}):(0,e.jsx)(g.Button,{disabled:a.finished,onClick:a.finished?void 0:a.onClick,children:a.buttonLabel})]})]},l))})]})]})}function H(i,t){switch(i){case s.EarnCreditsTaskType.Activate:return t.activate;case s.EarnCreditsTaskType.CompleteProfile:return t.completeProfileLabel;case s.EarnCreditsTaskType.Subscribe:return t.subscribeLabel;case s.EarnCreditsTaskType.Shop:return t.shopNow}}var W=z;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/EarnCredits/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useEffect, useMemo } from 'react'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useSubscribed } from './hooks/useSubscribed'\nimport { EarnCreditsTaskType, MemberPopupPanelType, type EarnCreditsCopy } from '../../type'\nimport { IconBag, IconLock, IconSubscription, IconOrders } from '../../icons'\nimport { numberFormat } from '../../../credits/context/utils'\nimport { ROUNDED_BRANDS } from '../../../../constants'\nimport { Button } from '@anker-in/headless-ui'\n\nfunction TaskIcon({ id, className }: { id: EarnCreditsTaskType; className?: string }) {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return <IconLock className={className} />\n case EarnCreditsTaskType.Subscribe:\n return <IconSubscription className={className} />\n case EarnCreditsTaskType.Shop:\n return <IconBag className={className} />\n case EarnCreditsTaskType.CompleteProfile:\n return <IconOrders className={className} />\n }\n}\n\ntype Props = {\n copy: EarnCreditsCopy\n}\n\nfunction EarnCredits({ copy }: Props) {\n const {\n profile,\n openSignUpPopup,\n alpcConfig,\n creditInfo,\n fetchCreditInfo,\n isSubscribeSuccess,\n isActivateSuccess,\n isProfileCompleteSuccess,\n } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { locale } = alpcConfig\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n useEffect(() => {\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n }, [])\n\n const isLogin = !!profile\n\n const isSubscribed = useSubscribed({\n userId: profile?.user_id,\n brand: brand,\n email: profile?.email,\n locale,\n apiBaseUrl: alpcConfig.apiBaseUrl,\n })\n\n const profileCompleted = useMemo(() => {\n return (\n isProfileCompleteSuccess ||\n (!!(profile?.first_name || profile?.last_name) && !!profile?.phone_number && !!profile?.dob)\n )\n }, [profile, isProfileCompleteSuccess])\n\n function trackTaskButton(taskId: EarnCreditsTaskType) {\n const taskButtonNameMap: Record<EarnCreditsTaskType, string> = {\n [EarnCreditsTaskType.Activate]: 'activate',\n [EarnCreditsTaskType.CompleteProfile]: 'complete_profile',\n [EarnCreditsTaskType.Subscribe]: 'subscribe',\n [EarnCreditsTaskType.Shop]: 'shop',\n }\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'earn_credits',\n button_name: taskButtonNameMap[taskId],\n info: 'Member Floating Window',\n },\n })\n }\n\n const taskStates: Record<EarnCreditsTaskType, { finished: boolean; onClick?: () => void; link?: string }> = useMemo(\n () => ({\n [EarnCreditsTaskType.Activate]: {\n finished: !!profile?.activated || isActivateSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Activate)\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.CompleteProfile]: {\n finished: profileCompleted,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.CompleteProfile)\n pushView({\n type: MemberPopupPanelType.CompleteProfile,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Subscribe]: {\n finished: isSubscribed || isSubscribeSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Subscribe)\n pushView({\n type: MemberPopupPanelType.SubscribeEmail,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Shop]: {\n finished: false,\n link: copy.goShopLink,\n onClick: isLogin ? () => trackTaskButton(EarnCreditsTaskType.Shop) : openSignUpPopup,\n },\n }),\n [\n profile,\n isLogin,\n isActivateSuccess,\n isProfileCompleteSuccess,\n profileCompleted,\n isSubscribed,\n isSubscribeSuccess,\n openSignUpPopup,\n pushView,\n copy.goShopLink,\n ]\n )\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const state = taskStates[item.id]\n if (!state) return null\n const buttonLabel = state.finished\n ? copy.completed\n : isLogin\n ? getNotFinishedLabel(item.id, copy)\n : copy.joinNow\n return { ...item, ...state, buttonLabel }\n })\n .filter(Boolean) as ((typeof copy.list)[number] & {\n finished: boolean\n onClick?: () => void\n link?: string\n buttonLabel: string\n })[]\n }, [copy, taskStates, isLogin])\n\n return (\n <div className=\"flex flex-col gap-[16px]\">\n <div className=\"flex flex-col gap-[16px]\">\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 </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 </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {copy.subtitle && <p className=\"text-[16px] font-[700] text-[#1e2024]\">{copy.subtitle}</p>}\n\n <div className=\"flex flex-col\">\n {list.map((item, idx) => (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute left-0 right-0 top-0 h-px bg-[#dadce0]\" />}\n <div className={cn('flex items-center gap-[12px]')}>\n <TaskIcon id={item.id} className=\"size-[24px] shrink-0\" />\n <div className=\"flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024]\">{item.title}</div>\n {item.credits && <div className=\"mt-[4px] text-[14px] font-bold text-[#4A4C56]\">{item.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C,OAAc,UAAU,qBACtB,UAAAA,EAAM,MAAK,OAAC,OAAI,UAAU,kDAAkD,KAC7E,QAAC,OAAI,aAAW,EAAAD,YAAG,8BAA8B,EAC/C,oBAAC7B,EAAA,CAAS,GAAIyB,EAAK,GAAI,UAAU,uBAAuB,KACxD,QAAC,OAAI,UAAU,SACb,oBAAC,OAAI,UAAU,wCAAyC,SAAAA,EAAK,MAAM,EAClEA,EAAK,YAAW,OAAC,OAAI,UAAU,gDAAiD,SAAAA,EAAK,QAAQ,GAChG,EACC,CAACA,EAAK,UAAYA,EAAK,MAAQR,KAC9B,OAAC,UACC,GAAG,IACH,
|
|
4
|
+
"sourcesContent": ["import { useEffect, useMemo } from 'react'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useSubscribed } from './hooks/useSubscribed'\nimport { EarnCreditsTaskType, MemberPopupPanelType, type EarnCreditsCopy } from '../../type'\nimport { IconBag, IconLock, IconSubscription, IconOrders } from '../../icons'\nimport { numberFormat } from '../../../credits/context/utils'\nimport { ROUNDED_BRANDS } from '../../../../constants'\nimport { Button } from '@anker-in/headless-ui'\n\nfunction TaskIcon({ id, className }: { id: EarnCreditsTaskType; className?: string }) {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return <IconLock className={className} />\n case EarnCreditsTaskType.Subscribe:\n return <IconSubscription className={className} />\n case EarnCreditsTaskType.Shop:\n return <IconBag className={className} />\n case EarnCreditsTaskType.CompleteProfile:\n return <IconOrders className={className} />\n }\n}\n\ntype Props = {\n copy: EarnCreditsCopy\n}\n\nfunction EarnCredits({ copy }: Props) {\n const {\n profile,\n openSignUpPopup,\n alpcConfig,\n creditInfo,\n fetchCreditInfo,\n isSubscribeSuccess,\n isActivateSuccess,\n isProfileCompleteSuccess,\n } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { locale } = alpcConfig\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n useEffect(() => {\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n }, [])\n\n const isLogin = !!profile\n\n const isSubscribed = useSubscribed({\n userId: profile?.user_id,\n brand: brand,\n email: profile?.email,\n locale,\n apiBaseUrl: alpcConfig.apiBaseUrl,\n })\n\n const profileCompleted = useMemo(() => {\n return (\n isProfileCompleteSuccess ||\n (!!(profile?.first_name || profile?.last_name) && !!profile?.phone_number && !!profile?.dob)\n )\n }, [profile, isProfileCompleteSuccess])\n\n function trackTaskButton(taskId: EarnCreditsTaskType) {\n const taskButtonNameMap: Record<EarnCreditsTaskType, string> = {\n [EarnCreditsTaskType.Activate]: 'activate',\n [EarnCreditsTaskType.CompleteProfile]: 'complete_profile',\n [EarnCreditsTaskType.Subscribe]: 'subscribe',\n [EarnCreditsTaskType.Shop]: 'shop',\n }\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'earn_credits',\n button_name: taskButtonNameMap[taskId],\n info: 'Member Floating Window',\n },\n })\n }\n\n const taskStates: Record<EarnCreditsTaskType, { finished: boolean; onClick?: () => void; link?: string }> = useMemo(\n () => ({\n [EarnCreditsTaskType.Activate]: {\n finished: !!profile?.activated || isActivateSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Activate)\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.CompleteProfile]: {\n finished: profileCompleted,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.CompleteProfile)\n pushView({\n type: MemberPopupPanelType.CompleteProfile,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Subscribe]: {\n finished: isSubscribed || isSubscribeSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Subscribe)\n pushView({\n type: MemberPopupPanelType.SubscribeEmail,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Shop]: {\n finished: false,\n link: copy.goShopLink,\n onClick: isLogin ? () => trackTaskButton(EarnCreditsTaskType.Shop) : openSignUpPopup,\n },\n }),\n [\n profile,\n isLogin,\n isActivateSuccess,\n isProfileCompleteSuccess,\n profileCompleted,\n isSubscribed,\n isSubscribeSuccess,\n openSignUpPopup,\n pushView,\n copy.goShopLink,\n ]\n )\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const state = taskStates[item.id]\n if (!state) return null\n const buttonLabel = state.finished\n ? copy.completed\n : isLogin\n ? getNotFinishedLabel(item.id, copy)\n : copy.joinNow\n return { ...item, ...state, buttonLabel }\n })\n .filter(Boolean) as ((typeof copy.list)[number] & {\n finished: boolean\n onClick?: () => void\n link?: string\n buttonLabel: string\n })[]\n }, [copy, taskStates, isLogin])\n\n return (\n <div className=\"flex flex-col gap-[16px]\">\n <div className=\"flex flex-col gap-[16px]\">\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 </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 </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {copy.subtitle && <p className=\"text-[16px] font-[700] text-[#1e2024]\">{copy.subtitle}</p>}\n\n <div className=\"flex flex-col\">\n {list.map((item, idx) => (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute left-0 right-0 top-0 h-px bg-[#dadce0]\" />}\n <div className={cn('flex items-center gap-[12px]')}>\n <TaskIcon id={item.id} className=\"size-[24px] shrink-0\" />\n <div className=\"flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024]\">{item.title}</div>\n {item.credits && <div className=\"mt-[4px] text-[14px] font-bold text-[#4A4C56]\">{item.credits}</div>}\n </div>\n {!item.finished && item.link && isLogin ? (\n <Button\n as=\"a\"\n href={item.link}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n onClick={() => trackTaskButton(item.id)}\n >\n {item.buttonLabel}\n </Button>\n ) : (\n <Button disabled={item.finished} onClick={!item.finished ? item.onClick : undefined}>\n {item.buttonLabel}\n </Button>\n )}\n </div>\n </div>\n ))}\n </div>\n </div>\n </div>\n )\n}\n\nfunction getNotFinishedLabel(id: EarnCreditsTaskType, copy: EarnCreditsCopy): string {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return copy.activate\n case EarnCreditsTaskType.CompleteProfile:\n return copy.completeProfileLabel\n case EarnCreditsTaskType.Subscribe:\n return copy.subscribeLabel\n case EarnCreditsTaskType.Shop:\n return copy.shopNow\n }\n}\n\nexport default EarnCredits\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAca,IAAAI,EAA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,UAAU,uBAAuB,KACxD,QAAC,OAAI,UAAU,SACb,oBAAC,OAAI,UAAU,wCAAyC,SAAAA,EAAK,MAAM,EAClEA,EAAK,YAAW,OAAC,OAAI,UAAU,gDAAiD,SAAAA,EAAK,QAAQ,GAChG,EACC,CAACA,EAAK,UAAYA,EAAK,MAAQR,KAC9B,OAAC,UACC,GAAG,IACH,KAAMQ,EAAK,KACX,OAAO,SACP,IAAI,sBACJ,QAAS,IAAML,EAAgBK,EAAK,EAAE,EAErC,SAAAA,EAAK,YACR,KAEA,OAAC,UAAO,SAAUA,EAAK,SAAU,QAAUA,EAAK,SAA0B,OAAfA,EAAK,QAC7D,SAAAA,EAAK,YACR,GAEJ,IAvBQK,CAwBV,CACD,EACH,GACF,GACF,CAEJ,CAEA,SAASF,EAAoB3B,EAAyBG,EAA+B,CACnF,OAAQH,EAAI,CACV,KAAK,sBAAoB,SACvB,OAAOG,EAAK,SACd,KAAK,sBAAoB,gBACvB,OAAOA,EAAK,qBACd,KAAK,sBAAoB,UACvB,OAAOA,EAAK,eACd,KAAK,sBAAoB,KACvB,OAAOA,EAAK,OAChB,CACF,CAEA,IAAOjB,EAAQgB",
|
|
6
6
|
"names": ["EarnCredits_exports", "__export", "EarnCredits_default", "__toCommonJS", "import_jsx_runtime", "import_react", "import_lib", "import_provider", "import_viewStack", "import_useSubscribed", "import_type", "import_icons", "import_utils", "import_constants", "import_headless_ui", "TaskIcon", "id", "className", "EarnCredits", "copy", "profile", "openSignUpPopup", "alpcConfig", "creditInfo", "fetchCreditInfo", "isSubscribeSuccess", "isActivateSuccess", "isProfileCompleteSuccess", "pushView", "locale", "brand", "rounded", "isLogin", "isSubscribed", "profileCompleted", "trackTaskButton", "taskId", "taskButtonNameMap", "taskStates", "list", "item", "state", "buttonLabel", "getNotFinishedLabel", "cn", "idx"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var P=(e,a)=>{for(var n in a)f(e,n,{get:a[n],enumerable:!0})},U=(e,a,n,o)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of R(a))!_.call(e,l)&&l!==n&&f(e,l,{get:()=>a[l],enumerable:!(o=T(a,l))||o.enumerable});return e};var D=e=>U(f({},"__esModule",{value:!0}),e);var k={};P(k,{default:()=>B});module.exports=D(k);var t=require("react/jsx-runtime"),s=require("@anker-in/headless-ui"),r=require("@anker-in/lib"),u=require("../../context/provider"),v=require("./hooks/useReferralOverview"),d=require("../../../credits/context/utils"),h=require("../../../../constants");function M({copy:e,onClose:a}){const{profile:n,alpcConfig:o,pageHandle:l}=(0,u.useMemberPopupContext)(),b=!!n,{brand:N,currencyCode:x="USD"}=(0,r.useHeadlessContext)(),
|
|
1
|
+
"use strict";var f=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var P=(e,a)=>{for(var n in a)f(e,n,{get:a[n],enumerable:!0})},U=(e,a,n,o)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of R(a))!_.call(e,l)&&l!==n&&f(e,l,{get:()=>a[l],enumerable:!(o=T(a,l))||o.enumerable});return e};var D=e=>U(f({},"__esModule",{value:!0}),e);var k={};P(k,{default:()=>B});module.exports=D(k);var t=require("react/jsx-runtime"),s=require("@anker-in/headless-ui"),r=require("@anker-in/lib"),u=require("../../context/provider"),v=require("./hooks/useReferralOverview"),d=require("../../../credits/context/utils"),h=require("../../../../constants");function M({copy:e,onClose:a}){const{profile:n,alpcConfig:o,pageHandle:l}=(0,u.useMemberPopupContext)(),b=!!n,{brand:N,currencyCode:x="USD"}=(0,r.useHeadlessContext)(),m=h.ROUNDED_BRANDS.includes(N),{data:c}=(0,v.useReferralOverview)(),w=c?.data?.data?.available??0,C=c?.data?.data?.pending??0;function p(i){try{if(!l)return i;const g=new URL(i,window.location.href);return g.searchParams.set("ref",`${l}_referral`),g.toString()}catch{return i}}function L(){(0,r.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"referral",button_name:"referral_cta",info:"Member Floating Window"}})}return(0,t.jsxs)("div",{className:"flex flex-col",children:[e.title&&(0,t.jsx)("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:e.title}),b&&(0,t.jsxs)("div",{className:(0,r.classNames)("flex items-center mt-[16px] gap-[12px] bg-[#f5f6f7] p-[16px]",m?"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:e.cashAvailableLabel}),(0,t.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,d.formatPrice)({amount:w,currencyCode:x,locale:o.locale})})]}),(0,t.jsx)("div",{className:"h-full w-px self-stretch 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:e.cashPendingLabel}),(0,t.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,d.formatPrice)({amount:C,currencyCode:x,locale:o.locale})})]})]}),(e.howToTitle||e.howToDescription)&&(0,t.jsxs)("div",{className:"flex mt-[32px] flex-col gap-[8px]",children:[e.howToTitle&&(0,t.jsx)("h3",{className:"text-[20px] font-bold leading-[1.2] text-[#080a0f]",children:e.howToTitle}),e.howToDescription&&(0,t.jsx)("p",{className:"text-[14px] font-bold leading-[1.4] text-[#080A0F]",children:e.howToDescription}),e.learnMoreLabel&&e.learnMoreUrl&&(0,t.jsxs)("a",{href:p(e.learnMoreUrl),target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-[4px] text-[14px] font-[700] text-[#080a0f] underline",children:[e.learnMoreLabel,(0,t.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:(0,t.jsx)("path",{d:"M5.52827 3.52876C5.78862 3.26841 6.21063 3.26841 6.47098 3.52876L10.471 7.52876C10.7313 7.78911 10.7313 8.21112 10.471 8.47147L6.47098 12.4715C6.21063 12.7318 5.78862 12.7318 5.52827 12.4715C5.26792 12.2111 5.26792 11.7891 5.52827 11.5288L9.05692 8.00011L5.52827 4.47147C5.26792 4.21112 5.26792 3.78911 5.52827 3.52876Z",fill:"#080A0F"})})]})]}),e.image?.url&&(0,t.jsx)(s.Picture,{source:e.image.url,alt:e.image.alt??"",className:(0,r.classNames)("mt-[8px] w-full",m?"rounded-[8px]":"rounded-none")}),e.ctaButton&&(0,t.jsx)(s.Button,{size:"base",as:"a",className:"mt-[16px]",href:e.ctaUrl?p(e.ctaUrl):"#",target:"_blank",rel:"noopener noreferrer",onClick:L,children:e.ctaButton})]})}var B=M;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/Referral/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Button, Picture } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useReferralOverview } from './hooks/useReferralOverview'\nimport { formatPrice } from '../../../credits/context/utils'\n\nimport type { ReferralCopy } from '../../type'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: ReferralCopy\n onClose: () => void\n}\n\nfunction Referral({ copy, onClose }: Props) {\n const { profile, alpcConfig, pageHandle } = useMemberPopupContext()\n const isLogin = !!profile\n const { brand, currencyCode = 'USD' as string } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const { data } = useReferralOverview()\n\n const cashAvailable = data?.data?.data?.available ?? 0\n const cashPending = data?.data?.data?.pending ?? 0\n\n function buildRefUrl(url: string) {\n try {\n if (!pageHandle) return url\n const target = new URL(url, window.location.href)\n target.searchParams.set('ref', `${pageHandle}_referral`)\n return target.toString()\n } catch {\n return url\n }\n }\n\n function trackReferralCta() {\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'referral',\n button_name: 'referral_cta',\n info: 'Member Floating Window',\n },\n })\n }\n\n return (\n <div className=\"flex flex-col\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center mt-[16px] 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.cashAvailableLabel}</div>\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {formatPrice({ amount: cashAvailable, currencyCode, locale: alpcConfig.locale })}\n </span>\n </div>\n <div className=\"h-full w-px self-stretch bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.cashPendingLabel}</div>\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {formatPrice({ amount: cashPending, currencyCode, locale: alpcConfig.locale })}\n </span>\n </div>\n </div>\n )}\n\n {(copy.howToTitle || copy.howToDescription) && (\n <div className=\"flex mt-[32px] flex-col gap-[8px]\">\n {copy.howToTitle && <h3 className=\"text-[20px] font-bold leading-[1.2] text-[#080a0f]\">{copy.howToTitle}</h3>}\n {copy.howToDescription && (\n <p className=\"text-[14px] font-bold leading-[1.4] text-[#080A0F]\">{copy.howToDescription}</p>\n )}\n {copy.learnMoreLabel && copy.learnMoreUrl && (\n <a\n href={buildRefUrl(copy.learnMoreUrl)}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"flex items-center gap-[4px] text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.learnMoreLabel}\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\">\n <path\n d=\"M5.52827 3.52876C5.78862 3.26841 6.21063 3.26841 6.47098 3.52876L10.471 7.52876C10.7313 7.78911 10.7313 8.21112 10.471 8.47147L6.47098 12.4715C6.21063 12.7318 5.78862 12.7318 5.52827 12.4715C5.26792 12.2111 5.26792 11.7891 5.52827 11.5288L9.05692 8.00011L5.52827 4.47147C5.26792 4.21112 5.26792 3.78911 5.52827 3.52876Z\"\n fill=\"#080A0F\"\n />\n </svg>\n </a>\n )}\n </div>\n )}\n\n {copy.image?.url && (\n <Picture\n source={copy.image.url}\n alt={copy.image.alt ?? ''}\n className={cn('mt-[8px] w-full', rounded ? 'rounded-[8px]' : 'rounded-none')}\n />\n )}\n\n {copy.ctaButton && (\n <Button\n size=\"base\"\n as=\"a\"\n href={copy.ctaUrl ? buildRefUrl(copy.ctaUrl) : '#'}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n onClick={trackReferralCta}\n >\n {copy.ctaButton}\n </Button>\n )}\n </div>\n )\n}\n\nexport default Referral\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAkDqB,IAAAI,EAAA,6BAlDrBC,EAAgC,iCAChCC,EAA8D,yBAC9DC,EAAsC,kCACtCC,EAAoC,uCACpCC,EAA4B,0CAG5BC,EAA+B,iCAO/B,SAASC,EAAS,CAAE,KAAAC,EAAM,QAAAC,CAAQ,EAAU,CAC1C,KAAM,CAAE,QAAAC,EAAS,WAAAC,EAAY,WAAAC,CAAW,KAAI,yBAAsB,EAC5DC,EAAU,CAAC,CAACH,EACZ,CAAE,MAAAI,EAAO,aAAAC,EAAe,KAAgB,KAAI,sBAAmB,EAC/DC,EAAU,iBAAe,SAASF,CAAK,EAEvC,CAAE,KAAAG,CAAK,KAAI,uBAAoB,EAE/BC,EAAgBD,G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BAC3B,QAAC,KACC,KAAMY,EAAYZ,EAAK,YAAY,EACnC,OAAO,SACP,IAAI,sBACJ,UAAU,8EAET,UAAAA,EAAK,kBACN,OAAC,OAAI,MAAM,KAAK,OAAO,KAAK,QAAQ,YAAY,KAAK,OACnD,mBAAC,QACC,EAAE,kUACF,KAAK,UACP,EACF,GACF,GAEJ,EAGDA,EAAK,OAAO,QACX,OAAC,WACC,OAAQA,EAAK,MAAM,IACnB,IAAKA,EAAK,MAAM,KAAO,GACvB,aAAW,EAAAgB,YAAG,kBAAmBR,EAAU,gBAAkB,cAAc,EAC7E,EAGDR,EAAK,cACJ,OAAC,UACC,KAAK,OACL,GAAG,IACH,KAAMA,EAAK,OAASY,EAAYZ,EAAK,MAAM,EAAI,IAC/C,OAAO,SACP,IAAI,sBACJ,QAASe,EAER,SAAAf,EAAK,UACR,GAEJ,CAEJ,CAEA,IAAOV,EAAQS",
|
|
4
|
+
"sourcesContent": ["import { Button, Picture } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useReferralOverview } from './hooks/useReferralOverview'\nimport { formatPrice } from '../../../credits/context/utils'\n\nimport type { ReferralCopy } from '../../type'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: ReferralCopy\n onClose: () => void\n}\n\nfunction Referral({ copy, onClose }: Props) {\n const { profile, alpcConfig, pageHandle } = useMemberPopupContext()\n const isLogin = !!profile\n const { brand, currencyCode = 'USD' as string } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const { data } = useReferralOverview()\n\n const cashAvailable = data?.data?.data?.available ?? 0\n const cashPending = data?.data?.data?.pending ?? 0\n\n function buildRefUrl(url: string) {\n try {\n if (!pageHandle) return url\n const target = new URL(url, window.location.href)\n target.searchParams.set('ref', `${pageHandle}_referral`)\n return target.toString()\n } catch {\n return url\n }\n }\n\n function trackReferralCta() {\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'referral',\n button_name: 'referral_cta',\n info: 'Member Floating Window',\n },\n })\n }\n\n return (\n <div className=\"flex flex-col\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center mt-[16px] 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.cashAvailableLabel}</div>\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {formatPrice({ amount: cashAvailable, currencyCode, locale: alpcConfig.locale })}\n </span>\n </div>\n <div className=\"h-full w-px self-stretch bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.cashPendingLabel}</div>\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {formatPrice({ amount: cashPending, currencyCode, locale: alpcConfig.locale })}\n </span>\n </div>\n </div>\n )}\n\n {(copy.howToTitle || copy.howToDescription) && (\n <div className=\"flex mt-[32px] flex-col gap-[8px]\">\n {copy.howToTitle && <h3 className=\"text-[20px] font-bold leading-[1.2] text-[#080a0f]\">{copy.howToTitle}</h3>}\n {copy.howToDescription && (\n <p className=\"text-[14px] font-bold leading-[1.4] text-[#080A0F]\">{copy.howToDescription}</p>\n )}\n {copy.learnMoreLabel && copy.learnMoreUrl && (\n <a\n href={buildRefUrl(copy.learnMoreUrl)}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"flex items-center gap-[4px] text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.learnMoreLabel}\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\">\n <path\n d=\"M5.52827 3.52876C5.78862 3.26841 6.21063 3.26841 6.47098 3.52876L10.471 7.52876C10.7313 7.78911 10.7313 8.21112 10.471 8.47147L6.47098 12.4715C6.21063 12.7318 5.78862 12.7318 5.52827 12.4715C5.26792 12.2111 5.26792 11.7891 5.52827 11.5288L9.05692 8.00011L5.52827 4.47147C5.26792 4.21112 5.26792 3.78911 5.52827 3.52876Z\"\n fill=\"#080A0F\"\n />\n </svg>\n </a>\n )}\n </div>\n )}\n\n {copy.image?.url && (\n <Picture\n source={copy.image.url}\n alt={copy.image.alt ?? ''}\n className={cn('mt-[8px] w-full', rounded ? 'rounded-[8px]' : 'rounded-none')}\n />\n )}\n\n {copy.ctaButton && (\n <Button\n size=\"base\"\n as=\"a\"\n className=\"mt-[16px]\"\n href={copy.ctaUrl ? buildRefUrl(copy.ctaUrl) : '#'}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n onClick={trackReferralCta}\n >\n {copy.ctaButton}\n </Button>\n )}\n </div>\n )\n}\n\nexport default Referral\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAkDqB,IAAAI,EAAA,6BAlDrBC,EAAgC,iCAChCC,EAA8D,yBAC9DC,EAAsC,kCACtCC,EAAoC,uCACpCC,EAA4B,0CAG5BC,EAA+B,iCAO/B,SAASC,EAAS,CAAE,KAAAC,EAAM,QAAAC,CAAQ,EAAU,CAC1C,KAAM,CAAE,QAAAC,EAAS,WAAAC,EAAY,WAAAC,CAAW,KAAI,yBAAsB,EAC5DC,EAAU,CAAC,CAACH,EACZ,CAAE,MAAAI,EAAO,aAAAC,EAAe,KAAgB,KAAI,sBAAmB,EAC/DC,EAAU,iBAAe,SAASF,CAAK,EAEvC,CAAE,KAAAG,CAAK,KAAI,uBAAoB,EAE/BC,EAAgBD,GAAM,MAAM,MAAM,WAAa,EAC/CE,EAAcF,GAAM,MAAM,MAAM,SAAW,EAEjD,SAASG,EAAYC,EAAa,CAChC,GAA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K,kBACN,OAAC,OAAI,MAAM,KAAK,OAAO,KAAK,QAAQ,YAAY,KAAK,OACnD,mBAAC,QACC,EAAE,kUACF,KAAK,UACP,EACF,GACF,GAEJ,EAGDA,EAAK,OAAO,QACX,OAAC,WACC,OAAQA,EAAK,MAAM,IACnB,IAAKA,EAAK,MAAM,KAAO,GACvB,aAAW,EAAAgB,YAAG,kBAAmBR,EAAU,gBAAkB,cAAc,EAC7E,EAGDR,EAAK,cACJ,OAAC,UACC,KAAK,OACL,GAAG,IACH,UAAU,YACV,KAAMA,EAAK,OAASY,EAAYZ,EAAK,MAAM,EAAI,IAC/C,OAAO,SACP,IAAI,sBACJ,QAASe,EAER,SAAAf,EAAK,UACR,GAEJ,CAEJ,CAEA,IAAOV,EAAQS",
|
|
6
6
|
"names": ["Referral_exports", "__export", "Referral_default", "__toCommonJS", "import_jsx_runtime", "import_headless_ui", "import_lib", "import_provider", "import_useReferralOverview", "import_utils", "import_constants", "Referral", "copy", "onClose", "profile", "alpcConfig", "pageHandle", "isLogin", "brand", "currencyCode", "rounded", "data", "cashAvailable", "cashPending", "buildRefUrl", "url", "target", "trackReferralCta", "cn"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Fragment as D,jsx as a,jsxs as n}from"react/jsx-runtime";import{useEffect as H,useMemo as W,useState as k}from"react";import{Picture as q,Button as J}from"@anker-in/headless-ui";import{gaTrack as _,classNames as B,useProductsByHandles as K,useHeadlessContext as Q}from"@anker-in/lib";import{useMemberPopupContext as X}from"../../context/provider";import{useViewStack as Y}from"../../context/viewStack";import{useRedeemableList as Z}from"./hooks/useRedeemableList";import{useRedeemAndBuy as ee}from"./hooks/useRedeemAndBuy";import{ConsumeCreditsItemType as s,MemberPopupPanelType as A}from"../../type";import{numberFormat as x}from"../../../credits/context/utils";import{ROUNDED_BRANDS as te}from"../../../../constants";function ae({copy:t}){const{profile:l,creditInfo:u,openSignUpPopup:S,alpcConfig:v,isActivateSuccess:L,fetchCreditInfo:E,pageHandle:c}=X(),{pushView:h}=Y(),{brand:M}=Q(),C=te.includes(M),[y,P]=k(""),[U,w]=k(null);H(()=>{l?.user_id&&E(l.user_id)},[]);const d=!!l,{redeemableList:R,listLoading:$}=Z(v),{trigger:F}=ee(v),z=t.list.map(e=>e.product?.handle).filter(Boolean),{data:I}=K({handles:z}),T=W(()=>t.list.map(e=>{const r=R.find(o=>String(o.id)===String(e.redeemId));if(!r)return null;const i=Number(u?.available_credit??0),m=r.consume_credits>i,b=r.is_limited&&(!r.remaining_inventory||r.remaining_inventory<=0),j=e.type===s.RedeemAndBuy||e.type===s.Product,f=I?.find(o=>o.handle===e.product?.handle),N=f?.variants?.find(o=>o.sku===e.product?.sku)??f?.variants?.[0];return j&&(!f||!N||!N?.availableForSale||b)||e.type===s.RedeemAndBuy&&e.price==null?null:{...e,alpcData:r,insufficient:m,product:f,variant:N}}).filter(Boolean),[t.list,R,u,l,d,I]),p=l?.activated||L;function O(e){return!d||!p?t.unlockRewards:e.soldOut?t.soldOut:t.btnRedeem}function G(e){return!d||!p?!1:e.insufficient}function g(e){_({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"consume_credits",button_name:"redeem",info:"Member Floating Window"}})}async function V(e){if(!d){S();return}if(!p){h({type:A.Activate});return}if(e.type===s.GiftCard||e.type===s.Product){if(t.creditsPage?.url){const r=t.creditsPage.redeemListSectionId??"creditsRedeemList",i=new URL(t.creditsPage.url,window.location.href);i.searchParams.set("section",r),i.hash=r,c&&i.searchParams.set("ref",`${c}_consume_credits`),g(e.title),window.open(i.toString(),"_blank","noopener,noreferrer")}return}if(e.type===s.Coupon)g(e.title),h({type:A.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,itemRules:e.rules,redeemId:Number(e.redeemId),userId:l?.user_id,alpcConfig:v}});else{P(""),w(e.redeemId),g(e.title);try{await F({productVariant:e.variant,redeemId:Number(e.redeemId),userId:l?.user_id}),_({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"consume_credits",button_name:"redeem_success",info:"Member Floating Window"}})}catch(r){P(r?.message??t.redeemModal.commonError)}finally{w(null)}}}return a(D,{children:n("div",{className:"flex flex-1 flex-col",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] mt-[8px] font-[700] leading-snug text-[#4a4c56]",children:t.subtitle})]}),d&&n("div",{className:B("flex items-center mt-[16px] gap-[12px] bg-[#f5f6f7] p-[16px]",C?"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:x(u?.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:x(u?.pending_credit||0)}),a("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:t.creditUnit??"ankercredits"})]})]})]}),y&&a("div",{className:"text-[14px] mt-[8px] font-[700] text-[#f84d4f]",children:y}),$?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 mt-[16px] flex-col",children:T.map((e,r)=>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 i=e.type===s.Product||e.type===s.RedeemAndBuy,m=i?e.variant?.image?.url??e.product?.images?.[0]?.url??e.image?.url:e.image?.url||t.imageMapping?.[e.type]?.url,b=i?e.variant?.image?.altText??e.product?.images?.[0]?.alt??e.image?.alt??"":e.image?.alt??"";return m?n("div",{className:B("relative size-[64px] shrink-0 overflow-hidden",C?"rounded-[4px]":"rounded-none"),children:[a(q,{source:m,alt:b,className:"flex size-full items-center justify-center",imgClassName:i?"object-cover":"h-full w-auto object-contain"}),e.type===s.Coupon&&e.value&&a("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:e.value&&`${e.value} ${t.off}`}),e.type===s.GiftCard&&e.value&&a("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:e.value&&`${e.value} ${t.giftCard||"Gift Card"}`})]}):null})(),n("div",{className:"min-w-0 flex-1",children:[a("div",{className:"text-[16px] font-[700] text-[#1e2024] line-clamp-2",children:e.product
|
|
1
|
+
import{Fragment as D,jsx as a,jsxs as n}from"react/jsx-runtime";import{useEffect as H,useMemo as W,useState as k}from"react";import{Picture as q,Button as J}from"@anker-in/headless-ui";import{gaTrack as _,classNames as B,useProductsByHandles as K,useHeadlessContext as Q}from"@anker-in/lib";import{useMemberPopupContext as X}from"../../context/provider";import{useViewStack as Y}from"../../context/viewStack";import{useRedeemableList as Z}from"./hooks/useRedeemableList";import{useRedeemAndBuy as ee}from"./hooks/useRedeemAndBuy";import{ConsumeCreditsItemType as s,MemberPopupPanelType as A}from"../../type";import{numberFormat as x}from"../../../credits/context/utils";import{ROUNDED_BRANDS as te}from"../../../../constants";function ae({copy:t}){const{profile:l,creditInfo:u,openSignUpPopup:S,alpcConfig:v,isActivateSuccess:L,fetchCreditInfo:E,pageHandle:c}=X(),{pushView:h}=Y(),{brand:M}=Q(),C=te.includes(M),[y,P]=k(""),[U,w]=k(null);H(()=>{l?.user_id&&E(l.user_id)},[]);const d=!!l,{redeemableList:R,listLoading:$}=Z(v),{trigger:F}=ee(v),z=t.list.map(e=>e.product?.handle).filter(Boolean),{data:I}=K({handles:z}),T=W(()=>t.list.map(e=>{const r=R.find(o=>String(o.id)===String(e.redeemId));if(!r)return null;const i=Number(u?.available_credit??0),m=r.consume_credits>i,b=r.is_limited&&(!r.remaining_inventory||r.remaining_inventory<=0),j=e.type===s.RedeemAndBuy||e.type===s.Product,f=I?.find(o=>o.handle===e.product?.handle),N=f?.variants?.find(o=>o.sku===e.product?.sku)??f?.variants?.[0];return j&&(!f||!N||!N?.availableForSale||b)||e.type===s.RedeemAndBuy&&e.price==null?null:{...e,alpcData:r,insufficient:m,product:f,variant:N}}).filter(Boolean),[t.list,R,u,l,d,I]),p=l?.activated||L;function O(e){return!d||!p?t.unlockRewards:e.soldOut?t.soldOut:t.btnRedeem}function G(e){return!d||!p?!1:e.insufficient}function g(e){_({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"consume_credits",button_name:"redeem",info:"Member Floating Window"}})}async function V(e){if(!d){S();return}if(!p){h({type:A.Activate});return}if(e.type===s.GiftCard||e.type===s.Product){if(t.creditsPage?.url){const r=t.creditsPage.redeemListSectionId??"creditsRedeemList",i=new URL(t.creditsPage.url,window.location.href);i.searchParams.set("section",r),i.hash=r,c&&i.searchParams.set("ref",`${c}_consume_credits`),g(e.title),window.open(i.toString(),"_blank","noopener,noreferrer")}return}if(e.type===s.Coupon)g(e.title),h({type:A.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,itemRules:e.rules,redeemId:Number(e.redeemId),userId:l?.user_id,alpcConfig:v}});else{P(""),w(e.redeemId),g(e.title);try{await F({productVariant:e.variant,redeemId:Number(e.redeemId),userId:l?.user_id}),_({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"consume_credits",button_name:"redeem_success",info:"Member Floating Window"}})}catch(r){P(r?.message??t.redeemModal.commonError)}finally{w(null)}}}return a(D,{children:n("div",{className:"flex flex-1 flex-col",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] mt-[8px] font-[700] leading-snug text-[#4a4c56]",children:t.subtitle})]}),d&&n("div",{className:B("flex items-center mt-[16px] gap-[12px] bg-[#f5f6f7] p-[16px]",C?"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:x(u?.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:x(u?.pending_credit||0)}),a("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:t.creditUnit??"ankercredits"})]})]})]}),y&&a("div",{className:"text-[14px] mt-[8px] font-[700] text-[#f84d4f]",children:y}),$?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 mt-[16px] flex-col",children:T.map((e,r)=>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 i=e.type===s.Product||e.type===s.RedeemAndBuy,m=i?e.variant?.image?.url??e.product?.images?.[0]?.url??e.image?.url:e.image?.url||t.imageMapping?.[e.type]?.url,b=i?e.variant?.image?.altText??e.product?.images?.[0]?.alt??e.image?.alt??"":e.image?.alt??"";return m?n("div",{className:B("relative size-[64px] shrink-0 overflow-hidden",C?"rounded-[4px]":"rounded-none"),children:[a(q,{source:m,alt:b,className:"flex size-full items-center justify-center",imgClassName:i?"object-cover":"h-full w-auto object-contain"}),e.type===s.Coupon&&e.value&&a("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:e.value&&`${e.value} ${t.off}`}),e.type===s.GiftCard&&e.value&&a("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:e.value&&`${e.value} ${t.giftCard||"Gift Card"}`})]}):null})(),n("div",{className:"min-w-0 flex-1",children:[a("div",{className:"text-[16px] font-[700] text-[#1e2024] line-clamp-2",children:e.product?.title??e.title??e.alpcData?.name}),a("div",{className:"mt-[4px] text-[14px] text-[#666]",children:e.type===s.RedeemAndBuy?n(D,{children:[n("div",{children:[x(e.alpcData.consume_credits)," ",t.creditUnit??""," + $",Number(e.price).toFixed(2)]}),e.variant?.price?.amount&&n("div",{className:"text-[12px] ml-1 text-[#999] line-through",children:["$",Number(e.variant.price.amount).toFixed(2)]})]}):`${x(e.alpcData.consume_credits)} ${t.creditUnit??""}`})]}),n("div",{className:"relative group",children:[a(J,{size:"base",disabled:G(e),loading:U===e.redeemId,onClick:()=>V(e),children:O(e)}),e.insufficient&&d&&p&&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:(()=>{if(!c)return t.creditsPage.url;try{const e=new URL(t.creditsPage.url,window.location.href);return e.searchParams.set("ref",`${c}_consume_credits`),e.toString()}catch{return t.creditsPage.url}})(),target:"_blank",rel:"noopener noreferrer",className:"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline",onClick:()=>_({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"consume_credits",button_name:"credits_page_link",info:"Member Floating Window"}}),children:t.creditsPage.label??"Go to Credits Page"})]})})}var me=ae;export{me 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 { useEffect, useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { gaTrack, 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 disabled: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n}\n\nfunction ConsumeCredits({ copy }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig, isActivateSuccess, fetchCreditInfo, pageHandle } =\n 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 useEffect(() => {\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n }, [])\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 = alpcData.consume_credits > availableCredit\n const alpcSoldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n const isPhysicalProduct =\n item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product\n const product = products?.find((p: any) => p.handle === item.product?.handle)\n const variant = product?.variants?.find((v: any) => v.sku === item.product?.sku) ?? product?.variants?.[0]\n if (isPhysicalProduct && (!product || !variant || !variant?.availableForSale || alpcSoldOut)) {\n return null\n }\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && item.price == null) {\n return null\n }\n return { ...item, alpcData, insufficient, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n const isActivate = profile?.activated || isActivateSuccess\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin || !isActivate) {\n return copy.unlockRewards\n }\n if (item.soldOut) {\n return copy.soldOut\n }\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (!isLogin || !isActivate) {\n return false\n }\n return item.insufficient\n }\n\n function trackRedeemButton(itemTitle: string) {\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'redeem',\n info: 'Member Floating Window',\n },\n })\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!isActivate) {\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n const sectionId = copy.creditsPage.redeemListSectionId ?? 'creditsRedeemList'\n const targetUrl = new URL(copy.creditsPage.url, window.location.href)\n targetUrl.searchParams.set('section', sectionId)\n targetUrl.hash = sectionId\n if (pageHandle) {\n targetUrl.searchParams.set('ref', `${pageHandle}_consume_credits`)\n }\n trackRedeemButton(item.title)\n window.open(targetUrl.toString(), '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n trackRedeemButton(item.title)\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 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 trackRedeemButton(item.title)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'redeem_success',\n info: 'Member Floating Window',\n },\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\">\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 && (\n <p className=\"text-[16px] mt-[8px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center mt-[16px] 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] mt-[8px] 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 mt-[16px] flex-col\">\n {list.map((item, idx) => {\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 phsicalProduct =\n item.type === ConsumeCreditsItemType.Product ||\n item.type === ConsumeCreditsItemType.RedeemAndBuy\n const imgUrl = phsicalProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : item.image?.url || copy.imageMapping?.[item.type]?.url\n const imgAlt = phsicalProduct\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={phsicalProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {item.type === ConsumeCreditsItemType.Coupon && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value && `${item.value} ${copy.off}`}\n </div>\n )}\n {item.type === ConsumeCreditsItemType.GiftCard && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value && `${item.value} ${copy.giftCard || 'Gift Card'}`}\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 {item.product.title ?? item.title ?? item.alpcData?.name}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {item.type === ConsumeCreditsItemType.RedeemAndBuy ? (\n <>\n <div>\n {numberFormat(item.alpcData.consume_credits)} {copy.creditUnit ?? ''} + $\n {Number(item.price).toFixed(2)}\n </div>\n {item.variant?.price?.amount && (\n <div className=\"text-[12px] ml-1 text-[#999] line-through\">\n ${Number(item.variant.price.amount).toFixed(2)}\n </div>\n )}\n </>\n ) : (\n `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''}`\n )}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n size=\"base\"\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && isLogin && isActivate && (\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={(() => {\n if (!pageHandle) return copy.creditsPage!.url\n try {\n const url = new URL(copy.creditsPage!.url, window.location.href)\n url.searchParams.set('ref', `${pageHandle}_consume_credits`)\n return url.toString()\n } catch {\n return copy.creditsPage!.url\n }\n })()}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={() =>\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'credits_page_link',\n info: 'Member Floating Window',\n },\n })\n }\n >\n {copy.creditsPage.label ?? 'Go to Credits Page'}\n </a>\n )}\n </div>\n </>\n )\n}\n\nexport default ConsumeCredits\n"],
|
|
5
|
-
"mappings": "AAmLQ,OA+FkB,YAAAA,EA9FD,OAAAC,EADjB,QAAAC,MAAA,oBAnLR,OAAS,aAAAC,EAAW,WAAAC,EAAS,YAAAC,MAAgB,QAC7C,OAAS,WAAAC,EAAS,UAAAC,MAAc,wBAChC,OAAS,WAAAC,EAAS,cAAcC,EAAI,wBAAAC,EAAsB,s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AASzB,EAAuB,aACjCiD,EAASD,EACVvB,EAAK,SAAS,OAAO,KAAOA,EAAK,SAAS,SAAS,CAAC,GAAG,KAAOA,EAAK,OAAO,IAC3EA,EAAK,OAAO,KAAOpB,EAAK,eAAeoB,EAAK,IAAI,GAAG,IACjDyB,EAASF,EACVvB,EAAK,SAAS,OAAO,SAAWA,EAAK,SAAS,SAAS,CAAC,GAAG,KAAOA,EAAK,OAAO,KAAO,GACrFA,EAAK,OAAO,KAAO,GACxB,OAAKwB,EAEH/D,EAAC,OACC,UAAWO,EACT,gDACAsB,EAAU,gBAAkB,cAC9B,EAEA,UAAA9B,EAACK,EAAA,CACC,OAAQ2D,EACR,IAAKC,EACL,UAAU,6CACV,aAAcF,EAAiB,eAAiB,+BAClD,EACCvB,EAAK,OAASzB,EAAuB,QAAUyB,EAAK,OACnDxC,EAAC,OAAI,UAAU,mFACZ,SAAAwC,EAAK,OAAS,GAAGA,EAAK,KAAK,IAAIpB,EAAK,GAAG,GAC1C,EAEDoB,EAAK,OAASzB,EAAuB,UAAYyB,EAAK,OACrDxC,EAAC,OAAI,UAAU,mFACZ,SAAAwC,EAAK,OAAS,GAAGA,EAAK,KAAK,IAAIpB,EAAK,UAAY,WAAW,GAC9D,GAEJ,EAxBkB,IA0BtB,GAAG,EACHnB,EAAC,OAAI,UAAU,iBACb,UAAAD,EAAC,OAAI,UAAU,qDACZ,SAAAwC,EAAK,
|
|
4
|
+
"sourcesContent": ["import { useEffect, useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { gaTrack, 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 disabled: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n}\n\nfunction ConsumeCredits({ copy }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig, isActivateSuccess, fetchCreditInfo, pageHandle } =\n 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 useEffect(() => {\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n }, [])\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 = alpcData.consume_credits > availableCredit\n const alpcSoldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n const isPhysicalProduct =\n item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product\n const product = products?.find((p: any) => p.handle === item.product?.handle)\n const variant = product?.variants?.find((v: any) => v.sku === item.product?.sku) ?? product?.variants?.[0]\n if (isPhysicalProduct && (!product || !variant || !variant?.availableForSale || alpcSoldOut)) {\n return null\n }\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && item.price == null) {\n return null\n }\n return { ...item, alpcData, insufficient, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n const isActivate = profile?.activated || isActivateSuccess\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin || !isActivate) {\n return copy.unlockRewards\n }\n if (item.soldOut) {\n return copy.soldOut\n }\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (!isLogin || !isActivate) {\n return false\n }\n return item.insufficient\n }\n\n function trackRedeemButton(itemTitle: string) {\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'redeem',\n info: 'Member Floating Window',\n },\n })\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!isActivate) {\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n const sectionId = copy.creditsPage.redeemListSectionId ?? 'creditsRedeemList'\n const targetUrl = new URL(copy.creditsPage.url, window.location.href)\n targetUrl.searchParams.set('section', sectionId)\n targetUrl.hash = sectionId\n if (pageHandle) {\n targetUrl.searchParams.set('ref', `${pageHandle}_consume_credits`)\n }\n trackRedeemButton(item.title)\n window.open(targetUrl.toString(), '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n trackRedeemButton(item.title)\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 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 trackRedeemButton(item.title)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'redeem_success',\n info: 'Member Floating Window',\n },\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\">\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 && (\n <p className=\"text-[16px] mt-[8px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center mt-[16px] 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] mt-[8px] 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 mt-[16px] flex-col\">\n {list.map((item, idx) => {\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 phsicalProduct =\n item.type === ConsumeCreditsItemType.Product ||\n item.type === ConsumeCreditsItemType.RedeemAndBuy\n const imgUrl = phsicalProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : item.image?.url || copy.imageMapping?.[item.type]?.url\n const imgAlt = phsicalProduct\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={phsicalProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {item.type === ConsumeCreditsItemType.Coupon && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value && `${item.value} ${copy.off}`}\n </div>\n )}\n {item.type === ConsumeCreditsItemType.GiftCard && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value && `${item.value} ${copy.giftCard || 'Gift Card'}`}\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 {item.product?.title ?? item.title ?? item.alpcData?.name}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {item.type === ConsumeCreditsItemType.RedeemAndBuy ? (\n <>\n <div>\n {numberFormat(item.alpcData.consume_credits)} {copy.creditUnit ?? ''} + $\n {Number(item.price).toFixed(2)}\n </div>\n {item.variant?.price?.amount && (\n <div className=\"text-[12px] ml-1 text-[#999] line-through\">\n ${Number(item.variant.price.amount).toFixed(2)}\n </div>\n )}\n </>\n ) : (\n `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''}`\n )}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n size=\"base\"\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && isLogin && isActivate && (\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={(() => {\n if (!pageHandle) return copy.creditsPage!.url\n try {\n const url = new URL(copy.creditsPage!.url, window.location.href)\n url.searchParams.set('ref', `${pageHandle}_consume_credits`)\n return url.toString()\n } catch {\n return copy.creditsPage!.url\n }\n })()}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={() =>\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'credits_page_link',\n info: 'Member Floating Window',\n },\n })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ACPb,EAAQ,CACN,MAAO,WACP,WAAY,YACZ,iBAAkB,CAChB,SAAU,kBACV,YAAa,oBACb,KAAM,wBACR,CACF,CAAC,EAGF,SAAAa,EAAK,YAAY,OAAS,qBAC7B,GAEJ,EACF,CAEJ,CAEA,IAAO+C,GAAQhD",
|
|
6
6
|
"names": ["Fragment", "jsx", "jsxs", "useEffect", "useMemo", "useState", "Picture", "Button", "gaTrack", "cn", "useProductsByHandles", "useHeadlessContext", "useMemberPopupContext", "useViewStack", "useRedeemableList", "useRedeemAndBuy", "ConsumeCreditsItemType", "MemberPopupPanelType", "numberFormat", "ROUNDED_BRANDS", "ConsumeCredits", "copy", "profile", "creditInfo", "openSignUpPopup", "alpcConfig", "isActivateSuccess", "fetchCreditInfo", "pageHandle", "pushView", "brand", "rounded", "redeemAndBuyError", "setRedeemAndBuyError", "loadingId", "setLoadingId", "isLogin", "redeemableList", "listLoading", "redeemAndBuy", "handles", "item", "products", "list", "alpcData", "r", "availableCredit", "insufficient", "alpcSoldOut", "isPhysicalProduct", "product", "p", "variant", "v", "isActivate", "getButtonLabel", "isDisabled", "trackRedeemButton", "itemTitle", "handleRedeem", "sectionId", "targetUrl", "e", "idx", "phsicalProduct", "imgUrl", "imgAlt", "url", "ConsumeCredits_default"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as t,jsxs as n}from"react/jsx-runtime";import{useEffect as
|
|
1
|
+
import{jsx as t,jsxs as n}from"react/jsx-runtime";import{useEffect as A,useMemo as f}from"react";import{gaTrack as w,classNames as h,useHeadlessContext as I}from"@anker-in/lib";import{useMemberPopupContext as U}from"../../context/provider";import{useViewStack as M}from"../../context/viewStack";import{useSubscribed as R}from"./hooks/useSubscribed";import{EarnCreditsTaskType as i,MemberPopupPanelType as m}from"../../type";import{IconBag as y,IconLock as D,IconSubscription as F,IconOrders as O}from"../../icons";import{numberFormat as S}from"../../../credits/context/utils";import{ROUNDED_BRANDS as V}from"../../../../constants";import{Button as T}from"@anker-in/headless-ui";function z({id:s,className:e}){switch(s){case i.Activate:return t(D,{className:e});case i.Subscribe:return t(F,{className:e});case i.Shop:return t(y,{className:e});case i.CompleteProfile:return t(O,{className:e})}}function H({copy:s}){const{profile:e,openSignUpPopup:l,alpcConfig:u,creditInfo:x,fetchCreditInfo:_,isSubscribeSuccess:b,isActivateSuccess:v,isProfileCompleteSuccess:p}=U(),{pushView:d}=M(),{locale:E}=u,{brand:g}=I(),P=V.includes(g);A(()=>{e?.user_id&&_(e.user_id)},[]);const o=!!e,C=R({userId:e?.user_id,brand:g,email:e?.email,locale:E,apiBaseUrl:u.apiBaseUrl}),k=f(()=>p||!!(e?.first_name||e?.last_name)&&!!e?.phone_number&&!!e?.dob,[e,p]);function c(a){const r={[i.Activate]:"activate",[i.CompleteProfile]:"complete_profile",[i.Subscribe]:"subscribe",[i.Shop]:"shop"};w({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"earn_credits",button_name:r[a],info:"Member Floating Window"}})}const N=f(()=>({[i.Activate]:{finished:!!e?.activated||v,onClick:o?()=>{c(i.Activate),d({type:m.Activate})}:l},[i.CompleteProfile]:{finished:k,onClick:o?()=>{c(i.CompleteProfile),d({type:m.CompleteProfile})}:l},[i.Subscribe]:{finished:C||b,onClick:o?()=>{c(i.Subscribe),d({type:m.SubscribeEmail})}:l},[i.Shop]:{finished:!1,link:s.goShopLink,onClick:o?()=>c(i.Shop):l}}),[e,o,v,p,k,C,b,l,d,s.goShopLink]),L=f(()=>s.list.map(a=>{const r=N[a.id];if(!r)return null;const B=r.finished?s.completed:o?W(a.id,s):s.joinNow;return{...a,...r,buttonLabel:B}}).filter(Boolean),[s,N,o]);return n("div",{className:"flex flex-col gap-[16px]",children:[n("div",{className:"flex flex-col gap-[16px]",children:[t("div",{className:"flex flex-col gap-[8px]",children:s.title&&t("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:s.title})}),o&&n("div",{className:h("flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]",P?"rounded-[8px]":"rounded-none"),children:[n("div",{className:"flex flex-1 flex-col gap-[4px]",children:[t("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:s.balanceLabel??"AnkerCredits Balance"}),n("div",{className:"flex items-end gap-[4px]",children:[t("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:S(x?.available_credit??0)}),t("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:s.creditUnit??"ankercredits"})]})]}),t("div",{className:"h-full w-px bg-[#dadce0]"}),n("div",{className:"flex flex-1 flex-col gap-[4px]",children:[t("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:s.comingSoonLabel??"Coming Soon"}),n("div",{className:"flex items-end gap-[4px]",children:[t("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:S(x?.pending_credit??0)}),t("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:s.creditUnit??"ankercredits"})]})]})]})]}),n("div",{className:"flex flex-col gap-[16px]",children:[s.subtitle&&t("p",{className:"text-[16px] font-[700] text-[#1e2024]",children:s.subtitle}),t("div",{className:"flex flex-col",children:L.map((a,r)=>n("div",{className:"relative py-[16px]",children:[r>0&&t("div",{className:"absolute left-0 right-0 top-0 h-px bg-[#dadce0]"}),n("div",{className:h("flex items-center gap-[12px]"),children:[t(z,{id:a.id,className:"size-[24px] shrink-0"}),n("div",{className:"flex-1",children:[t("div",{className:"text-[16px] font-[700] text-[#1e2024]",children:a.title}),a.credits&&t("div",{className:"mt-[4px] text-[14px] font-bold text-[#4A4C56]",children:a.credits})]}),!a.finished&&a.link&&o?t(T,{as:"a",href:a.link,target:"_blank",rel:"noopener noreferrer",onClick:()=>c(a.id),children:a.buttonLabel}):t(T,{disabled:a.finished,onClick:a.finished?void 0:a.onClick,children:a.buttonLabel})]})]},r))})]})]})}function W(s,e){switch(s){case i.Activate:return e.activate;case i.CompleteProfile:return e.completeProfileLabel;case i.Subscribe:return e.subscribeLabel;case i.Shop:return e.shopNow}}var ee=H;export{ee 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/EarnCredits/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useEffect, useMemo } from 'react'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useSubscribed } from './hooks/useSubscribed'\nimport { EarnCreditsTaskType, MemberPopupPanelType, type EarnCreditsCopy } from '../../type'\nimport { IconBag, IconLock, IconSubscription, IconOrders } from '../../icons'\nimport { numberFormat } from '../../../credits/context/utils'\nimport { ROUNDED_BRANDS } from '../../../../constants'\nimport { Button } from '@anker-in/headless-ui'\n\nfunction TaskIcon({ id, className }: { id: EarnCreditsTaskType; className?: string }) {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return <IconLock className={className} />\n case EarnCreditsTaskType.Subscribe:\n return <IconSubscription className={className} />\n case EarnCreditsTaskType.Shop:\n return <IconBag className={className} />\n case EarnCreditsTaskType.CompleteProfile:\n return <IconOrders className={className} />\n }\n}\n\ntype Props = {\n copy: EarnCreditsCopy\n}\n\nfunction EarnCredits({ copy }: Props) {\n const {\n profile,\n openSignUpPopup,\n alpcConfig,\n creditInfo,\n fetchCreditInfo,\n isSubscribeSuccess,\n isActivateSuccess,\n isProfileCompleteSuccess,\n } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { locale } = alpcConfig\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n useEffect(() => {\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n }, [])\n\n const isLogin = !!profile\n\n const isSubscribed = useSubscribed({\n userId: profile?.user_id,\n brand: brand,\n email: profile?.email,\n locale,\n apiBaseUrl: alpcConfig.apiBaseUrl,\n })\n\n const profileCompleted = useMemo(() => {\n return (\n isProfileCompleteSuccess ||\n (!!(profile?.first_name || profile?.last_name) && !!profile?.phone_number && !!profile?.dob)\n )\n }, [profile, isProfileCompleteSuccess])\n\n function trackTaskButton(taskId: EarnCreditsTaskType) {\n const taskButtonNameMap: Record<EarnCreditsTaskType, string> = {\n [EarnCreditsTaskType.Activate]: 'activate',\n [EarnCreditsTaskType.CompleteProfile]: 'complete_profile',\n [EarnCreditsTaskType.Subscribe]: 'subscribe',\n [EarnCreditsTaskType.Shop]: 'shop',\n }\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'earn_credits',\n button_name: taskButtonNameMap[taskId],\n info: 'Member Floating Window',\n },\n })\n }\n\n const taskStates: Record<EarnCreditsTaskType, { finished: boolean; onClick?: () => void; link?: string }> = useMemo(\n () => ({\n [EarnCreditsTaskType.Activate]: {\n finished: !!profile?.activated || isActivateSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Activate)\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.CompleteProfile]: {\n finished: profileCompleted,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.CompleteProfile)\n pushView({\n type: MemberPopupPanelType.CompleteProfile,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Subscribe]: {\n finished: isSubscribed || isSubscribeSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Subscribe)\n pushView({\n type: MemberPopupPanelType.SubscribeEmail,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Shop]: {\n finished: false,\n link: copy.goShopLink,\n onClick: isLogin ? () => trackTaskButton(EarnCreditsTaskType.Shop) : openSignUpPopup,\n },\n }),\n [\n profile,\n isLogin,\n isActivateSuccess,\n isProfileCompleteSuccess,\n profileCompleted,\n isSubscribed,\n isSubscribeSuccess,\n openSignUpPopup,\n pushView,\n copy.goShopLink,\n ]\n )\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const state = taskStates[item.id]\n if (!state) return null\n const buttonLabel = state.finished\n ? copy.completed\n : isLogin\n ? getNotFinishedLabel(item.id, copy)\n : copy.joinNow\n return { ...item, ...state, buttonLabel }\n })\n .filter(Boolean) as ((typeof copy.list)[number] & {\n finished: boolean\n onClick?: () => void\n link?: string\n buttonLabel: string\n })[]\n }, [copy, taskStates, isLogin])\n\n return (\n <div className=\"flex flex-col gap-[16px]\">\n <div className=\"flex flex-col gap-[16px]\">\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 </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 </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {copy.subtitle && <p className=\"text-[16px] font-[700] text-[#1e2024]\">{copy.subtitle}</p>}\n\n <div className=\"flex flex-col\">\n {list.map((item, idx) => (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute left-0 right-0 top-0 h-px bg-[#dadce0]\" />}\n <div className={cn('flex items-center gap-[12px]')}>\n <TaskIcon id={item.id} className=\"size-[24px] shrink-0\" />\n <div className=\"flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024]\">{item.title}</div>\n {item.credits && <div className=\"mt-[4px] text-[14px] font-bold text-[#4A4C56]\">{item.credits}</div>}\n </div>\n {!item.finished && item.link && isLogin ? (\n <Button\n as=\"a\"\n
|
|
5
|
-
"mappings": "AAca,cAAAA,EAgKC,QAAAC,MAhKD,oBAdb,OAAS,aAAAC,EAAW,WAAAC,MAAe,QACnC,OAAS,WAAAC,EAAS,cAAcC,EAAI,sBAAAC,MAA0B,gBAC9D,OAAS,yBAAAC,MAA6B,yBACtC,OAAS,gBAAAC,MAAoB,0BAC7B,OAAS,iBAAAC,MAAqB,wBAC9B,OAAS,uBAAAC,EAAqB,wBAAAC,MAAkD,aAChF,OAAS,WAAAC,EAAS,YAAAC,EAAU,oBAAAC,EAAkB,cAAAC,MAAkB,cAChE,OAAS,gBAAAC,MAAoB,iCAC7B,OAAS,kBAAAC,MAAsB,wBAC/B,OAAS,UAAAC,MAAc,wBAEvB,SAASC,EAAS,CAAE,GAAAC,EAAI,UAAAC,CAAU,EAAoD,CACpF,OAAQD,EAAI,CACV,KAAKV,EAAoB,SACvB,OAAOV,EAACa,EAAA,CAAS,UAAWQ,EAAW,EACzC,KAAKX,EAAoB,UACvB,OAAOV,EAACc,EAAA,CAAiB,UAAWO,EAAW,EACjD,KAAKX,EAAoB,KACvB,OAAOV,EAACY,EAAA,CAAQ,UAAWS,EAAW,EACxC,KAAKX,EAAoB,gBACvB,OAAOV,EAACe,EAAA,CAAW,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,OAAI,UAAU,wCAAyC,SAAAuB,EAAK,cAAgB,uBAAuB,EACpGtB,EAAC,OAAI,UAAU,2BACb,UAAAD,EAAC,QAAK,UAAU,sDACb,SAAAgB,EAAaW,GAAY,kBAAoB,CAAC,EACjD,EACA3B,EAAC,QAAK,UAAU,sDACb,SAAAuB,EAAK,YAAc,eACtB,GACF,GACF,EACAvB,EAAC,OAAI,UAAU,2BAA2B,EAC1CC,EAAC,OAAI,UAAU,iCACb,UAAAD,EAAC,OAAI,UAAU,wCAAyC,SAAAuB,EAAK,iBAAmB,cAAc,EAC9FtB,EAAC,OAAI,UAAU,2BACb,UAAAD,EAAC,QAAK,UAAU,sDACb,SAAAgB,EAAaW,GAAY,gBAAkB,CAAC,EAC/C,EACA3B,EAAC,QAAK,UAAU,sDACb,SAAAuB,EAAK,YAAc,eACtB,GACF,GACF,GACF,GAEJ,EAEAtB,EAAC,OAAI,UAAU,2BACZ,UAAAsB,EAAK,UAAYvB,EAAC,KAAE,UAAU,wCAAyC,SAAAuB,EAAK,SAAS,EAEtFvB,EAAC,OAAI,UAAU,gBACZ,SAAA2C,EAAK,IAAI,CAACC,EAAMI,IACf/C,EAAC,OAAc,UAAU,qBACtB,UAAA+C,EAAM,GAAKhD,EAAC,OAAI,UAAU,kDAAkD,EAC7EC,EAAC,OAAI,UAAWI,EAAG,8BAA8B,EAC/C,UAAAL,EAACmB,EAAA,CAAS,GAAIyB,EAAK,GAAI,UAAU,uBAAuB,EACxD3C,EAAC,OAAI,UAAU,SACb,UAAAD,EAAC,OAAI,UAAU,wCAAyC,SAAA4C,EAAK,MAAM,EAClEA,EAAK,SAAW5C,EAAC,OAAI,UAAU,gDAAiD,SAAA4C,EAAK,QAAQ,GAChG,EACC,CAACA,EAAK,UAAYA,EAAK,MAAQR,EAC9BpC,EAACkB,EAAA,CACC,GAAG,IACH,
|
|
4
|
+
"sourcesContent": ["import { useEffect, useMemo } from 'react'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useSubscribed } from './hooks/useSubscribed'\nimport { EarnCreditsTaskType, MemberPopupPanelType, type EarnCreditsCopy } from '../../type'\nimport { IconBag, IconLock, IconSubscription, IconOrders } from '../../icons'\nimport { numberFormat } from '../../../credits/context/utils'\nimport { ROUNDED_BRANDS } from '../../../../constants'\nimport { Button } from '@anker-in/headless-ui'\n\nfunction TaskIcon({ id, className }: { id: EarnCreditsTaskType; className?: string }) {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return <IconLock className={className} />\n case EarnCreditsTaskType.Subscribe:\n return <IconSubscription className={className} />\n case EarnCreditsTaskType.Shop:\n return <IconBag className={className} />\n case EarnCreditsTaskType.CompleteProfile:\n return <IconOrders className={className} />\n }\n}\n\ntype Props = {\n copy: EarnCreditsCopy\n}\n\nfunction EarnCredits({ copy }: Props) {\n const {\n profile,\n openSignUpPopup,\n alpcConfig,\n creditInfo,\n fetchCreditInfo,\n isSubscribeSuccess,\n isActivateSuccess,\n isProfileCompleteSuccess,\n } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { locale } = alpcConfig\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n useEffect(() => {\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n }, [])\n\n const isLogin = !!profile\n\n const isSubscribed = useSubscribed({\n userId: profile?.user_id,\n brand: brand,\n email: profile?.email,\n locale,\n apiBaseUrl: alpcConfig.apiBaseUrl,\n })\n\n const profileCompleted = useMemo(() => {\n return (\n isProfileCompleteSuccess ||\n (!!(profile?.first_name || profile?.last_name) && !!profile?.phone_number && !!profile?.dob)\n )\n }, [profile, isProfileCompleteSuccess])\n\n function trackTaskButton(taskId: EarnCreditsTaskType) {\n const taskButtonNameMap: Record<EarnCreditsTaskType, string> = {\n [EarnCreditsTaskType.Activate]: 'activate',\n [EarnCreditsTaskType.CompleteProfile]: 'complete_profile',\n [EarnCreditsTaskType.Subscribe]: 'subscribe',\n [EarnCreditsTaskType.Shop]: 'shop',\n }\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'earn_credits',\n button_name: taskButtonNameMap[taskId],\n info: 'Member Floating Window',\n },\n })\n }\n\n const taskStates: Record<EarnCreditsTaskType, { finished: boolean; onClick?: () => void; link?: string }> = useMemo(\n () => ({\n [EarnCreditsTaskType.Activate]: {\n finished: !!profile?.activated || isActivateSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Activate)\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.CompleteProfile]: {\n finished: profileCompleted,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.CompleteProfile)\n pushView({\n type: MemberPopupPanelType.CompleteProfile,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Subscribe]: {\n finished: isSubscribed || isSubscribeSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Subscribe)\n pushView({\n type: MemberPopupPanelType.SubscribeEmail,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Shop]: {\n finished: false,\n link: copy.goShopLink,\n onClick: isLogin ? () => trackTaskButton(EarnCreditsTaskType.Shop) : openSignUpPopup,\n },\n }),\n [\n profile,\n isLogin,\n isActivateSuccess,\n isProfileCompleteSuccess,\n profileCompleted,\n isSubscribed,\n isSubscribeSuccess,\n openSignUpPopup,\n pushView,\n copy.goShopLink,\n ]\n )\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const state = taskStates[item.id]\n if (!state) return null\n const buttonLabel = state.finished\n ? copy.completed\n : isLogin\n ? getNotFinishedLabel(item.id, copy)\n : copy.joinNow\n return { ...item, ...state, buttonLabel }\n })\n .filter(Boolean) as ((typeof copy.list)[number] & {\n finished: boolean\n onClick?: () => void\n link?: string\n buttonLabel: string\n })[]\n }, [copy, taskStates, isLogin])\n\n return (\n <div className=\"flex flex-col gap-[16px]\">\n <div className=\"flex flex-col gap-[16px]\">\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 </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 </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {copy.subtitle && <p className=\"text-[16px] font-[700] text-[#1e2024]\">{copy.subtitle}</p>}\n\n <div className=\"flex flex-col\">\n {list.map((item, idx) => (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute left-0 right-0 top-0 h-px bg-[#dadce0]\" />}\n <div className={cn('flex items-center gap-[12px]')}>\n <TaskIcon id={item.id} className=\"size-[24px] shrink-0\" />\n <div className=\"flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024]\">{item.title}</div>\n {item.credits && <div className=\"mt-[4px] text-[14px] font-bold text-[#4A4C56]\">{item.credits}</div>}\n </div>\n {!item.finished && item.link && isLogin ? (\n <Button\n as=\"a\"\n href={item.link}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n onClick={() => trackTaskButton(item.id)}\n >\n {item.buttonLabel}\n </Button>\n ) : (\n <Button disabled={item.finished} onClick={!item.finished ? item.onClick : undefined}>\n {item.buttonLabel}\n </Button>\n )}\n </div>\n </div>\n ))}\n </div>\n </div>\n </div>\n )\n}\n\nfunction getNotFinishedLabel(id: EarnCreditsTaskType, copy: EarnCreditsCopy): string {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return copy.activate\n case EarnCreditsTaskType.CompleteProfile:\n return copy.completeProfileLabel\n case EarnCreditsTaskType.Subscribe:\n return copy.subscribeLabel\n case EarnCreditsTaskType.Shop:\n return copy.shopNow\n }\n}\n\nexport default EarnCredits\n"],
|
|
5
|
+
"mappings": "AAca,cAAAA,EAgKC,QAAAC,MAhKD,oBAdb,OAAS,aAAAC,EAAW,WAAAC,MAAe,QACnC,OAAS,WAAAC,EAAS,cAAcC,EAAI,sBAAAC,MAA0B,gBAC9D,OAAS,yBAAAC,MAA6B,yBACtC,OAAS,gBAAAC,MAAoB,0BAC7B,OAAS,iBAAAC,MAAqB,wBAC9B,OAAS,uBAAAC,EAAqB,wBAAAC,MAAkD,aAChF,OAAS,WAAAC,EAAS,YAAAC,EAAU,oBAAAC,EAAkB,cAAAC,MAAkB,cAChE,OAAS,gBAAAC,MAAoB,iCAC7B,OAAS,kBAAAC,MAAsB,wBAC/B,OAAS,UAAAC,MAAc,wBAEvB,SAASC,EAAS,CAAE,GAAAC,EAAI,UAAAC,CAAU,EAAoD,CACpF,OAAQD,EAAI,CACV,KAAKV,EAAoB,SACvB,OAAOV,EAACa,EAAA,CAAS,UAAWQ,EAAW,EACzC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K,QAAQ,GAChG,EACC,CAACA,EAAK,UAAYA,EAAK,MAAQR,EAC9BpC,EAACkB,EAAA,CACC,GAAG,IACH,KAAM0B,EAAK,KACX,OAAO,SACP,IAAI,sBACJ,QAAS,IAAML,EAAgBK,EAAK,EAAE,EAErC,SAAAA,EAAK,YACR,EAEA5C,EAACkB,EAAA,CAAO,SAAU0B,EAAK,SAAU,QAAUA,EAAK,SAA0B,OAAfA,EAAK,QAC7D,SAAAA,EAAK,YACR,GAEJ,IAvBQI,CAwBV,CACD,EACH,GACF,GACF,CAEJ,CAEA,SAASD,EAAoB3B,EAAyBG,EAA+B,CACnF,OAAQH,EAAI,CACV,KAAKV,EAAoB,SACvB,OAAOa,EAAK,SACd,KAAKb,EAAoB,gBACvB,OAAOa,EAAK,qBACd,KAAKb,EAAoB,UACvB,OAAOa,EAAK,eACd,KAAKb,EAAoB,KACvB,OAAOa,EAAK,OAChB,CACF,CAEA,IAAO0B,GAAQ3B",
|
|
6
6
|
"names": ["jsx", "jsxs", "useEffect", "useMemo", "gaTrack", "cn", "useHeadlessContext", "useMemberPopupContext", "useViewStack", "useSubscribed", "EarnCreditsTaskType", "MemberPopupPanelType", "IconBag", "IconLock", "IconSubscription", "IconOrders", "numberFormat", "ROUNDED_BRANDS", "Button", "TaskIcon", "id", "className", "EarnCredits", "copy", "profile", "openSignUpPopup", "alpcConfig", "creditInfo", "fetchCreditInfo", "isSubscribeSuccess", "isActivateSuccess", "isProfileCompleteSuccess", "pushView", "locale", "brand", "rounded", "isLogin", "isSubscribed", "profileCompleted", "trackTaskButton", "taskId", "taskButtonNameMap", "taskStates", "list", "item", "state", "buttonLabel", "getNotFinishedLabel", "idx", "EarnCredits_default"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as t,jsxs as a}from"react/jsx-runtime";import{Button as b,Picture as N}from"@anker-in/headless-ui";import{gaTrack as w,classNames as x,useHeadlessContext as C}from"@anker-in/lib";import{useMemberPopupContext as L}from"../../context/provider";import{useReferralOverview as T}from"./hooks/useReferralOverview";import{formatPrice as
|
|
1
|
+
import{jsx as t,jsxs as a}from"react/jsx-runtime";import{Button as b,Picture as N}from"@anker-in/headless-ui";import{gaTrack as w,classNames as x,useHeadlessContext as C}from"@anker-in/lib";import{useMemberPopupContext as L}from"../../context/provider";import{useReferralOverview as T}from"./hooks/useReferralOverview";import{formatPrice as m}from"../../../credits/context/utils";import{ROUNDED_BRANDS as R}from"../../../../constants";function _({copy:e,onClose:P}){const{profile:c,alpcConfig:r,pageHandle:n}=L(),p=!!c,{brand:g,currencyCode:o="USD"}=C(),s=R.includes(g),{data:i}=T(),u=i?.data?.data?.available??0,v=i?.data?.data?.pending??0;function f(l){try{if(!n)return l;const d=new URL(l,window.location.href);return d.searchParams.set("ref",`${n}_referral`),d.toString()}catch{return l}}function h(){w({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"referral",button_name:"referral_cta",info:"Member Floating Window"}})}return a("div",{className:"flex flex-col",children:[e.title&&t("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:e.title}),p&&a("div",{className:x("flex items-center mt-[16px] gap-[12px] bg-[#f5f6f7] p-[16px]",s?"rounded-[8px]":"rounded-none"),children:[a("div",{className:"flex flex-1 flex-col gap-[4px]",children:[t("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:e.cashAvailableLabel}),t("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:m({amount:u,currencyCode:o,locale:r.locale})})]}),t("div",{className:"h-full w-px self-stretch bg-[#dadce0]"}),a("div",{className:"flex flex-1 flex-col gap-[4px]",children:[t("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:e.cashPendingLabel}),t("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:m({amount:v,currencyCode:o,locale:r.locale})})]})]}),(e.howToTitle||e.howToDescription)&&a("div",{className:"flex mt-[32px] flex-col gap-[8px]",children:[e.howToTitle&&t("h3",{className:"text-[20px] font-bold leading-[1.2] text-[#080a0f]",children:e.howToTitle}),e.howToDescription&&t("p",{className:"text-[14px] font-bold leading-[1.4] text-[#080A0F]",children:e.howToDescription}),e.learnMoreLabel&&e.learnMoreUrl&&a("a",{href:f(e.learnMoreUrl),target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-[4px] text-[14px] font-[700] text-[#080a0f] underline",children:[e.learnMoreLabel,t("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:t("path",{d:"M5.52827 3.52876C5.78862 3.26841 6.21063 3.26841 6.47098 3.52876L10.471 7.52876C10.7313 7.78911 10.7313 8.21112 10.471 8.47147L6.47098 12.4715C6.21063 12.7318 5.78862 12.7318 5.52827 12.4715C5.26792 12.2111 5.26792 11.7891 5.52827 11.5288L9.05692 8.00011L5.52827 4.47147C5.26792 4.21112 5.26792 3.78911 5.52827 3.52876Z",fill:"#080A0F"})})]})]}),e.image?.url&&t(N,{source:e.image.url,alt:e.image.alt??"",className:x("mt-[8px] w-full",s?"rounded-[8px]":"rounded-none")}),e.ctaButton&&t(b,{size:"base",as:"a",className:"mt-[16px]",href:e.ctaUrl?f(e.ctaUrl):"#",target:"_blank",rel:"noopener noreferrer",onClick:h,children:e.ctaButton})]})}var F=_;export{F 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/Referral/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Button, Picture } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useReferralOverview } from './hooks/useReferralOverview'\nimport { formatPrice } from '../../../credits/context/utils'\n\nimport type { ReferralCopy } from '../../type'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: ReferralCopy\n onClose: () => void\n}\n\nfunction Referral({ copy, onClose }: Props) {\n const { profile, alpcConfig, pageHandle } = useMemberPopupContext()\n const isLogin = !!profile\n const { brand, currencyCode = 'USD' as string } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const { data } = useReferralOverview()\n\n const cashAvailable = data?.data?.data?.available ?? 0\n const cashPending = data?.data?.data?.pending ?? 0\n\n function buildRefUrl(url: string) {\n try {\n if (!pageHandle) return url\n const target = new URL(url, window.location.href)\n target.searchParams.set('ref', `${pageHandle}_referral`)\n return target.toString()\n } catch {\n return url\n }\n }\n\n function trackReferralCta() {\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'referral',\n button_name: 'referral_cta',\n info: 'Member Floating Window',\n },\n })\n }\n\n return (\n <div className=\"flex flex-col\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center mt-[16px] 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.cashAvailableLabel}</div>\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {formatPrice({ amount: cashAvailable, currencyCode, locale: alpcConfig.locale })}\n </span>\n </div>\n <div className=\"h-full w-px self-stretch bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.cashPendingLabel}</div>\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {formatPrice({ amount: cashPending, currencyCode, locale: alpcConfig.locale })}\n </span>\n </div>\n </div>\n )}\n\n {(copy.howToTitle || copy.howToDescription) && (\n <div className=\"flex mt-[32px] flex-col gap-[8px]\">\n {copy.howToTitle && <h3 className=\"text-[20px] font-bold leading-[1.2] text-[#080a0f]\">{copy.howToTitle}</h3>}\n {copy.howToDescription && (\n <p className=\"text-[14px] font-bold leading-[1.4] text-[#080A0F]\">{copy.howToDescription}</p>\n )}\n {copy.learnMoreLabel && copy.learnMoreUrl && (\n <a\n href={buildRefUrl(copy.learnMoreUrl)}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"flex items-center gap-[4px] text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.learnMoreLabel}\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\">\n <path\n d=\"M5.52827 3.52876C5.78862 3.26841 6.21063 3.26841 6.47098 3.52876L10.471 7.52876C10.7313 7.78911 10.7313 8.21112 10.471 8.47147L6.47098 12.4715C6.21063 12.7318 5.78862 12.7318 5.52827 12.4715C5.26792 12.2111 5.26792 11.7891 5.52827 11.5288L9.05692 8.00011L5.52827 4.47147C5.26792 4.21112 5.26792 3.78911 5.52827 3.52876Z\"\n fill=\"#080A0F\"\n />\n </svg>\n </a>\n )}\n </div>\n )}\n\n {copy.image?.url && (\n <Picture\n source={copy.image.url}\n alt={copy.image.alt ?? ''}\n className={cn('mt-[8px] w-full', rounded ? 'rounded-[8px]' : 'rounded-none')}\n />\n )}\n\n {copy.ctaButton && (\n <Button\n size=\"base\"\n as=\"a\"\n href={copy.ctaUrl ? buildRefUrl(copy.ctaUrl) : '#'}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n onClick={trackReferralCta}\n >\n {copy.ctaButton}\n </Button>\n )}\n </div>\n )\n}\n\nexport default Referral\n"],
|
|
5
|
-
"mappings": "AAkDqB,cAAAA,EASX,QAAAC,MATW,oBAlDrB,OAAS,UAAAC,EAAQ,WAAAC,MAAe,wBAChC,OAAS,WAAAC,EAAS,cAAcC,EAAI,sBAAAC,MAA0B,gBAC9D,OAAS,yBAAAC,MAA6B,yBACtC,OAAS,uBAAAC,MAA2B,8BACpC,OAAS,eAAAC,MAAmB,iCAG5B,OAAS,kBAAAC,MAAsB,w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AAiB,EAC9EZ,EAAC,QAAK,UAAU,sDACb,SAAAS,EAAY,CAAE,OAAQc,EAAa,aAAAJ,EAAc,OAAQJ,EAAW,MAAO,CAAC,EAC/E,GACF,GACF,GAGAH,EAAK,YAAcA,EAAK,mBACxBX,EAAC,OAAI,UAAU,oCACZ,UAAAW,EAAK,YAAcZ,EAAC,MAAG,UAAU,qDAAsD,SAAAY,EAAK,WAAW,EACvGA,EAAK,kBACJZ,EAAC,KAAE,UAAU,qDAAsD,SAAAY,EAAK,iBAAiB,EAE1FA,EAAK,gBAAkBA,EAAK,cAC3BX,EAAC,KACC,KAAMuB,EAAYZ,EAAK,YAAY,EACnC,OAAO,SACP,IAAI,sBACJ,UAAU,8EAET,UAAAA,EAAK,eACNZ,EAAC,OAAI,MAAM,KAAK,OAAO,KAAK,QAAQ,YAAY,KAAK,OACnD,SAAAA,EAAC,QACC,EAAE,kUACF,KAAK,UACP,EACF,GACF,GAEJ,EAGDY,EAAK,OAAO,KACXZ,EAACG,EAAA,CACC,OAAQS,EAAK,MAAM,IACnB,IAAKA,EAAK,MAAM,KAAO,GACvB,UAAWP,EAAG,kBAAmBe,EAAU,gBAAkB,cAAc,EAC7E,EAGDR,EAAK,WACJZ,EAACE,EAAA,CACC,KAAK,OACL,GAAG,IACH,KAAMU,EAAK,OAASY,EAAYZ,EAAK,MAAM,EAAI,IAC/C,OAAO,SACP,IAAI,sBACJ,QAASe,EAER,SAAAf,EAAK,UACR,GAEJ,CAEJ,CAEA,IAAOgB,EAAQjB",
|
|
4
|
+
"sourcesContent": ["import { Button, Picture } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useReferralOverview } from './hooks/useReferralOverview'\nimport { formatPrice } from '../../../credits/context/utils'\n\nimport type { ReferralCopy } from '../../type'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: ReferralCopy\n onClose: () => void\n}\n\nfunction Referral({ copy, onClose }: Props) {\n const { profile, alpcConfig, pageHandle } = useMemberPopupContext()\n const isLogin = !!profile\n const { brand, currencyCode = 'USD' as string } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const { data } = useReferralOverview()\n\n const cashAvailable = data?.data?.data?.available ?? 0\n const cashPending = data?.data?.data?.pending ?? 0\n\n function buildRefUrl(url: string) {\n try {\n if (!pageHandle) return url\n const target = new URL(url, window.location.href)\n target.searchParams.set('ref', `${pageHandle}_referral`)\n return target.toString()\n } catch {\n return url\n }\n }\n\n function trackReferralCta() {\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'referral',\n button_name: 'referral_cta',\n info: 'Member Floating Window',\n },\n })\n }\n\n return (\n <div className=\"flex flex-col\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center mt-[16px] 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.cashAvailableLabel}</div>\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {formatPrice({ amount: cashAvailable, currencyCode, locale: alpcConfig.locale })}\n </span>\n </div>\n <div className=\"h-full w-px self-stretch bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.cashPendingLabel}</div>\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {formatPrice({ amount: cashPending, currencyCode, locale: alpcConfig.locale })}\n </span>\n </div>\n </div>\n )}\n\n {(copy.howToTitle || copy.howToDescription) && (\n <div className=\"flex mt-[32px] flex-col gap-[8px]\">\n {copy.howToTitle && <h3 className=\"text-[20px] font-bold leading-[1.2] text-[#080a0f]\">{copy.howToTitle}</h3>}\n {copy.howToDescription && (\n <p className=\"text-[14px] font-bold leading-[1.4] text-[#080A0F]\">{copy.howToDescription}</p>\n )}\n {copy.learnMoreLabel && copy.learnMoreUrl && (\n <a\n href={buildRefUrl(copy.learnMoreUrl)}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"flex items-center gap-[4px] text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.learnMoreLabel}\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\">\n <path\n d=\"M5.52827 3.52876C5.78862 3.26841 6.21063 3.26841 6.47098 3.52876L10.471 7.52876C10.7313 7.78911 10.7313 8.21112 10.471 8.47147L6.47098 12.4715C6.21063 12.7318 5.78862 12.7318 5.52827 12.4715C5.26792 12.2111 5.26792 11.7891 5.52827 11.5288L9.05692 8.00011L5.52827 4.47147C5.26792 4.21112 5.26792 3.78911 5.52827 3.52876Z\"\n fill=\"#080A0F\"\n />\n </svg>\n </a>\n )}\n </div>\n )}\n\n {copy.image?.url && (\n <Picture\n source={copy.image.url}\n alt={copy.image.alt ?? ''}\n className={cn('mt-[8px] w-full', rounded ? 'rounded-[8px]' : 'rounded-none')}\n />\n )}\n\n {copy.ctaButton && (\n <Button\n size=\"base\"\n as=\"a\"\n className=\"mt-[16px]\"\n href={copy.ctaUrl ? buildRefUrl(copy.ctaUrl) : '#'}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n onClick={trackReferralCta}\n >\n {copy.ctaButton}\n </Button>\n )}\n </div>\n )\n}\n\nexport default Referral\n"],
|
|
5
|
+
"mappings": "AAkDqB,cAAAA,EASX,QAAAC,MATW,oBAlDrB,OAAS,UAAAC,EAAQ,WAAAC,MAAe,wBAChC,OAAS,WAAAC,EAAS,cAAcC,EAAI,sBAAAC,MAA0B,gBAC9D,OAAS,yBAAAC,MAA6B,yBACtC,OAAS,uBAAAC,MAA2B,8BACpC,OAAS,eAAAC,MAAmB,iCAG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U,wCAAyC,SAAAY,EAAK,iBAAiB,EAC9EZ,EAAC,QAAK,UAAU,sDACb,SAAAS,EAAY,CAAE,OAAQc,EAAa,aAAAJ,EAAc,OAAQJ,EAAW,MAAO,CAAC,EAC/E,GACF,GACF,GAGAH,EAAK,YAAcA,EAAK,mBACxBX,EAAC,OAAI,UAAU,oCACZ,UAAAW,EAAK,YAAcZ,EAAC,MAAG,UAAU,qDAAsD,SAAAY,EAAK,WAAW,EACvGA,EAAK,kBACJZ,EAAC,KAAE,UAAU,qDAAsD,SAAAY,EAAK,iBAAiB,EAE1FA,EAAK,gBAAkBA,EAAK,cAC3BX,EAAC,KACC,KAAMuB,EAAYZ,EAAK,YAAY,EACnC,OAAO,SACP,IAAI,sBACJ,UAAU,8EAET,UAAAA,EAAK,eACNZ,EAAC,OAAI,MAAM,KAAK,OAAO,KAAK,QAAQ,YAAY,KAAK,OACnD,SAAAA,EAAC,QACC,EAAE,kUACF,KAAK,UACP,EACF,GACF,GAEJ,EAGDY,EAAK,OAAO,KACXZ,EAACG,EAAA,CACC,OAAQS,EAAK,MAAM,IACnB,IAAKA,EAAK,MAAM,KAAO,GACvB,UAAWP,EAAG,kBAAmBe,EAAU,gBAAkB,cAAc,EAC7E,EAGDR,EAAK,WACJZ,EAACE,EAAA,CACC,KAAK,OACL,GAAG,IACH,UAAU,YACV,KAAMU,EAAK,OAASY,EAAYZ,EAAK,MAAM,EAAI,IAC/C,OAAO,SACP,IAAI,sBACJ,QAASe,EAER,SAAAf,EAAK,UACR,GAEJ,CAEJ,CAEA,IAAOgB,EAAQjB",
|
|
6
6
|
"names": ["jsx", "jsxs", "Button", "Picture", "gaTrack", "cn", "useHeadlessContext", "useMemberPopupContext", "useReferralOverview", "formatPrice", "ROUNDED_BRANDS", "Referral", "copy", "onClose", "profile", "alpcConfig", "pageHandle", "isLogin", "brand", "currencyCode", "rounded", "data", "cashAvailable", "cashPending", "buildRefUrl", "url", "target", "trackReferralCta", "Referral_default"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -268,7 +268,7 @@ function ConsumeCredits({ copy }: Props) {
|
|
|
268
268
|
})()}
|
|
269
269
|
<div className="min-w-0 flex-1">
|
|
270
270
|
<div className="text-[16px] font-[700] text-[#1e2024] line-clamp-2">
|
|
271
|
-
{item.product
|
|
271
|
+
{item.product?.title ?? item.title ?? item.alpcData?.name}
|
|
272
272
|
</div>
|
|
273
273
|
<div className="mt-[4px] text-[14px] text-[#666]">
|
|
274
274
|
{item.type === ConsumeCreditsItemType.RedeemAndBuy ? (
|
|
@@ -213,7 +213,6 @@ function EarnCredits({ copy }: Props) {
|
|
|
213
213
|
{!item.finished && item.link && isLogin ? (
|
|
214
214
|
<Button
|
|
215
215
|
as="a"
|
|
216
|
-
className="w-full"
|
|
217
216
|
href={item.link}
|
|
218
217
|
target="_blank"
|
|
219
218
|
rel="noopener noreferrer"
|
|
@@ -222,11 +221,7 @@ function EarnCredits({ copy }: Props) {
|
|
|
222
221
|
{item.buttonLabel}
|
|
223
222
|
</Button>
|
|
224
223
|
) : (
|
|
225
|
-
<Button
|
|
226
|
-
className="w-full"
|
|
227
|
-
disabled={item.finished}
|
|
228
|
-
onClick={!item.finished ? item.onClick : undefined}
|
|
229
|
-
>
|
|
224
|
+
<Button disabled={item.finished} onClick={!item.finished ? item.onClick : undefined}>
|
|
230
225
|
{item.buttonLabel}
|
|
231
226
|
</Button>
|
|
232
227
|
)}
|