@anker-in/campaign-ui 0.4.0-beta.3 → 0.4.0-beta.4
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/credits/context/hooks/useMyRewards.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useMyRewards.js.map +2 -2
- package/dist/cjs/components/credits/creditsGoGift/CreditsGoGift.js +1 -1
- package/dist/cjs/components/credits/creditsGoGift/CreditsGoGift.js.map +3 -3
- package/dist/cjs/components/credits/creditsRedeemList/CreditsRedeemList.js +1 -1
- package/dist/cjs/components/credits/creditsRedeemList/CreditsRedeemList.js.map +3 -3
- package/dist/cjs/components/credits/creditsRedeemList/RedeemableItem.js +1 -1
- package/dist/cjs/components/credits/creditsRedeemList/RedeemableItem.js.map +2 -2
- package/dist/cjs/components/credits/type.d.ts +2 -0
- package/dist/cjs/components/credits/type.js +1 -1
- package/dist/cjs/components/credits/type.js.map +1 -1
- package/dist/esm/components/credits/context/hooks/useMyRewards.js +1 -1
- package/dist/esm/components/credits/context/hooks/useMyRewards.js.map +2 -2
- package/dist/esm/components/credits/creditsGoGift/CreditsGoGift.js +1 -1
- package/dist/esm/components/credits/creditsGoGift/CreditsGoGift.js.map +3 -3
- package/dist/esm/components/credits/creditsRedeemList/CreditsRedeemList.js +1 -1
- package/dist/esm/components/credits/creditsRedeemList/CreditsRedeemList.js.map +3 -3
- package/dist/esm/components/credits/creditsRedeemList/RedeemableItem.js +1 -1
- package/dist/esm/components/credits/creditsRedeemList/RedeemableItem.js.map +2 -2
- package/dist/esm/components/credits/type.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/credits/context/hooks/useMyRewards.ts +1 -0
- package/src/components/credits/creditsGoGift/CreditsGoGift.tsx +15 -3
- package/src/components/credits/creditsRedeemList/CreditsRedeemList.tsx +16 -1
- package/src/components/credits/creditsRedeemList/RedeemableItem.tsx +5 -0
- package/src/components/credits/type.ts +2 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var o in e)p(t,o,{get:e[o],enumerable:!0})},N=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of L(e))!T.call(t,s)&&s!==o&&p(t,s,{get:()=>e[s],enumerable:!(n=w(e,s))||n.enumerable});return t};var h=t=>N(p({},"__esModule",{value:!0}),t);var P={};x(P,{default:()=>B});module.exports=h(P);var r=require("react"),a=require("../const"),g=require("./useAlpcFetch"),_=require("../provider"),f=require("@anker-in/lib");function z({page:t,pageSize:e,consumeType:o}){const{profile:n,alpcBrand:s}=(0,_.useCreditsContext)(),{brand:y,locale:m,appName:R}=(0,f.useHeadlessContext)(),C=s||y,[d,b]=(0,r.useState)([]),[i,A]=(0,r.useState)(0),{isMutating:c,trigger:M}=(0,g.useAlpcMutation)({url:"/v1/credit/log/coupon",initData:{brand:C,country:a.ALPC_COUNTRY_MAP.get(m)||m,app_name:R}}),u=(0,r.useCallback)(async()=>{n?.user_id&&await M({consume_type:o||a.AlpcConsumeType.Coupon,page:t,page_size:e,user_id:n?.user_id},{onSuccess(l){A(l?.data?.total),b(l?.data?.redeem_logs||[])}})},[o,t,e,n?.user_id]);return(0,r.useEffect)(()=>{u()},[u]),{myRewards:d,isLoading:c,total:i,getMyRewards:u,canNext:i>d.length&&!c}}var B=z;
|
|
2
2
|
//# sourceMappingURL=useMyRewards.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useMyRewards.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { ALPC_COUNTRY_MAP, AlpcConsumeType } from '../const'\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { RedeemLogResponse } from '../response'\nimport { useCreditsContext } from '../provider'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useMyRewards({\n page,\n pageSize,\n consumeType,\n}: {\n page: number\n pageSize: number\n consumeType?: AlpcConsumeType\n}) {\n const { profile, alpcBrand } = useCreditsContext()\n const { brand: headlessBrand, locale, appName } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n\n const [myRewards, setMyRewards] = useState<RedeemLogResponse[]>([])\n const [total, setTotal] = useState(0)\n\n const { isMutating: isLoading, trigger } = useAlpcMutation<\n { data: { redeem_logs: RedeemLogResponse[]; total: number } },\n {\n page: number\n page_size: number\n consume_type: AlpcConsumeType\n user_id: string\n }\n >({\n url: `/v1/credit/log/coupon`,\n initData: {\n brand: brand,\n country: ALPC_COUNTRY_MAP.get(locale) || locale,\n app_name: appName,\n },\n })\n\n const getMyRewards = useCallback(async () => {\n if (!profile?.user_id) {\n return\n }\n await trigger(\n {\n consume_type: consumeType || AlpcConsumeType.Coupon,\n page,\n page_size: pageSize,\n user_id: profile?.user_id,\n },\n {\n onSuccess(responseData) {\n setMyRewards(responseData?.data?.redeem_logs || [])\n },\n }\n )\n }, [consumeType, page, pageSize, profile?.user_id])\n\n useEffect(() => {\n getMyRewards()\n }, [getMyRewards])\n\n return {\n myRewards,\n isLoading,\n total,\n getMyRewards,\n canNext: total > myRewards.length && !isLoading,\n }\n}\n\nexport default useMyRewards\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiD,iBAEjDC,EAAkD,oBAClDC,EAAgC,0BAEhCC,EAAkC,uBAClCC,EAAmC,yBAEnC,SAASC,EAAa,CACpB,KAAAC,EACA,SAAAC,EACA,YAAAC,CACF,EAIG,CACD,KAAM,CAAG,QAAAC,EAAS,UAAAC,CAAU,KAAI,qBAAkB,EAC5C,CAAE,MAAOC,EAAe,OAAAC,EAAQ,QAAAC,CAAQ,KAAI,sBAAmB,EAC/DC,EAAQJ,GAAaC,EAErB,CAACI,EAAWC,CAAY,KAAI,YAA8B,CAAC,CAAC,EAC5D,CAACC,EAAOC,CAAQ,KAAI,YAAS,CAAC,EAE9B,CAAE,WAAYC,EAAW,QAAAC,CAAQ,KAAI,mBAQzC,CACA,IAAK,wBACL,SAAU,CACR,MAAON,EACP,QAAS,mBAAiB,IAAIF,CAAM,GAAKA,EACzC,SAAUC,CACZ,CACF,CAAC,EAEKQ,KAAe,eAAY,SAAY,CACtCZ,GAAS,SAGd,MAAMW,EACJ,CACE,aAAcZ,GAAe,kBAAgB,OAC7C,KAAAF,EACA,UAAWC,EACX,QAASE,GAAS,OACpB,EACA,CACE,UAAUa,EAAc,
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { ALPC_COUNTRY_MAP, AlpcConsumeType } from '../const'\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { RedeemLogResponse } from '../response'\nimport { useCreditsContext } from '../provider'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useMyRewards({\n page,\n pageSize,\n consumeType,\n}: {\n page: number\n pageSize: number\n consumeType?: AlpcConsumeType\n}) {\n const { profile, alpcBrand } = useCreditsContext()\n const { brand: headlessBrand, locale, appName } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n\n const [myRewards, setMyRewards] = useState<RedeemLogResponse[]>([])\n const [total, setTotal] = useState(0)\n\n const { isMutating: isLoading, trigger } = useAlpcMutation<\n { data: { redeem_logs: RedeemLogResponse[]; total: number } },\n {\n page: number\n page_size: number\n consume_type: AlpcConsumeType\n user_id: string\n }\n >({\n url: `/v1/credit/log/coupon`,\n initData: {\n brand: brand,\n country: ALPC_COUNTRY_MAP.get(locale) || locale,\n app_name: appName,\n },\n })\n\n const getMyRewards = useCallback(async () => {\n if (!profile?.user_id) {\n return\n }\n await trigger(\n {\n consume_type: consumeType || AlpcConsumeType.Coupon,\n page,\n page_size: pageSize,\n user_id: profile?.user_id,\n },\n {\n onSuccess(responseData) {\n setTotal(responseData?.data?.total)\n setMyRewards(responseData?.data?.redeem_logs || [])\n },\n }\n )\n }, [consumeType, page, pageSize, profile?.user_id])\n\n useEffect(() => {\n getMyRewards()\n }, [getMyRewards])\n\n return {\n myRewards,\n isLoading,\n total,\n getMyRewards,\n canNext: total > myRewards.length && !isLoading,\n }\n}\n\nexport default useMyRewards\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiD,iBAEjDC,EAAkD,oBAClDC,EAAgC,0BAEhCC,EAAkC,uBAClCC,EAAmC,yBAEnC,SAASC,EAAa,CACpB,KAAAC,EACA,SAAAC,EACA,YAAAC,CACF,EAIG,CACD,KAAM,CAAG,QAAAC,EAAS,UAAAC,CAAU,KAAI,qBAAkB,EAC5C,CAAE,MAAOC,EAAe,OAAAC,EAAQ,QAAAC,CAAQ,KAAI,sBAAmB,EAC/DC,EAAQJ,GAAaC,EAErB,CAACI,EAAWC,CAAY,KAAI,YAA8B,CAAC,CAAC,EAC5D,CAACC,EAAOC,CAAQ,KAAI,YAAS,CAAC,EAE9B,CAAE,WAAYC,EAAW,QAAAC,CAAQ,KAAI,mBAQzC,CACA,IAAK,wBACL,SAAU,CACR,MAAON,EACP,QAAS,mBAAiB,IAAIF,CAAM,GAAKA,EACzC,SAAUC,CACZ,CACF,CAAC,EAEKQ,KAAe,eAAY,SAAY,CACtCZ,GAAS,SAGd,MAAMW,EACJ,CACE,aAAcZ,GAAe,kBAAgB,OAC7C,KAAAF,EACA,UAAWC,EACX,QAASE,GAAS,OACpB,EACA,CACE,UAAUa,EAAc,CACtBJ,EAASI,GAAc,MAAM,KAAK,EAClCN,EAAaM,GAAc,MAAM,aAAe,CAAC,CAAC,CACpD,CACF,CACF,CACF,EAAG,CAACd,EAAaF,EAAMC,EAAUE,GAAS,OAAO,CAAC,EAElD,sBAAU,IAAM,CACdY,EAAa,CACf,EAAG,CAACA,CAAY,CAAC,EAEV,CACL,UAAAN,EACA,UAAAI,EACA,MAAAF,EACA,aAAAI,EACA,QAASJ,EAAQF,EAAU,QAAU,CAACI,CACxC,CACF,CAEA,IAAOrB,EAAQO",
|
|
6
6
|
"names": ["useMyRewards_exports", "__export", "useMyRewards_default", "__toCommonJS", "import_react", "import_const", "import_useAlpcFetch", "import_provider", "import_lib", "useMyRewards", "page", "pageSize", "consumeType", "profile", "alpcBrand", "headlessBrand", "locale", "appName", "brand", "myRewards", "setMyRewards", "total", "setTotal", "isLoading", "trigger", "getMyRewards", "responseData"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var $=Object.create;var N=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var Q=(e,i)=>{for(var s in i)N(e,s,{get:i[s],enumerable:!0})},A=(e,i,s,x)=>{if(i&&typeof i=="object"||typeof i=="function")for(let d of q(i))!K.call(e,d)&&d!==s&&N(e,d,{get:()=>i[d],enumerable:!(x=V(i,d))||x.enumerable});return e};var h=(e,i,s)=>(s=e!=null?$(J(e)):{},A(i||!e||!e.__esModule?N(s,"default",{value:e,enumerable:!0}):s,e)),W=e=>A(N({},"__esModule",{value:!0}),e);var Y={};Q(Y,{CreditsGoGift:()=>X});module.exports=W(Y);var t=require("react/jsx-runtime"),l=require("@anker-in/headless-ui"),n=require("react"),C=require("@anker-in/lib"),T=h(require("../creditsRedeemList/RedeemVirtualProductModal")),k=h(require("../context/hooks/useRedeemableList")),_=require("../context/provider"),y=require("../../../constants"),O=require("@anker-in/lib"),m=require("../context/const"),G=h(require("../modal/RulesModal")),H=require("../../../components/registration"),B=h(require("../context/hooks/useMyRewards"));const X=({copy:e,id:i})=>{const[s,x]=(0,n.useState)(!1),[d,c]=(0,n.useState)(),[b,E]=(0,n.useState)(),{redeemableList:R}=(0,k.default)({consumeType:m.AlpcConsumeType.ExternalProduct}),{pageCommon:a,profile:g,creditInfo:S,setOpenMyRewardsModal:P,openSignUpPopup:L}=(0,_.useCreditsContext)(),{authCodeActivate:p}=(0,H.useRegistration)(),{brand:F}=(0,O.useHeadlessContext)(),v=y.ROUNDED_BRANDS.includes(F),f=Object.keys(g||{}).length>0,{myRewards:M}=(0,B.default)({page:1,pageSize:100,consumeType:m.AlpcConsumeType.ExternalProduct}),z=a?.redeemModal||{},o=(0,n.useMemo)(()=>{const r=R.find(u=>u.id?.toString()===e?.redeemId?.toString());return r?{alpc:{id:r.id.toString(),consumeCredits:r.consume_credits,remainingInventory:r.remaining_inventory,isLimited:!!r.is_limited,consumeType:r.consume_type,showCredit:!0,title:r.name},config:{title:e.cardTitle,desc:e.cardDesc,type:e.type,value:e.value||"",rules:e.rules,image:e.cardImg}}:null},[R,e]),j=r=>{const u=a?.redeemModal;r===m.AlpcErrorCode.CodeLpcShopifyCouponRuleRedeemLimit?c(u?.redeemLimitError):r===m.AlpcErrorCode.CodeLpcRuleInventoryNotEnough?c(u?.inventoryNotEnough):r===m.AlpcErrorCode.CodeLpcNotEnoughCredits?c(u?.creditsNotEnough):r===m.AlpcErrorCode.CodeCrossSiteError?c(u?.crossSiteError):c(u?.commonError)},D=(0,n.useMemo)(()=>g?.activated&&Number(o?.alpc?.consumeCredits)>Number(S?.available_credit||0),[g?.activated,o?.alpc?.consumeCredits,S?.available_credit]),U=(0,n.useMemo)(()=>!f||!o?.alpc?.id?!1:M.some(r=>r.rule_id===Number(o.alpc.id)),[f,o?.alpc?.id,M]),w=Number(o?.alpc.remainingInventory)<=0,I=(0,n.useMemo)(()=>w?a?.soldOut||"Sold Out":f?e.redeemBtn:e.unlockRewards,[f,w,e,a]);return o?(0,t.jsxs)(l.Container,{id:i,children:[(0,t.jsx)(l.Heading,{as:"h2",size:"4",html:e.title}),(0,t.jsxs)("div",{className:(0,C.classNames)("mt-[24px] flex h-fit w-full items-center bg-[#eaeaec] p-[24px]","l:flex-col l:gap-[12px] l:p-[12px]","min-l:flex-row min-l:gap-[64px]",!v&&"rounded-none",v&&"rounded-[12px]"),children:[(0,t.jsx)("div",{className:"relative flex h-[200px] w-[304px] shrink-0 items-center justify-center overflow-hidden l:h-auto l:aspect-h-[120] l:aspect-w-[304] l:w-full",children:e.cardImg?.url&&(0,t.jsx)(l.Picture,{className:(0,C.classNames)("size-full",v&&"rounded-[12px]"),source:e.mCardImg?.url?`${e.cardImg.url},${e.mCardImg.url} 1024`:e.cardImg.url})}),(0,t.jsxs)("div",{className:"flex w-full items-end justify-between l:flex-col l:items-start l:gap-[24px]",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-[20px] l:w-full l:gap-[12px]",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-[4px]",children:[(0,t.jsx)(l.Text,{html:e.cardTitle,className:"text-[32px] font-bold leading-[1.2] text-[#1D1D1F] l:text-[18px]"}),(0,t.jsx)(l.Text,{html:e.cardDesc,className:"text-[18px] font-bold leading-[1.4] text-[#3D3D3F] l:text-[12px]"})]}),(0,t.jsx)(l.Text,{html:e.cardTip,className:"text-[18px] font-bold leading-[1.4] text-[#000] l:text-[12px]"})]}),(0,t.jsxs)("div",{className:"flex shrink-0 flex-col items-end l:w-full l:items-start",children:[(0,t.jsx)(l.Button,{variant:"primary",disabled:D||w||U,onClick:()=>{f?!g?.activated&&!p.isActivateSuccess?(p.setAutoSendEmail(!0),p.open()):x(!0):L()},title:D?a.insufficientCredits:I,children:I}),d&&(0,t.jsx)("div",{className:"mt-[8px] text-[14px] font-bold leading-[1.2] text-[#FFC24D] l:text-[12px]",children:d}),(e.viewRedeemHistory||e.rulesLink)&&(0,t.jsxs)("div",{className:"mt-[18px] flex gap-[16px] text-[18px] font-bold leading-[1.4] l:mt-[12px] l:gap-0 l:text-[14px]",children:[e.viewRedeemHistory&&(0,t.jsx)(l.Text,{html:e.viewRedeemHistory,className:"cursor-pointer text-[#4794EC] font-bold underline",onClick:()=>{f?!g?.activated&&!p.isActivateSuccess?(p.setAutoSendEmail(!0),p.open()):P(!0):L()}}),a.ruleLabel&&(0,t.jsx)(l.Text,{html:a.ruleLabel,className:(0,C.classNames)("cursor-pointer text-[#4794EC] font-bold underline",e.viewRedeemHistory&&"l:ml-[16px]"),onClick:()=>E(e.rules)})]})]})]})]}),s&&o&&(0,t.jsx)(T.default,{copy:z,onClose:()=>{x(!1),c(void 0)},item:o,onError:j}),b&&(0,t.jsx)(G.default,{overlayClassName:"md:px-[16px] md:items-center",className:(0,C.classNames)("md:h-fit md:rounded-b-[16px]",!v&&"md:rounded-none"),isOpen:b.length>0,onClose:()=>E(void 0),titleClassName:"border-b-transparent h-[56px]",rules:b,scrollClassName:"md:mt-[8px] mt-[8px] md:mb-[24px] md:pt-0",title:a?.ruleLabel,ruleClassName:"text-[#1d1d1f] font-bold"})]}):null};
|
|
2
2
|
//# sourceMappingURL=CreditsGoGift.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/components/credits/creditsGoGift/CreditsGoGift.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Container, Heading, Picture, Button, Text } from '@anker-in/headless-ui'\nimport { useMemo, useState } from 'react'\nimport { classNames as cn } from '@anker-in/lib'\n\nimport RedeemVirtualProductModal from '../creditsRedeemList/RedeemVirtualProductModal'\nimport useRedeemableList from '../context/hooks/useRedeemableList'\nimport { useCreditsContext } from '../context/provider'\nimport { ROUNDED_BRANDS } from '../../../constants'\nimport { useHeadlessContext } from '@anker-in/lib'\nimport { CreditsGoGiftCopy } from './type'\nimport { AlpcConsumeType, AlpcErrorCode } from '../context/const'\nimport RulesModal from '../modal/RulesModal'\nimport { useRegistration } from '../../../components/registration'\n\nexport const CreditsGoGift = ({ copy, id }: { copy: CreditsGoGiftCopy; id?: string }) => {\n const [showModal, setShowModal] = useState(false)\n const [redeemError, setRedeemError] = useState<string>()\n const [rules, setRules] = useState<string | string[]>()\n const { redeemableList } = useRedeemableList({ consumeType: AlpcConsumeType.ExternalProduct })\n const { pageCommon, profile, creditInfo, setOpenMyRewardsModal, openSignUpPopup } = useCreditsContext()\n const { authCodeActivate } = useRegistration()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isLogin = Object.keys(profile || {}).length > 0\n\n const redeemModalCopy = pageCommon?.redeemModal || ({} as any)\n\n
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,
|
|
6
|
-
"names": ["CreditsGoGift_exports", "__export", "CreditsGoGift", "__toCommonJS", "import_jsx_runtime", "import_headless_ui", "import_react", "import_lib", "import_RedeemVirtualProductModal", "import_useRedeemableList", "import_provider", "import_constants", "import_const", "import_RulesModal", "import_registration", "copy", "id", "showModal", "setShowModal", "redeemError", "setRedeemError", "rules", "setRules", "redeemableList", "useRedeemableList", "pageCommon", "profile", "creditInfo", "setOpenMyRewardsModal", "openSignUpPopup", "authCodeActivate", "brand", "rounded", "isLogin", "redeemModalCopy", "item", "alpcData", "handleRedeemError", "code", "inSufficientCredit", "soldOut", "redeemButtonText", "cn", "RedeemVirtualProductModal", "RulesModal"]
|
|
4
|
+
"sourcesContent": ["import { Container, Heading, Picture, Button, Text } from '@anker-in/headless-ui'\nimport { useMemo, useState } from 'react'\nimport { classNames as cn } from '@anker-in/lib'\n\nimport RedeemVirtualProductModal from '../creditsRedeemList/RedeemVirtualProductModal'\nimport useRedeemableList from '../context/hooks/useRedeemableList'\nimport { useCreditsContext } from '../context/provider'\nimport { ROUNDED_BRANDS } from '../../../constants'\nimport { useHeadlessContext } from '@anker-in/lib'\nimport { CreditsGoGiftCopy } from './type'\nimport { AlpcConsumeType, AlpcErrorCode } from '../context/const'\nimport RulesModal from '../modal/RulesModal'\nimport { useRegistration } from '../../../components/registration'\nimport useMyRewards from '../context/hooks/useMyRewards'\n\nexport const CreditsGoGift = ({ copy, id }: { copy: CreditsGoGiftCopy; id?: string }) => {\n const [showModal, setShowModal] = useState(false)\n const [redeemError, setRedeemError] = useState<string>()\n const [rules, setRules] = useState<string | string[]>()\n const { redeemableList } = useRedeemableList({ consumeType: AlpcConsumeType.ExternalProduct })\n const { pageCommon, profile, creditInfo, setOpenMyRewardsModal, openSignUpPopup } = useCreditsContext()\n const { authCodeActivate } = useRegistration()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isLogin = Object.keys(profile || {}).length > 0\n\n // \u83B7\u53D6\u7528\u6237\u7684 ExternalProduct \u5151\u6362\u8BB0\u5F55\n const { myRewards } = useMyRewards({\n page: 1,\n pageSize: 100,\n consumeType: AlpcConsumeType.ExternalProduct,\n })\n\n const redeemModalCopy = pageCommon?.redeemModal || ({} as any)\n\n const item = useMemo(() => {\n // \u6839\u636E redeemId \u67E5\u8BE2 ExternalProduct \u7684 ALPC \u6570\u636E\n const alpcData = redeemableList.find(item => item.id?.toString() === copy?.redeemId?.toString())\n if (!alpcData) return null\n\n return {\n alpc: {\n id: alpcData.id.toString(),\n consumeCredits: alpcData.consume_credits,\n remainingInventory: alpcData.remaining_inventory,\n isLimited: !!alpcData.is_limited,\n consumeType: alpcData.consume_type,\n showCredit: true,\n title: alpcData.name,\n },\n config: {\n title: copy.cardTitle,\n desc: copy.cardDesc,\n type: copy.type,\n value: copy.value || '',\n rules: copy.rules,\n image: copy.cardImg,\n },\n }\n }, [redeemableList, copy])\n\n const handleRedeemError = (code: AlpcErrorCode) => {\n const redeemModalCopy = pageCommon?.redeemModal\n if (code === AlpcErrorCode.CodeLpcShopifyCouponRuleRedeemLimit) {\n setRedeemError(redeemModalCopy?.redeemLimitError)\n } else if (code === AlpcErrorCode.CodeLpcRuleInventoryNotEnough) {\n setRedeemError(redeemModalCopy?.inventoryNotEnough)\n } else if (code === AlpcErrorCode.CodeLpcNotEnoughCredits) {\n setRedeemError(redeemModalCopy?.creditsNotEnough)\n } else if (code === AlpcErrorCode.CodeCrossSiteError) {\n setRedeemError(redeemModalCopy?.crossSiteError)\n } else {\n setRedeemError(redeemModalCopy?.commonError)\n }\n }\n\n const inSufficientCredit = useMemo(() => {\n return (\n profile?.activated && Number(item?.alpc?.consumeCredits) > Number(creditInfo?.available_credit || 0)\n )\n }, [profile?.activated, item?.alpc?.consumeCredits, creditInfo?.available_credit])\n\n // \u68C0\u67E5\u7528\u6237\u662F\u5426\u5DF2\u7ECF\u5151\u6362\u8FC7\u8BE5 GoGift\n const hasRedeemed = useMemo(() => {\n if (!isLogin || !item?.alpc?.id) return false\n return myRewards.some(reward => reward.rule_id === Number(item.alpc.id))\n }, [isLogin, item?.alpc?.id, myRewards])\n\n const soldOut = Number(item?.alpc.remainingInventory) <= 0\n\n const redeemButtonText = useMemo(() => {\n // \u7F3A\u8D27\u6587\u6848\n if (soldOut) {\n return pageCommon?.soldOut || 'Sold Out'\n } else if (!isLogin) {\n return copy.unlockRewards\n } else {\n return copy.redeemBtn\n }\n }, [isLogin, soldOut, copy, pageCommon])\n\n if (!item) return null\n\n return (\n <Container id={id}>\n <Heading as=\"h2\" size=\"4\" html={copy.title} />\n <div\n className={cn(\n 'mt-[24px] flex h-fit w-full items-center bg-[#eaeaec] p-[24px]',\n 'l:flex-col l:gap-[12px] l:p-[12px]',\n 'min-l:flex-row min-l:gap-[64px]',\n !rounded && 'rounded-none',\n rounded && 'rounded-[12px]'\n )}\n >\n {/* Card Image */}\n <div className=\"relative flex h-[200px] w-[304px] shrink-0 items-center justify-center overflow-hidden l:h-auto l:aspect-h-[120] l:aspect-w-[304] l:w-full\">\n {copy.cardImg?.url && (\n <Picture\n className={cn('size-full', rounded && 'rounded-[12px]')}\n source={copy.mCardImg?.url ? `${copy.cardImg.url},${copy.mCardImg.url} 1024` : copy.cardImg.url}\n />\n )}\n </div>\n\n {/* Content Section */}\n <div className=\"flex w-full items-end justify-between l:flex-col l:items-start l:gap-[24px]\">\n {/* Text Content */}\n <div className=\"flex flex-col gap-[20px] l:w-full l:gap-[12px]\">\n <div className=\"flex flex-col gap-[4px]\">\n <Text\n html={copy.cardTitle}\n className=\"text-[32px] font-bold leading-[1.2] text-[#1D1D1F] l:text-[18px]\"\n />\n <Text\n html={copy.cardDesc}\n className=\"text-[18px] font-bold leading-[1.4] text-[#3D3D3F] l:text-[12px]\"\n />\n </div>\n <Text\n html={copy.cardTip}\n className=\"text-[18px] font-bold leading-[1.4] text-[#000] l:text-[12px]\"\n />\n </div>\n\n {/* Button and Links */}\n <div className=\"flex shrink-0 flex-col items-end l:w-full l:items-start\">\n <Button\n variant=\"primary\"\n disabled={inSufficientCredit || soldOut || hasRedeemed}\n onClick={() => {\n if (!isLogin) {\n openSignUpPopup()\n } else if (!profile?.activated && !authCodeActivate.isActivateSuccess) {\n authCodeActivate.setAutoSendEmail(true)\n authCodeActivate.open()\n } else {\n setShowModal(true)\n }\n }}\n title={inSufficientCredit ? pageCommon.insufficientCredits : redeemButtonText}\n >\n {redeemButtonText}\n </Button>\n {redeemError && (\n <div className=\"mt-[8px] text-[14px] font-bold leading-[1.2] text-[#FFC24D] l:text-[12px]\">\n {redeemError}\n </div>\n )}\n {(copy.viewRedeemHistory || copy.rulesLink) && (\n <div className=\"mt-[18px] flex gap-[16px] text-[18px] font-bold leading-[1.4] l:mt-[12px] l:gap-0 l:text-[14px]\">\n {copy.viewRedeemHistory && (\n <Text\n html={copy.viewRedeemHistory}\n className=\"cursor-pointer text-[#4794EC] font-bold underline\"\n onClick={() => {\n if (!isLogin) {\n openSignUpPopup()\n } else if (!profile?.activated && !authCodeActivate.isActivateSuccess) {\n authCodeActivate.setAutoSendEmail(true)\n authCodeActivate.open()\n } else {\n setOpenMyRewardsModal(true)\n }\n }}\n />\n )}\n {pageCommon.ruleLabel && (\n <Text\n html={pageCommon.ruleLabel}\n className={cn(\n 'cursor-pointer text-[#4794EC] font-bold underline',\n copy.viewRedeemHistory && 'l:ml-[16px]'\n )}\n onClick={() => setRules(copy.rules)}\n />\n )}\n </div>\n )}\n </div>\n </div>\n </div>\n\n {showModal && item && (\n <RedeemVirtualProductModal\n copy={redeemModalCopy}\n onClose={() => {\n setShowModal(false)\n setRedeemError(undefined)\n }}\n item={item}\n onError={handleRedeemError}\n />\n )}\n\n {rules && (\n <RulesModal\n overlayClassName=\"md:px-[16px] md:items-center\"\n className={cn('md:h-fit md:rounded-b-[16px]', !rounded && 'md:rounded-none')}\n isOpen={rules.length > 0}\n onClose={() => setRules(undefined)}\n titleClassName=\"border-b-transparent h-[56px]\"\n rules={rules}\n scrollClassName=\"md:mt-[8px] mt-[8px] md:mb-[24px] md:pt-0\"\n title={pageCommon?.ruleLabel}\n ruleClassName=\"text-[#1d1d1f] font-bold\"\n />\n )}\n </Container>\n )\n}\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GA0GM,IAAAI,EAAA,6BA1GNC,EAA0D,iCAC1DC,EAAkC,iBAClCC,EAAiC,yBAEjCC,EAAsC,6DACtCC,EAA8B,iDAC9BC,EAAkC,+BAClCC,EAA+B,8BAC/BJ,EAAmC,yBAEnCK,EAA+C,4BAC/CC,EAAuB,kCACvBC,EAAgC,4CAChCC,EAAyB,4CAElB,MAAMb,EAAgB,CAAC,CAAE,KAAAc,EAAM,GAAAC,CAAG,IAAgD,CACvF,KAAM,CAACC,EAAWC,CAAY,KAAI,YAAS,EAAK,EAC1C,CAACC,EAAaC,CAAc,KAAI,YAAiB,EACjD,CAACC,EAAOC,CAAQ,KAAI,YAA4B,EAChD,CAAE,eAAAC,CAAe,KAAI,EAAAC,SAAkB,CAAE,YAAa,kBAAgB,eAAgB,CAAC,EACvF,CAAE,WAAAC,EAAY,QAAAC,EAAS,WAAAC,EAAY,sBAAAC,EAAuB,gBAAAC,CAAgB,KAAI,qBAAkB,EAChG,CAAE,iBAAAC,CAAiB,KAAI,mBAAgB,EACvC,CA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EALjBW,EAAgB,CAOpB,EACA,MAAOY,EAAqBhB,EAAW,oBAAsBoB,EAE5D,SAAAA,EACH,EACC1B,MACC,OAAC,OAAI,UAAU,4EACZ,SAAAA,EACH,GAEAJ,EAAK,mBAAqBA,EAAK,eAC/B,QAAC,OAAI,UAAU,kGACZ,UAAAA,EAAK,sBACJ,OAAC,QACC,KAAMA,EAAK,kBACX,UAAU,oDACV,QAAS,IAAM,CACRkB,EAEM,CAACP,GAAS,WAAa,CAACI,EAAiB,mBAClDA,EAAiB,iBAAiB,EAAI,EACtCA,EAAiB,KAAK,GAEtBF,EAAsB,EAAI,EAL1BC,EAAgB,CAOpB,EACF,EAEDJ,EAAW,cACV,OAAC,QACC,KAAMA,EAAW,UACjB,aAAW,EAAAqB,YACT,oDACA/B,EAAK,mBAAqB,aAC5B,EACA,QAAS,IAAMO,EAASP,EAAK,KAAK,EACpC,GAEJ,GAEJ,GACF,GACF,EAECE,GAAaoB,MACZ,OAAC,EAAAU,QAAA,CACC,KAAMX,EACN,QAAS,IAAM,CACblB,EAAa,EAAK,EAClBE,EAAe,MAAS,CAC1B,EACA,KAAMiB,EACN,QAASE,EACX,EAGDlB,MACC,OAAC,EAAA2B,QAAA,CACC,iBAAiB,+BACjB,aAAW,EAAAF,YAAG,+BAAgC,CAACd,GAAW,iBAAiB,EAC3E,OAAQX,EAAM,OAAS,EACvB,QAAS,IAAMC,EAAS,MAAS,EACjC,eAAe,gCACf,MAAOD,EACP,gBAAgB,4CAChB,MAAOI,GAAY,UACnB,cAAc,2BAChB,GAEJ,EA/HgB,IAiIpB",
|
|
6
|
+
"names": ["CreditsGoGift_exports", "__export", "CreditsGoGift", "__toCommonJS", "import_jsx_runtime", "import_headless_ui", "import_react", "import_lib", "import_RedeemVirtualProductModal", "import_useRedeemableList", "import_provider", "import_constants", "import_const", "import_RulesModal", "import_registration", "import_useMyRewards", "copy", "id", "showModal", "setShowModal", "redeemError", "setRedeemError", "rules", "setRules", "redeemableList", "useRedeemableList", "pageCommon", "profile", "creditInfo", "setOpenMyRewardsModal", "openSignUpPopup", "authCodeActivate", "brand", "rounded", "isLogin", "myRewards", "useMyRewards", "redeemModalCopy", "item", "alpcData", "handleRedeemError", "code", "inSufficientCredit", "hasRedeemed", "reward", "soldOut", "redeemButtonText", "cn", "RedeemVirtualProductModal", "RulesModal"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var ee=Object.create;var y=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var ae=(e,o)=>{for(var i in o)y(e,i,{get:o[i],enumerable:!0})},F=(e,o,i,C)=>{if(o&&typeof o=="object"||typeof o=="function")for(let c of re(o))!ne.call(e,c)&&c!==i&&y(e,c,{get:()=>o[c],enumerable:!(C=te(o,c))||C.enumerable});return e};var g=(e,o,i)=>(i=e!=null?ee(oe(e)):{},F(o||!e||!e.__esModule?y(i,"default",{value:e,enumerable:!0}):i,e)),ie=e=>F(y({},"__esModule",{value:!0}),e);var de={};ae(de,{CreditsRedeemList:()=>se});module.exports=ie(de);var r=require("react/jsx-runtime"),l=require("@anker-in/headless-ui"),R=g(require("classnames")),d=require("react"),O=g(require("./RedeemCouponModal")),w=g(require("./RedeemProductModal")),H=g(require("./RedeemVirtualProductModal")),$=require("../context/provider"),z=g(require("../context/hooks/useRedeemableList")),a=require("../context/const"),p=require("@anker-in/lib"),B=require("./RedeemableItem"),U=require("../../../constants"),V=g(require("../modal/RulesModal")),j=require("../../../components/registration"),q=require("../context/utils"),J=g(require("../context/hooks/useMyRewards"));const se=({copy:e,id:o})=>{const{profile:i,openSignUpPopup:C,gtm:{pageGroup:c},pageCommon:h,creditInfo:K}=(0,$.useCreditsContext)(),{authCodeActivate:T}=(0,j.useRegistration)(),{brand:k}=(0,p.useHeadlessContext)(),I=U.ROUNDED_BRANDS.includes(k),v=Object.keys(i||{}).length>0,[L,Q]=(0,d.useState)(e.list?.[0]?.label||""),[s,x]=(0,d.useState)(void 0),[N,E]=(0,d.useState)(),{listLoading:W,redeemableList:M,getRedeemableList:A}=(0,z.default)(),{myRewards:P}=(0,J.default)({page:1,pageSize:100,consumeType:a.AlpcConsumeType.ExternalProduct}),f=(0,d.useMemo)(()=>({...h?.redeemModal||{},...e.redeemModal||{}}),[e.redeemModal,h?.redeemModal]),b=(0,d.useMemo)(()=>M.map(t=>({id:t.id.toString(),title:t.name,consumeCredits:t.consume_credits,remainingInventory:t.remaining_inventory,isLimited:!!t.is_limited,consumeType:t.consume_type,handle:t.sku_handle,sku:t.goods_sku,image:t.goods_url})),[e.list,L,M]),X=b.map(t=>t.handle),{data:G}=(0,p.useProductsByHandles)({handles:X}),Y=(0,d.useMemo)(()=>(e.list?.find(n=>n.label===L)?.list||[]).filter(n=>b.some(u=>String(u.id)===String(n.id))).map(n=>{const u=b.find(m=>String(m.id)===String(n.id)),_=G?.find(m=>m.handle===u?.handle),D=_?.variants.find(m=>m.sku===u?.sku);if(u?.isLimited&&(!u?.remainingInventory||u.remainingInventory<=0)||u?.consumeType===a.AlpcConsumeType.Product&&(!_||!D))return null;const Z=n.type===a.ConsumeType.GoGift&&v&&P.some(m=>m.rule_id===Number(n.id));return{alpc:b.find(m=>String(m.id)===String(n.id)),config:n,product:_,variant:D,hasRedeemed:Z}}).filter(n=>n!==null),[b,G,v,P]),S=(0,d.useCallback)(t=>{t===a.AlpcErrorCode.CodeLpcRuleInventoryNotEnough&&A()},[A]);return(0,r.jsxs)(l.Container,{id:o,className:(0,R.default)("relative bg-[#F5F5F7]"),children:[(0,r.jsx)(l.Heading,{as:"h2",size:"4",html:e.title}),v&&e.availableCredits&&(0,r.jsx)("p",{className:"mt-[12px] text-[20px] l-xxl:text-[18px] l:text-[16px] font-bold text-[#4A4C56]",children:e.availableCredits.includes("$credits")?(0,r.jsxs)(r.Fragment,{children:[e.availableCredits.split("$credits")[0],(0,r.jsx)("span",{className:(0,p.classNames)("text-brand-color-0",k==="ankersolix"&&"bg-gradient-to-r from-[#2c7ed0] via-[#00a9e1] via-[43%] to-[#00db84] bg-clip-text text-transparent"),children:(0,q.numberFormat)(K?.available_credit||0).toString()}),e.availableCredits.split("$credits")[1]||""]}):e.availableCredits}),(0,r.jsx)(l.Tabs,{shape:I?"rounded":"square",align:"left",className:(0,R.default)("py-[24px] md:justify-center"),value:L.toString(),onValueChange:t=>{Q(t),(0,p.gaTrack)({event:"ga4Event",event_name:"lp_navigation",event_parameters:{navigation:t,page_group:c}})},children:(0,r.jsx)(l.TabsList,{children:(e.list||[]).map(t=>(0,r.jsx)(l.TabsTrigger,{value:t.label,children:t.label},t.label))})}),!!b?.length&&!W&&(0,r.jsx)("div",{className:(0,R.default)("relative grid grid-cols-4 gap-[16px] md:grid-cols-2 md:gap-[12px] md-xl:grid-cols-3"),children:Y?.map(t=>(0,r.jsx)(B.RedeemableItem,{copy:e,item:t,onRedeem:n=>{v?!i?.activated&&!T.isActivateSuccess?(T.setAutoSendEmail(!0),T.open()):x(n):C()},onRulesOpen:E},t?.alpc?.id))}),(s?.config?.type===a.ConsumeType.Coupon||s?.config?.type===a.ConsumeType.ShippingCoupon)&&f?.coupon&&s&&(0,r.jsx)(O.default,{item:s,copy:f,onError:S,onClose:()=>{x(void 0)}}),s?.config?.type===a.ConsumeType.Product&&f?.product&&s&&(0,r.jsx)(w.default,{item:s,copy:f,onError:S,onClose:()=>{x(void 0)}}),(s?.config?.type===a.ConsumeType.GiftCard||s?.config?.type===a.ConsumeType.GoGift)&&f?.virtualProduct&&s&&(0,r.jsx)(H.default,{item:s,copy:f,onError:S,onClose:()=>{x(void 0)}}),N&&(0,r.jsx)(V.default,{overlayClassName:"md:px-[16px] md:items-center",className:(0,p.classNames)("md:h-fit md:rounded-b-[16px]",!I&&"md:rounded-none"),isOpen:N.length>0,onClose:()=>E([]),titleClassName:"border-b-transparent h-[56px]",rules:N,scrollClassName:"md:mt-[8px] md:mb-[24px] md:pt-0",title:h?.ruleLabel,ruleClassName:"text-[#1d1d1f] font-bold"})]})};
|
|
2
2
|
//# sourceMappingURL=CreditsRedeemList.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/components/credits/creditsRedeemList/CreditsRedeemList.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Container, Heading, Tabs, TabsList, TabsTrigger } from '@anker-in/headless-ui'\nimport classNames from 'classnames'\nimport { useCallback, useMemo, useState } from 'react'\n\nimport RedeemCouponModal from './RedeemCouponModal'\nimport RedeemProductModal from './RedeemProductModal'\nimport RedeemVirtualProductModal from './RedeemVirtualProductModal'\nimport { useCreditsContext } from '../context/provider'\nimport useRedeemableList from '../context/hooks/useRedeemableList'\nimport { AlpcConsumeType, AlpcErrorCode, ConsumeType } from '../context/const'\nimport { useHeadlessContext, useProductsByHandles, gaTrack, classNames as cn } from '@anker-in/lib'\nimport type { RedeemableItem as RedeemableItemType } from '../type'\nimport { RedeemableItem } from './RedeemableItem'\nimport { ROUNDED_BRANDS } from '../../../constants'\nimport RulesModal from '../modal/RulesModal'\nimport { CreditsRedeemListCopy } from './type'\nimport { useRegistration } from '../../../components/registration'\nimport { numberFormat } from '../context/utils'\n\nexport const CreditsRedeemList = ({ copy, id }: { copy: CreditsRedeemListCopy; id?: string }) => {\n const {\n profile,\n openSignUpPopup,\n gtm: { pageGroup },\n pageCommon,\n creditInfo,\n } = useCreditsContext()\n const { authCodeActivate } = useRegistration()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isLogin = Object.keys(profile || {}).length > 0\n\n const [activeTab, setActiveTab] = useState<string>(copy.list?.[0]?.label || '')\n\n const [popRedeemData, setPopRedeemData] = useState<RedeemableItemType | undefined>(undefined)\n\n const [rules, setRules] = useState<string | string[]>()\n\n const { listLoading, redeemableList, getRedeemableList } = useRedeemableList()\n\n // \u5408\u5E76 redeemModal \u6587\u6848\uFF0C\u4F18\u5148\u4F7F\u7528 copy.redeemModal\uFF0Cfallback \u5230 pageCommon.redeemModal\n const redeemModalCopy = useMemo(() => {\n return {\n ...(pageCommon?.redeemModal || {}),\n ...(copy.redeemModal || {}),\n }\n }, [copy.redeemModal, pageCommon?.redeemModal])\n\n const alpcList = useMemo(() => {\n return redeemableList.map(item => {\n return {\n id: item.id.toString(),\n title: item.name,\n consumeCredits: item.consume_credits,\n remainingInventory: item.remaining_inventory,\n isLimited: !!item.is_limited,\n consumeType: item.consume_type,\n handle: item.sku_handle,\n sku: item.goods_sku,\n image: item.goods_url,\n }\n })\n }, [copy.list, activeTab, redeemableList])\n\n const handles = alpcList.map(item => item.handle)\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n const currentList = copy.list?.find(item => item.label === activeTab)\n return (currentList?.list || [])\n .filter(item => alpcList.some(alpcItem => String(alpcItem.id) === String(item.id)))\n .map(item => {\n const alpcItem = alpcList.find(alpcItem => String(alpcItem.id) === String(item.id))\n const product = products?.find(product => product.handle === alpcItem?.handle)\n const variant = product?.variants.find(variant => variant.sku === alpcItem?.sku)\n // \u8FC7\u6EE4\u6389\u5E93\u5B58\u4E0D\u8DB3\u7684\u5546\u54C1\n if (alpcItem?.isLimited && (!alpcItem?.remainingInventory || alpcItem.remainingInventory <= 0)) return null\n if (alpcItem?.consumeType === AlpcConsumeType.Product && (!product || !variant)) return null\n return {\n alpc: alpcList.find(alpcItem => String(alpcItem.id) === String(item.id)),\n config: item,\n product,\n variant,\n }\n })\n .filter(item => item !== null) as unknown as RedeemableItemType[]\n }, [alpcList, products])\n\n const handleRedeemError = useCallback(\n (errorCode: AlpcErrorCode) => {\n if (errorCode === AlpcErrorCode.CodeLpcRuleInventoryNotEnough) {\n getRedeemableList()\n }\n },\n [getRedeemableList]\n )\n\n return (\n <Container id={id} className={classNames('relative bg-[#F5F5F7]')}>\n <Heading as=\"h2\" size=\"4\" html={copy.title} />\n\n {/* \u53EF\u7528\u79EF\u5206\u5C55\u793A */}\n {isLogin && copy.availableCredits && (\n <p className=\"mt-[12px] text-[20px] l-xxl:text-[18px] l:text-[16px] font-bold text-[#4A4C56]\">\n {copy.availableCredits.includes('$credits') ? (\n <>\n {copy.availableCredits.split('$credits')[0]}\n <span\n className={cn(\n 'text-brand-color-0',\n brand === 'ankersolix' &&\n 'bg-gradient-to-r from-[#2c7ed0] via-[#00a9e1] via-[43%] to-[#00db84] bg-clip-text text-transparent'\n )}\n >\n {numberFormat(creditInfo?.available_credit || 0).toString()}\n </span>\n {copy.availableCredits.split('$credits')[1] || ''}\n </>\n ) : (\n copy.availableCredits\n )}\n </p>\n )}\n\n <Tabs\n shape={rounded ? 'rounded' : 'square'}\n align=\"left\"\n className={classNames('py-[24px] md:justify-center')}\n value={activeTab.toString()}\n onValueChange={value => {\n setActiveTab(value)\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_navigation',\n event_parameters: {\n navigation: value,\n page_group: pageGroup,\n },\n })\n }}\n >\n <TabsList>\n {(copy.list || []).map(item => (\n <TabsTrigger key={item.label} value={item.label}>\n {item.label}\n </TabsTrigger>\n ))}\n </TabsList>\n </Tabs>\n {/* PC\u7AEF */}\n {!!alpcList?.length && !listLoading && (\n <div\n className={classNames('relative grid grid-cols-4 gap-[16px] md:grid-cols-2 md:gap-[12px] md-xl:grid-cols-3')}\n >\n {list?.map(item => (\n <RedeemableItem\n key={item?.alpc?.id}\n copy={copy}\n item={item}\n onRedeem={(item: RedeemableItemType) => {\n if (!isLogin) {\n openSignUpPopup()\n } else if (!profile?.activated && !authCodeActivate.isActivateSuccess) {\n authCodeActivate.setAutoSendEmail(true)\n authCodeActivate.open()\n } else {\n setPopRedeemData(item)\n }\n }}\n onRulesOpen={setRules}\n />\n ))}\n </div>\n )}\n\n {(popRedeemData?.config?.type === ConsumeType.Coupon ||\n popRedeemData?.config?.type === ConsumeType.ShippingCoupon) &&\n redeemModalCopy?.coupon &&\n popRedeemData && (\n <RedeemCouponModal\n item={popRedeemData}\n copy={redeemModalCopy}\n onError={handleRedeemError}\n onClose={() => {\n setPopRedeemData(undefined)\n }}\n />\n )}\n {popRedeemData?.config?.type === ConsumeType.Product && redeemModalCopy?.product && popRedeemData && (\n <RedeemProductModal\n item={popRedeemData}\n copy={redeemModalCopy}\n onError={handleRedeemError}\n onClose={() => {\n setPopRedeemData(undefined)\n }}\n />\n )}\n {(popRedeemData?.config?.type === ConsumeType.GiftCard || popRedeemData?.config?.type === ConsumeType.GoGift) &&\n redeemModalCopy?.virtualProduct &&\n popRedeemData && (\n <RedeemVirtualProductModal\n item={popRedeemData}\n copy={redeemModalCopy}\n onError={handleRedeemError}\n onClose={() => {\n setPopRedeemData(undefined)\n }}\n />\n )}\n {rules && (\n <RulesModal\n overlayClassName=\"md:px-[16px] md:items-center\"\n className={cn('md:h-fit md:rounded-b-[16px]', !rounded && 'md:rounded-none')}\n isOpen={rules.length > 0}\n onClose={() => setRules([])}\n titleClassName=\"border-b-transparent h-[56px]\"\n rules={rules}\n scrollClassName=\"md:mt-[8px] md:mb-[24px] md:pt-0\"\n title={pageCommon?.ruleLabel}\n ruleClassName=\"text-[#1d1d1f] font-bold\"\n />\n )}\n </Container>\n )\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["CreditsRedeemList_exports", "__export", "CreditsRedeemList", "__toCommonJS", "import_jsx_runtime", "import_headless_ui", "import_classnames", "import_react", "import_RedeemCouponModal", "import_RedeemProductModal", "import_RedeemVirtualProductModal", "import_provider", "import_useRedeemableList", "import_const", "import_lib", "import_RedeemableItem", "import_constants", "import_RulesModal", "import_registration", "import_utils", "copy", "id", "profile", "openSignUpPopup", "pageGroup", "pageCommon", "creditInfo", "authCodeActivate", "brand", "rounded", "isLogin", "activeTab", "setActiveTab", "popRedeemData", "setPopRedeemData", "rules", "setRules", "listLoading", "redeemableList", "getRedeemableList", "useRedeemableList", "redeemModalCopy", "alpcList", "item", "handles", "products", "list", "alpcItem", "product", "variant", "handleRedeemError", "errorCode", "classNames", "cn", "value", "RedeemCouponModal", "RedeemProductModal", "RedeemVirtualProductModal", "RulesModal"]
|
|
4
|
+
"sourcesContent": ["import { Container, Heading, Tabs, TabsList, TabsTrigger } from '@anker-in/headless-ui'\nimport classNames from 'classnames'\nimport { useCallback, useMemo, useState } from 'react'\n\nimport RedeemCouponModal from './RedeemCouponModal'\nimport RedeemProductModal from './RedeemProductModal'\nimport RedeemVirtualProductModal from './RedeemVirtualProductModal'\nimport { useCreditsContext } from '../context/provider'\nimport useRedeemableList from '../context/hooks/useRedeemableList'\nimport { AlpcConsumeType, AlpcErrorCode, ConsumeType } from '../context/const'\nimport { useHeadlessContext, useProductsByHandles, gaTrack, classNames as cn } from '@anker-in/lib'\nimport type { RedeemableItem as RedeemableItemType } from '../type'\nimport { RedeemableItem } from './RedeemableItem'\nimport { ROUNDED_BRANDS } from '../../../constants'\nimport RulesModal from '../modal/RulesModal'\nimport { CreditsRedeemListCopy } from './type'\nimport { useRegistration } from '../../../components/registration'\nimport { numberFormat } from '../context/utils'\nimport useMyRewards from '../context/hooks/useMyRewards'\n\nexport const CreditsRedeemList = ({ copy, id }: { copy: CreditsRedeemListCopy; id?: string }) => {\n const {\n profile,\n openSignUpPopup,\n gtm: { pageGroup },\n pageCommon,\n creditInfo,\n } = useCreditsContext()\n const { authCodeActivate } = useRegistration()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isLogin = Object.keys(profile || {}).length > 0\n\n const [activeTab, setActiveTab] = useState<string>(copy.list?.[0]?.label || '')\n\n const [popRedeemData, setPopRedeemData] = useState<RedeemableItemType | undefined>(undefined)\n\n const [rules, setRules] = useState<string | string[]>()\n\n const { listLoading, redeemableList, getRedeemableList } = useRedeemableList()\n\n // \u83B7\u53D6\u7528\u6237\u7684 ExternalProduct \u5151\u6362\u8BB0\u5F55\n const { myRewards } = useMyRewards({\n page: 1,\n pageSize: 100,\n consumeType: AlpcConsumeType.ExternalProduct,\n })\n\n // \u5408\u5E76 redeemModal \u6587\u6848\uFF0C\u4F18\u5148\u4F7F\u7528 copy.redeemModal\uFF0Cfallback \u5230 pageCommon.redeemModal\n const redeemModalCopy = useMemo(() => {\n return {\n ...(pageCommon?.redeemModal || {}),\n ...(copy.redeemModal || {}),\n }\n }, [copy.redeemModal, pageCommon?.redeemModal])\n\n const alpcList = useMemo(() => {\n return redeemableList.map(item => {\n return {\n id: item.id.toString(),\n title: item.name,\n consumeCredits: item.consume_credits,\n remainingInventory: item.remaining_inventory,\n isLimited: !!item.is_limited,\n consumeType: item.consume_type,\n handle: item.sku_handle,\n sku: item.goods_sku,\n image: item.goods_url,\n }\n })\n }, [copy.list, activeTab, redeemableList])\n\n const handles = alpcList.map(item => item.handle)\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n const currentList = copy.list?.find(item => item.label === activeTab)\n return (currentList?.list || [])\n .filter(item => alpcList.some(alpcItem => String(alpcItem.id) === String(item.id)))\n .map(item => {\n const alpcItem = alpcList.find(alpcItem => String(alpcItem.id) === String(item.id))\n const product = products?.find(product => product.handle === alpcItem?.handle)\n const variant = product?.variants.find(variant => variant.sku === alpcItem?.sku)\n // \u8FC7\u6EE4\u6389\u5E93\u5B58\u4E0D\u8DB3\u7684\u5546\u54C1\n if (alpcItem?.isLimited && (!alpcItem?.remainingInventory || alpcItem.remainingInventory <= 0)) return null\n if (alpcItem?.consumeType === AlpcConsumeType.Product && (!product || !variant)) return null\n\n // \u68C0\u67E5 GoGift \u662F\u5426\u5DF2\u7ECF\u5151\u6362\u8FC7\uFF08\u53EA\u6709 GoGift \u9650\u5236\u5151\u6362\u4E00\u6B21\uFF09\n const hasRedeemed = item.type === ConsumeType.GoGift &&\n isLogin &&\n myRewards.some(reward => reward.rule_id === Number(item.id))\n\n return {\n alpc: alpcList.find(alpcItem => String(alpcItem.id) === String(item.id)),\n config: item,\n product,\n variant,\n hasRedeemed,\n }\n })\n .filter(item => item !== null) as unknown as RedeemableItemType[]\n }, [alpcList, products, isLogin, myRewards])\n\n const handleRedeemError = useCallback(\n (errorCode: AlpcErrorCode) => {\n if (errorCode === AlpcErrorCode.CodeLpcRuleInventoryNotEnough) {\n getRedeemableList()\n }\n },\n [getRedeemableList]\n )\n\n return (\n <Container id={id} className={classNames('relative bg-[#F5F5F7]')}>\n <Heading as=\"h2\" size=\"4\" html={copy.title} />\n\n {/* \u53EF\u7528\u79EF\u5206\u5C55\u793A */}\n {isLogin && copy.availableCredits && (\n <p className=\"mt-[12px] text-[20px] l-xxl:text-[18px] l:text-[16px] font-bold text-[#4A4C56]\">\n {copy.availableCredits.includes('$credits') ? (\n <>\n {copy.availableCredits.split('$credits')[0]}\n <span\n className={cn(\n 'text-brand-color-0',\n brand === 'ankersolix' &&\n 'bg-gradient-to-r from-[#2c7ed0] via-[#00a9e1] via-[43%] to-[#00db84] bg-clip-text text-transparent'\n )}\n >\n {numberFormat(creditInfo?.available_credit || 0).toString()}\n </span>\n {copy.availableCredits.split('$credits')[1] || ''}\n </>\n ) : (\n copy.availableCredits\n )}\n </p>\n )}\n\n <Tabs\n shape={rounded ? 'rounded' : 'square'}\n align=\"left\"\n className={classNames('py-[24px] md:justify-center')}\n value={activeTab.toString()}\n onValueChange={value => {\n setActiveTab(value)\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_navigation',\n event_parameters: {\n navigation: value,\n page_group: pageGroup,\n },\n })\n }}\n >\n <TabsList>\n {(copy.list || []).map(item => (\n <TabsTrigger key={item.label} value={item.label}>\n {item.label}\n </TabsTrigger>\n ))}\n </TabsList>\n </Tabs>\n {/* PC\u7AEF */}\n {!!alpcList?.length && !listLoading && (\n <div\n className={classNames('relative grid grid-cols-4 gap-[16px] md:grid-cols-2 md:gap-[12px] md-xl:grid-cols-3')}\n >\n {list?.map(item => (\n <RedeemableItem\n key={item?.alpc?.id}\n copy={copy}\n item={item}\n onRedeem={(item: RedeemableItemType) => {\n if (!isLogin) {\n openSignUpPopup()\n } else if (!profile?.activated && !authCodeActivate.isActivateSuccess) {\n authCodeActivate.setAutoSendEmail(true)\n authCodeActivate.open()\n } else {\n setPopRedeemData(item)\n }\n }}\n onRulesOpen={setRules}\n />\n ))}\n </div>\n )}\n\n {(popRedeemData?.config?.type === ConsumeType.Coupon ||\n popRedeemData?.config?.type === ConsumeType.ShippingCoupon) &&\n redeemModalCopy?.coupon &&\n popRedeemData && (\n <RedeemCouponModal\n item={popRedeemData}\n copy={redeemModalCopy}\n onError={handleRedeemError}\n onClose={() => {\n setPopRedeemData(undefined)\n }}\n />\n )}\n {popRedeemData?.config?.type === ConsumeType.Product && redeemModalCopy?.product && popRedeemData && (\n <RedeemProductModal\n item={popRedeemData}\n copy={redeemModalCopy}\n onError={handleRedeemError}\n onClose={() => {\n setPopRedeemData(undefined)\n }}\n />\n )}\n {(popRedeemData?.config?.type === ConsumeType.GiftCard || popRedeemData?.config?.type === ConsumeType.GoGift) &&\n redeemModalCopy?.virtualProduct &&\n popRedeemData && (\n <RedeemVirtualProductModal\n item={popRedeemData}\n copy={redeemModalCopy}\n onError={handleRedeemError}\n onClose={() => {\n setPopRedeemData(undefined)\n }}\n />\n )}\n {rules && (\n <RulesModal\n overlayClassName=\"md:px-[16px] md:items-center\"\n className={cn('md:h-fit md:rounded-b-[16px]', !rounded && 'md:rounded-none')}\n isOpen={rules.length > 0}\n onClose={() => setRules([])}\n titleClassName=\"border-b-transparent h-[56px]\"\n rules={rules}\n scrollClassName=\"md:mt-[8px] md:mb-[24px] md:pt-0\"\n title={pageCommon?.ruleLabel}\n ruleClassName=\"text-[#1d1d1f] font-bold\"\n />\n )}\n </Container>\n )\n}\n"],
|
|
5
|
+
"mappings": "skBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,uBAAAE,KAAA,eAAAC,GAAAH,IAmHM,IAAAI,EAAA,6BAnHNC,EAAgE,iCAChEC,EAAuB,yBACvBC,EAA+C,iBAE/CC,EAA8B,kCAC9BC,EAA+B,mCAC/BC,EAAsC,0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,GAAe,QAAQ,OAAS,cAAY,iBAC5CU,GAAiB,QACjBV,MACE,OAAC,EAAA0B,QAAA,CACC,KAAM1B,EACN,KAAMU,EACN,QAASW,EACT,QAAS,IAAM,CACbpB,EAAiB,MAAS,CAC5B,EACF,EAEHD,GAAe,QAAQ,OAAS,cAAY,SAAWU,GAAiB,SAAWV,MAClF,OAAC,EAAA2B,QAAA,CACC,KAAM3B,EACN,KAAMU,EACN,QAASW,EACT,QAAS,IAAM,CACbpB,EAAiB,MAAS,CAC5B,EACF,GAEAD,GAAe,QAAQ,OAAS,cAAY,UAAYA,GAAe,QAAQ,OAAS,cAAY,SACpGU,GAAiB,gBACjBV,MACE,OAAC,EAAA4B,QAAA,CACC,KAAM5B,EACN,KAAMU,EACN,QAASW,EACT,QAAS,IAAM,CACbpB,EAAiB,MAAS,CAC5B,EACF,EAEHC,MACC,OAAC,EAAA2B,QAAA,CACC,iBAAiB,+BACjB,aAAW,EAAAL,YAAG,+BAAgC,CAAC5B,GAAW,iBAAiB,EAC3E,OAAQM,EAAM,OAAS,EACvB,QAAS,IAAMC,EAAS,CAAC,CAAC,EAC1B,eAAe,gCACf,MAAOD,EACP,gBAAgB,mCAChB,MAAOV,GAAY,UACnB,cAAc,2BAChB,GAEJ,CAEJ",
|
|
6
|
+
"names": ["CreditsRedeemList_exports", "__export", "CreditsRedeemList", "__toCommonJS", "import_jsx_runtime", "import_headless_ui", "import_classnames", "import_react", "import_RedeemCouponModal", "import_RedeemProductModal", "import_RedeemVirtualProductModal", "import_provider", "import_useRedeemableList", "import_const", "import_lib", "import_RedeemableItem", "import_constants", "import_RulesModal", "import_registration", "import_utils", "import_useMyRewards", "copy", "id", "profile", "openSignUpPopup", "pageGroup", "pageCommon", "creditInfo", "authCodeActivate", "brand", "rounded", "isLogin", "activeTab", "setActiveTab", "popRedeemData", "setPopRedeemData", "rules", "setRules", "listLoading", "redeemableList", "getRedeemableList", "useRedeemableList", "myRewards", "useMyRewards", "redeemModalCopy", "alpcList", "item", "handles", "products", "list", "alpcItem", "product", "variant", "hasRedeemed", "reward", "handleRedeemError", "errorCode", "classNames", "cn", "value", "RedeemCouponModal", "RedeemProductModal", "RedeemVirtualProductModal", "RulesModal"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var P=Object.create;var x=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var L=(t,l)=>{for(var e in l)x(t,e,{get:l[e],enumerable:!0})},_=(t,l,e,u)=>{if(l&&typeof l=="object"||typeof l=="function")for(let r of $(l))!E.call(t,r)&&r!==e&&x(t,r,{get:()=>l[r],enumerable:!(u=S(l,r))||u.enumerable});return t};var D=(t,l,e)=>(e=t!=null?P(z(t)):{},_(l||!t||!t.__esModule?x(e,"default",{value:t,enumerable:!0}):e,t)),O=t=>_(x({},"__esModule",{value:!0}),t);var A={};L(A,{RedeemableItem:()=>F});module.exports=O(A);var a=require("react/jsx-runtime"),n=require("@anker-in/headless-ui"),f=require("react"),v=D(require("classnames")),N=require("../context/provider"),o=require("../context/const"),d=require("../context/utils"),c=require("@anker-in/lib"),
|
|
1
|
+
"use strict";var P=Object.create;var x=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var L=(t,l)=>{for(var e in l)x(t,e,{get:l[e],enumerable:!0})},_=(t,l,e,u)=>{if(l&&typeof l=="object"||typeof l=="function")for(let r of $(l))!E.call(t,r)&&r!==e&&x(t,r,{get:()=>l[r],enumerable:!(u=S(l,r))||u.enumerable});return t};var D=(t,l,e)=>(e=t!=null?P(z(t)):{},_(l||!t||!t.__esModule?x(e,"default",{value:t,enumerable:!0}):e,t)),O=t=>_(x({},"__esModule",{value:!0}),t);var A={};L(A,{RedeemableItem:()=>F});module.exports=O(A);var a=require("react/jsx-runtime"),n=require("@anker-in/headless-ui"),f=require("react"),v=D(require("classnames")),N=require("../context/provider"),o=require("../context/const"),d=require("../context/utils"),c=require("@anker-in/lib"),R=require("./NonProductValue"),C=require("../../../constants");function F({copy:t,className:l,item:e,onRulesOpen:u,onRedeem:r}){const{creditInfo:b,profile:i,gtm:{pageGroup:h,pageHandle:p},pageCommon:s}=(0,N.useCreditsContext)(),{brand:T}=(0,c.useHeadlessContext)(),m=Object.keys(i||{}).length>0,w=C.ROUNDED_BRANDS.includes(T),I=(0,f.useMemo)(()=>!!(e.hasRedeemed||e.alpc?.remainingInventory<=0&&e.alpc?.isLimited||e.alpc?.consumeType===o.AlpcConsumeType.Product&&!e.variant?.availableForSale||m&&i?.activated&&e.alpc?.consumeCredits>Number(b?.available_credit||0)),[e.hasRedeemed,e.alpc?.remainingInventory,e.alpc?.isLimited,e.alpc?.consumeType,e.alpc?.consumeCredits,m,i?.activated,b?.available_credit,e.variant?.availableForSale]),y=(0,f.useMemo)(()=>m?e.alpc?.consumeType===o.AlpcConsumeType.Product?e.variant?.availableForSale?t.btnRedeem:s?.soldOut||"Sold Out":t.btnRedeem:t.unlockRewards,[m,e.alpc?.consumeType,e.variant?.availableForSale,t.btnRedeem,t.unlockRewards,s?.soldOut]),k=(0,f.useMemo)(()=>{if(!(e.config?.type!==o.ConsumeType.Product||!e.product?.handle))return(0,d.extractVariantId)(e.variant?.id)?`/products/${e.product.handle}?variant=${(0,d.extractVariantId)(e.variant?.id)}${p?`&ref=${p}`:""}`:`/products/${e.product.handle}${p?`?ref=${p}`:""}`},[e.config?.type,e.product?.handle,e.variant?.id,p]);return(0,a.jsxs)("div",{className:(0,v.default)("flex flex-col items-center rounded-[16px] bg-[#EAEAEC] p-[24px] md:rounded-[12px] md:px-[8px] xl:py-[16px] md-xl:px-[16px]",!w&&"rounded-none md:rounded-none",l),children:[e.config?.type===o.ConsumeType.Product?(0,a.jsx)("a",{href:k,className:(0,v.default)("relative mx-auto h-[224px] w-fit md:my-[10px] l:h-[120px] l-xxl:h-[138px]"),children:(0,a.jsx)(n.Picture,{className:"h-full w-auto [&_img]:h-full [&_img]:object-contain",source:e.config?.image?.url||e.product?.images?.[0]?.url})}):(0,a.jsxs)("div",{className:"relative mx-auto my-[30px] h-[164px] md:my-0 md:h-[66px] l-xxl:h-[138px] md-l:h-[80px]",children:[(0,a.jsx)(n.Picture,{source:s?.imageMapping?.[e.config?.type]?.url,className:"h-full [&_img]:h-full [&_img]:w-auto [&_img]:object-contain"}),(0,a.jsx)(R.NoneProductValue,{item:e})]}),(0,a.jsxs)("div",{className:(0,v.default)("mt-[10px] xl:mt-[8px] flex w-full flex-1 flex-col justify-between"),children:[(0,a.jsx)(n.Text,{html:e.config?.title||e.alpc?.title,title:e.config?.title||e.alpc?.title,size:2,className:"line-clamp-2 h-[58px] text-[24px] leading-[1.2] l:h-[40px] l:text-[16px] l-xxl:h-[48px] l-xxl:text-[20px]"}),e.config?.rules?.length>0&&(0,a.jsx)("button",{type:"button",onClick:()=>{u(e.config?.rules||[]),(0,c.gaTrack)({event:"ga4Event",event_name:"lp_button",member_active_status:i?.activated?"active":"not active",event_parameters:{page_group:h,position:t.title,button_name:s?.ruleLabel,info:e.alpc?.id?.toString()}})},className:"mt-[8px] w-fit text-[16px] font-bold underline md:text-[14px] l:mt-0",tabIndex:0,onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&g.preventDefault()},children:s?.ruleLabel}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"mt-[26px] flex items-center l:mt-[12px] l-xl:mt-[16px]",children:[(0,a.jsx)(n.Picture,{className:"size-[24px] l-xxl:size-[22px] md-l:size-[18px] md:size-[16px]",source:"https://cdn.shopify.com/s/files/1/0511/6346/3874/files/icon_hire_purchase.png?v=1757496783"}),(0,a.jsx)(n.Text,{html:`${(0,d.numberFormat)(e.alpc?.consumeCredits)}`,size:2,as:"p",className:"ml-[4px] text-[24px] font-bold mt-[4px] leading-none l-xxl:text-[20px] l:text-[16px] "})]}),(0,a.jsx)(n.Button,{disabled:I,variant:"primary",size:"lg",className:"mt-[8px] md:px-[8px] l:w-full",onClick:()=>{r(e),(0,c.gaTrack)({event:"ga4Event",event_name:"lp_button",member_active_status:i?.activated?"active":"not active",event_parameters:{page_group:h,position:t.title,button_name:y,info:e.alpc?.id?.toString()}})},children:y})]})]})]})}
|
|
2
2
|
//# sourceMappingURL=RedeemableItem.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/components/credits/creditsRedeemList/RedeemableItem.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Button, Text, Picture } from '@anker-in/headless-ui'\n\nimport { useMemo } from 'react'\n\nimport classNames from 'classnames'\nimport { useCreditsContext } from '../context/provider'\nimport type { RedeemableItem as RedeemableItemType } from '../type'\nimport { AlpcConsumeType, ConsumeType } from '../context/const'\nimport { numberFormat, extractVariantId } from '../context/utils'\nimport type { CreditsRedeemListCopy } from './type'\nimport { gaTrack, useHeadlessContext } from '@anker-in/lib'\nimport { NoneProductValue } from './NonProductValue'\nimport { ROUNDED_BRANDS } from '../../../constants'\n\nexport function RedeemableItem({\n copy,\n className,\n item,\n onRulesOpen,\n onRedeem,\n}: {\n copy: CreditsRedeemListCopy\n className?: string\n item: RedeemableItemType\n onRulesOpen: (rules: string[]) => void\n onRedeem: (item: RedeemableItemType) => void\n}) {\n const {\n creditInfo,\n profile,\n gtm: { pageGroup, pageHandle },\n pageCommon,\n } = useCreditsContext()\n const { brand } = useHeadlessContext()\n const isLogin = Object.keys(profile || {}).length > 0\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isDisabled = useMemo(() => {\n if (item.alpc?.remainingInventory <= 0 && item.alpc?.isLimited) {\n // \u6709\u5E93\u5B58\u9650\u5236\n return true\n }\n\n if (item.alpc?.consumeType === AlpcConsumeType.Product) {\n if (!item.variant?.availableForSale) {\n return true\n }\n }\n if (isLogin && profile?.activated && item.alpc?.consumeCredits > Number(creditInfo?.available_credit || 0)) {\n return true\n }\n return false\n }, [\n item.alpc?.remainingInventory,\n item.alpc?.isLimited,\n item.alpc?.consumeType,\n item.alpc?.consumeCredits,\n isLogin,\n profile?.activated,\n creditInfo?.available_credit,\n item.variant?.availableForSale,\n ])\n\n const redeemButtonText = useMemo(() => {\n if (!isLogin) {\n return copy.unlockRewards\n }\n\n // \u7F3A\u8D27\u6587\u6848\n if (item.alpc?.consumeType === AlpcConsumeType.Product) {\n return item.variant?.availableForSale ? copy.btnRedeem : pageCommon?.soldOut || 'Sold Out'\n }\n return copy.btnRedeem\n }, [\n isLogin,\n item.alpc?.consumeType,\n item.variant?.availableForSale,\n copy.btnRedeem,\n copy.unlockRewards,\n pageCommon?.soldOut,\n ])\n\n // \u751F\u6210\u4EA7\u54C1 listing \u9875\u9762\u94FE\u63A5\n const productUrl = useMemo(() => {\n if (item.config?.type !== ConsumeType.Product || !item.product?.handle) {\n return undefined\n }\n return extractVariantId(item.variant?.id)\n ? `/products/${item.product.handle}?variant=${extractVariantId(item.variant?.id)}${pageHandle ? `&ref=${pageHandle}` : ''}`\n : `/products/${item.product.handle}${pageHandle ? `?ref=${pageHandle}` : ''}`\n }, [item.config?.type, item.product?.handle, item.variant?.id, pageHandle])\n\n return (\n <div\n className={classNames(\n 'flex flex-col items-center rounded-[16px] bg-[#EAEAEC] p-[24px] md:rounded-[12px] md:px-[8px] xl:py-[16px] md-xl:px-[16px]',\n !rounded && 'rounded-none md:rounded-none',\n className\n )}\n >\n {item.config?.type === ConsumeType.Product ? (\n <a\n href={productUrl}\n className={classNames('relative mx-auto h-[224px] w-fit md:my-[10px] l:h-[120px] l-xxl:h-[138px]')}\n >\n <Picture\n className=\"h-full w-auto [&_img]:h-full [&_img]:object-contain\"\n source={item.config?.image?.url || item.product?.images?.[0]?.url}\n ></Picture>\n </a>\n ) : (\n <div className=\"relative mx-auto my-[30px] h-[164px] md:my-0 md:h-[66px] l-xxl:h-[138px] md-l:h-[80px]\">\n <Picture\n source={pageCommon?.imageMapping?.[item.config?.type]?.url}\n className=\"h-full [&_img]:h-full [&_img]:w-auto [&_img]:object-contain\"\n ></Picture>\n\n <NoneProductValue item={item} />\n </div>\n )}\n <div className={classNames('mt-[10px] xl:mt-[8px] flex w-full flex-1 flex-col justify-between')}>\n <Text\n html={item.config?.title || item.alpc?.title}\n title={item.config?.title || item.alpc?.title}\n size={2}\n className=\"line-clamp-2 h-[58px] text-[24px] leading-[1.2] l:h-[40px] l:text-[16px] l-xxl:h-[48px] l-xxl:text-[20px]\"\n />\n {item.config?.rules?.length > 0 && (\n <button\n type=\"button\"\n onClick={() => {\n onRulesOpen(item.config?.rules || [])\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n member_active_status: profile?.activated ? 'active' : 'not active',\n event_parameters: {\n page_group: pageGroup,\n position: copy.title,\n button_name: pageCommon?.ruleLabel,\n info: item.alpc?.id?.toString(),\n },\n })\n }}\n className=\"mt-[8px] w-fit text-[16px] font-bold underline md:text-[14px] l:mt-0\"\n tabIndex={0}\n onKeyDown={e => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault()\n }\n }}\n >\n {pageCommon?.ruleLabel}\n </button>\n )}\n <div>\n <div className=\"mt-[26px] flex items-center l:mt-[12px] l-xl:mt-[16px]\">\n <Picture\n className=\"size-[24px] l-xxl:size-[22px] md-l:size-[18px] md:size-[16px]\"\n source=\"https://cdn.shopify.com/s/files/1/0511/6346/3874/files/icon_hire_purchase.png?v=1757496783\"\n />\n <Text\n html={`${numberFormat(item.alpc?.consumeCredits)}`}\n size={2}\n as=\"p\"\n className=\"ml-[4px] text-[24px] font-bold mt-[4px] leading-none l-xxl:text-[20px] l:text-[16px] \"\n />\n </div>\n\n <Button\n disabled={isDisabled}\n variant=\"primary\"\n size=\"lg\"\n className=\"mt-[8px] md:px-[8px] l:w-full\"\n onClick={() => {\n onRedeem(item)\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n member_active_status: profile?.activated ? 'active' : 'not active',\n event_parameters: {\n page_group: pageGroup,\n position: copy.title,\n button_name: redeemButtonText,\n info: item.alpc?.id?.toString(),\n },\n })\n }}\n >\n {redeemButtonText}\n </Button>\n </div>\n </div>\n </div>\n )\n}\n"],
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,IAAA,eAAAC,EAAAH,
|
|
4
|
+
"sourcesContent": ["import { Button, Text, Picture } from '@anker-in/headless-ui'\n\nimport { useMemo } from 'react'\n\nimport classNames from 'classnames'\nimport { useCreditsContext } from '../context/provider'\nimport type { RedeemableItem as RedeemableItemType } from '../type'\nimport { AlpcConsumeType, ConsumeType } from '../context/const'\nimport { numberFormat, extractVariantId } from '../context/utils'\nimport type { CreditsRedeemListCopy } from './type'\nimport { gaTrack, useHeadlessContext } from '@anker-in/lib'\nimport { NoneProductValue } from './NonProductValue'\nimport { ROUNDED_BRANDS } from '../../../constants'\n\nexport function RedeemableItem({\n copy,\n className,\n item,\n onRulesOpen,\n onRedeem,\n}: {\n copy: CreditsRedeemListCopy\n className?: string\n item: RedeemableItemType\n onRulesOpen: (rules: string[]) => void\n onRedeem: (item: RedeemableItemType) => void\n}) {\n const {\n creditInfo,\n profile,\n gtm: { pageGroup, pageHandle },\n pageCommon,\n } = useCreditsContext()\n const { brand } = useHeadlessContext()\n const isLogin = Object.keys(profile || {}).length > 0\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isDisabled = useMemo(() => {\n if (item.hasRedeemed) {\n return true\n }\n\n if (item.alpc?.remainingInventory <= 0 && item.alpc?.isLimited) {\n // \u6709\u5E93\u5B58\u9650\u5236\n return true\n }\n\n if (item.alpc?.consumeType === AlpcConsumeType.Product) {\n if (!item.variant?.availableForSale) {\n return true\n }\n }\n if (isLogin && profile?.activated && item.alpc?.consumeCredits > Number(creditInfo?.available_credit || 0)) {\n return true\n }\n return false\n }, [\n item.hasRedeemed,\n item.alpc?.remainingInventory,\n item.alpc?.isLimited,\n item.alpc?.consumeType,\n item.alpc?.consumeCredits,\n isLogin,\n profile?.activated,\n creditInfo?.available_credit,\n item.variant?.availableForSale,\n ])\n\n const redeemButtonText = useMemo(() => {\n if (!isLogin) {\n return copy.unlockRewards\n }\n\n // \u7F3A\u8D27\u6587\u6848\n if (item.alpc?.consumeType === AlpcConsumeType.Product) {\n return item.variant?.availableForSale ? copy.btnRedeem : pageCommon?.soldOut || 'Sold Out'\n }\n return copy.btnRedeem\n }, [\n isLogin,\n item.alpc?.consumeType,\n item.variant?.availableForSale,\n copy.btnRedeem,\n copy.unlockRewards,\n pageCommon?.soldOut,\n ])\n\n // \u751F\u6210\u4EA7\u54C1 listing \u9875\u9762\u94FE\u63A5\n const productUrl = useMemo(() => {\n if (item.config?.type !== ConsumeType.Product || !item.product?.handle) {\n return undefined\n }\n return extractVariantId(item.variant?.id)\n ? `/products/${item.product.handle}?variant=${extractVariantId(item.variant?.id)}${pageHandle ? `&ref=${pageHandle}` : ''}`\n : `/products/${item.product.handle}${pageHandle ? `?ref=${pageHandle}` : ''}`\n }, [item.config?.type, item.product?.handle, item.variant?.id, pageHandle])\n\n return (\n <div\n className={classNames(\n 'flex flex-col items-center rounded-[16px] bg-[#EAEAEC] p-[24px] md:rounded-[12px] md:px-[8px] xl:py-[16px] md-xl:px-[16px]',\n !rounded && 'rounded-none md:rounded-none',\n className\n )}\n >\n {item.config?.type === ConsumeType.Product ? (\n <a\n href={productUrl}\n className={classNames('relative mx-auto h-[224px] w-fit md:my-[10px] l:h-[120px] l-xxl:h-[138px]')}\n >\n <Picture\n className=\"h-full w-auto [&_img]:h-full [&_img]:object-contain\"\n source={item.config?.image?.url || item.product?.images?.[0]?.url}\n ></Picture>\n </a>\n ) : (\n <div className=\"relative mx-auto my-[30px] h-[164px] md:my-0 md:h-[66px] l-xxl:h-[138px] md-l:h-[80px]\">\n <Picture\n source={pageCommon?.imageMapping?.[item.config?.type]?.url}\n className=\"h-full [&_img]:h-full [&_img]:w-auto [&_img]:object-contain\"\n ></Picture>\n\n <NoneProductValue item={item} />\n </div>\n )}\n <div className={classNames('mt-[10px] xl:mt-[8px] flex w-full flex-1 flex-col justify-between')}>\n <Text\n html={item.config?.title || item.alpc?.title}\n title={item.config?.title || item.alpc?.title}\n size={2}\n className=\"line-clamp-2 h-[58px] text-[24px] leading-[1.2] l:h-[40px] l:text-[16px] l-xxl:h-[48px] l-xxl:text-[20px]\"\n />\n {item.config?.rules?.length > 0 && (\n <button\n type=\"button\"\n onClick={() => {\n onRulesOpen(item.config?.rules || [])\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n member_active_status: profile?.activated ? 'active' : 'not active',\n event_parameters: {\n page_group: pageGroup,\n position: copy.title,\n button_name: pageCommon?.ruleLabel,\n info: item.alpc?.id?.toString(),\n },\n })\n }}\n className=\"mt-[8px] w-fit text-[16px] font-bold underline md:text-[14px] l:mt-0\"\n tabIndex={0}\n onKeyDown={e => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault()\n }\n }}\n >\n {pageCommon?.ruleLabel}\n </button>\n )}\n <div>\n <div className=\"mt-[26px] flex items-center l:mt-[12px] l-xl:mt-[16px]\">\n <Picture\n className=\"size-[24px] l-xxl:size-[22px] md-l:size-[18px] md:size-[16px]\"\n source=\"https://cdn.shopify.com/s/files/1/0511/6346/3874/files/icon_hire_purchase.png?v=1757496783\"\n />\n <Text\n html={`${numberFormat(item.alpc?.consumeCredits)}`}\n size={2}\n as=\"p\"\n className=\"ml-[4px] text-[24px] font-bold mt-[4px] leading-none l-xxl:text-[20px] l:text-[16px] \"\n />\n </div>\n\n <Button\n disabled={isDisabled}\n variant=\"primary\"\n size=\"lg\"\n className=\"mt-[8px] md:px-[8px] l:w-full\"\n onClick={() => {\n onRedeem(item)\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n member_active_status: profile?.activated ? 'active' : 'not active',\n event_parameters: {\n page_group: pageGroup,\n position: copy.title,\n button_name: redeemButtonText,\n info: item.alpc?.id?.toString(),\n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AAY,SAAW,aACtD,iBAAkB,CAChB,WAAYC,EACZ,SAAUP,EAAK,MACf,YAAaS,GAAY,UACzB,KAAMP,EAAK,MAAM,IAAI,SAAS,CAChC,CACF,CAAC,CACH,EACA,UAAU,uEACV,SAAU,EACV,UAAWe,GAAK,EACVA,EAAE,MAAQ,SAAWA,EAAE,MAAQ,MACjCA,EAAE,eAAe,CAErB,EAEC,SAAAR,GAAY,UACf,KAEF,QAAC,OACC,qBAAC,OAAI,UAAU,yDACb,oBAAC,WACC,UAAU,gEACV,OAAO,6FACT,KACA,OAAC,QACC,KAAM,MAAG,gBAAaP,EAAK,MAAM,cAAc,CAAC,GAChD,KAAM,EACN,GAAG,IACH,UAAU,wFACZ,GACF,KAEA,OAAC,UACC,SAAUW,EACV,QAAQ,UACR,KAAK,KACL,UAAU,gCACV,QAAS,IAAM,CACbT,EAASF,CAAI,KACb,WAAQ,CACN,MAAO,WACP,WAAY,YACZ,qBAAsBI,GAAS,UAAY,SAAW,aACtD,iBAAkB,CAChB,WAAYC,EACZ,SAAUP,EAAK,MACf,YAAac,EACb,KAAMZ,EAAK,MAAM,IAAI,SAAS,CAChC,CACF,CAAC,CACH,EAEC,SAAAY,EACH,GACF,GACF,GACF,CAEJ",
|
|
6
6
|
"names": ["RedeemableItem_exports", "__export", "RedeemableItem", "__toCommonJS", "import_jsx_runtime", "import_headless_ui", "import_react", "import_classnames", "import_provider", "import_const", "import_utils", "import_lib", "import_NonProductValue", "import_constants", "copy", "className", "item", "onRulesOpen", "onRedeem", "creditInfo", "profile", "pageGroup", "pageHandle", "pageCommon", "brand", "isLogin", "rounded", "isDisabled", "redeemButtonText", "productUrl", "classNames", "e"]
|
|
7
7
|
}
|
|
@@ -30,6 +30,7 @@ export type RedeemableItem = {
|
|
|
30
30
|
};
|
|
31
31
|
product?: Product;
|
|
32
32
|
variant?: ProductVariant;
|
|
33
|
+
hasRedeemed?: boolean;
|
|
33
34
|
};
|
|
34
35
|
export interface ShippingCountry {
|
|
35
36
|
id: string;
|
|
@@ -110,6 +111,7 @@ export type CreditsPageCommon = {
|
|
|
110
111
|
infoIcon?: string;
|
|
111
112
|
ruleLabel?: string;
|
|
112
113
|
soldOut?: string;
|
|
114
|
+
redeemed?: string;
|
|
113
115
|
copied?: string;
|
|
114
116
|
off?: string;
|
|
115
117
|
copy?: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var c=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of g(t))!a.call(e,r)&&r!==n&&s(e,r,{get:()=>t[r],enumerable:!(i=o(t,r))||i.enumerable});return e};var l=e=>c(s({},"__esModule",{value:!0}),e);var p={};module.exports=l(p);
|
|
2
2
|
//# sourceMappingURL=type.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/credits/type.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Product, ProductVariant } from '@anker-in/lib'\nimport type { AlpcConsumeType, ConsumeType } from './context/const'\nimport { MyActivitiesMetafields } from './modal/ActivitiesModal'\nimport { RewardsCopy } from './modal/RewardsModal'\n\nexport interface Subscription {\n preference: {\n subscribe: boolean\n brand: string\n }[]\n}\n\nexport type RedeemableItem = {\n config: {\n title: string\n desc: string\n rules: string[]\n image: {\n url: string\n }\n type: ConsumeType\n value: string\n }\n alpc: {\n id: string\n consumeCredits: number\n remainingInventory: number\n isLimited: boolean\n consumeType: AlpcConsumeType\n showCredit: boolean\n title: string\n }\n product?: Product\n variant?: ProductVariant\n}\n\nexport interface ShippingCountry {\n id: string\n name: string\n code: string\n provinces: {\n id: string\n name: string\n code: string\n }[]\n}\n\nexport interface ShippingZone {\n name: string\n countries: ShippingCountry[]\n}\n\nexport type RedeemModalCommon = {\n confirmTitle: string\n confirmButton: string\n commonError: string\n redeemLimitError: string\n inventoryNotEnough: string\n creditsNotEnough: string\n crossSiteError: string\n errorImageUrl: string\n coupon: {\n successDesc: string\n successTitle: string\n successButton: string\n successButtonUrl: string\n }\n virtualProduct: {\n successDesc: string\n successTitle: string\n successButton: string\n successButtonUrl: string\n stepTitle?: string\n steps?: {\n imageUrl: string\n title: string\n }[]\n }\n product: {\n required: string\n invalidEmail: string\n shippingAddress: string\n shippingProduct: string\n addressForm: {\n key: string\n type: string\n label: string\n isSelect: boolean\n required: boolean\n placeholder: string\n }[][]\n form: {\n key: string\n type: string\n isSelect: boolean\n required: boolean\n placeholder: string\n }[][]\n successDesc: string[]\n rules: string[]\n steps: {\n imageUrl: string\n title: string\n }[]\n quantityLabel: string\n totalPriceLabel: string\n variantLabel: string\n shippingFeeLabel: string\n paymentButton: string\n stepTitle: string\n }\n}\n\nexport type CreditsPageCommon = {\n pointUnit?: string\n infoIcon?: string\n ruleLabel?: string\n soldOut?: string\n copied?: string\n off?: string\n copy?: string\n giftCardLabel?: string\n goGiftLabel?: string\n imageMapping?: {\n [key in ConsumeType]: {\n url: string\n }\n }\n activitiesModal?: MyActivitiesMetafields\n rewardsModal?: RewardsCopy\n redeemModal?: RedeemModalCommon\n insufficientCredits?: string\n validatorInfo?: {\n addressInfo: {\n name: string\n country: string\n province: string\n city: string\n address: string\n }\n }\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { Product, ProductVariant } from '@anker-in/lib'\nimport type { AlpcConsumeType, ConsumeType } from './context/const'\nimport { MyActivitiesMetafields } from './modal/ActivitiesModal'\nimport { RewardsCopy } from './modal/RewardsModal'\n\nexport interface Subscription {\n preference: {\n subscribe: boolean\n brand: string\n }[]\n}\n\nexport type RedeemableItem = {\n config: {\n title: string\n desc: string\n rules: string[]\n image: {\n url: string\n }\n type: ConsumeType\n value: string\n }\n alpc: {\n id: string\n consumeCredits: number\n remainingInventory: number\n isLimited: boolean\n consumeType: AlpcConsumeType\n showCredit: boolean\n title: string\n }\n product?: Product\n variant?: ProductVariant\n hasRedeemed?: boolean\n}\n\nexport interface ShippingCountry {\n id: string\n name: string\n code: string\n provinces: {\n id: string\n name: string\n code: string\n }[]\n}\n\nexport interface ShippingZone {\n name: string\n countries: ShippingCountry[]\n}\n\nexport type RedeemModalCommon = {\n confirmTitle: string\n confirmButton: string\n commonError: string\n redeemLimitError: string\n inventoryNotEnough: string\n creditsNotEnough: string\n crossSiteError: string\n errorImageUrl: string\n coupon: {\n successDesc: string\n successTitle: string\n successButton: string\n successButtonUrl: string\n }\n virtualProduct: {\n successDesc: string\n successTitle: string\n successButton: string\n successButtonUrl: string\n stepTitle?: string\n steps?: {\n imageUrl: string\n title: string\n }[]\n }\n product: {\n required: string\n invalidEmail: string\n shippingAddress: string\n shippingProduct: string\n addressForm: {\n key: string\n type: string\n label: string\n isSelect: boolean\n required: boolean\n placeholder: string\n }[][]\n form: {\n key: string\n type: string\n isSelect: boolean\n required: boolean\n placeholder: string\n }[][]\n successDesc: string[]\n rules: string[]\n steps: {\n imageUrl: string\n title: string\n }[]\n quantityLabel: string\n totalPriceLabel: string\n variantLabel: string\n shippingFeeLabel: string\n paymentButton: string\n stepTitle: string\n }\n}\n\nexport type CreditsPageCommon = {\n pointUnit?: string\n infoIcon?: string\n ruleLabel?: string\n soldOut?: string\n redeemed?: string\n copied?: string\n off?: string\n copy?: string\n giftCardLabel?: string\n goGiftLabel?: string\n imageMapping?: {\n [key in ConsumeType]: {\n url: string\n }\n }\n activitiesModal?: MyActivitiesMetafields\n rewardsModal?: RewardsCopy\n redeemModal?: RedeemModalCommon\n insufficientCredits?: string\n validatorInfo?: {\n addressInfo: {\n name: string\n country: string\n province: string\n city: string\n address: string\n }\n }\n}\n"],
|
|
5
5
|
"mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
|
|
6
6
|
"names": ["type_exports", "__toCommonJS"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useCallback as
|
|
1
|
+
import{useCallback as R,useEffect as C,useState as d}from"react";import{ALPC_COUNTRY_MAP as b,AlpcConsumeType as A}from"../const";import{useAlpcMutation as M}from"./useAlpcFetch";import{useCreditsContext as w}from"../provider";import{useHeadlessContext as L}from"@anker-in/lib";function T({page:o,pageSize:s,consumeType:r}){const{profile:e,alpcBrand:i}=w(),{brand:c,locale:n,appName:l}=L(),g=i||c,[a,_]=d([]),[u,f]=d(0),{isMutating:p,trigger:y}=M({url:"/v1/credit/log/coupon",initData:{brand:g,country:b.get(n)||n,app_name:l}}),t=R(async()=>{e?.user_id&&await y({consume_type:r||A.Coupon,page:o,page_size:s,user_id:e?.user_id},{onSuccess(m){f(m?.data?.total),_(m?.data?.redeem_logs||[])}})},[r,o,s,e?.user_id]);return C(()=>{t()},[t]),{myRewards:a,isLoading:p,total:u,getMyRewards:t,canNext:u>a.length&&!p}}var P=T;export{P as default};
|
|
2
2
|
//# sourceMappingURL=useMyRewards.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useMyRewards.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { ALPC_COUNTRY_MAP, AlpcConsumeType } from '../const'\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { RedeemLogResponse } from '../response'\nimport { useCreditsContext } from '../provider'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useMyRewards({\n page,\n pageSize,\n consumeType,\n}: {\n page: number\n pageSize: number\n consumeType?: AlpcConsumeType\n}) {\n const { profile, alpcBrand } = useCreditsContext()\n const { brand: headlessBrand, locale, appName } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n\n const [myRewards, setMyRewards] = useState<RedeemLogResponse[]>([])\n const [total, setTotal] = useState(0)\n\n const { isMutating: isLoading, trigger } = useAlpcMutation<\n { data: { redeem_logs: RedeemLogResponse[]; total: number } },\n {\n page: number\n page_size: number\n consume_type: AlpcConsumeType\n user_id: string\n }\n >({\n url: `/v1/credit/log/coupon`,\n initData: {\n brand: brand,\n country: ALPC_COUNTRY_MAP.get(locale) || locale,\n app_name: appName,\n },\n })\n\n const getMyRewards = useCallback(async () => {\n if (!profile?.user_id) {\n return\n }\n await trigger(\n {\n consume_type: consumeType || AlpcConsumeType.Coupon,\n page,\n page_size: pageSize,\n user_id: profile?.user_id,\n },\n {\n onSuccess(responseData) {\n setMyRewards(responseData?.data?.redeem_logs || [])\n },\n }\n )\n }, [consumeType, page, pageSize, profile?.user_id])\n\n useEffect(() => {\n getMyRewards()\n }, [getMyRewards])\n\n return {\n myRewards,\n isLoading,\n total,\n getMyRewards,\n canNext: total > myRewards.length && !isLoading,\n }\n}\n\nexport default useMyRewards\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QAEjD,OAAS,oBAAAC,EAAkB,mBAAAC,MAAuB,WAClD,OAAS,mBAAAC,MAAuB,iBAEhC,OAAS,qBAAAC,MAAyB,cAClC,OAAS,sBAAAC,MAA0B,gBAEnC,SAASC,EAAa,CACpB,KAAAC,EACA,SAAAC,EACA,YAAAC,CACF,EAIG,CACD,KAAM,CAAG,QAAAC,EAAS,UAAAC,CAAU,EAAIP,EAAkB,EAC5C,CAAE,MAAOQ,EAAe,OAAAC,EAAQ,QAAAC,CAAQ,EAAIT,EAAmB,EAC/DU,EAAQJ,GAAaC,EAErB,CAACI,EAAWC,CAAY,EAAIjB,EAA8B,CAAC,CAAC,EAC5D,CAACkB,EAAOC,CAAQ,EAAInB,EAAS,CAAC,EAE9B,CAAE,WAAYoB,EAAW,QAAAC,CAAQ,EAAIlB,EAQzC,CACA,IAAK,wBACL,SAAU,CACR,MAAOY,EACP,QAASd,EAAiB,IAAIY,CAAM,GAAKA,EACzC,SAAUC,CACZ,CACF,CAAC,EAEKQ,EAAexB,EAAY,SAAY,CACtCY,GAAS,SAGd,MAAMW,EACJ,CACE,aAAcZ,GAAeP,EAAgB,OAC7C,KAAAK,EACA,UAAWC,EACX,QAASE,GAAS,OACpB,EACA,CACE,UAAUa,EAAc,
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { ALPC_COUNTRY_MAP, AlpcConsumeType } from '../const'\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { RedeemLogResponse } from '../response'\nimport { useCreditsContext } from '../provider'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useMyRewards({\n page,\n pageSize,\n consumeType,\n}: {\n page: number\n pageSize: number\n consumeType?: AlpcConsumeType\n}) {\n const { profile, alpcBrand } = useCreditsContext()\n const { brand: headlessBrand, locale, appName } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n\n const [myRewards, setMyRewards] = useState<RedeemLogResponse[]>([])\n const [total, setTotal] = useState(0)\n\n const { isMutating: isLoading, trigger } = useAlpcMutation<\n { data: { redeem_logs: RedeemLogResponse[]; total: number } },\n {\n page: number\n page_size: number\n consume_type: AlpcConsumeType\n user_id: string\n }\n >({\n url: `/v1/credit/log/coupon`,\n initData: {\n brand: brand,\n country: ALPC_COUNTRY_MAP.get(locale) || locale,\n app_name: appName,\n },\n })\n\n const getMyRewards = useCallback(async () => {\n if (!profile?.user_id) {\n return\n }\n await trigger(\n {\n consume_type: consumeType || AlpcConsumeType.Coupon,\n page,\n page_size: pageSize,\n user_id: profile?.user_id,\n },\n {\n onSuccess(responseData) {\n setTotal(responseData?.data?.total)\n setMyRewards(responseData?.data?.redeem_logs || [])\n },\n }\n )\n }, [consumeType, page, pageSize, profile?.user_id])\n\n useEffect(() => {\n getMyRewards()\n }, [getMyRewards])\n\n return {\n myRewards,\n isLoading,\n total,\n getMyRewards,\n canNext: total > myRewards.length && !isLoading,\n }\n}\n\nexport default useMyRewards\n"],
|
|
5
|
+
"mappings": "AAAA,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useAlpcMutation", "useCreditsContext", "useHeadlessContext", "useMyRewards", "page", "pageSize", "consumeType", "profile", "alpcBrand", "headlessBrand", "locale", "appName", "brand", "myRewards", "setMyRewards", "total", "setTotal", "isLoading", "trigger", "getMyRewards", "responseData", "useMyRewards_default"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as r,jsxs as
|
|
1
|
+
import{jsx as r,jsxs as o}from"react/jsx-runtime";import{Container as G,Heading as H,Picture as B,Button as P,Text as u}from"@anker-in/headless-ui";import{useMemo as p,useState as v}from"react";import{classNames as f}from"@anker-in/lib";import F from"../creditsRedeemList/RedeemVirtualProductModal";import z from"../context/hooks/useRedeemableList";import{useCreditsContext as j}from"../context/provider";import{ROUNDED_BRANDS as U}from"../../../constants";import{useHeadlessContext as $}from"@anker-in/lib";import{AlpcConsumeType as D,AlpcErrorCode as x}from"../context/const";import V from"../modal/RulesModal";import{useRegistration as q}from"../../../components/registration";import J from"../context/hooks/useMyRewards";const de=({copy:e,id:I})=>{const[A,N]=v(!1),[h,n]=v(),[g,b]=v(),{redeemableList:w}=z({consumeType:D.ExternalProduct}),{pageCommon:i,profile:m,creditInfo:E,setOpenMyRewardsModal:T,openSignUpPopup:R}=j(),{authCodeActivate:d}=q(),{brand:k}=$(),c=U.includes(k),a=Object.keys(m||{}).length>0,{myRewards:S}=J({page:1,pageSize:100,consumeType:D.ExternalProduct}),_=i?.redeemModal||{},l=p(()=>{const t=w.find(s=>s.id?.toString()===e?.redeemId?.toString());return t?{alpc:{id:t.id.toString(),consumeCredits:t.consume_credits,remainingInventory:t.remaining_inventory,isLimited:!!t.is_limited,consumeType:t.consume_type,showCredit:!0,title:t.name},config:{title:e.cardTitle,desc:e.cardDesc,type:e.type,value:e.value||"",rules:e.rules,image:e.cardImg}}:null},[w,e]),y=t=>{const s=i?.redeemModal;t===x.CodeLpcShopifyCouponRuleRedeemLimit?n(s?.redeemLimitError):t===x.CodeLpcRuleInventoryNotEnough?n(s?.inventoryNotEnough):t===x.CodeLpcNotEnoughCredits?n(s?.creditsNotEnough):t===x.CodeCrossSiteError?n(s?.crossSiteError):n(s?.commonError)},L=p(()=>m?.activated&&Number(l?.alpc?.consumeCredits)>Number(E?.available_credit||0),[m?.activated,l?.alpc?.consumeCredits,E?.available_credit]),O=p(()=>!a||!l?.alpc?.id?!1:S.some(t=>t.rule_id===Number(l.alpc.id)),[a,l?.alpc?.id,S]),C=Number(l?.alpc.remainingInventory)<=0,M=p(()=>C?i?.soldOut||"Sold Out":a?e.redeemBtn:e.unlockRewards,[a,C,e,i]);return l?o(G,{id:I,children:[r(H,{as:"h2",size:"4",html:e.title}),o("div",{className:f("mt-[24px] flex h-fit w-full items-center bg-[#eaeaec] p-[24px]","l:flex-col l:gap-[12px] l:p-[12px]","min-l:flex-row min-l:gap-[64px]",!c&&"rounded-none",c&&"rounded-[12px]"),children:[r("div",{className:"relative flex h-[200px] w-[304px] shrink-0 items-center justify-center overflow-hidden l:h-auto l:aspect-h-[120] l:aspect-w-[304] l:w-full",children:e.cardImg?.url&&r(B,{className:f("size-full",c&&"rounded-[12px]"),source:e.mCardImg?.url?`${e.cardImg.url},${e.mCardImg.url} 1024`:e.cardImg.url})}),o("div",{className:"flex w-full items-end justify-between l:flex-col l:items-start l:gap-[24px]",children:[o("div",{className:"flex flex-col gap-[20px] l:w-full l:gap-[12px]",children:[o("div",{className:"flex flex-col gap-[4px]",children:[r(u,{html:e.cardTitle,className:"text-[32px] font-bold leading-[1.2] text-[#1D1D1F] l:text-[18px]"}),r(u,{html:e.cardDesc,className:"text-[18px] font-bold leading-[1.4] text-[#3D3D3F] l:text-[12px]"})]}),r(u,{html:e.cardTip,className:"text-[18px] font-bold leading-[1.4] text-[#000] l:text-[12px]"})]}),o("div",{className:"flex shrink-0 flex-col items-end l:w-full l:items-start",children:[r(P,{variant:"primary",disabled:L||C||O,onClick:()=>{a?!m?.activated&&!d.isActivateSuccess?(d.setAutoSendEmail(!0),d.open()):N(!0):R()},title:L?i.insufficientCredits:M,children:M}),h&&r("div",{className:"mt-[8px] text-[14px] font-bold leading-[1.2] text-[#FFC24D] l:text-[12px]",children:h}),(e.viewRedeemHistory||e.rulesLink)&&o("div",{className:"mt-[18px] flex gap-[16px] text-[18px] font-bold leading-[1.4] l:mt-[12px] l:gap-0 l:text-[14px]",children:[e.viewRedeemHistory&&r(u,{html:e.viewRedeemHistory,className:"cursor-pointer text-[#4794EC] font-bold underline",onClick:()=>{a?!m?.activated&&!d.isActivateSuccess?(d.setAutoSendEmail(!0),d.open()):T(!0):R()}}),i.ruleLabel&&r(u,{html:i.ruleLabel,className:f("cursor-pointer text-[#4794EC] font-bold underline",e.viewRedeemHistory&&"l:ml-[16px]"),onClick:()=>b(e.rules)})]})]})]})]}),A&&l&&r(F,{copy:_,onClose:()=>{N(!1),n(void 0)},item:l,onError:y}),g&&r(V,{overlayClassName:"md:px-[16px] md:items-center",className:f("md:h-fit md:rounded-b-[16px]",!c&&"md:rounded-none"),isOpen:g.length>0,onClose:()=>b(void 0),titleClassName:"border-b-transparent h-[56px]",rules:g,scrollClassName:"md:mt-[8px] mt-[8px] md:mb-[24px] md:pt-0",title:i?.ruleLabel,ruleClassName:"text-[#1d1d1f] font-bold"})]}):null};export{de as CreditsGoGift};
|
|
2
2
|
//# sourceMappingURL=CreditsGoGift.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/components/credits/creditsGoGift/CreditsGoGift.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Container, Heading, Picture, Button, Text } from '@anker-in/headless-ui'\nimport { useMemo, useState } from 'react'\nimport { classNames as cn } from '@anker-in/lib'\n\nimport RedeemVirtualProductModal from '../creditsRedeemList/RedeemVirtualProductModal'\nimport useRedeemableList from '../context/hooks/useRedeemableList'\nimport { useCreditsContext } from '../context/provider'\nimport { ROUNDED_BRANDS } from '../../../constants'\nimport { useHeadlessContext } from '@anker-in/lib'\nimport { CreditsGoGiftCopy } from './type'\nimport { AlpcConsumeType, AlpcErrorCode } from '../context/const'\nimport RulesModal from '../modal/RulesModal'\nimport { useRegistration } from '../../../components/registration'\n\nexport const CreditsGoGift = ({ copy, id }: { copy: CreditsGoGiftCopy; id?: string }) => {\n const [showModal, setShowModal] = useState(false)\n const [redeemError, setRedeemError] = useState<string>()\n const [rules, setRules] = useState<string | string[]>()\n const { redeemableList } = useRedeemableList({ consumeType: AlpcConsumeType.ExternalProduct })\n const { pageCommon, profile, creditInfo, setOpenMyRewardsModal, openSignUpPopup } = useCreditsContext()\n const { authCodeActivate } = useRegistration()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isLogin = Object.keys(profile || {}).length > 0\n\n const redeemModalCopy = pageCommon?.redeemModal || ({} as any)\n\n
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["jsx", "jsxs", "Container", "Heading", "Picture", "Button", "Text", "useMemo", "useState", "cn", "RedeemVirtualProductModal", "useRedeemableList", "useCreditsContext", "ROUNDED_BRANDS", "useHeadlessContext", "AlpcConsumeType", "AlpcErrorCode", "RulesModal", "useRegistration", "CreditsGoGift", "copy", "id", "showModal", "setShowModal", "redeemError", "setRedeemError", "rules", "setRules", "redeemableList", "pageCommon", "profile", "creditInfo", "setOpenMyRewardsModal", "openSignUpPopup", "authCodeActivate", "brand", "rounded", "isLogin", "redeemModalCopy", "item", "alpcData", "handleRedeemError", "code", "inSufficientCredit", "soldOut", "redeemButtonText"]
|
|
4
|
+
"sourcesContent": ["import { Container, Heading, Picture, Button, Text } from '@anker-in/headless-ui'\nimport { useMemo, useState } from 'react'\nimport { classNames as cn } from '@anker-in/lib'\n\nimport RedeemVirtualProductModal from '../creditsRedeemList/RedeemVirtualProductModal'\nimport useRedeemableList from '../context/hooks/useRedeemableList'\nimport { useCreditsContext } from '../context/provider'\nimport { ROUNDED_BRANDS } from '../../../constants'\nimport { useHeadlessContext } from '@anker-in/lib'\nimport { CreditsGoGiftCopy } from './type'\nimport { AlpcConsumeType, AlpcErrorCode } from '../context/const'\nimport RulesModal from '../modal/RulesModal'\nimport { useRegistration } from '../../../components/registration'\nimport useMyRewards from '../context/hooks/useMyRewards'\n\nexport const CreditsGoGift = ({ copy, id }: { copy: CreditsGoGiftCopy; id?: string }) => {\n const [showModal, setShowModal] = useState(false)\n const [redeemError, setRedeemError] = useState<string>()\n const [rules, setRules] = useState<string | string[]>()\n const { redeemableList } = useRedeemableList({ consumeType: AlpcConsumeType.ExternalProduct })\n const { pageCommon, profile, creditInfo, setOpenMyRewardsModal, openSignUpPopup } = useCreditsContext()\n const { authCodeActivate } = useRegistration()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isLogin = Object.keys(profile || {}).length > 0\n\n // \u83B7\u53D6\u7528\u6237\u7684 ExternalProduct \u5151\u6362\u8BB0\u5F55\n const { myRewards } = useMyRewards({\n page: 1,\n pageSize: 100,\n consumeType: AlpcConsumeType.ExternalProduct,\n })\n\n const redeemModalCopy = pageCommon?.redeemModal || ({} as any)\n\n const item = useMemo(() => {\n // \u6839\u636E redeemId \u67E5\u8BE2 ExternalProduct \u7684 ALPC \u6570\u636E\n const alpcData = redeemableList.find(item => item.id?.toString() === copy?.redeemId?.toString())\n if (!alpcData) return null\n\n return {\n alpc: {\n id: alpcData.id.toString(),\n consumeCredits: alpcData.consume_credits,\n remainingInventory: alpcData.remaining_inventory,\n isLimited: !!alpcData.is_limited,\n consumeType: alpcData.consume_type,\n showCredit: true,\n title: alpcData.name,\n },\n config: {\n title: copy.cardTitle,\n desc: copy.cardDesc,\n type: copy.type,\n value: copy.value || '',\n rules: copy.rules,\n image: copy.cardImg,\n },\n }\n }, [redeemableList, copy])\n\n const handleRedeemError = (code: AlpcErrorCode) => {\n const redeemModalCopy = pageCommon?.redeemModal\n if (code === AlpcErrorCode.CodeLpcShopifyCouponRuleRedeemLimit) {\n setRedeemError(redeemModalCopy?.redeemLimitError)\n } else if (code === AlpcErrorCode.CodeLpcRuleInventoryNotEnough) {\n setRedeemError(redeemModalCopy?.inventoryNotEnough)\n } else if (code === AlpcErrorCode.CodeLpcNotEnoughCredits) {\n setRedeemError(redeemModalCopy?.creditsNotEnough)\n } else if (code === AlpcErrorCode.CodeCrossSiteError) {\n setRedeemError(redeemModalCopy?.crossSiteError)\n } else {\n setRedeemError(redeemModalCopy?.commonError)\n }\n }\n\n const inSufficientCredit = useMemo(() => {\n return (\n profile?.activated && Number(item?.alpc?.consumeCredits) > Number(creditInfo?.available_credit || 0)\n )\n }, [profile?.activated, item?.alpc?.consumeCredits, creditInfo?.available_credit])\n\n // \u68C0\u67E5\u7528\u6237\u662F\u5426\u5DF2\u7ECF\u5151\u6362\u8FC7\u8BE5 GoGift\n const hasRedeemed = useMemo(() => {\n if (!isLogin || !item?.alpc?.id) return false\n return myRewards.some(reward => reward.rule_id === Number(item.alpc.id))\n }, [isLogin, item?.alpc?.id, myRewards])\n\n const soldOut = Number(item?.alpc.remainingInventory) <= 0\n\n const redeemButtonText = useMemo(() => {\n // \u7F3A\u8D27\u6587\u6848\n if (soldOut) {\n return pageCommon?.soldOut || 'Sold Out'\n } else if (!isLogin) {\n return copy.unlockRewards\n } else {\n return copy.redeemBtn\n }\n }, [isLogin, soldOut, copy, pageCommon])\n\n if (!item) return null\n\n return (\n <Container id={id}>\n <Heading as=\"h2\" size=\"4\" html={copy.title} />\n <div\n className={cn(\n 'mt-[24px] flex h-fit w-full items-center bg-[#eaeaec] p-[24px]',\n 'l:flex-col l:gap-[12px] l:p-[12px]',\n 'min-l:flex-row min-l:gap-[64px]',\n !rounded && 'rounded-none',\n rounded && 'rounded-[12px]'\n )}\n >\n {/* Card Image */}\n <div className=\"relative flex h-[200px] w-[304px] shrink-0 items-center justify-center overflow-hidden l:h-auto l:aspect-h-[120] l:aspect-w-[304] l:w-full\">\n {copy.cardImg?.url && (\n <Picture\n className={cn('size-full', rounded && 'rounded-[12px]')}\n source={copy.mCardImg?.url ? `${copy.cardImg.url},${copy.mCardImg.url} 1024` : copy.cardImg.url}\n />\n )}\n </div>\n\n {/* Content Section */}\n <div className=\"flex w-full items-end justify-between l:flex-col l:items-start l:gap-[24px]\">\n {/* Text Content */}\n <div className=\"flex flex-col gap-[20px] l:w-full l:gap-[12px]\">\n <div className=\"flex flex-col gap-[4px]\">\n <Text\n html={copy.cardTitle}\n className=\"text-[32px] font-bold leading-[1.2] text-[#1D1D1F] l:text-[18px]\"\n />\n <Text\n html={copy.cardDesc}\n className=\"text-[18px] font-bold leading-[1.4] text-[#3D3D3F] l:text-[12px]\"\n />\n </div>\n <Text\n html={copy.cardTip}\n className=\"text-[18px] font-bold leading-[1.4] text-[#000] l:text-[12px]\"\n />\n </div>\n\n {/* Button and Links */}\n <div className=\"flex shrink-0 flex-col items-end l:w-full l:items-start\">\n <Button\n variant=\"primary\"\n disabled={inSufficientCredit || soldOut || hasRedeemed}\n onClick={() => {\n if (!isLogin) {\n openSignUpPopup()\n } else if (!profile?.activated && !authCodeActivate.isActivateSuccess) {\n authCodeActivate.setAutoSendEmail(true)\n authCodeActivate.open()\n } else {\n setShowModal(true)\n }\n }}\n title={inSufficientCredit ? pageCommon.insufficientCredits : redeemButtonText}\n >\n {redeemButtonText}\n </Button>\n {redeemError && (\n <div className=\"mt-[8px] text-[14px] font-bold leading-[1.2] text-[#FFC24D] l:text-[12px]\">\n {redeemError}\n </div>\n )}\n {(copy.viewRedeemHistory || copy.rulesLink) && (\n <div className=\"mt-[18px] flex gap-[16px] text-[18px] font-bold leading-[1.4] l:mt-[12px] l:gap-0 l:text-[14px]\">\n {copy.viewRedeemHistory && (\n <Text\n html={copy.viewRedeemHistory}\n className=\"cursor-pointer text-[#4794EC] font-bold underline\"\n onClick={() => {\n if (!isLogin) {\n openSignUpPopup()\n } else if (!profile?.activated && !authCodeActivate.isActivateSuccess) {\n authCodeActivate.setAutoSendEmail(true)\n authCodeActivate.open()\n } else {\n setOpenMyRewardsModal(true)\n }\n }}\n />\n )}\n {pageCommon.ruleLabel && (\n <Text\n html={pageCommon.ruleLabel}\n className={cn(\n 'cursor-pointer text-[#4794EC] font-bold underline',\n copy.viewRedeemHistory && 'l:ml-[16px]'\n )}\n onClick={() => setRules(copy.rules)}\n />\n )}\n </div>\n )}\n </div>\n </div>\n </div>\n\n {showModal && item && (\n <RedeemVirtualProductModal\n copy={redeemModalCopy}\n onClose={() => {\n setShowModal(false)\n setRedeemError(undefined)\n }}\n item={item}\n onError={handleRedeemError}\n />\n )}\n\n {rules && (\n <RulesModal\n overlayClassName=\"md:px-[16px] md:items-center\"\n className={cn('md:h-fit md:rounded-b-[16px]', !rounded && 'md:rounded-none')}\n isOpen={rules.length > 0}\n onClose={() => setRules(undefined)}\n titleClassName=\"border-b-transparent h-[56px]\"\n rules={rules}\n scrollClassName=\"md:mt-[8px] mt-[8px] md:mb-[24px] md:pt-0\"\n title={pageCommon?.ruleLabel}\n ruleClassName=\"text-[#1d1d1f] font-bold\"\n />\n )}\n </Container>\n )\n}\n"],
|
|
5
|
+
"mappings": "AA0GM,cAAAA,EAwBM,QAAAC,MAxBN,oBA1GN,OAAS,aAAAC,EAAW,WAAAC,EAAS,WAAAC,EAAS,UAAAC,EAAQ,QAAAC,MAAY,wBAC1D,OAAS,WAAAC,EAAS,YAAAC,MAAgB,QAClC,OAAS,cAAcC,MAAU,gBAEjC,OAAOC,MAA+B,iDACtC,OAAOC,MAAuB,qCAC9B,OAAS,qBAAAC,MAAyB,sBAClC,OAAS,kBAAAC,MAAsB,qBAC/B,OAAS,sBAAAC,MAA0B,gBAEnC,OAAS,mBAAAC,EAAiB,iBAAAC,MAAqB,mBAC/C,OAAOC,MAAgB,sBACvB,OAAS,mBAAAC,MAAuB,mCAChC,OAAOC,MAAkB,gCAElB,MAAMC,GAAgB,CAAC,CAAE,KAAAC,EAAM,GAAAC,CAAG,IAAgD,CACvF,KAAM,CAACC,EAAWC,CAAY,EAAIhB,EAAS,EAAK,EAC1C,CA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EAAM,OAAS,EACvB,QAAS,IAAMC,EAAS,MAAS,EACjC,eAAe,gCACf,MAAOD,EACP,gBAAgB,4CAChB,MAAOG,GAAY,UACnB,cAAc,2BAChB,GAEJ,EA/HgB,IAiIpB",
|
|
6
|
+
"names": ["jsx", "jsxs", "Container", "Heading", "Picture", "Button", "Text", "useMemo", "useState", "cn", "RedeemVirtualProductModal", "useRedeemableList", "useCreditsContext", "ROUNDED_BRANDS", "useHeadlessContext", "AlpcConsumeType", "AlpcErrorCode", "RulesModal", "useRegistration", "useMyRewards", "CreditsGoGift", "copy", "id", "showModal", "setShowModal", "redeemError", "setRedeemError", "rules", "setRules", "redeemableList", "pageCommon", "profile", "creditInfo", "setOpenMyRewardsModal", "openSignUpPopup", "authCodeActivate", "brand", "rounded", "isLogin", "myRewards", "redeemModalCopy", "item", "alpcData", "handleRedeemError", "code", "inSufficientCredit", "hasRedeemed", "reward", "soldOut", "redeemButtonText"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Fragment as
|
|
1
|
+
import{Fragment as le,jsx as o,jsxs as A}from"react/jsx-runtime";import{Container as B,Heading as U,Tabs as V,TabsList as j,TabsTrigger as q}from"@anker-in/headless-ui";import v from"classnames";import{useCallback as J,useMemo as x,useState as y}from"react";import K from"./RedeemCouponModal";import Q from"./RedeemProductModal";import W from"./RedeemVirtualProductModal";import{useCreditsContext as X}from"../context/provider";import Y from"../context/hooks/useRedeemableList";import{AlpcConsumeType as E,AlpcErrorCode as Z,ConsumeType as l}from"../context/const";import{useHeadlessContext as ee,useProductsByHandles as te,gaTrack as re,classNames as M}from"@anker-in/lib";import{RedeemableItem as oe}from"./RedeemableItem";import{ROUNDED_BRANDS as ne}from"../../../constants";import ae from"../modal/RulesModal";import{useRegistration as ie}from"../../../components/registration";import{numberFormat as se}from"../context/utils";import de from"../context/hooks/useMyRewards";const ke=({copy:t,id:P})=>{const{profile:R,openSignUpPopup:G,gtm:{pageGroup:D},pageCommon:u,creditInfo:F}=X(),{authCodeActivate:c}=ie(),{brand:h}=ee(),T=ne.includes(h),m=Object.keys(R||{}).length>0,[g,O]=y(t.list?.[0]?.label||""),[n,p]=y(void 0),[f,L]=y(),{listLoading:w,redeemableList:N,getRedeemableList:S}=Y(),{myRewards:_}=de({page:1,pageSize:100,consumeType:E.ExternalProduct}),s=x(()=>({...u?.redeemModal||{},...t.redeemModal||{}}),[t.redeemModal,u?.redeemModal]),d=x(()=>N.map(e=>({id:e.id.toString(),title:e.name,consumeCredits:e.consume_credits,remainingInventory:e.remaining_inventory,isLimited:!!e.is_limited,consumeType:e.consume_type,handle:e.sku_handle,sku:e.goods_sku,image:e.goods_url})),[t.list,g,N]),H=d.map(e=>e.handle),{data:k}=te({handles:H}),$=x(()=>(t.list?.find(r=>r.label===g)?.list||[]).filter(r=>d.some(i=>String(i.id)===String(r.id))).map(r=>{const i=d.find(a=>String(a.id)===String(r.id)),C=k?.find(a=>a.handle===i?.handle),I=C?.variants.find(a=>a.sku===i?.sku);if(i?.isLimited&&(!i?.remainingInventory||i.remainingInventory<=0)||i?.consumeType===E.Product&&(!C||!I))return null;const z=r.type===l.GoGift&&m&&_.some(a=>a.rule_id===Number(r.id));return{alpc:d.find(a=>String(a.id)===String(r.id)),config:r,product:C,variant:I,hasRedeemed:z}}).filter(r=>r!==null),[d,k,m,_]),b=J(e=>{e===Z.CodeLpcRuleInventoryNotEnough&&S()},[S]);return A(B,{id:P,className:v("relative bg-[#F5F5F7]"),children:[o(U,{as:"h2",size:"4",html:t.title}),m&&t.availableCredits&&o("p",{className:"mt-[12px] text-[20px] l-xxl:text-[18px] l:text-[16px] font-bold text-[#4A4C56]",children:t.availableCredits.includes("$credits")?A(le,{children:[t.availableCredits.split("$credits")[0],o("span",{className:M("text-brand-color-0",h==="ankersolix"&&"bg-gradient-to-r from-[#2c7ed0] via-[#00a9e1] via-[43%] to-[#00db84] bg-clip-text text-transparent"),children:se(F?.available_credit||0).toString()}),t.availableCredits.split("$credits")[1]||""]}):t.availableCredits}),o(V,{shape:T?"rounded":"square",align:"left",className:v("py-[24px] md:justify-center"),value:g.toString(),onValueChange:e=>{O(e),re({event:"ga4Event",event_name:"lp_navigation",event_parameters:{navigation:e,page_group:D}})},children:o(j,{children:(t.list||[]).map(e=>o(q,{value:e.label,children:e.label},e.label))})}),!!d?.length&&!w&&o("div",{className:v("relative grid grid-cols-4 gap-[16px] md:grid-cols-2 md:gap-[12px] md-xl:grid-cols-3"),children:$?.map(e=>o(oe,{copy:t,item:e,onRedeem:r=>{m?!R?.activated&&!c.isActivateSuccess?(c.setAutoSendEmail(!0),c.open()):p(r):G()},onRulesOpen:L},e?.alpc?.id))}),(n?.config?.type===l.Coupon||n?.config?.type===l.ShippingCoupon)&&s?.coupon&&n&&o(K,{item:n,copy:s,onError:b,onClose:()=>{p(void 0)}}),n?.config?.type===l.Product&&s?.product&&n&&o(Q,{item:n,copy:s,onError:b,onClose:()=>{p(void 0)}}),(n?.config?.type===l.GiftCard||n?.config?.type===l.GoGift)&&s?.virtualProduct&&n&&o(W,{item:n,copy:s,onError:b,onClose:()=>{p(void 0)}}),f&&o(ae,{overlayClassName:"md:px-[16px] md:items-center",className:M("md:h-fit md:rounded-b-[16px]",!T&&"md:rounded-none"),isOpen:f.length>0,onClose:()=>L([]),titleClassName:"border-b-transparent h-[56px]",rules:f,scrollClassName:"md:mt-[8px] md:mb-[24px] md:pt-0",title:u?.ruleLabel,ruleClassName:"text-[#1d1d1f] font-bold"})]})};export{ke as CreditsRedeemList};
|
|
2
2
|
//# sourceMappingURL=CreditsRedeemList.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/components/credits/creditsRedeemList/CreditsRedeemList.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Container, Heading, Tabs, TabsList, TabsTrigger } from '@anker-in/headless-ui'\nimport classNames from 'classnames'\nimport { useCallback, useMemo, useState } from 'react'\n\nimport RedeemCouponModal from './RedeemCouponModal'\nimport RedeemProductModal from './RedeemProductModal'\nimport RedeemVirtualProductModal from './RedeemVirtualProductModal'\nimport { useCreditsContext } from '../context/provider'\nimport useRedeemableList from '../context/hooks/useRedeemableList'\nimport { AlpcConsumeType, AlpcErrorCode, ConsumeType } from '../context/const'\nimport { useHeadlessContext, useProductsByHandles, gaTrack, classNames as cn } from '@anker-in/lib'\nimport type { RedeemableItem as RedeemableItemType } from '../type'\nimport { RedeemableItem } from './RedeemableItem'\nimport { ROUNDED_BRANDS } from '../../../constants'\nimport RulesModal from '../modal/RulesModal'\nimport { CreditsRedeemListCopy } from './type'\nimport { useRegistration } from '../../../components/registration'\nimport { numberFormat } from '../context/utils'\n\nexport const CreditsRedeemList = ({ copy, id }: { copy: CreditsRedeemListCopy; id?: string }) => {\n const {\n profile,\n openSignUpPopup,\n gtm: { pageGroup },\n pageCommon,\n creditInfo,\n } = useCreditsContext()\n const { authCodeActivate } = useRegistration()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isLogin = Object.keys(profile || {}).length > 0\n\n const [activeTab, setActiveTab] = useState<string>(copy.list?.[0]?.label || '')\n\n const [popRedeemData, setPopRedeemData] = useState<RedeemableItemType | undefined>(undefined)\n\n const [rules, setRules] = useState<string | string[]>()\n\n const { listLoading, redeemableList, getRedeemableList } = useRedeemableList()\n\n // \u5408\u5E76 redeemModal \u6587\u6848\uFF0C\u4F18\u5148\u4F7F\u7528 copy.redeemModal\uFF0Cfallback \u5230 pageCommon.redeemModal\n const redeemModalCopy = useMemo(() => {\n return {\n ...(pageCommon?.redeemModal || {}),\n ...(copy.redeemModal || {}),\n }\n }, [copy.redeemModal, pageCommon?.redeemModal])\n\n const alpcList = useMemo(() => {\n return redeemableList.map(item => {\n return {\n id: item.id.toString(),\n title: item.name,\n consumeCredits: item.consume_credits,\n remainingInventory: item.remaining_inventory,\n isLimited: !!item.is_limited,\n consumeType: item.consume_type,\n handle: item.sku_handle,\n sku: item.goods_sku,\n image: item.goods_url,\n }\n })\n }, [copy.list, activeTab, redeemableList])\n\n const handles = alpcList.map(item => item.handle)\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n const currentList = copy.list?.find(item => item.label === activeTab)\n return (currentList?.list || [])\n .filter(item => alpcList.some(alpcItem => String(alpcItem.id) === String(item.id)))\n .map(item => {\n const alpcItem = alpcList.find(alpcItem => String(alpcItem.id) === String(item.id))\n const product = products?.find(product => product.handle === alpcItem?.handle)\n const variant = product?.variants.find(variant => variant.sku === alpcItem?.sku)\n // \u8FC7\u6EE4\u6389\u5E93\u5B58\u4E0D\u8DB3\u7684\u5546\u54C1\n if (alpcItem?.isLimited && (!alpcItem?.remainingInventory || alpcItem.remainingInventory <= 0)) return null\n if (alpcItem?.consumeType === AlpcConsumeType.Product && (!product || !variant)) return null\n return {\n alpc: alpcList.find(alpcItem => String(alpcItem.id) === String(item.id)),\n config: item,\n product,\n variant,\n }\n })\n .filter(item => item !== null) as unknown as RedeemableItemType[]\n }, [alpcList, products])\n\n const handleRedeemError = useCallback(\n (errorCode: AlpcErrorCode) => {\n if (errorCode === AlpcErrorCode.CodeLpcRuleInventoryNotEnough) {\n getRedeemableList()\n }\n },\n [getRedeemableList]\n )\n\n return (\n <Container id={id} className={classNames('relative bg-[#F5F5F7]')}>\n <Heading as=\"h2\" size=\"4\" html={copy.title} />\n\n {/* \u53EF\u7528\u79EF\u5206\u5C55\u793A */}\n {isLogin && copy.availableCredits && (\n <p className=\"mt-[12px] text-[20px] l-xxl:text-[18px] l:text-[16px] font-bold text-[#4A4C56]\">\n {copy.availableCredits.includes('$credits') ? (\n <>\n {copy.availableCredits.split('$credits')[0]}\n <span\n className={cn(\n 'text-brand-color-0',\n brand === 'ankersolix' &&\n 'bg-gradient-to-r from-[#2c7ed0] via-[#00a9e1] via-[43%] to-[#00db84] bg-clip-text text-transparent'\n )}\n >\n {numberFormat(creditInfo?.available_credit || 0).toString()}\n </span>\n {copy.availableCredits.split('$credits')[1] || ''}\n </>\n ) : (\n copy.availableCredits\n )}\n </p>\n )}\n\n <Tabs\n shape={rounded ? 'rounded' : 'square'}\n align=\"left\"\n className={classNames('py-[24px] md:justify-center')}\n value={activeTab.toString()}\n onValueChange={value => {\n setActiveTab(value)\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_navigation',\n event_parameters: {\n navigation: value,\n page_group: pageGroup,\n },\n })\n }}\n >\n <TabsList>\n {(copy.list || []).map(item => (\n <TabsTrigger key={item.label} value={item.label}>\n {item.label}\n </TabsTrigger>\n ))}\n </TabsList>\n </Tabs>\n {/* PC\u7AEF */}\n {!!alpcList?.length && !listLoading && (\n <div\n className={classNames('relative grid grid-cols-4 gap-[16px] md:grid-cols-2 md:gap-[12px] md-xl:grid-cols-3')}\n >\n {list?.map(item => (\n <RedeemableItem\n key={item?.alpc?.id}\n copy={copy}\n item={item}\n onRedeem={(item: RedeemableItemType) => {\n if (!isLogin) {\n openSignUpPopup()\n } else if (!profile?.activated && !authCodeActivate.isActivateSuccess) {\n authCodeActivate.setAutoSendEmail(true)\n authCodeActivate.open()\n } else {\n setPopRedeemData(item)\n }\n }}\n onRulesOpen={setRules}\n />\n ))}\n </div>\n )}\n\n {(popRedeemData?.config?.type === ConsumeType.Coupon ||\n popRedeemData?.config?.type === ConsumeType.ShippingCoupon) &&\n redeemModalCopy?.coupon &&\n popRedeemData && (\n <RedeemCouponModal\n item={popRedeemData}\n copy={redeemModalCopy}\n onError={handleRedeemError}\n onClose={() => {\n setPopRedeemData(undefined)\n }}\n />\n )}\n {popRedeemData?.config?.type === ConsumeType.Product && redeemModalCopy?.product && popRedeemData && (\n <RedeemProductModal\n item={popRedeemData}\n copy={redeemModalCopy}\n onError={handleRedeemError}\n onClose={() => {\n setPopRedeemData(undefined)\n }}\n />\n )}\n {(popRedeemData?.config?.type === ConsumeType.GiftCard || popRedeemData?.config?.type === ConsumeType.GoGift) &&\n redeemModalCopy?.virtualProduct &&\n popRedeemData && (\n <RedeemVirtualProductModal\n item={popRedeemData}\n copy={redeemModalCopy}\n onError={handleRedeemError}\n onClose={() => {\n setPopRedeemData(undefined)\n }}\n />\n )}\n {rules && (\n <RulesModal\n overlayClassName=\"md:px-[16px] md:items-center\"\n className={cn('md:h-fit md:rounded-b-[16px]', !rounded && 'md:rounded-none')}\n isOpen={rules.length > 0}\n onClose={() => setRules([])}\n titleClassName=\"border-b-transparent h-[56px]\"\n rules={rules}\n scrollClassName=\"md:mt-[8px] md:mb-[24px] md:pt-0\"\n title={pageCommon?.ruleLabel}\n ruleClassName=\"text-[#1d1d1f] font-bold\"\n />\n )}\n </Container>\n )\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["Fragment", "jsx", "jsxs", "Container", "Heading", "Tabs", "TabsList", "TabsTrigger", "classNames", "useCallback", "useMemo", "useState", "RedeemCouponModal", "RedeemProductModal", "RedeemVirtualProductModal", "useCreditsContext", "useRedeemableList", "AlpcConsumeType", "AlpcErrorCode", "ConsumeType", "useHeadlessContext", "useProductsByHandles", "gaTrack", "cn", "RedeemableItem", "ROUNDED_BRANDS", "RulesModal", "useRegistration", "numberFormat", "CreditsRedeemList", "copy", "id", "profile", "openSignUpPopup", "pageGroup", "pageCommon", "creditInfo", "authCodeActivate", "brand", "rounded", "isLogin", "activeTab", "setActiveTab", "popRedeemData", "setPopRedeemData", "rules", "setRules", "listLoading", "redeemableList", "getRedeemableList", "redeemModalCopy", "alpcList", "item", "handles", "products", "list", "alpcItem", "product", "variant", "handleRedeemError", "errorCode", "value"]
|
|
4
|
+
"sourcesContent": ["import { Container, Heading, Tabs, TabsList, TabsTrigger } from '@anker-in/headless-ui'\nimport classNames from 'classnames'\nimport { useCallback, useMemo, useState } from 'react'\n\nimport RedeemCouponModal from './RedeemCouponModal'\nimport RedeemProductModal from './RedeemProductModal'\nimport RedeemVirtualProductModal from './RedeemVirtualProductModal'\nimport { useCreditsContext } from '../context/provider'\nimport useRedeemableList from '../context/hooks/useRedeemableList'\nimport { AlpcConsumeType, AlpcErrorCode, ConsumeType } from '../context/const'\nimport { useHeadlessContext, useProductsByHandles, gaTrack, classNames as cn } from '@anker-in/lib'\nimport type { RedeemableItem as RedeemableItemType } from '../type'\nimport { RedeemableItem } from './RedeemableItem'\nimport { ROUNDED_BRANDS } from '../../../constants'\nimport RulesModal from '../modal/RulesModal'\nimport { CreditsRedeemListCopy } from './type'\nimport { useRegistration } from '../../../components/registration'\nimport { numberFormat } from '../context/utils'\nimport useMyRewards from '../context/hooks/useMyRewards'\n\nexport const CreditsRedeemList = ({ copy, id }: { copy: CreditsRedeemListCopy; id?: string }) => {\n const {\n profile,\n openSignUpPopup,\n gtm: { pageGroup },\n pageCommon,\n creditInfo,\n } = useCreditsContext()\n const { authCodeActivate } = useRegistration()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isLogin = Object.keys(profile || {}).length > 0\n\n const [activeTab, setActiveTab] = useState<string>(copy.list?.[0]?.label || '')\n\n const [popRedeemData, setPopRedeemData] = useState<RedeemableItemType | undefined>(undefined)\n\n const [rules, setRules] = useState<string | string[]>()\n\n const { listLoading, redeemableList, getRedeemableList } = useRedeemableList()\n\n // \u83B7\u53D6\u7528\u6237\u7684 ExternalProduct \u5151\u6362\u8BB0\u5F55\n const { myRewards } = useMyRewards({\n page: 1,\n pageSize: 100,\n consumeType: AlpcConsumeType.ExternalProduct,\n })\n\n // \u5408\u5E76 redeemModal \u6587\u6848\uFF0C\u4F18\u5148\u4F7F\u7528 copy.redeemModal\uFF0Cfallback \u5230 pageCommon.redeemModal\n const redeemModalCopy = useMemo(() => {\n return {\n ...(pageCommon?.redeemModal || {}),\n ...(copy.redeemModal || {}),\n }\n }, [copy.redeemModal, pageCommon?.redeemModal])\n\n const alpcList = useMemo(() => {\n return redeemableList.map(item => {\n return {\n id: item.id.toString(),\n title: item.name,\n consumeCredits: item.consume_credits,\n remainingInventory: item.remaining_inventory,\n isLimited: !!item.is_limited,\n consumeType: item.consume_type,\n handle: item.sku_handle,\n sku: item.goods_sku,\n image: item.goods_url,\n }\n })\n }, [copy.list, activeTab, redeemableList])\n\n const handles = alpcList.map(item => item.handle)\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n const currentList = copy.list?.find(item => item.label === activeTab)\n return (currentList?.list || [])\n .filter(item => alpcList.some(alpcItem => String(alpcItem.id) === String(item.id)))\n .map(item => {\n const alpcItem = alpcList.find(alpcItem => String(alpcItem.id) === String(item.id))\n const product = products?.find(product => product.handle === alpcItem?.handle)\n const variant = product?.variants.find(variant => variant.sku === alpcItem?.sku)\n // \u8FC7\u6EE4\u6389\u5E93\u5B58\u4E0D\u8DB3\u7684\u5546\u54C1\n if (alpcItem?.isLimited && (!alpcItem?.remainingInventory || alpcItem.remainingInventory <= 0)) return null\n if (alpcItem?.consumeType === AlpcConsumeType.Product && (!product || !variant)) return null\n\n // \u68C0\u67E5 GoGift \u662F\u5426\u5DF2\u7ECF\u5151\u6362\u8FC7\uFF08\u53EA\u6709 GoGift \u9650\u5236\u5151\u6362\u4E00\u6B21\uFF09\n const hasRedeemed = item.type === ConsumeType.GoGift &&\n isLogin &&\n myRewards.some(reward => reward.rule_id === Number(item.id))\n\n return {\n alpc: alpcList.find(alpcItem => String(alpcItem.id) === String(item.id)),\n config: item,\n product,\n variant,\n hasRedeemed,\n }\n })\n .filter(item => item !== null) as unknown as RedeemableItemType[]\n }, [alpcList, products, isLogin, myRewards])\n\n const handleRedeemError = useCallback(\n (errorCode: AlpcErrorCode) => {\n if (errorCode === AlpcErrorCode.CodeLpcRuleInventoryNotEnough) {\n getRedeemableList()\n }\n },\n [getRedeemableList]\n )\n\n return (\n <Container id={id} className={classNames('relative bg-[#F5F5F7]')}>\n <Heading as=\"h2\" size=\"4\" html={copy.title} />\n\n {/* \u53EF\u7528\u79EF\u5206\u5C55\u793A */}\n {isLogin && copy.availableCredits && (\n <p className=\"mt-[12px] text-[20px] l-xxl:text-[18px] l:text-[16px] font-bold text-[#4A4C56]\">\n {copy.availableCredits.includes('$credits') ? (\n <>\n {copy.availableCredits.split('$credits')[0]}\n <span\n className={cn(\n 'text-brand-color-0',\n brand === 'ankersolix' &&\n 'bg-gradient-to-r from-[#2c7ed0] via-[#00a9e1] via-[43%] to-[#00db84] bg-clip-text text-transparent'\n )}\n >\n {numberFormat(creditInfo?.available_credit || 0).toString()}\n </span>\n {copy.availableCredits.split('$credits')[1] || ''}\n </>\n ) : (\n copy.availableCredits\n )}\n </p>\n )}\n\n <Tabs\n shape={rounded ? 'rounded' : 'square'}\n align=\"left\"\n className={classNames('py-[24px] md:justify-center')}\n value={activeTab.toString()}\n onValueChange={value => {\n setActiveTab(value)\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_navigation',\n event_parameters: {\n navigation: value,\n page_group: pageGroup,\n },\n })\n }}\n >\n <TabsList>\n {(copy.list || []).map(item => (\n <TabsTrigger key={item.label} value={item.label}>\n {item.label}\n </TabsTrigger>\n ))}\n </TabsList>\n </Tabs>\n {/* PC\u7AEF */}\n {!!alpcList?.length && !listLoading && (\n <div\n className={classNames('relative grid grid-cols-4 gap-[16px] md:grid-cols-2 md:gap-[12px] md-xl:grid-cols-3')}\n >\n {list?.map(item => (\n <RedeemableItem\n key={item?.alpc?.id}\n copy={copy}\n item={item}\n onRedeem={(item: RedeemableItemType) => {\n if (!isLogin) {\n openSignUpPopup()\n } else if (!profile?.activated && !authCodeActivate.isActivateSuccess) {\n authCodeActivate.setAutoSendEmail(true)\n authCodeActivate.open()\n } else {\n setPopRedeemData(item)\n }\n }}\n onRulesOpen={setRules}\n />\n ))}\n </div>\n )}\n\n {(popRedeemData?.config?.type === ConsumeType.Coupon ||\n popRedeemData?.config?.type === ConsumeType.ShippingCoupon) &&\n redeemModalCopy?.coupon &&\n popRedeemData && (\n <RedeemCouponModal\n item={popRedeemData}\n copy={redeemModalCopy}\n onError={handleRedeemError}\n onClose={() => {\n setPopRedeemData(undefined)\n }}\n />\n )}\n {popRedeemData?.config?.type === ConsumeType.Product && redeemModalCopy?.product && popRedeemData && (\n <RedeemProductModal\n item={popRedeemData}\n copy={redeemModalCopy}\n onError={handleRedeemError}\n onClose={() => {\n setPopRedeemData(undefined)\n }}\n />\n )}\n {(popRedeemData?.config?.type === ConsumeType.GiftCard || popRedeemData?.config?.type === ConsumeType.GoGift) &&\n redeemModalCopy?.virtualProduct &&\n popRedeemData && (\n <RedeemVirtualProductModal\n item={popRedeemData}\n copy={redeemModalCopy}\n onError={handleRedeemError}\n onClose={() => {\n setPopRedeemData(undefined)\n }}\n />\n )}\n {rules && (\n <RulesModal\n overlayClassName=\"md:px-[16px] md:items-center\"\n className={cn('md:h-fit md:rounded-b-[16px]', !rounded && 'md:rounded-none')}\n isOpen={rules.length > 0}\n onClose={() => setRules([])}\n titleClassName=\"border-b-transparent h-[56px]\"\n rules={rules}\n scrollClassName=\"md:mt-[8px] md:mb-[24px] md:pt-0\"\n title={pageCommon?.ruleLabel}\n ruleClassName=\"text-[#1d1d1f] font-bold\"\n />\n )}\n </Container>\n )\n}\n"],
|
|
5
|
+
"mappings": "AAmHM,OAMM,YAAAA,GANN,OAAAC,EAMM,QAAAC,MANN,oBAnHN,OAAS,aAAAC,EAAW,WAAAC,EAAS,QAAAC,EAAM,YAAAC,EAAU,eAAAC,MAAmB,wBAChE,OAAOC,MAAgB,aACvB,OAAS,eAAAC,EAAa,WAAAC,EAAS,YAAAC,MAAgB,QAE/C,OAAOC,MAAuB,sBAC9B,OAAOC,MAAwB,uBAC/B,OAAOC,MAA+B,8BACtC,OAAS,qBAAAC,MAAyB,sBAClC,OAAOC,MAAuB,qCAC9B,OAAS,mBAAAC,EAAiB,iBAAAC,EAAe,eAAAC,MAAmB,mBAC5D,OAAS,sBAAAC,GAAoB,wBAAAC,GAAsB,WAAAC,GAAS,cAAcC,MAAU,gBAEpF,OAAS,kBAAAC,OAAsB,mBAC/B,OAAS,kBAAAC,OAAsB,qBAC/B,OAAOC,OAAgB,sBAE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CyB,GAAe,QAAQ,OAASzB,EAAY,iBAC5CiC,GAAiB,QACjBR,GACE3C,EAACW,EAAA,CACC,KAAMgC,EACN,KAAMQ,EACN,QAASW,EACT,QAAS,IAAM,CACblB,EAAiB,MAAS,CAC5B,EACF,EAEHD,GAAe,QAAQ,OAASzB,EAAY,SAAWiC,GAAiB,SAAWR,GAClF3C,EAACY,EAAA,CACC,KAAM+B,EACN,KAAMQ,EACN,QAASW,EACT,QAAS,IAAM,CACblB,EAAiB,MAAS,CAC5B,EACF,GAEAD,GAAe,QAAQ,OAASzB,EAAY,UAAYyB,GAAe,QAAQ,OAASzB,EAAY,SACpGiC,GAAiB,gBACjBR,GACE3C,EAACa,EAAA,CACC,KAAM8B,EACN,KAAMQ,EACN,QAASW,EACT,QAAS,IAAM,CACblB,EAAiB,MAAS,CAC5B,EACF,EAEHC,GACC7C,EAACyB,GAAA,CACC,iBAAiB,+BACjB,UAAWH,EAAG,+BAAgC,CAACiB,GAAW,iBAAiB,EAC3E,OAAQM,EAAM,OAAS,EACvB,QAAS,IAAMC,EAAS,CAAC,CAAC,EAC1B,eAAe,gCACf,MAAOD,EACP,gBAAgB,mCAChB,MAAOV,GAAY,UACnB,cAAc,2BAChB,GAEJ,CAEJ",
|
|
6
|
+
"names": ["Fragment", "jsx", "jsxs", "Container", "Heading", "Tabs", "TabsList", "TabsTrigger", "classNames", "useCallback", "useMemo", "useState", "RedeemCouponModal", "RedeemProductModal", "RedeemVirtualProductModal", "useCreditsContext", "useRedeemableList", "AlpcConsumeType", "AlpcErrorCode", "ConsumeType", "useHeadlessContext", "useProductsByHandles", "gaTrack", "cn", "RedeemableItem", "ROUNDED_BRANDS", "RulesModal", "useRegistration", "numberFormat", "useMyRewards", "CreditsRedeemList", "copy", "id", "profile", "openSignUpPopup", "pageGroup", "pageCommon", "creditInfo", "authCodeActivate", "brand", "rounded", "isLogin", "activeTab", "setActiveTab", "popRedeemData", "setPopRedeemData", "rules", "setRules", "listLoading", "redeemableList", "getRedeemableList", "myRewards", "redeemModalCopy", "alpcList", "item", "handles", "products", "list", "alpcItem", "product", "variant", "hasRedeemed", "reward", "handleRedeemError", "errorCode", "value"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as t,jsxs as o}from"react/jsx-runtime";import{Button as I,Text as f,Picture as s}from"@anker-in/headless-ui";import{useMemo as d}from"react";import c from"classnames";import{useCreditsContext as k}from"../context/provider";import{AlpcConsumeType as v,ConsumeType as g}from"../context/const";import{numberFormat as P,extractVariantId as b}from"../context/utils";import{gaTrack as
|
|
1
|
+
import{jsx as t,jsxs as o}from"react/jsx-runtime";import{Button as I,Text as f,Picture as s}from"@anker-in/headless-ui";import{useMemo as d}from"react";import c from"classnames";import{useCreditsContext as k}from"../context/provider";import{AlpcConsumeType as v,ConsumeType as g}from"../context/const";import{numberFormat as P,extractVariantId as b}from"../context/utils";import{gaTrack as h,useHeadlessContext as S}from"@anker-in/lib";import{NoneProductValue as $}from"./NonProductValue";import{ROUNDED_BRANDS as z}from"../../../constants";function M({copy:a,className:y,item:e,onRulesOpen:_,onRedeem:N}){const{creditInfo:u,profile:l,gtm:{pageGroup:m,pageHandle:n},pageCommon:r}=k(),{brand:R}=S(),i=Object.keys(l||{}).length>0,C=z.includes(R),T=d(()=>!!(e.hasRedeemed||e.alpc?.remainingInventory<=0&&e.alpc?.isLimited||e.alpc?.consumeType===v.Product&&!e.variant?.availableForSale||i&&l?.activated&&e.alpc?.consumeCredits>Number(u?.available_credit||0)),[e.hasRedeemed,e.alpc?.remainingInventory,e.alpc?.isLimited,e.alpc?.consumeType,e.alpc?.consumeCredits,i,l?.activated,u?.available_credit,e.variant?.availableForSale]),x=d(()=>i?e.alpc?.consumeType===v.Product?e.variant?.availableForSale?a.btnRedeem:r?.soldOut||"Sold Out":a.btnRedeem:a.unlockRewards,[i,e.alpc?.consumeType,e.variant?.availableForSale,a.btnRedeem,a.unlockRewards,r?.soldOut]),w=d(()=>{if(!(e.config?.type!==g.Product||!e.product?.handle))return b(e.variant?.id)?`/products/${e.product.handle}?variant=${b(e.variant?.id)}${n?`&ref=${n}`:""}`:`/products/${e.product.handle}${n?`?ref=${n}`:""}`},[e.config?.type,e.product?.handle,e.variant?.id,n]);return o("div",{className:c("flex flex-col items-center rounded-[16px] bg-[#EAEAEC] p-[24px] md:rounded-[12px] md:px-[8px] xl:py-[16px] md-xl:px-[16px]",!C&&"rounded-none md:rounded-none",y),children:[e.config?.type===g.Product?t("a",{href:w,className:c("relative mx-auto h-[224px] w-fit md:my-[10px] l:h-[120px] l-xxl:h-[138px]"),children:t(s,{className:"h-full w-auto [&_img]:h-full [&_img]:object-contain",source:e.config?.image?.url||e.product?.images?.[0]?.url})}):o("div",{className:"relative mx-auto my-[30px] h-[164px] md:my-0 md:h-[66px] l-xxl:h-[138px] md-l:h-[80px]",children:[t(s,{source:r?.imageMapping?.[e.config?.type]?.url,className:"h-full [&_img]:h-full [&_img]:w-auto [&_img]:object-contain"}),t($,{item:e})]}),o("div",{className:c("mt-[10px] xl:mt-[8px] flex w-full flex-1 flex-col justify-between"),children:[t(f,{html:e.config?.title||e.alpc?.title,title:e.config?.title||e.alpc?.title,size:2,className:"line-clamp-2 h-[58px] text-[24px] leading-[1.2] l:h-[40px] l:text-[16px] l-xxl:h-[48px] l-xxl:text-[20px]"}),e.config?.rules?.length>0&&t("button",{type:"button",onClick:()=>{_(e.config?.rules||[]),h({event:"ga4Event",event_name:"lp_button",member_active_status:l?.activated?"active":"not active",event_parameters:{page_group:m,position:a.title,button_name:r?.ruleLabel,info:e.alpc?.id?.toString()}})},className:"mt-[8px] w-fit text-[16px] font-bold underline md:text-[14px] l:mt-0",tabIndex:0,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&p.preventDefault()},children:r?.ruleLabel}),o("div",{children:[o("div",{className:"mt-[26px] flex items-center l:mt-[12px] l-xl:mt-[16px]",children:[t(s,{className:"size-[24px] l-xxl:size-[22px] md-l:size-[18px] md:size-[16px]",source:"https://cdn.shopify.com/s/files/1/0511/6346/3874/files/icon_hire_purchase.png?v=1757496783"}),t(f,{html:`${P(e.alpc?.consumeCredits)}`,size:2,as:"p",className:"ml-[4px] text-[24px] font-bold mt-[4px] leading-none l-xxl:text-[20px] l:text-[16px] "})]}),t(I,{disabled:T,variant:"primary",size:"lg",className:"mt-[8px] md:px-[8px] l:w-full",onClick:()=>{N(e),h({event:"ga4Event",event_name:"lp_button",member_active_status:l?.activated?"active":"not active",event_parameters:{page_group:m,position:a.title,button_name:x,info:e.alpc?.id?.toString()}})},children:x})]})]})]})}export{M as RedeemableItem};
|
|
2
2
|
//# sourceMappingURL=RedeemableItem.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/components/credits/creditsRedeemList/RedeemableItem.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Button, Text, Picture } from '@anker-in/headless-ui'\n\nimport { useMemo } from 'react'\n\nimport classNames from 'classnames'\nimport { useCreditsContext } from '../context/provider'\nimport type { RedeemableItem as RedeemableItemType } from '../type'\nimport { AlpcConsumeType, ConsumeType } from '../context/const'\nimport { numberFormat, extractVariantId } from '../context/utils'\nimport type { CreditsRedeemListCopy } from './type'\nimport { gaTrack, useHeadlessContext } from '@anker-in/lib'\nimport { NoneProductValue } from './NonProductValue'\nimport { ROUNDED_BRANDS } from '../../../constants'\n\nexport function RedeemableItem({\n copy,\n className,\n item,\n onRulesOpen,\n onRedeem,\n}: {\n copy: CreditsRedeemListCopy\n className?: string\n item: RedeemableItemType\n onRulesOpen: (rules: string[]) => void\n onRedeem: (item: RedeemableItemType) => void\n}) {\n const {\n creditInfo,\n profile,\n gtm: { pageGroup, pageHandle },\n pageCommon,\n } = useCreditsContext()\n const { brand } = useHeadlessContext()\n const isLogin = Object.keys(profile || {}).length > 0\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isDisabled = useMemo(() => {\n if (item.alpc?.remainingInventory <= 0 && item.alpc?.isLimited) {\n // \u6709\u5E93\u5B58\u9650\u5236\n return true\n }\n\n if (item.alpc?.consumeType === AlpcConsumeType.Product) {\n if (!item.variant?.availableForSale) {\n return true\n }\n }\n if (isLogin && profile?.activated && item.alpc?.consumeCredits > Number(creditInfo?.available_credit || 0)) {\n return true\n }\n return false\n }, [\n item.alpc?.remainingInventory,\n item.alpc?.isLimited,\n item.alpc?.consumeType,\n item.alpc?.consumeCredits,\n isLogin,\n profile?.activated,\n creditInfo?.available_credit,\n item.variant?.availableForSale,\n ])\n\n const redeemButtonText = useMemo(() => {\n if (!isLogin) {\n return copy.unlockRewards\n }\n\n // \u7F3A\u8D27\u6587\u6848\n if (item.alpc?.consumeType === AlpcConsumeType.Product) {\n return item.variant?.availableForSale ? copy.btnRedeem : pageCommon?.soldOut || 'Sold Out'\n }\n return copy.btnRedeem\n }, [\n isLogin,\n item.alpc?.consumeType,\n item.variant?.availableForSale,\n copy.btnRedeem,\n copy.unlockRewards,\n pageCommon?.soldOut,\n ])\n\n // \u751F\u6210\u4EA7\u54C1 listing \u9875\u9762\u94FE\u63A5\n const productUrl = useMemo(() => {\n if (item.config?.type !== ConsumeType.Product || !item.product?.handle) {\n return undefined\n }\n return extractVariantId(item.variant?.id)\n ? `/products/${item.product.handle}?variant=${extractVariantId(item.variant?.id)}${pageHandle ? `&ref=${pageHandle}` : ''}`\n : `/products/${item.product.handle}${pageHandle ? `?ref=${pageHandle}` : ''}`\n }, [item.config?.type, item.product?.handle, item.variant?.id, pageHandle])\n\n return (\n <div\n className={classNames(\n 'flex flex-col items-center rounded-[16px] bg-[#EAEAEC] p-[24px] md:rounded-[12px] md:px-[8px] xl:py-[16px] md-xl:px-[16px]',\n !rounded && 'rounded-none md:rounded-none',\n className\n )}\n >\n {item.config?.type === ConsumeType.Product ? (\n <a\n href={productUrl}\n className={classNames('relative mx-auto h-[224px] w-fit md:my-[10px] l:h-[120px] l-xxl:h-[138px]')}\n >\n <Picture\n className=\"h-full w-auto [&_img]:h-full [&_img]:object-contain\"\n source={item.config?.image?.url || item.product?.images?.[0]?.url}\n ></Picture>\n </a>\n ) : (\n <div className=\"relative mx-auto my-[30px] h-[164px] md:my-0 md:h-[66px] l-xxl:h-[138px] md-l:h-[80px]\">\n <Picture\n source={pageCommon?.imageMapping?.[item.config?.type]?.url}\n className=\"h-full [&_img]:h-full [&_img]:w-auto [&_img]:object-contain\"\n ></Picture>\n\n <NoneProductValue item={item} />\n </div>\n )}\n <div className={classNames('mt-[10px] xl:mt-[8px] flex w-full flex-1 flex-col justify-between')}>\n <Text\n html={item.config?.title || item.alpc?.title}\n title={item.config?.title || item.alpc?.title}\n size={2}\n className=\"line-clamp-2 h-[58px] text-[24px] leading-[1.2] l:h-[40px] l:text-[16px] l-xxl:h-[48px] l-xxl:text-[20px]\"\n />\n {item.config?.rules?.length > 0 && (\n <button\n type=\"button\"\n onClick={() => {\n onRulesOpen(item.config?.rules || [])\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n member_active_status: profile?.activated ? 'active' : 'not active',\n event_parameters: {\n page_group: pageGroup,\n position: copy.title,\n button_name: pageCommon?.ruleLabel,\n info: item.alpc?.id?.toString(),\n },\n })\n }}\n className=\"mt-[8px] w-fit text-[16px] font-bold underline md:text-[14px] l:mt-0\"\n tabIndex={0}\n onKeyDown={e => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault()\n }\n }}\n >\n {pageCommon?.ruleLabel}\n </button>\n )}\n <div>\n <div className=\"mt-[26px] flex items-center l:mt-[12px] l-xl:mt-[16px]\">\n <Picture\n className=\"size-[24px] l-xxl:size-[22px] md-l:size-[18px] md:size-[16px]\"\n source=\"https://cdn.shopify.com/s/files/1/0511/6346/3874/files/icon_hire_purchase.png?v=1757496783\"\n />\n <Text\n html={`${numberFormat(item.alpc?.consumeCredits)}`}\n size={2}\n as=\"p\"\n className=\"ml-[4px] text-[24px] font-bold mt-[4px] leading-none l-xxl:text-[20px] l:text-[16px] \"\n />\n </div>\n\n <Button\n disabled={isDisabled}\n variant=\"primary\"\n size=\"lg\"\n className=\"mt-[8px] md:px-[8px] l:w-full\"\n onClick={() => {\n onRedeem(item)\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n member_active_status: profile?.activated ? 'active' : 'not active',\n event_parameters: {\n page_group: pageGroup,\n position: copy.title,\n button_name: redeemButtonText,\n info: item.alpc?.id?.toString(),\n },\n })\n }}\n >\n {redeemButtonText}\n </Button>\n </div>\n </div>\n </div>\n )\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { Button, Text, Picture } from '@anker-in/headless-ui'\n\nimport { useMemo } from 'react'\n\nimport classNames from 'classnames'\nimport { useCreditsContext } from '../context/provider'\nimport type { RedeemableItem as RedeemableItemType } from '../type'\nimport { AlpcConsumeType, ConsumeType } from '../context/const'\nimport { numberFormat, extractVariantId } from '../context/utils'\nimport type { CreditsRedeemListCopy } from './type'\nimport { gaTrack, useHeadlessContext } from '@anker-in/lib'\nimport { NoneProductValue } from './NonProductValue'\nimport { ROUNDED_BRANDS } from '../../../constants'\n\nexport function RedeemableItem({\n copy,\n className,\n item,\n onRulesOpen,\n onRedeem,\n}: {\n copy: CreditsRedeemListCopy\n className?: string\n item: RedeemableItemType\n onRulesOpen: (rules: string[]) => void\n onRedeem: (item: RedeemableItemType) => void\n}) {\n const {\n creditInfo,\n profile,\n gtm: { pageGroup, pageHandle },\n pageCommon,\n } = useCreditsContext()\n const { brand } = useHeadlessContext()\n const isLogin = Object.keys(profile || {}).length > 0\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isDisabled = useMemo(() => {\n if (item.hasRedeemed) {\n return true\n }\n\n if (item.alpc?.remainingInventory <= 0 && item.alpc?.isLimited) {\n // \u6709\u5E93\u5B58\u9650\u5236\n return true\n }\n\n if (item.alpc?.consumeType === AlpcConsumeType.Product) {\n if (!item.variant?.availableForSale) {\n return true\n }\n }\n if (isLogin && profile?.activated && item.alpc?.consumeCredits > Number(creditInfo?.available_credit || 0)) {\n return true\n }\n return false\n }, [\n item.hasRedeemed,\n item.alpc?.remainingInventory,\n item.alpc?.isLimited,\n item.alpc?.consumeType,\n item.alpc?.consumeCredits,\n isLogin,\n profile?.activated,\n creditInfo?.available_credit,\n item.variant?.availableForSale,\n ])\n\n const redeemButtonText = useMemo(() => {\n if (!isLogin) {\n return copy.unlockRewards\n }\n\n // \u7F3A\u8D27\u6587\u6848\n if (item.alpc?.consumeType === AlpcConsumeType.Product) {\n return item.variant?.availableForSale ? copy.btnRedeem : pageCommon?.soldOut || 'Sold Out'\n }\n return copy.btnRedeem\n }, [\n isLogin,\n item.alpc?.consumeType,\n item.variant?.availableForSale,\n copy.btnRedeem,\n copy.unlockRewards,\n pageCommon?.soldOut,\n ])\n\n // \u751F\u6210\u4EA7\u54C1 listing \u9875\u9762\u94FE\u63A5\n const productUrl = useMemo(() => {\n if (item.config?.type !== ConsumeType.Product || !item.product?.handle) {\n return undefined\n }\n return extractVariantId(item.variant?.id)\n ? `/products/${item.product.handle}?variant=${extractVariantId(item.variant?.id)}${pageHandle ? `&ref=${pageHandle}` : ''}`\n : `/products/${item.product.handle}${pageHandle ? `?ref=${pageHandle}` : ''}`\n }, [item.config?.type, item.product?.handle, item.variant?.id, pageHandle])\n\n return (\n <div\n className={classNames(\n 'flex flex-col items-center rounded-[16px] bg-[#EAEAEC] p-[24px] md:rounded-[12px] md:px-[8px] xl:py-[16px] md-xl:px-[16px]',\n !rounded && 'rounded-none md:rounded-none',\n className\n )}\n >\n {item.config?.type === ConsumeType.Product ? (\n <a\n href={productUrl}\n className={classNames('relative mx-auto h-[224px] w-fit md:my-[10px] l:h-[120px] l-xxl:h-[138px]')}\n >\n <Picture\n className=\"h-full w-auto [&_img]:h-full [&_img]:object-contain\"\n source={item.config?.image?.url || item.product?.images?.[0]?.url}\n ></Picture>\n </a>\n ) : (\n <div className=\"relative mx-auto my-[30px] h-[164px] md:my-0 md:h-[66px] l-xxl:h-[138px] md-l:h-[80px]\">\n <Picture\n source={pageCommon?.imageMapping?.[item.config?.type]?.url}\n className=\"h-full [&_img]:h-full [&_img]:w-auto [&_img]:object-contain\"\n ></Picture>\n\n <NoneProductValue item={item} />\n </div>\n )}\n <div className={classNames('mt-[10px] xl:mt-[8px] flex w-full flex-1 flex-col justify-between')}>\n <Text\n html={item.config?.title || item.alpc?.title}\n title={item.config?.title || item.alpc?.title}\n size={2}\n className=\"line-clamp-2 h-[58px] text-[24px] leading-[1.2] l:h-[40px] l:text-[16px] l-xxl:h-[48px] l-xxl:text-[20px]\"\n />\n {item.config?.rules?.length > 0 && (\n <button\n type=\"button\"\n onClick={() => {\n onRulesOpen(item.config?.rules || [])\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n member_active_status: profile?.activated ? 'active' : 'not active',\n event_parameters: {\n page_group: pageGroup,\n position: copy.title,\n button_name: pageCommon?.ruleLabel,\n info: item.alpc?.id?.toString(),\n },\n })\n }}\n className=\"mt-[8px] w-fit text-[16px] font-bold underline md:text-[14px] l:mt-0\"\n tabIndex={0}\n onKeyDown={e => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault()\n }\n }}\n >\n {pageCommon?.ruleLabel}\n </button>\n )}\n <div>\n <div className=\"mt-[26px] flex items-center l:mt-[12px] l-xl:mt-[16px]\">\n <Picture\n className=\"size-[24px] l-xxl:size-[22px] md-l:size-[18px] md:size-[16px]\"\n source=\"https://cdn.shopify.com/s/files/1/0511/6346/3874/files/icon_hire_purchase.png?v=1757496783\"\n />\n <Text\n html={`${numberFormat(item.alpc?.consumeCredits)}`}\n size={2}\n as=\"p\"\n className=\"ml-[4px] text-[24px] font-bold mt-[4px] leading-none l-xxl:text-[20px] l:text-[16px] \"\n />\n </div>\n\n <Button\n disabled={isDisabled}\n variant=\"primary\"\n size=\"lg\"\n className=\"mt-[8px] md:px-[8px] l:w-full\"\n onClick={() => {\n onRedeem(item)\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n member_active_status: profile?.activated ? 'active' : 'not active',\n event_parameters: {\n page_group: pageGroup,\n position: copy.title,\n button_name: redeemButtonText,\n info: item.alpc?.id?.toString(),\n },\n })\n }}\n >\n {redeemButtonText}\n </Button>\n </div>\n </div>\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": "AA8GU,cAAAA,EAMF,QAAAC,MANE,oBA9GV,OAAS,UAAAC,EAAQ,QAAAC,EAAM,WAAAC,MAAe,wBAEtC,OAAS,WAAAC,MAAe,QAExB,OAAOC,MAAgB,aACvB,OAAS,qBAAAC,MAAyB,sBAElC,OAAS,mBAAAC,EAAiB,eAAAC,MAAmB,mBAC7C,OAAS,gBAAAC,EAAc,oBAAAC,MAAwB,mBAE/C,OAAS,WAAAC,EAAS,sBAAAC,MAA0B,gBAC5C,OAAS,oBAAAC,MAAwB,oBACjC,OAAS,kBAAAC,MAAsB,qBAExB,SAASC,EAAe,CAC7B,KAAAC,EACA,UAAAC,EACA,KAAAC,EACA,YAAAC,EACA,SAAAC,CACF,EAMG,CACD,KAAM,CACJ,WAAAC,EACA,QAAAC,EACA,IAAK,CAAE,UAAAC,EAAW,WAAAC,CAAW,EAC7B,WAAAC,CACF,EAAInB,EAAkB,EAChB,CAAE,MAAAoB,CAAM,EAAId,EAAmB,EAC/Be,EAAU,OAAO,KAAKL,GAAW,CAAC,CAAC,EAAE,OAAS,EAC9CM,EAAUd,EAAe,SAASY,CAAK,EAEvCG,EAAazB,EAAQ,IACrB,GAAAc,EAAK,aAILA,EAAK,MAAM,oBAAsB,GAAKA,EAAK,MAAM,WAKjDA,EAAK,MAAM,cAAgBX,EAAgB,SACzC,CAACW,EAAK,SAAS,kBAIjBS,GAAWL,GAAS,WAAaJ,EAAK,MAAM,eAAiB,OAAOG,GAAY,kBAAoB,CAAC,GAIxG,CACDH,EAAK,YACLA,EAAK,MAAM,mBACXA,EAAK,MAAM,UACXA,EAAK,MAAM,YACXA,EAAK,MAAM,eACXS,EACAL,GAAS,UACTD,GAAY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AQ,OAASA,EAAK,MAAM,MACvC,MAAOA,EAAK,QAAQ,OAASA,EAAK,MAAM,MACxC,KAAM,EACN,UAAU,4GACZ,EACCA,EAAK,QAAQ,OAAO,OAAS,GAC5BnB,EAAC,UACC,KAAK,SACL,QAAS,IAAM,CACboB,EAAYD,EAAK,QAAQ,OAAS,CAAC,CAAC,EACpCP,EAAQ,CACN,MAAO,WACP,WAAY,YACZ,qBAAsBW,GAAS,UAAY,SAAW,aACtD,iBAAkB,CAChB,WAAYC,EACZ,SAAUP,EAAK,MACf,YAAaS,GAAY,UACzB,KAAMP,EAAK,MAAM,IAAI,SAAS,CAChC,CACF,CAAC,CACH,EACA,UAAU,uEACV,SAAU,EACV,UAAWc,GAAK,EACVA,EAAE,MAAQ,SAAWA,EAAE,MAAQ,MACjCA,EAAE,eAAe,CAErB,EAEC,SAAAP,GAAY,UACf,EAEFzB,EAAC,OACC,UAAAA,EAAC,OAAI,UAAU,yDACb,UAAAD,EAACI,EAAA,CACC,UAAU,gEACV,OAAO,6FACT,EACAJ,EAACG,EAAA,CACC,KAAM,GAAGO,EAAaS,EAAK,MAAM,cAAc,CAAC,GAChD,KAAM,EACN,GAAG,IACH,UAAU,wFACZ,GACF,EAEAnB,EAACE,EAAA,CACC,SAAU4B,EACV,QAAQ,UACR,KAAK,KACL,UAAU,gCACV,QAAS,IAAM,CACbT,EAASF,CAAI,EACbP,EAAQ,CACN,MAAO,WACP,WAAY,YACZ,qBAAsBW,GAAS,UAAY,SAAW,aACtD,iBAAkB,CAChB,WAAYC,EACZ,SAAUP,EAAK,MACf,YAAac,EACb,KAAMZ,EAAK,MAAM,IAAI,SAAS,CAChC,CACF,CAAC,CACH,EAEC,SAAAY,EACH,GACF,GACF,GACF,CAEJ",
|
|
6
6
|
"names": ["jsx", "jsxs", "Button", "Text", "Picture", "useMemo", "classNames", "useCreditsContext", "AlpcConsumeType", "ConsumeType", "numberFormat", "extractVariantId", "gaTrack", "useHeadlessContext", "NoneProductValue", "ROUNDED_BRANDS", "RedeemableItem", "copy", "className", "item", "onRulesOpen", "onRedeem", "creditInfo", "profile", "pageGroup", "pageHandle", "pageCommon", "brand", "isLogin", "rounded", "isDisabled", "redeemButtonText", "productUrl", "e"]
|
|
7
7
|
}
|
|
@@ -30,6 +30,7 @@ export type RedeemableItem = {
|
|
|
30
30
|
};
|
|
31
31
|
product?: Product;
|
|
32
32
|
variant?: ProductVariant;
|
|
33
|
+
hasRedeemed?: boolean;
|
|
33
34
|
};
|
|
34
35
|
export interface ShippingCountry {
|
|
35
36
|
id: string;
|
|
@@ -110,6 +111,7 @@ export type CreditsPageCommon = {
|
|
|
110
111
|
infoIcon?: string;
|
|
111
112
|
ruleLabel?: string;
|
|
112
113
|
soldOut?: string;
|
|
114
|
+
redeemed?: string;
|
|
113
115
|
copied?: string;
|
|
114
116
|
off?: string;
|
|
115
117
|
copy?: string;
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ import { CreditsGoGiftCopy } from './type'
|
|
|
11
11
|
import { AlpcConsumeType, AlpcErrorCode } from '../context/const'
|
|
12
12
|
import RulesModal from '../modal/RulesModal'
|
|
13
13
|
import { useRegistration } from '../../../components/registration'
|
|
14
|
+
import useMyRewards from '../context/hooks/useMyRewards'
|
|
14
15
|
|
|
15
16
|
export const CreditsGoGift = ({ copy, id }: { copy: CreditsGoGiftCopy; id?: string }) => {
|
|
16
17
|
const [showModal, setShowModal] = useState(false)
|
|
@@ -24,9 +25,14 @@ export const CreditsGoGift = ({ copy, id }: { copy: CreditsGoGiftCopy; id?: stri
|
|
|
24
25
|
|
|
25
26
|
const isLogin = Object.keys(profile || {}).length > 0
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
// 获取用户的 ExternalProduct 兑换记录
|
|
29
|
+
const { myRewards } = useMyRewards({
|
|
30
|
+
page: 1,
|
|
31
|
+
pageSize: 100,
|
|
32
|
+
consumeType: AlpcConsumeType.ExternalProduct,
|
|
33
|
+
})
|
|
28
34
|
|
|
29
|
-
|
|
35
|
+
const redeemModalCopy = pageCommon?.redeemModal || ({} as any)
|
|
30
36
|
|
|
31
37
|
const item = useMemo(() => {
|
|
32
38
|
// 根据 redeemId 查询 ExternalProduct 的 ALPC 数据
|
|
@@ -75,6 +81,12 @@ export const CreditsGoGift = ({ copy, id }: { copy: CreditsGoGiftCopy; id?: stri
|
|
|
75
81
|
)
|
|
76
82
|
}, [profile?.activated, item?.alpc?.consumeCredits, creditInfo?.available_credit])
|
|
77
83
|
|
|
84
|
+
// 检查用户是否已经兑换过该 GoGift
|
|
85
|
+
const hasRedeemed = useMemo(() => {
|
|
86
|
+
if (!isLogin || !item?.alpc?.id) return false
|
|
87
|
+
return myRewards.some(reward => reward.rule_id === Number(item.alpc.id))
|
|
88
|
+
}, [isLogin, item?.alpc?.id, myRewards])
|
|
89
|
+
|
|
78
90
|
const soldOut = Number(item?.alpc.remainingInventory) <= 0
|
|
79
91
|
|
|
80
92
|
const redeemButtonText = useMemo(() => {
|
|
@@ -136,7 +148,7 @@ export const CreditsGoGift = ({ copy, id }: { copy: CreditsGoGiftCopy; id?: stri
|
|
|
136
148
|
<div className="flex shrink-0 flex-col items-end l:w-full l:items-start">
|
|
137
149
|
<Button
|
|
138
150
|
variant="primary"
|
|
139
|
-
disabled={inSufficientCredit || soldOut}
|
|
151
|
+
disabled={inSufficientCredit || soldOut || hasRedeemed}
|
|
140
152
|
onClick={() => {
|
|
141
153
|
if (!isLogin) {
|
|
142
154
|
openSignUpPopup()
|
|
@@ -16,6 +16,7 @@ import RulesModal from '../modal/RulesModal'
|
|
|
16
16
|
import { CreditsRedeemListCopy } from './type'
|
|
17
17
|
import { useRegistration } from '../../../components/registration'
|
|
18
18
|
import { numberFormat } from '../context/utils'
|
|
19
|
+
import useMyRewards from '../context/hooks/useMyRewards'
|
|
19
20
|
|
|
20
21
|
export const CreditsRedeemList = ({ copy, id }: { copy: CreditsRedeemListCopy; id?: string }) => {
|
|
21
22
|
const {
|
|
@@ -39,6 +40,13 @@ export const CreditsRedeemList = ({ copy, id }: { copy: CreditsRedeemListCopy; i
|
|
|
39
40
|
|
|
40
41
|
const { listLoading, redeemableList, getRedeemableList } = useRedeemableList()
|
|
41
42
|
|
|
43
|
+
// 获取用户的 ExternalProduct 兑换记录
|
|
44
|
+
const { myRewards } = useMyRewards({
|
|
45
|
+
page: 1,
|
|
46
|
+
pageSize: 100,
|
|
47
|
+
consumeType: AlpcConsumeType.ExternalProduct,
|
|
48
|
+
})
|
|
49
|
+
|
|
42
50
|
// 合并 redeemModal 文案,优先使用 copy.redeemModal,fallback 到 pageCommon.redeemModal
|
|
43
51
|
const redeemModalCopy = useMemo(() => {
|
|
44
52
|
return {
|
|
@@ -77,15 +85,22 @@ export const CreditsRedeemList = ({ copy, id }: { copy: CreditsRedeemListCopy; i
|
|
|
77
85
|
// 过滤掉库存不足的商品
|
|
78
86
|
if (alpcItem?.isLimited && (!alpcItem?.remainingInventory || alpcItem.remainingInventory <= 0)) return null
|
|
79
87
|
if (alpcItem?.consumeType === AlpcConsumeType.Product && (!product || !variant)) return null
|
|
88
|
+
|
|
89
|
+
// 检查 GoGift 是否已经兑换过(只有 GoGift 限制兑换一次)
|
|
90
|
+
const hasRedeemed = item.type === ConsumeType.GoGift &&
|
|
91
|
+
isLogin &&
|
|
92
|
+
myRewards.some(reward => reward.rule_id === Number(item.id))
|
|
93
|
+
|
|
80
94
|
return {
|
|
81
95
|
alpc: alpcList.find(alpcItem => String(alpcItem.id) === String(item.id)),
|
|
82
96
|
config: item,
|
|
83
97
|
product,
|
|
84
98
|
variant,
|
|
99
|
+
hasRedeemed,
|
|
85
100
|
}
|
|
86
101
|
})
|
|
87
102
|
.filter(item => item !== null) as unknown as RedeemableItemType[]
|
|
88
|
-
}, [alpcList, products])
|
|
103
|
+
}, [alpcList, products, isLogin, myRewards])
|
|
89
104
|
|
|
90
105
|
const handleRedeemError = useCallback(
|
|
91
106
|
(errorCode: AlpcErrorCode) => {
|
|
@@ -36,6 +36,10 @@ export function RedeemableItem({
|
|
|
36
36
|
const rounded = ROUNDED_BRANDS.includes(brand)
|
|
37
37
|
|
|
38
38
|
const isDisabled = useMemo(() => {
|
|
39
|
+
if (item.hasRedeemed) {
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
39
43
|
if (item.alpc?.remainingInventory <= 0 && item.alpc?.isLimited) {
|
|
40
44
|
// 有库存限制
|
|
41
45
|
return true
|
|
@@ -51,6 +55,7 @@ export function RedeemableItem({
|
|
|
51
55
|
}
|
|
52
56
|
return false
|
|
53
57
|
}, [
|
|
58
|
+
item.hasRedeemed,
|
|
54
59
|
item.alpc?.remainingInventory,
|
|
55
60
|
item.alpc?.isLimited,
|
|
56
61
|
item.alpc?.consumeType,
|
|
@@ -32,6 +32,7 @@ export type RedeemableItem = {
|
|
|
32
32
|
}
|
|
33
33
|
product?: Product
|
|
34
34
|
variant?: ProductVariant
|
|
35
|
+
hasRedeemed?: boolean
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export interface ShippingCountry {
|
|
@@ -116,6 +117,7 @@ export type CreditsPageCommon = {
|
|
|
116
117
|
infoIcon?: string
|
|
117
118
|
ruleLabel?: string
|
|
118
119
|
soldOut?: string
|
|
120
|
+
redeemed?: string
|
|
119
121
|
copied?: string
|
|
120
122
|
off?: string
|
|
121
123
|
copy?: string
|