@greatapps/common 1.1.441 → 1.1.442
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/modules/plans/actions/list-plans.action.mjs +1 -10
- package/dist/modules/plans/actions/list-plans.action.mjs.map +1 -1
- package/dist/modules/plans/hooks/list-plans.hook.mjs.map +1 -1
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs +6 -3
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs.map +1 -1
- package/package.json +1 -1
- package/src/modules/plans/actions/list-plans.action.ts +2 -13
- package/src/modules/plans/hooks/list-plans.hook.ts +2 -2
- package/src/modules/plans/hooks/use-plan-by-id.hook.ts +9 -7
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { plansService, safeServerAction } from "@greatapps/common/server";
|
|
3
|
-
import { mapApiPlanToUiPlan } from "../utils/map-api-plan-to-ui";
|
|
4
3
|
async function listPlansAction() {
|
|
5
4
|
return safeServerAction(async () => {
|
|
6
5
|
const { data: apiPlans } = await plansService.listPlans({
|
|
@@ -9,15 +8,7 @@ async function listPlansAction() {
|
|
|
9
8
|
sort: "id:ASC"
|
|
10
9
|
});
|
|
11
10
|
if (!apiPlans?.length) return [];
|
|
12
|
-
|
|
13
|
-
return sorted.map((plan) => {
|
|
14
|
-
const popular = plan.id === 2 || plan.id_plan === 2;
|
|
15
|
-
return mapApiPlanToUiPlan(plan, {
|
|
16
|
-
planId: plan.id_plan ?? plan.id,
|
|
17
|
-
isPopular: popular,
|
|
18
|
-
buttonVariant: popular ? "brand" : void 0
|
|
19
|
-
});
|
|
20
|
-
});
|
|
11
|
+
return [...apiPlans].sort((a, b) => a.value - b.value);
|
|
21
12
|
});
|
|
22
13
|
}
|
|
23
14
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/plans/actions/list-plans.action.ts"],"sourcesContent":["'use server';\n\nimport { plansService, safeServerAction } from '@greatapps/common/server';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/plans/actions/list-plans.action.ts"],"sourcesContent":["'use server';\n\nimport { plansService, safeServerAction } from '@greatapps/common/server';\n\nexport async function listPlansAction() {\n return safeServerAction(async () => {\n const { data: apiPlans } = await plansService.listPlans({\n active: true,\n search: 'client',\n sort: 'id:ASC',\n });\n\n if (!apiPlans?.length) return [];\n\n return [...apiPlans].sort((a, b) => a.value - b.value);\n });\n}\n"],"mappings":";AAEA,SAAS,cAAc,wBAAwB;AAE/C,eAAsB,kBAAkB;AACtC,SAAO,iBAAiB,YAAY;AAClC,UAAM,EAAE,MAAM,SAAS,IAAI,MAAM,aAAa,UAAU;AAAA,MACtD,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,MAAM;AAAA,IACR,CAAC;AAED,QAAI,CAAC,UAAU,OAAQ,QAAO,CAAC;AAE/B,WAAO,CAAC,GAAG,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AAAA,EACvD,CAAC;AACH;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/plans/hooks/list-plans.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { withAction } from '@greatapps/common';\nimport { listPlansAction } from '../actions/list-plans.action';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/plans/hooks/list-plans.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { withAction } from '@greatapps/common';\nimport { listPlansAction } from '../actions/list-plans.action';\nimport type { Plan } from '../types/plan.type';\n\nexport const PLANS_QUERY_KEY = ['plans'];\n\nexport function usePlans() {\n return useQuery<Plan[]>({\n queryKey: [...PLANS_QUERY_KEY],\n queryFn: withAction(listPlansAction),\n staleTime: Infinity,\n gcTime: Infinity,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n refetchOnMount: false,\n retry: 1,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAGzB,MAAM,kBAAkB,CAAC,OAAO;AAEhC,SAAS,WAAW;AACzB,SAAO,SAAiB;AAAA,IACtB,UAAU,CAAC,GAAG,eAAe;AAAA,IAC7B,SAAS,WAAW,eAAe;AAAA,IACnC,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,sBAAsB;AAAA,IACtB,oBAAoB;AAAA,IACpB,gBAAgB;AAAA,IAChB,OAAO;AAAA,EACT,CAAC;AACH;","names":[]}
|
|
@@ -13,10 +13,13 @@ function usePlanById(idPlan) {
|
|
|
13
13
|
queryKey: [...PLANS_QUERY_KEY]
|
|
14
14
|
});
|
|
15
15
|
for (const [, data] of queries) {
|
|
16
|
-
if (!data) continue;
|
|
17
|
-
const
|
|
16
|
+
if (!data || !Array.isArray(data)) continue;
|
|
17
|
+
const numericId = Number(idPlan);
|
|
18
|
+
const plan = data.find(
|
|
19
|
+
(p) => p.id === numericId || p.id_plan === numericId
|
|
20
|
+
);
|
|
18
21
|
if (plan) {
|
|
19
|
-
return plan;
|
|
22
|
+
return { success: true, data: plan };
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
return void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/plans/hooks/use-plan-by-id.hook.ts"],"sourcesContent":["\"use client\";\n\nimport { useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport { withAction } from \"../../../utils/withAction\";\nimport { findPlanByIdAction } from \"../actions/find-plan-by-id.action\";\nimport { Plan } from \"../types/plan.type\";\nimport { PLANS_QUERY_KEY } from \"./list-plans.hook\";\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/plans/hooks/use-plan-by-id.hook.ts"],"sourcesContent":["\"use client\";\n\nimport { useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport { withAction } from \"../../../utils/withAction\";\nimport { findPlanByIdAction } from \"../actions/find-plan-by-id.action\";\nimport type { Plan } from \"../types/plan.type\";\nimport { PLANS_QUERY_KEY } from \"./list-plans.hook\";\n\nexport function usePlanById(idPlan: number | string | undefined) {\n const queryClient = useQueryClient();\n\n return useQuery({\n queryKey: [...PLANS_QUERY_KEY, idPlan],\n queryFn: withAction(() => findPlanByIdAction(idPlan!)),\n initialData: () => {\n const queries = queryClient.getQueriesData<Plan[]>({\n queryKey: [...PLANS_QUERY_KEY],\n });\n\n for (const [, data] of queries) {\n if (!data || !Array.isArray(data)) continue;\n const numericId = Number(idPlan);\n const plan = data.find(\n (p) => p.id === numericId || p.id_plan === numericId\n );\n if (plan) {\n return { success: true as const, data: plan };\n }\n }\n\n return undefined;\n },\n initialDataUpdatedAt: 0,\n enabled: !!idPlan,\n });\n}\n"],"mappings":";AAEA,SAAS,UAAU,sBAAsB;AACzC,SAAS,kBAAkB;AAC3B,SAAS,0BAA0B;AAEnC,SAAS,uBAAuB;AAEzB,SAAS,YAAY,QAAqC;AAC/D,QAAM,cAAc,eAAe;AAEnC,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,GAAG,iBAAiB,MAAM;AAAA,IACrC,SAAS,WAAW,MAAM,mBAAmB,MAAO,CAAC;AAAA,IACrD,aAAa,MAAM;AACjB,YAAM,UAAU,YAAY,eAAuB;AAAA,QACjD,UAAU,CAAC,GAAG,eAAe;AAAA,MAC/B,CAAC;AAED,iBAAW,CAAC,EAAE,IAAI,KAAK,SAAS;AAC9B,YAAI,CAAC,QAAQ,CAAC,MAAM,QAAQ,IAAI,EAAG;AACnC,cAAM,YAAY,OAAO,MAAM;AAC/B,cAAM,OAAO,KAAK;AAAA,UAChB,CAAC,MAAM,EAAE,OAAO,aAAa,EAAE,YAAY;AAAA,QAC7C;AACA,YAAI,MAAM;AACR,iBAAO,EAAE,SAAS,MAAe,MAAM,KAAK;AAAA,QAC9C;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,IACA,sBAAsB;AAAA,IACtB,SAAS,CAAC,CAAC;AAAA,EACb,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
3
|
import { plansService, safeServerAction } from '@greatapps/common/server';
|
|
4
|
-
import type { UiPlan } from '../types/plan.type';
|
|
5
|
-
import { mapApiPlanToUiPlan } from '../utils/map-api-plan-to-ui';
|
|
6
4
|
|
|
7
5
|
export async function listPlansAction() {
|
|
8
6
|
return safeServerAction(async () => {
|
|
@@ -12,17 +10,8 @@ export async function listPlansAction() {
|
|
|
12
10
|
sort: 'id:ASC',
|
|
13
11
|
});
|
|
14
12
|
|
|
15
|
-
if (!apiPlans?.length) return []
|
|
13
|
+
if (!apiPlans?.length) return [];
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return sorted.map((plan) => {
|
|
20
|
-
const popular = plan.id === 2 || plan.id_plan === 2;
|
|
21
|
-
return mapApiPlanToUiPlan(plan, {
|
|
22
|
-
planId: plan.id_plan ?? plan.id,
|
|
23
|
-
isPopular: popular,
|
|
24
|
-
buttonVariant: popular ? 'brand' : undefined,
|
|
25
|
-
});
|
|
26
|
-
});
|
|
15
|
+
return [...apiPlans].sort((a, b) => a.value - b.value);
|
|
27
16
|
});
|
|
28
17
|
}
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query';
|
|
4
4
|
import { withAction } from '@greatapps/common';
|
|
5
5
|
import { listPlansAction } from '../actions/list-plans.action';
|
|
6
|
-
import type {
|
|
6
|
+
import type { Plan } from '../types/plan.type';
|
|
7
7
|
|
|
8
8
|
export const PLANS_QUERY_KEY = ['plans'];
|
|
9
9
|
|
|
10
10
|
export function usePlans() {
|
|
11
|
-
return useQuery<
|
|
11
|
+
return useQuery<Plan[]>({
|
|
12
12
|
queryKey: [...PLANS_QUERY_KEY],
|
|
13
13
|
queryFn: withAction(listPlansAction),
|
|
14
14
|
staleTime: Infinity,
|
|
@@ -3,26 +3,28 @@
|
|
|
3
3
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
4
|
import { withAction } from "../../../utils/withAction";
|
|
5
5
|
import { findPlanByIdAction } from "../actions/find-plan-by-id.action";
|
|
6
|
-
import { Plan } from "../types/plan.type";
|
|
6
|
+
import type { Plan } from "../types/plan.type";
|
|
7
7
|
import { PLANS_QUERY_KEY } from "./list-plans.hook";
|
|
8
|
-
import { PaginatedSuccessResult } from "../../../infra/api/types";
|
|
9
8
|
|
|
10
9
|
export function usePlanById(idPlan: number | string | undefined) {
|
|
11
10
|
const queryClient = useQueryClient();
|
|
12
|
-
|
|
11
|
+
|
|
13
12
|
return useQuery({
|
|
14
13
|
queryKey: [...PLANS_QUERY_KEY, idPlan],
|
|
15
14
|
queryFn: withAction(() => findPlanByIdAction(idPlan!)),
|
|
16
15
|
initialData: () => {
|
|
17
|
-
const queries = queryClient.getQueriesData<
|
|
16
|
+
const queries = queryClient.getQueriesData<Plan[]>({
|
|
18
17
|
queryKey: [...PLANS_QUERY_KEY],
|
|
19
18
|
});
|
|
20
19
|
|
|
21
20
|
for (const [, data] of queries) {
|
|
22
|
-
if (!data) continue;
|
|
23
|
-
const
|
|
21
|
+
if (!data || !Array.isArray(data)) continue;
|
|
22
|
+
const numericId = Number(idPlan);
|
|
23
|
+
const plan = data.find(
|
|
24
|
+
(p) => p.id === numericId || p.id_plan === numericId
|
|
25
|
+
);
|
|
24
26
|
if (plan) {
|
|
25
|
-
return plan;
|
|
27
|
+
return { success: true as const, data: plan };
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
|