@anker-in/campaign-ui 0.5.0-beta.2 → 0.5.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/credits/context/hooks/useCountries.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useCountries.js.map +3 -3
- package/dist/cjs/components/memberPopup/MemberPopup.d.ts +1 -1
- package/dist/cjs/components/memberPopup/MemberPopup.js +1 -1
- package/dist/cjs/components/memberPopup/MemberPopup.js.map +3 -3
- package/dist/cjs/components/memberPopup/context/provider.d.ts +3 -3
- package/dist/cjs/components/memberPopup/context/provider.js +1 -1
- package/dist/cjs/components/memberPopup/context/provider.js.map +3 -3
- package/dist/cjs/components/memberPopup/panels/ActivitiesSubscribePanel.d.ts +7 -0
- package/dist/cjs/components/memberPopup/panels/ActivitiesSubscribePanel.js +2 -0
- package/dist/cjs/components/memberPopup/panels/ActivitiesSubscribePanel.js.map +7 -0
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/RedeemCouponPanel.d.ts +9 -7
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/RedeemCouponPanel.js +1 -1
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/RedeemCouponPanel.js.map +3 -3
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/index.d.ts +1 -2
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/index.js +1 -1
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/index.js.map +3 -3
- package/dist/cjs/components/memberPopup/panels/EarnCredits/ActivatePanel.d.ts +1 -2
- package/dist/cjs/components/memberPopup/panels/EarnCredits/ActivatePanel.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/ActivatePanel.js.map +3 -3
- package/dist/cjs/components/memberPopup/panels/EarnCredits/CompleteProfileModal.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/CompleteProfileModal.js.map +2 -2
- package/dist/cjs/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.d.ts +1 -3
- package/dist/cjs/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.js.map +3 -3
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.d.ts +1 -2
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.js.map +3 -3
- package/dist/cjs/components/memberPopup/panels/EarnCredits/index.d.ts +1 -8
- 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/cjs/components/memberPopup/panels/Referral/index.js +1 -1
- package/dist/cjs/components/memberPopup/panels/Referral/index.js.map +3 -3
- package/dist/cjs/components/memberPopup/type.d.ts +29 -3
- package/dist/cjs/components/memberPopup/type.js +1 -1
- package/dist/cjs/components/memberPopup/type.js.map +2 -2
- package/dist/cjs/templates/Credits.js +1 -1
- package/dist/cjs/templates/Credits.js.map +3 -3
- package/dist/esm/components/credits/context/hooks/useCountries.js +1 -1
- package/dist/esm/components/credits/context/hooks/useCountries.js.map +3 -3
- package/dist/esm/components/memberPopup/MemberPopup.d.ts +1 -1
- package/dist/esm/components/memberPopup/MemberPopup.js +1 -1
- package/dist/esm/components/memberPopup/MemberPopup.js.map +3 -3
- package/dist/esm/components/memberPopup/context/provider.d.ts +3 -3
- package/dist/esm/components/memberPopup/context/provider.js +1 -1
- package/dist/esm/components/memberPopup/context/provider.js.map +3 -3
- package/dist/esm/components/memberPopup/panels/ActivitiesSubscribePanel.d.ts +7 -0
- package/dist/esm/components/memberPopup/panels/ActivitiesSubscribePanel.js +2 -0
- package/dist/esm/components/memberPopup/panels/ActivitiesSubscribePanel.js.map +7 -0
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/RedeemCouponPanel.d.ts +9 -7
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/RedeemCouponPanel.js +1 -1
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/RedeemCouponPanel.js.map +3 -3
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/index.d.ts +1 -2
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/index.js +1 -1
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/index.js.map +3 -3
- package/dist/esm/components/memberPopup/panels/EarnCredits/ActivatePanel.d.ts +1 -2
- package/dist/esm/components/memberPopup/panels/EarnCredits/ActivatePanel.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/ActivatePanel.js.map +3 -3
- package/dist/esm/components/memberPopup/panels/EarnCredits/CompleteProfileModal.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/CompleteProfileModal.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.d.ts +1 -3
- package/dist/esm/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.js.map +3 -3
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.d.ts +1 -2
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.js.map +3 -3
- package/dist/esm/components/memberPopup/panels/EarnCredits/index.d.ts +1 -8
- package/dist/esm/components/memberPopup/panels/EarnCredits/index.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/index.js.map +3 -3
- package/dist/esm/components/memberPopup/panels/Referral/index.js +1 -1
- package/dist/esm/components/memberPopup/panels/Referral/index.js.map +3 -3
- package/dist/esm/components/memberPopup/type.d.ts +29 -3
- package/dist/esm/components/memberPopup/type.js +1 -1
- package/dist/esm/components/memberPopup/type.js.map +2 -2
- package/dist/esm/templates/Credits.js +1 -1
- package/dist/esm/templates/Credits.js.map +3 -3
- package/package.json +1 -1
- package/src/components/credits/context/hooks/useCountries.ts +4 -15
- package/src/components/memberPopup/MemberPopup.tsx +170 -177
- package/src/components/memberPopup/context/provider.tsx +24 -4
- package/src/components/memberPopup/panels/ActivitiesSubscribePanel.tsx +194 -0
- package/src/components/memberPopup/panels/ConsumeCredits/RedeemCouponPanel.tsx +93 -60
- package/src/components/memberPopup/panels/ConsumeCredits/index.tsx +200 -87
- package/src/components/memberPopup/panels/EarnCredits/ActivatePanel.tsx +30 -15
- package/src/components/memberPopup/panels/EarnCredits/CompleteProfileModal.tsx +6 -1
- package/src/components/memberPopup/panels/EarnCredits/CompleteProfilePanel.tsx +65 -35
- package/src/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.tsx +15 -6
- package/src/components/memberPopup/panels/EarnCredits/index.tsx +131 -86
- package/src/components/memberPopup/panels/Referral/index.tsx +35 -16
- package/src/components/memberPopup/type.ts +26 -3
- package/src/templates/Credits.tsx +25 -0
- package/dist/cjs/components/memberPopup/panels/Activity/SubscribeModal.d.ts +0 -10
- package/dist/cjs/components/memberPopup/panels/Activity/SubscribeModal.js +0 -2
- package/dist/cjs/components/memberPopup/panels/Activity/SubscribeModal.js.map +0 -7
- package/dist/cjs/components/memberPopup/panels/Activity/hooks/useActivitySubscribe.d.ts +0 -7
- package/dist/cjs/components/memberPopup/panels/Activity/hooks/useActivitySubscribe.js +0 -2
- package/dist/cjs/components/memberPopup/panels/Activity/hooks/useActivitySubscribe.js.map +0 -7
- package/dist/cjs/components/memberPopup/panels/Activity/index.d.ts +0 -7
- package/dist/cjs/components/memberPopup/panels/Activity/index.js +0 -2
- package/dist/cjs/components/memberPopup/panels/Activity/index.js.map +0 -7
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/RedeemCouponModal.d.ts +0 -19
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/RedeemCouponModal.js +0 -2
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/RedeemCouponModal.js.map +0 -7
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribeModal.d.ts +0 -10
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribeModal.js +0 -2
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribeModal.js.map +0 -7
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribePanel.d.ts +0 -9
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribePanel.js +0 -2
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribePanel.js.map +0 -7
- package/dist/cjs/components/memberPopup/panels/Referral/hooks/useReferralDashboard.d.ts +0 -13
- package/dist/cjs/components/memberPopup/panels/Referral/hooks/useReferralDashboard.js +0 -2
- package/dist/cjs/components/memberPopup/panels/Referral/hooks/useReferralDashboard.js.map +0 -7
- package/dist/esm/components/memberPopup/panels/Activity/SubscribeModal.d.ts +0 -10
- package/dist/esm/components/memberPopup/panels/Activity/SubscribeModal.js +0 -2
- package/dist/esm/components/memberPopup/panels/Activity/SubscribeModal.js.map +0 -7
- package/dist/esm/components/memberPopup/panels/Activity/hooks/useActivitySubscribe.d.ts +0 -7
- package/dist/esm/components/memberPopup/panels/Activity/hooks/useActivitySubscribe.js +0 -2
- package/dist/esm/components/memberPopup/panels/Activity/hooks/useActivitySubscribe.js.map +0 -7
- package/dist/esm/components/memberPopup/panels/Activity/index.d.ts +0 -7
- package/dist/esm/components/memberPopup/panels/Activity/index.js +0 -2
- package/dist/esm/components/memberPopup/panels/Activity/index.js.map +0 -7
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/RedeemCouponModal.d.ts +0 -19
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/RedeemCouponModal.js +0 -2
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/RedeemCouponModal.js.map +0 -7
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribeModal.d.ts +0 -10
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribeModal.js +0 -2
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribeModal.js.map +0 -7
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribePanel.d.ts +0 -9
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribePanel.js +0 -2
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribePanel.js.map +0 -7
- package/dist/esm/components/memberPopup/panels/Referral/hooks/useReferralDashboard.d.ts +0 -13
- package/dist/esm/components/memberPopup/panels/Referral/hooks/useReferralDashboard.js +0 -2
- package/dist/esm/components/memberPopup/panels/Referral/hooks/useReferralDashboard.js.map +0 -7
- package/dist/index.d.mts +0 -1775
- package/dist/index.d.ts +0 -1775
- package/dist/index.js +0 -18542
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -18514
- package/dist/index.mjs.map +0 -1
- package/src/components/memberPopup/panels/ConsumeCredits/RedeemCouponModal.tsx +0 -150
- package/src/components/memberPopup/panels/EarnCredits/SubscribeModal.tsx +0 -144
- package/src/components/memberPopup/panels/EarnCredits/SubscribePanel.tsx +0 -147
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/ConsumeCredits/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { classNames as cn, useProductsByHandles, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useRedeemableList } from './hooks/useRedeemableList'\nimport { useRedeemAndBuy } from './hooks/useRedeemAndBuy'\nimport {\n ConsumeCreditsItemType,\n MemberPopupPanelType,\n type ConsumeCreditsopy,\n type ConsumeCreditsItem,\n} from '../../type'\nimport { numberFormat } from '../../../credits/context/utils'\nimport type { ConsumeCreditRuleResponse } from '../../../credits/context/response'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype EnrichedItem = ConsumeCreditsItem & {\n alpcData: ConsumeCreditRuleResponse\n insufficient: boolean\n soldOut: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n onClose: () => void\n}\n\nfunction ConsumeCredits({ copy, onClose }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [redeemAndBuyError, setRedeemAndBuyError] = useState('')\n const [loadingId, setLoadingId] = useState<string | number | null>(null)\n\n const isLogin = !!profile\n const { redeemableList, listLoading } = useRedeemableList(alpcConfig)\n const { trigger: redeemAndBuy } = useRedeemAndBuy(alpcConfig)\n\n const handles = copy.list.map(item => item.product?.handle).filter(Boolean) as string[]\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const alpcData = redeemableList.find(r => String(r.id) === String(item.redeemId))\n if (!alpcData) return null\n\n const availableCredit = Number(creditInfo?.available_credit ?? 0)\n const insufficient = isLogin && !!profile?.activated && alpcData.consume_credits > availableCredit\n const soldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n let product\n let variant\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && item.product) {\n product = products?.find((p: any) => p.handle === item.product!.handle)\n variant = product?.variants?.find((v: any) => v.sku === item.product!.sku) ?? product?.variants?.[0]\n if (!product || !variant) return null\n }\n\n return { ...item, alpcData, insufficient, soldOut, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin) return copy.unlockRewards\n if (item.soldOut) return copy.soldOut\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n return item.soldOut || item.insufficient\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n pushView({\n type: MemberPopupPanelType.RedeemCoupon,\n props: {\n itemTitle: item.title,\n itemCredits: item.alpcData.consume_credits,\n itemImage: copy.imageMapping?.[item.type]\n ? { url: copy.imageMapping[item.type]!.url, alt: item.image?.alt }\n : item.image,\n itemValue: item.value,\n itemOff: copy.off,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n alpcConfig,\n },\n })\n } else {\n setRedeemAndBuyError('')\n setLoadingId(item.redeemId)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n } catch (e: any) {\n setRedeemAndBuyError(e?.message ?? copy.redeemModal.commonError)\n } finally {\n setLoadingId(null)\n }\n }\n }\n\n return (\n <>\n <div className=\"flex flex-1 flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n {copy.subtitle && <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>}\n </div>\n\n {copy.insufficientCredits && creditInfo && (\n <div className=\"text-[14px] font-[700] text-[#1d1d1f]\">\n {copy.insufficientCredits}: {numberFormat(creditInfo.available_credit)} {copy.pointUnit}\n </div>\n )}\n {redeemAndBuyError && <div className=\"text-[14px] font-[700] text-[#f84d4f]\">{redeemAndBuyError}</div>}\n\n {listLoading ? (\n <div className=\"flex flex-1 items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n ) : (\n <div className=\"flex flex-col\">\n {list.map((item, idx) => (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute inset-x-0 top-0 h-px bg-[#dadce0]\" />}\n <div className=\"flex items-center gap-[12px]\">\n {(() => {\n const isRedeemAndBuy = item.type === ConsumeCreditsItemType.RedeemAndBuy\n const mappedImgUrl = copy.imageMapping?.[item.type]?.url\n const imgUrl = isRedeemAndBuy\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : (mappedImgUrl ?? item.image?.url)\n const imgAlt = isRedeemAndBuy\n ? (item.variant?.image?.altText ?? item.product?.images?.[0]?.alt ?? item.image?.alt ?? '')\n : (item.image?.alt ?? '')\n if (!imgUrl) return null\n return (\n <div className={cn('relative size-[64px] shrink-0 overflow-hidden', rounded ? 'rounded-[4px]' : 'rounded-none')}>\n <Picture\n source={imgUrl}\n alt={imgAlt}\n className=\"flex size-full items-center justify-center\"\n imgClassName={isRedeemAndBuy ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {!isRedeemAndBuy && item.value && (\n <div className=\"absolute bottom-[20px] left-[4px] text-[14px] font-[800] leading-none text-white\">\n {item.value} {copy.off}\n </div>\n )}\n </div>\n )\n })()}\n <div className=\"min-w-0 flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024] line-clamp-2\">\n {item.type === ConsumeCreditsItemType.RedeemAndBuy && item.product?.title\n ? item.product.title\n : item.title}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {item.type === ConsumeCreditsItemType.RedeemAndBuy && item.price != null\n ? `${numberFormat(item.alpcData.consume_credits)} ${copy.pointUnit ?? ''} + $${Number(item.price).toFixed(2)}`\n : `${numberFormat(item.alpcData.consume_credits)} ${copy.pointUnit ?? ''}`}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n className={cn('bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white', rounded ? 'rounded-[4px]' : 'rounded-none')}\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && (\n <div className=\"pointer-events-none absolute left-[48px] top-full mt-[10px] hidden -translate-x-1/2 group-hover:block\">\n <div className=\"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow md:px-[10px] md:py-[8px]\">\n <p className=\"text-pretty tracking-[-0.02em] text-[14px]\">{copy.insufficientCredits}</p>\n <div className=\"absolute -top-[8px] left-[48px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]\" />\n </div>\n </div>\n )}\n </div>\n </div>\n </div>\n ))}\n </div>\n )}\n\n {copy.creditsPage?.url && (\n <a\n href={copy.creditsPage.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.creditsPage.label ?? 'Go to Credits Page'}\n </a>\n )}\n </div>\n </>\n )\n}\n\nexport default ConsumeCredits\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["Fragment", "jsx", "jsxs", "useMemo", "useState", "Picture", "Button", "cn", "useProductsByHandles", "useHeadlessContext", "useMemberPopupContext", "useViewStack", "useRedeemableList", "useRedeemAndBuy", "ConsumeCreditsItemType", "MemberPopupPanelType", "numberFormat", "ROUNDED_BRANDS", "ConsumeCredits", "copy", "
|
|
4
|
+
"sourcesContent": ["import { useEffect, useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { gaTrack, classNames as cn, useProductsByHandles, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useRedeemableList } from './hooks/useRedeemableList'\nimport { useRedeemAndBuy } from './hooks/useRedeemAndBuy'\nimport {\n ConsumeCreditsItemType,\n MemberPopupPanelType,\n type ConsumeCreditsopy,\n type ConsumeCreditsItem,\n} from '../../type'\nimport { numberFormat } from '../../../credits/context/utils'\nimport type { ConsumeCreditRuleResponse } from '../../../credits/context/response'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype EnrichedItem = ConsumeCreditsItem & {\n alpcData: ConsumeCreditRuleResponse\n insufficient: boolean\n soldOut: boolean\n disabled: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n}\n\nfunction ConsumeCredits({ copy }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig, isActivateSuccess, fetchCreditInfo, pageHandle } =\n useMemberPopupContext()\n const { pushView } = useViewStack()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [redeemAndBuyError, setRedeemAndBuyError] = useState('')\n const [loadingId, setLoadingId] = useState<string | number | null>(null)\n\n useEffect(() => {\n if (profile?.user_id) fetchCreditInfo(profile.user_id)\n }, [])\n\n const isLogin = !!profile\n const { redeemableList, listLoading } = useRedeemableList(alpcConfig)\n const { trigger: redeemAndBuy } = useRedeemAndBuy(alpcConfig)\n\n const handles = copy.list.map(item => item.product?.handle).filter(Boolean) as string[]\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const alpcData = redeemableList.find(r => String(r.id) === String(item.redeemId))\n if (!alpcData) return null\n\n const availableCredit = Number(creditInfo?.available_credit ?? 0)\n const insufficient = alpcData.consume_credits > availableCredit\n const alpcSoldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n const isPhysicalProduct =\n item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product\n const product = products?.find((p: any) => p.handle === item.product?.handle)\n const variant = product?.variants?.find((v: any) => v.sku === item.product?.sku) ?? product?.variants?.[0]\n if (isPhysicalProduct && (!product || !variant || !variant?.availableForSale || alpcSoldOut)) {\n return null\n }\n return { ...item, alpcData, insufficient, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n const isActivate = profile?.activated || isActivateSuccess\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin || !isActivate) {\n return copy.unlockRewards\n }\n if (item.soldOut) {\n return copy.soldOut\n }\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (!isLogin || !isActivate) {\n return false\n }\n return item.insufficient\n }\n\n function trackRedeemButton(itemTitle: string) {\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'redeem',\n info: 'Member Floating Window',\n },\n })\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!isActivate) {\n pushView({\n type: MemberPopupPanelType.Activate,\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n const sectionId = copy.creditsPage.redeemListSectionId ?? 'creditsRedeemList'\n const targetUrl = new URL(copy.creditsPage.url, window.location.href)\n targetUrl.searchParams.set('section', sectionId)\n targetUrl.hash = sectionId\n if (pageHandle) {\n targetUrl.searchParams.set('ref', `${pageHandle}_consume_credits`)\n }\n trackRedeemButton(item.title)\n window.open(targetUrl.toString(), '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n trackRedeemButton(item.title)\n pushView({\n type: MemberPopupPanelType.RedeemCoupon,\n props: {\n itemTitle: item.title,\n itemCredits: item.alpcData.consume_credits,\n itemImage: copy.imageMapping?.[item.type]\n ? { url: copy.imageMapping[item.type]!.url, alt: item.image?.alt }\n : item.image,\n itemValue: item.value,\n itemRules: item.rules,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n alpcConfig,\n },\n })\n } else {\n setRedeemAndBuyError('')\n setLoadingId(item.redeemId)\n trackRedeemButton(item.title)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'redeem_success',\n info: 'Member Floating Window',\n },\n })\n } catch (e: any) {\n setRedeemAndBuyError(e?.message ?? copy.redeemModal.commonError)\n } finally {\n setLoadingId(null)\n }\n }\n }\n\n return (\n <>\n <div className=\"flex flex-1 flex-col\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n {copy.subtitle && (\n <p className=\"text-[16px] mt-[8px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center mt-[16px] gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n {redeemAndBuyError && <div className=\"text-[14px] mt-[8px] font-[700] text-[#f84d4f]\">{redeemAndBuyError}</div>}\n\n {listLoading ? (\n <div className=\"flex flex-1 items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n ) : (\n <div className=\"flex mt-[16px] flex-col\">\n {list.map((item, idx) => {\n const hasProduct = !!item.product\n return (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute inset-x-0 top-0 h-px bg-[#dadce0]\" />}\n <div className=\"flex items-center gap-[12px]\">\n {(() => {\n const mappedImgUrl = copy.imageMapping?.[item.type]?.url\n const imgUrl = hasProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : (mappedImgUrl ?? item.image?.url)\n const imgAlt = hasProduct\n ? (item.variant?.image?.altText ?? item.product?.images?.[0]?.alt ?? item.image?.alt ?? '')\n : (item.image?.alt ?? '')\n if (!imgUrl) return null\n return (\n <div\n className={cn(\n 'relative size-[64px] shrink-0 overflow-hidden',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n >\n <Picture\n source={imgUrl}\n alt={imgAlt}\n className=\"flex size-full items-center justify-center\"\n imgClassName={hasProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {!hasProduct && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value} {copy.off}\n </div>\n )}\n </div>\n )\n })()}\n <div className=\"min-w-0 flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024] line-clamp-2\">\n {hasProduct && item.product?.title ? item.product.title : item.title}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {hasProduct && item.price != null\n ? `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''} + $${Number(item.price).toFixed(2)}`\n : `${numberFormat(item.alpcData.consume_credits)} ${copy.creditUnit ?? ''}`}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n className={cn(\n 'bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && isLogin && isActivate && (\n <div className=\"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block\">\n <div className=\"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow\">\n <p className=\"text-pretty tracking-[-0.02em] text-[14px]\">{copy.insufficientCredits}</p>\n <div className=\"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]\" />\n </div>\n </div>\n )}\n </div>\n </div>\n </div>\n )\n })}\n </div>\n )}\n\n {copy.creditsPage?.url && (\n <a\n href={(() => {\n if (!pageHandle) return copy.creditsPage!.url\n try {\n const url = new URL(copy.creditsPage!.url, window.location.href)\n url.searchParams.set('ref', `${pageHandle}_consume_credits`)\n return url.toString()\n } catch {\n return copy.creditsPage!.url\n }\n })()}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={() =>\n gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n position: 'consume_credits',\n button_name: 'credits_page_link',\n info: 'Member Floating Window',\n },\n })\n }\n >\n {copy.creditsPage.label ?? 'Go to Credits Page'}\n </a>\n )}\n </div>\n </>\n )\n}\n\nexport default ConsumeCredits\n"],
|
|
5
|
+
"mappings": "AA8KI,mBAAAA,GAGqB,OAAAC,EADjB,QAAAC,MAFJ,oBA9KJ,OAAS,aAAAC,EAAW,WAAAC,EAAS,YAAAC,MAAgB,QAC7C,OAAS,WAAAC,EAAS,UAAAC,MAAc,wBAChC,OAAS,WAAAC,EAAS,cAAcC,EAAI,wBAAAC,EAAsB,sBAAAC,MAA0B,gBACpF,OAAS,yBAAAC,MAA6B,yBACtC,OAAS,gBAAAC,MAAoB,0BAC7B,OAAS,qBAAAC,MAAyB,4BAClC,OAAS,mBAAAC,MAAuB,0BAChC,OACE,0BAAAC,EACA,wBAAAC,MAGK,aACP,OAAS,gBAAAC,MAAoB,iCAE7B,OAAS,kBAAAC,OAAs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,KACC,MAAO,IAAM,CACX,GAAI,CAAC2B,EAAY,OAAOP,EAAK,YAAa,IAC1C,GAAI,CACF,MAAM+C,EAAM,IAAI,IAAI/C,EAAK,YAAa,IAAK,OAAO,SAAS,IAAI,EAC/D,OAAA+C,EAAI,aAAa,IAAI,MAAO,GAAGxC,CAAU,kBAAkB,EACpDwC,EAAI,SAAS,CACtB,MAAQ,CACN,OAAO/C,EAAK,YAAa,GAC3B,CACF,GAAG,EACH,OAAO,SACP,IAAI,sBACJ,UAAU,qEACV,QAAS,IACPb,EAAQ,CACN,MAAO,WACP,WAAY,YACZ,iBAAkB,CAChB,SAAU,kBACV,YAAa,oBACb,KAAM,wBACR,CACF,CAAC,EAGF,SAAAa,EAAK,YAAY,OAAS,qBAC7B,GAEJ,EACF,CAEJ,CAEA,IAAOgD,GAAQjD",
|
|
6
|
+
"names": ["Fragment", "jsx", "jsxs", "useEffect", "useMemo", "useState", "Picture", "Button", "gaTrack", "cn", "useProductsByHandles", "useHeadlessContext", "useMemberPopupContext", "useViewStack", "useRedeemableList", "useRedeemAndBuy", "ConsumeCreditsItemType", "MemberPopupPanelType", "numberFormat", "ROUNDED_BRANDS", "ConsumeCredits", "copy", "profile", "creditInfo", "openSignUpPopup", "alpcConfig", "isActivateSuccess", "fetchCreditInfo", "pageHandle", "pushView", "brand", "rounded", "redeemAndBuyError", "setRedeemAndBuyError", "loadingId", "setLoadingId", "isLogin", "redeemableList", "listLoading", "redeemAndBuy", "handles", "item", "products", "list", "alpcData", "r", "availableCredit", "insufficient", "alpcSoldOut", "isPhysicalProduct", "product", "p", "variant", "v", "isActivate", "getButtonLabel", "isDisabled", "trackRedeemButton", "itemTitle", "handleRedeem", "sectionId", "targetUrl", "e", "idx", "hasProduct", "mappedImgUrl", "imgUrl", "imgAlt", "url", "ConsumeCredits_default"]
|
|
7
7
|
}
|
|
@@ -2,7 +2,6 @@ import type { AuthCodeActivateCopy } from '../../type';
|
|
|
2
2
|
type Props = {
|
|
3
3
|
copy: AuthCodeActivateCopy;
|
|
4
4
|
onClose: () => void;
|
|
5
|
-
onSuccess?: () => void;
|
|
6
5
|
};
|
|
7
|
-
export default function ActivatePanel({ copy, onClose
|
|
6
|
+
export default function ActivatePanel({ copy, onClose }: Props): import("react/jsx-runtime").JSX.Element;
|
|
8
7
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as n,jsxs as
|
|
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};
|
|
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 { ROUNDED_BRANDS } from '../../../../constants'\n\ntype Props = {\n copy: AuthCodeActivateCopy\n onClose: () => void\n onSuccess?: () => void\n}\n\nexport default function ActivatePanel({ copy, onClose, onSuccess }: Props) {\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 onSuccess?.()\n setTimeout(() => {\n onClose()\n }, 3000)\n } else {\n const errorCode = data?.data?.error_code ?? data?.error_code\n if (errorCode === '104') {\n onSuccess?.()\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 gaTrack({\n event: 'ga4Event',\n event_name: 'lp_button',\n event_parameters: {\n page_group: 'reg_sub_pop',\n position: 'auth_code',\n button_name: 'check_and_active',\n },\n })\n }, [\n code,\n copy?.codeEmptyError,\n copy?.authSuccessMessage,\n copy?.incorrectCodeError,\n copy?.expiredCodeMessage,\n copy?.sendEmailErrorMessage,\n locale,\n sendEmailData,\n triggerEmailValidation,\n onClose,\n onSuccess,\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": "
|
|
6
|
-
"names": ["jsx", "jsxs", "useState", "useCallback", "useRef", "useEffect", "Button", "Text", "useSendEmailValidation", "gaTrack", "cn", "useHeadlessContext", "useEmailValidation", "useCountDown", "Message", "useRegistration", "ROUNDED_BRANDS", "ActivatePanel", "copy", "onClose", "
|
|
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,aAAAC,MAAiB,QACzD,OAAS,UAAAC,EAAQ,QAAAC,MAAY,wBAC7B,OACE,0BAAAC,EACA,WAAAC,EACA,cAAcC,EACd,sBAAAC,EACA,sBAAAC,EACA,gBAAAC,MACK,gBACP,OAAS,WAAAC,MAAe,iDAExB,OAAS,mBAAAC,MAAuB,wBAChC,OAAS,yBAAAC,OAA6B,yBACtC,OAAS,kBAAAC,OAAsB,wBAOhB,SAARC,GAA+B,C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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
|
+
"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 e,jsxs as
|
|
1
|
+
import{jsx as e,jsxs as s}from"react/jsx-runtime";import{useCallback as M,useEffect as q,useState as o}from"react";import{Button as D,Text as v}from"@anker-in/headless-ui";import{classNames as L}from"@anker-in/lib";import{CreditsModalContainer as A}from"../../../credits/modal/ModalContainer";import{useUpdateProfile as I}from"./hooks/useUpdateProfile";import T from"../../../credits/context/hooks/useCountries";import{useMemberPopupContext as U}from"../../context/provider";function W({isOpen:S,onClose:i,onSuccess:h,copy:a,shopifyStoreDomain:z=""}){const{profile:l,fetchCreditInfo:C,alpcConfig:g}=U(),{locale:F}=g,[r,k]=o(""),[d,P]=o(""),[p,w]=o(""),[x,y]=o(""),[n,f]=o(""),[u,b]=o(""),[c,N]=o(""),{updateProfile:_,isLoading:E}=I({locale:F,appName:g.appName}),{countries:m}=T({shopifyStoreDomain:z});q(()=>{l&&(k(l.first_name??""),P(l.last_name??""),w(l.phone_number??""),y(l.dob??""),f(l.country?.id??""))},[l]),q(()=>{m.length>0&&!n&&f(m[0].id)},[m]);const B=M(()=>{let t=!1;return r.trim()?b(""):(b(a.required),t=!0),d.trim()?N(""):(N(a.required),t=!0),t},[r,d,a.required]),O=M(async()=>{if(B())return;await _({first_name:r.trim(),last_name:d.trim(),phone_number:p,country:n,dob:x})&&(C(l?.user_id),h?.(),i())},[B,_,r,d,p,n,x,C,l,h,i]);return e(A,{isOpen:S,onClose:i,title:a.title,titleClassName:"!h-auto !border-b-0 !pb-0",className:"w-[540px] md:h-auto",useAnimation:!0,animationClassName:"md:translate-y-[100vh]",children:s("div",{className:"flex flex-col gap-[20px]",children:[a.subtitle&&e(v,{className:"text-[14px] text-[#1d1d1f]",html:a.subtitle}),s("div",{children:[e("label",{className:"block text-[14px] font-semibold text-[#1d1d1f]",children:a.email}),e("input",{className:"mt-[8px] h-[46px] w-full rounded-[4px] border border-[#d8d8d8] bg-[#f5f5f5] px-[12px] text-[14px] text-[#999]",value:l?.email??"",disabled:!0})]}),s("div",{children:[s("label",{className:"block text-[14px] font-semibold text-[#1d1d1f]",children:[a.firstName," ",e("span",{className:"text-[#f84d4f]",children:"*"})]}),e("input",{className:L("mt-[8px] h-[46px] w-full rounded-[4px] border px-[12px] text-[14px] outline-none",u?"border-[#f84d4f]":"border-[#d8d8d8]"),value:r,onChange:t=>{k(t.target.value),b("")}}),u&&e(v,{className:"mt-[4px] text-[12px] text-[#f84d4f]",html:u})]}),s("div",{children:[s("label",{className:"block text-[14px] font-semibold text-[#1d1d1f]",children:[a.lastName," ",e("span",{className:"text-[#f84d4f]",children:"*"})]}),e("input",{className:L("mt-[8px] h-[46px] w-full rounded-[4px] border px-[12px] text-[14px] outline-none",c?"border-[#f84d4f]":"border-[#d8d8d8]"),value:d,onChange:t=>{P(t.target.value),N("")}}),c&&e(v,{className:"mt-[4px] text-[12px] text-[#f84d4f]",html:c})]}),s("div",{children:[e("label",{className:"block text-[14px] font-semibold text-[#1d1d1f]",children:a.birthday}),e("input",{className:"mt-[8px] h-[46px] w-full rounded-[4px] border border-[#d8d8d8] px-[12px] text-[14px] outline-none",type:"date",value:x,onChange:t=>y(t.target.value)})]}),s("div",{children:[e("label",{className:"block text-[14px] font-semibold text-[#1d1d1f]",children:a.phone}),e("input",{className:"mt-[8px] h-[46px] w-full rounded-[4px] border border-[#d8d8d8] px-[12px] text-[14px] outline-none",value:p,onChange:t=>w(t.target.value)})]}),s("div",{children:[e("label",{className:"block text-[14px] font-semibold text-[#1d1d1f]",children:a.country}),e("select",{className:"mt-[8px] h-[46px] w-full rounded-[4px] border border-[#d8d8d8] px-[12px] text-[14px] outline-none",value:n,onChange:t=>f(t.target.value),children:m.map(t=>e("option",{value:t.id,children:t.name},t.id))})]}),s("div",{className:"flex gap-[12px]",children:[e(D,{variant:"secondary",size:"lg",className:"flex-1",onClick:i,disabled:E,children:a.cancel}),e(D,{variant:"primary",size:"lg",className:"flex-1",loading:E,onClick:O,children:a.save})]})]})})}export{W as CompleteProfileModal};
|
|
2
2
|
//# sourceMappingURL=CompleteProfileModal.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/memberPopup/panels/EarnCredits/CompleteProfileModal.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport { Button, Text } from '@anker-in/headless-ui'\nimport { classNames as cn } from '@anker-in/lib'\nimport { CreditsModalContainer } from '../../../credits/modal/ModalContainer'\nimport type { CompleteProfileCopy } from '../../type'\nimport { useUpdateProfile } from './hooks/useUpdateProfile'\nimport useCountries from '../../../credits/context/hooks/useCountries'\nimport { useMemberPopupContext } from '../../context/provider'\n\ntype Props = {\n isOpen: boolean\n onClose: () => void\n onSuccess?: () => void\n copy: CompleteProfileCopy\n shopifyStoreDomain?: string\n}\n\nexport function CompleteProfileModal({ isOpen, onClose, onSuccess, copy, shopifyStoreDomain = '' }: Props) {\n const { profile, fetchCreditInfo, alpcConfig } = useMemberPopupContext()\n const { locale } = alpcConfig\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 })\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 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 onSuccess?.()\n onClose()\n }\n }, [validate, updateProfile, firstName, lastName, phone, country, birthDay, fetchCreditInfo, profile, onSuccess, onClose])\n\n return (\n <CreditsModalContainer\n isOpen={isOpen}\n onClose={onClose}\n title={copy.title}\n titleClassName=\"!h-auto !border-b-0 !pb-0\"\n className=\"w-[540px] md:h-auto\"\n useAnimation\n animationClassName=\"md:translate-y-[100vh]\"\n >\n <div className=\"flex flex-col gap-[20px]\">\n {copy.subtitle && (\n <Text className=\"text-[14px] text-[#1d1d1f]\" html={copy.subtitle} />\n )}\n\n <div>\n <label className=\"block text-[14px] font-semibold text-[#1d1d1f]\">{copy.email}</label>\n <input\n className=\"mt-[8px] h-[46px] w-full rounded-[4px] border border-[#d8d8d8] bg-[#f5f5f5] px-[12px] text-[14px] text-[#999]\"\n value={profile?.email ?? ''}\n disabled\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-semibold text-[#1d1d1f]\">\n {copy.firstName} <span className=\"text-[#f84d4f]\">*</span>\n </label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full rounded-[4px] border px-[12px] text-[14px] outline-none',\n firstNameError ? 'border-[#f84d4f]' : 'border-[#d8d8d8]'\n )}\n value={firstName}\n onChange={e => { setFirstName(e.target.value); setFirstNameError('') }}\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-semibold text-[#1d1d1f]\">\n {copy.lastName} <span className=\"text-[#f84d4f]\">*</span>\n </label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full rounded-[4px] border px-[12px] text-[14px] outline-none',\n lastNameError ? 'border-[#f84d4f]' : 'border-[#d8d8d8]'\n )}\n value={lastName}\n onChange={e => { setLastName(e.target.value); setLastNameError('') }}\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-semibold text-[#1d1d1f]\">{copy.birthday}</label>\n <input\n className=\"mt-[8px] h-[46px] w-full rounded-[4px] border border-[#d8d8d8] px-[12px] text-[14px] outline-none\"\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-semibold text-[#1d1d1f]\">{copy.phone}</label>\n <input\n className=\"mt-[8px] h-[46px] w-full rounded-[4px] border border-[#d8d8d8] px-[12px] text-[14px] outline-none\"\n value={phone}\n onChange={e => setPhone(e.target.value)}\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-semibold text-[#1d1d1f]\">{copy.country}</label>\n <select\n className=\"mt-[8px] h-[46px] w-full rounded-[4px] border border-[#d8d8d8] px-[12px] text-[14px] outline-none\"\n value={country}\n onChange={e => setCountry(e.target.value)}\n >\n
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport { Button, Text } from '@anker-in/headless-ui'\nimport { classNames as cn } from '@anker-in/lib'\nimport { CreditsModalContainer } from '../../../credits/modal/ModalContainer'\nimport type { CompleteProfileCopy } from '../../type'\nimport { useUpdateProfile } from './hooks/useUpdateProfile'\nimport useCountries from '../../../credits/context/hooks/useCountries'\nimport { useMemberPopupContext } from '../../context/provider'\n\ntype Props = {\n isOpen: boolean\n onClose: () => void\n onSuccess?: () => void\n copy: CompleteProfileCopy\n shopifyStoreDomain?: string\n}\n\nexport function CompleteProfileModal({ isOpen, onClose, onSuccess, copy, shopifyStoreDomain = '' }: Props) {\n const { profile, fetchCreditInfo, alpcConfig } = useMemberPopupContext()\n const { locale } = alpcConfig\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 })\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 onSuccess?.()\n onClose()\n }\n }, [validate, updateProfile, firstName, lastName, phone, country, birthDay, fetchCreditInfo, profile, onSuccess, onClose])\n\n return (\n <CreditsModalContainer\n isOpen={isOpen}\n onClose={onClose}\n title={copy.title}\n titleClassName=\"!h-auto !border-b-0 !pb-0\"\n className=\"w-[540px] md:h-auto\"\n useAnimation\n animationClassName=\"md:translate-y-[100vh]\"\n >\n <div className=\"flex flex-col gap-[20px]\">\n {copy.subtitle && (\n <Text className=\"text-[14px] text-[#1d1d1f]\" html={copy.subtitle} />\n )}\n\n <div>\n <label className=\"block text-[14px] font-semibold text-[#1d1d1f]\">{copy.email}</label>\n <input\n className=\"mt-[8px] h-[46px] w-full rounded-[4px] border border-[#d8d8d8] bg-[#f5f5f5] px-[12px] text-[14px] text-[#999]\"\n value={profile?.email ?? ''}\n disabled\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-semibold text-[#1d1d1f]\">\n {copy.firstName} <span className=\"text-[#f84d4f]\">*</span>\n </label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full rounded-[4px] border px-[12px] text-[14px] outline-none',\n firstNameError ? 'border-[#f84d4f]' : 'border-[#d8d8d8]'\n )}\n value={firstName}\n onChange={e => { setFirstName(e.target.value); setFirstNameError('') }}\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-semibold text-[#1d1d1f]\">\n {copy.lastName} <span className=\"text-[#f84d4f]\">*</span>\n </label>\n <input\n className={cn(\n 'mt-[8px] h-[46px] w-full rounded-[4px] border px-[12px] text-[14px] outline-none',\n lastNameError ? 'border-[#f84d4f]' : 'border-[#d8d8d8]'\n )}\n value={lastName}\n onChange={e => { setLastName(e.target.value); setLastNameError('') }}\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-semibold text-[#1d1d1f]\">{copy.birthday}</label>\n <input\n className=\"mt-[8px] h-[46px] w-full rounded-[4px] border border-[#d8d8d8] px-[12px] text-[14px] outline-none\"\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-semibold text-[#1d1d1f]\">{copy.phone}</label>\n <input\n className=\"mt-[8px] h-[46px] w-full rounded-[4px] border border-[#d8d8d8] px-[12px] text-[14px] outline-none\"\n value={phone}\n onChange={e => setPhone(e.target.value)}\n />\n </div>\n\n <div>\n <label className=\"block text-[14px] font-semibold text-[#1d1d1f]\">{copy.country}</label>\n <select\n className=\"mt-[8px] h-[46px] w-full rounded-[4px] border border-[#d8d8d8] px-[12px] text-[14px] outline-none\"\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}>{c.name}</option>\n ))}\n </select>\n </div>\n\n <div className=\"flex gap-[12px]\">\n <Button\n variant=\"secondary\"\n size=\"lg\"\n className=\"flex-1\"\n onClick={onClose}\n disabled={isLoading}\n >\n {copy.cancel}\n </Button>\n <Button\n variant=\"primary\"\n size=\"lg\"\n className=\"flex-1\"\n loading={isLoading}\n onClick={handleSubmit}\n >\n {copy.save}\n </Button>\n </div>\n </div>\n </CreditsModalContainer>\n )\n}\n"],
|
|
5
|
+
"mappings": "AA6FU,cAAAA,EAGF,QAAAC,MAHE,oBA7FV,OAAS,eAAAC,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QACjD,OAAS,UAAAC,EAAQ,QAAAC,MAAY,wBAC7B,OAAS,cAAcC,MAAU,gBACjC,OAAS,yBAAAC,MAA6B,wCAEtC,OAAS,oBAAAC,MAAwB,2BACjC,OAAOC,MAAkB,8CACzB,OAAS,yBAAAC,MAA6B,yBAU/B,SAASC,EAAqB,CAAE,OAAAC,EAAQ,QAAAC,EAAS,UAAAC,EAAW,KAAAC,EAAM,mBAAAC,EAAqB,EAAG,EAAU,CACzG,KAAM,CAAE,QAAAC,EAAS,gBAAAC,EAAiB,WAAAC,CAAW,EAAIT,EAAsB,EACjE,CAAE,OAAAU,CAAO,EAAID,EAEb,CAACE,EAAWC,CAAY,EAAInB,EAAS,EAAE,EACvC,CAACoB,EAAUC,CAAW,EAAIrB,EAAS,EAAE,EACrC,CAACsB,EAAOC,CAAQ,EAAIvB,EAAS,EAAE,EAC/B,CAACwB,EAAUC,CAAW,EAAIzB,EAAS,EAAE,EACrC,CAAC0B,EAASC,CAAU,EAAI3B,EAAS,EAAE,EACnC,CAAC4B,EAAgBC,CAAiB,EAAI7B,EAAS,EAAE,EACjD,CAAC8B,EAAeC,CAAgB,EAAI/B,EAAS,EAAE,EAE/C,CAAE,cAAAgC,EAAe,UAAAC,CAAU,EAAI5B,EAAiB,CAAE,O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Kf,EAASe,EAAE,OAAO,KAAK,EACxC,GACF,EAEAzC,EAAC,OACC,UAAAD,EAAC,SAAM,UAAU,iDAAkD,SAAAgB,EAAK,QAAQ,EAChFhB,EAAC,UACC,UAAU,oGACV,MAAO8B,EACP,SAAUY,GAAKX,EAAWW,EAAE,OAAO,KAAK,EAEvC,SAAAJ,EAAU,IAAKK,GACd3C,EAAC,UAAkB,MAAO2C,EAAE,GAAK,SAAAA,EAAE,MAAtBA,EAAE,EAAyB,CACzC,EACH,GACF,EAEA1C,EAAC,OAAI,UAAU,kBACb,UAAAD,EAACK,EAAA,CACC,QAAQ,YACR,KAAK,KACL,UAAU,SACV,QAASS,EACT,SAAUuB,EAET,SAAArB,EAAK,OACR,EACAhB,EAACK,EAAA,CACC,QAAQ,UACR,KAAK,KACL,UAAU,SACV,QAASgC,EACT,QAASI,EAER,SAAAzB,EAAK,KACR,GACF,GACF,EACF,CAEJ",
|
|
6
6
|
"names": ["jsx", "jsxs", "useCallback", "useEffect", "useState", "Button", "Text", "cn", "CreditsModalContainer", "useUpdateProfile", "useCountries", "useMemberPopupContext", "CompleteProfileModal", "isOpen", "onClose", "onSuccess", "copy", "shopifyStoreDomain", "profile", "fetchCreditInfo", "alpcConfig", "locale", "firstName", "setFirstName", "lastName", "setLastName", "phone", "setPhone", "birthDay", "setBirthDay", "country", "setCountry", "firstNameError", "setFirstNameError", "lastNameError", "setLastNameError", "updateProfile", "isLoading", "countries", "validate", "hasError", "handleSubmit", "e", "c"]
|
|
7
7
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { CompleteProfileCopy } from '../../type';
|
|
2
2
|
type Props = {
|
|
3
3
|
copy: CompleteProfileCopy;
|
|
4
|
-
shopifyStoreDomain?: string;
|
|
5
4
|
onClose: () => void;
|
|
6
|
-
onSuccess?: () => void;
|
|
7
5
|
};
|
|
8
|
-
export default function CompleteProfilePanel({ copy,
|
|
6
|
+
export default function CompleteProfilePanel({ copy, onClose }: Props): import("react/jsx-runtime").JSX.Element;
|
|
9
7
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as t,jsxs 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 T,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:z}=_,{brand:I,storeDomain:M}=U(),l=W.includes(I),[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:z,appName:_.appName}),{countries:m}=H({shopifyStoreDomain:M});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]),R=q(async()=>{if(S())return;await D({first_name:d.trim(),last_name:i.trim(),phone_number:u,country:p,dob:f})&&(C(o?.user_id),k(!0),T({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:R,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 { 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
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["jsx", "jsxs", "useCallback", "useEffect", "useState", "Button", "Text", "cn", "useHeadlessContext", "useUpdateProfile", "useCountries", "useMemberPopupContext", "ROUNDED_BRANDS", "CompleteProfilePanel", "copy", "
|
|
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,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AE,CACrB,EACF,EACCD,GAAiBrC,EAACM,EAAA,CAAK,UAAU,sCAAsC,KAAM+B,EAAe,GAC/F,EAEApC,EAAC,OACC,UAAAD,EAAC,SAAM,UAAU,8CAA+C,SAAAe,EAAK,SAAS,EAC9Ef,EAAC,SACC,UAAWQ,EACT,sFACAgB,EAAU,gBAAkB,cAC9B,EACA,KAAK,OACL,MAAOO,EACP,SAAU,GAAKC,EAAY,EAAE,OAAO,KAAK,EAC3C,GACF,EAEA/B,EAAC,OACC,UAAAD,EAAC,SAAM,UAAU,8CAA+C,SAAAe,EAAK,MAAM,EAC3Ef,EAAC,SACC,UAAWQ,EACT,sFACAgB,EAAU,gBAAkB,cAC9B,EACA,MAAOK,EACP,SAAU,GAAKC,EAAS,EAAE,OAAO,KAAK,EACxC,GACF,EAEA7B,EAAC,OACC,UAAAD,EAAC,SAAM,UAAU,8CAA+C,SAAAe,EAAK,QAAQ,EAC7Ef,EAAC,UACC,UAAWQ,EACT,sFACAgB,EAAU,gBAAkB,cAC9B,EACA,MAAOS,EACP,SAAU,GAAKC,EAAW,EAAE,OAAO,KAAK,EAEvC,SAAAO,EAAU,IAAKI,GACd7C,EAAC,UAAkB,MAAO6C,EAAE,GACzB,SAAAA,EAAE,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
|
+
"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
|
}
|
|
@@ -3,7 +3,6 @@ type Props = {
|
|
|
3
3
|
copy: SubscribeModalCopy;
|
|
4
4
|
email?: string;
|
|
5
5
|
onClose: () => void;
|
|
6
|
-
onSuccess?: () => void;
|
|
7
6
|
};
|
|
8
|
-
export default function SubscribeEmailPanel({ copy, email: initialEmail, onClose
|
|
7
|
+
export default function SubscribeEmailPanel({ copy, email: initialEmail, onClose }: Props): import("react/jsx-runtime").JSX.Element;
|
|
9
8
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as t,jsxs as d}from"react/jsx-runtime";import{useCallback as
|
|
1
|
+
import{jsx as t,jsxs as d}from"react/jsx-runtime";import{useCallback as E,useEffect as I,useState as l}from"react";import{Checkbox as D,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(!1),[i,v]=l(o??""),[n,s]=l(""),[f,y]=l(""),[M,C]=l(!1);I(()=>{o&&v(o)},[o]);const P=E(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(D,{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 { 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
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["jsx", "jsxs", "useCallback", "useEffect", "useState", "Checkbox", "Text", "cn", "useHeadlessContext", "Cookies", "parse", "emailValidate", "useMemberPopupContext", "ROUNDED_BRANDS", "getAdCookie", "search", "href", "query", "SubscribeEmailPanel", "copy", "initialEmail", "onClose", "
|
|
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(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": "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,OAAS,SAAAC,MAAa,eACtB,OAAS,iBAAAC,MAAqB,iCAC9B,OA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AAO,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
|
+
"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
|
}
|