@anker-in/campaign-ui 0.4.4 → 0.4.5-beta.2
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/useActivities.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useActivities.js.map +3 -3
- package/dist/cjs/components/credits/context/hooks/useAlpcFetch.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useAlpcFetch.js.map +3 -3
- package/dist/cjs/components/credits/context/hooks/useCountries.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useCountries.js.map +2 -2
- package/dist/cjs/components/credits/context/hooks/useMyRewards.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useMyRewards.js.map +3 -3
- package/dist/cjs/components/credits/context/hooks/useRedeemAndBuy.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useRedeemAndBuy.js.map +3 -3
- package/dist/cjs/components/credits/context/hooks/useRedeemableList.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useRedeemableList.js.map +2 -2
- package/dist/cjs/components/credits/context/hooks/useUploadReceipt.d.ts +0 -8
- package/dist/cjs/components/credits/context/hooks/useUploadReceipt.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useUploadReceipt.js.map +3 -3
- package/dist/cjs/components/credits/creditsRedeemList/RedeemCouponModal.js +1 -1
- package/dist/cjs/components/credits/creditsRedeemList/RedeemCouponModal.js.map +3 -3
- package/dist/cjs/components/credits/creditsRedeemList/RedeemVirtualProductModal.js +1 -1
- package/dist/cjs/components/credits/creditsRedeemList/RedeemVirtualProductModal.js.map +3 -3
- package/dist/cjs/components/credits/modal/SubscribeModal.js +1 -1
- package/dist/cjs/components/credits/modal/SubscribeModal.js.map +3 -3
- package/dist/cjs/components/registration/authCodeActivate/index.js +1 -1
- package/dist/cjs/components/registration/authCodeActivate/index.js.map +3 -3
- package/dist/esm/components/credits/context/hooks/useActivities.js +1 -1
- package/dist/esm/components/credits/context/hooks/useActivities.js.map +3 -3
- package/dist/esm/components/credits/context/hooks/useAlpcFetch.js +1 -1
- package/dist/esm/components/credits/context/hooks/useAlpcFetch.js.map +3 -3
- package/dist/esm/components/credits/context/hooks/useCountries.js +1 -1
- package/dist/esm/components/credits/context/hooks/useCountries.js.map +2 -2
- package/dist/esm/components/credits/context/hooks/useMyRewards.js +1 -1
- package/dist/esm/components/credits/context/hooks/useMyRewards.js.map +3 -3
- package/dist/esm/components/credits/context/hooks/useRedeemAndBuy.js +1 -1
- package/dist/esm/components/credits/context/hooks/useRedeemAndBuy.js.map +3 -3
- package/dist/esm/components/credits/context/hooks/useRedeemableList.js +1 -1
- package/dist/esm/components/credits/context/hooks/useRedeemableList.js.map +2 -2
- package/dist/esm/components/credits/context/hooks/useUploadReceipt.d.ts +0 -8
- package/dist/esm/components/credits/context/hooks/useUploadReceipt.js +1 -1
- package/dist/esm/components/credits/context/hooks/useUploadReceipt.js.map +3 -3
- package/dist/esm/components/credits/creditsRedeemList/RedeemCouponModal.js +1 -1
- package/dist/esm/components/credits/creditsRedeemList/RedeemCouponModal.js.map +3 -3
- package/dist/esm/components/credits/creditsRedeemList/RedeemVirtualProductModal.js +1 -1
- package/dist/esm/components/credits/creditsRedeemList/RedeemVirtualProductModal.js.map +3 -3
- package/dist/esm/components/credits/modal/SubscribeModal.js +1 -1
- package/dist/esm/components/credits/modal/SubscribeModal.js.map +3 -3
- package/dist/esm/components/registration/authCodeActivate/index.js +1 -1
- package/dist/esm/components/registration/authCodeActivate/index.js.map +3 -3
- package/package.json +1 -1
- package/src/components/credits/context/hooks/useActivities.ts +5 -4
- package/src/components/credits/context/hooks/useAlpcFetch.ts +30 -10
- package/src/components/credits/context/hooks/useCountries.ts +7 -2
- package/src/components/credits/context/hooks/useMyRewards.ts +8 -4
- package/src/components/credits/context/hooks/useRedeemAndBuy.ts +3 -2
- package/src/components/credits/context/hooks/useRedeemableList.ts +28 -23
- package/src/components/credits/context/hooks/useUploadReceipt.tsx +28 -23
- package/src/components/credits/creditsRedeemList/RedeemCouponModal.tsx +3 -2
- package/src/components/credits/creditsRedeemList/RedeemVirtualProductModal.tsx +3 -2
- package/src/components/credits/modal/SubscribeModal.tsx +4 -6
- package/src/components/registration/authCodeActivate/index.tsx +8 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/components/credits/creditsRedeemList/RedeemCouponModal.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Text } from '@anker-in/headless-ui'\nimport { useCallback, useEffect, useState } from 'react'\nimport type { ModalContainerProps } from '../modal/ModalContainer'\nimport { useCreditsContext } from '../context/provider'\nimport { useRedeemCoupon } from '../context/hooks/useRedeemCoupon'\nimport { AlpcErrorCode } from '../context/const'\nimport { CreditsModalContainer } from '../modal/ModalContainer'\nimport type { RedeemableItem as RedeemableItemType, RedeemModalCommon } from '../type'\nimport { CouponInit } from './RedeemCouponModal/CouponInit'\nimport { CouponSuccess } from './RedeemCouponModal/CouponSuccess'\n\nfunction RedeemCouponModal({\n item,\n copy,\n onError,\n ...props\n}: Omit<ModalContainerProps, 'isOpen'> & {\n item: RedeemableItemType\n copy: RedeemModalCommon\n onError: (code: number) => void\n}) {\n const [couponCode, setCouponCode] = useState<string>()\n const [errorInfo, setErrorInfo] = useState<string>()\n const [disabled, setDisabled] = useState(false)\n\n const { profile, fetchCreditInfo } = useCreditsContext()\n\n const { isMutating: loading, trigger } = useRedeemCoupon({\n onSuccess(responseData) {\n if (!responseData) {\n setErrorInfo(copy.commonError)\n return\n }\n\n
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["jsx", "jsxs", "Text", "useCallback", "useEffect", "useState", "useCreditsContext", "useRedeemCoupon", "AlpcErrorCode", "CreditsModalContainer", "CouponInit", "CouponSuccess", "RedeemCouponModal", "item", "copy", "onError", "props", "couponCode", "setCouponCode", "errorInfo", "setErrorInfo", "disabled", "setDisabled", "profile", "fetchCreditInfo", "loading", "trigger", "responseData", "errorMsg", "error", "handleConfirm", "RedeemCouponModal_default"]
|
|
4
|
+
"sourcesContent": ["import { Text } from '@anker-in/headless-ui'\nimport { useCallback, useEffect, useState } from 'react'\nimport type { ModalContainerProps } from '../modal/ModalContainer'\nimport { useCreditsContext } from '../context/provider'\nimport { useRedeemCoupon } from '../context/hooks/useRedeemCoupon'\nimport { AlpcErrorCode } from '../context/const'\nimport { CreditsModalContainer } from '../modal/ModalContainer'\nimport type { RedeemableItem as RedeemableItemType, RedeemModalCommon } from '../type'\nimport { CouponInit } from './RedeemCouponModal/CouponInit'\nimport { CouponSuccess } from './RedeemCouponModal/CouponSuccess'\n\nfunction RedeemCouponModal({\n item,\n copy,\n onError,\n ...props\n}: Omit<ModalContainerProps, 'isOpen'> & {\n item: RedeemableItemType\n copy: RedeemModalCommon\n onError: (code: number) => void\n}) {\n const [couponCode, setCouponCode] = useState<string>()\n const [errorInfo, setErrorInfo] = useState<string>()\n const [disabled, setDisabled] = useState(false)\n\n const { profile, fetchCreditInfo } = useCreditsContext()\n\n const { isMutating: loading, trigger } = useRedeemCoupon({\n onSuccess(responseData) {\n if (!responseData) {\n setErrorInfo(copy.commonError)\n return\n }\n\n const data = responseData?.data || responseData\n if (data?.success) {\n setCouponCode(data.coupon_code)\n fetchCreditInfo(profile?.user_id)\n } else {\n let errorMsg\n if (responseData.code === AlpcErrorCode.CodeLpcShopifyCouponRuleRedeemLimit) {\n errorMsg = copy.redeemLimitError\n setDisabled(true)\n } else if (responseData.code === AlpcErrorCode.CodeLpcRuleInventoryNotEnough) {\n errorMsg = copy.inventoryNotEnough\n setDisabled(true)\n } else if (responseData.code === AlpcErrorCode.CodeLpcNotEnoughCredits) {\n errorMsg = copy.creditsNotEnough\n setDisabled(true)\n fetchCreditInfo(profile?.user_id)\n } else if (responseData.code === AlpcErrorCode.CodeCrossSiteError) {\n errorMsg = copy.crossSiteError\n setDisabled(true)\n }\n\n setErrorInfo(errorMsg || copy.commonError || '')\n onError && onError(responseData.code)\n }\n },\n onError(error) {\n setErrorInfo(error.message || copy.commonError)\n },\n })\n\n const handleConfirm = useCallback(async () => {\n setErrorInfo('')\n trigger({\n user_id: profile?.user_id,\n rule_id: Number(item.alpc?.id),\n })\n }, [item, profile, trigger])\n\n useEffect(() => {\n return () => {\n setDisabled(false)\n setErrorInfo('')\n setCouponCode(undefined)\n }\n }, [])\n\n return (\n <CreditsModalContainer\n {...props}\n isOpen={!!item}\n className=\"w-[540px] md:h-auto\"\n scrollClassName=\"mb-[40px] min-l:px-0 md:mb-[24px] px-0\"\n titleClassName=\"h-[56px] bg-[#F5F5F7]\"\n >\n {couponCode && !loading ? (\n <CouponSuccess item={item} copy={copy} couponCode={couponCode} disabled={disabled} onClose={props.onClose} />\n ) : (\n <CouponInit item={item} copy={copy} loading={loading} disabled={disabled} onConfirm={handleConfirm} />\n )}\n {errorInfo && (\n <div className=\"mx-auto max-w-full bg-white px-[48px] py-[12px] text-center text-[#FF0000] md:px-[16px]\">\n <Text className=\"text-[14px] font-semibold text-[#1F2021]\" html={errorInfo} />\n </div>\n )}\n </CreditsModalContainer>\n )\n}\n\nexport default RedeemCouponModal\n"],
|
|
5
|
+
"mappings": "AAiFI,OAQI,OAAAA,EARJ,QAAAC,MAAA,oBAjFJ,OAAS,QAAAC,MAAY,wBACrB,OAAS,eAAAC,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QAEjD,OAAS,qBAAAC,MAAyB,sBAClC,OAAS,mBAAAC,MAAuB,mCAChC,OAAS,iBAAAC,MAAqB,mBAC9B,OAAS,yBAAAC,MAA6B,0BAEtC,OAAS,cAAAC,MAAkB,iCAC3B,OAAS,iBAAAC,MAAqB,oCAE9B,SAASC,EAAkB,CACzB,KAAAC,EACA,KAAAC,EACA,QAAAC,EACA,GAAGC,CACL,EAIG,CACD,KAAM,CAACC,EAAYC,CAAa,EAAIb,EAAiB,EAC/C,CAACc,EAAWC,CAAY,EAAIf,EAAiB,EAC7C,CAACgB,EAAUC,CAAW,EAAIjB,EAAS,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,CAAc,KAAME,EAAM,KAAMC,EAAM,WAAYG,EAAY,SAAUI,EAAU,QAASL,EAAM,QAAS,EAE3GhB,EAACU,EAAA,CAAW,KAAMG,EAAM,KAAMC,EAAM,QAASW,EAAS,SAAUJ,EAAU,UAAWU,EAAe,EAErGZ,GACCnB,EAAC,OAAI,UAAU,0FACb,SAAAA,EAACE,EAAA,CAAK,UAAU,2CAA2C,KAAMiB,EAAW,EAC9E,GAEJ,CAEJ,CAEA,IAAOa,EAAQpB",
|
|
6
|
+
"names": ["jsx", "jsxs", "Text", "useCallback", "useEffect", "useState", "useCreditsContext", "useRedeemCoupon", "AlpcErrorCode", "CreditsModalContainer", "CouponInit", "CouponSuccess", "RedeemCouponModal", "item", "copy", "onError", "props", "couponCode", "setCouponCode", "errorInfo", "setErrorInfo", "disabled", "setDisabled", "profile", "fetchCreditInfo", "loading", "trigger", "responseData", "data", "errorMsg", "error", "handleConfirm", "RedeemCouponModal_default"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as m,jsxs as B}from"react/jsx-runtime";import{Text as S}from"@anker-in/headless-ui";import{useCallback as y,useEffect as P,useState as f}from"react";import{useCreditsContext as L}from"../context/provider";import{useRedeemGoGift as F}from"../context/hooks/useRedeemGoGift";import{useRedeemProduct as T}from"../context/hooks/useRedeemProduct";import{AlpcErrorCode as s,ConsumeType as _}from"../context/const";import{CreditsModalContainer as O}from"../modal/ModalContainer";import{gaTrack as w}from"@anker-in/lib";import{VirtualProductInit as A}from"./RedeemVirtualProductModal/VirtualProductInit";import{VirtualProductSuccess as V}from"./RedeemVirtualProductModal/VirtualProductSuccess";function k({item:t,copy:r,onError:c,...p}){const[h,a]=f(),[g,
|
|
1
|
+
import{jsx as m,jsxs as B}from"react/jsx-runtime";import{Text as S}from"@anker-in/headless-ui";import{useCallback as y,useEffect as P,useState as f}from"react";import{useCreditsContext as L}from"../context/provider";import{useRedeemGoGift as F}from"../context/hooks/useRedeemGoGift";import{useRedeemProduct as T}from"../context/hooks/useRedeemProduct";import{AlpcErrorCode as s,ConsumeType as _}from"../context/const";import{CreditsModalContainer as O}from"../modal/ModalContainer";import{gaTrack as w}from"@anker-in/lib";import{VirtualProductInit as A}from"./RedeemVirtualProductModal/VirtualProductInit";import{VirtualProductSuccess as V}from"./RedeemVirtualProductModal/VirtualProductSuccess";function k({item:t,copy:r,onError:c,...p}){const[h,a]=f(),[g,n]=f(),[C,d]=f(!1),{profile:o,fetchCreditInfo:l,gtm:b}=L(),u=t.config?.type===_.GoGift,x=t.config?.type===_.GiftCard,{isMutating:R,trigger:E}=F({onSuccess(e){if(!e){n(r?.commonError);return}const i=e?.data||e;i?.id?(a(i.id),l(o?.user_id)):G(e.code)},onError(e){n(e.message||r?.commonError)}}),{isMutating:M,trigger:v}=T({onSuccess(e){if(!e){n(r?.commonError);return}e?.code===0?(a("success"),l(o?.user_id)):G(e.code)},onError(){n(r?.commonError)}}),N=u?R:M,G=e=>{let i;e===s.CodeLpcShopifyCouponRuleRedeemLimit?(i=r?.redeemLimitError,d(!0)):e===s.CodeLpcRuleInventoryNotEnough?(i=r?.inventoryNotEnough,d(!0)):e===s.CodeLpcNotEnoughCredits?(i=r?.creditsNotEnough,d(!0),l(o?.user_id)):e===s.CodeCrossSiteError&&(i=r?.crossSiteError,d(!0)),n(i||r?.commonError||""),c&&c(e)},I=y(async()=>{if(n(""),w({event:"ga4Event",event_name:"lp_button",member_active_status:o?.activated?"active":"not active",event_parameters:{page_group:b.pageGroup,position:"redeem virtual product modal",button_name:r.confirmButton,info:t.alpc?.id}}),u)E({user_id:o?.user_id,rule_id:Number(t.alpc?.id)});else if(x){const e={email:o?.email||"",firstName:o?.firstName||"",lastName:o?.lastName||"",address1:"Default Address",city:"Default City",province:"Default Province",country:"US",zip:"00000"};v({address:btoa(JSON.stringify(e)),rule_id:Number(t.alpc?.id)})}},[t,o,E,v,u,x,r.confirmButton,b.pageGroup]);return P(()=>()=>{d(!1),n(""),a(void 0)},[]),B(O,{...p,isOpen:!!t,className:"w-[540px] md:h-auto",scrollClassName:"mb-[40px] min-l:px-0 md:mb-[24px] px-0",titleClassName:"h-[56px] bg-[#F5F5F7]",children:[h&&!N?m(V,{item:t,copy:r,disabled:C,onClose:p.onClose}):m(A,{item:t,copy:r,loading:N,disabled:C,onConfirm:I}),g&&m("div",{className:"mx-auto max-w-full bg-white px-[48px] py-[12px] text-center text-[#FF0000] md:px-[16px]",children:m(S,{className:"text-[14px] font-semibold text-[#1F2021]",html:g})})]})}var Z=k;export{Z as default};
|
|
2
2
|
//# sourceMappingURL=RedeemVirtualProductModal.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/components/credits/creditsRedeemList/RedeemVirtualProductModal.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Text } from '@anker-in/headless-ui'\nimport { useCallback, useEffect, useState } from 'react'\nimport type { ModalContainerProps } from '../modal/ModalContainer'\nimport { useCreditsContext } from '../context/provider'\nimport { useRedeemGoGift } from '../context/hooks/useRedeemGoGift'\nimport { useRedeemProduct } from '../context/hooks/useRedeemProduct'\nimport { AlpcErrorCode, ConsumeType } from '../context/const'\nimport { CreditsModalContainer } from '../modal/ModalContainer'\nimport type { RedeemableItem as RedeemableItemType, RedeemModalCommon } from '../type'\nimport { gaTrack } from '@anker-in/lib'\nimport { VirtualProductInit } from './RedeemVirtualProductModal/VirtualProductInit'\nimport { VirtualProductSuccess } from './RedeemVirtualProductModal/VirtualProductSuccess'\n\nfunction RedeemVirtualProductModal({\n item,\n copy,\n onError,\n ...props\n}: Omit<ModalContainerProps, 'isOpen'> & {\n item: RedeemableItemType\n copy: RedeemModalCommon\n onError: (code: number) => void\n}) {\n const [giftCardId, setGiftCardId] = useState<string>()\n const [errorInfo, setErrorInfo] = useState<string>()\n\n const [disabled, setDisabled] = useState(false)\n\n const { profile, fetchCreditInfo, gtm } = useCreditsContext()\n\n // \u5224\u65AD\u662F GoGift \u8FD8\u662F GiftCard \u7C7B\u578B\n const isGoGift = item.config?.type === ConsumeType.GoGift\n const isGiftCard = item.config?.type === ConsumeType.GiftCard\n\n // GoGift \u4F7F\u7528\u4E13\u7528\u63A5\u53E3\n const { isMutating: goGiftLoading, trigger: triggerGoGift } = useRedeemGoGift({\n onSuccess(responseData) {\n if (!responseData) {\n setErrorInfo(copy?.commonError)\n return\n }\n\n
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["jsx", "jsxs", "Text", "useCallback", "useEffect", "useState", "useCreditsContext", "useRedeemGoGift", "useRedeemProduct", "AlpcErrorCode", "ConsumeType", "CreditsModalContainer", "gaTrack", "VirtualProductInit", "VirtualProductSuccess", "RedeemVirtualProductModal", "item", "copy", "onError", "props", "giftCardId", "setGiftCardId", "errorInfo", "setErrorInfo", "disabled", "setDisabled", "profile", "fetchCreditInfo", "gtm", "isGoGift", "isGiftCard", "goGiftLoading", "triggerGoGift", "responseData", "handleRedeemError", "error", "productLoading", "triggerProduct", "loading", "code", "errorMsg", "handleConfirm", "defaultAddress", "RedeemVirtualProductModal_default"]
|
|
4
|
+
"sourcesContent": ["import { Text } from '@anker-in/headless-ui'\nimport { useCallback, useEffect, useState } from 'react'\nimport type { ModalContainerProps } from '../modal/ModalContainer'\nimport { useCreditsContext } from '../context/provider'\nimport { useRedeemGoGift } from '../context/hooks/useRedeemGoGift'\nimport { useRedeemProduct } from '../context/hooks/useRedeemProduct'\nimport { AlpcErrorCode, ConsumeType } from '../context/const'\nimport { CreditsModalContainer } from '../modal/ModalContainer'\nimport type { RedeemableItem as RedeemableItemType, RedeemModalCommon } from '../type'\nimport { gaTrack } from '@anker-in/lib'\nimport { VirtualProductInit } from './RedeemVirtualProductModal/VirtualProductInit'\nimport { VirtualProductSuccess } from './RedeemVirtualProductModal/VirtualProductSuccess'\n\nfunction RedeemVirtualProductModal({\n item,\n copy,\n onError,\n ...props\n}: Omit<ModalContainerProps, 'isOpen'> & {\n item: RedeemableItemType\n copy: RedeemModalCommon\n onError: (code: number) => void\n}) {\n const [giftCardId, setGiftCardId] = useState<string>()\n const [errorInfo, setErrorInfo] = useState<string>()\n\n const [disabled, setDisabled] = useState(false)\n\n const { profile, fetchCreditInfo, gtm } = useCreditsContext()\n\n // \u5224\u65AD\u662F GoGift \u8FD8\u662F GiftCard \u7C7B\u578B\n const isGoGift = item.config?.type === ConsumeType.GoGift\n const isGiftCard = item.config?.type === ConsumeType.GiftCard\n\n // GoGift \u4F7F\u7528\u4E13\u7528\u63A5\u53E3\n const { isMutating: goGiftLoading, trigger: triggerGoGift } = useRedeemGoGift({\n onSuccess(responseData) {\n if (!responseData) {\n setErrorInfo(copy?.commonError)\n return\n }\n\n const data = responseData?.data || responseData\n if (data?.id) {\n setGiftCardId(data.id)\n fetchCreditInfo(profile?.user_id)\n } else {\n handleRedeemError(responseData.code)\n }\n },\n onError(error) {\n setErrorInfo(error.message || copy?.commonError)\n },\n })\n\n // GiftCard \u4F7F\u7528 Product \u63A5\u53E3\uFF0C\u4F46\u4E0D\u9700\u8981\u5730\u5740\n const { isMutating: productLoading, trigger: triggerProduct } = useRedeemProduct({\n onSuccess(responseData) {\n if (!responseData) {\n setErrorInfo(copy?.commonError)\n return\n }\n\n if (responseData?.code === 0) {\n setGiftCardId('success')\n fetchCreditInfo(profile?.user_id)\n } else {\n handleRedeemError(responseData.code)\n }\n },\n onError() {\n setErrorInfo(copy?.commonError)\n },\n })\n\n const loading = isGoGift ? goGiftLoading : productLoading\n\n const handleRedeemError = (code: number) => {\n let errorMsg: string | undefined\n if (code === AlpcErrorCode.CodeLpcShopifyCouponRuleRedeemLimit) {\n errorMsg = copy?.redeemLimitError\n setDisabled(true)\n } else if (code === AlpcErrorCode.CodeLpcRuleInventoryNotEnough) {\n errorMsg = copy?.inventoryNotEnough\n setDisabled(true)\n } else if (code === AlpcErrorCode.CodeLpcNotEnoughCredits) {\n errorMsg = copy?.creditsNotEnough\n setDisabled(true)\n fetchCreditInfo(profile?.user_id)\n } else if (code === AlpcErrorCode.CodeCrossSiteError) {\n errorMsg = copy?.crossSiteError\n setDisabled(true)\n }\n\n setErrorInfo(errorMsg || copy?.commonError || '')\n onError && onError(code)\n }\n\n const handleConfirm = useCallback(async () => {\n setErrorInfo('')\n\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: gtm.pageGroup,\n position: 'redeem virtual product modal',\n button_name: copy.confirmButton,\n info: item.alpc?.id,\n },\n })\n\n if (isGoGift) {\n // GoGift \u7C7B\u578B\u4F7F\u7528\u4E13\u7528\u63A5\u53E3\n triggerGoGift({\n user_id: profile?.user_id,\n rule_id: Number(item.alpc?.id),\n })\n } else if (isGiftCard) {\n // GiftCard \u7C7B\u578B\u4F7F\u7528 Product \u63A5\u53E3\uFF0C\u4F20\u9012\u9ED8\u8BA4\u5730\u5740\n const defaultAddress = {\n email: profile?.email || '',\n firstName: profile?.firstName || '',\n lastName: profile?.lastName || '',\n address1: 'Default Address',\n city: 'Default City',\n province: 'Default Province',\n country: 'US',\n zip: '00000',\n }\n triggerProduct({\n address: btoa(JSON.stringify(defaultAddress)),\n rule_id: Number(item.alpc?.id),\n })\n }\n }, [item, profile, triggerGoGift, triggerProduct, isGoGift, isGiftCard, copy.confirmButton, gtm.pageGroup])\n\n useEffect(() => {\n return () => {\n setDisabled(false)\n setErrorInfo('')\n setGiftCardId(undefined)\n }\n }, [])\n\n return (\n <CreditsModalContainer\n {...props}\n isOpen={!!item}\n className=\"w-[540px] md:h-auto\"\n scrollClassName=\"mb-[40px] min-l:px-0 md:mb-[24px] px-0\"\n titleClassName=\"h-[56px] bg-[#F5F5F7]\"\n >\n {giftCardId && !loading ? (\n <VirtualProductSuccess item={item} copy={copy} disabled={disabled} onClose={props.onClose} />\n ) : (\n <VirtualProductInit item={item} copy={copy} loading={loading} disabled={disabled} onConfirm={handleConfirm} />\n )}\n {errorInfo && (\n <div className=\"mx-auto max-w-full bg-white px-[48px] py-[12px] text-center text-[#FF0000] md:px-[16px]\">\n <Text className=\"text-[14px] font-semibold text-[#1F2021]\" html={errorInfo} />\n </div>\n )}\n </CreditsModalContainer>\n )\n}\n\nexport default RedeemVirtualProductModal\n"],
|
|
5
|
+
"mappings": "AAmJI,OAQI,OAAAA,EARJ,QAAAC,MAAA,oBAnJJ,OAAS,QAAAC,MAAY,wBACrB,OAAS,eAAAC,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QAEjD,OAAS,qBAAAC,MAAyB,sBAClC,OAAS,mBAAAC,MAAuB,mCAChC,OAAS,oBAAAC,MAAwB,oCACjC,OAAS,iBAAAC,EAAe,eAAAC,MAAmB,mBAC3C,OAAS,yBAAAC,MAA6B,0BAEtC,OAAS,WAAAC,MAAe,gBACxB,OAAS,sBAAAC,MAA0B,iDACnC,OAAS,yBAAAC,MAA6B,oDAEtC,SAASC,EAA0B,CACjC,KAAAC,EACA,KAAAC,EACA,QAAAC,EACA,GAAGC,CACL,EAIG,CACD,KAAM,CAACC,EAAYC,CAAa,EAAIhB,EAAiB,EAC/C,CAACiB,EAAWC,CAAY,EAAIlB,EAAiB,EAE7C,CAACmB,EAAUC,CAAW,EAAIpB,EAAS,EAAK,EAExC,CAAE,QAAAqB,EAAS,gBAAAC,EAAiB,IAAAC,CAAI,EAAItB,EAAkB,EAGtDuB,EAAWb,EAAK,QAAQ,OAASN,EAAY,OAC7CoB,EAAad,EAAK,QAAQ,OAASN,EAAY,SAG/C,CAAE,WAAYqB,EAAe,QAASC,CAAc,EAAIzB,EAAgB,CAC5E,UAAU0B,EAAc,CACtB,GAAI,CAACA,EAAc,CACjBV,EAAaN,GAAM,WAAW,EAC9B,MACF,CAEA,MAAMiB,EAAOD,GAAc,MAAQA,EAC/BC,GAAM,IACRb,EAAca,EAAK,EAAE,EACrBP,EAAgBD,GAAS,OAAO,GAEhCS,EAAkBF,EAAa,IAAI,CAEvC,EACA,QAAQG,EAAO,CACbb,EAAaa,EA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eACN,SAAU,mBACV,QAAS,KACT,IAAK,OACP,EACAY,EAAe,CACb,QAAS,KAAK,KAAK,UAAUK,CAAc,CAAC,EAC5C,QAAS,OAAO3B,EAAK,MAAM,EAAE,CAC/B,CAAC,CACH,CACF,EAAG,CAACA,EAAMU,EAASM,EAAeM,EAAgBT,EAAUC,EAAYb,EAAK,cAAeW,EAAI,SAAS,CAAC,EAE1G,OAAAxB,EAAU,IACD,IAAM,CACXqB,EAAY,EAAK,EACjBF,EAAa,EAAE,EACfF,EAAc,MAAS,CACzB,EACC,CAAC,CAAC,EAGHpB,EAACU,EAAA,CACE,GAAGQ,EACJ,OAAQ,CAAC,CAACH,EACV,UAAU,sBACV,gBAAgB,yCAChB,eAAe,wBAEd,UAAAI,GAAc,CAACmB,EACdvC,EAACc,EAAA,CAAsB,KAAME,EAAM,KAAMC,EAAM,SAAUO,EAAU,QAASL,EAAM,QAAS,EAE3FnB,EAACa,EAAA,CAAmB,KAAMG,EAAM,KAAMC,EAAM,QAASsB,EAAS,SAAUf,EAAU,UAAWkB,EAAe,EAE7GpB,GACCtB,EAAC,OAAI,UAAU,0FACb,SAAAA,EAACE,EAAA,CAAK,UAAU,2CAA2C,KAAMoB,EAAW,EAC9E,GAEJ,CAEJ,CAEA,IAAOsB,EAAQ7B",
|
|
6
|
+
"names": ["jsx", "jsxs", "Text", "useCallback", "useEffect", "useState", "useCreditsContext", "useRedeemGoGift", "useRedeemProduct", "AlpcErrorCode", "ConsumeType", "CreditsModalContainer", "gaTrack", "VirtualProductInit", "VirtualProductSuccess", "RedeemVirtualProductModal", "item", "copy", "onError", "props", "giftCardId", "setGiftCardId", "errorInfo", "setErrorInfo", "disabled", "setDisabled", "profile", "fetchCreditInfo", "gtm", "isGoGift", "isGiftCard", "goGiftLoading", "triggerGoGift", "responseData", "data", "handleRedeemError", "error", "productLoading", "triggerProduct", "loading", "code", "errorMsg", "handleConfirm", "defaultAddress", "RedeemVirtualProductModal_default"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as t,jsxs as g}from"react/jsx-runtime";import{useCallback as T,useEffect as P,useState as l}from"react";import{
|
|
1
|
+
import{jsx as t,jsxs as g}from"react/jsx-runtime";import{useCallback as T,useEffect as P,useState as l}from"react";import{Button as k,Checkbox as A,Picture as D,Text as x}from"@anker-in/headless-ui";import{classNames as n,fetcher as I,gaTrack as b,useHeadlessContext as L}from"@anker-in/lib";import r from"js-cookie";import{parse as B}from"query-string";import F from"crypto-js/sha256";import{useCreditsContext as H}from"../context/provider";import{ROUNDED_BRANDS as R}from"../../../constants";import{emailValidate as q}from"../context/utils";import{CreditsModalContainer as O}from"./ModalContainer";const z=()=>{if(typeof window>"u")return{register_source:""};const{search:e,href:a}=window.location||{},o=B(e);return{fbuy_ref_code:r.get("fbuy_ref_code"),affiliate:r.get("affiliate"),ref:r.get("ref_ads"),inviter_code:o.ic||o.inviter_code||r.get("inviter_code"),register_source:o.redirect||r.get("reg_source")||a,deals_type:r.get("deal"),transfer_id:r.get("transfer_id")}};function $({copy:e,onSuccess:a,...o}){const{brand:p,locale:h}=L(),m=R.includes(p),[d,M]=l(!1),[s,v]=l(""),[_,i]=l(""),[C,y]=l(""),[w,N]=l(!1),{profile:c}=H(),S=T(u=>{i(""),v(u.target?.value?.trim())},[]),E=T(async()=>{if(i(""),!s)return i("Please fill in your email");if(!q(s))return i("Invalid email address");if(!d)return i("Please agree to the policy");N(!0);const{register_source:u}=z(),f=await I({locale:h,action:"subscribe",url:"/api/multipass/subscribe/subscribe_emails",method:"POST",body:{email:s,register_source:u,brand:p,deals_type:e.dealsType||"vip_subscribe"},headers:{},type:""});N(!1),f.errors?i(f.errors||f.statusText):(y(e.successTips||"Subscribed successfully!"),a&&a(),setTimeout(()=>{y("")},3e3),b({subscribe_hashed_email:s?F(s):""}),b({event:"ga4Event",event_name:"subscribe",event_parameters:{page_group:e.dealsType||"vip_subscribe",position:"pop_up"}}),b({event:"uaEvent",eventCategory:"subscribe",eventAction:e.dealsType||"vip_subscribe",eventLabel:"pop_up",nonInteraction:!1}))},[s,d,h,p,e.dealsType,e.successTips,a]);return P(()=>{c&&c?.email&&v(c?.email)},[c]),t(O,{className:"w-[540px] md:h-auto",scrollClassName:"mb-[40px] min-l:px-[48px] md:mb-[24px]",titleClassName:"h-[56px]",useAnimation:!0,animationClassName:"md:translate-y-[100vh]",...o,children:g("div",{className:"min-l:px-[16px] flex flex-col gap-[16px] text-center",children:[t("div",{children:t(x,{className:n("mb-[24px] text-[22px] font-bold"),html:e.title})}),e.desc&&t(x,{className:"mb-[8px] text-left text-[16px] font-semibold leading-[1.4] text-[#1F2021]",html:e.desc}),g("div",{className:n("relative flex h-[52px] w-full overflow-hidden rounded-[2px] md:grid md:h-auto md:grid-rows-1 md:gap-[16px]",!m&&"rounded-none"),children:[t("input",{className:n("h-full flex-1 rounded-l-[2px] border-[1px] border-[#d8d8d8] px-[14px] py-[17px] text-[16px] font-semibold leading-[1] outline-none placeholder:text-[#999] md:h-[52px] md:rounded-[2px]",!m&&"rounded-none"),placeholder:e.placeholder,value:s,onChange:S}),t(k,{variant:"primary",onClick:E,loading:w,className:n("legacy-headless-ui-primary-button !h-full !min-w-0 !rounded-l-none !rounded-r-[2px] !px-[40px] !py-[13px]",!m&&"rounded-none"),children:t(D,{source:"https://cdn.shopify.com/s/files/1/0512/8568/8505/files/icon_email.png?v=1697527383",className:"size-[24px]",alt:"email"})})]}),g("div",{className:"flex w-full",children:[t(A,{checked:d,onCheckedChange:()=>M(!d),required:!0,className:"border-[#1d1d1f]"}),t("label",{className:"ml-2 text-left text-[14px] font-semibold text-[#777] [&_a]:underline",dangerouslySetInnerHTML:{__html:e?.policy||""}})]}),t("div",{className:n("w-full text-left text-[16px] font-semibold",_&&"text-[#F84D4F]",C&&"text-[#52C41A]"),children:t(x,{html:C||_||""})})]})})}export{$ as CreditsSubscribeModal};
|
|
2
2
|
//# sourceMappingURL=SubscribeModal.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/components/credits/modal/SubscribeModal.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["jsx", "jsxs", "useCallback", "useEffect", "useState", "
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport { Button, Checkbox, Picture, Text } from '@anker-in/headless-ui'\nimport { classNames, fetcher, gaTrack, useHeadlessContext } from '@anker-in/lib'\nimport Cookies from 'js-cookie'\nimport { parse } from 'query-string'\nimport sha256 from 'crypto-js/sha256'\nimport { useCreditsContext } from '../context/provider'\nimport { ROUNDED_BRANDS } from '../../../constants'\nimport { emailValidate } from '../context/utils'\nimport { CreditsModalContainer, type ModalContainerProps } from './ModalContainer'\n\nexport type CreditsSubscribeModalCopy = {\n title: string\n desc?: string\n placeholder: string\n policy?: string\n successTips?: string\n dealsType?: string\n}\n\ninterface CreditsSubscribeModalProps extends ModalContainerProps {\n copy: CreditsSubscribeModalCopy\n onSuccess?: () => void\n}\n\nconst getAdCookie = () => {\n if (typeof window === 'undefined') {\n return { register_source: '' }\n }\n const { search, href } = window.location || {}\n const query = parse(search)\n\n return {\n fbuy_ref_code: Cookies.get('fbuy_ref_code'),\n affiliate: Cookies.get('affiliate'),\n ref: Cookies.get('ref_ads'),\n inviter_code: query.ic || query.inviter_code || Cookies.get('inviter_code'),\n register_source: query.redirect || Cookies.get('reg_source') || href,\n deals_type: Cookies.get('deal'),\n transfer_id: Cookies.get('transfer_id'),\n }\n}\n\nexport function CreditsSubscribeModal({ copy, onSuccess, ...props }: CreditsSubscribeModalProps) {\n const { brand, locale } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n const [policy, setPolicy] = useState(false)\n const [email, setEmail] = useState('')\n const [errorMessage, setErrorMessage] = useState('')\n const [successMessage, setSuccessMessage] = useState('')\n const [loading, setLoading] = useState(false)\n const { profile } = useCreditsContext()\n\n const handleEmailChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {\n setErrorMessage('')\n setEmail(event.target?.value?.trim())\n }, [])\n\n const handleSubmit = useCallback(async () => {\n setErrorMessage('')\n if (!email) {\n return setErrorMessage('Please fill in your email')\n }\n\n if (!emailValidate(email)) {\n return setErrorMessage('Invalid email address')\n }\n\n if (!policy) {\n return setErrorMessage('Please agree to the policy')\n }\n\n setLoading(true)\n const { register_source } = getAdCookie()\n\n const result = await fetcher({\n locale,\n action: 'subscribe',\n url: '/api/multipass/subscribe/subscribe_emails',\n method: 'POST',\n body: {\n email,\n register_source,\n brand,\n deals_type: copy.dealsType || 'vip_subscribe',\n },\n headers: {},\n type: '',\n })\n setLoading(false)\n\n if (!result.errors) {\n setSuccessMessage(copy.successTips || 'Subscribed successfully!')\n if (onSuccess) {\n onSuccess()\n }\n setTimeout(() => {\n setSuccessMessage('')\n }, 3000)\n gaTrack({\n subscribe_hashed_email: email ? sha256(email) : '',\n })\n gaTrack({\n event: 'ga4Event',\n event_name: 'subscribe',\n event_parameters: {\n page_group: copy.dealsType || 'vip_subscribe',\n position: 'pop_up',\n },\n })\n gaTrack({\n event: 'uaEvent',\n eventCategory: 'subscribe',\n eventAction: copy.dealsType || 'vip_subscribe',\n eventLabel: 'pop_up',\n nonInteraction: false,\n })\n } else {\n setErrorMessage(result.errors || result.statusText)\n }\n }, [email, policy, locale, brand, copy.dealsType, copy.successTips, onSuccess])\n\n useEffect(() => {\n if (profile && profile?.email) {\n setEmail(profile?.email)\n }\n }, [profile])\n\n return (\n <CreditsModalContainer\n className=\"w-[540px] md:h-auto\"\n scrollClassName=\"mb-[40px] min-l:px-[48px] md:mb-[24px]\"\n titleClassName=\"h-[56px]\"\n useAnimation\n animationClassName=\"md:translate-y-[100vh]\"\n {...props}\n >\n <div className=\"min-l:px-[16px] flex flex-col gap-[16px] text-center\">\n <div>\n <Text className={classNames('mb-[24px] text-[22px] font-bold')} html={copy.title}></Text>\n </div>\n {copy.desc && (\n <Text\n className=\"mb-[8px] text-left text-[16px] font-semibold leading-[1.4] text-[#1F2021]\"\n html={copy.desc}\n ></Text>\n )}\n <div\n className={classNames(\n 'relative flex h-[52px] w-full overflow-hidden rounded-[2px] md:grid md:h-auto md:grid-rows-1 md:gap-[16px]',\n !rounded && 'rounded-none'\n )}\n >\n <input\n className={classNames(\n 'h-full flex-1 rounded-l-[2px] border-[1px] border-[#d8d8d8] px-[14px] py-[17px] text-[16px] font-semibold leading-[1] outline-none placeholder:text-[#999] md:h-[52px] md:rounded-[2px]',\n !rounded && 'rounded-none'\n )}\n placeholder={copy.placeholder}\n value={email}\n onChange={handleEmailChange}\n />\n <Button\n variant=\"primary\"\n onClick={handleSubmit}\n loading={loading}\n className={classNames(\n 'legacy-headless-ui-primary-button !h-full !min-w-0 !rounded-l-none !rounded-r-[2px] !px-[40px] !py-[13px]',\n !rounded && 'rounded-none'\n )}\n >\n <Picture\n source=\"https://cdn.shopify.com/s/files/1/0512/8568/8505/files/icon_email.png?v=1697527383\"\n className=\"size-[24px]\"\n alt=\"email\"\n />\n </Button>\n </div>\n <div className=\"flex w-full\">\n <Checkbox checked={policy} onCheckedChange={() => setPolicy(!policy)} required className=\"border-[#1d1d1f]\" />\n <label\n className=\"ml-2 text-left text-[14px] font-semibold text-[#777] [&_a]:underline\"\n dangerouslySetInnerHTML={{\n __html: copy?.policy || '',\n }}\n />\n </div>\n <div\n className={classNames(\n 'w-full text-left text-[16px] font-semibold',\n errorMessage && 'text-[#F84D4F]',\n successMessage && 'text-[#52C41A]'\n )}\n >\n <Text html={successMessage || errorMessage || ''} />\n </div>\n </div>\n </CreditsModalContainer>\n )\n}\n"],
|
|
5
|
+
"mappings": "AA2IU,cAAAA,EAQF,QAAAC,MARE,oBA3IV,OAAS,eAAAC,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QACjD,OAAS,UAAAC,EAAQ,YAAAC,EAAU,WAAAC,EAAS,QAAAC,M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A,CACC,UAAU,sBACV,gBAAgB,yCAChB,eAAe,WACf,aAAY,GACZ,mBAAmB,yBAClB,GAAGQ,EAEJ,SAAA1B,EAAC,OAAI,UAAU,uDACb,UAAAD,EAAC,OACC,SAAAA,EAACQ,EAAA,CAAK,UAAWC,EAAW,iCAAiC,EAAG,KAAMgB,EAAK,MAAO,EACpF,EACCA,EAAK,MACJzB,EAACQ,EAAA,CACC,UAAU,4EACV,KAAMiB,EAAK,KACZ,EAEHxB,EAAC,OACC,UAAWQ,EACT,6GACA,CAACqB,GAAW,cACd,EAEA,UAAA9B,EAAC,SACC,UAAWS,EACT,0LACA,CAACqB,GAAW,cACd,EACA,YAAaL,EAAK,YAClB,MAAOQ,EACP,SAAUS,EACZ,EACA1C,EAACK,EAAA,CACC,QAAQ,UACR,QAASuC,EACT,QAASL,EACT,UAAW9B,EACT,4GACA,CAACqB,GAAW,cACd,EAEA,SAAA9B,EAACO,EAAA,CACC,OAAO,qFACP,UAAU,cACV,IAAI,QACN,EACF,GACF,EACAN,EAAC,OAAI,UAAU,cACb,UAAAD,EAACM,EAAA,CAAS,QAASyB,EAAQ,gBAAiB,IAAMC,EAAU,CAACD,CAAM,EAAG,SAAQ,GAAC,UAAU,mBAAmB,EAC5G/B,EAAC,SACC,UAAU,uEACV,wBAAyB,CACvB,OAAQyB,GAAM,QAAU,EAC1B,EACF,GACF,EACAzB,EAAC,OACC,UAAWS,EACT,6CACA0B,GAAgB,iBAChBE,GAAkB,gBACpB,EAEA,SAAArC,EAACQ,EAAA,CAAK,KAAM6B,GAAkBF,GAAgB,GAAI,EACpD,GACF,EACF,CAEJ",
|
|
6
|
+
"names": ["jsx", "jsxs", "useCallback", "useEffect", "useState", "Button", "Checkbox", "Picture", "Text", "classNames", "fetcher", "gaTrack", "useHeadlessContext", "Cookies", "parse", "sha256", "useCreditsContext", "ROUNDED_BRANDS", "emailValidate", "CreditsModalContainer", "getAdCookie", "search", "href", "query", "CreditsSubscribeModal", "copy", "onSuccess", "props", "brand", "locale", "rounded", "policy", "setPolicy", "email", "setEmail", "errorMessage", "setErrorMessage", "successMessage", "setSuccessMessage", "loading", "setLoading", "profile", "handleEmailChange", "event", "handleSubmit", "register_source", "result"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as n,jsxs as _}from"react/jsx-runtime";import{Button as W,Text as l}from"@anker-in/headless-ui";import{useSendEmailValidation as X,gaTrack as H,classNames as L,useHeadlessContext as Y,useEmailValidation as Z,useCountDown as y}from"@anker-in/lib";import{useCallback as V,useEffect as C,useRef as ee,useState as p}from"react";import{Message as te}from"./Message";import{useRegistration as ae}from"../context";import{RegistrationModalContainer as ne}from"../modalContainer";import{ROUNDED_BRANDS as se}from"../../../constants";const pe=({copy:t})=>{const{locale:B,brand:$}=Y(),{email:i,authCodeActivate:f}=ae(),F=se.includes($),{activeToken:E,setActiveToken:O,setIsSendingActivateEmail:k,setIsActivateSuccess:P,onAuthSuccess:b,autoSendEmail:M}=f,{isMutating:j,trigger:z}=Z(),{isMutating:w,trigger:h,data:x}=X(),[K,c]=p(""),[U,u]=p(""),{startCountDown:D,startAction:I,countDown:q}=y(60),[R,d]=p(""),[N,m]=p(0),[s,S]=p(new Array(6).fill("")),T=ee([]),v=s.join("");C(()=>{T.current[N]&&T.current[N].focus()},[N]),C(()=>{const o=x?.data?.data?.active_token??x?.data?.active_token;o&&O(o)},[x?.data?.data?.active_token,x?.data?.active_token]),C(()=>{k(w)},[w,k]),C(()=>{M&&i&&h({email:i,data:{redirect_url:`${window?.location?.origin}${window?.location?.pathname}`}},{onSuccess:()=>{u("success"),c(t?.sendEmailSuccessMessage||""),I(),setTimeout(()=>{u(""),c("")},5e3)}})},[M,i,h]);const G=V(async()=>{i&&(await h({email:i,data:{redirect_url:`${window?.location?.origin}${window?.location?.pathname}`}},{onSuccess:()=>{u("success"),c(t?.sendEmailSuccessMessage||""),I(),setTimeout(()=>{u(""),c("")},5e3)}}),H({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"sent_again"}}))},[i,h]),J=(o,e)=>{const{value:a}=o.target;if(d(""),Number.isNaN(Number(a)))return;if(a.length>1){e<s.length-1&&(s[e+1]||(m(e+1),S(g=>{const A=[...g];return A[e]=a[0],a.length>1&&(A[e+1]=a[1]),A})));return}const r=[...s];r[e]=a,S(r),a?e<s.length-1&&!s[e+1]&&m(e+1):e>0&&m(e-1)},Q=V(async()=>{if(!v?.length){d(t?.codeEmptyError||"");return}if(v.length<6){d(t?.incorrectCodeError||"");return}E&&await z({token:E,code:v},{onSuccess:e=>{if(e.status>=200&&e.status<300)u("success"),c(t?.authSuccessMessage||""),P(!0),b?b():setTimeout(()=>{f.close(),window.location.reload()},3e3);else{const a=e?.data?.error_code??e?.error_code;a==="104"?b?b():setTimeout(()=>{f.close(),window.location.reload()},3e3):d(a==="142"?t?.incorrectCodeError||"Invalid verification code.":a==="154"?t?.expiredCodeMessage||"":t?.sendEmailErrorMessage||"")}}});let o=setTimeout(()=>{u(""),c(""),clearTimeout(o)},5e3);H({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"check_and_active"}})},[v,t?.codeEmptyError,t?.authSuccessMessage,t?.incorrectCodeError,t?.expiredCodeMessage,t?.sendEmailErrorMessage,B,E]);return n(ne,{isOpen:f.isOpen,onClose:f.close,children:_("div",{className:"relative",children:[_("div",{children:[n(l,{className:"text-[22px] font-extrabold leading-[120%] text-[#333] min-l:text-[24px] [&_abbr]:text-[#005d8e]",html:t?.authCodeTitle}),n(l,{as:"p",className:"mt-3 text-[14px] font-semibold leading-[140%] text-[rgba(51,51,51,0.75)] min-l:text-base [&_abbr]:text-[#333]",html:t?.authCodeDesc?.replace("%email%",i||"")})]}),_("div",{className:"mt-6",children:[n(l,{className:"mt-4 text-[14px] !font-bold font-semibold leading-[140%] text-[#333] min-l:mt-6",html:t?.enterActiveCodeText}),n("div",{className:"my-3 grid grid-cols-6 gap-2",children:s.map((o,e)=>n("div",{className:"col-span-1 aspect-1 text-[#555]",children:n("input",{ref:a=>{a&&(T.current[e]=a)},type:"tel",className:L("flex size-full items-center justify-center border border-[#333333]/20 bg-[#EEEEEE] text-center text-[24px] font-medium focus:border-[#333]/50 [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none [&:focus-visible]:outline-none",F&&"rounded-[12px]"),value:o,autoComplete:"false",autoCorrect:"false",spellCheck:"false",autoCapitalize:"false",onChange:a=>J(a,e),onFocus:()=>{m(e)},onPaste:a=>{const r=a.clipboardData.getData("text");if(!Number.isNaN(Number(r))){const g=r.split("").slice(0,6);S(g.concat(Array(6-g.length).fill(""))),g.length<=s.length&&m(g.length-1)}},onKeyDown:a=>{const{value:r}=a.target;a.key==="Backspace"&&!r&&e>0&&m(e-1)}},e)},e))}),R&&n(l,{className:"mb-3 text-[14px] font-semibold leading-[120%] text-[#f84d4f]",html:R}),t?.authCodeContent&&n("ul",{className:'flex flex-col gap-1 [&_li]:flex [&_li]:gap-2 [&_li]:text-[14px] [&_li]:font-semibold [&_li]:leading-[120%] [&_li]:text-[rgba(51,51,51,0.55)] [&_li]:before:content-["\u2022"]',dangerouslySetInnerHTML:{__html:t?.authCodeContent}})]}),_("div",{className:"mt-4 min-l:mt-6",children:[n(l,{className:"text-base font-semibold leading-[100%] text-[#333]",html:t?.authCodeReceiveText})," ",D?n(l,{html:t?.retrieveText?.replace("%countdownTime%",q.toString()),className:"cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline"}):n(l,{onClick:G,className:L("cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline",{"pointer-events-none":D||w}),html:t?.sendAgainText}),n(W,{type:"submit",loading:j,className:"mt-6 flex h-[54px] w-full cursor-pointer items-center justify-center px-8 py-[15px] text-center text-base font-bold leading-[100%] text-white min-l:mt-8",onClick:Q,children:t.buttonText})]}),n(te,{status:U,message:K})]})})};export{pe as AuthCodeActivate};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/components/registration/authCodeActivate/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Button, Text } from '@anker-in/headless-ui'\nimport {\n useSendEmailValidation,\n gaTrack,\n classNames as cn,\n useHeadlessContext,\n useEmailValidation,\n useCountDown,\n} from '@anker-in/lib'\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { Message } from './Message'\nimport { AuthCodeActivateProps } from './type'\nimport { useRegistration } from '../context'\nimport { RegistrationModalContainer } from '../modalContainer'\nimport { ROUNDED_BRANDS } from '../../../constants'\n\nexport const AuthCodeActivate: React.FC<AuthCodeActivateProps> = ({ copy }) => {\n const { locale, brand } = useHeadlessContext()\n const { email, authCodeActivate } = useRegistration()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const { activeToken, setActiveToken, setIsSendingActivateEmail, setIsActivateSuccess, onAuthSuccess, autoSendEmail } =\n authCodeActivate\n\n const { isMutating: emailValidationLoading, trigger: triggerEmailValidation } = useEmailValidation()\n\n const {\n isMutating: isSendingEmail,\n trigger: triggerSendValidationEmail,\n data: sendEmailData,\n } = useSendEmailValidation()\n\n const [messageText, setMessageText] = useState('')\n const [messageStatus, setMessageStatus] = useState('')\n const { startCountDown: isStartCountDown, startAction: startCountDown, countDown } = useCountDown(60)\n\n const [error, setError] = useState('')\n const [focusIndex, setFocusIndex] = useState(0)\n const [codeArray, setCodeArray] = useState(new Array(6).fill(''))\n\n const inputRefs = useRef<HTMLInputElement[]>([])\n const code = codeArray.join('')\n\n useEffect(() => {\n if (inputRefs.current[focusIndex]) {\n inputRefs.current[focusIndex].focus()\n }\n }, [focusIndex])\n\n useEffect(() => {\n if (sendEmailData?.data?.data?.active_token) {\n setActiveToken(sendEmailData.data.data.active_token)\n }\n }, [sendEmailData?.data?.data?.active_token])\n\n useEffect(() => {\n setIsSendingActivateEmail(isSendingEmail)\n }, [isSendingEmail, setIsSendingActivateEmail])\n\n // \u81EA\u52A8\u53D1\u9001\u90AE\u7BB1\u9A8C\u8BC1\u7801\n useEffect(() => {\n if (autoSendEmail && email) {\n triggerSendValidationEmail(\n {\n email: email,\n data: {\n redirect_url: `${window?.location?.origin}${window?.location?.pathname}`,\n },\n },\n {\n onSuccess: () => {\n setMessageStatus('success')\n setMessageText(copy?.sendEmailSuccessMessage || '')\n startCountDown()\n setTimeout(() => {\n setMessageStatus('')\n setMessageText('')\n }, 5000)\n },\n }\n )\n }\n }, [autoSendEmail, email, triggerSendValidationEmail])\n\n const handleSendAgain = useCallback(async () => {\n if (!email) return\n // \u53D1\u8D77\u7F51\u7EDC\u8BF7\u6C42\n await triggerSendValidationEmail(\n {\n email: email,\n data: {\n redirect_url: `${window?.location?.origin}${window?.location?.pathname}`,\n },\n },\n {\n onSuccess: () => {\n setMessageStatus('success')\n setMessageText(copy?.sendEmailSuccessMessage || '')\n startCountDown()\n setTimeout(() => {\n setMessageStatus('')\n setMessageText('')\n }, 5000)\n },\n }\n )\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n page_group: 'reg_sub_pop',\n position: 'auth_code',\n button_name: 'sent_again',\n },\n })\n }, [email, triggerSendValidationEmail])\n\n const handleInputCodeChange = (event: React.ChangeEvent<HTMLInputElement>, index: number) => {\n const { value } = event.target\n\n setError('')\n\n if (Number.isNaN(Number(value))) {\n return\n }\n\n if (value.length > 1) {\n if (index < codeArray.length - 1) {\n if (!codeArray[index + 1]) {\n setFocusIndex(index + 1)\n setCodeArray(old => {\n const newCode = [...old]\n newCode[index] = value[0]\n if (value.length > 1) {\n newCode[index + 1] = value[1]\n }\n return newCode\n })\n }\n }\n return\n }\n const newCode = [...codeArray]\n newCode[index] = value\n setCodeArray(newCode)\n if (value) {\n if (index < codeArray.length - 1 && !codeArray[index + 1]) {\n setFocusIndex(index + 1)\n }\n } else if (index > 0) {\n setFocusIndex(index - 1)\n }\n }\n\n const handleAuthCodeSubmit = useCallback(async () => {\n if (!code?.length) {\n setError(copy?.codeEmptyError || '')\n return\n }\n\n if (code.length < 6) {\n setError(copy?.incorrectCodeError || '')\n return\n }\n\n if (activeToken) {\n await triggerEmailValidation(\n {\n token: activeToken,\n code: code,\n },\n {\n onSuccess: data => {\n if (data.status >= 200 && data.status < 300) {\n setMessageStatus('success')\n setMessageText(copy?.authSuccessMessage || '')\n setIsActivateSuccess(true)\n if (onAuthSuccess) {\n onAuthSuccess()\n } else {\n setTimeout(() => {\n authCodeActivate.close()\n window.location.reload()\n }, 3000)\n }\n } else {\n if (data?.data?.error_code === '104') {\n if (onAuthSuccess) {\n onAuthSuccess()\n } else {\n setTimeout(() => {\n authCodeActivate.close()\n window.location.reload()\n }, 3000)\n }\n } else if (data?.data?.error_code === '142') {\n setError(copy?.incorrectCodeError || 'Invalid verification code.')\n } else if (data?.data?.error_code === '154') {\n setError(copy?.expiredCodeMessage || '')\n } else {\n setError(copy?.sendEmailErrorMessage || '')\n }\n }\n },\n }\n )\n }\n\n // \u8BBE\u7F6E\u5B9A\u65F6\u5668\u6E05\u9664\u72B6\u6001\u4FE1\u606F\n let timer = setTimeout(() => {\n setMessageStatus('')\n setMessageText('')\n clearTimeout(timer)\n }, 5000)\n\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n page_group: 'reg_sub_pop',\n position: 'auth_code',\n button_name: 'check_and_active',\n },\n })\n }, [\n code,\n copy?.codeEmptyError,\n copy?.authSuccessMessage,\n copy?.incorrectCodeError,\n copy?.expiredCodeMessage,\n copy?.sendEmailErrorMessage,\n locale,\n activeToken,\n ])\n\n return (\n <RegistrationModalContainer isOpen={authCodeActivate.isOpen} onClose={authCodeActivate.close}>\n <div className=\"relative\">\n <div>\n <Text\n className=\"text-[22px] font-extrabold leading-[120%] text-[#333] min-l:text-[24px] [&_abbr]:text-[#005d8e]\"\n html={copy?.authCodeTitle}\n />\n <Text\n as=\"p\"\n className=\"mt-3 text-[14px] font-semibold leading-[140%] text-[rgba(51,51,51,0.75)] min-l:text-base [&_abbr]:text-[#333]\"\n html={copy?.authCodeDesc?.replace('%email%', email || '')}\n />\n </div>\n <div className=\"mt-6\">\n <Text\n className=\"mt-4 text-[14px] !font-bold font-semibold leading-[140%] text-[#333] min-l:mt-6\"\n html={copy?.enterActiveCodeText}\n />\n <div className=\"my-3 grid grid-cols-6 gap-2\">\n {codeArray.map((item, index) => (\n <div key={index} className=\"col-span-1 aspect-1 text-[#555]\">\n <input\n ref={inputRef => {\n if (inputRef) {\n inputRefs.current[index] = inputRef\n }\n }}\n key={index}\n type=\"tel\"\n className={cn(\n 'flex size-full items-center justify-center border border-[#333333]/20 bg-[#EEEEEE] text-center text-[24px] font-medium focus:border-[#333]/50 [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none [&:focus-visible]:outline-none',\n rounded && 'rounded-[12px]'\n )}\n value={item}\n autoComplete=\"false\"\n autoCorrect=\"false\"\n spellCheck=\"false\"\n autoCapitalize=\"false\"\n onChange={event => handleInputCodeChange(event, index)}\n onFocus={() => {\n setFocusIndex(index)\n }}\n onPaste={event => {\n const paste = event.clipboardData.getData('text')\n if (!Number.isNaN(Number(paste))) {\n const pastedCode = paste.split('').slice(0, 6)\n setCodeArray(pastedCode.concat(Array(6 - pastedCode.length).fill('')))\n if (pastedCode.length <= codeArray.length) {\n setFocusIndex(pastedCode.length - 1)\n }\n }\n }}\n onKeyDown={event => {\n const { value } = event.target as HTMLInputElement\n if (event.key === 'Backspace' && !value && index > 0) {\n setFocusIndex(index - 1)\n }\n }}\n />\n </div>\n ))}\n </div>\n\n {error && <Text className=\"mb-3 text-[14px] font-semibold leading-[120%] text-[#f84d4f]\" html={error} />}\n {copy?.authCodeContent && (\n <ul\n className='flex flex-col gap-1 [&_li]:flex [&_li]:gap-2 [&_li]:text-[14px] [&_li]:font-semibold [&_li]:leading-[120%] [&_li]:text-[rgba(51,51,51,0.55)] [&_li]:before:content-[\"\u2022\"]'\n dangerouslySetInnerHTML={{ __html: copy?.authCodeContent }}\n />\n )}\n </div>\n <div className=\"mt-4 min-l:mt-6\">\n <Text className=\"text-base font-semibold leading-[100%] text-[#333]\" html={copy?.authCodeReceiveText} />{' '}\n {isStartCountDown ? (\n <Text\n html={copy?.retrieveText?.replace('%countdownTime%', countDown.toString())}\n className=\"cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline\"\n />\n ) : (\n <Text\n onClick={handleSendAgain}\n className={cn(\n 'cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline',\n {\n 'pointer-events-none': isStartCountDown || isSendingEmail,\n }\n )}\n html={copy?.sendAgainText}\n />\n )}\n <Button\n type=\"submit\"\n loading={emailValidationLoading}\n className=\"mt-6 flex h-[54px] w-full cursor-pointer items-center justify-center px-8 py-[15px] text-center text-base font-bold leading-[100%] text-white min-l:mt-8\"\n onClick={handleAuthCodeSubmit}\n >\n {copy.buttonText}\n </Button>\n </div>\n <Message status={messageStatus} message={messageText} />\n </div>\n </RegistrationModalContainer>\n )\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["jsx", "jsxs", "Button", "Text", "useSendEmailValidation", "gaTrack", "cn", "useHeadlessContext", "useEmailValidation", "useCountDown", "useCallback", "useEffect", "useRef", "useState", "Message", "useRegistration", "RegistrationModalContainer", "ROUNDED_BRANDS", "AuthCodeActivate", "copy", "locale", "brand", "email", "authCodeActivate", "rounded", "activeToken", "setActiveToken", "setIsSendingActivateEmail", "setIsActivateSuccess", "onAuthSuccess", "autoSendEmail", "emailValidationLoading", "triggerEmailValidation", "isSendingEmail", "triggerSendValidationEmail", "sendEmailData", "messageText", "setMessageText", "messageStatus", "setMessageStatus", "isStartCountDown", "startCountDown", "countDown", "error", "setError", "focusIndex", "setFocusIndex", "codeArray", "setCodeArray", "inputRefs", "code", "handleSendAgain", "handleInputCodeChange", "event", "index", "value", "old", "newCode", "handleAuthCodeSubmit", "data", "timer", "item", "inputRef", "paste", "pastedCode"]
|
|
4
|
+
"sourcesContent": ["import { Button, Text } from '@anker-in/headless-ui'\nimport {\n useSendEmailValidation,\n gaTrack,\n classNames as cn,\n useHeadlessContext,\n useEmailValidation,\n useCountDown,\n} from '@anker-in/lib'\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { Message } from './Message'\nimport { AuthCodeActivateProps } from './type'\nimport { useRegistration } from '../context'\nimport { RegistrationModalContainer } from '../modalContainer'\nimport { ROUNDED_BRANDS } from '../../../constants'\n\nexport const AuthCodeActivate: React.FC<AuthCodeActivateProps> = ({ copy }) => {\n const { locale, brand } = useHeadlessContext()\n const { email, authCodeActivate } = useRegistration()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const { activeToken, setActiveToken, setIsSendingActivateEmail, setIsActivateSuccess, onAuthSuccess, autoSendEmail } =\n authCodeActivate\n\n const { isMutating: emailValidationLoading, trigger: triggerEmailValidation } = useEmailValidation()\n\n const {\n isMutating: isSendingEmail,\n trigger: triggerSendValidationEmail,\n data: sendEmailData,\n } = useSendEmailValidation()\n\n const [messageText, setMessageText] = useState('')\n const [messageStatus, setMessageStatus] = useState('')\n const { startCountDown: isStartCountDown, startAction: startCountDown, countDown } = useCountDown(60)\n\n const [error, setError] = useState('')\n const [focusIndex, setFocusIndex] = useState(0)\n const [codeArray, setCodeArray] = useState(new Array(6).fill(''))\n\n const inputRefs = useRef<HTMLInputElement[]>([])\n const code = codeArray.join('')\n\n useEffect(() => {\n if (inputRefs.current[focusIndex]) {\n inputRefs.current[focusIndex].focus()\n }\n }, [focusIndex])\n\n useEffect(() => {\n const token = sendEmailData?.data?.data?.active_token ?? sendEmailData?.data?.active_token\n if (token) {\n setActiveToken(token)\n }\n }, [sendEmailData?.data?.data?.active_token, sendEmailData?.data?.active_token])\n\n useEffect(() => {\n setIsSendingActivateEmail(isSendingEmail)\n }, [isSendingEmail, setIsSendingActivateEmail])\n\n // \u81EA\u52A8\u53D1\u9001\u90AE\u7BB1\u9A8C\u8BC1\u7801\n useEffect(() => {\n if (autoSendEmail && email) {\n triggerSendValidationEmail(\n {\n email: email,\n data: {\n redirect_url: `${window?.location?.origin}${window?.location?.pathname}`,\n },\n },\n {\n onSuccess: () => {\n setMessageStatus('success')\n setMessageText(copy?.sendEmailSuccessMessage || '')\n startCountDown()\n setTimeout(() => {\n setMessageStatus('')\n setMessageText('')\n }, 5000)\n },\n }\n )\n }\n }, [autoSendEmail, email, triggerSendValidationEmail])\n\n const handleSendAgain = useCallback(async () => {\n if (!email) return\n // \u53D1\u8D77\u7F51\u7EDC\u8BF7\u6C42\n await triggerSendValidationEmail(\n {\n email: email,\n data: {\n redirect_url: `${window?.location?.origin}${window?.location?.pathname}`,\n },\n },\n {\n onSuccess: () => {\n setMessageStatus('success')\n setMessageText(copy?.sendEmailSuccessMessage || '')\n startCountDown()\n setTimeout(() => {\n setMessageStatus('')\n setMessageText('')\n }, 5000)\n },\n }\n )\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n page_group: 'reg_sub_pop',\n position: 'auth_code',\n button_name: 'sent_again',\n },\n })\n }, [email, triggerSendValidationEmail])\n\n const handleInputCodeChange = (event: React.ChangeEvent<HTMLInputElement>, index: number) => {\n const { value } = event.target\n\n setError('')\n\n if (Number.isNaN(Number(value))) {\n return\n }\n\n if (value.length > 1) {\n if (index < codeArray.length - 1) {\n if (!codeArray[index + 1]) {\n setFocusIndex(index + 1)\n setCodeArray(old => {\n const newCode = [...old]\n newCode[index] = value[0]\n if (value.length > 1) {\n newCode[index + 1] = value[1]\n }\n return newCode\n })\n }\n }\n return\n }\n const newCode = [...codeArray]\n newCode[index] = value\n setCodeArray(newCode)\n if (value) {\n if (index < codeArray.length - 1 && !codeArray[index + 1]) {\n setFocusIndex(index + 1)\n }\n } else if (index > 0) {\n setFocusIndex(index - 1)\n }\n }\n\n const handleAuthCodeSubmit = useCallback(async () => {\n if (!code?.length) {\n setError(copy?.codeEmptyError || '')\n return\n }\n\n if (code.length < 6) {\n setError(copy?.incorrectCodeError || '')\n return\n }\n\n if (activeToken) {\n await triggerEmailValidation(\n {\n token: activeToken,\n code: code,\n },\n {\n onSuccess: data => {\n if (data.status >= 200 && data.status < 300) {\n setMessageStatus('success')\n setMessageText(copy?.authSuccessMessage || '')\n setIsActivateSuccess(true)\n if (onAuthSuccess) {\n onAuthSuccess()\n } else {\n setTimeout(() => {\n authCodeActivate.close()\n window.location.reload()\n }, 3000)\n }\n } else {\n const errorCode = data?.data?.error_code ?? data?.error_code\n if (errorCode === '104') {\n if (onAuthSuccess) {\n onAuthSuccess()\n } else {\n setTimeout(() => {\n authCodeActivate.close()\n window.location.reload()\n }, 3000)\n }\n } else if (errorCode === '142') {\n setError(copy?.incorrectCodeError || 'Invalid verification code.')\n } else if (errorCode === '154') {\n setError(copy?.expiredCodeMessage || '')\n } else {\n setError(copy?.sendEmailErrorMessage || '')\n }\n }\n },\n }\n )\n }\n\n // \u8BBE\u7F6E\u5B9A\u65F6\u5668\u6E05\u9664\u72B6\u6001\u4FE1\u606F\n let timer = setTimeout(() => {\n setMessageStatus('')\n setMessageText('')\n clearTimeout(timer)\n }, 5000)\n\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n page_group: 'reg_sub_pop',\n position: 'auth_code',\n button_name: 'check_and_active',\n },\n })\n }, [\n code,\n copy?.codeEmptyError,\n copy?.authSuccessMessage,\n copy?.incorrectCodeError,\n copy?.expiredCodeMessage,\n copy?.sendEmailErrorMessage,\n locale,\n activeToken,\n ])\n\n return (\n <RegistrationModalContainer isOpen={authCodeActivate.isOpen} onClose={authCodeActivate.close}>\n <div className=\"relative\">\n <div>\n <Text\n className=\"text-[22px] font-extrabold leading-[120%] text-[#333] min-l:text-[24px] [&_abbr]:text-[#005d8e]\"\n html={copy?.authCodeTitle}\n />\n <Text\n as=\"p\"\n className=\"mt-3 text-[14px] font-semibold leading-[140%] text-[rgba(51,51,51,0.75)] min-l:text-base [&_abbr]:text-[#333]\"\n html={copy?.authCodeDesc?.replace('%email%', email || '')}\n />\n </div>\n <div className=\"mt-6\">\n <Text\n className=\"mt-4 text-[14px] !font-bold font-semibold leading-[140%] text-[#333] min-l:mt-6\"\n html={copy?.enterActiveCodeText}\n />\n <div className=\"my-3 grid grid-cols-6 gap-2\">\n {codeArray.map((item, index) => (\n <div key={index} className=\"col-span-1 aspect-1 text-[#555]\">\n <input\n ref={inputRef => {\n if (inputRef) {\n inputRefs.current[index] = inputRef\n }\n }}\n key={index}\n type=\"tel\"\n className={cn(\n 'flex size-full items-center justify-center border border-[#333333]/20 bg-[#EEEEEE] text-center text-[24px] font-medium focus:border-[#333]/50 [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none [&:focus-visible]:outline-none',\n rounded && 'rounded-[12px]'\n )}\n value={item}\n autoComplete=\"false\"\n autoCorrect=\"false\"\n spellCheck=\"false\"\n autoCapitalize=\"false\"\n onChange={event => handleInputCodeChange(event, index)}\n onFocus={() => {\n setFocusIndex(index)\n }}\n onPaste={event => {\n const paste = event.clipboardData.getData('text')\n if (!Number.isNaN(Number(paste))) {\n const pastedCode = paste.split('').slice(0, 6)\n setCodeArray(pastedCode.concat(Array(6 - pastedCode.length).fill('')))\n if (pastedCode.length <= codeArray.length) {\n setFocusIndex(pastedCode.length - 1)\n }\n }\n }}\n onKeyDown={event => {\n const { value } = event.target as HTMLInputElement\n if (event.key === 'Backspace' && !value && index > 0) {\n setFocusIndex(index - 1)\n }\n }}\n />\n </div>\n ))}\n </div>\n\n {error && <Text className=\"mb-3 text-[14px] font-semibold leading-[120%] text-[#f84d4f]\" html={error} />}\n {copy?.authCodeContent && (\n <ul\n className='flex flex-col gap-1 [&_li]:flex [&_li]:gap-2 [&_li]:text-[14px] [&_li]:font-semibold [&_li]:leading-[120%] [&_li]:text-[rgba(51,51,51,0.55)] [&_li]:before:content-[\"\u2022\"]'\n dangerouslySetInnerHTML={{ __html: copy?.authCodeContent }}\n />\n )}\n </div>\n <div className=\"mt-4 min-l:mt-6\">\n <Text className=\"text-base font-semibold leading-[100%] text-[#333]\" html={copy?.authCodeReceiveText} />{' '}\n {isStartCountDown ? (\n <Text\n html={copy?.retrieveText?.replace('%countdownTime%', countDown.toString())}\n className=\"cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline\"\n />\n ) : (\n <Text\n onClick={handleSendAgain}\n className={cn(\n 'cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline',\n {\n 'pointer-events-none': isStartCountDown || isSendingEmail,\n }\n )}\n html={copy?.sendAgainText}\n />\n )}\n <Button\n type=\"submit\"\n loading={emailValidationLoading}\n className=\"mt-6 flex h-[54px] w-full cursor-pointer items-center justify-center px-8 py-[15px] text-center text-base font-bold leading-[100%] text-white min-l:mt-8\"\n onClick={handleAuthCodeSubmit}\n >\n {copy.buttonText}\n </Button>\n </div>\n <Message status={messageStatus} message={messageText} />\n </div>\n </RegistrationModalContainer>\n )\n}\n"],
|
|
5
|
+
"mappings": "AAgPQ,OACE,OAAAA,EADF,QAAAC,MAAA,oBAhPR,OAAS,UAAAC,EAAQ,QAAAC,MAAY,wBAC7B,OACE,0BAAAC,EACA,WAAAC,EACA,cAAcC,EACd,sBAAAC,EACA,sBAAAC,EACA,gBAAAC,MACK,gBACP,OAAgB,eAAAC,EAAa,aAAAC,EAAW,UAAAC,GAAQ,YAAAC,MAAgB,QAChE,OAAS,WAAAC,OAAe,YAExB,OAAS,mBAAAC,OAAuB,aAChC,OAAS,8BAAAC,OAAkC,oBAC3C,OAAS,kBAAAC,OAAsB,qBAExB,MAAMC,GAAoD,CAAC,CAAE,KAAAC,CAAK,IAAM,CAC7E,KAAM,CAAE,OAAAC,EAAQ,MAAAC,CAAM,EAAId,EAAmB,EACvC,CAAE,MAAAe,EAAO,iBA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aAAe,CAACE,GAASD,EAAQ,GACjDT,EAAcS,EAAQ,CAAC,CAE3B,GA9BKA,CA+BP,GAtCQA,CAuCV,CACD,EACH,EAECZ,GAAS3C,EAACG,EAAA,CAAK,UAAU,+DAA+D,KAAMwC,EAAO,EACrGxB,GAAM,iBACLnB,EAAC,MACC,UAAU,gLACV,wBAAyB,CAAE,OAAQmB,GAAM,eAAgB,EAC3D,GAEJ,EACAlB,EAAC,OAAI,UAAU,kBACb,UAAAD,EAACG,EAAA,CAAK,UAAU,qDAAqD,KAAMgB,GAAM,oBAAqB,EAAG,IACxGqB,EACCxC,EAACG,EAAA,CACC,KAAMgB,GAAM,cAAc,QAAQ,kBAAmBuB,EAAU,SAAS,CAAC,EACzE,UAAU,yGACZ,EAEA1C,EAACG,EAAA,CACC,QAASiD,EACT,UAAW9C,EACT,yGACA,CACE,sBAAuBkC,GAAoBP,CAC7C,CACF,EACA,KAAMd,GAAM,cACd,EAEFnB,EAACE,EAAA,CACC,KAAK,SACL,QAAS6B,EACT,UAAU,2JACV,QAAS4B,EAER,SAAAxC,EAAK,WACR,GACF,EACAnB,EAACc,GAAA,CAAQ,OAAQwB,EAAe,QAASF,EAAa,GACxD,EACF,CAEJ",
|
|
6
|
+
"names": ["jsx", "jsxs", "Button", "Text", "useSendEmailValidation", "gaTrack", "cn", "useHeadlessContext", "useEmailValidation", "useCountDown", "useCallback", "useEffect", "useRef", "useState", "Message", "useRegistration", "RegistrationModalContainer", "ROUNDED_BRANDS", "AuthCodeActivate", "copy", "locale", "brand", "email", "authCodeActivate", "rounded", "activeToken", "setActiveToken", "setIsSendingActivateEmail", "setIsActivateSuccess", "onAuthSuccess", "autoSendEmail", "emailValidationLoading", "triggerEmailValidation", "isSendingEmail", "triggerSendValidationEmail", "sendEmailData", "messageText", "setMessageText", "messageStatus", "setMessageStatus", "isStartCountDown", "startCountDown", "countDown", "error", "setError", "focusIndex", "setFocusIndex", "codeArray", "setCodeArray", "inputRefs", "code", "token", "handleSendAgain", "handleInputCodeChange", "event", "index", "value", "old", "newCode", "handleAuthCodeSubmit", "data", "errorCode", "timer", "item", "inputRef", "paste", "pastedCode"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -44,21 +44,22 @@ function useActivities({ page, pageSize, options = {} }: { page: number; pageSiz
|
|
|
44
44
|
trigger(params, {
|
|
45
45
|
onSuccess(responseData) {
|
|
46
46
|
setCurrentPage(page)
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const data = responseData?.data || responseData
|
|
48
|
+
setTotal(data?.total)
|
|
49
|
+
setActivities(activities.concat(data?.creditLogs || []))
|
|
49
50
|
},
|
|
50
51
|
})
|
|
51
52
|
}, [activities, profile, page, pageSize, options, trigger])
|
|
52
53
|
|
|
53
54
|
useEffect(() => {
|
|
54
|
-
if (isLoadingProfile || !profile || isLoading) {
|
|
55
|
+
if (isLoadingProfile || !profile || !brand || isLoading) {
|
|
55
56
|
return
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
if (page !== currentPage && page) {
|
|
59
60
|
getActivities()
|
|
60
61
|
}
|
|
61
|
-
}, [getActivities, isLoadingProfile, isLoading, profile, page, currentPage])
|
|
62
|
+
}, [getActivities, isLoadingProfile, isLoading, profile, brand, page, currentPage])
|
|
62
63
|
|
|
63
64
|
return {
|
|
64
65
|
activities,
|
|
@@ -36,7 +36,7 @@ const fetcher = (options: FetcherOptions) => {
|
|
|
36
36
|
return fetch(getAlpcPath(options.locale) + options.url, options.fetchOptions).then(async response => {
|
|
37
37
|
if (response.status < 300) {
|
|
38
38
|
const responseData = await response.json()
|
|
39
|
-
return responseData
|
|
39
|
+
return responseData
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// 错误处理
|
|
@@ -56,7 +56,7 @@ const fetcher = (options: FetcherOptions) => {
|
|
|
56
56
|
return fetch(getAlpcPath(options.locale) + options.url, options.fetchOptions).then(async response => {
|
|
57
57
|
if (response.status < 300) {
|
|
58
58
|
const responseData = await response.json()
|
|
59
|
-
return responseData
|
|
59
|
+
return responseData
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
if (response.status === 401) {
|
|
@@ -127,7 +127,8 @@ export interface UseMutationConfig<TData> {
|
|
|
127
127
|
const useMutation = <TData, TBody>(
|
|
128
128
|
url: string,
|
|
129
129
|
fetcher: Fetcher<TData, TBody>,
|
|
130
|
-
mutationConfig: UseMutationConfig<TData> = {}
|
|
130
|
+
mutationConfig: UseMutationConfig<TData> = {},
|
|
131
|
+
brandRef: React.MutableRefObject<string | undefined>
|
|
131
132
|
) => {
|
|
132
133
|
const innerMutating = useRef<boolean>(false)
|
|
133
134
|
|
|
@@ -140,7 +141,15 @@ const useMutation = <TData, TBody>(
|
|
|
140
141
|
|
|
141
142
|
const trigger = useCallback(
|
|
142
143
|
async (fetchData: TBody, opts: UseMutationConfig<TData> = {}) => {
|
|
144
|
+
console.log('[useAlpcMutation] trigger called with:', { url: urlRef.current, fetchData, brand: brandRef.current })
|
|
145
|
+
|
|
143
146
|
if (innerMutating.current) {
|
|
147
|
+
console.log('[useAlpcMutation] already mutating, skipping')
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!brandRef.current) {
|
|
152
|
+
console.log('[useAlpcMutation] brand not available, skipping request')
|
|
144
153
|
return
|
|
145
154
|
}
|
|
146
155
|
|
|
@@ -207,7 +216,7 @@ export const useAlpcFetch = <TData>(
|
|
|
207
216
|
|
|
208
217
|
const context = useSWR<TData>(
|
|
209
218
|
[url, requestBody],
|
|
210
|
-
!fetchEnable
|
|
219
|
+
!fetchEnable || !brand
|
|
211
220
|
? null
|
|
212
221
|
: ([requestUrl, data]: [string, Record<string, any>]) =>
|
|
213
222
|
fetcher({
|
|
@@ -256,13 +265,22 @@ export const useAlpcMutation = <TData, TBody>(options: MutationOptions, mutation
|
|
|
256
265
|
const { locale = '', brand: headlessBrand } = useHeadlessContext()
|
|
257
266
|
// 优先使用 creditsContext 中的 alpcBrand,如果没有则使用 headlessConfig 中的 brand
|
|
258
267
|
const brand = alpcBrand || headlessBrand
|
|
268
|
+
const brandRef = useRef(brand)
|
|
269
|
+
brandRef.current = brand
|
|
259
270
|
|
|
260
271
|
const { url, initData, headers, ...fetchOptions } = options
|
|
272
|
+
const initDataRef = useRef(initData)
|
|
273
|
+
initDataRef.current = initData
|
|
261
274
|
|
|
262
275
|
const context = useMutation<TData, TBody>(
|
|
263
276
|
url,
|
|
264
|
-
(requestUrl, data: { arg: TBody }) =>
|
|
265
|
-
|
|
277
|
+
(requestUrl, data: { arg: TBody }) => {
|
|
278
|
+
// Prevent requests when brand is not available
|
|
279
|
+
if (!brandRef.current) {
|
|
280
|
+
return Promise.resolve(undefined as unknown as TData)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return fetcher({
|
|
266
284
|
url: requestUrl,
|
|
267
285
|
locale,
|
|
268
286
|
fetchOptions: {
|
|
@@ -273,12 +291,12 @@ export const useAlpcMutation = <TData, TBody>(options: MutationOptions, mutation
|
|
|
273
291
|
},
|
|
274
292
|
...fetchOptions,
|
|
275
293
|
body: JSON.stringify({
|
|
276
|
-
...
|
|
294
|
+
...initDataRef.current,
|
|
277
295
|
...data.arg,
|
|
278
296
|
}),
|
|
279
297
|
},
|
|
280
298
|
onReAuth: async () => {
|
|
281
|
-
const result = await reAuth(locale, retry,
|
|
299
|
+
const result = await reAuth(locale, retry, brandRef.current!)
|
|
282
300
|
|
|
283
301
|
if (result) {
|
|
284
302
|
setRetry(true)
|
|
@@ -291,8 +309,10 @@ export const useAlpcMutation = <TData, TBody>(options: MutationOptions, mutation
|
|
|
291
309
|
// 失败后退出登录
|
|
292
310
|
removeProfile()
|
|
293
311
|
},
|
|
294
|
-
})
|
|
295
|
-
|
|
312
|
+
})
|
|
313
|
+
},
|
|
314
|
+
mutationOptions,
|
|
315
|
+
brandRef
|
|
296
316
|
)
|
|
297
317
|
|
|
298
318
|
return context
|
|
@@ -13,13 +13,18 @@ function useCountries({ shopifyStoreDomain }: { shopifyStoreDomain: string }) {
|
|
|
13
13
|
const fetchCountries = async () => {
|
|
14
14
|
setLoading(true)
|
|
15
15
|
try {
|
|
16
|
-
const response = await fetch(`/api/multipass/rainbowbridge/uc/shop/shipping_zones?shop=${shopifyStoreDomain}
|
|
16
|
+
const response = await fetch(`/api/multipass/rainbowbridge/uc/shop/shipping_zones?shop=${shopifyStoreDomain}`, {
|
|
17
|
+
headers: {
|
|
18
|
+
'current-language': locale,
|
|
19
|
+
},
|
|
20
|
+
})
|
|
17
21
|
const res: any = await response.json()
|
|
18
22
|
|
|
19
23
|
// 国家过滤
|
|
20
24
|
let shipsToCountries: ShippingCountry[] = []
|
|
21
25
|
const countrySet = new Set()
|
|
22
|
-
res
|
|
26
|
+
const shippingZones = res?.data?.data || res?.data || []
|
|
27
|
+
shippingZones.forEach((shippingZoneItem: ShippingZone) => {
|
|
23
28
|
shippingZoneItem.countries.forEach(shippingZoneCountryItem => {
|
|
24
29
|
if (!countrySet.has(shippingZoneCountryItem.code)) {
|
|
25
30
|
countrySet.add(shippingZoneCountryItem.code)
|
|
@@ -15,7 +15,7 @@ function useMyRewards({
|
|
|
15
15
|
pageSize: number
|
|
16
16
|
consumeType?: AlpcConsumeType
|
|
17
17
|
}) {
|
|
18
|
-
const {
|
|
18
|
+
const { profile, alpcBrand } = useCreditsContext()
|
|
19
19
|
const { brand: headlessBrand, locale, appName } = useHeadlessContext()
|
|
20
20
|
const brand = alpcBrand || headlessBrand
|
|
21
21
|
|
|
@@ -52,16 +52,20 @@ function useMyRewards({
|
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
54
|
onSuccess(responseData) {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const data = responseData?.data || responseData
|
|
56
|
+
setTotal(data?.total)
|
|
57
|
+
setMyRewards(data?.redeem_logs || [])
|
|
57
58
|
},
|
|
58
59
|
}
|
|
59
60
|
)
|
|
60
61
|
}, [consumeType, page, pageSize, profile?.user_id])
|
|
61
62
|
|
|
62
63
|
useEffect(() => {
|
|
64
|
+
if (!brand || !profile?.user_id) {
|
|
65
|
+
return
|
|
66
|
+
}
|
|
63
67
|
getMyRewards()
|
|
64
|
-
}, [getMyRewards])
|
|
68
|
+
}, [getMyRewards, brand])
|
|
65
69
|
|
|
66
70
|
return {
|
|
67
71
|
myRewards,
|
|
@@ -38,9 +38,10 @@ export const useRedeemAndBuy = (
|
|
|
38
38
|
user_id: profile?.user_id,
|
|
39
39
|
rule_id: arg.redeemId,
|
|
40
40
|
})
|
|
41
|
-
|
|
41
|
+
const data = (res?.data || res) as { success?: boolean; coupon_code?: string }
|
|
42
|
+
if (res && data?.coupon_code) {
|
|
42
43
|
buyNow({
|
|
43
|
-
discountCodes: [
|
|
44
|
+
discountCodes: [data.coupon_code],
|
|
44
45
|
lineItems: [
|
|
45
46
|
{
|
|
46
47
|
variant: arg.productVariant,
|