@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.
@@ -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
- const sorted = [...apiPlans].sort((a, b) => a.value - b.value);
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';\nimport type { UiPlan } from '../types/plan.type';\nimport { mapApiPlanToUiPlan } from '../utils/map-api-plan-to-ui';\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 [] as UiPlan[];\n\n const sorted = [...apiPlans].sort((a, b) => a.value - b.value);\n\n return sorted.map((plan) => {\n const popular = plan.id === 2 || plan.id_plan === 2;\n return mapApiPlanToUiPlan(plan, {\n planId: plan.id_plan ?? plan.id,\n isPopular: popular,\n buttonVariant: popular ? 'brand' : undefined,\n });\n });\n });\n}\n"],"mappings":";AAEA,SAAS,cAAc,wBAAwB;AAE/C,SAAS,0BAA0B;AAEnC,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,UAAM,SAAS,CAAC,GAAG,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AAE7D,WAAO,OAAO,IAAI,CAAC,SAAS;AAC1B,YAAM,UAAU,KAAK,OAAO,KAAK,KAAK,YAAY;AAClD,aAAO,mBAAmB,MAAM;AAAA,QAC9B,QAAQ,KAAK,WAAW,KAAK;AAAA,QAC7B,WAAW;AAAA,QACX,eAAe,UAAU,UAAU;AAAA,MACrC,CAAC;AAAA,IACH,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
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 { UiPlan } from '../types/plan.type';\n\nexport const PLANS_QUERY_KEY = ['plans'];\n\nexport function usePlans() {\n return useQuery<UiPlan[]>({\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,SAAmB;AAAA,IACxB,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":[]}
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 plan = (Array.isArray(data) ? data : data.data)?.find((p) => p.idPlan === idPlan);
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\";\nimport { PaginatedSuccessResult } from \"../../../infra/api/types\";\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<PaginatedSuccessResult<Plan>>({\n queryKey: [...PLANS_QUERY_KEY],\n });\n\n for (const [, data] of queries) {\n if (!data) continue;\n const plan = (Array.isArray(data) ? data : data.data)?.find((p) => p.idPlan === idPlan);\n if (plan) {\n return 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;AAGzB,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,eAA6C;AAAA,QACvE,UAAU,CAAC,GAAG,eAAe;AAAA,MAC/B,CAAC;AAED,iBAAW,CAAC,EAAE,IAAI,KAAK,SAAS;AAC9B,YAAI,CAAC,KAAM;AACX,cAAM,QAAQ,MAAM,QAAQ,IAAI,IAAI,OAAO,KAAK,OAAO,KAAK,CAAC,MAAM,EAAE,WAAW,MAAM;AACtF,YAAI,MAAM;AACR,iBAAO;AAAA,QACT;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,IACA,sBAAsB;AAAA,IACtB,SAAS,CAAC,CAAC;AAAA,EACb,CAAC;AACH;","names":[]}
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/common",
3
- "version": "1.1.441",
3
+ "version": "1.1.442",
4
4
  "description": "Shared library for GreatApps frontend applications",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./src/index.ts",
@@ -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 [] as UiPlan[];
13
+ if (!apiPlans?.length) return [];
16
14
 
17
- const sorted = [...apiPlans].sort((a, b) => a.value - b.value);
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 { UiPlan } from '../types/plan.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<UiPlan[]>({
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<PaginatedSuccessResult<Plan>>({
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 plan = (Array.isArray(data) ? data : data.data)?.find((p) => p.idPlan === idPlan);
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