@anker-in/campaign-ui 0.4.5-beta.7 → 0.4.5-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/credits/context/hooks/useActivities.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useActivities.js.map +3 -3
- package/dist/cjs/components/credits/context/hooks/useAlpcFetch.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useAlpcFetch.js.map +3 -3
- package/dist/cjs/components/credits/context/hooks/useMyRewards.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useMyRewards.js.map +3 -3
- package/dist/cjs/components/credits/context/hooks/useRedeemableList.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useRedeemableList.js.map +2 -2
- package/dist/cjs/components/credits/context/hooks/useUploadReceipt.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useUploadReceipt.js.map +3 -3
- package/dist/esm/components/credits/context/hooks/useActivities.js +1 -1
- package/dist/esm/components/credits/context/hooks/useActivities.js.map +3 -3
- package/dist/esm/components/credits/context/hooks/useAlpcFetch.js +1 -1
- package/dist/esm/components/credits/context/hooks/useAlpcFetch.js.map +3 -3
- package/dist/esm/components/credits/context/hooks/useMyRewards.js +1 -1
- package/dist/esm/components/credits/context/hooks/useMyRewards.js.map +3 -3
- package/dist/esm/components/credits/context/hooks/useRedeemableList.js +1 -1
- package/dist/esm/components/credits/context/hooks/useRedeemableList.js.map +2 -2
- package/dist/esm/components/credits/context/hooks/useUploadReceipt.js +1 -1
- package/dist/esm/components/credits/context/hooks/useUploadReceipt.js.map +3 -3
- package/package.json +1 -1
- package/src/components/credits/context/hooks/useActivities.ts +2 -3
- package/src/components/credits/context/hooks/useAlpcFetch.ts +25 -4
- package/src/components/credits/context/hooks/useMyRewards.ts +2 -3
- package/src/components/credits/context/hooks/useRedeemableList.ts +1 -7
- package/src/components/credits/context/hooks/useUploadReceipt.tsx +19 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var z=(t,e)=>{for(var r in e)u(t,r,{get:e[r],enumerable:!0})},B=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of R(e))!h.call(t,s)&&s!==r&&u(t,s,{get:()=>e[s],enumerable:!(o=P(e,s))||o.enumerable});return t};var M=t=>B(u({},"__esModule",{value:!0}),t);var E={};z(E,{default:()=>k});module.exports=M(E);var i=require("react"),f=require("./useAlpcFetch"),b=require("../provider"),C=require("@anker-in/lib");function S({page:t,pageSize:e,options:r={}}){const{profile:o,isLoadingProfile:s,alpcBrand:L}=(0,b.useCreditsContext)(),{brand:v}=(0,C.useHeadlessContext)(),c=L||v,[n,_]=(0,i.useState)([]),[d,x]=(0,i.useState)(0),[g,A]=(0,i.useState)(0),{isMutating:a,trigger:l}=(0,f.useAlpcMutation)({url:"/v1/credit/log",initData:{brand:c}}),m=(0,i.useCallback)(async()=>{const y={page:t,page_size:e,user_id:o?.user_id,...r};l(y,{onSuccess(p){A(t),x(p?.data?.total),_(n.concat(p?.data?.creditLogs||[]))}})},[n,o,t,e,r,l]);return(0,i.useEffect)(()=>{s||!o||!c||a||t!==g&&t&&m()},[m,s,a,o,c,t,g]),{activities:n,isLoading:a,total:d,canNext:d>n.length&&!a}}var k=S;
|
|
2
2
|
//# sourceMappingURL=useActivities.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useActivities.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { CreditLogResponse } from '../response'\nimport { useCreditsContext } from '../provider'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useActivities({ page, pageSize, options = {} }: { page: number; pageSize: number; options?: any }) {\n const { profile, isLoadingProfile, alpcBrand } = useCreditsContext()\n const { brand: headlessBrand } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n const [activities, setActivities] = useState<CreditLogResponse[]>([])\n const [total, setTotal] = useState(0)\n\n const [currentPage, setCurrentPage] = useState(0)\n\n const { isMutating: isLoading, trigger } = useAlpcMutation<\n {\n data: {\n total: number\n creditLogs: CreditLogResponse[]\n }\n },\n {\n page: number\n page_size: number\n user_id: string\n }\n >({\n url: `/v1/credit/log`,\n initData: {\n brand,\n },\n })\n\n const getActivities = useCallback(async () => {\n const params = {\n page: page,\n page_size: pageSize,\n user_id: profile?.user_id,\n ...options,\n }\n\n trigger(params, {\n onSuccess(responseData) {\n setCurrentPage(page)\n
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiD,iBAEjDC,EAAgC,0BAEhCC,EAAkC,uBAClCC,EAAmC,yBAEnC,SAASC,EAAc,CAAE,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAU,CAAC,CAAE,EAAsD,CAC1G,KAAM,CAAE,QAAAC,EAAS,iBAAAC,EAAkB,UAAAC,CAAU,KAAI,qBAAkB,EAC7D,CAAE,MAAOC,CAAc,KAAI,sBAAmB,EAC9CC,EAAQF,GAAaC,EACrB,CAACE,EAAYC,CAAa,KAAI,YAA8B,CAAC,CAAC,EAC9D,CAACC,EAAOC,CAAQ,KAAI,YAAS,CAAC,EAE9B,CAACC,EAAaC,CAAc,KAAI,YAAS,CAAC,EAE1C,CAAE,WAAYC,EAAW,QAAAC,CAAQ,KAAI,mBAYzC,CACA,IAAK,iBACL,SAAU,CACR,MAAAR,CACF,CACF,CAAC,EAEKS,KAAgB,eAAY,SAAY,CAC5C,MAAMC,EAAS,CACb,KAAMjB,EACN,UAAWC,EACX,QAASE,GAAS,QAClB,GAAGD,CACL,EAEAa,EAAQE,EAAQ,CACd,UAAUC,EAAc,CACtBL,EAAeb,CAAI,
|
|
6
|
-
"names": ["useActivities_exports", "__export", "useActivities_default", "__toCommonJS", "import_react", "import_useAlpcFetch", "import_provider", "import_lib", "useActivities", "page", "pageSize", "options", "profile", "isLoadingProfile", "alpcBrand", "headlessBrand", "brand", "activities", "setActivities", "total", "setTotal", "currentPage", "setCurrentPage", "isLoading", "trigger", "getActivities", "params", "responseData"
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { CreditLogResponse } from '../response'\nimport { useCreditsContext } from '../provider'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useActivities({ page, pageSize, options = {} }: { page: number; pageSize: number; options?: any }) {\n const { profile, isLoadingProfile, alpcBrand } = useCreditsContext()\n const { brand: headlessBrand } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n const [activities, setActivities] = useState<CreditLogResponse[]>([])\n const [total, setTotal] = useState(0)\n\n const [currentPage, setCurrentPage] = useState(0)\n\n const { isMutating: isLoading, trigger } = useAlpcMutation<\n {\n data: {\n total: number\n creditLogs: CreditLogResponse[]\n }\n },\n {\n page: number\n page_size: number\n user_id: string\n }\n >({\n url: `/v1/credit/log`,\n initData: {\n brand,\n },\n })\n\n const getActivities = useCallback(async () => {\n const params = {\n page: page,\n page_size: pageSize,\n user_id: profile?.user_id,\n ...options,\n }\n\n trigger(params, {\n onSuccess(responseData) {\n setCurrentPage(page)\n setTotal(responseData?.data?.total)\n setActivities(activities.concat(responseData?.data?.creditLogs || []))\n },\n })\n }, [activities, profile, page, pageSize, options, trigger])\n\n useEffect(() => {\n if (isLoadingProfile || !profile || !brand || isLoading) {\n return\n }\n\n if (page !== currentPage && page) {\n getActivities()\n }\n }, [getActivities, isLoadingProfile, isLoading, profile, brand, page, currentPage])\n\n return {\n activities,\n isLoading,\n total,\n canNext: total > activities.length && !isLoading,\n }\n}\n\nexport default useActivities\n"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,CACF,CAEA,IAAOrB,EAAQM",
|
|
6
|
+
"names": ["useActivities_exports", "__export", "useActivities_default", "__toCommonJS", "import_react", "import_useAlpcFetch", "import_provider", "import_lib", "useActivities", "page", "pageSize", "options", "profile", "isLoadingProfile", "alpcBrand", "headlessBrand", "brand", "activities", "setActivities", "total", "setTotal", "currentPage", "setCurrentPage", "isLoading", "trigger", "getActivities", "params", "responseData"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var j=Object.create;var A=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var N=(t,e)=>{for(var n in e)A(t,n,{get:e[n],enumerable:!0})},M=(t,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of v(e))!$.call(t,r)&&r!==n&&A(t,r,{get:()=>e[r],enumerable:!(a=k(e,r))||a.enumerable});return t};var S=(t,e,n)=>(n=t!=null?j(I(t)):{},M(e||!t||!t.__esModule?A(n,"default",{value:t,enumerable:!0}):n,t)),W=t=>M(A({},"__esModule",{value:!0}),t);var H={};N(H,{useAlpcFetch:()=>J,useAlpcMutation:()=>K});module.exports=W(H);var D=S(require("js-cookie")),o=require("react"),P=S(require("swr")),B=require("@anker-in/lib"),O=require("../utils"),w=require("../provider");let b;const U=t=>t&&(t.data&&typeof t.data=="object"&&!Array.isArray(t.data)?t.data:t),x=t=>fetch((0,O.getAlpcPath)(t.locale,t.apiBaseUrl)+t.url,t.fetchOptions).then(async e=>{if(e.status<300){const n=await e.json();return U(n)}if(e.status===401&&t.onReAuth){b||(b=t.onReAuth());const n=await b;if(b=void 0,n)return fetch((0,O.getAlpcPath)(t.locale,t.apiBaseUrl)+t.url,t.fetchOptions).then(async a=>{if(a.status<300){const r=await a.json();return U(r)}if(a.status===401){t.onUnAuth&&t.onUnAuth();return}});t.onUnAuth&&t.onUnAuth();return}}),C=async(t,e,n,a)=>{let r=await fetch(`${(0,O.getAlpcPath)(t,a)}/cloud/login`,{method:"POST"}),i=await r.json(),s=U(i);if(r.status<300&&!e&&s?.code===27004){const c=D.default.get("alpcEU");if(Number(c)===1?D.default.set("alpcEU","0",{expires:30,domain:`.${n}.com`}):D.default.set("alpcEU","1",{expires:30,domain:`.${n}.com`}),r=await fetch(`${(0,O.getAlpcPath)(t,a)}/cloud/login`,{method:"POST"}),i=await r.json(),s=U(i),r.status>300)return!1}return!s?.code},z=(t,e,n={},a)=>{const r=(0,o.useRef)(!1),[i,s]=(0,o.useState)(),[c,d]=(0,o.useState)(!1),u=(0,o.useRef)(t),f=(0,o.useRef)(e),h=(0,o.useRef)(n),g=(0,o.useCallback)(async(y,T={})=>{if(console.log("[useAlpcMutation] trigger called with:",{url:u.current,fetchData:y,brand:a.current}),r.current){console.log("[useAlpcMutation] already mutating, skipping");return}if(!a.current){console.log("[useAlpcMutation] brand not available, skipping request");return}r.current=!0,d(!0);const p={...h.current,...T},{onSuccess:R,onError:m}=p||{};try{const l=await f.current(u.current,{arg:y});return s(l),d(!1),r.current=!1,R&&R(l),l}catch(l){d(!1),r.current=!1,m&&m(l)}},[]);return{isMutating:c,trigger:g,data:i}},J=(t,e)=>{const[n,a]=(0,o.useState)(!1),{removeProfile:r,alpcBrand:i,apiBaseUrl:s}=(0,w.useCreditsContext)(),{enable:c,...d}=e||{},{locale:u="",brand:f}=(0,B.useHeadlessContext)(),h=i||f,{queryKey:g=[],body:y={},headers:T,...p}=t,R=c??!0,[m,l]=g;return(0,P.default)([m,l],!R||!h?null:([F,q])=>x({url:F,locale:u,apiBaseUrl:s,fetchOptions:{method:"POST",headers:{"current-language":u,...T},body:JSON.stringify({...y,...q}),...p},onReAuth:async()=>await C(u,n,h,s)?(a(!0),!0):!1,onUnAuth(){r()}}),{revalidateOnFocus:!1,...d})},K=(t,e)=>{const[n,a]=(0,o.useState)(!1),{removeProfile:r,alpcBrand:i,apiBaseUrl:s}=(0,w.useCreditsContext)(),{locale:c="",brand:d}=(0,B.useHeadlessContext)(),u=i||d,f=(0,o.useRef)(u);f.current=u;const{url:h,initData:g,headers:y,...T}=t,p=(0,o.useRef)(g);return p.current=g,z(h,(m,l)=>f.current?x({url:m,locale:c,apiBaseUrl:s,fetchOptions:{method:"POST",headers:{"current-language":c,...y},...T,body:JSON.stringify({...p.current,...l.arg})},onReAuth:async()=>await C(c,n,f.current,s)?(a(!0),!0):!1,onUnAuth(){r()}}):Promise.resolve(void 0),e,f)};
|
|
2
2
|
//# sourceMappingURL=useAlpcFetch.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useAlpcFetch.ts"],
|
|
4
|
-
"sourcesContent": ["import Cookies from 'js-cookie'\nimport { useCallback, useRef, useState } from 'react'\nimport useSWR, { type SWRConfiguration } from 'swr'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nimport { getAlpcPath } from '../utils'\nimport { useCreditsContext } from '../provider'\n\ninterface UseAlpcFetchOptionsSwrOptions<TData, Error> extends SWRConfiguration<TData, Error> {\n enable?: boolean\n}\n\ninterface FetchOptions extends RequestInit {\n queryKey: [string, Record<string, any>]\n data?: Record<string, any>\n}\n\ninterface MutationOptions extends RequestInit {\n url: string\n initData: Record<string, any>\n}\n\ninterface FetcherOptions {\n url: string\n locale: string\n fetchOptions: RequestInit\n onReAuth: () => Promise<boolean>\n onUnAuth: () => void\n apiBaseUrl?: string\n}\n\nlet reAuthPromise: Promise<boolean> | undefined\n\ntype Fetcher<TData, TBody> = (url: string, data: { arg: TBody }) => Promise<TData>\n\nconst fetcher = (options: FetcherOptions) => {\n return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, options.fetchOptions).then(async response => {\n if (response.status < 300) {\n const responseData = await response.json()\n return responseData\n }\n\n // \u9519\u8BEF\u5904\u7406\n if (response.status === 401) {\n // \u91CD\u65B0\u767B\u5F55\u5C1D\u8BD5\n if (options.onReAuth) {\n if (!reAuthPromise) {\n reAuthPromise = options.onReAuth()\n }\n\n const result = await reAuthPromise\n\n reAuthPromise = undefined\n\n if (result) {\n // \u8DE8\u533A\u91CD\u65B0\u767B\u5F55\u540E\u9700\u8981\u66FF\u6362\u533A\u57DF\u6807\u5FD7\uFF0C\u6240\u4EE5\u4E0D\u80FD\u7528\u6700\u5F00\u59CB\u8BF7\u6C42\u7684\u90A3\u4E2A\u94FE\u63A5\n return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, options.fetchOptions).then(async response => {\n if (response.status < 300) {\n const responseData = await response.json()\n return responseData\n }\n\n if (response.status === 401) {\n if (options.onUnAuth) {\n options.onUnAuth()\n }\n return\n }\n })\n } else {\n if (options.onUnAuth) {\n options.onUnAuth()\n }\n return\n }\n }\n }\n })\n}\n\nconst reAuth = async (locale: string, retry: boolean, brand: string, apiBaseUrl?: string) => {\n let reloginResponse = await fetch(`${getAlpcPath(locale, apiBaseUrl)}/cloud/login`, {\n method: 'POST',\n })\n let reloginResponseData = await reloginResponse.json()\n\n if (reloginResponse!.status < 300 && !retry) {\n if (reloginResponseData?.data?.code === 27004) {\n // \u8DE8\u533A\u767B\u5F55\u9519\u8BEF\n const alpcEUCookie = Cookies.get('alpcEU')\n\n if (Number(alpcEUCookie) === 1) {\n Cookies.set('alpcEU', '0', {\n expires: 30,\n domain: `.${brand}.com`,\n })\n } else {\n Cookies.set('alpcEU', '1', {\n expires: 30,\n domain: `.${brand}.com`,\n })\n }\n\n // \u91CD\u65B0\u5C1D\u8BD5\u6362\u533A\u767B\u5F55\n reloginResponse = await fetch(`${getAlpcPath(locale, apiBaseUrl)}/cloud/login`, {\n method: 'POST',\n })\n reloginResponseData = await reloginResponse.json()\n\n if (reloginResponse.status > 300) {\n return false\n }\n }\n }\n if (!reloginResponseData?.data?.code) {\n // \u91CD\u65B0\u767B\u5F55\u6210\u529F\n return true\n }\n\n return false\n}\n\nexport interface UseMutationConfig<TData> {\n onSuccess?: (response: TData) => any\n onError?: (error: Error) => any\n}\n\nconst useMutation = <TData, TBody>(\n url: string,\n fetcher: Fetcher<TData, TBody>,\n mutationConfig: UseMutationConfig<TData> = {},\n brandRef: React.MutableRefObject<string | undefined>\n) => {\n const innerMutating = useRef<boolean>(false)\n\n const [data, setData] = useState<TData>()\n const [isMutating, setIsMutating] = useState(false)\n\n const urlRef = useRef(url)\n const fetcherRef = useRef(fetcher)\n const configRef = useRef(mutationConfig)\n\n const trigger = useCallback(\n async (fetchData: TBody, opts: UseMutationConfig<TData> = {}) => {\n console.log('[useAlpcMutation] trigger called with:', { url: urlRef.current, fetchData, brand: brandRef.current })\n\n if (innerMutating.current) {\n console.log('[useAlpcMutation] already mutating, skipping')\n return\n }\n\n if (!brandRef.current) {\n console.log('[useAlpcMutation] brand not available, skipping request')\n return\n }\n\n innerMutating.current = true\n setIsMutating(true)\n\n const config = {\n ...configRef.current,\n ...opts,\n }\n\n const { onSuccess, onError } = config || {}\n\n try {\n const fetchResult = await fetcherRef.current(urlRef.current, {\n arg: fetchData,\n })\n setData(fetchResult)\n\n setIsMutating(false)\n innerMutating.current = false\n\n if (onSuccess) {\n onSuccess(fetchResult)\n }\n return fetchResult\n } catch (err: any) {\n setIsMutating(false)\n innerMutating.current = false\n\n if (onError) {\n onError(err)\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n []\n )\n\n return {\n isMutating,\n trigger,\n data,\n }\n}\n\nexport const useAlpcFetch = <TData>(\n options: FetchOptions,\n swrOptions?: UseAlpcFetchOptionsSwrOptions<TData, Error>\n) => {\n const [retry, setRetry] = useState(false)\n const { removeProfile, alpcBrand, apiBaseUrl } = useCreditsContext()\n\n const { enable, ...otherSwrOptions } = swrOptions || {}\n\n const { locale = '', brand: headlessBrand } = useHeadlessContext()\n // \u4F18\u5148\u4F7F\u7528 creditsContext \u4E2D\u7684 alpcBrand\uFF0C\u5982\u679C\u6CA1\u6709\u5219\u4F7F\u7528 headlessConfig \u4E2D\u7684 brand\n const brand = alpcBrand || headlessBrand\n\n const { queryKey = [], body: fetchBody = {}, headers, ...fetchOptions } = options\n const fetchEnable = enable ?? true\n\n const [url, requestBody] = queryKey\n\n const context = useSWR<TData>(\n [url, requestBody],\n !fetchEnable || !brand\n ? null\n : ([requestUrl, data]: [string, Record<string, any>]) =>\n fetcher({\n url: requestUrl,\n locale,\n apiBaseUrl,\n fetchOptions: {\n method: 'POST',\n headers: {\n 'current-language': locale,\n ...headers,\n },\n body: JSON.stringify({\n ...fetchBody,\n ...data,\n }),\n ...fetchOptions,\n },\n onReAuth: async () => {\n const result = await reAuth(locale, retry, brand, apiBaseUrl)\n\n if (result) {\n setRetry(true)\n return true\n }\n\n return false\n },\n onUnAuth() {\n // \u5931\u8D25\u540E\u9000\u51FA\u767B\u5F55\n removeProfile()\n },\n }),\n {\n revalidateOnFocus: false,\n ...otherSwrOptions,\n }\n )\n\n return context\n}\n\nexport const useAlpcMutation = <TData, TBody>(options: MutationOptions, mutationOptions?: UseMutationConfig<TData>) => {\n const [retry, setRetry] = useState(false)\n const { removeProfile, alpcBrand, apiBaseUrl } = useCreditsContext()\n\n const { locale = '', brand: headlessBrand } = useHeadlessContext()\n // \u4F18\u5148\u4F7F\u7528 creditsContext \u4E2D\u7684 alpcBrand\uFF0C\u5982\u679C\u6CA1\u6709\u5219\u4F7F\u7528 headlessConfig \u4E2D\u7684 brand\n const brand = alpcBrand || headlessBrand\n const brandRef = useRef(brand)\n brandRef.current = brand\n\n const { url, initData, headers, ...fetchOptions } = options\n const initDataRef = useRef(initData)\n initDataRef.current = initData\n\n const context = useMutation<TData, TBody>(\n url,\n (requestUrl, data: { arg: TBody }) => {\n // Prevent requests when brand is not available\n if (!brandRef.current) {\n return Promise.resolve(undefined as unknown as TData)\n }\n\n return fetcher({\n url: requestUrl,\n locale,\n apiBaseUrl,\n fetchOptions: {\n method: 'POST',\n headers: {\n 'current-language': locale,\n ...headers,\n },\n ...fetchOptions,\n body: JSON.stringify({\n ...initDataRef.current,\n ...data.arg,\n }),\n },\n onReAuth: async () => {\n const result = await reAuth(locale, retry, brandRef.current!, apiBaseUrl)\n\n if (result) {\n setRetry(true)\n return true\n }\n\n return false\n },\n onUnAuth() {\n // \u5931\u8D25\u540E\u9000\u51FA\u767B\u5F55\n removeProfile()\n },\n })\n },\n mutationOptions,\n brandRef\n )\n\n return context\n}\n"],
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,oBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAAoB,wBACpBC,EAA8C,iBAC9CC,EAA8C,kBAC9CC,EAAmC,yBAEnCC,EAA4B,oBAC5BC,EAAkC,uBAyBlC,IAAIC,
|
|
6
|
-
"names": ["useAlpcFetch_exports", "__export", "useAlpcFetch", "useAlpcMutation", "__toCommonJS", "import_js_cookie", "import_react", "import_swr", "import_lib", "import_utils", "import_provider", "reAuthPromise", "fetcher", "options", "response", "result", "reAuth", "locale", "retry", "brand", "apiBaseUrl", "reloginResponse", "reloginResponseData", "alpcEUCookie", "Cookies", "useMutation", "url", "mutationConfig", "brandRef", "innerMutating", "data", "setData", "isMutating", "setIsMutating", "urlRef", "fetcherRef", "configRef", "trigger", "fetchData", "opts", "config", "onSuccess", "onError", "fetchResult", "err", "swrOptions", "setRetry", "removeProfile", "alpcBrand", "enable", "otherSwrOptions", "headlessBrand", "queryKey", "fetchBody", "headers", "fetchOptions", "fetchEnable", "requestBody", "useSWR", "requestUrl", "mutationOptions", "initData", "initDataRef"]
|
|
4
|
+
"sourcesContent": ["import Cookies from 'js-cookie'\nimport { useCallback, useRef, useState } from 'react'\nimport useSWR, { type SWRConfiguration } from 'swr'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nimport { getAlpcPath } from '../utils'\nimport { useCreditsContext } from '../provider'\n\ninterface UseAlpcFetchOptionsSwrOptions<TData, Error> extends SWRConfiguration<TData, Error> {\n enable?: boolean\n}\n\ninterface FetchOptions extends RequestInit {\n queryKey: [string, Record<string, any>]\n data?: Record<string, any>\n}\n\ninterface MutationOptions extends RequestInit {\n url: string\n initData: Record<string, any>\n}\n\ninterface FetcherOptions {\n url: string\n locale: string\n fetchOptions: RequestInit\n onReAuth: () => Promise<boolean>\n onUnAuth: () => void\n apiBaseUrl?: string\n}\n\nlet reAuthPromise: Promise<boolean> | undefined\n\ntype Fetcher<TData, TBody> = (url: string, data: { arg: TBody }) => Promise<TData>\n\n/**\n * \u7EDF\u4E00\u5904\u7406 ALPC \u63A5\u53E3\u8FD4\u56DE\u7684\u6570\u636E\u7ED3\u6784\n * \u517C\u5BB9\u4E00\u5C42 data \u548C\u4E24\u5C42 data \u7684\u573A\u666F\uFF1A\n * - \u4E24\u5C42 data: {data: {data: ..., code: 27004}}\n * - \u4E00\u5C42 data: {data: ..., code: 27004}\n */\nconst normalizeResponseData = (responseData: any) => {\n if (!responseData) return responseData\n\n // \u5982\u679C responseData.data \u5B58\u5728\u4E14\u662F\u4E00\u4E2A\u5BF9\u8C61\uFF08\u4E0D\u662F\u6570\u7EC4\uFF09\uFF0C\u8BF4\u660E\u662F\u4E24\u5C42 data \u7ED3\u6784\n if (responseData.data && typeof responseData.data === 'object' && !Array.isArray(responseData.data)) {\n return responseData.data\n }\n\n // \u4E00\u5C42 data \u7ED3\u6784\u6216\u5176\u4ED6\u60C5\u51B5\uFF0C\u76F4\u63A5\u8FD4\u56DE\n return responseData\n}\n\nconst fetcher = (options: FetcherOptions) => {\n return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, options.fetchOptions).then(async response => {\n if (response.status < 300) {\n const responseData = await response.json()\n return normalizeResponseData(responseData)\n }\n\n // \u9519\u8BEF\u5904\u7406\n if (response.status === 401) {\n // \u91CD\u65B0\u767B\u5F55\u5C1D\u8BD5\n if (options.onReAuth) {\n if (!reAuthPromise) {\n reAuthPromise = options.onReAuth()\n }\n\n const result = await reAuthPromise\n\n reAuthPromise = undefined\n\n if (result) {\n // \u8DE8\u533A\u91CD\u65B0\u767B\u5F55\u540E\u9700\u8981\u66FF\u6362\u533A\u57DF\u6807\u5FD7\uFF0C\u6240\u4EE5\u4E0D\u80FD\u7528\u6700\u5F00\u59CB\u8BF7\u6C42\u7684\u90A3\u4E2A\u94FE\u63A5\n return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, options.fetchOptions).then(async response => {\n if (response.status < 300) {\n const responseData = await response.json()\n return normalizeResponseData(responseData)\n }\n\n if (response.status === 401) {\n if (options.onUnAuth) {\n options.onUnAuth()\n }\n return\n }\n })\n } else {\n if (options.onUnAuth) {\n options.onUnAuth()\n }\n return\n }\n }\n }\n })\n}\n\nconst reAuth = async (locale: string, retry: boolean, brand: string, apiBaseUrl?: string) => {\n let reloginResponse = await fetch(`${getAlpcPath(locale, apiBaseUrl)}/cloud/login`, {\n method: 'POST',\n })\n let reloginResponseData = await reloginResponse.json()\n // \u517C\u5BB9\u4E24\u5C42 data \u7ED3\u6784\n let normalizedData = normalizeResponseData(reloginResponseData)\n\n if (reloginResponse!.status < 300 && !retry) {\n if (normalizedData?.code === 27004) {\n // \u8DE8\u533A\u767B\u5F55\u9519\u8BEF\n const alpcEUCookie = Cookies.get('alpcEU')\n\n if (Number(alpcEUCookie) === 1) {\n Cookies.set('alpcEU', '0', {\n expires: 30,\n domain: `.${brand}.com`,\n })\n } else {\n Cookies.set('alpcEU', '1', {\n expires: 30,\n domain: `.${brand}.com`,\n })\n }\n\n // \u91CD\u65B0\u5C1D\u8BD5\u6362\u533A\u767B\u5F55\n reloginResponse = await fetch(`${getAlpcPath(locale, apiBaseUrl)}/cloud/login`, {\n method: 'POST',\n })\n reloginResponseData = await reloginResponse.json()\n normalizedData = normalizeResponseData(reloginResponseData)\n\n if (reloginResponse.status > 300) {\n return false\n }\n }\n }\n if (!normalizedData?.code) {\n // \u91CD\u65B0\u767B\u5F55\u6210\u529F\n return true\n }\n\n return false\n}\n\nexport interface UseMutationConfig<TData> {\n onSuccess?: (response: TData) => any\n onError?: (error: Error) => any\n}\n\nconst useMutation = <TData, TBody>(\n url: string,\n fetcher: Fetcher<TData, TBody>,\n mutationConfig: UseMutationConfig<TData> = {},\n brandRef: React.MutableRefObject<string | undefined>\n) => {\n const innerMutating = useRef<boolean>(false)\n\n const [data, setData] = useState<TData>()\n const [isMutating, setIsMutating] = useState(false)\n\n const urlRef = useRef(url)\n const fetcherRef = useRef(fetcher)\n const configRef = useRef(mutationConfig)\n\n const trigger = useCallback(\n async (fetchData: TBody, opts: UseMutationConfig<TData> = {}) => {\n console.log('[useAlpcMutation] trigger called with:', { url: urlRef.current, fetchData, brand: brandRef.current })\n\n if (innerMutating.current) {\n console.log('[useAlpcMutation] already mutating, skipping')\n return\n }\n\n if (!brandRef.current) {\n console.log('[useAlpcMutation] brand not available, skipping request')\n return\n }\n\n innerMutating.current = true\n setIsMutating(true)\n\n const config = {\n ...configRef.current,\n ...opts,\n }\n\n const { onSuccess, onError } = config || {}\n\n try {\n const fetchResult = await fetcherRef.current(urlRef.current, {\n arg: fetchData,\n })\n setData(fetchResult)\n\n setIsMutating(false)\n innerMutating.current = false\n\n if (onSuccess) {\n onSuccess(fetchResult)\n }\n return fetchResult\n } catch (err: any) {\n setIsMutating(false)\n innerMutating.current = false\n\n if (onError) {\n onError(err)\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n []\n )\n\n return {\n isMutating,\n trigger,\n data,\n }\n}\n\nexport const useAlpcFetch = <TData>(\n options: FetchOptions,\n swrOptions?: UseAlpcFetchOptionsSwrOptions<TData, Error>\n) => {\n const [retry, setRetry] = useState(false)\n const { removeProfile, alpcBrand, apiBaseUrl } = useCreditsContext()\n\n const { enable, ...otherSwrOptions } = swrOptions || {}\n\n const { locale = '', brand: headlessBrand } = useHeadlessContext()\n // \u4F18\u5148\u4F7F\u7528 creditsContext \u4E2D\u7684 alpcBrand\uFF0C\u5982\u679C\u6CA1\u6709\u5219\u4F7F\u7528 headlessConfig \u4E2D\u7684 brand\n const brand = alpcBrand || headlessBrand\n\n const { queryKey = [], body: fetchBody = {}, headers, ...fetchOptions } = options\n const fetchEnable = enable ?? true\n\n const [url, requestBody] = queryKey\n\n const context = useSWR<TData>(\n [url, requestBody],\n !fetchEnable || !brand\n ? null\n : ([requestUrl, data]: [string, Record<string, any>]) =>\n fetcher({\n url: requestUrl,\n locale,\n apiBaseUrl,\n fetchOptions: {\n method: 'POST',\n headers: {\n 'current-language': locale,\n ...headers,\n },\n body: JSON.stringify({\n ...fetchBody,\n ...data,\n }),\n ...fetchOptions,\n },\n onReAuth: async () => {\n const result = await reAuth(locale, retry, brand, apiBaseUrl)\n\n if (result) {\n setRetry(true)\n return true\n }\n\n return false\n },\n onUnAuth() {\n // \u5931\u8D25\u540E\u9000\u51FA\u767B\u5F55\n removeProfile()\n },\n }),\n {\n revalidateOnFocus: false,\n ...otherSwrOptions,\n }\n )\n\n return context\n}\n\nexport const useAlpcMutation = <TData, TBody>(options: MutationOptions, mutationOptions?: UseMutationConfig<TData>) => {\n const [retry, setRetry] = useState(false)\n const { removeProfile, alpcBrand, apiBaseUrl } = useCreditsContext()\n\n const { locale = '', brand: headlessBrand } = useHeadlessContext()\n // \u4F18\u5148\u4F7F\u7528 creditsContext \u4E2D\u7684 alpcBrand\uFF0C\u5982\u679C\u6CA1\u6709\u5219\u4F7F\u7528 headlessConfig \u4E2D\u7684 brand\n const brand = alpcBrand || headlessBrand\n const brandRef = useRef(brand)\n brandRef.current = brand\n\n const { url, initData, headers, ...fetchOptions } = options\n const initDataRef = useRef(initData)\n initDataRef.current = initData\n\n const context = useMutation<TData, TBody>(\n url,\n (requestUrl, data: { arg: TBody }) => {\n // Prevent requests when brand is not available\n if (!brandRef.current) {\n return Promise.resolve(undefined as unknown as TData)\n }\n\n return fetcher({\n url: requestUrl,\n locale,\n apiBaseUrl,\n fetchOptions: {\n method: 'POST',\n headers: {\n 'current-language': locale,\n ...headers,\n },\n ...fetchOptions,\n body: JSON.stringify({\n ...initDataRef.current,\n ...data.arg,\n }),\n },\n onReAuth: async () => {\n const result = await reAuth(locale, retry, brandRef.current!, apiBaseUrl)\n\n if (result) {\n setRetry(true)\n return true\n }\n\n return false\n },\n onUnAuth() {\n // \u5931\u8D25\u540E\u9000\u51FA\u767B\u5F55\n removeProfile()\n },\n })\n },\n mutationOptions,\n brandRef\n )\n\n return context\n}\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,oBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAAoB,wBACpBC,EAA8C,iBAC9CC,EAA8C,kBAC9CC,EAAmC,yBAEnCC,EAA4B,oBAC5BC,EAAkC,uBAyBlC,IAAIC,EAUJ,MAAMC,EAAyBC,GACxBA,IAGDA,EAAa,MAAQ,OAAOA,EAAa,MAAS,UAAY,CAAC,MAAM,QAAQA,EAAa,IAAI,EACzFA,EAAa,KAIfA,GAGHC,EAAWC,GACR,SAAM,eAAYA,EAAQ,OAAQA,EAAQ,UAAU,EAAIA,EAAQ,IAAKA,EAAQ,YAAY,EAAE,KAAK,MAAMC,GAAY,CACvH,GAAIA,EAAS,OAAS,IAAK,CACzB,MAAMH,EAAe,MAAMG,EAAS,KAAK,EACzC,OAAOJ,EAAsBC,CAAY,CAC3C,CAGA,GAAIG,EAAS,SAAW,KAElBD,EAAQ,SAAU,CACfJ,IACHA,EAAgBI,EAAQ,SAAS,GAGnC,MAAME,EAAS,MAAMN,EAIrB,GAFAA,EAAgB,OAEZM,EAEF,OAAO,SAAM,eAAYF,EAAQ,OAAQA,EAAQ,UAAU,EAAIA,EAAQ,IAAKA,EAAQ,YAAY,EAAE,KAAK,MAAMC,GAAY,CACvH,GAAIA,EAAS,OAAS,IAAK,CACzB,MAAMH,EAAe,MAAMG,EAAS,KAAK,EACzC,OAAOJ,EAAsBC,CAAY,CAC3C,CAEA,GAAIG,EAAS,SAAW,IAAK,CACvBD,EAAQ,UACVA,EAAQ,SAA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C,EAjCQ,QAAQ,QAAQ,MAA6B,EAmCxDa,EACAhC,CACF,CAGF",
|
|
6
|
+
"names": ["useAlpcFetch_exports", "__export", "useAlpcFetch", "useAlpcMutation", "__toCommonJS", "import_js_cookie", "import_react", "import_swr", "import_lib", "import_utils", "import_provider", "reAuthPromise", "normalizeResponseData", "responseData", "fetcher", "options", "response", "result", "reAuth", "locale", "retry", "brand", "apiBaseUrl", "reloginResponse", "reloginResponseData", "normalizedData", "alpcEUCookie", "Cookies", "useMutation", "url", "mutationConfig", "brandRef", "innerMutating", "data", "setData", "isMutating", "setIsMutating", "urlRef", "fetcherRef", "configRef", "trigger", "fetchData", "opts", "config", "onSuccess", "onError", "fetchResult", "err", "swrOptions", "setRetry", "removeProfile", "alpcBrand", "enable", "otherSwrOptions", "headlessBrand", "queryKey", "fetchBody", "headers", "fetchOptions", "fetchEnable", "requestBody", "useSWR", "requestUrl", "mutationOptions", "initData", "initDataRef"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var i=Object.defineProperty;var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var s in e)i(t,s,{get:e[s],enumerable:!0})},N=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of L(e))!T.call(t,r)&&r!==s&&i(t,r,{get:()=>e[r],enumerable:!(o=w(e,r))||o.enumerable});return t};var h=t=>N(i({},"__esModule",{value:!0}),t);var P={};x(P,{default:()=>B});module.exports=h(P);var n=require("react"),a=require("../const"),_=require("./useAlpcFetch"),f=require("../provider"),y=require("@anker-in/lib");function z({page:t,pageSize:e,consumeType:s}){const{profile:o,alpcBrand:r}=(0,f.useCreditsContext)(),{brand:R,locale:m,appName:C}=(0,y.useHeadlessContext)(),u=r||R,[d,b]=(0,n.useState)([]),[c,A]=(0,n.useState)(0),{isMutating:l,trigger:M}=(0,_.useAlpcMutation)({url:"/v1/credit/log/coupon",initData:{brand:u,country:a.ALPC_COUNTRY_MAP.get(m)||m,app_name:C}}),p=(0,n.useCallback)(async()=>{o?.user_id&&await M({consume_type:s||a.AlpcConsumeType.Coupon,page:t,page_size:e,user_id:o?.user_id},{onSuccess(g){A(g?.data?.total),b(g?.data?.redeem_logs||[])}})},[s,t,e,o?.user_id]);return(0,n.useEffect)(()=>{!u||!o?.user_id||p()},[p,u]),{myRewards:d,isLoading:l,total:c,getMyRewards:p,canNext:c>d.length&&!l}}var B=z;
|
|
2
2
|
//# sourceMappingURL=useMyRewards.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useMyRewards.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { ALPC_COUNTRY_MAP, AlpcConsumeType } from '../const'\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { RedeemLogResponse } from '../response'\nimport { useCreditsContext } from '../provider'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useMyRewards({\n page,\n pageSize,\n consumeType,\n}: {\n page: number\n pageSize: number\n consumeType?: AlpcConsumeType\n}) {\n const { profile, alpcBrand } = useCreditsContext()\n const { brand: headlessBrand, locale, appName } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n\n const [myRewards, setMyRewards] = useState<RedeemLogResponse[]>([])\n const [total, setTotal] = useState(0)\n\n const { isMutating: isLoading, trigger } = useAlpcMutation<\n { data: { redeem_logs: RedeemLogResponse[]; total: number } },\n {\n page: number\n page_size: number\n consume_type: AlpcConsumeType\n user_id: string\n }\n >({\n url: `/v1/credit/log/coupon`,\n initData: {\n brand: brand,\n country: ALPC_COUNTRY_MAP.get(locale) || locale,\n app_name: appName,\n },\n })\n\n const getMyRewards = useCallback(async () => {\n if (!profile?.user_id) {\n return\n }\n await trigger(\n {\n consume_type: consumeType || AlpcConsumeType.Coupon,\n page,\n page_size: pageSize,\n user_id: profile?.user_id,\n },\n {\n onSuccess(responseData) {\n
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiD,iBAEjDC,EAAkD,oBAClDC,EAAgC,0BAEhCC,EAAkC,uBAClCC,EAAmC,yBAEnC,SAASC,EAAa,CACpB,KAAAC,EACA,SAAAC,EACA,YAAAC,CACF,EAIG,CACD,KAAM,CAAE,QAAAC,EAAS,UAAAC,CAAU,KAAI,qBAAkB,EAC3C,CAAE,MAAOC,EAAe,OAAAC,EAAQ,QAAAC,CAAQ,KAAI,sBAAmB,EAC/DC,EAAQJ,GAAaC,EAErB,CAACI,EAAWC,CAAY,KAAI,YAA8B,CAAC,CAAC,EAC5D,CAACC,EAAOC,CAAQ,KAAI,YAAS,CAAC,EAE9B,CAAE,WAAYC,EAAW,QAAAC,CAAQ,KAAI,mBAQzC,CACA,IAAK,wBACL,SAAU,CACR,MAAON,EACP,QAAS,mBAAiB,IAAIF,CAAM,GAAKA,EACzC,SAAUC,CACZ,CACF,CAAC,EAEKQ,KAAe,eAAY,SAAY,CACtCZ,GAAS,SAGd,MAAMW,EACJ,CACE,aAAcZ,GAAe,kBAAgB,OAC7C,KAAAF,EACA,UAAWC,EACX,QAASE,GAAS,OACpB,EACA,CACE,UAAUa,EAAc,
|
|
6
|
-
"names": ["useMyRewards_exports", "__export", "useMyRewards_default", "__toCommonJS", "import_react", "import_const", "import_useAlpcFetch", "import_provider", "import_lib", "useMyRewards", "page", "pageSize", "consumeType", "profile", "alpcBrand", "headlessBrand", "locale", "appName", "brand", "myRewards", "setMyRewards", "total", "setTotal", "isLoading", "trigger", "getMyRewards", "responseData"
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { ALPC_COUNTRY_MAP, AlpcConsumeType } from '../const'\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { RedeemLogResponse } from '../response'\nimport { useCreditsContext } from '../provider'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useMyRewards({\n page,\n pageSize,\n consumeType,\n}: {\n page: number\n pageSize: number\n consumeType?: AlpcConsumeType\n}) {\n const { profile, alpcBrand } = useCreditsContext()\n const { brand: headlessBrand, locale, appName } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n\n const [myRewards, setMyRewards] = useState<RedeemLogResponse[]>([])\n const [total, setTotal] = useState(0)\n\n const { isMutating: isLoading, trigger } = useAlpcMutation<\n { data: { redeem_logs: RedeemLogResponse[]; total: number } },\n {\n page: number\n page_size: number\n consume_type: AlpcConsumeType\n user_id: string\n }\n >({\n url: `/v1/credit/log/coupon`,\n initData: {\n brand: brand,\n country: ALPC_COUNTRY_MAP.get(locale) || locale,\n app_name: appName,\n },\n })\n\n const getMyRewards = useCallback(async () => {\n if (!profile?.user_id) {\n return\n }\n await trigger(\n {\n consume_type: consumeType || AlpcConsumeType.Coupon,\n page,\n page_size: pageSize,\n user_id: profile?.user_id,\n },\n {\n onSuccess(responseData) {\n setTotal(responseData?.data?.total)\n setMyRewards(responseData?.data?.redeem_logs || [])\n },\n }\n )\n }, [consumeType, page, pageSize, profile?.user_id])\n\n useEffect(() => {\n if (!brand || !profile?.user_id) {\n return\n }\n getMyRewards()\n }, [getMyRewards, brand])\n\n return {\n myRewards,\n isLoading,\n total,\n getMyRewards,\n canNext: total > myRewards.length && !isLoading,\n }\n}\n\nexport default useMyRewards\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiD,iBAEjDC,EAAkD,oBAClDC,EAAgC,0BAEhCC,EAAkC,uBAClCC,EAAmC,yBAEnC,SAASC,EAAa,CACpB,KAAAC,EACA,SAAAC,EACA,YAAAC,CACF,EAIG,CACD,KAAM,CAAE,QAAAC,EAAS,UAAAC,CAAU,KAAI,qBAAkB,EAC3C,CAAE,MAAOC,EAAe,OAAAC,EAAQ,QAAAC,CAAQ,KAAI,sBAAmB,EAC/DC,EAAQJ,GAAaC,EAErB,CAACI,EAAWC,CAAY,KAAI,YAA8B,CAAC,CAAC,EAC5D,CAACC,EAAOC,CAAQ,KAAI,YAAS,CAAC,EAE9B,CAAE,WAAYC,EAAW,QAAAC,CAAQ,KAAI,mBAQzC,CACA,IAAK,wBACL,SAAU,CACR,MAAON,EACP,QAAS,mBAAiB,IAAIF,CAAM,GAAKA,EACzC,SAAUC,CACZ,CACF,CAAC,EAEKQ,KAAe,eAAY,SAAY,CACtCZ,GAAS,SAGd,MAAMW,EACJ,CACE,aAAcZ,GAAe,kBAAgB,OAC7C,KAAAF,EACA,UAAWC,EACX,QAASE,GAAS,OACpB,EACA,CACE,UAAUa,EAAc,CACtBJ,EAASI,GAAc,MAAM,KAAK,EAClCN,EAAaM,GAAc,MAAM,aAAe,CAAC,CAAC,CACpD,CACF,CACF,CACF,EAAG,CAACd,EAAaF,EAAMC,EAAUE,GAAS,OAAO,CAAC,EAElD,sBAAU,IAAM,CACV,CAACK,GAAS,CAACL,GAAS,SAGxBY,EAAa,CACf,EAAG,CAACA,EAAcP,CAAK,CAAC,EAEjB,CACL,UAAAC,EACA,UAAAI,EACA,MAAAF,EACA,aAAAI,EACA,QAASJ,EAAQF,EAAU,QAAU,CAACI,CACxC,CACF,CAEA,IAAOrB,EAAQO",
|
|
6
|
+
"names": ["useMyRewards_exports", "__export", "useMyRewards_default", "__toCommonJS", "import_react", "import_const", "import_useAlpcFetch", "import_provider", "import_lib", "useMyRewards", "page", "pageSize", "consumeType", "profile", "alpcBrand", "headlessBrand", "locale", "appName", "brand", "myRewards", "setMyRewards", "total", "setTotal", "isLoading", "trigger", "getMyRewards", "responseData"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var c=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var M=(s,e)=>{for(var t in e)c(s,t,{get:e[t],enumerable:!0})},P=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of A(e))!x.call(s,o)&&o!==t&&c(s,o,{get:()=>e[o],enumerable:!(r=b(e,o))||r.enumerable});return s};var B=s=>P(c({},"__esModule",{value:!0}),s);var h={};M(h,{default:()=>U});module.exports=B(h);var n=require("react"),d=require("./useAlpcFetch"),C=require("../const"),f=require("../provider"),y=require("@anker-in/lib");function S(s){let e="";const{profile:t,isLoadingProfile:r,alpcBrand:o}=(0,f.useCreditsContext)(),{locale:l,brand:_}=(0,y.useHeadlessContext)(),u=o||_;l==="pl"?e="eu":e=l;const[g,T]=(0,n.useState)([]),{isMutating:R,trigger:m}=(0,d.useAlpcMutation)({url:"/v1/credit/consume_credit_rules",initData:{brand:u,page:1,page_size:999,country:(C.ALPC_COUNTRY_MAP.get(e)||e)?.toUpperCase()}}),i=(0,n.useCallback)(p=>{m({user_id:t?.user_id,...p?.consumeType&&{consume_type:p.consumeType}},{onSuccess(a){console.log("responseData",a);let L=a?.data?.consume_credit_rules||[];T(L)}})},[t,m,e]);return(0,n.useEffect)(()=>{!u||r||i({consumeType:s?.consumeType})},[i,r,u]),{listLoading:R,redeemableList:g,getRedeemableList:i}}var U=S;
|
|
2
2
|
//# sourceMappingURL=useRedeemableList.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useRedeemableList.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { useAlpcMutation } from './useAlpcFetch'\nimport { ALPC_COUNTRY_MAP, AlpcConsumeType } from '../const'\nimport { useCreditsContext } from '../provider'\nimport type { ConsumeCreditRuleResponse } from '../response'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useRedeemableList(props?: { consumeType: AlpcConsumeType }) {\n let locale = '' as string\n const { profile, isLoadingProfile, alpcBrand } = useCreditsContext()\n const { locale: contextLocale, brand: headlessBrand } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n\n if (contextLocale === 'pl') {\n locale = 'eu'\n } else {\n locale = contextLocale\n }\n\n const [redeemableList, setRedeemableList] = useState<ConsumeCreditRuleResponse[]>([])\n const { isMutating: listLoading, trigger } = useAlpcMutation<\n {\n data: { consume_credit_rules: ConsumeCreditRuleResponse[] }\n },\n { consume_type?: AlpcConsumeType; user_id?: string }\n >({\n url: `/v1/credit/consume_credit_rules`,\n initData: {\n brand,\n page: 1,\n page_size: 999,\n country: (ALPC_COUNTRY_MAP.get(locale) || locale)?.toUpperCase(),\n },\n })\n\n const getRedeemableList = useCallback(\n (props?: { consumeType?: AlpcConsumeType }) => {\n trigger(\n {\n user_id: profile?.user_id,\n ...(props?.consumeType && { consume_type: props.consumeType }),\n },\n {\n onSuccess(responseData) {\n console.log('responseData', responseData)\n
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiD,iBAEjDC,EAAgC,0BAChCC,EAAkD,oBAClDC,EAAkC,uBAElCC,EAAmC,yBAEnC,SAASC,EAAkBC,EAA0C,CACnE,IAAIC,EAAS,GACb,KAAM,CAAE,QAAAC,EAAS,iBAAAC,EAAkB,UAAAC,CAAU,KAAI,qBAAkB,EAC7D,CAAE,OAAQC,EAAe,MAAOC,CAAc,KAAI,sBAAmB,EACrEC,EAAQH,GAAaE,EAEvBD,IAAkB,KACpBJ,EAAS,KAETA,EAASI,EAGX,KAAM,CAACG,EAAgBC,CAAiB,KAAI,YAAsC,CAAC,CAAC,EAC9E,CAAE,WAAYC,EAAa,QAAAC,CAAQ,KAAI,mBAK3C,CACA,IAAK,kCACL,SAAU,CACR,MAAAJ,EACA,KAAM,EACN,UAAW,IACX,SAAU,mBAAiB,IAAIN,CAAM,GAAKA,IAAS,YAAY,CACjE,CACF,CAAC,EAEKW,KAAoB,eACvBZ,GAA8C,CAC7CW,EACE,CACE,QAAST,GAAS,QAClB,GAAIF,GAAO,aAAe,CAAE,aAAcA,EAAM,WAAY,CAC9D,EACA,CACE,UAAUa,EAAc,CACtB,QAAQ,IAAI,eAAgBA,CAAY,
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { useAlpcMutation } from './useAlpcFetch'\nimport { ALPC_COUNTRY_MAP, AlpcConsumeType } from '../const'\nimport { useCreditsContext } from '../provider'\nimport type { ConsumeCreditRuleResponse } from '../response'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useRedeemableList(props?: { consumeType: AlpcConsumeType }) {\n let locale = '' as string\n const { profile, isLoadingProfile, alpcBrand } = useCreditsContext()\n const { locale: contextLocale, brand: headlessBrand } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n\n if (contextLocale === 'pl') {\n locale = 'eu'\n } else {\n locale = contextLocale\n }\n\n const [redeemableList, setRedeemableList] = useState<ConsumeCreditRuleResponse[]>([])\n const { isMutating: listLoading, trigger } = useAlpcMutation<\n {\n data: { consume_credit_rules: ConsumeCreditRuleResponse[] }\n },\n { consume_type?: AlpcConsumeType; user_id?: string }\n >({\n url: `/v1/credit/consume_credit_rules`,\n initData: {\n brand,\n page: 1,\n page_size: 999,\n country: (ALPC_COUNTRY_MAP.get(locale) || locale)?.toUpperCase(),\n },\n })\n\n const getRedeemableList = useCallback(\n (props?: { consumeType?: AlpcConsumeType }) => {\n trigger(\n {\n user_id: profile?.user_id,\n ...(props?.consumeType && { consume_type: props.consumeType }),\n },\n {\n onSuccess(responseData) {\n console.log('responseData', responseData)\n let list = responseData?.data?.consume_credit_rules || []\n setRedeemableList(list)\n },\n }\n )\n },\n [profile, trigger, locale]\n )\n\n useEffect(() => {\n if (!brand || isLoadingProfile) {\n return\n }\n getRedeemableList({ consumeType: props?.consumeType })\n }, [getRedeemableList, isLoadingProfile, brand])\n\n return {\n listLoading,\n redeemableList,\n getRedeemableList,\n }\n}\n\nexport default useRedeemableList\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiD,iBAEjDC,EAAgC,0BAChCC,EAAkD,oBAClDC,EAAkC,uBAElCC,EAAmC,yBAEnC,SAASC,EAAkBC,EAA0C,CACnE,IAAIC,EAAS,GACb,KAAM,CAAE,QAAAC,EAAS,iBAAAC,EAAkB,UAAAC,CAAU,KAAI,qBAAkB,EAC7D,CAAE,OAAQC,EAAe,MAAOC,CAAc,KAAI,sBAAmB,EACrEC,EAAQH,GAAaE,EAEvBD,IAAkB,KACpBJ,EAAS,KAETA,EAASI,EAGX,KAAM,CAACG,EAAgBC,CAAiB,KAAI,YAAsC,CAAC,CAAC,EAC9E,CAAE,WAAYC,EAAa,QAAAC,CAAQ,KAAI,mBAK3C,CACA,IAAK,kCACL,SAAU,CACR,MAAAJ,EACA,KAAM,EACN,UAAW,IACX,SAAU,mBAAiB,IAAIN,CAAM,GAAKA,IAAS,YAAY,CACjE,CACF,CAAC,EAEKW,KAAoB,eACvBZ,GAA8C,CAC7CW,EACE,CACE,QAAST,GAAS,QAClB,GAAIF,GAAO,aAAe,CAAE,aAAcA,EAAM,WAAY,CAC9D,EACA,CACE,UAAUa,EAAc,CACtB,QAAQ,IAAI,eAAgBA,CAAY,EACxC,IAAIC,EAAOD,GAAc,MAAM,sBAAwB,CAAC,EACxDJ,EAAkBK,CAAI,CACxB,CACF,CACF,CACF,EACA,CAACZ,EAASS,EAASV,CAAM,CAC3B,EAEA,sBAAU,IAAM,CACV,CAACM,GAASJ,GAGdS,EAAkB,CAAE,YAAaZ,GAAO,WAAY,CAAC,CACvD,EAAG,CAACY,EAAmBT,EAAkBI,CAAK,CAAC,EAExC,CACL,YAAAG,EACA,eAAAF,EACA,kBAAAI,CACF,CACF,CAEA,IAAOpB,EAAQO",
|
|
6
6
|
"names": ["useRedeemableList_exports", "__export", "useRedeemableList_default", "__toCommonJS", "import_react", "import_useAlpcFetch", "import_const", "import_provider", "import_lib", "useRedeemableList", "props", "locale", "profile", "isLoadingProfile", "alpcBrand", "contextLocale", "headlessBrand", "brand", "redeemableList", "setRedeemableList", "listLoading", "trigger", "getRedeemableList", "responseData", "list"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.create;var d=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var f=(t,e)=>{for(var r in e)d(t,r,{get:e[r],enumerable:!0})},i=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of m(e))!_.call(t,a)&&a!==r&&d(t,a,{get:()=>e[a],enumerable:!(o=p(e,a))||o.enumerable});return t};var g=(t,e,r)=>(r=t!=null?l(y(t)):{},i(e||!t||!t.__esModule?d(r,"default",{value:t,enumerable:!0}):r,t)),h=t=>i(d({},"__esModule",{value:!0}),t);var k={};f(k,{useUploadReceipt:()=>b});module.exports=h(k);var c=g(require("swr/mutation")),s=require("@anker-in/lib");const R=t=>t&&(t.data&&typeof t.data=="object"&&!Array.isArray(t.data)?t.data:t),b=()=>{const{locale:t}=(0,s.useHeadlessContext)();return(0,c.default)("/api/multipass/mktsrv/v1/credit/upload_third_party_order",async(r,{arg:{orderName:o}})=>{const u=await(await fetch("/api/multipass/mktsrv/v1/credit/upload_third_party_order",{credentials:"include",method:"POST",headers:{"Content-Type":"application/json","current-language":t},body:JSON.stringify({order_name:o})})).json(),n=R(u);return{ok:n?.data?.code===0,code:n?.data?.code??-1}})};
|
|
2
2
|
//# sourceMappingURL=useUploadReceipt.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useUploadReceipt.tsx"],
|
|
4
|
-
"sourcesContent": ["import useSWRMutation from 'swr/mutation'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nexport const useUploadReceipt = () => {\n const { locale } = useHeadlessContext()\n\n const uploadReceipt = async (\n _: any,\n { arg: { orderName } }: { arg: { orderName: string } }\n ): Promise<{\n ok: boolean\n code: number\n }> => {\n const response = await fetch(`/api/multipass/mktsrv/v1/credit/upload_third_party_order`, {\n credentials: 'include',\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'current-language': locale,\n },\n body: JSON.stringify({\n order_name: orderName,\n }),\n })\n const result = await response.json()\n const
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA2B,2BAC3BC,EAAmC,
|
|
6
|
-
"names": ["useUploadReceipt_exports", "__export", "useUploadReceipt", "__toCommonJS", "import_mutation", "import_lib", "locale", "useSWRMutation", "_", "orderName", "result", "
|
|
4
|
+
"sourcesContent": ["import useSWRMutation from 'swr/mutation'\nimport { useHeadlessContext } from '@anker-in/lib'\n\n/**\n * \u7EDF\u4E00\u5904\u7406 ALPC \u63A5\u53E3\u8FD4\u56DE\u7684\u6570\u636E\u7ED3\u6784\n * \u517C\u5BB9\u4E00\u5C42 data \u548C\u4E24\u5C42 data \u7684\u573A\u666F\n */\nconst normalizeResponseData = (responseData: any) => {\n if (!responseData) return responseData\n\n // \u5982\u679C responseData.data \u5B58\u5728\u4E14\u662F\u4E00\u4E2A\u5BF9\u8C61\uFF08\u4E0D\u662F\u6570\u7EC4\uFF09\uFF0C\u8BF4\u660E\u662F\u4E24\u5C42 data \u7ED3\u6784\n if (responseData.data && typeof responseData.data === 'object' && !Array.isArray(responseData.data)) {\n return responseData.data\n }\n\n // \u4E00\u5C42 data \u7ED3\u6784\u6216\u5176\u4ED6\u60C5\u51B5\uFF0C\u76F4\u63A5\u8FD4\u56DE\n return responseData\n}\n\nexport const useUploadReceipt = () => {\n const { locale } = useHeadlessContext()\n\n const uploadReceipt = async (\n _: any,\n { arg: { orderName } }: { arg: { orderName: string } }\n ): Promise<{\n ok: boolean\n code: number\n }> => {\n const response = await fetch(`/api/multipass/mktsrv/v1/credit/upload_third_party_order`, {\n credentials: 'include',\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'current-language': locale,\n },\n body: JSON.stringify({\n order_name: orderName,\n }),\n })\n const result = await response.json()\n const normalizedData = normalizeResponseData(result)\n return {\n ok: normalizedData?.data?.code === 0,\n code: normalizedData?.data?.code ?? -1,\n }\n }\n\n return useSWRMutation('/api/multipass/mktsrv/v1/credit/upload_third_party_order', uploadReceipt)\n}\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA2B,2BAC3BC,EAAmC,yBAMnC,MAAMC,EAAyBC,GACxBA,IAGDA,EAAa,MAAQ,OAAOA,EAAa,MAAS,UAAY,CAAC,MAAM,QAAQA,EAAa,IAAI,EACzFA,EAAa,KAIfA,GAGIL,EAAmB,IAAM,CACpC,KAAM,CAAE,OAAAM,CAAO,KAAI,sBAAmB,EA4BtC,SAAO,EAAAC,SAAe,2DA1BA,MACpBC,EACA,CAAE,IAAK,CAAE,UAAAC,CAAU,CAAE,IAIjB,CAYJ,MAAMC,EAAS,MAXE,MAAM,MAAM,2DAA4D,CACvF,YAAa,UACb,OAAQ,OACR,QAAS,CACP,eAAgB,mBAChB,mBAAoBJ,CACtB,EACA,KAAM,KAAK,UAAU,CACnB,WAAYG,CACd,CAAC,CACH,CAAC,GAC6B,KAAK,EAC7BE,EAAiBP,EAAsBM,CAAM,EACnD,MAAO,CACL,GAAIC,GAAgB,MAAM,OAAS,EACnC,KAAMA,GAAgB,MAAM,MAAQ,EACtC,CACF,CAE+F,CACjG",
|
|
6
|
+
"names": ["useUploadReceipt_exports", "__export", "useUploadReceipt", "__toCommonJS", "import_mutation", "import_lib", "normalizeResponseData", "responseData", "locale", "useSWRMutation", "_", "orderName", "result", "normalizedData"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useCallback as
|
|
1
|
+
import{useCallback as _,useEffect as x,useState as o}from"react";import{useAlpcMutation as A}from"./useAlpcFetch";import{useCreditsContext as y}from"../provider";import{useHeadlessContext as P}from"@anker-in/lib";function R({page:t,pageSize:n,options:a={}}){const{profile:e,isLoadingProfile:c,alpcBrand:p}=y(),{brand:f}=P(),r=p||f,[s,b]=o([]),[u,C]=o(0),[d,L]=o(0),{isMutating:i,trigger:g}=A({url:"/v1/credit/log",initData:{brand:r}}),l=_(async()=>{const v={page:t,page_size:n,user_id:e?.user_id,...a};g(v,{onSuccess(m){L(t),C(m?.data?.total),b(s.concat(m?.data?.creditLogs||[]))}})},[s,e,t,n,a,g]);return x(()=>{c||!e||!r||i||t!==d&&t&&l()},[l,c,i,e,r,t,d]),{activities:s,isLoading:i,total:u,canNext:u>s.length&&!i}}var S=R;export{S as default};
|
|
2
2
|
//# sourceMappingURL=useActivities.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useActivities.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { CreditLogResponse } from '../response'\nimport { useCreditsContext } from '../provider'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useActivities({ page, pageSize, options = {} }: { page: number; pageSize: number; options?: any }) {\n const { profile, isLoadingProfile, alpcBrand } = useCreditsContext()\n const { brand: headlessBrand } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n const [activities, setActivities] = useState<CreditLogResponse[]>([])\n const [total, setTotal] = useState(0)\n\n const [currentPage, setCurrentPage] = useState(0)\n\n const { isMutating: isLoading, trigger } = useAlpcMutation<\n {\n data: {\n total: number\n creditLogs: CreditLogResponse[]\n }\n },\n {\n page: number\n page_size: number\n user_id: string\n }\n >({\n url: `/v1/credit/log`,\n initData: {\n brand,\n },\n })\n\n const getActivities = useCallback(async () => {\n const params = {\n page: page,\n page_size: pageSize,\n user_id: profile?.user_id,\n ...options,\n }\n\n trigger(params, {\n onSuccess(responseData) {\n setCurrentPage(page)\n
|
|
5
|
-
"mappings": "AAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QAEjD,OAAS,mBAAAC,MAAuB,iBAEhC,OAAS,qBAAAC,MAAyB,cAClC,OAAS,sBAAAC,MAA0B,gBAEnC,SAASC,EAAc,CAAE,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAU,CAAC,CAAE,EAAsD,CAC1G,KAAM,CAAE,QAAAC,EAAS,iBAAAC,EAAkB,UAAAC,CAAU,EAAIR,EAAkB,EAC7D,CAAE,MAAOS,CAAc,EAAIR,EAAmB,EAC9CS,EAAQF,GAAaC,EACrB,CAACE,EAAYC,CAAa,EAAId,EAA8B,CAAC,CAAC,EAC9D,CAACe,EAAOC,CAAQ,EAAIhB,EAAS,CAAC,EAE9B,CAACiB,EAAaC,CAAc,EAAIlB,EAAS,CAAC,EAE1C,CAAE,WAAYmB,EAAW,QAAAC,CAAQ,EAAInB,EAYzC,CACA,IAAK,iBACL,SAAU,CACR,MAAAW,CACF,CACF,CAAC,EAEKS,EAAgBvB,EAAY,SAAY,CAC5C,MAAMwB,EAAS,CACb,KAAMjB,EACN,UAAWC,EACX,QAASE,GAAS,QAClB,GAAGD,CACL,EAEAa,EAAQE,EAAQ,CACd,UAAUC,EAAc,CACtBL,EAAeb,CAAI,
|
|
6
|
-
"names": ["useCallback", "useEffect", "useState", "useAlpcMutation", "useCreditsContext", "useHeadlessContext", "useActivities", "page", "pageSize", "options", "profile", "isLoadingProfile", "alpcBrand", "headlessBrand", "brand", "activities", "setActivities", "total", "setTotal", "currentPage", "setCurrentPage", "isLoading", "trigger", "getActivities", "params", "responseData", "
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { CreditLogResponse } from '../response'\nimport { useCreditsContext } from '../provider'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useActivities({ page, pageSize, options = {} }: { page: number; pageSize: number; options?: any }) {\n const { profile, isLoadingProfile, alpcBrand } = useCreditsContext()\n const { brand: headlessBrand } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n const [activities, setActivities] = useState<CreditLogResponse[]>([])\n const [total, setTotal] = useState(0)\n\n const [currentPage, setCurrentPage] = useState(0)\n\n const { isMutating: isLoading, trigger } = useAlpcMutation<\n {\n data: {\n total: number\n creditLogs: CreditLogResponse[]\n }\n },\n {\n page: number\n page_size: number\n user_id: string\n }\n >({\n url: `/v1/credit/log`,\n initData: {\n brand,\n },\n })\n\n const getActivities = useCallback(async () => {\n const params = {\n page: page,\n page_size: pageSize,\n user_id: profile?.user_id,\n ...options,\n }\n\n trigger(params, {\n onSuccess(responseData) {\n setCurrentPage(page)\n setTotal(responseData?.data?.total)\n setActivities(activities.concat(responseData?.data?.creditLogs || []))\n },\n })\n }, [activities, profile, page, pageSize, options, trigger])\n\n useEffect(() => {\n if (isLoadingProfile || !profile || !brand || isLoading) {\n return\n }\n\n if (page !== currentPage && page) {\n getActivities()\n }\n }, [getActivities, isLoadingProfile, isLoading, profile, brand, page, currentPage])\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,QAEjD,OAAS,mBAAAC,MAAuB,iBAEhC,OAAS,qBAAAC,MAAyB,cAClC,OAAS,sBAAAC,MAA0B,gBAEnC,SAASC,EAAc,CAAE,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAU,CAAC,CAAE,EAAsD,CAC1G,KAAM,CAAE,QAAAC,EAAS,iBAAAC,EAAkB,UAAAC,CAAU,EAAIR,EAAkB,EAC7D,CAAE,MAAOS,CAAc,EAAIR,EAAmB,EAC9CS,EAAQF,GAAaC,EACrB,CAACE,EAAYC,CAAa,EAAId,EAA8B,CAAC,CAAC,EAC9D,CAACe,EAAOC,CAAQ,EAAIhB,EAAS,CAAC,EAE9B,CAACiB,EAAaC,CAAc,EAAIlB,EAAS,CAAC,EAE1C,CAAE,WAAYmB,EAAW,QAAAC,CAAQ,EAAInB,EAYzC,CACA,IAAK,iBACL,SAAU,CACR,MAAAW,CACF,CACF,CAAC,EAEKS,EAAgBvB,EAAY,SAAY,CAC5C,MAAMwB,EAAS,CACb,KAAMjB,EACN,UAAWC,EACX,QAASE,GAAS,QAClB,GAAGD,CACL,EAEAa,EAAQE,EAAQ,CACd,UAAUC,EAAc,CACtBL,EAAeb,CAAI,EACnBW,EAASO,GAAc,MAAM,KAAK,EAClCT,EAAcD,EAAW,OAAOU,GAAc,MAAM,YAAc,CAAC,CAAC,CAAC,CACvE,CACF,CAAC,CACH,EAAG,CAACV,EAAYL,EAASH,EAAMC,EAAUC,EAASa,CAAO,CAAC,EAE1D,OAAArB,EAAU,IAAM,CACVU,GAAoB,CAACD,GAAW,CAACI,GAASO,GAI1Cd,IAASY,GAAeZ,GAC1BgB,EAAc,CAElB,EAAG,CAACA,EAAeZ,EAAkBU,EAAWX,EAASI,EAAOP,EAAMY,CAAW,CAAC,EAE3E,CACL,WAAAJ,EACA,UAAAM,EACA,MAAAJ,EACA,QAASA,EAAQF,EAAW,QAAU,CAACM,CACzC,CACF,CAEA,IAAOK,EAAQpB",
|
|
6
|
+
"names": ["useCallback", "useEffect", "useState", "useAlpcMutation", "useCreditsContext", "useHeadlessContext", "useActivities", "page", "pageSize", "options", "profile", "isLoadingProfile", "alpcBrand", "headlessBrand", "brand", "activities", "setActivities", "total", "setTotal", "currentPage", "setCurrentPage", "isLoading", "trigger", "getActivities", "params", "responseData", "useActivities_default"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import D from"js-cookie";import{useCallback as E,useRef as m,useState as O}from"react";import F from"swr";import{useHeadlessContext as B}from"@anker-in/lib";import{getAlpcPath as A}from"../utils";import{useCreditsContext as w}from"../provider";let b;const U=t=>t&&(t.data&&typeof t.data=="object"&&!Array.isArray(t.data)?t.data:t),M=t=>fetch(A(t.locale,t.apiBaseUrl)+t.url,t.fetchOptions).then(async a=>{if(a.status<300){const n=await a.json();return U(n)}if(a.status===401&&t.onReAuth){b||(b=t.onReAuth());const n=await b;if(b=void 0,n)return fetch(A(t.locale,t.apiBaseUrl)+t.url,t.fetchOptions).then(async r=>{if(r.status<300){const e=await r.json();return U(e)}if(r.status===401){t.onUnAuth&&t.onUnAuth();return}});t.onUnAuth&&t.onUnAuth();return}}),S=async(t,a,n,r)=>{let e=await fetch(`${A(t,r)}/cloud/login`,{method:"POST"}),s=await e.json(),o=U(s);if(e.status<300&&!a&&o?.code===27004){const i=D.get("alpcEU");if(Number(i)===1?D.set("alpcEU","0",{expires:30,domain:`.${n}.com`}):D.set("alpcEU","1",{expires:30,domain:`.${n}.com`}),e=await fetch(`${A(t,r)}/cloud/login`,{method:"POST"}),s=await e.json(),o=U(s),e.status>300)return!1}return!o?.code},q=(t,a,n={},r)=>{const e=m(!1),[s,o]=O(),[i,f]=O(!1),c=m(t),l=m(a),d=m(n),h=E(async(g,T={})=>{if(console.log("[useAlpcMutation] trigger called with:",{url:c.current,fetchData:g,brand:r.current}),e.current){console.log("[useAlpcMutation] already mutating, skipping");return}if(!r.current){console.log("[useAlpcMutation] brand not available, skipping request");return}e.current=!0,f(!0);const y={...d.current,...T},{onSuccess:R,onError:p}=y||{};try{const u=await l.current(c.current,{arg:g});return o(u),f(!1),e.current=!1,R&&R(u),u}catch(u){f(!1),e.current=!1,p&&p(u)}},[]);return{isMutating:i,trigger:h,data:s}},z=(t,a)=>{const[n,r]=O(!1),{removeProfile:e,alpcBrand:s,apiBaseUrl:o}=w(),{enable:i,...f}=a||{},{locale:c="",brand:l}=B(),d=s||l,{queryKey:h=[],body:g={},headers:T,...y}=t,R=i??!0,[p,u]=h;return F([p,u],!R||!d?null:([C,P])=>M({url:C,locale:c,apiBaseUrl:o,fetchOptions:{method:"POST",headers:{"current-language":c,...T},body:JSON.stringify({...g,...P}),...y},onReAuth:async()=>await S(c,n,d,o)?(r(!0),!0):!1,onUnAuth(){e()}}),{revalidateOnFocus:!1,...f})},J=(t,a)=>{const[n,r]=O(!1),{removeProfile:e,alpcBrand:s,apiBaseUrl:o}=w(),{locale:i="",brand:f}=B(),c=s||f,l=m(c);l.current=c;const{url:d,initData:h,headers:g,...T}=t,y=m(h);return y.current=h,q(d,(p,u)=>l.current?M({url:p,locale:i,apiBaseUrl:o,fetchOptions:{method:"POST",headers:{"current-language":i,...g},...T,body:JSON.stringify({...y.current,...u.arg})},onReAuth:async()=>await S(i,n,l.current,o)?(r(!0),!0):!1,onUnAuth(){e()}}):Promise.resolve(void 0),a,l)};export{z as useAlpcFetch,J as useAlpcMutation};
|
|
2
2
|
//# sourceMappingURL=useAlpcFetch.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useAlpcFetch.ts"],
|
|
4
|
-
"sourcesContent": ["import Cookies from 'js-cookie'\nimport { useCallback, useRef, useState } from 'react'\nimport useSWR, { type SWRConfiguration } from 'swr'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nimport { getAlpcPath } from '../utils'\nimport { useCreditsContext } from '../provider'\n\ninterface UseAlpcFetchOptionsSwrOptions<TData, Error> extends SWRConfiguration<TData, Error> {\n enable?: boolean\n}\n\ninterface FetchOptions extends RequestInit {\n queryKey: [string, Record<string, any>]\n data?: Record<string, any>\n}\n\ninterface MutationOptions extends RequestInit {\n url: string\n initData: Record<string, any>\n}\n\ninterface FetcherOptions {\n url: string\n locale: string\n fetchOptions: RequestInit\n onReAuth: () => Promise<boolean>\n onUnAuth: () => void\n apiBaseUrl?: string\n}\n\nlet reAuthPromise: Promise<boolean> | undefined\n\ntype Fetcher<TData, TBody> = (url: string, data: { arg: TBody }) => Promise<TData>\n\nconst fetcher = (options: FetcherOptions) => {\n return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, options.fetchOptions).then(async response => {\n if (response.status < 300) {\n const responseData = await response.json()\n return responseData\n }\n\n // \u9519\u8BEF\u5904\u7406\n if (response.status === 401) {\n // \u91CD\u65B0\u767B\u5F55\u5C1D\u8BD5\n if (options.onReAuth) {\n if (!reAuthPromise) {\n reAuthPromise = options.onReAuth()\n }\n\n const result = await reAuthPromise\n\n reAuthPromise = undefined\n\n if (result) {\n // \u8DE8\u533A\u91CD\u65B0\u767B\u5F55\u540E\u9700\u8981\u66FF\u6362\u533A\u57DF\u6807\u5FD7\uFF0C\u6240\u4EE5\u4E0D\u80FD\u7528\u6700\u5F00\u59CB\u8BF7\u6C42\u7684\u90A3\u4E2A\u94FE\u63A5\n return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, options.fetchOptions).then(async response => {\n if (response.status < 300) {\n const responseData = await response.json()\n return responseData\n }\n\n if (response.status === 401) {\n if (options.onUnAuth) {\n options.onUnAuth()\n }\n return\n }\n })\n } else {\n if (options.onUnAuth) {\n options.onUnAuth()\n }\n return\n }\n }\n }\n })\n}\n\nconst reAuth = async (locale: string, retry: boolean, brand: string, apiBaseUrl?: string) => {\n let reloginResponse = await fetch(`${getAlpcPath(locale, apiBaseUrl)}/cloud/login`, {\n method: 'POST',\n })\n let reloginResponseData = await reloginResponse.json()\n\n if (reloginResponse!.status < 300 && !retry) {\n if (reloginResponseData?.data?.code === 27004) {\n // \u8DE8\u533A\u767B\u5F55\u9519\u8BEF\n const alpcEUCookie = Cookies.get('alpcEU')\n\n if (Number(alpcEUCookie) === 1) {\n Cookies.set('alpcEU', '0', {\n expires: 30,\n domain: `.${brand}.com`,\n })\n } else {\n Cookies.set('alpcEU', '1', {\n expires: 30,\n domain: `.${brand}.com`,\n })\n }\n\n // \u91CD\u65B0\u5C1D\u8BD5\u6362\u533A\u767B\u5F55\n reloginResponse = await fetch(`${getAlpcPath(locale, apiBaseUrl)}/cloud/login`, {\n method: 'POST',\n })\n reloginResponseData = await reloginResponse.json()\n\n if (reloginResponse.status > 300) {\n return false\n }\n }\n }\n if (!reloginResponseData?.data?.code) {\n // \u91CD\u65B0\u767B\u5F55\u6210\u529F\n return true\n }\n\n return false\n}\n\nexport interface UseMutationConfig<TData> {\n onSuccess?: (response: TData) => any\n onError?: (error: Error) => any\n}\n\nconst useMutation = <TData, TBody>(\n url: string,\n fetcher: Fetcher<TData, TBody>,\n mutationConfig: UseMutationConfig<TData> = {},\n brandRef: React.MutableRefObject<string | undefined>\n) => {\n const innerMutating = useRef<boolean>(false)\n\n const [data, setData] = useState<TData>()\n const [isMutating, setIsMutating] = useState(false)\n\n const urlRef = useRef(url)\n const fetcherRef = useRef(fetcher)\n const configRef = useRef(mutationConfig)\n\n const trigger = useCallback(\n async (fetchData: TBody, opts: UseMutationConfig<TData> = {}) => {\n console.log('[useAlpcMutation] trigger called with:', { url: urlRef.current, fetchData, brand: brandRef.current })\n\n if (innerMutating.current) {\n console.log('[useAlpcMutation] already mutating, skipping')\n return\n }\n\n if (!brandRef.current) {\n console.log('[useAlpcMutation] brand not available, skipping request')\n return\n }\n\n innerMutating.current = true\n setIsMutating(true)\n\n const config = {\n ...configRef.current,\n ...opts,\n }\n\n const { onSuccess, onError } = config || {}\n\n try {\n const fetchResult = await fetcherRef.current(urlRef.current, {\n arg: fetchData,\n })\n setData(fetchResult)\n\n setIsMutating(false)\n innerMutating.current = false\n\n if (onSuccess) {\n onSuccess(fetchResult)\n }\n return fetchResult\n } catch (err: any) {\n setIsMutating(false)\n innerMutating.current = false\n\n if (onError) {\n onError(err)\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n []\n )\n\n return {\n isMutating,\n trigger,\n data,\n }\n}\n\nexport const useAlpcFetch = <TData>(\n options: FetchOptions,\n swrOptions?: UseAlpcFetchOptionsSwrOptions<TData, Error>\n) => {\n const [retry, setRetry] = useState(false)\n const { removeProfile, alpcBrand, apiBaseUrl } = useCreditsContext()\n\n const { enable, ...otherSwrOptions } = swrOptions || {}\n\n const { locale = '', brand: headlessBrand } = useHeadlessContext()\n // \u4F18\u5148\u4F7F\u7528 creditsContext \u4E2D\u7684 alpcBrand\uFF0C\u5982\u679C\u6CA1\u6709\u5219\u4F7F\u7528 headlessConfig \u4E2D\u7684 brand\n const brand = alpcBrand || headlessBrand\n\n const { queryKey = [], body: fetchBody = {}, headers, ...fetchOptions } = options\n const fetchEnable = enable ?? true\n\n const [url, requestBody] = queryKey\n\n const context = useSWR<TData>(\n [url, requestBody],\n !fetchEnable || !brand\n ? null\n : ([requestUrl, data]: [string, Record<string, any>]) =>\n fetcher({\n url: requestUrl,\n locale,\n apiBaseUrl,\n fetchOptions: {\n method: 'POST',\n headers: {\n 'current-language': locale,\n ...headers,\n },\n body: JSON.stringify({\n ...fetchBody,\n ...data,\n }),\n ...fetchOptions,\n },\n onReAuth: async () => {\n const result = await reAuth(locale, retry, brand, apiBaseUrl)\n\n if (result) {\n setRetry(true)\n return true\n }\n\n return false\n },\n onUnAuth() {\n // \u5931\u8D25\u540E\u9000\u51FA\u767B\u5F55\n removeProfile()\n },\n }),\n {\n revalidateOnFocus: false,\n ...otherSwrOptions,\n }\n )\n\n return context\n}\n\nexport const useAlpcMutation = <TData, TBody>(options: MutationOptions, mutationOptions?: UseMutationConfig<TData>) => {\n const [retry, setRetry] = useState(false)\n const { removeProfile, alpcBrand, apiBaseUrl } = useCreditsContext()\n\n const { locale = '', brand: headlessBrand } = useHeadlessContext()\n // \u4F18\u5148\u4F7F\u7528 creditsContext \u4E2D\u7684 alpcBrand\uFF0C\u5982\u679C\u6CA1\u6709\u5219\u4F7F\u7528 headlessConfig \u4E2D\u7684 brand\n const brand = alpcBrand || headlessBrand\n const brandRef = useRef(brand)\n brandRef.current = brand\n\n const { url, initData, headers, ...fetchOptions } = options\n const initDataRef = useRef(initData)\n initDataRef.current = initData\n\n const context = useMutation<TData, TBody>(\n url,\n (requestUrl, data: { arg: TBody }) => {\n // Prevent requests when brand is not available\n if (!brandRef.current) {\n return Promise.resolve(undefined as unknown as TData)\n }\n\n return fetcher({\n url: requestUrl,\n locale,\n apiBaseUrl,\n fetchOptions: {\n method: 'POST',\n headers: {\n 'current-language': locale,\n ...headers,\n },\n ...fetchOptions,\n body: JSON.stringify({\n ...initDataRef.current,\n ...data.arg,\n }),\n },\n onReAuth: async () => {\n const result = await reAuth(locale, retry, brandRef.current!, apiBaseUrl)\n\n if (result) {\n setRetry(true)\n return true\n }\n\n return false\n },\n onUnAuth() {\n // \u5931\u8D25\u540E\u9000\u51FA\u767B\u5F55\n removeProfile()\n },\n })\n },\n mutationOptions,\n brandRef\n )\n\n return context\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAOA,MAAa,YACpB,OAAS,eAAAC,EAAa,UAAAC,EAAQ,YAAAC,MAAgB,QAC9C,OAAOC,MAAuC,MAC9C,OAAS,sBAAAC,MAA0B,gBAEnC,OAAS,eAAAC,MAAmB,WAC5B,OAAS,qBAAAC,MAAyB,cAyBlC,IAAIC,
|
|
6
|
-
"names": ["Cookies", "useCallback", "useRef", "useState", "useSWR", "useHeadlessContext", "getAlpcPath", "useCreditsContext", "reAuthPromise", "fetcher", "options", "response", "result", "reAuth", "locale", "retry", "brand", "apiBaseUrl", "reloginResponse", "reloginResponseData", "alpcEUCookie", "useMutation", "url", "mutationConfig", "brandRef", "innerMutating", "data", "setData", "isMutating", "setIsMutating", "urlRef", "fetcherRef", "configRef", "trigger", "fetchData", "opts", "config", "onSuccess", "onError", "fetchResult", "err", "useAlpcFetch", "swrOptions", "setRetry", "removeProfile", "alpcBrand", "enable", "otherSwrOptions", "headlessBrand", "queryKey", "fetchBody", "headers", "fetchOptions", "fetchEnable", "requestBody", "requestUrl", "useAlpcMutation", "mutationOptions", "initData", "initDataRef"]
|
|
4
|
+
"sourcesContent": ["import Cookies from 'js-cookie'\nimport { useCallback, useRef, useState } from 'react'\nimport useSWR, { type SWRConfiguration } from 'swr'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nimport { getAlpcPath } from '../utils'\nimport { useCreditsContext } from '../provider'\n\ninterface UseAlpcFetchOptionsSwrOptions<TData, Error> extends SWRConfiguration<TData, Error> {\n enable?: boolean\n}\n\ninterface FetchOptions extends RequestInit {\n queryKey: [string, Record<string, any>]\n data?: Record<string, any>\n}\n\ninterface MutationOptions extends RequestInit {\n url: string\n initData: Record<string, any>\n}\n\ninterface FetcherOptions {\n url: string\n locale: string\n fetchOptions: RequestInit\n onReAuth: () => Promise<boolean>\n onUnAuth: () => void\n apiBaseUrl?: string\n}\n\nlet reAuthPromise: Promise<boolean> | undefined\n\ntype Fetcher<TData, TBody> = (url: string, data: { arg: TBody }) => Promise<TData>\n\n/**\n * \u7EDF\u4E00\u5904\u7406 ALPC \u63A5\u53E3\u8FD4\u56DE\u7684\u6570\u636E\u7ED3\u6784\n * \u517C\u5BB9\u4E00\u5C42 data \u548C\u4E24\u5C42 data \u7684\u573A\u666F\uFF1A\n * - \u4E24\u5C42 data: {data: {data: ..., code: 27004}}\n * - \u4E00\u5C42 data: {data: ..., code: 27004}\n */\nconst normalizeResponseData = (responseData: any) => {\n if (!responseData) return responseData\n\n // \u5982\u679C responseData.data \u5B58\u5728\u4E14\u662F\u4E00\u4E2A\u5BF9\u8C61\uFF08\u4E0D\u662F\u6570\u7EC4\uFF09\uFF0C\u8BF4\u660E\u662F\u4E24\u5C42 data \u7ED3\u6784\n if (responseData.data && typeof responseData.data === 'object' && !Array.isArray(responseData.data)) {\n return responseData.data\n }\n\n // \u4E00\u5C42 data \u7ED3\u6784\u6216\u5176\u4ED6\u60C5\u51B5\uFF0C\u76F4\u63A5\u8FD4\u56DE\n return responseData\n}\n\nconst fetcher = (options: FetcherOptions) => {\n return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, options.fetchOptions).then(async response => {\n if (response.status < 300) {\n const responseData = await response.json()\n return normalizeResponseData(responseData)\n }\n\n // \u9519\u8BEF\u5904\u7406\n if (response.status === 401) {\n // \u91CD\u65B0\u767B\u5F55\u5C1D\u8BD5\n if (options.onReAuth) {\n if (!reAuthPromise) {\n reAuthPromise = options.onReAuth()\n }\n\n const result = await reAuthPromise\n\n reAuthPromise = undefined\n\n if (result) {\n // \u8DE8\u533A\u91CD\u65B0\u767B\u5F55\u540E\u9700\u8981\u66FF\u6362\u533A\u57DF\u6807\u5FD7\uFF0C\u6240\u4EE5\u4E0D\u80FD\u7528\u6700\u5F00\u59CB\u8BF7\u6C42\u7684\u90A3\u4E2A\u94FE\u63A5\n return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, options.fetchOptions).then(async response => {\n if (response.status < 300) {\n const responseData = await response.json()\n return normalizeResponseData(responseData)\n }\n\n if (response.status === 401) {\n if (options.onUnAuth) {\n options.onUnAuth()\n }\n return\n }\n })\n } else {\n if (options.onUnAuth) {\n options.onUnAuth()\n }\n return\n }\n }\n }\n })\n}\n\nconst reAuth = async (locale: string, retry: boolean, brand: string, apiBaseUrl?: string) => {\n let reloginResponse = await fetch(`${getAlpcPath(locale, apiBaseUrl)}/cloud/login`, {\n method: 'POST',\n })\n let reloginResponseData = await reloginResponse.json()\n // \u517C\u5BB9\u4E24\u5C42 data \u7ED3\u6784\n let normalizedData = normalizeResponseData(reloginResponseData)\n\n if (reloginResponse!.status < 300 && !retry) {\n if (normalizedData?.code === 27004) {\n // \u8DE8\u533A\u767B\u5F55\u9519\u8BEF\n const alpcEUCookie = Cookies.get('alpcEU')\n\n if (Number(alpcEUCookie) === 1) {\n Cookies.set('alpcEU', '0', {\n expires: 30,\n domain: `.${brand}.com`,\n })\n } else {\n Cookies.set('alpcEU', '1', {\n expires: 30,\n domain: `.${brand}.com`,\n })\n }\n\n // \u91CD\u65B0\u5C1D\u8BD5\u6362\u533A\u767B\u5F55\n reloginResponse = await fetch(`${getAlpcPath(locale, apiBaseUrl)}/cloud/login`, {\n method: 'POST',\n })\n reloginResponseData = await reloginResponse.json()\n normalizedData = normalizeResponseData(reloginResponseData)\n\n if (reloginResponse.status > 300) {\n return false\n }\n }\n }\n if (!normalizedData?.code) {\n // \u91CD\u65B0\u767B\u5F55\u6210\u529F\n return true\n }\n\n return false\n}\n\nexport interface UseMutationConfig<TData> {\n onSuccess?: (response: TData) => any\n onError?: (error: Error) => any\n}\n\nconst useMutation = <TData, TBody>(\n url: string,\n fetcher: Fetcher<TData, TBody>,\n mutationConfig: UseMutationConfig<TData> = {},\n brandRef: React.MutableRefObject<string | undefined>\n) => {\n const innerMutating = useRef<boolean>(false)\n\n const [data, setData] = useState<TData>()\n const [isMutating, setIsMutating] = useState(false)\n\n const urlRef = useRef(url)\n const fetcherRef = useRef(fetcher)\n const configRef = useRef(mutationConfig)\n\n const trigger = useCallback(\n async (fetchData: TBody, opts: UseMutationConfig<TData> = {}) => {\n console.log('[useAlpcMutation] trigger called with:', { url: urlRef.current, fetchData, brand: brandRef.current })\n\n if (innerMutating.current) {\n console.log('[useAlpcMutation] already mutating, skipping')\n return\n }\n\n if (!brandRef.current) {\n console.log('[useAlpcMutation] brand not available, skipping request')\n return\n }\n\n innerMutating.current = true\n setIsMutating(true)\n\n const config = {\n ...configRef.current,\n ...opts,\n }\n\n const { onSuccess, onError } = config || {}\n\n try {\n const fetchResult = await fetcherRef.current(urlRef.current, {\n arg: fetchData,\n })\n setData(fetchResult)\n\n setIsMutating(false)\n innerMutating.current = false\n\n if (onSuccess) {\n onSuccess(fetchResult)\n }\n return fetchResult\n } catch (err: any) {\n setIsMutating(false)\n innerMutating.current = false\n\n if (onError) {\n onError(err)\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n []\n )\n\n return {\n isMutating,\n trigger,\n data,\n }\n}\n\nexport const useAlpcFetch = <TData>(\n options: FetchOptions,\n swrOptions?: UseAlpcFetchOptionsSwrOptions<TData, Error>\n) => {\n const [retry, setRetry] = useState(false)\n const { removeProfile, alpcBrand, apiBaseUrl } = useCreditsContext()\n\n const { enable, ...otherSwrOptions } = swrOptions || {}\n\n const { locale = '', brand: headlessBrand } = useHeadlessContext()\n // \u4F18\u5148\u4F7F\u7528 creditsContext \u4E2D\u7684 alpcBrand\uFF0C\u5982\u679C\u6CA1\u6709\u5219\u4F7F\u7528 headlessConfig \u4E2D\u7684 brand\n const brand = alpcBrand || headlessBrand\n\n const { queryKey = [], body: fetchBody = {}, headers, ...fetchOptions } = options\n const fetchEnable = enable ?? true\n\n const [url, requestBody] = queryKey\n\n const context = useSWR<TData>(\n [url, requestBody],\n !fetchEnable || !brand\n ? null\n : ([requestUrl, data]: [string, Record<string, any>]) =>\n fetcher({\n url: requestUrl,\n locale,\n apiBaseUrl,\n fetchOptions: {\n method: 'POST',\n headers: {\n 'current-language': locale,\n ...headers,\n },\n body: JSON.stringify({\n ...fetchBody,\n ...data,\n }),\n ...fetchOptions,\n },\n onReAuth: async () => {\n const result = await reAuth(locale, retry, brand, apiBaseUrl)\n\n if (result) {\n setRetry(true)\n return true\n }\n\n return false\n },\n onUnAuth() {\n // \u5931\u8D25\u540E\u9000\u51FA\u767B\u5F55\n removeProfile()\n },\n }),\n {\n revalidateOnFocus: false,\n ...otherSwrOptions,\n }\n )\n\n return context\n}\n\nexport const useAlpcMutation = <TData, TBody>(options: MutationOptions, mutationOptions?: UseMutationConfig<TData>) => {\n const [retry, setRetry] = useState(false)\n const { removeProfile, alpcBrand, apiBaseUrl } = useCreditsContext()\n\n const { locale = '', brand: headlessBrand } = useHeadlessContext()\n // \u4F18\u5148\u4F7F\u7528 creditsContext \u4E2D\u7684 alpcBrand\uFF0C\u5982\u679C\u6CA1\u6709\u5219\u4F7F\u7528 headlessConfig \u4E2D\u7684 brand\n const brand = alpcBrand || headlessBrand\n const brandRef = useRef(brand)\n brandRef.current = brand\n\n const { url, initData, headers, ...fetchOptions } = options\n const initDataRef = useRef(initData)\n initDataRef.current = initData\n\n const context = useMutation<TData, TBody>(\n url,\n (requestUrl, data: { arg: TBody }) => {\n // Prevent requests when brand is not available\n if (!brandRef.current) {\n return Promise.resolve(undefined as unknown as TData)\n }\n\n return fetcher({\n url: requestUrl,\n locale,\n apiBaseUrl,\n fetchOptions: {\n method: 'POST',\n headers: {\n 'current-language': locale,\n ...headers,\n },\n ...fetchOptions,\n body: JSON.stringify({\n ...initDataRef.current,\n ...data.arg,\n }),\n },\n onReAuth: async () => {\n const result = await reAuth(locale, retry, brandRef.current!, apiBaseUrl)\n\n if (result) {\n setRetry(true)\n return true\n }\n\n return false\n },\n onUnAuth() {\n // \u5931\u8D25\u540E\u9000\u51FA\u767B\u5F55\n removeProfile()\n },\n })\n },\n mutationOptions,\n brandRef\n )\n\n return context\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAa,YACpB,OAAS,eAAAC,EAAa,UAAAC,EAAQ,YAAAC,MAAgB,QAC9C,OAAOC,MAAuC,MAC9C,OAAS,sBAAAC,MAA0B,gBAEnC,OAAS,eAAAC,MAAmB,WAC5B,OAAS,qBAAAC,MAAyB,cAyBlC,IAAIC,EAUJ,MAAMC,EAAyBC,GACxBA,IAGDA,EAAa,MAAQ,OAAOA,EAAa,MAAS,UAAY,CAAC,MAAM,QAAQA,EAAa,IAAI,EACzFA,EAAa,KAIfA,GAGHC,EAAWC,GACR,MAAMN,EAAYM,EAAQ,OAAQA,EAAQ,UAAU,EAAIA,EAAQ,IAAKA,EAAQ,YAAY,EAAE,KAAK,MAAMC,GAAY,CACvH,GAAIA,EAAS,OAAS,IAAK,CACzB,MAAMH,EAAe,MAAMG,EAAS,KAAK,EACzC,OAAOJ,EAAsBC,CAAY,CAC3C,CAGA,GAAIG,EAAS,SAAW,KAElBD,EAAQ,SAA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AUD,EAENrC,EACdC,EACA,CAACiC,EAAY7B,IAENF,EAAS,QAIPhB,EAAQ,CACb,IAAK+C,EACL,OAAA1C,EACA,WAAAG,EACA,aAAc,CACZ,OAAQ,OACR,QAAS,CACP,mBAAoBH,EACpB,GAAGsC,CACL,EACA,GAAGC,EACH,KAAM,KAAK,UAAU,CACnB,GAAGO,EAAY,QACf,GAAGjC,EAAK,GACV,CAAC,CACH,EACA,SAAU,SACO,MAAMd,EAAOC,EAAQC,EAAOU,EAAS,QAAUR,CAAU,GAGtE2B,EAAS,EAAI,EACN,IAGF,GAET,UAAW,CAETC,EAAc,CAChB,CACF,CAAC,EAjCQ,QAAQ,QAAQ,MAA6B,EAmCxDa,EACAjC,CACF,CAGF",
|
|
6
|
+
"names": ["Cookies", "useCallback", "useRef", "useState", "useSWR", "useHeadlessContext", "getAlpcPath", "useCreditsContext", "reAuthPromise", "normalizeResponseData", "responseData", "fetcher", "options", "response", "result", "reAuth", "locale", "retry", "brand", "apiBaseUrl", "reloginResponse", "reloginResponseData", "normalizedData", "alpcEUCookie", "useMutation", "url", "mutationConfig", "brandRef", "innerMutating", "data", "setData", "isMutating", "setIsMutating", "urlRef", "fetcherRef", "configRef", "trigger", "fetchData", "opts", "config", "onSuccess", "onError", "fetchResult", "err", "useAlpcFetch", "swrOptions", "setRetry", "removeProfile", "alpcBrand", "enable", "otherSwrOptions", "headlessBrand", "queryKey", "fetchBody", "headers", "fetchOptions", "fetchEnable", "requestBody", "requestUrl", "useAlpcMutation", "mutationOptions", "initData", "initDataRef"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useCallback as
|
|
1
|
+
import{useCallback as R,useEffect as C,useState as d}from"react";import{ALPC_COUNTRY_MAP as b,AlpcConsumeType as A}from"../const";import{useAlpcMutation as M}from"./useAlpcFetch";import{useCreditsContext as w}from"../provider";import{useHeadlessContext as L}from"@anker-in/lib";function T({page:o,pageSize:r,consumeType:n}){const{profile:e,alpcBrand:c}=w(),{brand:l,locale:a,appName:g}=L(),t=c||l,[u,_]=d([]),[p,f]=d(0),{isMutating:i,trigger:y}=M({url:"/v1/credit/log/coupon",initData:{brand:t,country:b.get(a)||a,app_name:g}}),s=R(async()=>{e?.user_id&&await y({consume_type:n||A.Coupon,page:o,page_size:r,user_id:e?.user_id},{onSuccess(m){f(m?.data?.total),_(m?.data?.redeem_logs||[])}})},[n,o,r,e?.user_id]);return C(()=>{!t||!e?.user_id||s()},[s,t]),{myRewards:u,isLoading:i,total:p,getMyRewards:s,canNext:p>u.length&&!i}}var P=T;export{P as default};
|
|
2
2
|
//# sourceMappingURL=useMyRewards.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useMyRewards.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { ALPC_COUNTRY_MAP, AlpcConsumeType } from '../const'\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { RedeemLogResponse } from '../response'\nimport { useCreditsContext } from '../provider'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useMyRewards({\n page,\n pageSize,\n consumeType,\n}: {\n page: number\n pageSize: number\n consumeType?: AlpcConsumeType\n}) {\n const { profile, alpcBrand } = useCreditsContext()\n const { brand: headlessBrand, locale, appName } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n\n const [myRewards, setMyRewards] = useState<RedeemLogResponse[]>([])\n const [total, setTotal] = useState(0)\n\n const { isMutating: isLoading, trigger } = useAlpcMutation<\n { data: { redeem_logs: RedeemLogResponse[]; total: number } },\n {\n page: number\n page_size: number\n consume_type: AlpcConsumeType\n user_id: string\n }\n >({\n url: `/v1/credit/log/coupon`,\n initData: {\n brand: brand,\n country: ALPC_COUNTRY_MAP.get(locale) || locale,\n app_name: appName,\n },\n })\n\n const getMyRewards = useCallback(async () => {\n if (!profile?.user_id) {\n return\n }\n await trigger(\n {\n consume_type: consumeType || AlpcConsumeType.Coupon,\n page,\n page_size: pageSize,\n user_id: profile?.user_id,\n },\n {\n onSuccess(responseData) {\n
|
|
5
|
-
"mappings": "AAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QAEjD,OAAS,oBAAAC,EAAkB,mBAAAC,MAAuB,WAClD,OAAS,mBAAAC,MAAuB,iBAEhC,OAAS,qBAAAC,MAAyB,cAClC,OAAS,sBAAAC,MAA0B,gBAEnC,SAASC,EAAa,CACpB,KAAAC,EACA,SAAAC,EACA,YAAAC,CACF,EAIG,CACD,KAAM,CAAE,QAAAC,EAAS,UAAAC,CAAU,EAAIP,EAAkB,EAC3C,CAAE,MAAOQ,EAAe,OAAAC,EAAQ,QAAAC,CAAQ,EAAIT,EAAmB,EAC/DU,EAAQJ,GAAaC,EAErB,CAACI,EAAWC,CAAY,EAAIjB,EAA8B,CAAC,CAAC,EAC5D,CAACkB,EAAOC,CAAQ,EAAInB,EAAS,CAAC,EAE9B,CAAE,WAAYoB,EAAW,QAAAC,CAAQ,EAAIlB,EAQzC,CACA,IAAK,wBACL,SAAU,CACR,MAAOY,EACP,QAASd,EAAiB,IAAIY,CAAM,GAAKA,EACzC,SAAUC,CACZ,CACF,CAAC,EAEKQ,EAAexB,EAAY,SAAY,CACtCY,GAAS,SAGd,MAAMW,EACJ,CACE,aAAcZ,GAAeP,EAAgB,OAC7C,KAAAK,EACA,UAAWC,EACX,QAASE,GAAS,OACpB,EACA,CACE,UAAUa,EAAc,
|
|
6
|
-
"names": ["useCallback", "useEffect", "useState", "ALPC_COUNTRY_MAP", "AlpcConsumeType", "useAlpcMutation", "useCreditsContext", "useHeadlessContext", "useMyRewards", "page", "pageSize", "consumeType", "profile", "alpcBrand", "headlessBrand", "locale", "appName", "brand", "myRewards", "setMyRewards", "total", "setTotal", "isLoading", "trigger", "getMyRewards", "responseData", "
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { ALPC_COUNTRY_MAP, AlpcConsumeType } from '../const'\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { RedeemLogResponse } from '../response'\nimport { useCreditsContext } from '../provider'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useMyRewards({\n page,\n pageSize,\n consumeType,\n}: {\n page: number\n pageSize: number\n consumeType?: AlpcConsumeType\n}) {\n const { profile, alpcBrand } = useCreditsContext()\n const { brand: headlessBrand, locale, appName } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n\n const [myRewards, setMyRewards] = useState<RedeemLogResponse[]>([])\n const [total, setTotal] = useState(0)\n\n const { isMutating: isLoading, trigger } = useAlpcMutation<\n { data: { redeem_logs: RedeemLogResponse[]; total: number } },\n {\n page: number\n page_size: number\n consume_type: AlpcConsumeType\n user_id: string\n }\n >({\n url: `/v1/credit/log/coupon`,\n initData: {\n brand: brand,\n country: ALPC_COUNTRY_MAP.get(locale) || locale,\n app_name: appName,\n },\n })\n\n const getMyRewards = useCallback(async () => {\n if (!profile?.user_id) {\n return\n }\n await trigger(\n {\n consume_type: consumeType || AlpcConsumeType.Coupon,\n page,\n page_size: pageSize,\n user_id: profile?.user_id,\n },\n {\n onSuccess(responseData) {\n setTotal(responseData?.data?.total)\n setMyRewards(responseData?.data?.redeem_logs || [])\n },\n }\n )\n }, [consumeType, page, pageSize, profile?.user_id])\n\n useEffect(() => {\n if (!brand || !profile?.user_id) {\n return\n }\n getMyRewards()\n }, [getMyRewards, brand])\n\n return {\n myRewards,\n isLoading,\n total,\n getMyRewards,\n canNext: total > myRewards.length && !isLoading,\n }\n}\n\nexport default useMyRewards\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QAEjD,OAAS,oBAAAC,EAAkB,mBAAAC,MAAuB,WAClD,OAAS,mBAAAC,MAAuB,iBAEhC,OAAS,qBAAAC,MAAyB,cAClC,OAAS,sBAAAC,MAA0B,gBAEnC,SAASC,EAAa,CACpB,KAAAC,EACA,SAAAC,EACA,YAAAC,CACF,EAIG,CACD,KAAM,CAAE,QAAAC,EAAS,UAAAC,CAAU,EAAIP,EAAkB,EAC3C,CAAE,MAAOQ,EAAe,OAAAC,EAAQ,QAAAC,CAAQ,EAAIT,EAAmB,EAC/DU,EAAQJ,GAAaC,EAErB,CAACI,EAAWC,CAAY,EAAIjB,EAA8B,CAAC,CAAC,EAC5D,CAACkB,EAAOC,CAAQ,EAAInB,EAAS,CAAC,EAE9B,CAAE,WAAYoB,EAAW,QAAAC,CAAQ,EAAIlB,EAQzC,CACA,IAAK,wBACL,SAAU,CACR,MAAOY,EACP,QAASd,EAAiB,IAAIY,CAAM,GAAKA,EACzC,SAAUC,CACZ,CACF,CAAC,EAEKQ,EAAexB,EAAY,SAAY,CACtCY,GAAS,SAGd,MAAMW,EACJ,CACE,aAAcZ,GAAeP,EAAgB,OAC7C,KAAAK,EACA,UAAWC,EACX,QAASE,GAAS,OACpB,EACA,CACE,UAAUa,EAAc,CACtBJ,EAASI,GAAc,MAAM,KAAK,EAClCN,EAAaM,GAAc,MAAM,aAAe,CAAC,CAAC,CACpD,CACF,CACF,CACF,EAAG,CAACd,EAAaF,EAAMC,EAAUE,GAAS,OAAO,CAAC,EAElD,OAAAX,EAAU,IAAM,CACV,CAACgB,GAAS,CAACL,GAAS,SAGxBY,EAAa,CACf,EAAG,CAACA,EAAcP,CAAK,CAAC,EAEjB,CACL,UAAAC,EACA,UAAAI,EACA,MAAAF,EACA,aAAAI,EACA,QAASJ,EAAQF,EAAU,QAAU,CAACI,CACxC,CACF,CAEA,IAAOI,EAAQlB",
|
|
6
|
+
"names": ["useCallback", "useEffect", "useState", "ALPC_COUNTRY_MAP", "AlpcConsumeType", "useAlpcMutation", "useCreditsContext", "useHeadlessContext", "useMyRewards", "page", "pageSize", "consumeType", "profile", "alpcBrand", "headlessBrand", "locale", "appName", "brand", "myRewards", "setMyRewards", "total", "setTotal", "isLoading", "trigger", "getMyRewards", "responseData", "useMyRewards_default"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useCallback as y,useEffect as _,useState as g}from"react";import{useAlpcMutation as T}from"./useAlpcFetch";import{ALPC_COUNTRY_MAP as R}from"../const";import{useCreditsContext as L}from"../provider";import{useHeadlessContext as b}from"@anker-in/lib";function A(l){let e="";const{profile:
|
|
1
|
+
import{useCallback as y,useEffect as _,useState as g}from"react";import{useAlpcMutation as T}from"./useAlpcFetch";import{ALPC_COUNTRY_MAP as R}from"../const";import{useCreditsContext as L}from"../provider";import{useHeadlessContext as b}from"@anker-in/lib";function A(l){let e="";const{profile:o,isLoadingProfile:n,alpcBrand:m}=L(),{locale:r,brand:p}=b(),s=m||p;r==="pl"?e="eu":e=r;const[a,d]=g([]),{isMutating:C,trigger:u}=T({url:"/v1/credit/consume_credit_rules",initData:{brand:s,page:1,page_size:999,country:(R.get(e)||e)?.toUpperCase()}}),t=y(i=>{u({user_id:o?.user_id,...i?.consumeType&&{consume_type:i.consumeType}},{onSuccess(c){console.log("responseData",c);let f=c?.data?.consume_credit_rules||[];d(f)}})},[o,u,e]);return _(()=>{!s||n||t({consumeType:l?.consumeType})},[t,n,s]),{listLoading:C,redeemableList:a,getRedeemableList:t}}var h=A;export{h as default};
|
|
2
2
|
//# sourceMappingURL=useRedeemableList.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useRedeemableList.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { useAlpcMutation } from './useAlpcFetch'\nimport { ALPC_COUNTRY_MAP, AlpcConsumeType } from '../const'\nimport { useCreditsContext } from '../provider'\nimport type { ConsumeCreditRuleResponse } from '../response'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useRedeemableList(props?: { consumeType: AlpcConsumeType }) {\n let locale = '' as string\n const { profile, isLoadingProfile, alpcBrand } = useCreditsContext()\n const { locale: contextLocale, brand: headlessBrand } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n\n if (contextLocale === 'pl') {\n locale = 'eu'\n } else {\n locale = contextLocale\n }\n\n const [redeemableList, setRedeemableList] = useState<ConsumeCreditRuleResponse[]>([])\n const { isMutating: listLoading, trigger } = useAlpcMutation<\n {\n data: { consume_credit_rules: ConsumeCreditRuleResponse[] }\n },\n { consume_type?: AlpcConsumeType; user_id?: string }\n >({\n url: `/v1/credit/consume_credit_rules`,\n initData: {\n brand,\n page: 1,\n page_size: 999,\n country: (ALPC_COUNTRY_MAP.get(locale) || locale)?.toUpperCase(),\n },\n })\n\n const getRedeemableList = useCallback(\n (props?: { consumeType?: AlpcConsumeType }) => {\n trigger(\n {\n user_id: profile?.user_id,\n ...(props?.consumeType && { consume_type: props.consumeType }),\n },\n {\n onSuccess(responseData) {\n console.log('responseData', responseData)\n
|
|
5
|
-
"mappings": "AAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QAEjD,OAAS,mBAAAC,MAAuB,iBAChC,OAAS,oBAAAC,MAAyC,WAClD,OAAS,qBAAAC,MAAyB,cAElC,OAAS,sBAAAC,MAA0B,gBAEnC,SAASC,EAAkBC,EAA0C,CACnE,IAAIC,EAAS,GACb,KAAM,CAAE,QAAAC,EAAS,iBAAAC,EAAkB,UAAAC,CAAU,EAAIP,EAAkB,EAC7D,CAAE,OAAQQ,EAAe,MAAOC,CAAc,EAAIR,EAAmB,EACrES,EAAQH,GAAaE,EAEvBD,IAAkB,KACpBJ,EAAS,KAETA,EAASI,EAGX,KAAM,CAACG,EAAgBC,CAAiB,EAAIf,EAAsC,CAAC,CAAC,EAC9E,CAAE,WAAYgB,EAAa,QAAAC,CAAQ,EAAIhB,EAK3C,CACA,IAAK,kCACL,SAAU,CACR,MAAAY,EACA,KAAM,EACN,UAAW,IACX,SAAUX,EAAiB,IAAIK,CAAM,GAAKA,IAAS,YAAY,CACjE,CACF,CAAC,EAEKW,EAAoBpB,EACvBQ,GAA8C,CAC7CW,EACE,CACE,QAAST,GAAS,QAClB,GAAIF,GAAO,aAAe,CAAE,aAAcA,EAAM,WAAY,CAC9D,EACA,CACE,UAAUa,EAAc,CACtB,QAAQ,IAAI,eAAgBA,CAAY,
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { useAlpcMutation } from './useAlpcFetch'\nimport { ALPC_COUNTRY_MAP, AlpcConsumeType } from '../const'\nimport { useCreditsContext } from '../provider'\nimport type { ConsumeCreditRuleResponse } from '../response'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nfunction useRedeemableList(props?: { consumeType: AlpcConsumeType }) {\n let locale = '' as string\n const { profile, isLoadingProfile, alpcBrand } = useCreditsContext()\n const { locale: contextLocale, brand: headlessBrand } = useHeadlessContext()\n const brand = alpcBrand || headlessBrand\n\n if (contextLocale === 'pl') {\n locale = 'eu'\n } else {\n locale = contextLocale\n }\n\n const [redeemableList, setRedeemableList] = useState<ConsumeCreditRuleResponse[]>([])\n const { isMutating: listLoading, trigger } = useAlpcMutation<\n {\n data: { consume_credit_rules: ConsumeCreditRuleResponse[] }\n },\n { consume_type?: AlpcConsumeType; user_id?: string }\n >({\n url: `/v1/credit/consume_credit_rules`,\n initData: {\n brand,\n page: 1,\n page_size: 999,\n country: (ALPC_COUNTRY_MAP.get(locale) || locale)?.toUpperCase(),\n },\n })\n\n const getRedeemableList = useCallback(\n (props?: { consumeType?: AlpcConsumeType }) => {\n trigger(\n {\n user_id: profile?.user_id,\n ...(props?.consumeType && { consume_type: props.consumeType }),\n },\n {\n onSuccess(responseData) {\n console.log('responseData', responseData)\n let list = responseData?.data?.consume_credit_rules || []\n setRedeemableList(list)\n },\n }\n )\n },\n [profile, trigger, locale]\n )\n\n useEffect(() => {\n if (!brand || isLoadingProfile) {\n return\n }\n getRedeemableList({ consumeType: props?.consumeType })\n }, [getRedeemableList, isLoadingProfile, brand])\n\n return {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AOG,EAAQhB",
|
|
6
6
|
"names": ["useCallback", "useEffect", "useState", "useAlpcMutation", "ALPC_COUNTRY_MAP", "useCreditsContext", "useHeadlessContext", "useRedeemableList", "props", "locale", "profile", "isLoadingProfile", "alpcBrand", "contextLocale", "headlessBrand", "brand", "redeemableList", "setRedeemableList", "listLoading", "trigger", "getRedeemableList", "responseData", "list", "useRedeemableList_default"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import o from"swr/mutation";import{useHeadlessContext as d}from"@anker-in/lib";const n=t=>t&&(t.data&&typeof t.data=="object"&&!Array.isArray(t.data)?t.data:t),p=()=>{const{locale:t}=d();return o("/api/multipass/mktsrv/v1/credit/upload_third_party_order",async(c,{arg:{orderName:r}})=>{const a=await(await fetch("/api/multipass/mktsrv/v1/credit/upload_third_party_order",{credentials:"include",method:"POST",headers:{"Content-Type":"application/json","current-language":t},body:JSON.stringify({order_name:r})})).json(),e=n(a);return{ok:e?.data?.code===0,code:e?.data?.code??-1}})};export{p as useUploadReceipt};
|
|
2
2
|
//# sourceMappingURL=useUploadReceipt.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useUploadReceipt.tsx"],
|
|
4
|
-
"sourcesContent": ["import useSWRMutation from 'swr/mutation'\nimport { useHeadlessContext } from '@anker-in/lib'\n\nexport const useUploadReceipt = () => {\n const { locale } = useHeadlessContext()\n\n const uploadReceipt = async (\n _: any,\n { arg: { orderName } }: { arg: { orderName: string } }\n ): Promise<{\n ok: boolean\n code: number\n }> => {\n const response = await fetch(`/api/multipass/mktsrv/v1/credit/upload_third_party_order`, {\n credentials: 'include',\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'current-language': locale,\n },\n body: JSON.stringify({\n order_name: orderName,\n }),\n })\n const result = await response.json()\n const
|
|
5
|
-
"mappings": "AAAA,OAAOA,MAAoB,eAC3B,OAAS,sBAAAC,MAA0B,
|
|
6
|
-
"names": ["useSWRMutation", "useHeadlessContext", "useUploadReceipt", "locale", "_", "orderName", "result", "
|
|
4
|
+
"sourcesContent": ["import useSWRMutation from 'swr/mutation'\nimport { useHeadlessContext } from '@anker-in/lib'\n\n/**\n * \u7EDF\u4E00\u5904\u7406 ALPC \u63A5\u53E3\u8FD4\u56DE\u7684\u6570\u636E\u7ED3\u6784\n * \u517C\u5BB9\u4E00\u5C42 data \u548C\u4E24\u5C42 data \u7684\u573A\u666F\n */\nconst normalizeResponseData = (responseData: any) => {\n if (!responseData) return responseData\n\n // \u5982\u679C responseData.data \u5B58\u5728\u4E14\u662F\u4E00\u4E2A\u5BF9\u8C61\uFF08\u4E0D\u662F\u6570\u7EC4\uFF09\uFF0C\u8BF4\u660E\u662F\u4E24\u5C42 data \u7ED3\u6784\n if (responseData.data && typeof responseData.data === 'object' && !Array.isArray(responseData.data)) {\n return responseData.data\n }\n\n // \u4E00\u5C42 data \u7ED3\u6784\u6216\u5176\u4ED6\u60C5\u51B5\uFF0C\u76F4\u63A5\u8FD4\u56DE\n return responseData\n}\n\nexport const useUploadReceipt = () => {\n const { locale } = useHeadlessContext()\n\n const uploadReceipt = async (\n _: any,\n { arg: { orderName } }: { arg: { orderName: string } }\n ): Promise<{\n ok: boolean\n code: number\n }> => {\n const response = await fetch(`/api/multipass/mktsrv/v1/credit/upload_third_party_order`, {\n credentials: 'include',\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'current-language': locale,\n },\n body: JSON.stringify({\n order_name: orderName,\n }),\n })\n const result = await response.json()\n const normalizedData = normalizeResponseData(result)\n return {\n ok: normalizedData?.data?.code === 0,\n code: normalizedData?.data?.code ?? -1,\n }\n }\n\n return useSWRMutation('/api/multipass/mktsrv/v1/credit/upload_third_party_order', uploadReceipt)\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAoB,eAC3B,OAAS,sBAAAC,MAA0B,gBAMnC,MAAMC,EAAyBC,GACxBA,IAGDA,EAAa,MAAQ,OAAOA,EAAa,MAAS,UAAY,CAAC,MAAM,QAAQA,EAAa,IAAI,EACzFA,EAAa,KAIfA,GAGIC,EAAmB,IAAM,CACpC,KAAM,CAAE,OAAAC,CAAO,EAAIJ,EAAmB,EA4BtC,OAAOD,EAAe,2DA1BA,MACpBM,EACA,CAAE,IAAK,CAAE,UAAAC,CAAU,CAAE,IAIjB,CAYJ,MAAMC,EAAS,MAXE,MAAM,MAAM,2DAA4D,CACvF,YAAa,UACb,OAAQ,OACR,QAAS,CACP,eAAgB,mBAChB,mBAAoBH,CACtB,EACA,KAAM,KAAK,UAAU,CACnB,WAAYE,CACd,CAAC,CACH,CAAC,GAC6B,KAAK,EAC7BE,EAAiBP,EAAsBM,CAAM,EACnD,MAAO,CACL,GAAIC,GAAgB,MAAM,OAAS,EACnC,KAAMA,GAAgB,MAAM,MAAQ,EACtC,CACF,CAE+F,CACjG",
|
|
6
|
+
"names": ["useSWRMutation", "useHeadlessContext", "normalizeResponseData", "responseData", "useUploadReceipt", "locale", "_", "orderName", "result", "normalizedData"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -44,9 +44,8 @@ function useActivities({ page, pageSize, options = {} }: { page: number; pageSiz
|
|
|
44
44
|
trigger(params, {
|
|
45
45
|
onSuccess(responseData) {
|
|
46
46
|
setCurrentPage(page)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
setActivities(activities.concat(data?.creditLogs || []))
|
|
47
|
+
setTotal(responseData?.data?.total)
|
|
48
|
+
setActivities(activities.concat(responseData?.data?.creditLogs || []))
|
|
50
49
|
},
|
|
51
50
|
})
|
|
52
51
|
}, [activities, profile, page, pageSize, options, trigger])
|
|
@@ -33,11 +33,29 @@ let reAuthPromise: Promise<boolean> | undefined
|
|
|
33
33
|
|
|
34
34
|
type Fetcher<TData, TBody> = (url: string, data: { arg: TBody }) => Promise<TData>
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* 统一处理 ALPC 接口返回的数据结构
|
|
38
|
+
* 兼容一层 data 和两层 data 的场景:
|
|
39
|
+
* - 两层 data: {data: {data: ..., code: 27004}}
|
|
40
|
+
* - 一层 data: {data: ..., code: 27004}
|
|
41
|
+
*/
|
|
42
|
+
const normalizeResponseData = (responseData: any) => {
|
|
43
|
+
if (!responseData) return responseData
|
|
44
|
+
|
|
45
|
+
// 如果 responseData.data 存在且是一个对象(不是数组),说明是两层 data 结构
|
|
46
|
+
if (responseData.data && typeof responseData.data === 'object' && !Array.isArray(responseData.data)) {
|
|
47
|
+
return responseData.data
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 一层 data 结构或其他情况,直接返回
|
|
51
|
+
return responseData
|
|
52
|
+
}
|
|
53
|
+
|
|
36
54
|
const fetcher = (options: FetcherOptions) => {
|
|
37
55
|
return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, options.fetchOptions).then(async response => {
|
|
38
56
|
if (response.status < 300) {
|
|
39
57
|
const responseData = await response.json()
|
|
40
|
-
return responseData
|
|
58
|
+
return normalizeResponseData(responseData)
|
|
41
59
|
}
|
|
42
60
|
|
|
43
61
|
// 错误处理
|
|
@@ -57,7 +75,7 @@ const fetcher = (options: FetcherOptions) => {
|
|
|
57
75
|
return fetch(getAlpcPath(options.locale, options.apiBaseUrl) + options.url, options.fetchOptions).then(async response => {
|
|
58
76
|
if (response.status < 300) {
|
|
59
77
|
const responseData = await response.json()
|
|
60
|
-
return responseData
|
|
78
|
+
return normalizeResponseData(responseData)
|
|
61
79
|
}
|
|
62
80
|
|
|
63
81
|
if (response.status === 401) {
|
|
@@ -83,9 +101,11 @@ const reAuth = async (locale: string, retry: boolean, brand: string, apiBaseUrl?
|
|
|
83
101
|
method: 'POST',
|
|
84
102
|
})
|
|
85
103
|
let reloginResponseData = await reloginResponse.json()
|
|
104
|
+
// 兼容两层 data 结构
|
|
105
|
+
let normalizedData = normalizeResponseData(reloginResponseData)
|
|
86
106
|
|
|
87
107
|
if (reloginResponse!.status < 300 && !retry) {
|
|
88
|
-
if (
|
|
108
|
+
if (normalizedData?.code === 27004) {
|
|
89
109
|
// 跨区登录错误
|
|
90
110
|
const alpcEUCookie = Cookies.get('alpcEU')
|
|
91
111
|
|
|
@@ -106,13 +126,14 @@ const reAuth = async (locale: string, retry: boolean, brand: string, apiBaseUrl?
|
|
|
106
126
|
method: 'POST',
|
|
107
127
|
})
|
|
108
128
|
reloginResponseData = await reloginResponse.json()
|
|
129
|
+
normalizedData = normalizeResponseData(reloginResponseData)
|
|
109
130
|
|
|
110
131
|
if (reloginResponse.status > 300) {
|
|
111
132
|
return false
|
|
112
133
|
}
|
|
113
134
|
}
|
|
114
135
|
}
|
|
115
|
-
if (!
|
|
136
|
+
if (!normalizedData?.code) {
|
|
116
137
|
// 重新登录成功
|
|
117
138
|
return true
|
|
118
139
|
}
|
|
@@ -52,9 +52,8 @@ function useMyRewards({
|
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
54
|
onSuccess(responseData) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
setMyRewards(data?.redeem_logs || [])
|
|
55
|
+
setTotal(responseData?.data?.total)
|
|
56
|
+
setMyRewards(responseData?.data?.redeem_logs || [])
|
|
58
57
|
},
|
|
59
58
|
}
|
|
60
59
|
)
|
|
@@ -44,13 +44,7 @@ function useRedeemableList(props?: { consumeType: AlpcConsumeType }) {
|
|
|
44
44
|
{
|
|
45
45
|
onSuccess(responseData) {
|
|
46
46
|
console.log('responseData', responseData)
|
|
47
|
-
|
|
48
|
-
let list = data?.consume_credit_rules || []
|
|
49
|
-
// let cList = list.filter(i => i.consume_type == 1) || []
|
|
50
|
-
// let pList = list.filter(i => i.consume_type == 2) || []
|
|
51
|
-
// cList = cList.sort((prev, next) => prev.consume_credits - next.consume_credits)
|
|
52
|
-
// pList = pList.sort((prev, next) => prev.consume_credits - next.consume_credits)
|
|
53
|
-
// const resultList = cList.concat(pList)
|
|
47
|
+
let list = responseData?.data?.consume_credit_rules || []
|
|
54
48
|
setRedeemableList(list)
|
|
55
49
|
},
|
|
56
50
|
}
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import useSWRMutation from 'swr/mutation'
|
|
2
2
|
import { useHeadlessContext } from '@anker-in/lib'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* 统一处理 ALPC 接口返回的数据结构
|
|
6
|
+
* 兼容一层 data 和两层 data 的场景
|
|
7
|
+
*/
|
|
8
|
+
const normalizeResponseData = (responseData: any) => {
|
|
9
|
+
if (!responseData) return responseData
|
|
10
|
+
|
|
11
|
+
// 如果 responseData.data 存在且是一个对象(不是数组),说明是两层 data 结构
|
|
12
|
+
if (responseData.data && typeof responseData.data === 'object' && !Array.isArray(responseData.data)) {
|
|
13
|
+
return responseData.data
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 一层 data 结构或其他情况,直接返回
|
|
17
|
+
return responseData
|
|
18
|
+
}
|
|
19
|
+
|
|
4
20
|
export const useUploadReceipt = () => {
|
|
5
21
|
const { locale } = useHeadlessContext()
|
|
6
22
|
|
|
@@ -23,10 +39,10 @@ export const useUploadReceipt = () => {
|
|
|
23
39
|
}),
|
|
24
40
|
})
|
|
25
41
|
const result = await response.json()
|
|
26
|
-
const
|
|
42
|
+
const normalizedData = normalizeResponseData(result)
|
|
27
43
|
return {
|
|
28
|
-
ok:
|
|
29
|
-
code:
|
|
44
|
+
ok: normalizedData?.data?.code === 0,
|
|
45
|
+
code: normalizedData?.data?.code ?? -1,
|
|
30
46
|
}
|
|
31
47
|
}
|
|
32
48
|
|