@anker-in/campaign-ui 0.5.5 → 0.5.7-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/credits/context/hooks/useActivities.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useActivities.js.map +3 -3
- package/dist/cjs/components/credits/context/hooks/useAlpcFetch.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useAlpcFetch.js.map +2 -2
- package/dist/cjs/components/credits/context/hooks/useCountries.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useCountries.js.map +2 -2
- package/dist/cjs/components/credits/context/hooks/useShippingCountries.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useShippingCountries.js.map +2 -2
- package/dist/cjs/components/credits/context/hooks/useSubscribed.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useSubscribed.js.map +3 -3
- package/dist/cjs/components/memberPopup/panels/ActivitiesSubscribePanel.js +1 -1
- package/dist/cjs/components/memberPopup/panels/ActivitiesSubscribePanel.js.map +2 -2
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/hooks/useRedeemCoupon.js +1 -1
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/hooks/useRedeemCoupon.js.map +2 -2
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/hooks/useRedeemableList.js +1 -1
- package/dist/cjs/components/memberPopup/panels/ConsumeCredits/hooks/useRedeemableList.js.map +2 -2
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.js.map +2 -2
- package/dist/cjs/components/memberPopup/panels/EarnCredits/hooks/useActivities.d.ts +2 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/hooks/useActivities.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/hooks/useActivities.js.map +3 -3
- package/dist/cjs/components/memberPopup/panels/EarnCredits/hooks/useSubscribed.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/hooks/useSubscribed.js.map +2 -2
- package/dist/cjs/components/memberPopup/panels/EarnCredits/hooks/useUpdateProfile.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/hooks/useUpdateProfile.js.map +2 -2
- package/dist/cjs/components/memberPopup/panels/Referral/hooks/useReferralOverview.js +1 -1
- package/dist/cjs/components/memberPopup/panels/Referral/hooks/useReferralOverview.js.map +2 -2
- package/dist/esm/components/credits/context/hooks/useActivities.js +1 -1
- package/dist/esm/components/credits/context/hooks/useActivities.js.map +3 -3
- package/dist/esm/components/credits/context/hooks/useAlpcFetch.js +1 -1
- package/dist/esm/components/credits/context/hooks/useAlpcFetch.js.map +2 -2
- package/dist/esm/components/credits/context/hooks/useCountries.js +1 -1
- package/dist/esm/components/credits/context/hooks/useCountries.js.map +2 -2
- package/dist/esm/components/credits/context/hooks/useShippingCountries.js +1 -1
- package/dist/esm/components/credits/context/hooks/useShippingCountries.js.map +2 -2
- package/dist/esm/components/credits/context/hooks/useSubscribed.js +1 -1
- package/dist/esm/components/credits/context/hooks/useSubscribed.js.map +3 -3
- package/dist/esm/components/memberPopup/panels/ActivitiesSubscribePanel.js +1 -1
- package/dist/esm/components/memberPopup/panels/ActivitiesSubscribePanel.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/hooks/useRedeemCoupon.js +1 -1
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/hooks/useRedeemCoupon.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/hooks/useRedeemableList.js +1 -1
- package/dist/esm/components/memberPopup/panels/ConsumeCredits/hooks/useRedeemableList.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/EarnCredits/hooks/useActivities.d.ts +2 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/hooks/useActivities.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/hooks/useActivities.js.map +3 -3
- package/dist/esm/components/memberPopup/panels/EarnCredits/hooks/useSubscribed.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/hooks/useSubscribed.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/EarnCredits/hooks/useUpdateProfile.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/hooks/useUpdateProfile.js.map +2 -2
- package/dist/esm/components/memberPopup/panels/Referral/hooks/useReferralOverview.js +1 -1
- package/dist/esm/components/memberPopup/panels/Referral/hooks/useReferralOverview.js.map +2 -2
- package/package.json +1 -1
- package/src/components/credits/context/hooks/useActivities.ts +4 -2
- package/src/components/credits/context/hooks/useAlpcFetch.ts +2 -2
- package/src/components/credits/context/hooks/useCountries.ts +1 -0
- package/src/components/credits/context/hooks/useShippingCountries.ts +1 -0
- package/src/components/credits/context/hooks/useSubscribed.ts +2 -2
- package/src/components/memberPopup/panels/ActivitiesSubscribePanel.tsx +1 -0
- package/src/components/memberPopup/panels/ConsumeCredits/hooks/useRedeemCoupon.ts +4 -3
- package/src/components/memberPopup/panels/ConsumeCredits/hooks/useRedeemableList.ts +4 -3
- package/src/components/memberPopup/panels/EarnCredits/SubscribeEmailPanel.tsx +1 -0
- package/src/components/memberPopup/panels/EarnCredits/hooks/useActivities.ts +8 -5
- package/src/components/memberPopup/panels/EarnCredits/hooks/useSubscribed.ts +1 -1
- package/src/components/memberPopup/panels/EarnCredits/hooks/useUpdateProfile.ts +1 -0
- package/src/components/memberPopup/panels/Referral/hooks/useReferralOverview.ts +1 -0
|
@@ -4,12 +4,13 @@ type UseActivitiesConfig = {
|
|
|
4
4
|
brand: string;
|
|
5
5
|
apiBaseUrl?: string;
|
|
6
6
|
locale?: string;
|
|
7
|
+
country?: string;
|
|
7
8
|
};
|
|
8
9
|
type Params = {
|
|
9
10
|
page: number;
|
|
10
11
|
pageSize: number;
|
|
11
12
|
};
|
|
12
|
-
declare function useActivities({ userId, brand, apiBaseUrl, locale }: UseActivitiesConfig, { page, pageSize }: Params): {
|
|
13
|
+
declare function useActivities({ userId, brand, apiBaseUrl, locale, country }: UseActivitiesConfig, { page, pageSize }: Params): {
|
|
13
14
|
activities: CreditLogResponse[];
|
|
14
15
|
isLoading: boolean;
|
|
15
16
|
total: number;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useCallback as
|
|
1
|
+
import{useCallback as P,useEffect as v,useState as c}from"react";import h from"swr/mutation";import{getAlpcPath as L}from"../../../../credits/context/utils";import{ALPC_COUNTRY_MAP as R}from"../../../../credits/context/const";function S({userId:e,brand:i,apiBaseUrl:d,locale:s="",country:y},{page:t,pageSize:a}){const[g,l]=c([]),[u,C]=c(0),[p,A]=c(0),{isMutating:n,trigger:f}=h("/v1/credit/log",async(r,{arg:o})=>(await fetch(L(s,d)+r,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","current-language":s},body:JSON.stringify(o)})).json()),m=P(async()=>{await f({page:t,page_size:a,user_id:e,brand:i,country:y||R.get(s)||s},{onSuccess(r){A(t),C(r?.data?.total??0),l(o=>o.concat(r?.data?.creditLogs??[]))}})},[t,a,e,i,f]);return v(()=>{!e||!i||n||t===p||m()},[m,e,i,t,p,n]),{activities:g,isLoading:n,total:u,canNext:u>g.length&&!n}}var N=S;export{N as default};
|
|
2
2
|
//# sourceMappingURL=useActivities.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/components/memberPopup/panels/EarnCredits/hooks/useActivities.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport useSWRMutation from 'swr/mutation'\nimport { getAlpcPath } from '../../../../credits/context/utils'\nimport type { CreditLogResponse } from '../../../../credits/context/response'\n\ntype UseActivitiesConfig = {\n userId: string | undefined\n brand: string\n apiBaseUrl?: string\n locale?: string\n}\n\ntype Params = {\n page: number\n pageSize: number\n}\n\nfunction useActivities(\n { userId, brand, apiBaseUrl, locale = '' }: UseActivitiesConfig,\n { page, pageSize }: Params\n) {\n const [activities, setActivities] = useState<CreditLogResponse[]>([])\n const [total, setTotal] = useState(0)\n const [currentPage, setCurrentPage] = useState(0)\n\n const { isMutating: isLoading, trigger } = useSWRMutation(\n `/v1/credit/log`,\n async (url: string, { arg }: { arg: Record<string, any> }) => {\n
|
|
5
|
-
"mappings": "AAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QACjD,OAAOC,MAAoB,eAC3B,OAAS,eAAAC,MAAmB,
|
|
6
|
-
"names": ["useCallback", "useEffect", "useState", "useSWRMutation", "getAlpcPath", "useActivities", "userId", "brand", "apiBaseUrl", "locale", "page", "pageSize", "activities", "setActivities", "total", "setTotal", "currentPage", "setCurrentPage", "isLoading", "trigger", "url", "arg", "fetchActivities", "data", "prev", "useActivities_default"]
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport useSWRMutation from 'swr/mutation'\nimport { getAlpcPath } from '../../../../credits/context/utils'\nimport type { CreditLogResponse } from '../../../../credits/context/response'\nimport { ALPC_COUNTRY_MAP } from '../../../../credits/context/const'\n\ntype UseActivitiesConfig = {\n userId: string | undefined\n brand: string\n apiBaseUrl?: string\n locale?: string\n country?: string\n}\n\ntype Params = {\n page: number\n pageSize: number\n}\n\nfunction useActivities(\n { userId, brand, apiBaseUrl, locale = '', country }: UseActivitiesConfig,\n { page, pageSize }: Params\n) {\n const [activities, setActivities] = useState<CreditLogResponse[]>([])\n const [total, setTotal] = useState(0)\n const [currentPage, setCurrentPage] = useState(0)\n\n const { isMutating: isLoading, trigger } = useSWRMutation(\n `/v1/credit/log`,\n async (url: string, { arg }: { arg: Record<string, any> }) => {\n const response = await fetch(getAlpcPath(locale, apiBaseUrl) + url, {\n method: 'POST',\n credentials: 'include',\n headers: { 'Content-Type': 'application/json', 'current-language': locale },\n body: JSON.stringify(arg),\n })\n return response.json()\n }\n )\n\n const fetchActivities = useCallback(async () => {\n await trigger(\n { page, page_size: pageSize, user_id: userId, brand, country: country || ALPC_COUNTRY_MAP.get(locale) || locale },\n {\n onSuccess(data) {\n setCurrentPage(page)\n setTotal(data?.data?.total ?? 0)\n setActivities(prev => prev.concat(data?.data?.creditLogs ?? []))\n },\n }\n )\n }, [page, pageSize, userId, brand, trigger])\n\n useEffect(() => {\n if (!userId || !brand || isLoading || page === currentPage) return\n fetchActivities()\n }, [fetchActivities, userId, brand, page, currentPage, isLoading])\n\n return {\n activities,\n isLoading,\n total,\n canNext: total > activities.length && !isLoading,\n }\n}\n\nexport default useActivities\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QACjD,OAAOC,MAAoB,eAC3B,OAAS,eAAAC,MAAmB,oCAE5B,OAAS,oBAAAC,MAAwB,oCAejC,SAASC,EACP,CAAE,OAAAC,EAAQ,MAAAC,EAAO,WAAAC,EAAY,OAAAC,EAAS,GAAI,QAAAC,CAAQ,EAClD,CAAE,KAAAC,EAAM,SAAAC,CAAS,EACjB,CACA,KAAM,CAACC,EAAYC,CAAa,EAAIb,EAA8B,CAAC,CAAC,EAC9D,CAACc,EAAOC,CAAQ,EAAIf,EAAS,CAAC,EAC9B,CAACgB,EAAaC,CAAc,EAAIjB,EAAS,CAAC,EAE1C,CAAE,WAAYkB,EAAW,QAAAC,CAAQ,EAAIlB,EACzC,iBACA,MAAOmB,EAAa,CAAE,IAAAC,CAAI,KACL,MAAM,MAAMnB,EAAYM,EAAQD,CAAU,EAAIa,EAAK,CAClE,OAAQ,OACR,YAAa,UACb,QAAS,CAAE,eAAgB,mBAAoB,mBAAoBZ,CAAO,EAC5E,KAAM,KAAK,UAAUa,CAAG,CAC1B,CAAC,GACe,KAAK,CAEzB,EAEMC,EAAkBxB,EAAY,SAAY,CAC9C,MAAMqB,EACJ,CAAE,KAAAT,EAAM,UAAWC,EAAU,QAASN,EAAQ,MAAAC,EAAO,QAASG,GAAWN,EAAiB,IAAIK,CAAM,GAAKA,CAAO,EAChH,CACE,UAAUe,EAAM,CACdN,EAAeP,CAAI,EACnBK,EAASQ,GAAM,MAAM,OAAS,CAAC,EAC/BV,EAAcW,GAAQA,EAAK,OAAOD,GAAM,MAAM,YAAc,CAAC,CAAC,CAAC,CACjE,CACF,CACF,CACF,EAAG,CAACb,EAAMC,EAAUN,EAAQC,EAAOa,CAAO,CAAC,EAE3C,OAAApB,EAAU,IAAM,CACV,CAACM,GAAU,CAACC,GAASY,GAAaR,IAASM,GAC/CM,EAAgB,CAClB,EAAG,CAACA,EAAiBjB,EAAQC,EAAOI,EAAMM,EAAaE,CAAS,CAAC,EAE1D,CACL,WAAAN,EACA,UAAAM,EACA,MAAAJ,EACA,QAASA,EAAQF,EAAW,QAAU,CAACM,CACzC,CACF,CAEA,IAAOO,EAAQrB",
|
|
6
|
+
"names": ["useCallback", "useEffect", "useState", "useSWRMutation", "getAlpcPath", "ALPC_COUNTRY_MAP", "useActivities", "userId", "brand", "apiBaseUrl", "locale", "country", "page", "pageSize", "activities", "setActivities", "total", "setTotal", "currentPage", "setCurrentPage", "isLoading", "trigger", "url", "arg", "fetchActivities", "data", "prev", "useActivities_default"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useMemo as b}from"react";import{useSubscriptions as
|
|
1
|
+
import{useMemo as b}from"react";import{useSubscriptions as f}from"@anker-in/lib";import{TaskSubType as p}from"../../../../credits/context/const";import a from"./useActivities";function l({userId:u,brand:r,email:o,locale:c="",apiBaseUrl:i}){const{activities:t}=a({userId:u,brand:r,apiBaseUrl:i,locale:c},{page:1,pageSize:50}),{data:n}=f({email:o,baseUrl:i}),s=n?.data||n;return b(()=>s?.preference?s.preference.some(e=>e.brand===r&&e.subscribe)?!0:t?.some(e=>e.task_sub_type===p.Subscription):!1,[s?.preference,t,r])}export{l as useSubscribed};
|
|
2
2
|
//# sourceMappingURL=useSubscribed.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/components/memberPopup/panels/EarnCredits/hooks/useSubscribed.ts"],
|
|
4
|
-
"sourcesContent": ["import { useMemo } from 'react'\nimport { useSubscriptions } from '@anker-in/lib'\nimport { TaskSubType } from '../../../../credits/context/const'\nimport useActivities from './useActivities'\n\ntype UseSubscribedConfig = {\n userId: string | undefined\n brand: string\n email: string | undefined\n locale?: string\n apiBaseUrl?: string\n}\n\nexport function useSubscribed({ userId, brand, email, locale = '', apiBaseUrl }: UseSubscribedConfig) {\n const { activities } = useActivities(\n { userId, brand, apiBaseUrl, locale },\n { page: 1, pageSize: 50 }\n )\n const { data: subscription } = useSubscriptions({ email })\n const subscriptionData = subscription?.data || subscription\n\n return useMemo(() => {\n if (!subscriptionData?.preference) {\n return false\n }\n const subscribedByPreference = subscriptionData.preference.some(\n (item: any) => item.brand === brand && item.subscribe\n )\n if (subscribedByPreference) return true\n return activities?.some(item => item.task_sub_type === TaskSubType.Subscription)\n }, [subscriptionData?.preference, activities, brand])\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,WAAAA,MAAe,QACxB,OAAS,oBAAAC,MAAwB,gBACjC,OAAS,eAAAC,MAAmB,oCAC5B,OAAOC,MAAmB,kBAUnB,SAASC,EAAc,CAAE,OAAAC,EAAQ,MAAAC,EAAO,MAAAC,EAAO,OAAAC,EAAS,GAAI,WAAAC,CAAW,EAAwB,CACpG,KAAM,CAAE,WAAAC,CAAW,EAAIP,EACrB,CAAE,OAAAE,EAAQ,MAAAC,EAAO,WAAAG,EAAY,OAAAD,CAAO,EACpC,CAAE,KAAM,EAAG,SAAU,EAAG,CAC1B,EACM,CAAE,KAAMG,CAAa,EAAIV,EAAiB,CAAE,MAAAM,
|
|
4
|
+
"sourcesContent": ["import { useMemo } from 'react'\nimport { useSubscriptions } from '@anker-in/lib'\nimport { TaskSubType } from '../../../../credits/context/const'\nimport useActivities from './useActivities'\n\ntype UseSubscribedConfig = {\n userId: string | undefined\n brand: string\n email: string | undefined\n locale?: string\n apiBaseUrl?: string\n}\n\nexport function useSubscribed({ userId, brand, email, locale = '', apiBaseUrl }: UseSubscribedConfig) {\n const { activities } = useActivities(\n { userId, brand, apiBaseUrl, locale },\n { page: 1, pageSize: 50 }\n )\n const { data: subscription } = useSubscriptions({ email, baseUrl: apiBaseUrl })\n const subscriptionData = subscription?.data || subscription\n\n return useMemo(() => {\n if (!subscriptionData?.preference) {\n return false\n }\n const subscribedByPreference = subscriptionData.preference.some(\n (item: any) => item.brand === brand && item.subscribe\n )\n if (subscribedByPreference) return true\n return activities?.some(item => item.task_sub_type === TaskSubType.Subscription)\n }, [subscriptionData?.preference, activities, brand])\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,WAAAA,MAAe,QACxB,OAAS,oBAAAC,MAAwB,gBACjC,OAAS,eAAAC,MAAmB,oCAC5B,OAAOC,MAAmB,kBAUnB,SAASC,EAAc,CAAE,OAAAC,EAAQ,MAAAC,EAAO,MAAAC,EAAO,OAAAC,EAAS,GAAI,WAAAC,CAAW,EAAwB,CACpG,KAAM,CAAE,WAAAC,CAAW,EAAIP,EACrB,CAAE,OAAAE,EAAQ,MAAAC,EAAO,WAAAG,EAAY,OAAAD,CAAO,EACpC,CAAE,KAAM,EAAG,SAAU,EAAG,CAC1B,EACM,CAAE,KAAMG,CAAa,EAAIV,EAAiB,CAAE,MAAAM,EAAO,QAASE,CAAW,CAAC,EACxEG,EAAmBD,GAAc,MAAQA,EAE/C,OAAOX,EAAQ,IACRY,GAAkB,WAGQA,EAAiB,WAAW,KACxDC,GAAcA,EAAK,QAAUP,GAASO,EAAK,SAC9C,EACmC,GAC5BH,GAAY,KAAKG,GAAQA,EAAK,gBAAkBX,EAAY,YAAY,EANtE,GAOR,CAACU,GAAkB,WAAYF,EAAYJ,CAAK,CAAC,CACtD",
|
|
6
6
|
"names": ["useMemo", "useSubscriptions", "TaskSubType", "useActivities", "useSubscribed", "userId", "brand", "email", "locale", "apiBaseUrl", "activities", "subscription", "subscriptionData", "item"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useCallback as f,useState as o}from"react";function
|
|
1
|
+
import{useCallback as f,useState as o}from"react";function g({locale:n="",appName:s=""}={}){const[i,a]=o(!1),[l,r]=o(null);return{updateProfile:f(async u=>{a(!0),r(null);try{const e=await fetch("/api/multipass/account/users/update_profile",{method:"PUT",credentials:"include",headers:{"Content-Type":"application/json","current-language":n},body:JSON.stringify({app:s,...u})}),t=await e.json();return e.ok&&!t.error?!0:(r(t?.error?.message||t?.error||"Update failed"),!1)}catch(e){return r(e?.message??"Unknown error"),!1}finally{a(!1)}},[n,s]),isLoading:i,error:l}}export{g as useUpdateProfile};
|
|
2
2
|
//# sourceMappingURL=useUpdateProfile.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/components/memberPopup/panels/EarnCredits/hooks/useUpdateProfile.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useState } from 'react'\n\ntype UseUpdateProfileConfig = {\n locale?: string\n appName?: string\n}\n\ntype ProfileData = {\n first_name?: string\n last_name?: string\n phone_number?: string\n country?: string\n dob?: string\n}\n\nexport function useUpdateProfile({ locale = '', appName = '' }: UseUpdateProfileConfig = {}) {\n const [isLoading, setIsLoading] = useState(false)\n const [error, setError] = useState<string | null>(null)\n\n const updateProfile = useCallback(\n async (data: ProfileData): Promise<boolean> => {\n setIsLoading(true)\n setError(null)\n try {\n const response = await fetch('/api/multipass/account/users/update_profile', {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n 'current-language': locale,\n },\n body: JSON.stringify({ app: appName, ...data }),\n })\n const result = await response.json()\n if (response.ok && !result.error) {\n return true\n }\n setError(result?.error?.message || result?.error || 'Update failed')\n return false\n } catch (e: any) {\n setError(e?.message ?? 'Unknown error')\n return false\n } finally {\n setIsLoading(false)\n }\n },\n [locale, appName]\n )\n\n return { updateProfile, isLoading, error }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,eAAAA,EAAa,YAAAC,MAAgB,QAe/B,SAASC,EAAiB,CAAE,OAAAC,EAAS,GAAI,QAAAC,EAAU,EAAG,EAA4B,CAAC,EAAG,CAC3F,KAAM,CAACC,EAAWC,CAAY,EAAIL,EAAS,EAAK,EAC1C,CAACM,EAAOC,CAAQ,EAAIP,EAAwB,IAAI,
|
|
4
|
+
"sourcesContent": ["import { useCallback, useState } from 'react'\n\ntype UseUpdateProfileConfig = {\n locale?: string\n appName?: string\n}\n\ntype ProfileData = {\n first_name?: string\n last_name?: string\n phone_number?: string\n country?: string\n dob?: string\n}\n\nexport function useUpdateProfile({ locale = '', appName = '' }: UseUpdateProfileConfig = {}) {\n const [isLoading, setIsLoading] = useState(false)\n const [error, setError] = useState<string | null>(null)\n\n const updateProfile = useCallback(\n async (data: ProfileData): Promise<boolean> => {\n setIsLoading(true)\n setError(null)\n try {\n const response = await fetch('/api/multipass/account/users/update_profile', {\n method: 'PUT',\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n 'current-language': locale,\n },\n body: JSON.stringify({ app: appName, ...data }),\n })\n const result = await response.json()\n if (response.ok && !result.error) {\n return true\n }\n setError(result?.error?.message || result?.error || 'Update failed')\n return false\n } catch (e: any) {\n setError(e?.message ?? 'Unknown error')\n return false\n } finally {\n setIsLoading(false)\n }\n },\n [locale, appName]\n )\n\n return { updateProfile, isLoading, error }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,eAAAA,EAAa,YAAAC,MAAgB,QAe/B,SAASC,EAAiB,CAAE,OAAAC,EAAS,GAAI,QAAAC,EAAU,EAAG,EAA4B,CAAC,EAAG,CAC3F,KAAM,CAACC,EAAWC,CAAY,EAAIL,EAAS,EAAK,EAC1C,CAACM,EAAOC,CAAQ,EAAIP,EAAwB,IAAI,EAgCtD,MAAO,CAAE,cA9BaD,EACpB,MAAOS,GAAwC,CAC7CH,EAAa,EAAI,EACjBE,EAAS,IAAI,EACb,GAAI,CACF,MAAME,EAAW,MAAM,MAAM,8CAA+C,CAC1E,OAAQ,MACR,YAAa,UACb,QAAS,CACP,eAAgB,mBAChB,mBAAoBP,CACtB,EACA,KAAM,KAAK,UAAU,CAAE,IAAKC,EAAS,GAAGK,CAAK,CAAC,CAChD,CAAC,EACKE,EAAS,MAAMD,EAAS,KAAK,EACnC,OAAIA,EAAS,IAAM,CAACC,EAAO,MAClB,IAETH,EAASG,GAAQ,OAAO,SAAWA,GAAQ,OAAS,eAAe,EAC5D,GACT,OAAS,EAAQ,CACf,OAAAH,EAAS,GAAG,SAAW,eAAe,EAC/B,EACT,QAAE,CACAF,EAAa,EAAK,CACpB,CACF,EACA,CAACH,EAAQC,CAAO,CAClB,EAEwB,UAAAC,EAAW,MAAAE,CAAM,CAC3C",
|
|
6
6
|
"names": ["useCallback", "useState", "useUpdateProfile", "locale", "appName", "isLoading", "setIsLoading", "error", "setError", "data", "response", "result"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import l from"swr";import{useMemberPopupContext as p}from"../../../context/provider";function v(){const{profile:r,alpcConfig:a}=p(),
|
|
1
|
+
import l from"swr";import{useMemberPopupContext as p}from"../../../context/provider";function v(){const{profile:r,alpcConfig:a}=p(),n=!!r?"/api/multipass/mktsrv/v1/referral/reward/overview/cash":null,o=async i=>{const e=await fetch(i,{method:"GET",credentials:"include",headers:{"Content-Type":"application/json","current-language":a.locale}});if(!e.ok)throw new Error(`HTTP error! status: ${e.status}`);return e.json()},{data:s,isLoading:t}=l(n,o,{revalidateOnFocus:!1});return{isLoading:t,data:s}}export{v as useReferralOverview};
|
|
2
2
|
//# sourceMappingURL=useReferralOverview.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/components/memberPopup/panels/Referral/hooks/useReferralOverview.ts"],
|
|
4
|
-
"sourcesContent": ["import useSWR from 'swr'\nimport { useMemberPopupContext } from '../../../context/provider'\n\nexport type ReferralRewardOverviewResponse = {\n data: {\n data: {\n available: number\n pending: number\n }\n }\n}\n\nexport function useReferralOverview(): {\n isLoading: boolean\n data?: ReferralRewardOverviewResponse\n} {\n const { profile, alpcConfig } = useMemberPopupContext()\n const isLogin = !!profile\n\n const swrKey = isLogin ? `/api/multipass/mktsrv/v1/referral/reward/overview/cash` : null\n\n const swrFetcher = async (url: string) => {\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n 'current-language': alpcConfig.locale,\n },\n })\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`)\n }\n return response.json()\n }\n\n const { data, isLoading } = useSWR<ReferralRewardOverviewResponse>(swrKey, swrFetcher, {\n revalidateOnFocus: false,\n })\n\n return { isLoading, data }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAOA,MAAY,MACnB,OAAS,yBAAAC,MAA6B,4BAW/B,SAASC,GAGd,CACA,KAAM,CAAE,QAAAC,EAAS,WAAAC,CAAW,EAAIH,EAAsB,EAGhDI,EAFU,CAAC,CAACF,EAEO,yDAA2D,KAE9EG,EAAa,MAAOC,GAAgB,CACxC,MAAMC,EAAW,MAAM,MAAMD,EAAK,CAChC,OAAQ,MACR,QAAS,CACP,eAAgB,mBAChB,mBAAoBH,EAAW,MACjC,CACF,CAAC,EACD,GAAI,CAACI,EAAS,GACZ,MAAM,IAAI,MAAM,uBAAuBA,EAAS,MAAM,EAAE,EAE1D,OAAOA,EAAS,KAAK,CACvB,EAEM,CAAE,KAAAC,EAAM,UAAAC,CAAU,EAAIV,EAAuCK,EAAQC,EAAY,CACrF,kBAAmB,EACrB,CAAC,EAED,MAAO,CAAE,UAAAI,EAAW,KAAAD,CAAK,CAC3B",
|
|
4
|
+
"sourcesContent": ["import useSWR from 'swr'\nimport { useMemberPopupContext } from '../../../context/provider'\n\nexport type ReferralRewardOverviewResponse = {\n data: {\n data: {\n available: number\n pending: number\n }\n }\n}\n\nexport function useReferralOverview(): {\n isLoading: boolean\n data?: ReferralRewardOverviewResponse\n} {\n const { profile, alpcConfig } = useMemberPopupContext()\n const isLogin = !!profile\n\n const swrKey = isLogin ? `/api/multipass/mktsrv/v1/referral/reward/overview/cash` : null\n\n const swrFetcher = async (url: string) => {\n const response = await fetch(url, {\n method: 'GET',\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n 'current-language': alpcConfig.locale,\n },\n })\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`)\n }\n return response.json()\n }\n\n const { data, isLoading } = useSWR<ReferralRewardOverviewResponse>(swrKey, swrFetcher, {\n revalidateOnFocus: false,\n })\n\n return { isLoading, data }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAY,MACnB,OAAS,yBAAAC,MAA6B,4BAW/B,SAASC,GAGd,CACA,KAAM,CAAE,QAAAC,EAAS,WAAAC,CAAW,EAAIH,EAAsB,EAGhDI,EAFU,CAAC,CAACF,EAEO,yDAA2D,KAE9EG,EAAa,MAAOC,GAAgB,CACxC,MAAMC,EAAW,MAAM,MAAMD,EAAK,CAChC,OAAQ,MACR,YAAa,UACb,QAAS,CACP,eAAgB,mBAChB,mBAAoBH,EAAW,MACjC,CACF,CAAC,EACD,GAAI,CAACI,EAAS,GACZ,MAAM,IAAI,MAAM,uBAAuBA,EAAS,MAAM,EAAE,EAE1D,OAAOA,EAAS,KAAK,CACvB,EAEM,CAAE,KAAAC,EAAM,UAAAC,CAAU,EAAIV,EAAuCK,EAAQC,EAAY,CACrF,kBAAmB,EACrB,CAAC,EAED,MAAO,CAAE,UAAAI,EAAW,KAAAD,CAAK,CAC3B",
|
|
6
6
|
"names": ["useSWR", "useMemberPopupContext", "useReferralOverview", "profile", "alpcConfig", "swrKey", "swrFetcher", "url", "response", "data", "isLoading"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -2,12 +2,13 @@ import { useCallback, useEffect, useState } from 'react'
|
|
|
2
2
|
|
|
3
3
|
import { useAlpcMutation } from './useAlpcFetch'
|
|
4
4
|
import type { CreditLogResponse } from '../response'
|
|
5
|
+
import { ALPC_COUNTRY_MAP } from '../const'
|
|
5
6
|
import { useCreditsContext } from '../provider'
|
|
6
7
|
import { useHeadlessContext } from '@anker-in/lib'
|
|
7
8
|
|
|
8
9
|
function useActivities({ page, pageSize, options = {} }: { page: number; pageSize: number; options?: any }) {
|
|
9
|
-
const { profile, isLoadingProfile, alpcBrand } = useCreditsContext()
|
|
10
|
-
const { brand: headlessBrand } = useHeadlessContext()
|
|
10
|
+
const { profile, isLoadingProfile, alpcBrand, alpcCountry } = useCreditsContext()
|
|
11
|
+
const { brand: headlessBrand, locale } = useHeadlessContext()
|
|
11
12
|
const brand = alpcBrand || headlessBrand
|
|
12
13
|
const [activities, setActivities] = useState<CreditLogResponse[]>([])
|
|
13
14
|
const [total, setTotal] = useState(0)
|
|
@@ -30,6 +31,7 @@ function useActivities({ page, pageSize, options = {} }: { page: number; pageSiz
|
|
|
30
31
|
url: `/v1/credit/log`,
|
|
31
32
|
initData: {
|
|
32
33
|
brand,
|
|
34
|
+
country: alpcCountry || ALPC_COUNTRY_MAP.get(locale) || locale,
|
|
33
35
|
},
|
|
34
36
|
})
|
|
35
37
|
|
|
@@ -59,7 +59,7 @@ const normalizeResponseData = (responseData: any) => {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
const fetcher = (options: FetcherOptions) => {
|
|
62
|
-
return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, options.fetchOptions).then(async response => {
|
|
62
|
+
return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, { credentials: 'include', ...options.fetchOptions }).then(async response => {
|
|
63
63
|
if (response.status < 300) {
|
|
64
64
|
const responseData = await response.json()
|
|
65
65
|
return normalizeResponseData(responseData)
|
|
@@ -79,7 +79,7 @@ const fetcher = (options: FetcherOptions) => {
|
|
|
79
79
|
|
|
80
80
|
if (result) {
|
|
81
81
|
// 跨区重新登录后需要替换区域标志,所以不能用最开始请求的那个链接
|
|
82
|
-
return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, options.fetchOptions).then(async response => {
|
|
82
|
+
return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, { credentials: 'include', ...options.fetchOptions }).then(async response => {
|
|
83
83
|
if (response.status < 300) {
|
|
84
84
|
const responseData = await response.json()
|
|
85
85
|
return normalizeResponseData(responseData)
|
|
@@ -14,6 +14,7 @@ function useShippingCountries({ shopifyStoreDomain }: { shopifyStoreDomain: stri
|
|
|
14
14
|
setLoading(true)
|
|
15
15
|
try {
|
|
16
16
|
const response = await fetch(`/api/multipass/rainbowbridge/uc/shop/shipping_zones?shop=${shopifyStoreDomain}`, {
|
|
17
|
+
credentials: 'include',
|
|
17
18
|
headers: {
|
|
18
19
|
'current-language': locale,
|
|
19
20
|
},
|
|
@@ -6,13 +6,13 @@ import { useCreditsContext } from '../provider'
|
|
|
6
6
|
import { useHeadlessContext, useSubscriptions } from '@anker-in/lib'
|
|
7
7
|
|
|
8
8
|
export const useSubscribed = () => {
|
|
9
|
-
const { profile } = useCreditsContext()
|
|
9
|
+
const { profile, apiBaseUrl } = useCreditsContext()
|
|
10
10
|
const { brand } = useHeadlessContext()
|
|
11
11
|
|
|
12
12
|
const activitiesOptions = useMemo(() => ({ page: 1, pageSize: 50 }), [])
|
|
13
13
|
|
|
14
14
|
const { activities } = useActivities(activitiesOptions)
|
|
15
|
-
const { data: subscription } = useSubscriptions({ email: profile?.email })
|
|
15
|
+
const { data: subscription } = useSubscriptions({ email: profile?.email, baseUrl: apiBaseUrl })
|
|
16
16
|
const subscriptionData = subscription?.data || subscription
|
|
17
17
|
|
|
18
18
|
const isSubscribed = useMemo(() => {
|
|
@@ -62,6 +62,7 @@ export default function ActivitiesSubscribeModal({ copy, email: initialEmail }:
|
|
|
62
62
|
try {
|
|
63
63
|
const response = await fetch('/api/multipass/rainbowbridge/activities', {
|
|
64
64
|
method: 'POST',
|
|
65
|
+
credentials: 'include',
|
|
65
66
|
headers: {
|
|
66
67
|
'Content-Type': 'application/json',
|
|
67
68
|
'current-language': locale,
|
|
@@ -22,9 +22,10 @@ export function useRedeemCoupon(config: AlpcConfig) {
|
|
|
22
22
|
return useSWRMutation<RedeemCouponResponse, Error, string, RedeemCouponParams>(
|
|
23
23
|
`/v1/credit/redeem/coupon`,
|
|
24
24
|
async (url: string, { arg }) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const response = await fetch(getAlpcPath(locale, apiBaseUrl) + url, {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
credentials: 'include',
|
|
28
|
+
headers: { 'Content-Type': 'application/json', 'current-language': locale },
|
|
28
29
|
body: JSON.stringify({
|
|
29
30
|
brand,
|
|
30
31
|
country: ALPC_COUNTRY_MAP.get(locale) || locale,
|
|
@@ -16,9 +16,10 @@ export function useRedeemableList(config: AlpcConfig) {
|
|
|
16
16
|
const { isMutating: listLoading, trigger } = useSWRMutation(
|
|
17
17
|
`/v1/credit/consume_credit_rules`,
|
|
18
18
|
async (url: string, { arg }: { arg: Record<string, any> }) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const response = await fetch(getAlpcPath(resolvedLocale, apiBaseUrl) + url, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
credentials: 'include',
|
|
22
|
+
headers: { 'Content-Type': 'application/json', 'current-language': resolvedLocale },
|
|
22
23
|
body: JSON.stringify(arg),
|
|
23
24
|
})
|
|
24
25
|
return response.json()
|
|
@@ -52,6 +52,7 @@ export default function SubscribeEmailPanel({ copy, email: initialEmail, onClose
|
|
|
52
52
|
try {
|
|
53
53
|
const response = await fetch('/api/multipass/subscribe/subscribe_emails', {
|
|
54
54
|
method: 'POST',
|
|
55
|
+
credentials: 'include',
|
|
55
56
|
headers: { 'Content-Type': 'application/json', 'current-language': locale },
|
|
56
57
|
body: JSON.stringify({
|
|
57
58
|
email,
|
|
@@ -2,12 +2,14 @@ import { useCallback, useEffect, useState } from 'react'
|
|
|
2
2
|
import useSWRMutation from 'swr/mutation'
|
|
3
3
|
import { getAlpcPath } from '../../../../credits/context/utils'
|
|
4
4
|
import type { CreditLogResponse } from '../../../../credits/context/response'
|
|
5
|
+
import { ALPC_COUNTRY_MAP } from '../../../../credits/context/const'
|
|
5
6
|
|
|
6
7
|
type UseActivitiesConfig = {
|
|
7
8
|
userId: string | undefined
|
|
8
9
|
brand: string
|
|
9
10
|
apiBaseUrl?: string
|
|
10
11
|
locale?: string
|
|
12
|
+
country?: string
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
type Params = {
|
|
@@ -16,7 +18,7 @@ type Params = {
|
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
function useActivities(
|
|
19
|
-
{ userId, brand, apiBaseUrl, locale = '' }: UseActivitiesConfig,
|
|
21
|
+
{ userId, brand, apiBaseUrl, locale = '', country }: UseActivitiesConfig,
|
|
20
22
|
{ page, pageSize }: Params
|
|
21
23
|
) {
|
|
22
24
|
const [activities, setActivities] = useState<CreditLogResponse[]>([])
|
|
@@ -26,9 +28,10 @@ function useActivities(
|
|
|
26
28
|
const { isMutating: isLoading, trigger } = useSWRMutation(
|
|
27
29
|
`/v1/credit/log`,
|
|
28
30
|
async (url: string, { arg }: { arg: Record<string, any> }) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
const response = await fetch(getAlpcPath(locale, apiBaseUrl) + url, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
credentials: 'include',
|
|
34
|
+
headers: { 'Content-Type': 'application/json', 'current-language': locale },
|
|
32
35
|
body: JSON.stringify(arg),
|
|
33
36
|
})
|
|
34
37
|
return response.json()
|
|
@@ -37,7 +40,7 @@ function useActivities(
|
|
|
37
40
|
|
|
38
41
|
const fetchActivities = useCallback(async () => {
|
|
39
42
|
await trigger(
|
|
40
|
-
{ page, page_size: pageSize, user_id: userId, brand },
|
|
43
|
+
{ page, page_size: pageSize, user_id: userId, brand, country: country || ALPC_COUNTRY_MAP.get(locale) || locale },
|
|
41
44
|
{
|
|
42
45
|
onSuccess(data) {
|
|
43
46
|
setCurrentPage(page)
|
|
@@ -16,7 +16,7 @@ export function useSubscribed({ userId, brand, email, locale = '', apiBaseUrl }:
|
|
|
16
16
|
{ userId, brand, apiBaseUrl, locale },
|
|
17
17
|
{ page: 1, pageSize: 50 }
|
|
18
18
|
)
|
|
19
|
-
const { data: subscription } = useSubscriptions({ email })
|
|
19
|
+
const { data: subscription } = useSubscriptions({ email, baseUrl: apiBaseUrl })
|
|
20
20
|
const subscriptionData = subscription?.data || subscription
|
|
21
21
|
|
|
22
22
|
return useMemo(() => {
|
|
@@ -24,6 +24,7 @@ export function useUpdateProfile({ locale = '', appName = '' }: UseUpdateProfile
|
|
|
24
24
|
try {
|
|
25
25
|
const response = await fetch('/api/multipass/account/users/update_profile', {
|
|
26
26
|
method: 'PUT',
|
|
27
|
+
credentials: 'include',
|
|
27
28
|
headers: {
|
|
28
29
|
'Content-Type': 'application/json',
|
|
29
30
|
'current-language': locale,
|
|
@@ -22,6 +22,7 @@ export function useReferralOverview(): {
|
|
|
22
22
|
const swrFetcher = async (url: string) => {
|
|
23
23
|
const response = await fetch(url, {
|
|
24
24
|
method: 'GET',
|
|
25
|
+
credentials: 'include',
|
|
25
26
|
headers: {
|
|
26
27
|
'Content-Type': 'application/json',
|
|
27
28
|
'current-language': alpcConfig.locale,
|