@anker-in/campaign-ui 0.5.0-beta.23 → 0.5.0-beta.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/memberPopup/panels/EarnCredits/ActivatePanel.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/ActivatePanel.js.map +2 -2
- package/dist/cjs/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.js.map +2 -2
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.js.map +2 -2
- package/dist/cjs/components/memberPopup/panels/EarnCredits/index.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/index.js.map +3 -3
- package/dist/esm/components/memberPopup/panels/EarnCredits/ActivatePanel.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/ActivatePanel.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/EarnCredits/index.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/index.js.map +3 -3
- package/package.json +1 -1
- package/src/components/memberPopup/panels/EarnCredits/ActivatePanel.tsx +2 -2
- package/src/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.tsx +1 -1
- package/src/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.tsx +1 -1
- package/src/components/memberPopup/panels/EarnCredits/index.tsx +6 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var S=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var X=(e,i)=>{for(var u in i)S(e,u,{get:i[u],enumerable:!0})},Y=(e,i,u,g)=>{if(i&&typeof i=="object"||typeof i=="function")for(let r of J(i))!Q.call(e,r)&&r!==u&&S(e,r,{get:()=>i[r],enumerable:!(g=G(i,r))||g.enumerable});return e};var Z=e=>Y(S({},"__esModule",{value:!0}),e);var ee={};X(ee,{default:()=>V});module.exports=Z(ee);var n=require("react/jsx-runtime"),o=require("react"),c=require("@anker-in/headless-ui"),s=require("@anker-in/lib"),R=require("../../../registration/authCodeActivate/Message"),H=require("../../../registration"),L=require("../../context/provider"),P=require("../../../../constants");function V({copy:e,onClose:i}){const{setIsActivateSuccess:u,fetchCreditInfo:g,profile:r}=(0,L.useMemberPopupContext)(),{locale:y,brand:B}=(0,s.useHeadlessContext)(),{email:d}=(0,H.useRegistration)(),F=P.ROUNDED_BRANDS.includes(B),{isMutating:$,trigger:C,data:E}=(0,s.useSendEmailValidation)(),{isMutating:j,trigger:k}=(0,s.useEmailValidation)(),[z,f]=(0,o.useState)(""),[W,p]=(0,o.useState)(""),{startCountDown:A,startAction:D,countDown:K}=(0,s.useCountDown)(60),[I,b]=(0,o.useState)(""),[w,_]=(0,o.useState)(0),[m,N]=(0,o.useState)(new Array(6).fill("")),T=(0,o.useRef)([]),v=m.join("");(0,o.useEffect)(()=>{T.current[w]&&T.current[w].focus()},[w]),(0,o.useEffect)(()=>{d&&C({email:d,data:{redirect_url:`${window?.location?.origin}${window?.location?.pathname}`}},{onSuccess:()=>{p("success"),f(e?.sendEmailSuccessMessage||""),D(),setTimeout(()=>{p(""),f("")},5e3)}})},[d]);const O=(0,o.useCallback)(async()=>{d&&(await C({email:d,data:{redirect_url:`${window?.location?.origin}${window?.location?.pathname}`}},{onSuccess:()=>{p("success"),f(e?.sendEmailSuccessMessage||""),D(),setTimeout(()=>{p(""),f("")},5e3)}}),(0,s.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"sent_again"}}))},[d,C]),U=(x,a)=>{const{value:t}=x.target;if(b(""),Number.isNaN(Number(t)))return;if(t.length>1){a<m.length-1&&(m[a+1]||(_(a+1),N(h=>{const M=[...h];return M[a]=t[0],t.length>1&&(M[a+1]=t[1]),M})));return}const l=[...m];l[a]=t,N(l),t?a<m.length-1&&!m[a+1]&&_(a+1):a>0&&_(a-1)},q=(0,o.useCallback)(async()=>{if(!v?.length){b(e?.codeEmptyError||"");return}if(v.length<6){b(e?.incorrectCodeError||"");return}const x=E?.data?.data?.active_token??E?.data?.active_token;x&&await k({token:x,code:v},{onSuccess:t=>{if(t.status>=200&&t.status<300)p("success"),f(e?.authSuccessMessage||""),u(!0),r?.user_id&&g(r.user_id),(0,s.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"check_and_active",info:"Member Floating Window"}}),setTimeout(()=>{i()},3e3);else{const l=t?.data?.error_code??t?.error_code;l==="104"?(u(!0),r?.user_id&&g(r.user_id),(0,s.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"check_and_active",info:"Member Floating Window"}}),setTimeout(()=>{i()},3e3)):b(l==="142"?e?.incorrectCodeError||"Invalid verification code.":l==="154"?e?.expiredCodeMessage||"":e?.sendEmailErrorMessage||"")}}});let a=setTimeout(()=>{p(""),f(""),clearTimeout(a)},5e3)},[v,e?.codeEmptyError,e?.authSuccessMessage,e?.incorrectCodeError,e?.expiredCodeMessage,e?.sendEmailErrorMessage,y,E,k,i,u,g,r]);return(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)(c.Text,{className:"text-[22px] font-extrabold leading-[120%] text-[#333] min-l:text-[24px] [&_abbr]:text-[#005d8e]",html:e?.authCodeTitle}),(0,n.jsx)(c.Text,{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:e?.authCodeDesc?.replace("%email%",d||"")})]}),(0,n.jsxs)("div",{className:"mt-6",children:[(0,n.jsx)(c.Text,{className:"mt-4 text-[14px] !font-bold font-semibold leading-[140%] text-[#333] min-l:mt-6",html:e?.enterActiveCodeText}),(0,n.jsx)("div",{className:"my-3 grid grid-cols-6 gap-2",children:m.map((x,a)=>(0,n.jsx)("div",{className:"col-span-1 aspect-1 text-[#555]",children:(0,n.jsx)("input",{ref:t=>{t&&(T.current[a]=t)},type:"tel",className:(0,s.classNames)("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:x,autoComplete:"false",autoCorrect:"false",spellCheck:"false",autoCapitalize:"false",onChange:t=>U(t,a),onFocus:()=>{_(a)},onPaste:t=>{const l=t.clipboardData.getData("text");if(!Number.isNaN(Number(l))){const h=l.split("").slice(0,6);N(h.concat(Array(6-h.length).fill(""))),h.length<=m.length&&_(h.length-1)}},onKeyDown:t=>{const{value:l}=t.target;t.key==="Backspace"&&!l&&a>0&&_(a-1)}},a)},a))}),I&&(0,n.jsx)(c.Text,{className:"mb-3 text-[14px] font-semibold leading-[120%] text-[#f84d4f]",html:I}),e?.authCodeContent&&(0,n.jsx)("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:e?.authCodeContent}})]}),(0,n.jsxs)("div",{className:"mt-4 min-l:mt-6",children:[(0,n.jsx)(c.Text,{className:"text-base font-semibold leading-[100%] text-[#333]",html:e?.authCodeReceiveText})," ",A?(0,n.jsx)(c.Text,{html:e?.retrieveText?.replace("%countdownTime%",K.toString()),className:"cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline"}):(0,n.jsx)(c.Text,{onClick:O,className:(0,s.classNames)("cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline",{"pointer-events-none":A||$}),html:e?.sendAgainText}),(0,n.jsx)(c.Button,{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:e.buttonText})]}),(0,n.jsx)(R.Message,{status:W,message:z})]})}
|
|
1
|
+
"use strict";var S=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var X=(e,i)=>{for(var u in i)S(e,u,{get:i[u],enumerable:!0})},Y=(e,i,u,g)=>{if(i&&typeof i=="object"||typeof i=="function")for(let r of J(i))!Q.call(e,r)&&r!==u&&S(e,r,{get:()=>i[r],enumerable:!(g=G(i,r))||g.enumerable});return e};var Z=e=>Y(S({},"__esModule",{value:!0}),e);var ee={};X(ee,{default:()=>V});module.exports=Z(ee);var n=require("react/jsx-runtime"),o=require("react"),c=require("@anker-in/headless-ui"),s=require("@anker-in/lib"),R=require("../../../registration/authCodeActivate/Message"),H=require("../../../registration"),L=require("../../context/provider"),P=require("../../../../constants");function V({copy:e,onClose:i}){const{setIsActivateSuccess:u,fetchCreditInfo:g,profile:r}=(0,L.useMemberPopupContext)(),{locale:y,brand:B}=(0,s.useHeadlessContext)(),{email:d}=(0,H.useRegistration)(),F=P.ROUNDED_BRANDS.includes(B),{isMutating:$,trigger:C,data:E}=(0,s.useSendEmailValidation)(),{isMutating:j,trigger:k}=(0,s.useEmailValidation)(),[z,f]=(0,o.useState)(""),[W,p]=(0,o.useState)(""),{startCountDown:A,startAction:D,countDown:K}=(0,s.useCountDown)(60),[I,b]=(0,o.useState)(""),[w,_]=(0,o.useState)(0),[m,N]=(0,o.useState)(new Array(6).fill("")),T=(0,o.useRef)([]),v=m.join("");(0,o.useEffect)(()=>{T.current[w]&&T.current[w].focus()},[w]),(0,o.useEffect)(()=>{d&&C({email:d,data:{redirect_url:`${window?.location?.origin}${window?.location?.pathname}`}},{onSuccess:()=>{p("success"),f(e?.sendEmailSuccessMessage||""),D(),setTimeout(()=>{p(""),f("")},5e3)}})},[d]);const O=(0,o.useCallback)(async()=>{d&&(await C({email:d,data:{redirect_url:`${window?.location?.origin}${window?.location?.pathname}`}},{onSuccess:()=>{p("success"),f(e?.sendEmailSuccessMessage||""),D(),setTimeout(()=>{p(""),f("")},5e3)}}),(0,s.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"sent_again"}}))},[d,C]),U=(x,a)=>{const{value:t}=x.target;if(b(""),Number.isNaN(Number(t)))return;if(t.length>1){a<m.length-1&&(m[a+1]||(_(a+1),N(h=>{const M=[...h];return M[a]=t[0],t.length>1&&(M[a+1]=t[1]),M})));return}const l=[...m];l[a]=t,N(l),t?a<m.length-1&&!m[a+1]&&_(a+1):a>0&&_(a-1)},q=(0,o.useCallback)(async()=>{if(!v?.length){b(e?.codeEmptyError||"");return}if(v.length<6){b(e?.incorrectCodeError||"");return}const x=E?.data?.data?.active_token??E?.data?.active_token;x&&await k({token:x,code:v},{onSuccess:t=>{if(t.status>=200&&t.status<300)p("success"),f(e?.authSuccessMessage||""),u(!0),r?.user_id&&setTimeout(()=>g(r.user_id),3e3),(0,s.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"check_and_active",info:"Member Floating Window"}}),setTimeout(()=>{i()},3e3);else{const l=t?.data?.error_code??t?.error_code;l==="104"?(u(!0),r?.user_id&&setTimeout(()=>g(r.user_id),3e3),(0,s.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"check_and_active",info:"Member Floating Window"}}),setTimeout(()=>{i()},3e3)):b(l==="142"?e?.incorrectCodeError||"Invalid verification code.":l==="154"?e?.expiredCodeMessage||"":e?.sendEmailErrorMessage||"")}}});let a=setTimeout(()=>{p(""),f(""),clearTimeout(a)},5e3)},[v,e?.codeEmptyError,e?.authSuccessMessage,e?.incorrectCodeError,e?.expiredCodeMessage,e?.sendEmailErrorMessage,y,E,k,i,u,g,r]);return(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)(c.Text,{className:"text-[22px] font-extrabold leading-[120%] text-[#333] min-l:text-[24px] [&_abbr]:text-[#005d8e]",html:e?.authCodeTitle}),(0,n.jsx)(c.Text,{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:e?.authCodeDesc?.replace("%email%",d||"")})]}),(0,n.jsxs)("div",{className:"mt-6",children:[(0,n.jsx)(c.Text,{className:"mt-4 text-[14px] !font-bold font-semibold leading-[140%] text-[#333] min-l:mt-6",html:e?.enterActiveCodeText}),(0,n.jsx)("div",{className:"my-3 grid grid-cols-6 gap-2",children:m.map((x,a)=>(0,n.jsx)("div",{className:"col-span-1 aspect-1 text-[#555]",children:(0,n.jsx)("input",{ref:t=>{t&&(T.current[a]=t)},type:"tel",className:(0,s.classNames)("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:x,autoComplete:"false",autoCorrect:"false",spellCheck:"false",autoCapitalize:"false",onChange:t=>U(t,a),onFocus:()=>{_(a)},onPaste:t=>{const l=t.clipboardData.getData("text");if(!Number.isNaN(Number(l))){const h=l.split("").slice(0,6);N(h.concat(Array(6-h.length).fill(""))),h.length<=m.length&&_(h.length-1)}},onKeyDown:t=>{const{value:l}=t.target;t.key==="Backspace"&&!l&&a>0&&_(a-1)}},a)},a))}),I&&(0,n.jsx)(c.Text,{className:"mb-3 text-[14px] font-semibold leading-[120%] text-[#f84d4f]",html:I}),e?.authCodeContent&&(0,n.jsx)("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:e?.authCodeContent}})]}),(0,n.jsxs)("div",{className:"mt-4 min-l:mt-6",children:[(0,n.jsx)(c.Text,{className:"text-base font-semibold leading-[100%] text-[#333]",html:e?.authCodeReceiveText})," ",A?(0,n.jsx)(c.Text,{html:e?.retrieveText?.replace("%countdownTime%",K.toString()),className:"cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline"}):(0,n.jsx)(c.Text,{onClick:O,className:(0,s.classNames)("cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline",{"pointer-events-none":A||$}),html:e?.sendAgainText}),(0,n.jsx)(c.Button,{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:e.buttonText})]}),(0,n.jsx)(R.Message,{status:W,message:z})]})}
|
|
2
2
|
//# sourceMappingURL=ActivatePanel.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/EarnCredits/ActivatePanel.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useState, useCallback, useRef, useEffect } from 'react'\nimport { 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 { Message } from '../../../registration/authCodeActivate/Message'\nimport type { AuthCodeActivateCopy } from '../../type'\nimport { useRegistration } from '../../../registration'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: AuthCodeActivateCopy\n onClose: () => void\n}\n\nexport default function ActivatePanel({ copy, onClose }: Props) {\n const { setIsActivateSuccess, fetchCreditInfo, profile } = useMemberPopupContext()\n const { locale, brand } = useHeadlessContext()\n const { email } = useRegistration()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const {\n isMutating: isSendingEmail,\n trigger: triggerSendValidationEmail,\n data: sendEmailData,\n } = useSendEmailValidation()\n\n const { isMutating: emailValidationLoading, trigger: triggerEmailValidation } = useEmailValidation()\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 (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 }, [email])\n\n const handleSendAgain = useCallback(async () => {\n if (!email) return\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 const token = sendEmailData?.data?.data?.active_token ?? sendEmailData?.data?.active_token\n if (token) {\n await triggerEmailValidation(\n {\n token: token,\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 (profile?.user_id) fetchCreditInfo(profile.user_id)\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 info: 'Member Floating Window',\n },\n })\n setTimeout(() => {\n onClose()\n }, 3000)\n } else {\n const errorCode = data?.data?.error_code ?? data?.error_code\n if (errorCode === '104') {\n setIsActivateSuccess(true)\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\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 info: 'Member Floating Window',\n },\n })\n setTimeout(() => {\n onClose()\n }, 3000)\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 let timer = setTimeout(() => {\n setMessageStatus('')\n setMessageText('')\n clearTimeout(timer)\n }, 5000)\n }, [\n code,\n copy?.codeEmptyError,\n copy?.authSuccessMessage,\n copy?.incorrectCodeError,\n copy?.expiredCodeMessage,\n copy?.sendEmailErrorMessage,\n locale,\n sendEmailData,\n triggerEmailValidation,\n onClose,\n setIsActivateSuccess,\n fetchCreditInfo,\n profile,\n ])\n\n return (\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 )\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,aAAAE,IAAA,eAAAC,EAAAH,IA6OM,IAAAI,EAAA,6BA7ONC,EAAyD,iBACzDC,EAA6B,iCAC7BC,EAOO,yBACPC,EAAwB,0DAExBC,EAAgC,iCAChCC,EAAsC,kCACtCC,EAA+B,iCAOhB,SAART,EAA+B,CAAE,KAAAU,EAAM,QAAAC,CAAQ,EAAU,CAC9D,KAAM,CAAE,qBAAAC,EAAsB,gBAAAC,EAAiB,QAAAC,CAAQ,KAAI,yBAAsB,EAC3E,CAAE,OAAAC,EAAQ,MAAAC,CAAM,KAAI,sBAAmB,EACvC,CAAE,MAAAC,CAAM,KAAI,mBAAgB,EAC5BC,EAAU,iBAAe,SAASF,CAAK,EAEvC,CACJ,WAAYG,EACZ,QAASC,EACT,KAAMC,CACR,KAAI,0BAAuB,EAErB,CAAE,WAAYC,EAAwB,QAASC,CAAuB,KAAI,sBAAmB,EAE7F,CAACC,EAAaC,CAAc,KAAI,YAAS,EAAE,EAC3C,CAACC,EAAeC,CAAgB,KAAI,YAAS,EAAE,EAC/C,CAAE,eAAgBC,EAAkB,YAAaC,EAAgB,UAAAC,CAAU,KAAI,gBAAa,EAAE,EAE9F,CAACC,EAAOC,CAAQ,KAAI,YAAS,EAAE,EAC/B,CAACC,EAAYC,CAAa,KAAI,YAAS,CAAC,EACxC,CAACC,EAAWC,CAAY,KAAI,YAAS,IAAI,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAE1DC,KAAY,UAA2B,CAAC,CAAC,EACzCC,EAAOH,EAAU,KAAK,EAAE,KAE9B,aAAU,IAAM,CACVE,EAAU,QAAQJ,CAAU,GAC9BI,EAAU,QAAQJ,CAAU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,EACpBA,EAAM,OAAS,IACjBE,EAAQH,EAAQ,CAAC,EAAIC,EAAM,CAAC,GAEvBE,CACT,CAAC,IAGL,MACF,CACA,MAAMA,EAAU,CAAC,GAAGV,CAAS,EAC7BU,EAAQH,CAAK,EAAIC,EACjBP,EAAaS,CAAO,EAChBF,EACED,EAAQP,EAAU,OAAS,GAAK,CAACA,EAAUO,EAAQ,CAAC,GACtDR,EAAcQ,EAAQ,CAAC,EAEhBA,EAAQ,GACjBR,EAAcQ,EAAQ,CAAC,CAE3B,EAEMI,KAAuB,eAAY,SAAY,CACnD,GAAI,CAACR,GAAM,OAAQ,CACjBN,EAAStB,GAAM,gBAAkB,EAAE,EACnC,MACF,CAEA,GAAI4B,EAAK,OAAS,EAAG,CACnBN,EAAStB,GAAM,oBAAsB,EAAE,EACvC,MACF,CAEA,MAAMqC,EAAQ1B,GAAe,MAAM,MAAM,cAAgBA,GAAe,MAAM,aAC1E0B,GACF,MAAMxB,EACJ,CACE,MAAOwB,EACP,KAAMT,CACR,EACA,CACE,UAAWU,GAAQ,CACjB,GAAIA,EAAK,QAAU,KAAOA,EAAK,OAAS,IACtCrB,EAAiB,SAAS,EAC1BF,EAAef,GAAM,oBAAsB,EAAE,EAC7CE,EAAqB,EAAI,EACrBE,GAAS,
|
|
4
|
+
"sourcesContent": ["import { useState, useCallback, useRef, useEffect } from 'react'\nimport { 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 { Message } from '../../../registration/authCodeActivate/Message'\nimport type { AuthCodeActivateCopy } from '../../type'\nimport { useRegistration } from '../../../registration'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: AuthCodeActivateCopy\n onClose: () => void\n}\n\nexport default function ActivatePanel({ copy, onClose }: Props) {\n const { setIsActivateSuccess, fetchCreditInfo, profile } = useMemberPopupContext()\n const { locale, brand } = useHeadlessContext()\n const { email } = useRegistration()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const {\n isMutating: isSendingEmail,\n trigger: triggerSendValidationEmail,\n data: sendEmailData,\n } = useSendEmailValidation()\n\n const { isMutating: emailValidationLoading, trigger: triggerEmailValidation } = useEmailValidation()\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 (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 }, [email])\n\n const handleSendAgain = useCallback(async () => {\n if (!email) return\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 const token = sendEmailData?.data?.data?.active_token ?? sendEmailData?.data?.active_token\n if (token) {\n await triggerEmailValidation(\n {\n token: token,\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 (profile?.user_id) setTimeout(() => fetchCreditInfo(profile.user_id), 3000)\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 info: 'Member Floating Window',\n },\n })\n setTimeout(() => {\n onClose()\n }, 3000)\n } else {\n const errorCode = data?.data?.error_code ?? data?.error_code\n if (errorCode === '104') {\n setIsActivateSuccess(true)\n if (profile?.user_id) setTimeout(() => fetchCreditInfo(profile.user_id), 3000)\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 info: 'Member Floating Window',\n },\n })\n setTimeout(() => {\n onClose()\n }, 3000)\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 let timer = setTimeout(() => {\n setMessageStatus('')\n setMessageText('')\n clearTimeout(timer)\n }, 5000)\n }, [\n code,\n copy?.codeEmptyError,\n copy?.authSuccessMessage,\n copy?.incorrectCodeError,\n copy?.expiredCodeMessage,\n copy?.sendEmailErrorMessage,\n locale,\n sendEmailData,\n triggerEmailValidation,\n onClose,\n setIsActivateSuccess,\n fetchCreditInfo,\n profile,\n ])\n\n return (\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 )\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,a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AS,CAClB,KAAM,CAAE,MAAAE,CAAM,EAAIF,EAAM,OACpBA,EAAM,MAAQ,aAAe,CAACE,GAASD,EAAQ,GACjDR,EAAcQ,EAAQ,CAAC,CAE3B,GA9BKA,CA+BP,GAtCQA,CAuCV,CACD,EACH,EAECX,MAAS,OAAC,QAAK,UAAU,+DAA+D,KAAMA,EAAO,EACrGrB,GAAM,oBACL,OAAC,MACC,UAAU,gLACV,wBAAyB,CAAE,OAAQA,GAAM,eAAgB,EAC3D,GAEJ,KACA,QAAC,OAAI,UAAU,kBACb,oBAAC,QAAK,UAAU,qDAAqD,KAAMA,GAAM,oBAAqB,EAAG,IACxGkB,KACC,OAAC,QACC,KAAMlB,GAAM,cAAc,QAAQ,kBAAmBoB,EAAU,SAAS,CAAC,EACzE,UAAU,yGACZ,KAEA,OAAC,QACC,QAASS,EACT,aAAW,EAAAc,YACT,yGACA,CACE,sBAAuBzB,GAAoBT,CAC7C,CACF,EACA,KAAMT,GAAM,cACd,KAEF,OAAC,UACC,KAAK,SACL,QAASY,EACT,UAAU,2JACV,QAASwB,EAER,SAAApC,EAAK,WACR,GACF,KACA,OAAC,WAAQ,OAAQgB,EAAe,QAASF,EAAa,GACxD,CAEJ",
|
|
6
6
|
"names": ["ActivatePanel_exports", "__export", "ActivatePanel", "__toCommonJS", "import_jsx_runtime", "import_react", "import_headless_ui", "import_lib", "import_Message", "import_registration", "import_provider", "import_constants", "copy", "onClose", "setIsActivateSuccess", "fetchCreditInfo", "profile", "locale", "brand", "email", "rounded", "isSendingEmail", "triggerSendValidationEmail", "sendEmailData", "emailValidationLoading", "triggerEmailValidation", "messageText", "setMessageText", "messageStatus", "setMessageStatus", "isStartCountDown", "startCountDown", "countDown", "error", "setError", "focusIndex", "setFocusIndex", "codeArray", "setCodeArray", "inputRefs", "code", "handleSendAgain", "handleInputCodeChange", "event", "index", "value", "old", "newCode", "handleAuthCodeSubmit", "token", "data", "errorCode", "timer", "item", "inputRef", "cn", "paste", "pastedCode"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var H=Object.create;var c=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var K=(t,n)=>{for(var a in n)c(t,a,{get:n[a],enumerable:!0})},q=(t,n,a,p)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of W(n))!J.call(t,s)&&s!==a&&c(t,s,{get:()=>n[s],enumerable:!(p=O(n,s))||p.enumerable});return t};var Q=(t,n,a)=>(a=t!=null?H(G(t)):{},q(n||!t||!t.__esModule?c(a,"default",{value:t,enumerable:!0}):a,t)),V=t=>q(c({},"__esModule",{value:!0}),t);var X={};K(X,{default:()=>
|
|
1
|
+
"use strict";var H=Object.create;var c=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var K=(t,n)=>{for(var a in n)c(t,a,{get:n[a],enumerable:!0})},q=(t,n,a,p)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of W(n))!J.call(t,s)&&s!==a&&c(t,s,{get:()=>n[s],enumerable:!(p=O(n,s))||p.enumerable});return t};var Q=(t,n,a)=>(a=t!=null?H(G(t)):{},q(n||!t||!t.__esModule?c(a,"default",{value:t,enumerable:!0}):a,t)),V=t=>q(c({},"__esModule",{value:!0}),t);var X={};K(X,{default:()=>I});module.exports=V(X);var e=require("react/jsx-runtime"),r=require("react"),d=require("@anker-in/headless-ui"),l=require("@anker-in/lib"),F=require("./hooks/useUpdateProfile"),L=Q(require("../../../credits/context/hooks/useCountries")),T=require("../../context/provider"),z=require("../../../../constants");function I({copy:t,onClose:n}){const{profile:a,fetchCreditInfo:p,alpcConfig:s,setIsProfileCompleteSuccess:k}=(0,T.useMemberPopupContext)(),{locale:M}=s,{brand:R,storeDomain:U}=(0,l.useHeadlessContext)(),i=z.ROUNDED_BRANDS.includes(R),[m,P]=(0,r.useState)(""),[x,w]=(0,r.useState)(""),[b,E]=(0,r.useState)(""),[v,y]=(0,r.useState)(""),[u,N]=(0,r.useState)(""),[h,g]=(0,r.useState)(""),[C,_]=(0,r.useState)(""),{updateProfile:D,isLoading:B}=(0,F.useUpdateProfile)({locale:M,appName:s.appName}),{countries:f}=(0,L.default)({shopifyStoreDomain:U});(0,r.useEffect)(()=>{a&&(P(a.first_name??""),w(a.last_name??""),E(a.phone_number??""),y(a.dob??""),N(a.country?.id??""))},[a]),(0,r.useEffect)(()=>{f.length>0&&!u&&N(f[0].id)},[f]);const S=(0,r.useCallback)(()=>{let o=!1;return m.trim()?g(""):(g(t.required),o=!0),x.trim()?_(""):(_(t.required),o=!0),o},[m,x,t.required]),A=(0,r.useCallback)(async()=>{if(S())return;await D({first_name:m.trim(),last_name:x.trim(),phone_number:b,country:u,dob:v})&&(setTimeout(()=>p(a?.user_id),3e3),k(!0),(0,l.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"earn_credits",button_name:"complete_profile_success",info:"Member Floating Window"}}),n())},[S,D,m,x,b,u,v,p,a,k,n]);return(0,e.jsxs)("div",{className:"flex flex-col gap-[16px]",children:[t.subtitle&&(0,e.jsx)(d.Text,{className:"text-[14px] text-[#1d1d1f]",html:t.subtitle}),(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-[14px] font-[700] text-[#1d1d1f]",children:t.email}),(0,e.jsx)("input",{className:(0,l.classNames)("mt-[8px] h-[46px] w-full border border-[#d8d8d8] bg-[#f5f5f5] px-[12px] text-[14px] text-[#999]",i?"rounded-[4px]":"rounded-none"),value:a?.email??"",disabled:!0})]}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("label",{className:"block text-[14px] font-[700] text-[#1d1d1f]",children:[t.firstName," ",(0,e.jsx)("span",{className:"text-[#f84d4f]",children:"*"})]}),(0,e.jsx)("input",{className:(0,l.classNames)("mt-[8px] h-[46px] w-full border px-[12px] text-[14px] outline-none",h?"border-[#f84d4f]":"border-[#d8d8d8]",i?"rounded-[4px]":"rounded-none"),value:m,onChange:o=>{P(o.target.value),g("")}}),h&&(0,e.jsx)(d.Text,{className:"mt-[4px] text-[12px] text-[#f84d4f]",html:h})]}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("label",{className:"block text-[14px] font-[700] text-[#1d1d1f]",children:[t.lastName," ",(0,e.jsx)("span",{className:"text-[#f84d4f]",children:"*"})]}),(0,e.jsx)("input",{className:(0,l.classNames)("mt-[8px] h-[46px] w-full border px-[12px] text-[14px] outline-none",C?"border-[#f84d4f]":"border-[#d8d8d8]",i?"rounded-[4px]":"rounded-none"),value:x,onChange:o=>{w(o.target.value),_("")}}),C&&(0,e.jsx)(d.Text,{className:"mt-[4px] text-[12px] text-[#f84d4f]",html:C})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-[14px] font-[700] text-[#1d1d1f]",children:t.birthday}),(0,e.jsx)("input",{className:(0,l.classNames)("mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none",i?"rounded-[4px]":"rounded-none"),type:"date",value:v,onChange:o=>y(o.target.value)})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-[14px] font-[700] text-[#1d1d1f]",children:t.phone}),(0,e.jsx)("input",{className:(0,l.classNames)("mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none",i?"rounded-[4px]":"rounded-none"),value:b,onChange:o=>E(o.target.value)})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-[14px] font-[700] text-[#1d1d1f]",children:t.country}),(0,e.jsx)("select",{className:(0,l.classNames)("mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none",i?"rounded-[4px]":"rounded-none"),value:u,onChange:o=>N(o.target.value),children:f.map(o=>(0,e.jsx)("option",{value:o.id,children:o.name},o.id))})]}),(0,e.jsxs)("div",{className:"flex gap-[12px]",children:[(0,e.jsx)(d.Button,{variant:"secondary",size:"lg",className:"flex-1",onClick:n,disabled:B,children:t.cancel}),(0,e.jsx)(d.Button,{variant:"primary",size:"lg",className:"flex-1",loading:B,onClick:A,children:t.save})]})]})}
|
|
2
2
|
//# sourceMappingURL=CompleteProfilePanel.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport { Button, Text } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport type { CompleteProfileCopy } from '../../type'\nimport { useUpdateProfile } from './hooks/useUpdateProfile'\nimport useCountries from '../../../credits/context/hooks/useCountries'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: CompleteProfileCopy\n onClose: () => void\n}\n\nexport default function CompleteProfilePanel({ copy, onClose }: Props) {\n const { profile, fetchCreditInfo, alpcConfig, setIsProfileCompleteSuccess } = useMemberPopupContext()\n const { locale } = alpcConfig\n const { brand, storeDomain } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [firstName, setFirstName] = useState('')\n const [lastName, setLastName] = useState('')\n const [phone, setPhone] = useState('')\n const [birthDay, setBirthDay] = useState('')\n const [country, setCountry] = useState('')\n const [firstNameError, setFirstNameError] = useState('')\n const [lastNameError, setLastNameError] = useState('')\n\n const { updateProfile, isLoading } = useUpdateProfile({ locale, appName: alpcConfig.appName })\n const { countries } = useCountries({ shopifyStoreDomain: storeDomain })\n\n useEffect(() => {\n if (profile) {\n setFirstName(profile.first_name ?? '')\n setLastName(profile.last_name ?? '')\n setPhone(profile.phone_number ?? '')\n setBirthDay(profile.dob ?? '')\n setCountry(profile.country?.id ?? '')\n }\n }, [profile])\n\n useEffect(() => {\n if (countries.length > 0 && !country) {\n setCountry(countries[0].id)\n }\n }, [countries])\n\n const validate = useCallback(() => {\n let hasError = false\n if (!firstName.trim()) {\n setFirstNameError(copy.required)\n hasError = true\n } else {\n setFirstNameError('')\n }\n if (!lastName.trim()) {\n setLastNameError(copy.required)\n hasError = true\n } else {\n setLastNameError('')\n }\n return hasError\n }, [firstName, lastName, copy.required])\n\n const handleSubmit = useCallback(async () => {\n if (validate()) return\n const success = await updateProfile({\n first_name: firstName.trim(),\n last_name: lastName.trim(),\n phone_number: phone,\n country,\n dob: birthDay,\n })\n if (success) {\n fetchCreditInfo(profile?.user_id)\n setIsProfileCompleteSuccess(true)\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'earn_credits',\n button_name: 'complete_profile_success',\n info: 'Member Floating Window',\n },\n })\n onClose()\n }\n }, [\n validate,\n updateProfile,\n firstName,\n lastName,\n phone,\n country,\n birthDay,\n fetchCreditInfo,\n profile,\n setIsProfileCompleteSuccess,\n onClose,\n ])\n\n return (\n <div className=\"flex flex-col gap-[16px]\">\n {copy.subtitle && <Text className=\"text-[14px] text-[#1d1d1f]\" html={copy.subtitle} />}\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.email}</label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] bg-[#f5f5f5] px-[12px] text-[14px] text-[#999]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={profile?.email ?? ''}\n disabled\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">\n {copy.firstName} <span className=\"text-[#f84d4f]\">*</span>\n </label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border px-[12px] text-[14px] outline-none',\n firstNameError ? 'border-[#f84d4f]' : 'border-[#d8d8d8]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={firstName}\n onChange={e => {\n setFirstName(e.target.value)\n setFirstNameError('')\n }}\n />\n {firstNameError && <Text className=\"mt-[4px] text-[12px] text-[#f84d4f]\" html={firstNameError} />}\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">\n {copy.lastName} <span className=\"text-[#f84d4f]\">*</span>\n </label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border px-[12px] text-[14px] outline-none',\n lastNameError ? 'border-[#f84d4f]' : 'border-[#d8d8d8]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={lastName}\n onChange={e => {\n setLastName(e.target.value)\n setLastNameError('')\n }}\n />\n {lastNameError && <Text className=\"mt-[4px] text-[12px] text-[#f84d4f]\" html={lastNameError} />}\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.birthday}</label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n type=\"date\"\n value={birthDay}\n onChange={e => setBirthDay(e.target.value)}\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.phone}</label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={phone}\n onChange={e => setPhone(e.target.value)}\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.country}</label>\n <select\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={country}\n onChange={e => setCountry(e.target.value)}\n >\n {countries.map((c: { id: string; name: string }) => (\n <option key={c.id} value={c.id}>\n {c.name}\n </option>\n ))}\n </select>\n </div>\n\n <div className=\"flex gap-[12px]\">\n <Button variant=\"secondary\" size=\"lg\" className=\"flex-1\" onClick={onClose} disabled={isLoading}>\n {copy.cancel}\n </Button>\n <Button variant=\"primary\" size=\"lg\" className=\"flex-1\" loading={isLoading} onClick={handleSubmit}>\n {copy.save}\n </Button>\n </div>\n </div>\n )\n}\n"],
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAuGwB,IAAAI,EAAA,6BAvGxBC,EAAiD,iBACjDC,EAA6B,iCAC7BC,EAA8D,yBAE9DC,EAAiC,oCACjCC,EAAyB,0DACzBC,EAAsC,kCACtCC,EAA+B,iCAOhB,SAART,EAAsC,CAAE,KAAAU,EAAM,QAAAC,CAAQ,EAAU,CACrE,KAAM,CAAE,QAAAC,EAAS,gBAAAC,EAAiB,WAAAC,EAAY,4BAAAC,CAA4B,KAAI,yBAAsB,EAC9F,CAAE,OAAAC,CAAO,EAAIF,EACb,CAAE,MAAAG,EAAO,YAAAC,CAAY,KAAI,sBAAmB,EAC5CC,EAAU,iBAAe,SAASF,CAAK,EAEvC,CAACG,EAAWC,CAAY,KAAI,YAAS,EAAE,EACvC,CAACC,EAAUC,CAAW,KAAI,YAAS,EAAE,EACrC,CAACC,EAAOC,CAAQ,KAAI,YAAS,EAAE,EAC/B,CAACC,EAAUC,CAAW,KAAI,YAAS,EAAE,EACrC,CAACC,EAASC,CAAU,KAAI,YAAS,EAAE,EACnC,CAACC,EAAgBC,CAAiB,KAAI,YAAS,EAAE,EACjD,CAACC,EAAeC,CAAgB,KAAI,YAAS,EAAE,EAE/C,CAAE,cAAAC,EAAe,UAAAC,CAAU,KAAI,oBAAiB,CAAE,OAAAnB,EAAQ,QAASF,EAAW,OAAQ,CAAC,EACvF,CAAE,UAAAsB,CAAU,KAAI,EAAAC,SAAa,CAAE,mBAAoBnB,CAAY,CAAC,KAEtE,aAAU,IAAM,CACVN,IACFS,EAAaT,EAAQ,YAAc,EAAE,EACrCW,EAAYX,EAAQ,WAAa,EAAE,EACnCa,EAASb,EAAQ,cAAgB,EAAE,EACnCe,EAAYf,EAAQ,KAAO,EAAE,EAC7BiB,EAAWjB,EAAQ,SAAS,IAAM,EAAE,EAExC,EAAG,CAACA,CAAO,CAAC,KAEZ,aAAU,IAAM,CACVwB,EAAU,OAAS,GAAK,CAACR,GAC3BC,EAAWO,EAAU,CAAC,EAAE,EAAE,CAE9B,EAAG,CAACA,CAAS,CAAC,EAEd,MAAME,KAAW,eAAY,IAAM,CACjC,IAAIC,EAAW,GACf,OAAKnB,EAAU,KAAK,EAIlBW,EAAkB,EAAE,GAHpBA,EAAkBrB,EAAK,QAAQ,EAC/B6B,EAAW,IAIRjB,EAAS,KAAK,EAIjBW,EAAiB,EAAE,GAHnBA,EAAiBvB,EAAK,QAAQ,EAC9B6B,EAAW,IAINA,CACT,EAAG,CAACnB,EAAWE,EAAUZ,EAAK,QAAQ,CAAC,EAEjC8B,KAAe,eAAY,SAAY,CAC3C,GAAIF,EAAS,EAAG,OACA,MAAMJ,EAAc,CAClC,WAAYd,EAAU,KAAK,EAC3B,UAAWE,EAAS,KAAK,EACzB,aAAcE,EACd,QAAAI,EACA,IAAKF,CACP,CAAC,
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport { Button, Text } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport type { CompleteProfileCopy } from '../../type'\nimport { useUpdateProfile } from './hooks/useUpdateProfile'\nimport useCountries from '../../../credits/context/hooks/useCountries'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: CompleteProfileCopy\n onClose: () => void\n}\n\nexport default function CompleteProfilePanel({ copy, onClose }: Props) {\n const { profile, fetchCreditInfo, alpcConfig, setIsProfileCompleteSuccess } = useMemberPopupContext()\n const { locale } = alpcConfig\n const { brand, storeDomain } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [firstName, setFirstName] = useState('')\n const [lastName, setLastName] = useState('')\n const [phone, setPhone] = useState('')\n const [birthDay, setBirthDay] = useState('')\n const [country, setCountry] = useState('')\n const [firstNameError, setFirstNameError] = useState('')\n const [lastNameError, setLastNameError] = useState('')\n\n const { updateProfile, isLoading } = useUpdateProfile({ locale, appName: alpcConfig.appName })\n const { countries } = useCountries({ shopifyStoreDomain: storeDomain })\n\n useEffect(() => {\n if (profile) {\n setFirstName(profile.first_name ?? '')\n setLastName(profile.last_name ?? '')\n setPhone(profile.phone_number ?? '')\n setBirthDay(profile.dob ?? '')\n setCountry(profile.country?.id ?? '')\n }\n }, [profile])\n\n useEffect(() => {\n if (countries.length > 0 && !country) {\n setCountry(countries[0].id)\n }\n }, [countries])\n\n const validate = useCallback(() => {\n let hasError = false\n if (!firstName.trim()) {\n setFirstNameError(copy.required)\n hasError = true\n } else {\n setFirstNameError('')\n }\n if (!lastName.trim()) {\n setLastNameError(copy.required)\n hasError = true\n } else {\n setLastNameError('')\n }\n return hasError\n }, [firstName, lastName, copy.required])\n\n const handleSubmit = useCallback(async () => {\n if (validate()) return\n const success = await updateProfile({\n first_name: firstName.trim(),\n last_name: lastName.trim(),\n phone_number: phone,\n country,\n dob: birthDay,\n })\n if (success) {\n setTimeout(() => fetchCreditInfo(profile?.user_id), 3000)\n setIsProfileCompleteSuccess(true)\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'earn_credits',\n button_name: 'complete_profile_success',\n info: 'Member Floating Window',\n },\n })\n onClose()\n }\n }, [\n validate,\n updateProfile,\n firstName,\n lastName,\n phone,\n country,\n birthDay,\n fetchCreditInfo,\n profile,\n setIsProfileCompleteSuccess,\n onClose,\n ])\n\n return (\n <div className=\"flex flex-col gap-[16px]\">\n {copy.subtitle && <Text className=\"text-[14px] text-[#1d1d1f]\" html={copy.subtitle} />}\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.email}</label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] bg-[#f5f5f5] px-[12px] text-[14px] text-[#999]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={profile?.email ?? ''}\n disabled\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">\n {copy.firstName} <span className=\"text-[#f84d4f]\">*</span>\n </label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border px-[12px] text-[14px] outline-none',\n firstNameError ? 'border-[#f84d4f]' : 'border-[#d8d8d8]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={firstName}\n onChange={e => {\n setFirstName(e.target.value)\n setFirstNameError('')\n }}\n />\n {firstNameError && <Text className=\"mt-[4px] text-[12px] text-[#f84d4f]\" html={firstNameError} />}\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">\n {copy.lastName} <span className=\"text-[#f84d4f]\">*</span>\n </label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border px-[12px] text-[14px] outline-none',\n lastNameError ? 'border-[#f84d4f]' : 'border-[#d8d8d8]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={lastName}\n onChange={e => {\n setLastName(e.target.value)\n setLastNameError('')\n }}\n />\n {lastNameError && <Text className=\"mt-[4px] text-[12px] text-[#f84d4f]\" html={lastNameError} />}\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.birthday}</label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n type=\"date\"\n value={birthDay}\n onChange={e => setBirthDay(e.target.value)}\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.phone}</label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={phone}\n onChange={e => setPhone(e.target.value)}\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.country}</label>\n <select\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={country}\n onChange={e => setCountry(e.target.value)}\n >\n {countries.map((c: { id: string; name: string }) => (\n <option key={c.id} value={c.id}>\n {c.name}\n </option>\n ))}\n </select>\n </div>\n\n <div className=\"flex gap-[12px]\">\n <Button variant=\"secondary\" size=\"lg\" className=\"flex-1\" onClick={onClose} disabled={isLoading}>\n {copy.cancel}\n </Button>\n <Button variant=\"primary\" size=\"lg\" className=\"flex-1\" loading={isLoading} onClick={handleSubmit}>\n {copy.save}\n </Button>\n </div>\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAuGwB,IAAAI,EAAA,6BAvGxBC,EAAiD,iBACjDC,EAA6B,iCAC7BC,EAA8D,yBAE9DC,EAAiC,oCACjCC,EAAyB,0DACzBC,EAAsC,kCACtCC,EAA+B,iCAOhB,SAART,EAAsC,CAAE,KAAAU,EAAM,QAAAC,CAAQ,EAAU,CACrE,KAAM,CAAE,QAAAC,EAAS,gBAAAC,EAAiB,WAAAC,EAAY,4BAAAC,CAA4B,KAAI,yBAAsB,EAC9F,CAAE,OAAAC,CAAO,EAAIF,EACb,CAAE,MAAAG,EAAO,YAAAC,CAAY,KAAI,sBAAmB,EAC5CC,EAAU,iBAAe,SAASF,CAAK,EAEvC,CAACG,EAAWC,CAAY,KAAI,YAAS,EAAE,EACvC,CAACC,EAAUC,CAAW,KAAI,YAAS,EAAE,EACrC,CAACC,EAAOC,CAAQ,KAAI,YAAS,EAAE,EAC/B,CAACC,EAAUC,CAAW,KAAI,YAAS,EAAE,EACrC,CAACC,E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,EAAA+B,YACT,sFACAtB,EAAU,gBAAkB,cAC9B,EACA,KAAK,OACL,MAAOO,EACP,SAAUgB,GAAKf,EAAYe,EAAE,OAAO,KAAK,EAC3C,GACF,KAEA,QAAC,OACC,oBAAC,SAAM,UAAU,8CAA+C,SAAAhC,EAAK,MAAM,KAC3E,OAAC,SACC,aAAW,EAAA+B,YACT,sFACAtB,EAAU,gBAAkB,cAC9B,EACA,MAAOK,EACP,SAAUkB,GAAKjB,EAASiB,EAAE,OAAO,KAAK,EACxC,GACF,KAEA,QAAC,OACC,oBAAC,SAAM,UAAU,8CAA+C,SAAAhC,EAAK,QAAQ,KAC7E,OAAC,UACC,aAAW,EAAA+B,YACT,sFACAtB,EAAU,gBAAkB,cAC9B,EACA,MAAOS,EACP,SAAUc,GAAKb,EAAWa,EAAE,OAAO,KAAK,EAEvC,SAAAN,EAAU,IAAKO,MACd,OAAC,UAAkB,MAAOA,EAAE,GACzB,SAAAA,EAAE,MADQA,EAAE,EAEf,CACD,EACH,GACF,KAEA,QAAC,OAAI,UAAU,kBACb,oBAAC,UAAO,QAAQ,YAAY,KAAK,KAAK,UAAU,SAAS,QAAShC,EAAS,SAAUwB,EAClF,SAAAzB,EAAK,OACR,KACA,OAAC,UAAO,QAAQ,UAAU,KAAK,KAAK,UAAU,SAAS,QAASyB,EAAW,QAASK,EACjF,SAAA9B,EAAK,KACR,GACF,GACF,CAEJ",
|
|
6
6
|
"names": ["CompleteProfilePanel_exports", "__export", "CompleteProfilePanel", "__toCommonJS", "import_jsx_runtime", "import_react", "import_headless_ui", "import_lib", "import_useUpdateProfile", "import_useCountries", "import_provider", "import_constants", "copy", "onClose", "profile", "fetchCreditInfo", "alpcConfig", "setIsProfileCompleteSuccess", "locale", "brand", "storeDomain", "rounded", "firstName", "setFirstName", "lastName", "setLastName", "phone", "setPhone", "birthDay", "setBirthDay", "country", "setCountry", "firstNameError", "setFirstNameError", "lastNameError", "setLastNameError", "updateProfile", "isLoading", "countries", "useCountries", "validate", "hasError", "handleSubmit", "cn", "e", "c"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var B=Object.create;var m=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var J=(e,t)=>{for(var s in t)m(e,s,{get:t[s],enumerable:!0})},w=(e,t,s,f)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of R(t))!q.call(e,a)&&a!==s&&m(e,a,{get:()=>t[a],enumerable:!(f=H(t,a))||f.enumerable});return e};var U=(e,t,s)=>(s=e!=null?B(j(e)):{},w(t||!e||!e.__esModule?m(s,"default",{value:e,enumerable:!0}):s,e)),V=e=>w(m({},"__esModule",{value:!0}),e);var F={};J(F,{default:()=>E});module.exports=V(F);var r=require("react/jsx-runtime"),o=require("react"),u=require("@anker-in/headless-ui"),i=require("@anker-in/lib"),d=U(require("js-cookie")),T=require("query-string"),M=require("../../../credits/context/utils"),P=require("../../context/provider"),D=require("../../../../constants");function z(){if(typeof window>"u")return{register_source:""};const{search:e,href:t}=window.location,s=(0,T.parse)(e);return{fbuy_ref_code:d.default.get("fbuy_ref_code"),ref:d.default.get("ref_ads"),inviter_code:s.ic??s.inviter_code??d.default.get("inviter_code"),register_source:s.redirect??d.default.get("reg_source")??t}}function E({copy:e,email:t,onClose:s}){const{alpcConfig:f,setIsSubscribeSuccess:a,fetchCreditInfo:I,profile:g}=(0,P.useMemberPopupContext)(),{brand:h,locale:_}=f,{brand:L}=(0,i.useHeadlessContext)(),v=D.ROUNDED_BRANDS.includes(L),[x,y]=(0,o.useState)(e.policyDefaultChecked??!1),[c,C]=(0,o.useState)(t??""),[p,l]=(0,o.useState)(""),[b,N]=(0,o.useState)(""),[O,S]=(0,o.useState)(!1);(0,o.useEffect)(()=>{t&&C(t)},[t]);const A=(0,o.useCallback)(async()=>{if(l(""),!c)return l("Please fill in your email");if(!(0,M.emailValidate)(c))return l("Invalid email address");if(!x)return l("Please agree to the policy");S(!0);const{register_source:n}=z();try{const k=await(await fetch("/api/multipass/subscribe/subscribe_emails",{method:"POST",headers:{"Content-Type":"application/json","current-language":_},body:JSON.stringify({email:c,register_source:n,brand:h,deals_type:e.dealsType??"vip_subscribe"})})).json();k.errors?l(k.errors??"Error occurred"):(N(e.successTips??"Subscribed successfully!"),a(!0),g?.user_id&&I(g.user_id),(0,i.gaTrack)({event:"ga4Event",event_name:"subscribe",event_parameters:{page_group:e.dealsType??"",position:"sticky",info:""}}),setTimeout(()=>{N(""),s()},3e3))}catch{l("Network error")}finally{S(!1)}},[c,x,_,h,e,s,a]);return(0,r.jsxs)("div",{className:"flex flex-col gap-[12px]",children:[(0,r.jsxs)("div",{className:"flex flex-col gap-[8px]",children:[e.title&&(0,r.jsx)("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:e.title}),e.desc&&(0,r.jsx)(u.Text,{className:"text-[16px] text-[#1e2024]",html:e.desc})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-[16px]",children:[(0,r.jsx)("input",{className:(0,i.classNames)("h-[46px] w-full border px-[14px] text-[16px] outline-none placeholder:text-[#999]",p?"border-[#f84d4f]":"border-[#d8d8d8]",v?"rounded-[4px]":"rounded-none"),placeholder:e.placeholder,value:c,onChange:n=>{l(""),C(n.target.value.trim())}}),(0,r.jsxs)("div",{className:"flex w-full items-start gap-[8px]",children:[(0,r.jsx)(u.Checkbox,{checked:x,onCheckedChange:()=>y(n=>!n),className:"mt-[2px] border-[#1d1d1f]"}),(0,r.jsx)("label",{className:"cursor-pointer text-left text-[14px] text-[#1e2024] [&_a]:underline",onClick:()=>y(n=>!n),dangerouslySetInnerHTML:{__html:e.policy??""}})]}),(p||b)&&(0,r.jsx)("div",{className:(0,i.classNames)("text-[14px] font-[700]",p&&"text-[#f84d4f]",b&&"text-[#52c41a]"),children:(0,r.jsx)(u.Text,{html:b||p})}),(0,r.jsx)("button",{className:(0,i.classNames)("w-full cursor-pointer bg-[#080a0f] py-[14px] text-[14px] font-[700] text-white disabled:opacity-60",v?"rounded-[4px]":"rounded-none"),disabled:O,onClick:A,children:e.buttonLabel??"Subscribe"})]})]})}
|
|
1
|
+
"use strict";var B=Object.create;var m=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var J=(e,t)=>{for(var s in t)m(e,s,{get:t[s],enumerable:!0})},w=(e,t,s,f)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of R(t))!q.call(e,a)&&a!==s&&m(e,a,{get:()=>t[a],enumerable:!(f=H(t,a))||f.enumerable});return e};var U=(e,t,s)=>(s=e!=null?B(j(e)):{},w(t||!e||!e.__esModule?m(s,"default",{value:e,enumerable:!0}):s,e)),V=e=>w(m({},"__esModule",{value:!0}),e);var F={};J(F,{default:()=>E});module.exports=V(F);var r=require("react/jsx-runtime"),o=require("react"),u=require("@anker-in/headless-ui"),i=require("@anker-in/lib"),d=U(require("js-cookie")),T=require("query-string"),M=require("../../../credits/context/utils"),P=require("../../context/provider"),D=require("../../../../constants");function z(){if(typeof window>"u")return{register_source:""};const{search:e,href:t}=window.location,s=(0,T.parse)(e);return{fbuy_ref_code:d.default.get("fbuy_ref_code"),ref:d.default.get("ref_ads"),inviter_code:s.ic??s.inviter_code??d.default.get("inviter_code"),register_source:s.redirect??d.default.get("reg_source")??t}}function E({copy:e,email:t,onClose:s}){const{alpcConfig:f,setIsSubscribeSuccess:a,fetchCreditInfo:I,profile:g}=(0,P.useMemberPopupContext)(),{brand:h,locale:_}=f,{brand:L}=(0,i.useHeadlessContext)(),v=D.ROUNDED_BRANDS.includes(L),[x,y]=(0,o.useState)(e.policyDefaultChecked??!1),[c,C]=(0,o.useState)(t??""),[p,l]=(0,o.useState)(""),[b,N]=(0,o.useState)(""),[O,S]=(0,o.useState)(!1);(0,o.useEffect)(()=>{t&&C(t)},[t]);const A=(0,o.useCallback)(async()=>{if(l(""),!c)return l("Please fill in your email");if(!(0,M.emailValidate)(c))return l("Invalid email address");if(!x)return l("Please agree to the policy");S(!0);const{register_source:n}=z();try{const k=await(await fetch("/api/multipass/subscribe/subscribe_emails",{method:"POST",headers:{"Content-Type":"application/json","current-language":_},body:JSON.stringify({email:c,register_source:n,brand:h,deals_type:e.dealsType??"vip_subscribe"})})).json();k.errors?l(k.errors??"Error occurred"):(N(e.successTips??"Subscribed successfully!"),a(!0),g?.user_id&&setTimeout(()=>I(g.user_id),3e3),(0,i.gaTrack)({event:"ga4Event",event_name:"subscribe",event_parameters:{page_group:e.dealsType??"",position:"sticky",info:""}}),setTimeout(()=>{N(""),s()},3e3))}catch{l("Network error")}finally{S(!1)}},[c,x,_,h,e,s,a]);return(0,r.jsxs)("div",{className:"flex flex-col gap-[12px]",children:[(0,r.jsxs)("div",{className:"flex flex-col gap-[8px]",children:[e.title&&(0,r.jsx)("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:e.title}),e.desc&&(0,r.jsx)(u.Text,{className:"text-[16px] text-[#1e2024]",html:e.desc})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-[16px]",children:[(0,r.jsx)("input",{className:(0,i.classNames)("h-[46px] w-full border px-[14px] text-[16px] outline-none placeholder:text-[#999]",p?"border-[#f84d4f]":"border-[#d8d8d8]",v?"rounded-[4px]":"rounded-none"),placeholder:e.placeholder,value:c,onChange:n=>{l(""),C(n.target.value.trim())}}),(0,r.jsxs)("div",{className:"flex w-full items-start gap-[8px]",children:[(0,r.jsx)(u.Checkbox,{checked:x,onCheckedChange:()=>y(n=>!n),className:"mt-[2px] border-[#1d1d1f]"}),(0,r.jsx)("label",{className:"cursor-pointer text-left text-[14px] text-[#1e2024] [&_a]:underline",onClick:()=>y(n=>!n),dangerouslySetInnerHTML:{__html:e.policy??""}})]}),(p||b)&&(0,r.jsx)("div",{className:(0,i.classNames)("text-[14px] font-[700]",p&&"text-[#f84d4f]",b&&"text-[#52c41a]"),children:(0,r.jsx)(u.Text,{html:b||p})}),(0,r.jsx)("button",{className:(0,i.classNames)("w-full cursor-pointer bg-[#080a0f] py-[14px] text-[14px] font-[700] text-white disabled:opacity-60",v?"rounded-[4px]":"rounded-none"),disabled:O,onClick:A,children:e.buttonLabel??"Subscribe"})]})]})}
|
|
2
2
|
//# sourceMappingURL=SubscribeEmailPanel.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport { Checkbox, Text } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport Cookies from 'js-cookie'\nimport { parse } from 'query-string'\nimport { emailValidate } from '../../../credits/context/utils'\nimport { useMemberPopupContext } from '../../context/provider'\nimport type { SubscribeModalCopy } from '../../type'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: SubscribeModalCopy\n email?: string\n onClose: () => void\n}\n\nfunction getAdCookie() {\n if (typeof window === 'undefined') return { register_source: '' }\n const { search, href } = window.location\n const query = parse(search)\n return {\n fbuy_ref_code: Cookies.get('fbuy_ref_code'),\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 }\n}\n\nexport default function SubscribeEmailPanel({ copy, email: initialEmail, onClose }: Props) {\n const { alpcConfig, setIsSubscribeSuccess, fetchCreditInfo, profile } = useMemberPopupContext()\n const { brand, locale } = alpcConfig\n const { brand: headlessBrand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(headlessBrand)\n const [policy, setPolicy] = useState(copy.policyDefaultChecked ?? false)\n const [email, setEmail] = useState(initialEmail ?? '')\n const [errorMessage, setErrorMessage] = useState('')\n const [successMessage, setSuccessMessage] = useState('')\n const [loading, setLoading] = useState(false)\n\n useEffect(() => {\n if (initialEmail) setEmail(initialEmail)\n }, [initialEmail])\n\n const handleSubmit = useCallback(async () => {\n setErrorMessage('')\n if (!email) return setErrorMessage('Please fill in your email')\n if (!emailValidate(email)) return setErrorMessage('Invalid email address')\n if (!policy) return setErrorMessage('Please agree to the policy')\n\n setLoading(true)\n const { register_source } = getAdCookie()\n try {\n const response = await fetch('/api/multipass/subscribe/subscribe_emails', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', 'current-language': locale },\n body: JSON.stringify({\n email,\n register_source,\n brand,\n deals_type: copy.dealsType ?? 'vip_subscribe',\n }),\n })\n const result = await response.json()\n if (!result.errors) {\n setSuccessMessage(copy.successTips ?? 'Subscribed successfully!')\n setIsSubscribeSuccess(true)\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n gaTrack({\n event: 'ga4Event',\n event_name: 'subscribe',\n event_parameters: {\n page_group: copy.dealsType ?? '',\n position: 'sticky',\n info: '',\n },\n })\n setTimeout(() => {\n setSuccessMessage('')\n onClose()\n }, 3000)\n } else {\n setErrorMessage(result.errors ?? 'Error occurred')\n }\n } catch {\n setErrorMessage('Network error')\n } finally {\n setLoading(false)\n }\n }, [email, policy, locale, brand, copy, onClose, setIsSubscribeSuccess])\n\n return (\n <div className=\"flex flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && (\n <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>\n )}\n {copy.desc && (\n <Text className=\"text-[16px] text-[#1e2024]\" html={copy.desc} />\n )}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n <input\n className={cn(\n 'h-[46px] w-full border px-[14px] text-[16px] outline-none placeholder:text-[#999]',\n errorMessage ? 'border-[#f84d4f]' : 'border-[#d8d8d8]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n placeholder={copy.placeholder}\n value={email}\n onChange={e => { setErrorMessage(''); setEmail(e.target.value.trim()) }}\n />\n\n <div className=\"flex w-full items-start gap-[8px]\">\n <Checkbox checked={policy} onCheckedChange={() => setPolicy(v => !v)} className=\"mt-[2px] border-[#1d1d1f]\" />\n <label\n className=\"cursor-pointer text-left text-[14px] text-[#1e2024] [&_a]:underline\"\n onClick={() => setPolicy(v => !v)}\n dangerouslySetInnerHTML={{ __html: copy.policy ?? '' }}\n />\n </div>\n\n {(errorMessage || successMessage) && (\n <div className={cn('text-[14px] font-[700]', errorMessage && 'text-[#f84d4f]', successMessage && 'text-[#52c41a]')}>\n <Text html={successMessage || errorMessage} />\n </div>\n )}\n\n <button\n className={cn('w-full cursor-pointer bg-[#080a0f] py-[14px] text-[14px] font-[700] text-white disabled:opacity-60', rounded ? 'rounded-[4px]' : 'rounded-none')}\n disabled={loading}\n onClick={handleSubmit}\n >\n {copy.buttonLabel ?? 'Subscribe'}\n </button>\n </div>\n </div>\n )\n}\n"],
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GA4FM,IAAAI,EAAA,6BA5FNC,EAAiD,iBACjDC,EAA+B,iCAC/BC,EAA8D,yBAC9DC,EAAoB,wBACpBC,EAAsB,wBACtBC,EAA8B,0CAC9BC,EAAsC,kCAEtCC,EAA+B,iCAQ/B,SAASC,GAAc,CACrB,GAAI,OAAO,OAAW,IAAa,MAAO,CAAE,gBAAiB,EAAG,EAChE,KAAM,CAAE,OAAAC,EAAQ,KAAAC,CAAK,EAAI,OAAO,SAC1BC,KAAQ,SAAMF,CAAM,EAC1B,MAAO,CACL,cAAe,EAAAG,QAAQ,IAAI,eAAe,EAC1C,IAAK,EAAAA,QAAQ,IAAI,SAAS,EAC1B,aAAcD,EAAM,IAAMA,EAAM,cAAgB,EAAAC,QAAQ,IAAI,cAAc,EAC1E,gBAAiBD,EAAM,UAAY,EAAAC,QAAQ,IAAI,YAAY,GAAKF,CAClE,CACF,CAEe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I,EACtBE,GAAS,
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport { Checkbox, Text } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport Cookies from 'js-cookie'\nimport { parse } from 'query-string'\nimport { emailValidate } from '../../../credits/context/utils'\nimport { useMemberPopupContext } from '../../context/provider'\nimport type { SubscribeModalCopy } from '../../type'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: SubscribeModalCopy\n email?: string\n onClose: () => void\n}\n\nfunction getAdCookie() {\n if (typeof window === 'undefined') return { register_source: '' }\n const { search, href } = window.location\n const query = parse(search)\n return {\n fbuy_ref_code: Cookies.get('fbuy_ref_code'),\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 }\n}\n\nexport default function SubscribeEmailPanel({ copy, email: initialEmail, onClose }: Props) {\n const { alpcConfig, setIsSubscribeSuccess, fetchCreditInfo, profile } = useMemberPopupContext()\n const { brand, locale } = alpcConfig\n const { brand: headlessBrand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(headlessBrand)\n const [policy, setPolicy] = useState(copy.policyDefaultChecked ?? false)\n const [email, setEmail] = useState(initialEmail ?? '')\n const [errorMessage, setErrorMessage] = useState('')\n const [successMessage, setSuccessMessage] = useState('')\n const [loading, setLoading] = useState(false)\n\n useEffect(() => {\n if (initialEmail) setEmail(initialEmail)\n }, [initialEmail])\n\n const handleSubmit = useCallback(async () => {\n setErrorMessage('')\n if (!email) return setErrorMessage('Please fill in your email')\n if (!emailValidate(email)) return setErrorMessage('Invalid email address')\n if (!policy) return setErrorMessage('Please agree to the policy')\n\n setLoading(true)\n const { register_source } = getAdCookie()\n try {\n const response = await fetch('/api/multipass/subscribe/subscribe_emails', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', 'current-language': locale },\n body: JSON.stringify({\n email,\n register_source,\n brand,\n deals_type: copy.dealsType ?? 'vip_subscribe',\n }),\n })\n const result = await response.json()\n if (!result.errors) {\n setSuccessMessage(copy.successTips ?? 'Subscribed successfully!')\n setIsSubscribeSuccess(true)\n if (profile?.user_id) setTimeout(() => fetchCreditInfo(profile.user_id), 3000)\n gaTrack({\n event: 'ga4Event',\n event_name: 'subscribe',\n event_parameters: {\n page_group: copy.dealsType ?? '',\n position: 'sticky',\n info: '',\n },\n })\n setTimeout(() => {\n setSuccessMessage('')\n onClose()\n }, 3000)\n } else {\n setErrorMessage(result.errors ?? 'Error occurred')\n }\n } catch {\n setErrorMessage('Network error')\n } finally {\n setLoading(false)\n }\n }, [email, policy, locale, brand, copy, onClose, setIsSubscribeSuccess])\n\n return (\n <div className=\"flex flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && (\n <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>\n )}\n {copy.desc && (\n <Text className=\"text-[16px] text-[#1e2024]\" html={copy.desc} />\n )}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n <input\n className={cn(\n 'h-[46px] w-full border px-[14px] text-[16px] outline-none placeholder:text-[#999]',\n errorMessage ? 'border-[#f84d4f]' : 'border-[#d8d8d8]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n placeholder={copy.placeholder}\n value={email}\n onChange={e => { setErrorMessage(''); setEmail(e.target.value.trim()) }}\n />\n\n <div className=\"flex w-full items-start gap-[8px]\">\n <Checkbox checked={policy} onCheckedChange={() => setPolicy(v => !v)} className=\"mt-[2px] border-[#1d1d1f]\" />\n <label\n className=\"cursor-pointer text-left text-[14px] text-[#1e2024] [&_a]:underline\"\n onClick={() => setPolicy(v => !v)}\n dangerouslySetInnerHTML={{ __html: copy.policy ?? '' }}\n />\n </div>\n\n {(errorMessage || successMessage) && (\n <div className={cn('text-[14px] font-[700]', errorMessage && 'text-[#f84d4f]', successMessage && 'text-[#52c41a]')}>\n <Text html={successMessage || errorMessage} />\n </div>\n )}\n\n <button\n className={cn('w-full cursor-pointer bg-[#080a0f] py-[14px] text-[14px] font-[700] text-white disabled:opacity-60', rounded ? 'rounded-[4px]' : 'rounded-none')}\n disabled={loading}\n onClick={handleSubmit}\n >\n {copy.buttonLabel ?? 'Subscribe'}\n </button>\n </div>\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GA4FM,IAAAI,EAAA,6BA5FNC,EAAiD,iBACjDC,EAA+B,iCAC/BC,EAA8D,yBAC9DC,EAAoB,wBACpBC,EAAsB,wBACtBC,EAA8B,0CAC9BC,EAAsC,kCAEtCC,EAA+B,iCAQ/B,SAASC,GAAc,CACrB,GAAI,OAAO,OAAW,IAAa,MAAO,CAAE,gBAAiB,EAAG,EAChE,KAAM,CAAE,OAAAC,EAAQ,KAAAC,CAAK,EAAI,OAAO,SAC1BC,KAAQ,SAAMF,CAAM,EAC1B,MAAO,CACL,cAAe,EAAAG,QAAQ,IAAI,eAAe,EAC1C,IAAK,EAAAA,QAAQ,IAAI,SAAS,EAC1B,aAAcD,EAAM,IAAMA,EAAM,cAAgB,EAAAC,QAAQ,IAAI,cAAc,EAC1E,gBAAiBD,EAAM,UAAY,EAAAC,QAAQ,IAAI,YAAY,GAAKF,CAClE,CACF,CAEe,SAARb,EAAqC,CAAE,KAAAgB,EAAM,MAAOC,EAAc,QAAAC,CAAQ,EAAU,CACzF,KAAM,CAAE,WAAAC,EAAY,sBAAAC,EAAuB,gBAAAC,EAAiB,QAAAC,CAAQ,KAAI,yBAAsB,EACxF,CAAE,MAAAC,EAAO,OAAAC,CAAO,EAAIL,EACpB,CAAE,MAAOM,CAAc,KAAI,sBAAmB,EAC9CC,EAAU,iBAAe,SAASD,CAAa,EAC/C,CAACE,EAAQC,CAAS,KAAI,YAASZ,EAAK,sBAAwB,EAA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P,EAAOF,EAAQH,EAAQD,EAAOP,EAAME,EAASE,CAAqB,CAAC,EAEvE,SACE,QAAC,OAAI,UAAU,2BACb,qBAAC,OAAI,UAAU,0BACZ,UAAAJ,EAAK,UACJ,OAAC,MAAG,UAAU,sDAAuD,SAAAA,EAAK,MAAM,EAEjFA,EAAK,SACJ,OAAC,QAAK,UAAU,6BAA6B,KAAMA,EAAK,KAAM,GAElE,KAEA,QAAC,OAAI,UAAU,2BACb,oBAAC,SACC,aAAW,EAAAwB,YACT,oFACAT,EAAe,mBAAqB,mBACpCL,EAAU,gBAAkB,cAC9B,EACA,YAAaV,EAAK,YAClB,MAAOa,EACP,SAAUY,GAAK,CAAET,EAAgB,EAAE,EAAGF,EAASW,EAAE,OAAO,MAAM,KAAK,CAAC,CAAE,EACxE,KAEA,QAAC,OAAI,UAAU,oCACb,oBAAC,YAAS,QAASd,EAAQ,gBAAiB,IAAMC,EAAUc,GAAK,CAACA,CAAC,EAAG,UAAU,4BAA4B,KAC5G,OAAC,SACC,UAAU,sEACV,QAAS,IAAMd,EAAUc,GAAK,CAACA,CAAC,EAChC,wBAAyB,CAAE,OAAQ1B,EAAK,QAAU,EAAG,EACvD,GACF,GAEEe,GAAgBE,OAChB,OAAC,OAAI,aAAW,EAAAO,YAAG,yBAA0BT,GAAgB,iBAAkBE,GAAkB,gBAAgB,EAC/G,mBAAC,QAAK,KAAMA,GAAkBF,EAAc,EAC9C,KAGF,OAAC,UACC,aAAW,EAAAS,YAAG,qGAAsGd,EAAU,gBAAkB,cAAc,EAC9J,SAAUS,EACV,QAASE,EAER,SAAArB,EAAK,aAAe,YACvB,GACF,GACF,CAEJ",
|
|
6
6
|
"names": ["SubscribeEmailPanel_exports", "__export", "SubscribeEmailPanel", "__toCommonJS", "import_jsx_runtime", "import_react", "import_headless_ui", "import_lib", "import_js_cookie", "import_query_string", "import_utils", "import_provider", "import_constants", "getAdCookie", "search", "href", "query", "Cookies", "copy", "initialEmail", "onClose", "alpcConfig", "setIsSubscribeSuccess", "fetchCreditInfo", "profile", "brand", "locale", "headlessBrand", "rounded", "policy", "setPolicy", "email", "setEmail", "errorMessage", "setErrorMessage", "successMessage", "setSuccessMessage", "loading", "setLoading", "handleSubmit", "register_source", "result", "cn", "e", "v"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var v=Object.defineProperty;var
|
|
1
|
+
"use strict";var v=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var R=(i,t)=>{for(var n in t)v(i,n,{get:t[n],enumerable:!0})},D=(i,t,n,f)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of M(t))!y.call(i,l)&&l!==n&&v(i,l,{get:()=>t[l],enumerable:!(f=U(t,l))||f.enumerable});return i};var F=i=>D(v({},"__esModule",{value:!0}),i);var W={};R(W,{default:()=>H});module.exports=F(W);var e=require("react/jsx-runtime"),c=require("react"),r=require("@anker-in/lib"),_=require("../../context/provider"),E=require("../../context/viewStack"),P=require("./hooks/useSubscribed"),s=require("../../type"),p=require("../../icons"),g=require("../../../credits/context/utils"),L=require("../../../../constants");function O({id:i,className:t}){switch(i){case s.EarnCreditsTaskType.Activate:return(0,e.jsx)(p.IconLock,{className:t});case s.EarnCreditsTaskType.Subscribe:return(0,e.jsx)(p.IconSubscription,{className:t});case s.EarnCreditsTaskType.Shop:return(0,e.jsx)(p.IconBag,{className:t});case s.EarnCreditsTaskType.CompleteProfile:return(0,e.jsx)(p.IconOrders,{className:t})}}function V({copy:i}){const{profile:t,openSignUpPopup:n,alpcConfig:f,creditInfo:l,fetchCreditInfo:w,isSubscribeSuccess:C,isActivateSuccess:N,isProfileCompleteSuccess:m}=(0,_.useMemberPopupContext)(),{pushView:u}=(0,E.useViewStack)(),{locale:A}=f,{brand:h}=(0,r.useHeadlessContext)(),b=L.ROUNDED_BRANDS.includes(h);(0,c.useEffect)(()=>{t?.user_id&&w(t.user_id)},[]);const o=!!t,k=(0,P.useSubscribed)({userId:t?.user_id,brand:h,email:t?.email,locale:A,apiBaseUrl:f.apiBaseUrl}),S=(0,c.useMemo)(()=>m||!!(t?.first_name||t?.last_name)&&!!t?.phone_number&&!!t?.dob,[t,m]);function x(a){const d={[s.EarnCreditsTaskType.Activate]:"activate",[s.EarnCreditsTaskType.CompleteProfile]:"complete_profile",[s.EarnCreditsTaskType.Subscribe]:"subscribe",[s.EarnCreditsTaskType.Shop]:"shop"};(0,r.gaTrack)({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"earn_credits",button_name:d[a],info:"Member Floating Window"}})}const T=(0,c.useMemo)(()=>({[s.EarnCreditsTaskType.Activate]:{finished:!!t?.activated||N,onClick:o?()=>{x(s.EarnCreditsTaskType.Activate),u({type:s.MemberPopupPanelType.Activate})}:n},[s.EarnCreditsTaskType.CompleteProfile]:{finished:S,onClick:o?()=>{x(s.EarnCreditsTaskType.CompleteProfile),u({type:s.MemberPopupPanelType.CompleteProfile})}:n},[s.EarnCreditsTaskType.Subscribe]:{finished:k||C,onClick:o?()=>{x(s.EarnCreditsTaskType.Subscribe),u({type:s.MemberPopupPanelType.SubscribeEmail})}:n},[s.EarnCreditsTaskType.Shop]:{finished:!1,link:i.goShopLink,onClick:o?()=>x(s.EarnCreditsTaskType.Shop):n}}),[t,o,N,m,S,k,C,n,u,i.goShopLink]),B=(0,c.useMemo)(()=>i.list.map(a=>{const d=T[a.id];if(!d)return null;const I=d.finished?i.completed:o?z(a.id,i):i.joinNow;return{...a,...d,buttonLabel:I}}).filter(Boolean),[i,T,o]);return(0,e.jsxs)("div",{className:"flex flex-col gap-[16px]",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-[16px]",children:[(0,e.jsx)("div",{className:"flex flex-col gap-[8px]",children:i.title&&(0,e.jsx)("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:i.title})}),o&&(0,e.jsxs)("div",{className:(0,r.classNames)("flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]",b?"rounded-[8px]":"rounded-none"),children:[(0,e.jsxs)("div",{className:"flex flex-1 flex-col gap-[4px]",children:[(0,e.jsx)("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:i.balanceLabel??"AnkerCredits Balance"}),(0,e.jsxs)("div",{className:"flex items-end gap-[4px]",children:[(0,e.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,g.numberFormat)(l?.available_credit??0)}),(0,e.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:i.creditUnit??"ankercredits"})]})]}),(0,e.jsx)("div",{className:"h-full w-px bg-[#dadce0]"}),(0,e.jsxs)("div",{className:"flex flex-1 flex-col gap-[4px]",children:[(0,e.jsx)("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:i.comingSoonLabel??"Coming Soon"}),(0,e.jsxs)("div",{className:"flex items-end gap-[4px]",children:[(0,e.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,g.numberFormat)(l?.pending_credit??0)}),(0,e.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:i.creditUnit??"ankercredits"})]})]})]})]}),(0,e.jsxs)("div",{className:"flex flex-col gap-[16px]",children:[i.subtitle&&(0,e.jsx)("p",{className:"text-[16px] font-[700] text-[#1e2024]",children:i.subtitle}),(0,e.jsx)("div",{className:"flex flex-col",children:B.map((a,d)=>(0,e.jsxs)("div",{className:"relative py-[16px]",children:[d>0&&(0,e.jsx)("div",{className:"absolute left-0 right-0 top-0 h-px bg-[#dadce0]"}),(0,e.jsxs)("div",{className:(0,r.classNames)("flex items-center gap-[12px]"),children:[(0,e.jsx)(O,{id:a.id,className:"size-[24px] shrink-0"}),(0,e.jsxs)("div",{className:"flex-1",children:[(0,e.jsx)("div",{className:"text-[16px] font-[700] text-[#1e2024]",children:a.title}),a.credits&&(0,e.jsx)("div",{className:"mt-[4px] text-[14px] font-bold text-[#4A4C56]",children:a.credits})]}),!a.finished&&a.link&&o?(0,e.jsx)("a",{href:a.link,target:"_blank",rel:"noopener noreferrer",className:(0,r.classNames)("cursor-pointer bg-[#080a0f] min-w-[118px] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white",b?"rounded-[4px]":"rounded-none"),onClick:()=>x(a.id),children:a.buttonLabel}):(0,e.jsx)("button",{className:(0,r.classNames)("cursor-pointer min-w-[118px] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white",a.finished?"bg-[#767880]":"bg-[#080a0f]",b?"rounded-[4px]":"rounded-none",a.finished&&"opacity-60"),disabled:a.finished,onClick:a.finished?void 0:a.onClick,children:a.buttonLabel})]})]},d))})]})]})}function z(i,t){switch(i){case s.EarnCreditsTaskType.Activate:return t.activate;case s.EarnCreditsTaskType.CompleteProfile:return t.completeProfileLabel;case s.EarnCreditsTaskType.Subscribe:return t.subscribeLabel;case s.EarnCreditsTaskType.Shop:return t.shopNow}}var H=V;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/EarnCredits/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useMemo } from 'react'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useSubscribed } from './hooks/useSubscribed'\nimport { EarnCreditsTaskType, MemberPopupPanelType, type EarnCreditsCopy } from '../../type'\nimport { IconBag, IconLock, IconSubscription, IconOrders } from '../../icons'\nimport { numberFormat } from '../../../credits/context/utils'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\nfunction TaskIcon({ id, className }: { id: EarnCreditsTaskType; className?: string }) {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return <IconLock className={className} />\n case EarnCreditsTaskType.Subscribe:\n return <IconSubscription className={className} />\n case EarnCreditsTaskType.Shop:\n return <IconBag className={className} />\n case EarnCreditsTaskType.CompleteProfile:\n return <IconOrders className={className} />\n }\n}\n\ntype Props = {\n copy: EarnCreditsCopy\n}\n\nfunction EarnCredits({ copy }: Props) {\n const {\n profile,\n openSignUpPopup,\n alpcConfig,\n creditInfo,\n isSubscribeSuccess,\n isActivateSuccess,\n isProfileCompleteSuccess,\n } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { locale } = alpcConfig\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isLogin = !!profile\n\n const isSubscribed = useSubscribed({\n userId: profile?.user_id,\n brand: brand,\n email: profile?.email,\n locale,\n apiBaseUrl: alpcConfig.apiBaseUrl,\n })\n\n const profileCompleted = useMemo(() => {\n return (\n isProfileCompleteSuccess ||\n (!!(profile?.first_name || profile?.last_name) && !!profile?.phone_number && !!profile?.dob)\n )\n }, [profile, isProfileCompleteSuccess])\n\n function trackTaskButton(taskId: EarnCreditsTaskType) {\n const taskButtonNameMap: Record<EarnCreditsTaskType, string> = {\n [EarnCreditsTaskType.Activate]: 'activate',\n [EarnCreditsTaskType.CompleteProfile]: 'complete_profile',\n [EarnCreditsTaskType.Subscribe]: 'subscribe',\n [EarnCreditsTaskType.Shop]: 'shop',\n }\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'earn_credits',\n button_name: taskButtonNameMap[taskId],\n info: 'Member Floating Window',\n },\n })\n }\n\n const taskStates: Record<EarnCreditsTaskType, { finished: boolean; onClick?: () => void; link?: string }> = useMemo(\n () => ({\n [EarnCreditsTaskType.Activate]: {\n finished: !!profile?.activated || isActivateSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Activate)\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.CompleteProfile]: {\n finished: profileCompleted,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.CompleteProfile)\n pushView({\n type: MemberPopupPanelType.CompleteProfile,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Subscribe]: {\n finished: isSubscribed || isSubscribeSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Subscribe)\n pushView({\n type: MemberPopupPanelType.SubscribeEmail,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Shop]: {\n finished: false,\n link: copy.goShopLink,\n onClick: isLogin ? () => trackTaskButton(EarnCreditsTaskType.Shop) : openSignUpPopup,\n },\n }),\n [\n profile,\n isLogin,\n isActivateSuccess,\n isProfileCompleteSuccess,\n profileCompleted,\n isSubscribed,\n isSubscribeSuccess,\n openSignUpPopup,\n pushView,\n copy.goShopLink,\n ]\n )\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const state = taskStates[item.id]\n if (!state) return null\n const buttonLabel = state.finished\n ? copy.completed\n : isLogin\n ? getNotFinishedLabel(item.id, copy)\n : copy.joinNow\n return { ...item, ...state, buttonLabel }\n })\n .filter(Boolean) as ((typeof copy.list)[number] & {\n finished: boolean\n onClick?: () => void\n link?: string\n buttonLabel: string\n })[]\n }, [copy, taskStates, isLogin])\n\n return (\n <div className=\"flex flex-col gap-[16px]\">\n <div className=\"flex flex-col gap-[16px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit ?? 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit ?? 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {copy.subtitle && <p className=\"text-[16px] font-[700] text-[#1e2024]\">{copy.subtitle}</p>}\n\n <div className=\"flex flex-col\">\n {list.map((item, idx) => (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute left-0 right-0 top-0 h-px bg-[#dadce0]\" />}\n <div className={cn('flex items-center gap-[12px]')}>\n <TaskIcon id={item.id} className=\"size-[24px] shrink-0\" />\n <div className=\"flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024]\">{item.title}</div>\n {item.credits && (\n <div className=\"mt-[4px] text-[14px] font-bold text-[#4A4C56]\">{item.credits}</div>\n )}\n </div>\n {!item.finished && item.link && isLogin ? (\n <a\n href={item.link}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className={cn(\n 'cursor-pointer bg-[#080a0f] min-w-[118px] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n onClick={() => trackTaskButton(item.id)}\n >\n {item.buttonLabel}\n </a>\n ) : (\n <button\n className={cn(\n 'cursor-pointer min-w-[118px] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n item.finished ? 'bg-[#767880]' : 'bg-[#080a0f]',\n rounded ? 'rounded-[4px]' : 'rounded-none',\n item.finished && 'opacity-60'\n )}\n disabled={item.finished}\n onClick={!item.finished ? item.onClick : undefined}\n >\n {item.buttonLabel}\n </button>\n )}\n </div>\n </div>\n ))}\n </div>\n </div>\n </div>\n )\n}\n\nfunction getNotFinishedLabel(id: EarnCreditsTaskType, copy: EarnCreditsCopy): string {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return copy.activate\n case EarnCreditsTaskType.CompleteProfile:\n return copy.completeProfileLabel\n case EarnCreditsTaskType.Subscribe:\n return copy.subscribeLabel\n case EarnCreditsTaskType.Shop:\n return copy.shopNow\n }\n}\n\nexport default EarnCredits\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAaa,IAAAI,EAAA,6BAbbC,
|
|
6
|
-
"names": ["EarnCredits_exports", "__export", "EarnCredits_default", "__toCommonJS", "import_jsx_runtime", "import_react", "import_lib", "import_provider", "import_viewStack", "import_useSubscribed", "import_type", "import_icons", "import_utils", "import_constants", "TaskIcon", "id", "className", "EarnCredits", "copy", "profile", "openSignUpPopup", "alpcConfig", "creditInfo", "isSubscribeSuccess", "isActivateSuccess", "isProfileCompleteSuccess", "pushView", "locale", "brand", "rounded", "isLogin", "isSubscribed", "profileCompleted", "trackTaskButton", "taskId", "taskButtonNameMap", "taskStates", "list", "item", "state", "buttonLabel", "getNotFinishedLabel", "cn", "idx"]
|
|
4
|
+
"sourcesContent": ["import { useEffect, useMemo } from 'react'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useSubscribed } from './hooks/useSubscribed'\nimport { EarnCreditsTaskType, MemberPopupPanelType, type EarnCreditsCopy } from '../../type'\nimport { IconBag, IconLock, IconSubscription, IconOrders } from '../../icons'\nimport { numberFormat } from '../../../credits/context/utils'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\nfunction TaskIcon({ id, className }: { id: EarnCreditsTaskType; className?: string }) {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return <IconLock className={className} />\n case EarnCreditsTaskType.Subscribe:\n return <IconSubscription className={className} />\n case EarnCreditsTaskType.Shop:\n return <IconBag className={className} />\n case EarnCreditsTaskType.CompleteProfile:\n return <IconOrders className={className} />\n }\n}\n\ntype Props = {\n copy: EarnCreditsCopy\n}\n\nfunction EarnCredits({ copy }: Props) {\n const {\n profile,\n openSignUpPopup,\n alpcConfig,\n creditInfo,\n fetchCreditInfo,\n isSubscribeSuccess,\n isActivateSuccess,\n isProfileCompleteSuccess,\n } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { locale } = alpcConfig\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n useEffect(() => {\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n }, [])\n\n const isLogin = !!profile\n\n const isSubscribed = useSubscribed({\n userId: profile?.user_id,\n brand: brand,\n email: profile?.email,\n locale,\n apiBaseUrl: alpcConfig.apiBaseUrl,\n })\n\n const profileCompleted = useMemo(() => {\n return (\n isProfileCompleteSuccess ||\n (!!(profile?.first_name || profile?.last_name) && !!profile?.phone_number && !!profile?.dob)\n )\n }, [profile, isProfileCompleteSuccess])\n\n function trackTaskButton(taskId: EarnCreditsTaskType) {\n const taskButtonNameMap: Record<EarnCreditsTaskType, string> = {\n [EarnCreditsTaskType.Activate]: 'activate',\n [EarnCreditsTaskType.CompleteProfile]: 'complete_profile',\n [EarnCreditsTaskType.Subscribe]: 'subscribe',\n [EarnCreditsTaskType.Shop]: 'shop',\n }\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'earn_credits',\n button_name: taskButtonNameMap[taskId],\n info: 'Member Floating Window',\n },\n })\n }\n\n const taskStates: Record<EarnCreditsTaskType, { finished: boolean; onClick?: () => void; link?: string }> = useMemo(\n () => ({\n [EarnCreditsTaskType.Activate]: {\n finished: !!profile?.activated || isActivateSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Activate)\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.CompleteProfile]: {\n finished: profileCompleted,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.CompleteProfile)\n pushView({\n type: MemberPopupPanelType.CompleteProfile,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Subscribe]: {\n finished: isSubscribed || isSubscribeSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Subscribe)\n pushView({\n type: MemberPopupPanelType.SubscribeEmail,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Shop]: {\n finished: false,\n link: copy.goShopLink,\n onClick: isLogin ? () => trackTaskButton(EarnCreditsTaskType.Shop) : openSignUpPopup,\n },\n }),\n [\n profile,\n isLogin,\n isActivateSuccess,\n isProfileCompleteSuccess,\n profileCompleted,\n isSubscribed,\n isSubscribeSuccess,\n openSignUpPopup,\n pushView,\n copy.goShopLink,\n ]\n )\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const state = taskStates[item.id]\n if (!state) return null\n const buttonLabel = state.finished\n ? copy.completed\n : isLogin\n ? getNotFinishedLabel(item.id, copy)\n : copy.joinNow\n return { ...item, ...state, buttonLabel }\n })\n .filter(Boolean) as ((typeof copy.list)[number] & {\n finished: boolean\n onClick?: () => void\n link?: string\n buttonLabel: string\n })[]\n }, [copy, taskStates, isLogin])\n\n return (\n <div className=\"flex flex-col gap-[16px]\">\n <div className=\"flex flex-col gap-[16px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit ?? 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit ?? 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {copy.subtitle && <p className=\"text-[16px] font-[700] text-[#1e2024]\">{copy.subtitle}</p>}\n\n <div className=\"flex flex-col\">\n {list.map((item, idx) => (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute left-0 right-0 top-0 h-px bg-[#dadce0]\" />}\n <div className={cn('flex items-center gap-[12px]')}>\n <TaskIcon id={item.id} className=\"size-[24px] shrink-0\" />\n <div className=\"flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024]\">{item.title}</div>\n {item.credits && (\n <div className=\"mt-[4px] text-[14px] font-bold text-[#4A4C56]\">{item.credits}</div>\n )}\n </div>\n {!item.finished && item.link && isLogin ? (\n <a\n href={item.link}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className={cn(\n 'cursor-pointer bg-[#080a0f] min-w-[118px] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n onClick={() => trackTaskButton(item.id)}\n >\n {item.buttonLabel}\n </a>\n ) : (\n <button\n className={cn(\n 'cursor-pointer min-w-[118px] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n item.finished ? 'bg-[#767880]' : 'bg-[#080a0f]',\n rounded ? 'rounded-[4px]' : 'rounded-none',\n item.finished && 'opacity-60'\n )}\n disabled={item.finished}\n onClick={!item.finished ? item.onClick : undefined}\n >\n {item.buttonLabel}\n </button>\n )}\n </div>\n </div>\n ))}\n </div>\n </div>\n </div>\n )\n}\n\nfunction getNotFinishedLabel(id: EarnCreditsTaskType, copy: EarnCreditsCopy): string {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return copy.activate\n case EarnCreditsTaskType.CompleteProfile:\n return copy.completeProfileLabel\n case EarnCreditsTaskType.Subscribe:\n return copy.subscribeLabel\n case EarnCreditsTaskType.Shop:\n return copy.shopNow\n }\n}\n\nexport default EarnCredits\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAaa,IAAAI,EAAA,6BAbbC,EAAmC,iBACnCC,EAA8D,yBAC9DC,EAAsC,kCACtCC,EAA6B,mCAC7BC,EAA8B,iCAC9BC,EAAgF,sBAChFC,EAAgE,uBAChEC,EAA6B,0CAC7BC,EAA+B,iCAE/B,SAASC,EAAS,CAAE,GAAAC,EAAI,UAAAC,CAAU,EAAoD,CACpF,OAAQD,EAAI,CACV,KAAK,sBAAoB,SACvB,SAAO,OAAC,YAAS,UAAWC,EAAW,EACzC,KAAK,sBAAoB,UACvB,SAAO,OAAC,oBAAiB,UAAWA,EAAW,EACjD,KAAK,sBAA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,OAAC,UACC,aAAW,EAAAI,YACT,6GACAJ,EAAK,SAAW,eAAiB,eACjCT,EAAU,gBAAkB,eAC5BS,EAAK,UAAY,YACnB,EACA,SAAUA,EAAK,SACf,QAAUA,EAAK,SAA0B,OAAfA,EAAK,QAE9B,SAAAA,EAAK,YACR,GAEJ,IArCQK,CAsCV,CACD,EACH,GACF,GACF,CAEJ,CAEA,SAASF,EAAoB3B,EAAyBG,EAA+B,CACnF,OAAQH,EAAI,CACV,KAAK,sBAAoB,SACvB,OAAOG,EAAK,SACd,KAAK,sBAAoB,gBACvB,OAAOA,EAAK,qBACd,KAAK,sBAAoB,UACvB,OAAOA,EAAK,eACd,KAAK,sBAAoB,KACvB,OAAOA,EAAK,OAChB,CACF,CAEA,IAAOhB,EAAQe",
|
|
6
|
+
"names": ["EarnCredits_exports", "__export", "EarnCredits_default", "__toCommonJS", "import_jsx_runtime", "import_react", "import_lib", "import_provider", "import_viewStack", "import_useSubscribed", "import_type", "import_icons", "import_utils", "import_constants", "TaskIcon", "id", "className", "EarnCredits", "copy", "profile", "openSignUpPopup", "alpcConfig", "creditInfo", "fetchCreditInfo", "isSubscribeSuccess", "isActivateSuccess", "isProfileCompleteSuccess", "pushView", "locale", "brand", "rounded", "isLogin", "isSubscribed", "profileCompleted", "trackTaskButton", "taskId", "taskButtonNameMap", "taskStates", "list", "item", "state", "buttonLabel", "getNotFinishedLabel", "cn", "idx"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as n,jsxs as _}from"react/jsx-runtime";import{useState as p,useCallback as R,useRef as U,useEffect as H}from"react";import{Button as q,Text as r}from"@anker-in/headless-ui";import{useSendEmailValidation as G,gaTrack as S,classNames as L,useHeadlessContext as J,useEmailValidation as Q,useCountDown as X}from"@anker-in/lib";import{Message as Y}from"../../../registration/authCodeActivate/Message";import{useRegistration as Z}from"../../../registration";import{useMemberPopupContext as ee}from"../../context/provider";import{ROUNDED_BRANDS as te}from"../../../../constants";function ae({copy:e,onClose:x}){const{setIsActivateSuccess:h,fetchCreditInfo:v,profile:f}=ee(),{locale:P,brand:V}=J(),{email:i}=Z(),y=te.includes(V),{isMutating:B,trigger:C,data:E}=G(),{isMutating:F,trigger:k}=Q(),[$,l]=p(""),[j,c]=p(""),{startCountDown:A,startAction:D,countDown:z}=X(60),[I,u]=p(""),[w,m]=p(0),[o,N]=p(new Array(6).fill("")),T=U([]),b=o.join("");H(()=>{T.current[w]&&T.current[w].focus()},[w]),H(()=>{i&&C({email:i,data:{redirect_url:`${window?.location?.origin}${window?.location?.pathname}`}},{onSuccess:()=>{c("success"),l(e?.sendEmailSuccessMessage||""),D(),setTimeout(()=>{c(""),l("")},5e3)}})},[i]);const W=R(async()=>{i&&(await C({email:i,data:{redirect_url:`${window?.location?.origin}${window?.location?.pathname}`}},{onSuccess:()=>{c("success"),l(e?.sendEmailSuccessMessage||""),D(),setTimeout(()=>{c(""),l("")},5e3)}}),S({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"sent_again"}}))},[i,C]),K=(d,a)=>{const{value:t}=d.target;if(u(""),Number.isNaN(Number(t)))return;if(t.length>1){a<o.length-1&&(o[a+1]||(m(a+1),N(g=>{const M=[...g];return M[a]=t[0],t.length>1&&(M[a+1]=t[1]),M})));return}const s=[...o];s[a]=t,N(s),t?a<o.length-1&&!o[a+1]&&m(a+1):a>0&&m(a-1)},O=R(async()=>{if(!b?.length){u(e?.codeEmptyError||"");return}if(b.length<6){u(e?.incorrectCodeError||"");return}const d=E?.data?.data?.active_token??E?.data?.active_token;d&&await k({token:d,code:b},{onSuccess:t=>{if(t.status>=200&&t.status<300)c("success"),l(e?.authSuccessMessage||""),h(!0),f?.user_id&&v(f.user_id),S({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"check_and_active",info:"Member Floating Window"}}),setTimeout(()=>{x()},3e3);else{const s=t?.data?.error_code??t?.error_code;s==="104"?(h(!0),f?.user_id&&v(f.user_id),S({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"check_and_active",info:"Member Floating Window"}}),setTimeout(()=>{x()},3e3)):u(s==="142"?e?.incorrectCodeError||"Invalid verification code.":s==="154"?e?.expiredCodeMessage||"":e?.sendEmailErrorMessage||"")}}});let a=setTimeout(()=>{c(""),l(""),clearTimeout(a)},5e3)},[b,e?.codeEmptyError,e?.authSuccessMessage,e?.incorrectCodeError,e?.expiredCodeMessage,e?.sendEmailErrorMessage,P,E,k,x,h,v,f]);return _("div",{className:"relative",children:[_("div",{children:[n(r,{className:"text-[22px] font-extrabold leading-[120%] text-[#333] min-l:text-[24px] [&_abbr]:text-[#005d8e]",html:e?.authCodeTitle}),n(r,{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:e?.authCodeDesc?.replace("%email%",i||"")})]}),_("div",{className:"mt-6",children:[n(r,{className:"mt-4 text-[14px] !font-bold font-semibold leading-[140%] text-[#333] min-l:mt-6",html:e?.enterActiveCodeText}),n("div",{className:"my-3 grid grid-cols-6 gap-2",children:o.map((d,a)=>n("div",{className:"col-span-1 aspect-1 text-[#555]",children:n("input",{ref:t=>{t&&(T.current[a]=t)},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",y&&"rounded-[12px]"),value:d,autoComplete:"false",autoCorrect:"false",spellCheck:"false",autoCapitalize:"false",onChange:t=>K(t,a),onFocus:()=>{m(a)},onPaste:t=>{const s=t.clipboardData.getData("text");if(!Number.isNaN(Number(s))){const g=s.split("").slice(0,6);N(g.concat(Array(6-g.length).fill(""))),g.length<=o.length&&m(g.length-1)}},onKeyDown:t=>{const{value:s}=t.target;t.key==="Backspace"&&!s&&a>0&&m(a-1)}},a)},a))}),I&&n(r,{className:"mb-3 text-[14px] font-semibold leading-[120%] text-[#f84d4f]",html:I}),e?.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:e?.authCodeContent}})]}),_("div",{className:"mt-4 min-l:mt-6",children:[n(r,{className:"text-base font-semibold leading-[100%] text-[#333]",html:e?.authCodeReceiveText})," ",A?n(r,{html:e?.retrieveText?.replace("%countdownTime%",z.toString()),className:"cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline"}):n(r,{onClick:W,className:L("cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline",{"pointer-events-none":A||B}),html:e?.sendAgainText}),n(q,{type:"submit",loading:F,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:O,children:e.buttonText})]}),n(Y,{status:j,message:$})]})}export{ae as default};
|
|
1
|
+
import{jsx as n,jsxs as _}from"react/jsx-runtime";import{useState as p,useCallback as R,useRef as U,useEffect as H}from"react";import{Button as q,Text as r}from"@anker-in/headless-ui";import{useSendEmailValidation as G,gaTrack as S,classNames as L,useHeadlessContext as J,useEmailValidation as Q,useCountDown as X}from"@anker-in/lib";import{Message as Y}from"../../../registration/authCodeActivate/Message";import{useRegistration as Z}from"../../../registration";import{useMemberPopupContext as ee}from"../../context/provider";import{ROUNDED_BRANDS as te}from"../../../../constants";function ae({copy:e,onClose:x}){const{setIsActivateSuccess:h,fetchCreditInfo:v,profile:f}=ee(),{locale:P,brand:V}=J(),{email:i}=Z(),y=te.includes(V),{isMutating:B,trigger:C,data:E}=G(),{isMutating:F,trigger:k}=Q(),[$,l]=p(""),[j,c]=p(""),{startCountDown:A,startAction:D,countDown:z}=X(60),[I,u]=p(""),[w,m]=p(0),[o,N]=p(new Array(6).fill("")),T=U([]),b=o.join("");H(()=>{T.current[w]&&T.current[w].focus()},[w]),H(()=>{i&&C({email:i,data:{redirect_url:`${window?.location?.origin}${window?.location?.pathname}`}},{onSuccess:()=>{c("success"),l(e?.sendEmailSuccessMessage||""),D(),setTimeout(()=>{c(""),l("")},5e3)}})},[i]);const W=R(async()=>{i&&(await C({email:i,data:{redirect_url:`${window?.location?.origin}${window?.location?.pathname}`}},{onSuccess:()=>{c("success"),l(e?.sendEmailSuccessMessage||""),D(),setTimeout(()=>{c(""),l("")},5e3)}}),S({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"sent_again"}}))},[i,C]),K=(d,a)=>{const{value:t}=d.target;if(u(""),Number.isNaN(Number(t)))return;if(t.length>1){a<o.length-1&&(o[a+1]||(m(a+1),N(g=>{const M=[...g];return M[a]=t[0],t.length>1&&(M[a+1]=t[1]),M})));return}const s=[...o];s[a]=t,N(s),t?a<o.length-1&&!o[a+1]&&m(a+1):a>0&&m(a-1)},O=R(async()=>{if(!b?.length){u(e?.codeEmptyError||"");return}if(b.length<6){u(e?.incorrectCodeError||"");return}const d=E?.data?.data?.active_token??E?.data?.active_token;d&&await k({token:d,code:b},{onSuccess:t=>{if(t.status>=200&&t.status<300)c("success"),l(e?.authSuccessMessage||""),h(!0),f?.user_id&&setTimeout(()=>v(f.user_id),3e3),S({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"check_and_active",info:"Member Floating Window"}}),setTimeout(()=>{x()},3e3);else{const s=t?.data?.error_code??t?.error_code;s==="104"?(h(!0),f?.user_id&&setTimeout(()=>v(f.user_id),3e3),S({event:"ga4Event",event_name:"lp_button",event_parameters:{page_group:"reg_sub_pop",position:"auth_code",button_name:"check_and_active",info:"Member Floating Window"}}),setTimeout(()=>{x()},3e3)):u(s==="142"?e?.incorrectCodeError||"Invalid verification code.":s==="154"?e?.expiredCodeMessage||"":e?.sendEmailErrorMessage||"")}}});let a=setTimeout(()=>{c(""),l(""),clearTimeout(a)},5e3)},[b,e?.codeEmptyError,e?.authSuccessMessage,e?.incorrectCodeError,e?.expiredCodeMessage,e?.sendEmailErrorMessage,P,E,k,x,h,v,f]);return _("div",{className:"relative",children:[_("div",{children:[n(r,{className:"text-[22px] font-extrabold leading-[120%] text-[#333] min-l:text-[24px] [&_abbr]:text-[#005d8e]",html:e?.authCodeTitle}),n(r,{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:e?.authCodeDesc?.replace("%email%",i||"")})]}),_("div",{className:"mt-6",children:[n(r,{className:"mt-4 text-[14px] !font-bold font-semibold leading-[140%] text-[#333] min-l:mt-6",html:e?.enterActiveCodeText}),n("div",{className:"my-3 grid grid-cols-6 gap-2",children:o.map((d,a)=>n("div",{className:"col-span-1 aspect-1 text-[#555]",children:n("input",{ref:t=>{t&&(T.current[a]=t)},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",y&&"rounded-[12px]"),value:d,autoComplete:"false",autoCorrect:"false",spellCheck:"false",autoCapitalize:"false",onChange:t=>K(t,a),onFocus:()=>{m(a)},onPaste:t=>{const s=t.clipboardData.getData("text");if(!Number.isNaN(Number(s))){const g=s.split("").slice(0,6);N(g.concat(Array(6-g.length).fill(""))),g.length<=o.length&&m(g.length-1)}},onKeyDown:t=>{const{value:s}=t.target;t.key==="Backspace"&&!s&&a>0&&m(a-1)}},a)},a))}),I&&n(r,{className:"mb-3 text-[14px] font-semibold leading-[120%] text-[#f84d4f]",html:I}),e?.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:e?.authCodeContent}})]}),_("div",{className:"mt-4 min-l:mt-6",children:[n(r,{className:"text-base font-semibold leading-[100%] text-[#333]",html:e?.authCodeReceiveText})," ",A?n(r,{html:e?.retrieveText?.replace("%countdownTime%",z.toString()),className:"cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline"}):n(r,{onClick:W,className:L("cursor-pointer text-base font-semibold leading-[100%] !text-brand text-[#005d8e] text-[#333] underline",{"pointer-events-none":A||B}),html:e?.sendAgainText}),n(q,{type:"submit",loading:F,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:O,children:e.buttonText})]}),n(Y,{status:j,message:$})]})}export{ae as default};
|
|
2
2
|
//# sourceMappingURL=ActivatePanel.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/EarnCredits/ActivatePanel.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useState, useCallback, useRef, useEffect } from 'react'\nimport { 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 { Message } from '../../../registration/authCodeActivate/Message'\nimport type { AuthCodeActivateCopy } from '../../type'\nimport { useRegistration } from '../../../registration'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: AuthCodeActivateCopy\n onClose: () => void\n}\n\nexport default function ActivatePanel({ copy, onClose }: Props) {\n const { setIsActivateSuccess, fetchCreditInfo, profile } = useMemberPopupContext()\n const { locale, brand } = useHeadlessContext()\n const { email } = useRegistration()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const {\n isMutating: isSendingEmail,\n trigger: triggerSendValidationEmail,\n data: sendEmailData,\n } = useSendEmailValidation()\n\n const { isMutating: emailValidationLoading, trigger: triggerEmailValidation } = useEmailValidation()\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 (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 }, [email])\n\n const handleSendAgain = useCallback(async () => {\n if (!email) return\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 const token = sendEmailData?.data?.data?.active_token ?? sendEmailData?.data?.active_token\n if (token) {\n await triggerEmailValidation(\n {\n token: token,\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 (profile?.user_id) fetchCreditInfo(profile.user_id)\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 info: 'Member Floating Window',\n },\n })\n setTimeout(() => {\n onClose()\n }, 3000)\n } else {\n const errorCode = data?.data?.error_code ?? data?.error_code\n if (errorCode === '104') {\n setIsActivateSuccess(true)\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\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 info: 'Member Floating Window',\n },\n })\n setTimeout(() => {\n onClose()\n }, 3000)\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 let timer = setTimeout(() => {\n setMessageStatus('')\n setMessageText('')\n clearTimeout(timer)\n }, 5000)\n }, [\n code,\n copy?.codeEmptyError,\n copy?.authSuccessMessage,\n copy?.incorrectCodeError,\n copy?.expiredCodeMessage,\n copy?.sendEmailErrorMessage,\n locale,\n sendEmailData,\n triggerEmailValidation,\n onClose,\n setIsActivateSuccess,\n fetchCreditInfo,\n profile,\n ])\n\n return (\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 )\n}\n"],
|
|
5
|
-
"mappings": "AA6OM,OACE,OAAAA,EADF,QAAAC,MAAA,oBA7ON,OAAS,YAAAC,EAAU,eAAAC,EAAa,UAAAC,EAAQ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AEvBE,CACT,CAAC,IAGL,MACF,CACA,MAAMA,EAAU,CAAC,GAAGV,CAAS,EAC7BU,EAAQH,CAAK,EAAIC,EACjBP,EAAaS,CAAO,EAChBF,EACED,EAAQP,EAAU,OAAS,GAAK,CAACA,EAAUO,EAAQ,CAAC,GACtDR,EAAcQ,EAAQ,CAAC,EAEhBA,EAAQ,GACjBR,EAAcQ,EAAQ,CAAC,CAE3B,EAEMI,EAAuBpD,EAAY,SAAY,CACnD,GAAI,CAAC4C,GAAM,OAAQ,CACjBN,EAAStB,GAAM,gBAAkB,EAAE,EACnC,MACF,CAEA,GAAI4B,EAAK,OAAS,EAAG,CACnBN,EAAStB,GAAM,oBAAsB,EAAE,EACvC,MACF,CAEA,MAAMqC,EAAQ1B,GAAe,MAAM,MAAM,cAAgBA,GAAe,MAAM,aAC1E0B,GACF,MAAMxB,EACJ,CACE,MAAOwB,EACP,KAAMT,CACR,EACA,CACE,UAAWU,GAAQ,CACjB,GAAIA,EAAK,QAAU,KAAOA,EAAK,OAAS,IACtCrB,EAAiB,SAAS,EAC1BF,EAAef,GAAM,oBAAsB,EAAE,EAC7CE,EAAqB,EAAI,EACrBE,GAAS,
|
|
4
|
+
"sourcesContent": ["import { useState, useCallback, useRef, useEffect } from 'react'\nimport { 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 { Message } from '../../../registration/authCodeActivate/Message'\nimport type { AuthCodeActivateCopy } from '../../type'\nimport { useRegistration } from '../../../registration'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: AuthCodeActivateCopy\n onClose: () => void\n}\n\nexport default function ActivatePanel({ copy, onClose }: Props) {\n const { setIsActivateSuccess, fetchCreditInfo, profile } = useMemberPopupContext()\n const { locale, brand } = useHeadlessContext()\n const { email } = useRegistration()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const {\n isMutating: isSendingEmail,\n trigger: triggerSendValidationEmail,\n data: sendEmailData,\n } = useSendEmailValidation()\n\n const { isMutating: emailValidationLoading, trigger: triggerEmailValidation } = useEmailValidation()\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 (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 }, [email])\n\n const handleSendAgain = useCallback(async () => {\n if (!email) return\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 const token = sendEmailData?.data?.data?.active_token ?? sendEmailData?.data?.active_token\n if (token) {\n await triggerEmailValidation(\n {\n token: token,\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 (profile?.user_id) setTimeout(() => fetchCreditInfo(profile.user_id), 3000)\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 info: 'Member Floating Window',\n },\n })\n setTimeout(() => {\n onClose()\n }, 3000)\n } else {\n const errorCode = data?.data?.error_code ?? data?.error_code\n if (errorCode === '104') {\n setIsActivateSuccess(true)\n if (profile?.user_id) setTimeout(() => fetchCreditInfo(profile.user_id), 3000)\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 info: 'Member Floating Window',\n },\n })\n setTimeout(() => {\n onClose()\n }, 3000)\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 let timer = setTimeout(() => {\n setMessageStatus('')\n setMessageText('')\n clearTimeout(timer)\n }, 5000)\n }, [\n code,\n copy?.codeEmptyError,\n copy?.authSuccessMessage,\n copy?.incorrectCodeError,\n copy?.expiredCodeMessage,\n copy?.sendEmailErrorMessage,\n locale,\n sendEmailData,\n triggerEmailValidation,\n onClose,\n setIsActivateSuccess,\n fetchCreditInfo,\n profile,\n ])\n\n return (\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 )\n}\n"],
|
|
5
|
+
"mappings": "AA6OM,OACE,OAAAA,EADF,QAAAC,MAAA,oBA7ON,OAAS,YAAAC,EAAU,eAAAC,EAAa,UAAAC,EAAQ,aAAAC,MAAiB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,MAAM,EAAG,CAAC,EAC7CjB,EAAakB,EAAW,OAAO,MAAM,EAAIA,EAAW,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,EACjEA,EAAW,QAAUnB,EAAU,QACjCD,EAAcoB,EAAW,OAAS,CAAC,CAEvC,CACF,EACA,UAAWb,GAAS,CAClB,KAAM,CAAE,MAAAE,CAAM,EAAIF,EAAM,OACpBA,EAAM,MAAQ,aAAe,CAACE,GAASD,EAAQ,GACjDR,EAAcQ,EAAQ,CAAC,CAE3B,GA9BKA,CA+BP,GAtCQA,CAuCV,CACD,EACH,EAECX,GAASxC,EAACO,EAAA,CAAK,UAAU,+DAA+D,KAAMiC,EAAO,EACrGrB,GAAM,iBACLnB,EAAC,MACC,UAAU,gLACV,wBAAyB,CAAE,OAAQmB,GAAM,eAAgB,EAC3D,GAEJ,EACAlB,EAAC,OAAI,UAAU,kBACb,UAAAD,EAACO,EAAA,CAAK,UAAU,qDAAqD,KAAMY,GAAM,oBAAqB,EAAG,IACxGkB,EACCrC,EAACO,EAAA,CACC,KAAMY,GAAM,cAAc,QAAQ,kBAAmBoB,EAAU,SAAS,CAAC,EACzE,UAAU,yGACZ,EAEAvC,EAACO,EAAA,CACC,QAASyC,EACT,UAAWtC,EACT,yGACA,CACE,sBAAuB2B,GAAoBT,CAC7C,CACF,EACA,KAAMT,GAAM,cACd,EAEFnB,EAACM,EAAA,CACC,KAAK,SACL,QAASyB,EACT,UAAU,2JACV,QAASwB,EAER,SAAApC,EAAK,WACR,GACF,EACAnB,EAACc,EAAA,CAAQ,OAAQqB,EAAe,QAASF,EAAa,GACxD,CAEJ",
|
|
6
6
|
"names": ["jsx", "jsxs", "useState", "useCallback", "useRef", "useEffect", "Button", "Text", "useSendEmailValidation", "gaTrack", "cn", "useHeadlessContext", "useEmailValidation", "useCountDown", "Message", "useRegistration", "useMemberPopupContext", "ROUNDED_BRANDS", "ActivatePanel", "copy", "onClose", "setIsActivateSuccess", "fetchCreditInfo", "profile", "locale", "brand", "email", "rounded", "isSendingEmail", "triggerSendValidationEmail", "sendEmailData", "emailValidationLoading", "triggerEmailValidation", "messageText", "setMessageText", "messageStatus", "setMessageStatus", "isStartCountDown", "startCountDown", "countDown", "error", "setError", "focusIndex", "setFocusIndex", "codeArray", "setCodeArray", "inputRefs", "code", "handleSendAgain", "handleInputCodeChange", "event", "index", "value", "old", "newCode", "handleAuthCodeSubmit", "token", "data", "errorCode", "timer", "item", "inputRef", "paste", "pastedCode"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as t,jsxs as n}from"react/jsx-runtime";import{useCallback as q,useEffect as F,useState as r}from"react";import{Button as L,Text as g}from"@anker-in/headless-ui";import{gaTrack as
|
|
1
|
+
import{jsx as t,jsxs as n}from"react/jsx-runtime";import{useCallback as q,useEffect as F,useState as r}from"react";import{Button as L,Text as g}from"@anker-in/headless-ui";import{gaTrack as R,classNames as s,useHeadlessContext as U}from"@anker-in/lib";import{useUpdateProfile as A}from"./hooks/useUpdateProfile";import H from"../../../credits/context/hooks/useCountries";import{useMemberPopupContext as O}from"../../context/provider";import{ROUNDED_BRANDS as W}from"../../../../constants";function G({copy:a,onClose:x}){const{profile:o,fetchCreditInfo:C,alpcConfig:_,setIsProfileCompleteSuccess:k}=O(),{locale:T}=_,{brand:z,storeDomain:I}=U(),l=W.includes(z),[d,P]=r(""),[i,w]=r(""),[u,E]=r(""),[f,y]=r(""),[p,c]=r(""),[b,v]=r(""),[N,h]=r(""),{updateProfile:D,isLoading:B}=A({locale:T,appName:_.appName}),{countries:m}=H({shopifyStoreDomain:I});F(()=>{o&&(P(o.first_name??""),w(o.last_name??""),E(o.phone_number??""),y(o.dob??""),c(o.country?.id??""))},[o]),F(()=>{m.length>0&&!p&&c(m[0].id)},[m]);const S=q(()=>{let e=!1;return d.trim()?v(""):(v(a.required),e=!0),i.trim()?h(""):(h(a.required),e=!0),e},[d,i,a.required]),M=q(async()=>{if(S())return;await D({first_name:d.trim(),last_name:i.trim(),phone_number:u,country:p,dob:f})&&(setTimeout(()=>C(o?.user_id),3e3),k(!0),R({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"earn_credits",button_name:"complete_profile_success",info:"Member Floating Window"}}),x())},[S,D,d,i,u,p,f,C,o,k,x]);return n("div",{className:"flex flex-col gap-[16px]",children:[a.subtitle&&t(g,{className:"text-[14px] text-[#1d1d1f]",html:a.subtitle}),n("div",{children:[t("label",{className:"block text-[14px] font-[700] text-[#1d1d1f]",children:a.email}),t("input",{className:s("mt-[8px] h-[46px] w-full border border-[#d8d8d8] bg-[#f5f5f5] px-[12px] text-[14px] text-[#999]",l?"rounded-[4px]":"rounded-none"),value:o?.email??"",disabled:!0})]}),n("div",{children:[n("label",{className:"block text-[14px] font-[700] text-[#1d1d1f]",children:[a.firstName," ",t("span",{className:"text-[#f84d4f]",children:"*"})]}),t("input",{className:s("mt-[8px] h-[46px] w-full border px-[12px] text-[14px] outline-none",b?"border-[#f84d4f]":"border-[#d8d8d8]",l?"rounded-[4px]":"rounded-none"),value:d,onChange:e=>{P(e.target.value),v("")}}),b&&t(g,{className:"mt-[4px] text-[12px] text-[#f84d4f]",html:b})]}),n("div",{children:[n("label",{className:"block text-[14px] font-[700] text-[#1d1d1f]",children:[a.lastName," ",t("span",{className:"text-[#f84d4f]",children:"*"})]}),t("input",{className:s("mt-[8px] h-[46px] w-full border px-[12px] text-[14px] outline-none",N?"border-[#f84d4f]":"border-[#d8d8d8]",l?"rounded-[4px]":"rounded-none"),value:i,onChange:e=>{w(e.target.value),h("")}}),N&&t(g,{className:"mt-[4px] text-[12px] text-[#f84d4f]",html:N})]}),n("div",{children:[t("label",{className:"block text-[14px] font-[700] text-[#1d1d1f]",children:a.birthday}),t("input",{className:s("mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none",l?"rounded-[4px]":"rounded-none"),type:"date",value:f,onChange:e=>y(e.target.value)})]}),n("div",{children:[t("label",{className:"block text-[14px] font-[700] text-[#1d1d1f]",children:a.phone}),t("input",{className:s("mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none",l?"rounded-[4px]":"rounded-none"),value:u,onChange:e=>E(e.target.value)})]}),n("div",{children:[t("label",{className:"block text-[14px] font-[700] text-[#1d1d1f]",children:a.country}),t("select",{className:s("mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none",l?"rounded-[4px]":"rounded-none"),value:p,onChange:e=>c(e.target.value),children:m.map(e=>t("option",{value:e.id,children:e.name},e.id))})]}),n("div",{className:"flex gap-[12px]",children:[t(L,{variant:"secondary",size:"lg",className:"flex-1",onClick:x,disabled:B,children:a.cancel}),t(L,{variant:"primary",size:"lg",className:"flex-1",loading:B,onClick:M,children:a.save})]})]})}export{G as default};
|
|
2
2
|
//# sourceMappingURL=CompleteProfilePanel.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport { Button, Text } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport type { CompleteProfileCopy } from '../../type'\nimport { useUpdateProfile } from './hooks/useUpdateProfile'\nimport useCountries from '../../../credits/context/hooks/useCountries'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: CompleteProfileCopy\n onClose: () => void\n}\n\nexport default function CompleteProfilePanel({ copy, onClose }: Props) {\n const { profile, fetchCreditInfo, alpcConfig, setIsProfileCompleteSuccess } = useMemberPopupContext()\n const { locale } = alpcConfig\n const { brand, storeDomain } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [firstName, setFirstName] = useState('')\n const [lastName, setLastName] = useState('')\n const [phone, setPhone] = useState('')\n const [birthDay, setBirthDay] = useState('')\n const [country, setCountry] = useState('')\n const [firstNameError, setFirstNameError] = useState('')\n const [lastNameError, setLastNameError] = useState('')\n\n const { updateProfile, isLoading } = useUpdateProfile({ locale, appName: alpcConfig.appName })\n const { countries } = useCountries({ shopifyStoreDomain: storeDomain })\n\n useEffect(() => {\n if (profile) {\n setFirstName(profile.first_name ?? '')\n setLastName(profile.last_name ?? '')\n setPhone(profile.phone_number ?? '')\n setBirthDay(profile.dob ?? '')\n setCountry(profile.country?.id ?? '')\n }\n }, [profile])\n\n useEffect(() => {\n if (countries.length > 0 && !country) {\n setCountry(countries[0].id)\n }\n }, [countries])\n\n const validate = useCallback(() => {\n let hasError = false\n if (!firstName.trim()) {\n setFirstNameError(copy.required)\n hasError = true\n } else {\n setFirstNameError('')\n }\n if (!lastName.trim()) {\n setLastNameError(copy.required)\n hasError = true\n } else {\n setLastNameError('')\n }\n return hasError\n }, [firstName, lastName, copy.required])\n\n const handleSubmit = useCallback(async () => {\n if (validate()) return\n const success = await updateProfile({\n first_name: firstName.trim(),\n last_name: lastName.trim(),\n phone_number: phone,\n country,\n dob: birthDay,\n })\n if (success) {\n fetchCreditInfo(profile?.user_id)\n setIsProfileCompleteSuccess(true)\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'earn_credits',\n button_name: 'complete_profile_success',\n info: 'Member Floating Window',\n },\n })\n onClose()\n }\n }, [\n validate,\n updateProfile,\n firstName,\n lastName,\n phone,\n country,\n birthDay,\n fetchCreditInfo,\n profile,\n setIsProfileCompleteSuccess,\n onClose,\n ])\n\n return (\n <div className=\"flex flex-col gap-[16px]\">\n {copy.subtitle && <Text className=\"text-[14px] text-[#1d1d1f]\" html={copy.subtitle} />}\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.email}</label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] bg-[#f5f5f5] px-[12px] text-[14px] text-[#999]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={profile?.email ?? ''}\n disabled\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">\n {copy.firstName} <span className=\"text-[#f84d4f]\">*</span>\n </label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border px-[12px] text-[14px] outline-none',\n firstNameError ? 'border-[#f84d4f]' : 'border-[#d8d8d8]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={firstName}\n onChange={e => {\n setFirstName(e.target.value)\n setFirstNameError('')\n }}\n />\n {firstNameError && <Text className=\"mt-[4px] text-[12px] text-[#f84d4f]\" html={firstNameError} />}\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">\n {copy.lastName} <span className=\"text-[#f84d4f]\">*</span>\n </label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border px-[12px] text-[14px] outline-none',\n lastNameError ? 'border-[#f84d4f]' : 'border-[#d8d8d8]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={lastName}\n onChange={e => {\n setLastName(e.target.value)\n setLastNameError('')\n }}\n />\n {lastNameError && <Text className=\"mt-[4px] text-[12px] text-[#f84d4f]\" html={lastNameError} />}\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.birthday}</label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n type=\"date\"\n value={birthDay}\n onChange={e => setBirthDay(e.target.value)}\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.phone}</label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={phone}\n onChange={e => setPhone(e.target.value)}\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.country}</label>\n <select\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={country}\n onChange={e => setCountry(e.target.value)}\n >\n {countries.map((c: { id: string; name: string }) => (\n <option key={c.id} value={c.id}>\n {c.name}\n </option>\n ))}\n </select>\n </div>\n\n <div className=\"flex gap-[12px]\">\n <Button variant=\"secondary\" size=\"lg\" className=\"flex-1\" onClick={onClose} disabled={isLoading}>\n {copy.cancel}\n </Button>\n <Button variant=\"primary\" size=\"lg\" className=\"flex-1\" loading={isLoading} onClick={handleSubmit}>\n {copy.save}\n </Button>\n </div>\n </div>\n )\n}\n"],
|
|
5
|
-
"mappings": "AAuGwB,cAAAA,EAElB,QAAAC,MAFkB,oBAvGxB,OAAS,eAAAC,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QACjD,OAAS,UAAAC,EAAQ,QAAAC,MAAY,wBAC7B,OAAS,WAAAC,EAAS,cAAcC,EAAI,sBAAAC,MAA0B,gBAE9D,OAAS,oBAAAC,MAAwB,2BACjC,OAAOC,MAAkB,8CACzB,OAAS,yBAAAC,MAA6B,yBACtC,OAAS,kBAAAC,MAAsB,wBAOhB,SAARC,EAAsC,CAAE,KAAAC,EAAM,QAAAC,CAAQ,EAAU,CACrE,KAAM,CAAE,QAAAC,EAAS,gBAAAC,EAAiB,WAAAC,EAAY,4BAAAC,CAA4B,EAAIR,EAAsB,EAC9F,CAAE,OAAAS,CAAO,EAAIF,EACb,CAAE,MAAAG,EAAO,YAAAC,CAAY,EAAId,EAAmB,EAC5Ce,EAAUX,EAAe,SAASS,CAAK,EAEvC,CAACG,EAAWC,CAAY,EAAItB,EAAS,EAAE,EACvC,CAACuB,EAAUC,CAAW,EAAIxB,EAAS,EAAE,EACrC,CAACyB,EAAOC,CAAQ,EAAI1B,EAAS,EAAE,EAC/B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 'react'\nimport { Button, Text } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport type { CompleteProfileCopy } from '../../type'\nimport { useUpdateProfile } from './hooks/useUpdateProfile'\nimport useCountries from '../../../credits/context/hooks/useCountries'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: CompleteProfileCopy\n onClose: () => void\n}\n\nexport default function CompleteProfilePanel({ copy, onClose }: Props) {\n const { profile, fetchCreditInfo, alpcConfig, setIsProfileCompleteSuccess } = useMemberPopupContext()\n const { locale } = alpcConfig\n const { brand, storeDomain } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [firstName, setFirstName] = useState('')\n const [lastName, setLastName] = useState('')\n const [phone, setPhone] = useState('')\n const [birthDay, setBirthDay] = useState('')\n const [country, setCountry] = useState('')\n const [firstNameError, setFirstNameError] = useState('')\n const [lastNameError, setLastNameError] = useState('')\n\n const { updateProfile, isLoading } = useUpdateProfile({ locale, appName: alpcConfig.appName })\n const { countries } = useCountries({ shopifyStoreDomain: storeDomain })\n\n useEffect(() => {\n if (profile) {\n setFirstName(profile.first_name ?? '')\n setLastName(profile.last_name ?? '')\n setPhone(profile.phone_number ?? '')\n setBirthDay(profile.dob ?? '')\n setCountry(profile.country?.id ?? '')\n }\n }, [profile])\n\n useEffect(() => {\n if (countries.length > 0 && !country) {\n setCountry(countries[0].id)\n }\n }, [countries])\n\n const validate = useCallback(() => {\n let hasError = false\n if (!firstName.trim()) {\n setFirstNameError(copy.required)\n hasError = true\n } else {\n setFirstNameError('')\n }\n if (!lastName.trim()) {\n setLastNameError(copy.required)\n hasError = true\n } else {\n setLastNameError('')\n }\n return hasError\n }, [firstName, lastName, copy.required])\n\n const handleSubmit = useCallback(async () => {\n if (validate()) return\n const success = await updateProfile({\n first_name: firstName.trim(),\n last_name: lastName.trim(),\n phone_number: phone,\n country,\n dob: birthDay,\n })\n if (success) {\n setTimeout(() => fetchCreditInfo(profile?.user_id), 3000)\n setIsProfileCompleteSuccess(true)\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'earn_credits',\n button_name: 'complete_profile_success',\n info: 'Member Floating Window',\n },\n })\n onClose()\n }\n }, [\n validate,\n updateProfile,\n firstName,\n lastName,\n phone,\n country,\n birthDay,\n fetchCreditInfo,\n profile,\n setIsProfileCompleteSuccess,\n onClose,\n ])\n\n return (\n <div className=\"flex flex-col gap-[16px]\">\n {copy.subtitle && <Text className=\"text-[14px] text-[#1d1d1f]\" html={copy.subtitle} />}\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.email}</label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] bg-[#f5f5f5] px-[12px] text-[14px] text-[#999]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={profile?.email ?? ''}\n disabled\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">\n {copy.firstName} <span className=\"text-[#f84d4f]\">*</span>\n </label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border px-[12px] text-[14px] outline-none',\n firstNameError ? 'border-[#f84d4f]' : 'border-[#d8d8d8]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={firstName}\n onChange={e => {\n setFirstName(e.target.value)\n setFirstNameError('')\n }}\n />\n {firstNameError && <Text className=\"mt-[4px] text-[12px] text-[#f84d4f]\" html={firstNameError} />}\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">\n {copy.lastName} <span className=\"text-[#f84d4f]\">*</span>\n </label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border px-[12px] text-[14px] outline-none',\n lastNameError ? 'border-[#f84d4f]' : 'border-[#d8d8d8]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={lastName}\n onChange={e => {\n setLastName(e.target.value)\n setLastNameError('')\n }}\n />\n {lastNameError && <Text className=\"mt-[4px] text-[12px] text-[#f84d4f]\" html={lastNameError} />}\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.birthday}</label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n type=\"date\"\n value={birthDay}\n onChange={e => setBirthDay(e.target.value)}\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.phone}</label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={phone}\n onChange={e => setPhone(e.target.value)}\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-[700] text-[#1d1d1f]\">{copy.country}</label>\n <select\n className={cn(\n 'mt-[8px] h-[46px] w-full border border-[#d8d8d8] px-[12px] text-[14px] outline-none',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n value={country}\n onChange={e => setCountry(e.target.value)}\n >\n {countries.map((c: { id: string; name: string }) => (\n <option key={c.id} value={c.id}>\n {c.name}\n </option>\n ))}\n </select>\n </div>\n\n <div className=\"flex gap-[12px]\">\n <Button variant=\"secondary\" size=\"lg\" className=\"flex-1\" onClick={onClose} disabled={isLoading}>\n {copy.cancel}\n </Button>\n <Button variant=\"primary\" size=\"lg\" className=\"flex-1\" loading={isLoading} onClick={handleSubmit}>\n {copy.save}\n </Button>\n </div>\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": "AAuGwB,cAAAA,EAElB,QAAAC,MAFkB,oBAvGxB,OAAS,eAAAC,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QACjD,OAAS,UAAAC,EAAQ,QAAAC,MAAY,wBAC7B,OAAS,WAAAC,EAAS,cAAcC,EAAI,sBAAAC,MA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MADQA,EAAE,EAEf,CACD,EACH,GACF,EAEA5C,EAAC,OAAI,UAAU,kBACb,UAAAD,EAACK,EAAA,CAAO,QAAQ,YAAY,KAAK,KAAK,UAAU,SAAS,QAASW,EAAS,SAAUwB,EAClF,SAAAzB,EAAK,OACR,EACAf,EAACK,EAAA,CAAO,QAAQ,UAAU,KAAK,KAAK,UAAU,SAAS,QAASmC,EAAW,QAASI,EACjF,SAAA7B,EAAK,KACR,GACF,GACF,CAEJ",
|
|
6
6
|
"names": ["jsx", "jsxs", "useCallback", "useEffect", "useState", "Button", "Text", "gaTrack", "cn", "useHeadlessContext", "useUpdateProfile", "useCountries", "useMemberPopupContext", "ROUNDED_BRANDS", "CompleteProfilePanel", "copy", "onClose", "profile", "fetchCreditInfo", "alpcConfig", "setIsProfileCompleteSuccess", "locale", "brand", "storeDomain", "rounded", "firstName", "setFirstName", "lastName", "setLastName", "phone", "setPhone", "birthDay", "setBirthDay", "country", "setCountry", "firstNameError", "setFirstNameError", "lastNameError", "setLastNameError", "updateProfile", "isLoading", "countries", "validate", "hasError", "handleSubmit", "c"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as t,jsxs as d}from"react/jsx-runtime";import{useCallback as D,useEffect as E,useState as l}from"react";import{Checkbox as I,Text as S}from"@anker-in/headless-ui";import{gaTrack as L,classNames as p,useHeadlessContext as O}from"@anker-in/lib";import c from"js-cookie";import{parse as A}from"query-string";import{emailValidate as B}from"../../../credits/context/utils";import{useMemberPopupContext as H}from"../../context/provider";import{ROUNDED_BRANDS as R}from"../../../../constants";function j(){if(typeof window>"u")return{register_source:""};const{search:e,href:o}=window.location,a=A(e);return{fbuy_ref_code:c.get("fbuy_ref_code"),ref:c.get("ref_ads"),inviter_code:a.ic??a.inviter_code??c.get("inviter_code"),register_source:a.redirect??c.get("reg_source")??o}}function q({copy:e,email:o,onClose:a}){const{alpcConfig:k,setIsSubscribeSuccess:m,fetchCreditInfo:w,profile:x}=H(),{brand:b,locale:g}=k,{brand:T}=O(),h=R.includes(T),[u,_]=l(e.policyDefaultChecked??!1),[i,v]=l(o??""),[n,s]=l(""),[f,y]=l(""),[M,C]=l(!1);E(()=>{o&&v(o)},[o]);const P=D(async()=>{if(s(""),!i)return s("Please fill in your email");if(!B(i))return s("Invalid email address");if(!u)return s("Please agree to the policy");C(!0);const{register_source:r}=j();try{const N=await(await fetch("/api/multipass/subscribe/subscribe_emails",{method:"POST",headers:{"Content-Type":"application/json","current-language":g},body:JSON.stringify({email:i,register_source:r,brand:b,deals_type:e.dealsType??"vip_subscribe"})})).json();N.errors?s(N.errors??"Error occurred"):(y(e.successTips??"Subscribed successfully!"),m(!0),x?.user_id&&w(x.user_id),L({event:"ga4Event",event_name:"subscribe",event_parameters:{page_group:e.dealsType??"",position:"sticky",info:""}}),setTimeout(()=>{y(""),a()},3e3))}catch{s("Network error")}finally{C(!1)}},[i,u,g,b,e,a,m]);return d("div",{className:"flex flex-col gap-[12px]",children:[d("div",{className:"flex flex-col gap-[8px]",children:[e.title&&t("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:e.title}),e.desc&&t(S,{className:"text-[16px] text-[#1e2024]",html:e.desc})]}),d("div",{className:"flex flex-col gap-[16px]",children:[t("input",{className:p("h-[46px] w-full border px-[14px] text-[16px] outline-none placeholder:text-[#999]",n?"border-[#f84d4f]":"border-[#d8d8d8]",h?"rounded-[4px]":"rounded-none"),placeholder:e.placeholder,value:i,onChange:r=>{s(""),v(r.target.value.trim())}}),d("div",{className:"flex w-full items-start gap-[8px]",children:[t(I,{checked:u,onCheckedChange:()=>_(r=>!r),className:"mt-[2px] border-[#1d1d1f]"}),t("label",{className:"cursor-pointer text-left text-[14px] text-[#1e2024] [&_a]:underline",onClick:()=>_(r=>!r),dangerouslySetInnerHTML:{__html:e.policy??""}})]}),(n||f)&&t("div",{className:p("text-[14px] font-[700]",n&&"text-[#f84d4f]",f&&"text-[#52c41a]"),children:t(S,{html:f||n})}),t("button",{className:p("w-full cursor-pointer bg-[#080a0f] py-[14px] text-[14px] font-[700] text-white disabled:opacity-60",h?"rounded-[4px]":"rounded-none"),disabled:M,onClick:P,children:e.buttonLabel??"Subscribe"})]})]})}export{q as default};
|
|
1
|
+
import{jsx as t,jsxs as d}from"react/jsx-runtime";import{useCallback as D,useEffect as E,useState as l}from"react";import{Checkbox as I,Text as S}from"@anker-in/headless-ui";import{gaTrack as L,classNames as p,useHeadlessContext as O}from"@anker-in/lib";import c from"js-cookie";import{parse as A}from"query-string";import{emailValidate as B}from"../../../credits/context/utils";import{useMemberPopupContext as H}from"../../context/provider";import{ROUNDED_BRANDS as R}from"../../../../constants";function j(){if(typeof window>"u")return{register_source:""};const{search:e,href:o}=window.location,a=A(e);return{fbuy_ref_code:c.get("fbuy_ref_code"),ref:c.get("ref_ads"),inviter_code:a.ic??a.inviter_code??c.get("inviter_code"),register_source:a.redirect??c.get("reg_source")??o}}function q({copy:e,email:o,onClose:a}){const{alpcConfig:k,setIsSubscribeSuccess:m,fetchCreditInfo:w,profile:x}=H(),{brand:b,locale:g}=k,{brand:T}=O(),h=R.includes(T),[u,_]=l(e.policyDefaultChecked??!1),[i,v]=l(o??""),[n,s]=l(""),[f,y]=l(""),[M,C]=l(!1);E(()=>{o&&v(o)},[o]);const P=D(async()=>{if(s(""),!i)return s("Please fill in your email");if(!B(i))return s("Invalid email address");if(!u)return s("Please agree to the policy");C(!0);const{register_source:r}=j();try{const N=await(await fetch("/api/multipass/subscribe/subscribe_emails",{method:"POST",headers:{"Content-Type":"application/json","current-language":g},body:JSON.stringify({email:i,register_source:r,brand:b,deals_type:e.dealsType??"vip_subscribe"})})).json();N.errors?s(N.errors??"Error occurred"):(y(e.successTips??"Subscribed successfully!"),m(!0),x?.user_id&&setTimeout(()=>w(x.user_id),3e3),L({event:"ga4Event",event_name:"subscribe",event_parameters:{page_group:e.dealsType??"",position:"sticky",info:""}}),setTimeout(()=>{y(""),a()},3e3))}catch{s("Network error")}finally{C(!1)}},[i,u,g,b,e,a,m]);return d("div",{className:"flex flex-col gap-[12px]",children:[d("div",{className:"flex flex-col gap-[8px]",children:[e.title&&t("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:e.title}),e.desc&&t(S,{className:"text-[16px] text-[#1e2024]",html:e.desc})]}),d("div",{className:"flex flex-col gap-[16px]",children:[t("input",{className:p("h-[46px] w-full border px-[14px] text-[16px] outline-none placeholder:text-[#999]",n?"border-[#f84d4f]":"border-[#d8d8d8]",h?"rounded-[4px]":"rounded-none"),placeholder:e.placeholder,value:i,onChange:r=>{s(""),v(r.target.value.trim())}}),d("div",{className:"flex w-full items-start gap-[8px]",children:[t(I,{checked:u,onCheckedChange:()=>_(r=>!r),className:"mt-[2px] border-[#1d1d1f]"}),t("label",{className:"cursor-pointer text-left text-[14px] text-[#1e2024] [&_a]:underline",onClick:()=>_(r=>!r),dangerouslySetInnerHTML:{__html:e.policy??""}})]}),(n||f)&&t("div",{className:p("text-[14px] font-[700]",n&&"text-[#f84d4f]",f&&"text-[#52c41a]"),children:t(S,{html:f||n})}),t("button",{className:p("w-full cursor-pointer bg-[#080a0f] py-[14px] text-[14px] font-[700] text-white disabled:opacity-60",h?"rounded-[4px]":"rounded-none"),disabled:M,onClick:P,children:e.buttonLabel??"Subscribe"})]})]})}export{q as default};
|
|
2
2
|
//# sourceMappingURL=SubscribeEmailPanel.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport { Checkbox, Text } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport Cookies from 'js-cookie'\nimport { parse } from 'query-string'\nimport { emailValidate } from '../../../credits/context/utils'\nimport { useMemberPopupContext } from '../../context/provider'\nimport type { SubscribeModalCopy } from '../../type'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: SubscribeModalCopy\n email?: string\n onClose: () => void\n}\n\nfunction getAdCookie() {\n if (typeof window === 'undefined') return { register_source: '' }\n const { search, href } = window.location\n const query = parse(search)\n return {\n fbuy_ref_code: Cookies.get('fbuy_ref_code'),\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 }\n}\n\nexport default function SubscribeEmailPanel({ copy, email: initialEmail, onClose }: Props) {\n const { alpcConfig, setIsSubscribeSuccess, fetchCreditInfo, profile } = useMemberPopupContext()\n const { brand, locale } = alpcConfig\n const { brand: headlessBrand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(headlessBrand)\n const [policy, setPolicy] = useState(copy.policyDefaultChecked ?? false)\n const [email, setEmail] = useState(initialEmail ?? '')\n const [errorMessage, setErrorMessage] = useState('')\n const [successMessage, setSuccessMessage] = useState('')\n const [loading, setLoading] = useState(false)\n\n useEffect(() => {\n if (initialEmail) setEmail(initialEmail)\n }, [initialEmail])\n\n const handleSubmit = useCallback(async () => {\n setErrorMessage('')\n if (!email) return setErrorMessage('Please fill in your email')\n if (!emailValidate(email)) return setErrorMessage('Invalid email address')\n if (!policy) return setErrorMessage('Please agree to the policy')\n\n setLoading(true)\n const { register_source } = getAdCookie()\n try {\n const response = await fetch('/api/multipass/subscribe/subscribe_emails', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', 'current-language': locale },\n body: JSON.stringify({\n email,\n register_source,\n brand,\n deals_type: copy.dealsType ?? 'vip_subscribe',\n }),\n })\n const result = await response.json()\n if (!result.errors) {\n setSuccessMessage(copy.successTips ?? 'Subscribed successfully!')\n setIsSubscribeSuccess(true)\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n gaTrack({\n event: 'ga4Event',\n event_name: 'subscribe',\n event_parameters: {\n page_group: copy.dealsType ?? '',\n position: 'sticky',\n info: '',\n },\n })\n setTimeout(() => {\n setSuccessMessage('')\n onClose()\n }, 3000)\n } else {\n setErrorMessage(result.errors ?? 'Error occurred')\n }\n } catch {\n setErrorMessage('Network error')\n } finally {\n setLoading(false)\n }\n }, [email, policy, locale, brand, copy, onClose, setIsSubscribeSuccess])\n\n return (\n <div className=\"flex flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && (\n <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>\n )}\n {copy.desc && (\n <Text className=\"text-[16px] text-[#1e2024]\" html={copy.desc} />\n )}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n <input\n className={cn(\n 'h-[46px] w-full border px-[14px] text-[16px] outline-none placeholder:text-[#999]',\n errorMessage ? 'border-[#f84d4f]' : 'border-[#d8d8d8]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n placeholder={copy.placeholder}\n value={email}\n onChange={e => { setErrorMessage(''); setEmail(e.target.value.trim()) }}\n />\n\n <div className=\"flex w-full items-start gap-[8px]\">\n <Checkbox checked={policy} onCheckedChange={() => setPolicy(v => !v)} className=\"mt-[2px] border-[#1d1d1f]\" />\n <label\n className=\"cursor-pointer text-left text-[14px] text-[#1e2024] [&_a]:underline\"\n onClick={() => setPolicy(v => !v)}\n dangerouslySetInnerHTML={{ __html: copy.policy ?? '' }}\n />\n </div>\n\n {(errorMessage || successMessage) && (\n <div className={cn('text-[14px] font-[700]', errorMessage && 'text-[#f84d4f]', successMessage && 'text-[#52c41a]')}>\n <Text html={successMessage || errorMessage} />\n </div>\n )}\n\n <button\n className={cn('w-full cursor-pointer bg-[#080a0f] py-[14px] text-[14px] font-[700] text-white disabled:opacity-60', rounded ? 'rounded-[4px]' : 'rounded-none')}\n disabled={loading}\n onClick={handleSubmit}\n >\n {copy.buttonLabel ?? 'Subscribe'}\n </button>\n </div>\n </div>\n )\n}\n"],
|
|
5
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,CAAU,EAAIpC,EAAS,EAAK,EAE5CD,EAAU,IAAM,CACVkB,GAAca,EAASb,CAAY,CACzC,EAAG,CAACA,CAAY,CAAC,EAEjB,MAAMoB,EAAevC,EAAY,SAAY,CAE3C,GADAkC,EAAgB,EAAE,EACd,CAACH,EAAO,OAAOG,EAAgB,2BAA2B,EAC9D,GAAI,CAACxB,EAAcqB,CAAK,EAAG,OAAOG,EAAgB,uBAAuB,EACzE,GAAI,CAACL,EAAQ,OAAOK,EAAgB,4BAA4B,EAEhEI,EAAW,EAAI,EACf,KAAM,CAAE,gBAAAE,CAAgB,EAAI3B,EAAY,EACxC,GAAI,CAWF,MAAM4B,EAAS,MAVE,MAAM,MAAM,4CAA6C,CACxE,OAAQ,OACR,QAAS,CAAE,eAAgB,mBAAoB,mBAAoBf,CAAO,EAC1E,KAAM,KAAK,UAAU,CACnB,MAAAK,EACA,gBAAAS,EACA,MAAAf,EACA,WAAYP,EAAK,WAAa,eAChC,CAAC,CACH,CAAC,GAC6B,KAAK,EAC9BuB,EAAO,OAkBVP,EAAgBO,EAAO,QAAU,gBAAgB,GAjBjDL,EAAkBlB,EAAK,aAAe,0BAA0B,EAChEI,EAAsB,EAAI,EACtBE,GAAS,
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport { Checkbox, Text } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport Cookies from 'js-cookie'\nimport { parse } from 'query-string'\nimport { emailValidate } from '../../../credits/context/utils'\nimport { useMemberPopupContext } from '../../context/provider'\nimport type { SubscribeModalCopy } from '../../type'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: SubscribeModalCopy\n email?: string\n onClose: () => void\n}\n\nfunction getAdCookie() {\n if (typeof window === 'undefined') return { register_source: '' }\n const { search, href } = window.location\n const query = parse(search)\n return {\n fbuy_ref_code: Cookies.get('fbuy_ref_code'),\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 }\n}\n\nexport default function SubscribeEmailPanel({ copy, email: initialEmail, onClose }: Props) {\n const { alpcConfig, setIsSubscribeSuccess, fetchCreditInfo, profile } = useMemberPopupContext()\n const { brand, locale } = alpcConfig\n const { brand: headlessBrand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(headlessBrand)\n const [policy, setPolicy] = useState(copy.policyDefaultChecked ?? false)\n const [email, setEmail] = useState(initialEmail ?? '')\n const [errorMessage, setErrorMessage] = useState('')\n const [successMessage, setSuccessMessage] = useState('')\n const [loading, setLoading] = useState(false)\n\n useEffect(() => {\n if (initialEmail) setEmail(initialEmail)\n }, [initialEmail])\n\n const handleSubmit = useCallback(async () => {\n setErrorMessage('')\n if (!email) return setErrorMessage('Please fill in your email')\n if (!emailValidate(email)) return setErrorMessage('Invalid email address')\n if (!policy) return setErrorMessage('Please agree to the policy')\n\n setLoading(true)\n const { register_source } = getAdCookie()\n try {\n const response = await fetch('/api/multipass/subscribe/subscribe_emails', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', 'current-language': locale },\n body: JSON.stringify({\n email,\n register_source,\n brand,\n deals_type: copy.dealsType ?? 'vip_subscribe',\n }),\n })\n const result = await response.json()\n if (!result.errors) {\n setSuccessMessage(copy.successTips ?? 'Subscribed successfully!')\n setIsSubscribeSuccess(true)\n if (profile?.user_id) setTimeout(() => fetchCreditInfo(profile.user_id), 3000)\n gaTrack({\n event: 'ga4Event',\n event_name: 'subscribe',\n event_parameters: {\n page_group: copy.dealsType ?? '',\n position: 'sticky',\n info: '',\n },\n })\n setTimeout(() => {\n setSuccessMessage('')\n onClose()\n }, 3000)\n } else {\n setErrorMessage(result.errors ?? 'Error occurred')\n }\n } catch {\n setErrorMessage('Network error')\n } finally {\n setLoading(false)\n }\n }, [email, policy, locale, brand, copy, onClose, setIsSubscribeSuccess])\n\n return (\n <div className=\"flex flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && (\n <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>\n )}\n {copy.desc && (\n <Text className=\"text-[16px] text-[#1e2024]\" html={copy.desc} />\n )}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n <input\n className={cn(\n 'h-[46px] w-full border px-[14px] text-[16px] outline-none placeholder:text-[#999]',\n errorMessage ? 'border-[#f84d4f]' : 'border-[#d8d8d8]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n placeholder={copy.placeholder}\n value={email}\n onChange={e => { setErrorMessage(''); setEmail(e.target.value.trim()) }}\n />\n\n <div className=\"flex w-full items-start gap-[8px]\">\n <Checkbox checked={policy} onCheckedChange={() => setPolicy(v => !v)} className=\"mt-[2px] border-[#1d1d1f]\" />\n <label\n className=\"cursor-pointer text-left text-[14px] text-[#1e2024] [&_a]:underline\"\n onClick={() => setPolicy(v => !v)}\n dangerouslySetInnerHTML={{ __html: copy.policy ?? '' }}\n />\n </div>\n\n {(errorMessage || successMessage) && (\n <div className={cn('text-[14px] font-[700]', errorMessage && 'text-[#f84d4f]', successMessage && 'text-[#52c41a]')}>\n <Text html={successMessage || errorMessage} />\n </div>\n )}\n\n <button\n className={cn('w-full cursor-pointer bg-[#080a0f] py-[14px] text-[14px] font-[700] text-white disabled:opacity-60', rounded ? 'rounded-[4px]' : 'rounded-none')}\n disabled={loading}\n onClick={handleSubmit}\n >\n {copy.buttonLabel ?? 'Subscribe'}\n </button>\n </div>\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": "AA4FM,OAEI,OAAAA,EAFJ,QAAAC,MAAA,oBA5FN,OAAS,eAAAC,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QACjD,OAAS,YAAAC,EAAU,QAAAC,MAAY,wBAC/B,OAAS,WAAAC,EAAS,cAAcC,EAAI,sBAAAC,MAA0B,gBAC9D,OAAOC,MAAa,YACpB,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,cAC9B,EACA,YAAaV,EAAK,YAClB,MAAOa,EACP,SAAUW,GAAK,CAAER,EAAgB,EAAE,EAAGF,EAASU,EAAE,OAAO,MAAM,KAAK,CAAC,CAAE,EACxE,EAEA3C,EAAC,OAAI,UAAU,oCACb,UAAAD,EAACK,EAAA,CAAS,QAAS0B,EAAQ,gBAAiB,IAAMC,EAAUa,GAAK,CAACA,CAAC,EAAG,UAAU,4BAA4B,EAC5G7C,EAAC,SACC,UAAU,sEACV,QAAS,IAAMgC,EAAUa,GAAK,CAACA,CAAC,EAChC,wBAAyB,CAAE,OAAQzB,EAAK,QAAU,EAAG,EACvD,GACF,GAEEe,GAAgBE,IAChBrC,EAAC,OAAI,UAAWQ,EAAG,yBAA0B2B,GAAgB,iBAAkBE,GAAkB,gBAAgB,EAC/G,SAAArC,EAACM,EAAA,CAAK,KAAM+B,GAAkBF,EAAc,EAC9C,EAGFnC,EAAC,UACC,UAAWQ,EAAG,qGAAsGsB,EAAU,gBAAkB,cAAc,EAC9J,SAAUS,EACV,QAASE,EAER,SAAArB,EAAK,aAAe,YACvB,GACF,GACF,CAEJ",
|
|
6
6
|
"names": ["jsx", "jsxs", "useCallback", "useEffect", "useState", "Checkbox", "Text", "gaTrack", "cn", "useHeadlessContext", "Cookies", "parse", "emailValidate", "useMemberPopupContext", "ROUNDED_BRANDS", "getAdCookie", "search", "href", "query", "SubscribeEmailPanel", "copy", "initialEmail", "onClose", "alpcConfig", "setIsSubscribeSuccess", "fetchCreditInfo", "profile", "brand", "locale", "headlessBrand", "rounded", "policy", "setPolicy", "email", "setEmail", "errorMessage", "setErrorMessage", "successMessage", "setSuccessMessage", "loading", "setLoading", "handleSubmit", "register_source", "result", "e", "v"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as i,jsxs as n}from"react/jsx-runtime";import{useEffect as w,useMemo as u}from"react";import{gaTrack as A,classNames as c,useHeadlessContext as B}from"@anker-in/lib";import{useMemberPopupContext as I}from"../../context/provider";import{useViewStack as U}from"../../context/viewStack";import{useSubscribed as M}from"./hooks/useSubscribed";import{EarnCreditsTaskType as s,MemberPopupPanelType as m}from"../../type";import{IconBag as y,IconLock as R,IconSubscription as D,IconOrders as F}from"../../icons";import{numberFormat as T}from"../../../credits/context/utils";import{ROUNDED_BRANDS as O}from"../../../../constants";function V({id:a,className:e}){switch(a){case s.Activate:return i(R,{className:e});case s.Subscribe:return i(D,{className:e});case s.Shop:return i(y,{className:e});case s.CompleteProfile:return i(F,{className:e})}}function z({copy:a}){const{profile:e,openSignUpPopup:l,alpcConfig:b,creditInfo:v,fetchCreditInfo:_,isSubscribeSuccess:g,isActivateSuccess:C,isProfileCompleteSuccess:f}=I(),{pushView:p}=U(),{locale:E}=b,{brand:N}=B(),x=O.includes(N);w(()=>{e?.user_id&&_(e.user_id)},[]);const o=!!e,h=M({userId:e?.user_id,brand:N,email:e?.email,locale:E,apiBaseUrl:b.apiBaseUrl}),k=u(()=>f||!!(e?.first_name||e?.last_name)&&!!e?.phone_number&&!!e?.dob,[e,f]);function d(t){const r={[s.Activate]:"activate",[s.CompleteProfile]:"complete_profile",[s.Subscribe]:"subscribe",[s.Shop]:"shop"};A({event:"ga4Event",event_name:"lp_button",event_parameters:{position:"earn_credits",button_name:r[t],info:"Member Floating Window"}})}const S=u(()=>({[s.Activate]:{finished:!!e?.activated||C,onClick:o?()=>{d(s.Activate),p({type:m.Activate})}:l},[s.CompleteProfile]:{finished:k,onClick:o?()=>{d(s.CompleteProfile),p({type:m.CompleteProfile})}:l},[s.Subscribe]:{finished:h||g,onClick:o?()=>{d(s.Subscribe),p({type:m.SubscribeEmail})}:l},[s.Shop]:{finished:!1,link:a.goShopLink,onClick:o?()=>d(s.Shop):l}}),[e,o,C,f,k,h,g,l,p,a.goShopLink]),P=u(()=>a.list.map(t=>{const r=S[t.id];if(!r)return null;const L=r.finished?a.completed:o?H(t.id,a):a.joinNow;return{...t,...r,buttonLabel:L}}).filter(Boolean),[a,S,o]);return n("div",{className:"flex flex-col gap-[16px]",children:[n("div",{className:"flex flex-col gap-[16px]",children:[i("div",{className:"flex flex-col gap-[8px]",children:a.title&&i("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:a.title})}),o&&n("div",{className:c("flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]",x?"rounded-[8px]":"rounded-none"),children:[n("div",{className:"flex flex-1 flex-col gap-[4px]",children:[i("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:a.balanceLabel??"AnkerCredits Balance"}),n("div",{className:"flex items-end gap-[4px]",children:[i("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:T(v?.available_credit??0)}),i("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??"ankercredits"})]})]}),i("div",{className:"h-full w-px bg-[#dadce0]"}),n("div",{className:"flex flex-1 flex-col gap-[4px]",children:[i("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:a.comingSoonLabel??"Coming Soon"}),n("div",{className:"flex items-end gap-[4px]",children:[i("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:T(v?.pending_credit??0)}),i("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??"ankercredits"})]})]})]})]}),n("div",{className:"flex flex-col gap-[16px]",children:[a.subtitle&&i("p",{className:"text-[16px] font-[700] text-[#1e2024]",children:a.subtitle}),i("div",{className:"flex flex-col",children:P.map((t,r)=>n("div",{className:"relative py-[16px]",children:[r>0&&i("div",{className:"absolute left-0 right-0 top-0 h-px bg-[#dadce0]"}),n("div",{className:c("flex items-center gap-[12px]"),children:[i(V,{id:t.id,className:"size-[24px] shrink-0"}),n("div",{className:"flex-1",children:[i("div",{className:"text-[16px] font-[700] text-[#1e2024]",children:t.title}),t.credits&&i("div",{className:"mt-[4px] text-[14px] font-bold text-[#4A4C56]",children:t.credits})]}),!t.finished&&t.link&&o?i("a",{href:t.link,target:"_blank",rel:"noopener noreferrer",className:c("cursor-pointer bg-[#080a0f] min-w-[118px] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white",x?"rounded-[4px]":"rounded-none"),onClick:()=>d(t.id),children:t.buttonLabel}):i("button",{className:c("cursor-pointer min-w-[118px] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white",t.finished?"bg-[#767880]":"bg-[#080a0f]",x?"rounded-[4px]":"rounded-none",t.finished&&"opacity-60"),disabled:t.finished,onClick:t.finished?void 0:t.onClick,children:t.buttonLabel})]})]},r))})]})]})}function H(a,e){switch(a){case s.Activate:return e.activate;case s.CompleteProfile:return e.completeProfileLabel;case s.Subscribe:return e.subscribeLabel;case s.Shop:return e.shopNow}}var Z=z;export{Z as default};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/EarnCredits/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useMemo } from 'react'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useSubscribed } from './hooks/useSubscribed'\nimport { EarnCreditsTaskType, MemberPopupPanelType, type EarnCreditsCopy } from '../../type'\nimport { IconBag, IconLock, IconSubscription, IconOrders } from '../../icons'\nimport { numberFormat } from '../../../credits/context/utils'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\nfunction TaskIcon({ id, className }: { id: EarnCreditsTaskType; className?: string }) {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return <IconLock className={className} />\n case EarnCreditsTaskType.Subscribe:\n return <IconSubscription className={className} />\n case EarnCreditsTaskType.Shop:\n return <IconBag className={className} />\n case EarnCreditsTaskType.CompleteProfile:\n return <IconOrders className={className} />\n }\n}\n\ntype Props = {\n copy: EarnCreditsCopy\n}\n\nfunction EarnCredits({ copy }: Props) {\n const {\n profile,\n openSignUpPopup,\n alpcConfig,\n creditInfo,\n isSubscribeSuccess,\n isActivateSuccess,\n isProfileCompleteSuccess,\n } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { locale } = alpcConfig\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const isLogin = !!profile\n\n const isSubscribed = useSubscribed({\n userId: profile?.user_id,\n brand: brand,\n email: profile?.email,\n locale,\n apiBaseUrl: alpcConfig.apiBaseUrl,\n })\n\n const profileCompleted = useMemo(() => {\n return (\n isProfileCompleteSuccess ||\n (!!(profile?.first_name || profile?.last_name) && !!profile?.phone_number && !!profile?.dob)\n )\n }, [profile, isProfileCompleteSuccess])\n\n function trackTaskButton(taskId: EarnCreditsTaskType) {\n const taskButtonNameMap: Record<EarnCreditsTaskType, string> = {\n [EarnCreditsTaskType.Activate]: 'activate',\n [EarnCreditsTaskType.CompleteProfile]: 'complete_profile',\n [EarnCreditsTaskType.Subscribe]: 'subscribe',\n [EarnCreditsTaskType.Shop]: 'shop',\n }\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'earn_credits',\n button_name: taskButtonNameMap[taskId],\n info: 'Member Floating Window',\n },\n })\n }\n\n const taskStates: Record<EarnCreditsTaskType, { finished: boolean; onClick?: () => void; link?: string }> = useMemo(\n () => ({\n [EarnCreditsTaskType.Activate]: {\n finished: !!profile?.activated || isActivateSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Activate)\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.CompleteProfile]: {\n finished: profileCompleted,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.CompleteProfile)\n pushView({\n type: MemberPopupPanelType.CompleteProfile,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Subscribe]: {\n finished: isSubscribed || isSubscribeSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Subscribe)\n pushView({\n type: MemberPopupPanelType.SubscribeEmail,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Shop]: {\n finished: false,\n link: copy.goShopLink,\n onClick: isLogin ? () => trackTaskButton(EarnCreditsTaskType.Shop) : openSignUpPopup,\n },\n }),\n [\n profile,\n isLogin,\n isActivateSuccess,\n isProfileCompleteSuccess,\n profileCompleted,\n isSubscribed,\n isSubscribeSuccess,\n openSignUpPopup,\n pushView,\n copy.goShopLink,\n ]\n )\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const state = taskStates[item.id]\n if (!state) return null\n const buttonLabel = state.finished\n ? copy.completed\n : isLogin\n ? getNotFinishedLabel(item.id, copy)\n : copy.joinNow\n return { ...item, ...state, buttonLabel }\n })\n .filter(Boolean) as ((typeof copy.list)[number] & {\n finished: boolean\n onClick?: () => void\n link?: string\n buttonLabel: string\n })[]\n }, [copy, taskStates, isLogin])\n\n return (\n <div className=\"flex flex-col gap-[16px]\">\n <div className=\"flex flex-col gap-[16px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit ?? 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit ?? 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {copy.subtitle && <p className=\"text-[16px] font-[700] text-[#1e2024]\">{copy.subtitle}</p>}\n\n <div className=\"flex flex-col\">\n {list.map((item, idx) => (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute left-0 right-0 top-0 h-px bg-[#dadce0]\" />}\n <div className={cn('flex items-center gap-[12px]')}>\n <TaskIcon id={item.id} className=\"size-[24px] shrink-0\" />\n <div className=\"flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024]\">{item.title}</div>\n {item.credits && (\n <div className=\"mt-[4px] text-[14px] font-bold text-[#4A4C56]\">{item.credits}</div>\n )}\n </div>\n {!item.finished && item.link && isLogin ? (\n <a\n href={item.link}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className={cn(\n 'cursor-pointer bg-[#080a0f] min-w-[118px] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n onClick={() => trackTaskButton(item.id)}\n >\n {item.buttonLabel}\n </a>\n ) : (\n <button\n className={cn(\n 'cursor-pointer min-w-[118px] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n item.finished ? 'bg-[#767880]' : 'bg-[#080a0f]',\n rounded ? 'rounded-[4px]' : 'rounded-none',\n item.finished && 'opacity-60'\n )}\n disabled={item.finished}\n onClick={!item.finished ? item.onClick : undefined}\n >\n {item.buttonLabel}\n </button>\n )}\n </div>\n </div>\n ))}\n </div>\n </div>\n </div>\n )\n}\n\nfunction getNotFinishedLabel(id: EarnCreditsTaskType, copy: EarnCreditsCopy): string {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return copy.activate\n case EarnCreditsTaskType.CompleteProfile:\n return copy.completeProfileLabel\n case EarnCreditsTaskType.Subscribe:\n return copy.subscribeLabel\n case EarnCreditsTaskType.Shop:\n return copy.shopNow\n }\n}\n\nexport default EarnCredits\n"],
|
|
5
|
-
"mappings": "AAaa,cAAAA,
|
|
6
|
-
"names": ["jsx", "jsxs", "useMemo", "gaTrack", "cn", "useHeadlessContext", "useMemberPopupContext", "useViewStack", "useSubscribed", "EarnCreditsTaskType", "MemberPopupPanelType", "IconBag", "IconLock", "IconSubscription", "IconOrders", "numberFormat", "ROUNDED_BRANDS", "TaskIcon", "id", "className", "EarnCredits", "copy", "profile", "openSignUpPopup", "alpcConfig", "creditInfo", "isSubscribeSuccess", "isActivateSuccess", "isProfileCompleteSuccess", "pushView", "locale", "brand", "rounded", "isLogin", "isSubscribed", "profileCompleted", "trackTaskButton", "taskId", "taskButtonNameMap", "taskStates", "list", "item", "state", "buttonLabel", "getNotFinishedLabel", "idx", "EarnCredits_default"]
|
|
4
|
+
"sourcesContent": ["import { useEffect, useMemo } from 'react'\nimport { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useSubscribed } from './hooks/useSubscribed'\nimport { EarnCreditsTaskType, MemberPopupPanelType, type EarnCreditsCopy } from '../../type'\nimport { IconBag, IconLock, IconSubscription, IconOrders } from '../../icons'\nimport { numberFormat } from '../../../credits/context/utils'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\nfunction TaskIcon({ id, className }: { id: EarnCreditsTaskType; className?: string }) {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return <IconLock className={className} />\n case EarnCreditsTaskType.Subscribe:\n return <IconSubscription className={className} />\n case EarnCreditsTaskType.Shop:\n return <IconBag className={className} />\n case EarnCreditsTaskType.CompleteProfile:\n return <IconOrders className={className} />\n }\n}\n\ntype Props = {\n copy: EarnCreditsCopy\n}\n\nfunction EarnCredits({ copy }: Props) {\n const {\n profile,\n openSignUpPopup,\n alpcConfig,\n creditInfo,\n fetchCreditInfo,\n isSubscribeSuccess,\n isActivateSuccess,\n isProfileCompleteSuccess,\n } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { locale } = alpcConfig\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n useEffect(() => {\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n }, [])\n\n const isLogin = !!profile\n\n const isSubscribed = useSubscribed({\n userId: profile?.user_id,\n brand: brand,\n email: profile?.email,\n locale,\n apiBaseUrl: alpcConfig.apiBaseUrl,\n })\n\n const profileCompleted = useMemo(() => {\n return (\n isProfileCompleteSuccess ||\n (!!(profile?.first_name || profile?.last_name) && !!profile?.phone_number && !!profile?.dob)\n )\n }, [profile, isProfileCompleteSuccess])\n\n function trackTaskButton(taskId: EarnCreditsTaskType) {\n const taskButtonNameMap: Record<EarnCreditsTaskType, string> = {\n [EarnCreditsTaskType.Activate]: 'activate',\n [EarnCreditsTaskType.CompleteProfile]: 'complete_profile',\n [EarnCreditsTaskType.Subscribe]: 'subscribe',\n [EarnCreditsTaskType.Shop]: 'shop',\n }\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'earn_credits',\n button_name: taskButtonNameMap[taskId],\n info: 'Member Floating Window',\n },\n })\n }\n\n const taskStates: Record<EarnCreditsTaskType, { finished: boolean; onClick?: () => void; link?: string }> = useMemo(\n () => ({\n [EarnCreditsTaskType.Activate]: {\n finished: !!profile?.activated || isActivateSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Activate)\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.CompleteProfile]: {\n finished: profileCompleted,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.CompleteProfile)\n pushView({\n type: MemberPopupPanelType.CompleteProfile,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Subscribe]: {\n finished: isSubscribed || isSubscribeSuccess,\n onClick: isLogin\n ? () => {\n trackTaskButton(EarnCreditsTaskType.Subscribe)\n pushView({\n type: MemberPopupPanelType.SubscribeEmail,\n })\n }\n : openSignUpPopup,\n },\n [EarnCreditsTaskType.Shop]: {\n finished: false,\n link: copy.goShopLink,\n onClick: isLogin ? () => trackTaskButton(EarnCreditsTaskType.Shop) : openSignUpPopup,\n },\n }),\n [\n profile,\n isLogin,\n isActivateSuccess,\n isProfileCompleteSuccess,\n profileCompleted,\n isSubscribed,\n isSubscribeSuccess,\n openSignUpPopup,\n pushView,\n copy.goShopLink,\n ]\n )\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const state = taskStates[item.id]\n if (!state) return null\n const buttonLabel = state.finished\n ? copy.completed\n : isLogin\n ? getNotFinishedLabel(item.id, copy)\n : copy.joinNow\n return { ...item, ...state, buttonLabel }\n })\n .filter(Boolean) as ((typeof copy.list)[number] & {\n finished: boolean\n onClick?: () => void\n link?: string\n buttonLabel: string\n })[]\n }, [copy, taskStates, isLogin])\n\n return (\n <div className=\"flex flex-col gap-[16px]\">\n <div className=\"flex flex-col gap-[16px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit ?? 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit ?? 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {copy.subtitle && <p className=\"text-[16px] font-[700] text-[#1e2024]\">{copy.subtitle}</p>}\n\n <div className=\"flex flex-col\">\n {list.map((item, idx) => (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute left-0 right-0 top-0 h-px bg-[#dadce0]\" />}\n <div className={cn('flex items-center gap-[12px]')}>\n <TaskIcon id={item.id} className=\"size-[24px] shrink-0\" />\n <div className=\"flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024]\">{item.title}</div>\n {item.credits && (\n <div className=\"mt-[4px] text-[14px] font-bold text-[#4A4C56]\">{item.credits}</div>\n )}\n </div>\n {!item.finished && item.link && isLogin ? (\n <a\n href={item.link}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className={cn(\n 'cursor-pointer bg-[#080a0f] min-w-[118px] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n onClick={() => trackTaskButton(item.id)}\n >\n {item.buttonLabel}\n </a>\n ) : (\n <button\n className={cn(\n 'cursor-pointer min-w-[118px] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n item.finished ? 'bg-[#767880]' : 'bg-[#080a0f]',\n rounded ? 'rounded-[4px]' : 'rounded-none',\n item.finished && 'opacity-60'\n )}\n disabled={item.finished}\n onClick={!item.finished ? item.onClick : undefined}\n >\n {item.buttonLabel}\n </button>\n )}\n </div>\n </div>\n ))}\n </div>\n </div>\n </div>\n )\n}\n\nfunction getNotFinishedLabel(id: EarnCreditsTaskType, copy: EarnCreditsCopy): string {\n switch (id) {\n case EarnCreditsTaskType.Activate:\n return copy.activate\n case EarnCreditsTaskType.CompleteProfile:\n return copy.completeProfileLabel\n case EarnCreditsTaskType.Subscribe:\n return copy.subscribeLabel\n case EarnCreditsTaskType.Shop:\n return copy.shopNow\n }\n}\n\nexport default EarnCredits\n"],
|
|
5
|
+
"mappings": "AAaa,cAAAA,EAgKC,QAAAC,MAhKD,oBAbb,OAAS,aAAAC,EAAW,WAAAC,MAAe,QACnC,OAAS,WAAAC,EAAS,cAAcC,EAAI,sBAAAC,MAA0B,gBAC9D,OAAS,yBAAAC,MAA6B,yBACtC,OAAS,gBAAAC,MAAoB,0BAC7B,OAAS,iBAAAC,MAAqB,wBAC9B,OAAS,uBAAAC,EAAqB,wBAAAC,MAAkD,aAChF,OAAS,WAAAC,EAAS,YAAAC,EAAU,oBAAAC,EAAkB,cAAAC,MAAkB,cAChE,OAAS,gBAAAC,MAAoB,iCAC7B,OAAS,kBAAAC,MAAsB,wBAE/B,SAASC,EAAS,CAAE,GAAAC,EAAI,UAAAC,CAAU,EAAoD,CACpF,OAAQD,EAAI,CACV,KAAKT,EAAoB,SACvB,OAAOV,EAACa,EAAA,CAAS,UAAWO,EAAW,EACzC,KAAKV,EAAoB,UACvB,OAAOV,EAACc,EAAA,CAAiB,UAAWM,EAAW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,EAAC,KACC,KAAM2C,EAAK,KACX,OAAO,SACP,IAAI,sBACJ,UAAWtC,EACT,0HACA6B,EAAU,gBAAkB,cAC9B,EACA,QAAS,IAAMI,EAAgBK,EAAK,EAAE,EAErC,SAAAA,EAAK,YACR,EAEA3C,EAAC,UACC,UAAWK,EACT,6GACAsC,EAAK,SAAW,eAAiB,eACjCT,EAAU,gBAAkB,eAC5BS,EAAK,UAAY,YACnB,EACA,SAAUA,EAAK,SACf,QAAUA,EAAK,SAA0B,OAAfA,EAAK,QAE9B,SAAAA,EAAK,YACR,GAEJ,IArCQI,CAsCV,CACD,EACH,GACF,GACF,CAEJ,CAEA,SAASD,EAAoB3B,EAAyBG,EAA+B,CACnF,OAAQH,EAAI,CACV,KAAKT,EAAoB,SACvB,OAAOY,EAAK,SACd,KAAKZ,EAAoB,gBACvB,OAAOY,EAAK,qBACd,KAAKZ,EAAoB,UACvB,OAAOY,EAAK,eACd,KAAKZ,EAAoB,KACvB,OAAOY,EAAK,OAChB,CACF,CAEA,IAAO0B,EAAQ3B",
|
|
6
|
+
"names": ["jsx", "jsxs", "useEffect", "useMemo", "gaTrack", "cn", "useHeadlessContext", "useMemberPopupContext", "useViewStack", "useSubscribed", "EarnCreditsTaskType", "MemberPopupPanelType", "IconBag", "IconLock", "IconSubscription", "IconOrders", "numberFormat", "ROUNDED_BRANDS", "TaskIcon", "id", "className", "EarnCredits", "copy", "profile", "openSignUpPopup", "alpcConfig", "creditInfo", "fetchCreditInfo", "isSubscribeSuccess", "isActivateSuccess", "isProfileCompleteSuccess", "pushView", "locale", "brand", "rounded", "isLogin", "isSubscribed", "profileCompleted", "trackTaskButton", "taskId", "taskButtonNameMap", "taskStates", "list", "item", "state", "buttonLabel", "getNotFinishedLabel", "idx", "EarnCredits_default"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -167,7 +167,7 @@ export default function ActivatePanel({ copy, onClose }: Props) {
|
|
|
167
167
|
setMessageStatus('success')
|
|
168
168
|
setMessageText(copy?.authSuccessMessage || '')
|
|
169
169
|
setIsActivateSuccess(true)
|
|
170
|
-
if (profile?.user_id) fetchCreditInfo(profile.user_id)
|
|
170
|
+
if (profile?.user_id) setTimeout(() => fetchCreditInfo(profile.user_id), 3000)
|
|
171
171
|
gaTrack({
|
|
172
172
|
event: 'ga4Event',
|
|
173
173
|
event_name: 'lp_button',
|
|
@@ -185,7 +185,7 @@ export default function ActivatePanel({ copy, onClose }: Props) {
|
|
|
185
185
|
const errorCode = data?.data?.error_code ?? data?.error_code
|
|
186
186
|
if (errorCode === '104') {
|
|
187
187
|
setIsActivateSuccess(true)
|
|
188
|
-
if (profile?.user_id) fetchCreditInfo(profile.user_id)
|
|
188
|
+
if (profile?.user_id) setTimeout(() => fetchCreditInfo(profile.user_id), 3000)
|
|
189
189
|
gaTrack({
|
|
190
190
|
event: 'ga4Event',
|
|
191
191
|
event_name: 'lp_button',
|
|
@@ -72,7 +72,7 @@ export default function CompleteProfilePanel({ copy, onClose }: Props) {
|
|
|
72
72
|
dob: birthDay,
|
|
73
73
|
})
|
|
74
74
|
if (success) {
|
|
75
|
-
fetchCreditInfo(profile?.user_id)
|
|
75
|
+
setTimeout(() => fetchCreditInfo(profile?.user_id), 3000)
|
|
76
76
|
setIsProfileCompleteSuccess(true)
|
|
77
77
|
gaTrack({
|
|
78
78
|
event: 'ga4Event',
|
|
@@ -64,7 +64,7 @@ export default function SubscribeEmailPanel({ copy, email: initialEmail, onClose
|
|
|
64
64
|
if (!result.errors) {
|
|
65
65
|
setSuccessMessage(copy.successTips ?? 'Subscribed successfully!')
|
|
66
66
|
setIsSubscribeSuccess(true)
|
|
67
|
-
if (profile?.user_id) fetchCreditInfo(profile.user_id)
|
|
67
|
+
if (profile?.user_id) setTimeout(() => fetchCreditInfo(profile.user_id), 3000)
|
|
68
68
|
gaTrack({
|
|
69
69
|
event: 'ga4Event',
|
|
70
70
|
event_name: 'subscribe',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo } from 'react'
|
|
1
|
+
import { useEffect, useMemo } from 'react'
|
|
2
2
|
import { gaTrack, classNames as cn, useHeadlessContext } from '@anker-in/lib'
|
|
3
3
|
import { useMemberPopupContext } from '../../context/provider'
|
|
4
4
|
import { useViewStack } from '../../context/viewStack'
|
|
@@ -31,6 +31,7 @@ function EarnCredits({ copy }: Props) {
|
|
|
31
31
|
openSignUpPopup,
|
|
32
32
|
alpcConfig,
|
|
33
33
|
creditInfo,
|
|
34
|
+
fetchCreditInfo,
|
|
34
35
|
isSubscribeSuccess,
|
|
35
36
|
isActivateSuccess,
|
|
36
37
|
isProfileCompleteSuccess,
|
|
@@ -40,6 +41,10 @@ function EarnCredits({ copy }: Props) {
|
|
|
40
41
|
const { brand } = useHeadlessContext()
|
|
41
42
|
const rounded = ROUNDED_BRANDS.includes(brand)
|
|
42
43
|
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (profile?.user_id) fetchCreditInfo(profile.user_id)
|
|
46
|
+
}, [])
|
|
47
|
+
|
|
43
48
|
const isLogin = !!profile
|
|
44
49
|
|
|
45
50
|
const isSubscribed = useSubscribed({
|