@anker-in/campaign-ui 0.5.6 → 0.5.7-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/credits/context/hooks/useActivities.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useActivities.js.map +3 -3
- package/dist/cjs/components/memberPopup/panels/EarnCredits/hooks/useActivities.d.ts +2 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/hooks/useActivities.js +1 -1
- package/dist/cjs/components/memberPopup/panels/EarnCredits/hooks/useActivities.js.map +3 -3
- package/dist/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/memberPopup/panels/EarnCredits/hooks/useActivities.d.ts +2 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/hooks/useActivities.js +1 -1
- package/dist/esm/components/memberPopup/panels/EarnCredits/hooks/useActivities.js.map +3 -3
- package/package.json +1 -1
- package/src/components/credits/context/hooks/useActivities.ts +4 -2
- package/src/components/memberPopup/panels/EarnCredits/hooks/useActivities.ts +4 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var N=(t,e)=>{for(var o in e)u(t,o,{get:e[o],enumerable:!0})},S=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of z(e))!B.call(t,r)&&r!==o&&u(t,r,{get:()=>e[r],enumerable:!(i=h(e,r))||i.enumerable});return t};var T=t=>S(u({},"__esModule",{value:!0}),t);var H={};N(H,{default:()=>E});module.exports=T(H);var s=require("react"),C=require("./useAlpcFetch"),b=require("../const"),L=require("../provider"),_=require("@anker-in/lib");function k({page:t,pageSize:e,options:o={}}){const{profile:i,isLoadingProfile:r,alpcBrand:A,alpcCountry:v}=(0,L.useCreditsContext)(),{brand:y,locale:d}=(0,_.useHeadlessContext)(),c=A||y,[n,P]=(0,s.useState)([]),[l,x]=(0,s.useState)(0),[m,R]=(0,s.useState)(0),{isMutating:a,trigger:g}=(0,C.useAlpcMutation)({url:"/v1/credit/log",initData:{brand:c,country:v||b.ALPC_COUNTRY_MAP.get(d)||d}}),p=(0,s.useCallback)(async()=>{const M={page:t,page_size:e,user_id:i?.user_id,...o};g(M,{onSuccess(f){R(t),x(f?.data?.total),P(n.concat(f?.data?.creditLogs||[]))}})},[n,i,t,e,o,g]);return(0,s.useEffect)(()=>{r||!i||!c||a||t!==m&&t&&p()},[p,r,a,i,c,t,m]),{activities:n,isLoading:a,total:l,canNext:l>n.length&&!a}}var E=k;
|
|
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 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": "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,
|
|
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 { ALPC_COUNTRY_MAP } from '../const'\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, alpcCountry } = useCreditsContext()\n const { brand: headlessBrand, locale } = 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 country: alpcCountry || ALPC_COUNTRY_MAP.get(locale) || locale,\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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiD,iBAEjDC,EAAgC,0BAEhCC,EAAiC,oBACjCC,EAAkC,uBAClCC,EAAmC,yBAEnC,SAASC,EAAc,CAAE,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAU,CAAC,CAAE,EAAsD,CAC1G,KAAM,CAAE,QAAAC,EAAS,iBAAAC,EAAkB,UAAAC,EAAW,YAAAC,CAAY,KAAI,qBAAkB,EAC1E,CAAE,MAAOC,EAAe,OAAAC,CAAO,KAAI,sBAAmB,EACtDC,EAAQJ,GAAaE,EACrB,CAACG,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,EACA,QAASH,GAAe,mBAAiB,IAAIE,CAAM,GAAKA,CAC1D,CACF,CAAC,EAEKU,KAAgB,eAAY,SAAY,CAC5C,MAAMC,EAAS,CACb,KAAMnB,EACN,UAAWC,EACX,QAASE,GAAS,QAClB,GAAGD,CACL,EAEAe,EAAQE,EAAQ,CACd,UAAUC,EAAc,CACtBL,EAAef,CAAI,EACnBa,EAASO,GAAc,MAAM,KAAK,EAClCT,EAAcD,EAAW,OAAOU,GAAc,MAAM,YAAc,CAAC,CAAC,CAAC,CACvE,CACF,CAAC,CACH,EAAG,CAACV,EAAYP,EAASH,EAAMC,EAAUC,EAASe,CAAO,CAAC,EAE1D,sBAAU,IAAM,CACVb,GAAoB,CAACD,GAAW,CAACM,GAASO,GAI1ChB,IAASc,GAAed,GAC1BkB,EAAc,CAElB,EAAG,CAACA,EAAed,EAAkBY,EAAWb,EAASM,EAAOT,EAAMc,CAAW,CAAC,EAE3E,CACL,WAAAJ,EACA,UAAAM,EACA,MAAAJ,EACA,QAASA,EAAQF,EAAW,QAAU,CAACM,CACzC,CACF,CAEA,IAAOxB,EAAQO",
|
|
6
|
+
"names": ["useActivities_exports", "__export", "useActivities_default", "__toCommonJS", "import_react", "import_useAlpcFetch", "import_const", "import_provider", "import_lib", "useActivities", "page", "pageSize", "options", "profile", "isLoadingProfile", "alpcBrand", "alpcCountry", "headlessBrand", "locale", "brand", "activities", "setActivities", "total", "setTotal", "currentPage", "setCurrentPage", "isLoading", "trigger", "getActivities", "params", "responseData"]
|
|
7
7
|
}
|
|
@@ -4,12 +4,13 @@ type UseActivitiesConfig = {
|
|
|
4
4
|
brand: string;
|
|
5
5
|
apiBaseUrl?: string;
|
|
6
6
|
locale?: string;
|
|
7
|
+
country?: string;
|
|
7
8
|
};
|
|
8
9
|
type Params = {
|
|
9
10
|
page: number;
|
|
10
11
|
pageSize: number;
|
|
11
12
|
};
|
|
12
|
-
declare function useActivities({ userId, brand, apiBaseUrl, locale }: UseActivitiesConfig, { page, pageSize }: Params): {
|
|
13
|
+
declare function useActivities({ userId, brand, apiBaseUrl, locale, country }: UseActivitiesConfig, { page, pageSize }: Params): {
|
|
13
14
|
activities: CreditLogResponse[];
|
|
14
15
|
isLoading: boolean;
|
|
15
16
|
total: number;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var S=Object.create;var
|
|
1
|
+
"use strict";var S=Object.create;var g=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var M=(t,e)=>{for(var i in e)g(t,i,{get:e[i],enumerable:!0})},C=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of U(e))!x.call(t,r)&&r!==i&&g(t,r,{get:()=>e[r],enumerable:!(n=T(e,r))||n.enumerable});return t};var N=(t,e,i)=>(i=t!=null?S(_(t)):{},C(e||!t||!t.__esModule?g(i,"default",{value:t,enumerable:!0}):i,t)),O=t=>C(g({},"__esModule",{value:!0}),t);var w={};M(w,{default:()=>j});module.exports=O(w);var s=require("react"),A=N(require("swr/mutation")),P=require("../../../../credits/context/utils"),v=require("../../../../credits/context/const");function b({userId:t,brand:e,apiBaseUrl:i,locale:n="",country:r},{page:o,pageSize:p}){const[f,h]=(0,s.useState)([]),[m,L]=(0,s.useState)(0),[d,R]=(0,s.useState)(0),{isMutating:c,trigger:y}=(0,A.default)("/v1/credit/log",async(a,{arg:u})=>(await fetch((0,P.getAlpcPath)(n,i)+a,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","current-language":n},body:JSON.stringify(u)})).json()),l=(0,s.useCallback)(async()=>{await y({page:o,page_size:p,user_id:t,brand:e,country:r||v.ALPC_COUNTRY_MAP.get(n)||n},{onSuccess(a){R(o),L(a?.data?.total??0),h(u=>u.concat(a?.data?.creditLogs??[]))}})},[o,p,t,e,y]);return(0,s.useEffect)(()=>{!t||!e||c||o===d||l()},[l,t,e,o,d,c]),{activities:f,isLoading:c,total:m,canNext:m>f.length&&!c}}var j=b;
|
|
2
2
|
//# sourceMappingURL=useActivities.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/components/memberPopup/panels/EarnCredits/hooks/useActivities.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport useSWRMutation from 'swr/mutation'\nimport { getAlpcPath } from '../../../../credits/context/utils'\nimport type { CreditLogResponse } from '../../../../credits/context/response'\n\ntype UseActivitiesConfig = {\n userId: string | undefined\n brand: string\n apiBaseUrl?: string\n locale?: string\n}\n\ntype Params = {\n page: number\n pageSize: number\n}\n\nfunction useActivities(\n { userId, brand, apiBaseUrl, locale = '' }: UseActivitiesConfig,\n { page, pageSize }: Params\n) {\n const [activities, setActivities] = useState<CreditLogResponse[]>([])\n const [total, setTotal] = useState(0)\n const [currentPage, setCurrentPage] = useState(0)\n\n const { isMutating: isLoading, trigger } = useSWRMutation(\n `/v1/credit/log`,\n async (url: string, { arg }: { arg: Record<string, any> }) => {\n const response = await fetch(getAlpcPath(locale, apiBaseUrl) + url, {\n method: 'POST',\n credentials: 'include',\n headers: { 'Content-Type': 'application/json', 'current-language': locale },\n body: JSON.stringify(arg),\n })\n return response.json()\n }\n )\n\n const fetchActivities = useCallback(async () => {\n await trigger(\n { page, page_size: pageSize, user_id: userId, brand },\n {\n onSuccess(data) {\n setCurrentPage(page)\n setTotal(data?.data?.total ?? 0)\n setActivities(prev => prev.concat(data?.data?.creditLogs ?? []))\n },\n }\n )\n }, [page, pageSize, userId, brand, trigger])\n\n useEffect(() => {\n if (!userId || !brand || isLoading || page === currentPage) return\n fetchActivities()\n }, [fetchActivities, userId, brand, page, currentPage, isLoading])\n\n return {\n activities,\n isLoading,\n total,\n canNext: total > activities.length && !isLoading,\n }\n}\n\nexport default useActivities\n"],
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiD,iBACjDC,EAA2B,2BAC3BC,EAA4B,
|
|
6
|
-
"names": ["useActivities_exports", "__export", "useActivities_default", "__toCommonJS", "import_react", "import_mutation", "import_utils", "useActivities", "userId", "brand", "apiBaseUrl", "locale", "page", "pageSize", "activities", "setActivities", "total", "setTotal", "currentPage", "setCurrentPage", "isLoading", "trigger", "useSWRMutation", "url", "arg", "fetchActivities", "data", "prev"]
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport useSWRMutation from 'swr/mutation'\nimport { getAlpcPath } from '../../../../credits/context/utils'\nimport type { CreditLogResponse } from '../../../../credits/context/response'\nimport { ALPC_COUNTRY_MAP } from '../../../../credits/context/const'\n\ntype UseActivitiesConfig = {\n userId: string | undefined\n brand: string\n apiBaseUrl?: string\n locale?: string\n country?: string\n}\n\ntype Params = {\n page: number\n pageSize: number\n}\n\nfunction useActivities(\n { userId, brand, apiBaseUrl, locale = '', country }: UseActivitiesConfig,\n { page, pageSize }: Params\n) {\n const [activities, setActivities] = useState<CreditLogResponse[]>([])\n const [total, setTotal] = useState(0)\n const [currentPage, setCurrentPage] = useState(0)\n\n const { isMutating: isLoading, trigger } = useSWRMutation(\n `/v1/credit/log`,\n async (url: string, { arg }: { arg: Record<string, any> }) => {\n const response = await fetch(getAlpcPath(locale, apiBaseUrl) + url, {\n method: 'POST',\n credentials: 'include',\n headers: { 'Content-Type': 'application/json', 'current-language': locale },\n body: JSON.stringify(arg),\n })\n return response.json()\n }\n )\n\n const fetchActivities = useCallback(async () => {\n await trigger(\n { page, page_size: pageSize, user_id: userId, brand, country: country || ALPC_COUNTRY_MAP.get(locale) || locale },\n {\n onSuccess(data) {\n setCurrentPage(page)\n setTotal(data?.data?.total ?? 0)\n setActivities(prev => prev.concat(data?.data?.creditLogs ?? []))\n },\n }\n )\n }, [page, pageSize, userId, brand, trigger])\n\n useEffect(() => {\n if (!userId || !brand || isLoading || page === currentPage) return\n fetchActivities()\n }, [fetchActivities, userId, brand, page, currentPage, isLoading])\n\n return {\n activities,\n isLoading,\n total,\n canNext: total > activities.length && !isLoading,\n }\n}\n\nexport default useActivities\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiD,iBACjDC,EAA2B,2BAC3BC,EAA4B,6CAE5BC,EAAiC,6CAejC,SAASC,EACP,CAAE,OAAAC,EAAQ,MAAAC,EAAO,WAAAC,EAAY,OAAAC,EAAS,GAAI,QAAAC,CAAQ,EAClD,CAAE,KAAAC,EAAM,SAAAC,CAAS,EACjB,CACA,KAAM,CAACC,EAAYC,CAAa,KAAI,YAA8B,CAAC,CAAC,EAC9D,CAACC,EAAOC,CAAQ,KAAI,YAAS,CAAC,EAC9B,CAACC,EAAaC,CAAc,KAAI,YAAS,CAAC,EAE1C,CAAE,WAAYC,EAAW,QAAAC,CAAQ,KAAI,EAAAC,SACzC,iBACA,MAAOC,EAAa,CAAE,IAAAC,CAAI,KACL,MAAM,SAAM,eAAYd,EAAQD,CAAU,EAAIc,EAAK,CAClE,OAAQ,OACR,YAAa,UACb,QAAS,CAAE,eAAgB,mBAAoB,mBAAoBb,CAAO,EAC5E,KAAM,KAAK,UAAUc,CAAG,CAC1B,CAAC,GACe,KAAK,CAEzB,EAEMC,KAAkB,eAAY,SAAY,CAC9C,MAAMJ,EACJ,CAAE,KAAAT,EAAM,UAAWC,EAAU,QAASN,EAAQ,MAAAC,EAAO,QAASG,GAAW,mBAAiB,IAAID,CAAM,GAAKA,CAAO,EAChH,CACE,UAAUgB,EAAM,CACdP,EAAeP,CAAI,EACnBK,EAASS,GAAM,MAAM,OAAS,CAAC,EAC/BX,EAAcY,GAAQA,EAAK,OAAOD,GAAM,MAAM,YAAc,CAAC,CAAC,CAAC,CACjE,CACF,CACF,CACF,EAAG,CAACd,EAAMC,EAAUN,EAAQC,EAAOa,CAAO,CAAC,EAE3C,sBAAU,IAAM,CACV,CAACd,GAAU,CAACC,GAASY,GAAaR,IAASM,GAC/CO,EAAgB,CAClB,EAAG,CAACA,EAAiBlB,EAAQC,EAAOI,EAAMM,EAAaE,CAAS,CAAC,EAE1D,CACL,WAAAN,EACA,UAAAM,EACA,MAAAJ,EACA,QAASA,EAAQF,EAAW,QAAU,CAACM,CACzC,CACF,CAEA,IAAOpB,EAAQM",
|
|
6
|
+
"names": ["useActivities_exports", "__export", "useActivities_default", "__toCommonJS", "import_react", "import_mutation", "import_utils", "import_const", "useActivities", "userId", "brand", "apiBaseUrl", "locale", "country", "page", "pageSize", "activities", "setActivities", "total", "setTotal", "currentPage", "setCurrentPage", "isLoading", "trigger", "useSWRMutation", "url", "arg", "fetchActivities", "data", "prev"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useCallback as
|
|
1
|
+
import{useCallback as y,useEffect as P,useState as i}from"react";import{useAlpcMutation as x}from"./useAlpcFetch";import{ALPC_COUNTRY_MAP as R}from"../const";import{useCreditsContext as M}from"../provider";import{useHeadlessContext as h}from"@anker-in/lib";function z({page:t,pageSize:n,options:a={}}){const{profile:e,isLoadingProfile:c,alpcBrand:f,alpcCountry:C}=M(),{brand:b,locale:u}=h(),o=f||b,[r,L]=i([]),[d,_]=i(0),[l,A]=i(0),{isMutating:s,trigger:m}=x({url:"/v1/credit/log",initData:{brand:o,country:C||R.get(u)||u}}),g=y(async()=>{const v={page:t,page_size:n,user_id:e?.user_id,...a};m(v,{onSuccess(p){A(t),_(p?.data?.total),L(r.concat(p?.data?.creditLogs||[]))}})},[r,e,t,n,a,m]);return P(()=>{c||!e||!o||s||t!==l&&t&&g()},[g,c,s,e,o,t,l]),{activities:r,isLoading:s,total:d,canNext:d>r.length&&!s}}var E=z;export{E 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 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,
|
|
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"]
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\n\nimport { useAlpcMutation } from './useAlpcFetch'\nimport type { CreditLogResponse } from '../response'\nimport { ALPC_COUNTRY_MAP } from '../const'\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, alpcCountry } = useCreditsContext()\n const { brand: headlessBrand, locale } = 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 country: alpcCountry || ALPC_COUNTRY_MAP.get(locale) || locale,\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,oBAAAC,MAAwB,WACjC,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,EAAW,YAAAC,CAAY,EAAIT,EAAkB,EAC1E,CAAE,MAAOU,EAAe,OAAAC,CAAO,EAAIV,EAAmB,EACtDW,EAAQJ,GAAaE,EACrB,CAACG,EAAYC,CAAa,EAAIjB,EAA8B,CAAC,CAAC,EAC9D,CAACkB,EAAOC,CAAQ,EAAInB,EAAS,CAAC,EAE9B,CAACoB,EAAaC,CAAc,EAAIrB,EAAS,CAAC,EAE1C,CAAE,WAAYsB,EAAW,QAAAC,CAAQ,EAAItB,EAYzC,CACA,IAAK,iBACL,SAAU,CACR,MAAAc,EACA,QAASH,GAAeV,EAAiB,IAAIY,CAAM,GAAKA,CAC1D,CACF,CAAC,EAEKU,EAAgB1B,EAAY,SAAY,CAC5C,MAAM2B,EAAS,CACb,KAAMnB,EACN,UAAWC,EACX,QAASE,GAAS,QAClB,GAAGD,CACL,EAEAe,EAAQE,EAAQ,CACd,UAAUC,EAAc,CACtBL,EAAef,CAAI,EACnBa,EAASO,GAAc,MAAM,KAAK,EAClCT,EAAcD,EAAW,OAAOU,GAAc,MAAM,YAAc,CAAC,CAAC,CAAC,CACvE,CACF,CAAC,CACH,EAAG,CAACV,EAAYP,EAASH,EAAMC,EAAUC,EAASe,CAAO,CAAC,EAE1D,OAAAxB,EAAU,IAAM,CACVW,GAAoB,CAACD,GAAW,CAACM,GAASO,GAI1ChB,IAASc,GAAed,GAC1BkB,EAAc,CAElB,EAAG,CAACA,EAAed,EAAkBY,EAAWb,EAASM,EAAOT,EAAMc,CAAW,CAAC,EAE3E,CACL,WAAAJ,EACA,UAAAM,EACA,MAAAJ,EACA,QAASA,EAAQF,EAAW,QAAU,CAACM,CACzC,CACF,CAEA,IAAOK,EAAQtB",
|
|
6
|
+
"names": ["useCallback", "useEffect", "useState", "useAlpcMutation", "ALPC_COUNTRY_MAP", "useCreditsContext", "useHeadlessContext", "useActivities", "page", "pageSize", "options", "profile", "isLoadingProfile", "alpcBrand", "alpcCountry", "headlessBrand", "locale", "brand", "activities", "setActivities", "total", "setTotal", "currentPage", "setCurrentPage", "isLoading", "trigger", "getActivities", "params", "responseData", "useActivities_default"]
|
|
7
7
|
}
|
|
@@ -4,12 +4,13 @@ type UseActivitiesConfig = {
|
|
|
4
4
|
brand: string;
|
|
5
5
|
apiBaseUrl?: string;
|
|
6
6
|
locale?: string;
|
|
7
|
+
country?: string;
|
|
7
8
|
};
|
|
8
9
|
type Params = {
|
|
9
10
|
page: number;
|
|
10
11
|
pageSize: number;
|
|
11
12
|
};
|
|
12
|
-
declare function useActivities({ userId, brand, apiBaseUrl, locale }: UseActivitiesConfig, { page, pageSize }: Params): {
|
|
13
|
+
declare function useActivities({ userId, brand, apiBaseUrl, locale, country }: UseActivitiesConfig, { page, pageSize }: Params): {
|
|
13
14
|
activities: CreditLogResponse[];
|
|
14
15
|
isLoading: boolean;
|
|
15
16
|
total: number;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useCallback as
|
|
1
|
+
import{useCallback as P,useEffect as v,useState as c}from"react";import h from"swr/mutation";import{getAlpcPath as L}from"../../../../credits/context/utils";import{ALPC_COUNTRY_MAP as R}from"../../../../credits/context/const";function S({userId:e,brand:i,apiBaseUrl:d,locale:s="",country:y},{page:t,pageSize:a}){const[g,l]=c([]),[u,C]=c(0),[p,A]=c(0),{isMutating:n,trigger:f}=h("/v1/credit/log",async(r,{arg:o})=>(await fetch(L(s,d)+r,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","current-language":s},body:JSON.stringify(o)})).json()),m=P(async()=>{await f({page:t,page_size:a,user_id:e,brand:i,country:y||R.get(s)||s},{onSuccess(r){A(t),C(r?.data?.total??0),l(o=>o.concat(r?.data?.creditLogs??[]))}})},[t,a,e,i,f]);return v(()=>{!e||!i||n||t===p||m()},[m,e,i,t,p,n]),{activities:g,isLoading:n,total:u,canNext:u>g.length&&!n}}var N=S;export{N as default};
|
|
2
2
|
//# sourceMappingURL=useActivities.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/components/memberPopup/panels/EarnCredits/hooks/useActivities.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport useSWRMutation from 'swr/mutation'\nimport { getAlpcPath } from '../../../../credits/context/utils'\nimport type { CreditLogResponse } from '../../../../credits/context/response'\n\ntype UseActivitiesConfig = {\n userId: string | undefined\n brand: string\n apiBaseUrl?: string\n locale?: string\n}\n\ntype Params = {\n page: number\n pageSize: number\n}\n\nfunction useActivities(\n { userId, brand, apiBaseUrl, locale = '' }: UseActivitiesConfig,\n { page, pageSize }: Params\n) {\n const [activities, setActivities] = useState<CreditLogResponse[]>([])\n const [total, setTotal] = useState(0)\n const [currentPage, setCurrentPage] = useState(0)\n\n const { isMutating: isLoading, trigger } = useSWRMutation(\n `/v1/credit/log`,\n async (url: string, { arg }: { arg: Record<string, any> }) => {\n const response = await fetch(getAlpcPath(locale, apiBaseUrl) + url, {\n method: 'POST',\n credentials: 'include',\n headers: { 'Content-Type': 'application/json', 'current-language': locale },\n body: JSON.stringify(arg),\n })\n return response.json()\n }\n )\n\n const fetchActivities = useCallback(async () => {\n await trigger(\n { page, page_size: pageSize, user_id: userId, brand },\n {\n onSuccess(data) {\n setCurrentPage(page)\n setTotal(data?.data?.total ?? 0)\n setActivities(prev => prev.concat(data?.data?.creditLogs ?? []))\n },\n }\n )\n }, [page, pageSize, userId, brand, trigger])\n\n useEffect(() => {\n if (!userId || !brand || isLoading || page === currentPage) return\n fetchActivities()\n }, [fetchActivities, userId, brand, page, currentPage, isLoading])\n\n return {\n activities,\n isLoading,\n total,\n canNext: total > activities.length && !isLoading,\n }\n}\n\nexport default useActivities\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QACjD,OAAOC,MAAoB,eAC3B,OAAS,eAAAC,MAAmB,
|
|
6
|
-
"names": ["useCallback", "useEffect", "useState", "useSWRMutation", "getAlpcPath", "useActivities", "userId", "brand", "apiBaseUrl", "locale", "page", "pageSize", "activities", "setActivities", "total", "setTotal", "currentPage", "setCurrentPage", "isLoading", "trigger", "url", "arg", "fetchActivities", "data", "prev", "useActivities_default"]
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useState } from 'react'\nimport useSWRMutation from 'swr/mutation'\nimport { getAlpcPath } from '../../../../credits/context/utils'\nimport type { CreditLogResponse } from '../../../../credits/context/response'\nimport { ALPC_COUNTRY_MAP } from '../../../../credits/context/const'\n\ntype UseActivitiesConfig = {\n userId: string | undefined\n brand: string\n apiBaseUrl?: string\n locale?: string\n country?: string\n}\n\ntype Params = {\n page: number\n pageSize: number\n}\n\nfunction useActivities(\n { userId, brand, apiBaseUrl, locale = '', country }: UseActivitiesConfig,\n { page, pageSize }: Params\n) {\n const [activities, setActivities] = useState<CreditLogResponse[]>([])\n const [total, setTotal] = useState(0)\n const [currentPage, setCurrentPage] = useState(0)\n\n const { isMutating: isLoading, trigger } = useSWRMutation(\n `/v1/credit/log`,\n async (url: string, { arg }: { arg: Record<string, any> }) => {\n const response = await fetch(getAlpcPath(locale, apiBaseUrl) + url, {\n method: 'POST',\n credentials: 'include',\n headers: { 'Content-Type': 'application/json', 'current-language': locale },\n body: JSON.stringify(arg),\n })\n return response.json()\n }\n )\n\n const fetchActivities = useCallback(async () => {\n await trigger(\n { page, page_size: pageSize, user_id: userId, brand, country: country || ALPC_COUNTRY_MAP.get(locale) || locale },\n {\n onSuccess(data) {\n setCurrentPage(page)\n setTotal(data?.data?.total ?? 0)\n setActivities(prev => prev.concat(data?.data?.creditLogs ?? []))\n },\n }\n )\n }, [page, pageSize, userId, brand, trigger])\n\n useEffect(() => {\n if (!userId || !brand || isLoading || page === currentPage) return\n fetchActivities()\n }, [fetchActivities, userId, brand, page, currentPage, isLoading])\n\n return {\n activities,\n isLoading,\n total,\n canNext: total > activities.length && !isLoading,\n }\n}\n\nexport default useActivities\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,YAAAC,MAAgB,QACjD,OAAOC,MAAoB,eAC3B,OAAS,eAAAC,MAAmB,oCAE5B,OAAS,oBAAAC,MAAwB,oCAejC,SAASC,EACP,CAAE,OAAAC,EAAQ,MAAAC,EAAO,WAAAC,EAAY,OAAAC,EAAS,GAAI,QAAAC,CAAQ,EAClD,CAAE,KAAAC,EAAM,SAAAC,CAAS,EACjB,CACA,KAAM,CAACC,EAAYC,CAAa,EAAIb,EAA8B,CAAC,CAAC,EAC9D,CAACc,EAAOC,CAAQ,EAAIf,EAAS,CAAC,EAC9B,CAACgB,EAAaC,CAAc,EAAIjB,EAAS,CAAC,EAE1C,CAAE,WAAYkB,EAAW,QAAAC,CAAQ,EAAIlB,EACzC,iBACA,MAAOmB,EAAa,CAAE,IAAAC,CAAI,KACL,MAAM,MAAMnB,EAAYM,EAAQD,CAAU,EAAIa,EAAK,CAClE,OAAQ,OACR,YAAa,UACb,QAAS,CAAE,eAAgB,mBAAoB,mBAAoBZ,CAAO,EAC5E,KAAM,KAAK,UAAUa,CAAG,CAC1B,CAAC,GACe,KAAK,CAEzB,EAEMC,EAAkBxB,EAAY,SAAY,CAC9C,MAAMqB,EACJ,CAAE,KAAAT,EAAM,UAAWC,EAAU,QAASN,EAAQ,MAAAC,EAAO,QAASG,GAAWN,EAAiB,IAAIK,CAAM,GAAKA,CAAO,EAChH,CACE,UAAUe,EAAM,CACdN,EAAeP,CAAI,EACnBK,EAASQ,GAAM,MAAM,OAAS,CAAC,EAC/BV,EAAcW,GAAQA,EAAK,OAAOD,GAAM,MAAM,YAAc,CAAC,CAAC,CAAC,CACjE,CACF,CACF,CACF,EAAG,CAACb,EAAMC,EAAUN,EAAQC,EAAOa,CAAO,CAAC,EAE3C,OAAApB,EAAU,IAAM,CACV,CAACM,GAAU,CAACC,GAASY,GAAaR,IAASM,GAC/CM,EAAgB,CAClB,EAAG,CAACA,EAAiBjB,EAAQC,EAAOI,EAAMM,EAAaE,CAAS,CAAC,EAE1D,CACL,WAAAN,EACA,UAAAM,EACA,MAAAJ,EACA,QAASA,EAAQF,EAAW,QAAU,CAACM,CACzC,CACF,CAEA,IAAOO,EAAQrB",
|
|
6
|
+
"names": ["useCallback", "useEffect", "useState", "useSWRMutation", "getAlpcPath", "ALPC_COUNTRY_MAP", "useActivities", "userId", "brand", "apiBaseUrl", "locale", "country", "page", "pageSize", "activities", "setActivities", "total", "setTotal", "currentPage", "setCurrentPage", "isLoading", "trigger", "url", "arg", "fetchActivities", "data", "prev", "useActivities_default"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -2,12 +2,13 @@ import { useCallback, useEffect, useState } from 'react'
|
|
|
2
2
|
|
|
3
3
|
import { useAlpcMutation } from './useAlpcFetch'
|
|
4
4
|
import type { CreditLogResponse } from '../response'
|
|
5
|
+
import { ALPC_COUNTRY_MAP } from '../const'
|
|
5
6
|
import { useCreditsContext } from '../provider'
|
|
6
7
|
import { useHeadlessContext } from '@anker-in/lib'
|
|
7
8
|
|
|
8
9
|
function useActivities({ page, pageSize, options = {} }: { page: number; pageSize: number; options?: any }) {
|
|
9
|
-
const { profile, isLoadingProfile, alpcBrand } = useCreditsContext()
|
|
10
|
-
const { brand: headlessBrand } = useHeadlessContext()
|
|
10
|
+
const { profile, isLoadingProfile, alpcBrand, alpcCountry } = useCreditsContext()
|
|
11
|
+
const { brand: headlessBrand, locale } = useHeadlessContext()
|
|
11
12
|
const brand = alpcBrand || headlessBrand
|
|
12
13
|
const [activities, setActivities] = useState<CreditLogResponse[]>([])
|
|
13
14
|
const [total, setTotal] = useState(0)
|
|
@@ -30,6 +31,7 @@ function useActivities({ page, pageSize, options = {} }: { page: number; pageSiz
|
|
|
30
31
|
url: `/v1/credit/log`,
|
|
31
32
|
initData: {
|
|
32
33
|
brand,
|
|
34
|
+
country: alpcCountry || ALPC_COUNTRY_MAP.get(locale) || locale,
|
|
33
35
|
},
|
|
34
36
|
})
|
|
35
37
|
|
|
@@ -2,12 +2,14 @@ import { useCallback, useEffect, useState } from 'react'
|
|
|
2
2
|
import useSWRMutation from 'swr/mutation'
|
|
3
3
|
import { getAlpcPath } from '../../../../credits/context/utils'
|
|
4
4
|
import type { CreditLogResponse } from '../../../../credits/context/response'
|
|
5
|
+
import { ALPC_COUNTRY_MAP } from '../../../../credits/context/const'
|
|
5
6
|
|
|
6
7
|
type UseActivitiesConfig = {
|
|
7
8
|
userId: string | undefined
|
|
8
9
|
brand: string
|
|
9
10
|
apiBaseUrl?: string
|
|
10
11
|
locale?: string
|
|
12
|
+
country?: string
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
type Params = {
|
|
@@ -16,7 +18,7 @@ type Params = {
|
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
function useActivities(
|
|
19
|
-
{ userId, brand, apiBaseUrl, locale = '' }: UseActivitiesConfig,
|
|
21
|
+
{ userId, brand, apiBaseUrl, locale = '', country }: UseActivitiesConfig,
|
|
20
22
|
{ page, pageSize }: Params
|
|
21
23
|
) {
|
|
22
24
|
const [activities, setActivities] = useState<CreditLogResponse[]>([])
|
|
@@ -38,7 +40,7 @@ function useActivities(
|
|
|
38
40
|
|
|
39
41
|
const fetchActivities = useCallback(async () => {
|
|
40
42
|
await trigger(
|
|
41
|
-
{ page, page_size: pageSize, user_id: userId, brand },
|
|
43
|
+
{ page, page_size: pageSize, user_id: userId, brand, country: country || ALPC_COUNTRY_MAP.get(locale) || locale },
|
|
42
44
|
{
|
|
43
45
|
onSuccess(data) {
|
|
44
46
|
setCurrentPage(page)
|