@greatapps/common 1.1.655 → 1.1.657
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/components/account/sections/TokenSection.mjs +1 -1
- package/dist/components/account/sections/TokenSection.mjs.map +1 -1
- package/dist/components/embeds/CrispEmbed.mjs +8 -20
- package/dist/components/embeds/CrispEmbed.mjs.map +1 -1
- package/dist/handlers.mjs +33 -0
- package/dist/handlers.mjs.map +1 -0
- package/dist/http.mjs +5 -0
- package/dist/http.mjs.map +1 -0
- package/dist/infra/http/api-fetch.mjs +30 -0
- package/dist/infra/http/api-fetch.mjs.map +1 -0
- package/dist/infra/route/parse-id.mjs +12 -0
- package/dist/infra/route/parse-id.mjs.map +1 -0
- package/dist/infra/route/safe-route-handler.mjs +18 -0
- package/dist/infra/route/safe-route-handler.mjs.map +1 -0
- package/dist/infra/route/search-params.mjs +11 -0
- package/dist/infra/route/search-params.mjs.map +1 -0
- package/dist/modules/cards/handlers/find-card-by-id.handler.mjs +16 -0
- package/dist/modules/cards/handlers/find-card-by-id.handler.mjs.map +1 -0
- package/dist/modules/cards/handlers/list-cards.handler.mjs +12 -0
- package/dist/modules/cards/handlers/list-cards.handler.mjs.map +1 -0
- package/dist/modules/cards/hooks/card-by-id.hook.mjs +2 -5
- package/dist/modules/cards/hooks/card-by-id.hook.mjs.map +1 -1
- package/dist/modules/cards/hooks/cards.hook.mjs +2 -5
- package/dist/modules/cards/hooks/cards.hook.mjs.map +1 -1
- package/dist/modules/charges/handlers/find-charge-by-id.handler.mjs +15 -0
- package/dist/modules/charges/handlers/find-charge-by-id.handler.mjs.map +1 -0
- package/dist/modules/charges/handlers/list-charges.handler.mjs +15 -0
- package/dist/modules/charges/handlers/list-charges.handler.mjs.map +1 -0
- package/dist/modules/charges/hooks/charge-by-id.hook.mjs +2 -3
- package/dist/modules/charges/hooks/charge-by-id.hook.mjs.map +1 -1
- package/dist/modules/charges/hooks/charges.hook.mjs +2 -3
- package/dist/modules/charges/hooks/charges.hook.mjs.map +1 -1
- package/dist/modules/ia-credits/handlers/list-ia-credits.handler.mjs +15 -0
- package/dist/modules/ia-credits/handlers/list-ia-credits.handler.mjs.map +1 -0
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs +5 -3
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs.map +1 -1
- package/dist/modules/pages/handlers/count-pages.handler.mjs +14 -0
- package/dist/modules/pages/handlers/count-pages.handler.mjs.map +1 -0
- package/dist/modules/pages/hooks/count-pages.hook.mjs +3 -4
- package/dist/modules/pages/hooks/count-pages.hook.mjs.map +1 -1
- package/dist/modules/plans/handlers/find-plan-by-id.handler.mjs +15 -0
- package/dist/modules/plans/handlers/find-plan-by-id.handler.mjs.map +1 -0
- package/dist/modules/plans/handlers/list-plans.handler.mjs +20 -0
- package/dist/modules/plans/handlers/list-plans.handler.mjs.map +1 -0
- package/dist/modules/plans/hooks/list-plans.hook.mjs +2 -3
- package/dist/modules/plans/hooks/list-plans.hook.mjs.map +1 -1
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs +2 -3
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs.map +1 -1
- package/dist/modules/projects/handlers/find-project.handler.mjs +16 -0
- package/dist/modules/projects/handlers/find-project.handler.mjs.map +1 -0
- package/dist/modules/projects/handlers/list-all-account-users.handler.mjs +17 -0
- package/dist/modules/projects/handlers/list-all-account-users.handler.mjs.map +1 -0
- package/dist/modules/projects/handlers/list-available-users.handler.mjs +20 -0
- package/dist/modules/projects/handlers/list-available-users.handler.mjs.map +1 -0
- package/dist/modules/projects/handlers/list-project-users.handler.mjs +20 -0
- package/dist/modules/projects/handlers/list-project-users.handler.mjs.map +1 -0
- package/dist/modules/projects/handlers/list-projects.handler.mjs +17 -0
- package/dist/modules/projects/handlers/list-projects.handler.mjs.map +1 -0
- package/dist/modules/projects/hooks/find-project.hook.mjs +2 -3
- package/dist/modules/projects/hooks/find-project.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-all-account-users.hook.mjs +6 -6
- package/dist/modules/projects/hooks/list-all-account-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-available-users.hook.mjs +6 -6
- package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs +6 -6
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-project-users.hook.mjs +6 -6
- package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-projects.hook.mjs +2 -3
- package/dist/modules/projects/hooks/list-projects.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/handlers/list-subscriptions.handler.mjs +17 -0
- package/dist/modules/subscriptions/handlers/list-subscriptions.handler.mjs.map +1 -0
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +5 -5
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +5 -3
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -1
- package/dist/modules/users/handlers/list-messages.handler.mjs +36 -0
- package/dist/modules/users/handlers/list-messages.handler.mjs.map +1 -0
- package/dist/modules/users/hooks/messages.hook.mjs +7 -6
- package/dist/modules/users/hooks/messages.hook.mjs.map +1 -1
- package/dist/route.mjs +9 -0
- package/dist/route.mjs.map +1 -0
- package/package.json +13 -1
- package/src/components/account/sections/TokenSection.tsx +1 -1
- package/src/components/embeds/CrispEmbed.tsx +11 -28
- package/src/handlers.ts +22 -0
- package/src/http.ts +1 -0
- package/src/infra/http/api-fetch.ts +39 -0
- package/src/infra/route/parse-id.ts +9 -0
- package/src/infra/route/safe-route-handler.ts +16 -0
- package/src/infra/route/search-params.ts +9 -0
- package/src/modules/cards/handlers/find-card-by-id.handler.ts +15 -0
- package/src/modules/cards/handlers/list-cards.handler.ts +10 -0
- package/src/modules/cards/hooks/card-by-id.hook.ts +4 -5
- package/src/modules/cards/hooks/cards.hook.ts +4 -5
- package/src/modules/charges/handlers/find-charge-by-id.handler.ts +14 -0
- package/src/modules/charges/handlers/list-charges.handler.ts +15 -0
- package/src/modules/charges/hooks/charge-by-id.hook.ts +5 -3
- package/src/modules/charges/hooks/charges.hook.ts +5 -4
- package/src/modules/ia-credits/handlers/list-ia-credits.handler.ts +14 -0
- package/src/modules/ia-credits/hooks/ia-credits.hook.ts +7 -3
- package/src/modules/pages/handlers/count-pages.handler.ts +12 -0
- package/src/modules/pages/hooks/count-pages.hook.ts +3 -4
- package/src/modules/plans/handlers/find-plan-by-id.handler.ts +14 -0
- package/src/modules/plans/handlers/list-plans.handler.ts +20 -0
- package/src/modules/plans/hooks/list-plans.hook.ts +2 -3
- package/src/modules/plans/hooks/use-plan-by-id.hook.ts +4 -3
- package/src/modules/projects/handlers/find-project.handler.ts +15 -0
- package/src/modules/projects/handlers/list-all-account-users.handler.ts +17 -0
- package/src/modules/projects/handlers/list-available-users.handler.ts +20 -0
- package/src/modules/projects/handlers/list-project-users.handler.ts +20 -0
- package/src/modules/projects/handlers/list-projects.handler.ts +17 -0
- package/src/modules/projects/hooks/find-project.hook.ts +3 -3
- package/src/modules/projects/hooks/list-all-account-users.hook.ts +8 -7
- package/src/modules/projects/hooks/list-available-users.hook.ts +8 -7
- package/src/modules/projects/hooks/list-infinite-projects.hook.ts +8 -7
- package/src/modules/projects/hooks/list-project-users.hook.ts +8 -7
- package/src/modules/projects/hooks/list-projects.hook.ts +3 -3
- package/src/modules/subscriptions/handlers/list-subscriptions.handler.ts +17 -0
- package/src/modules/subscriptions/hooks/find-active-subscription.hook.ts +8 -5
- package/src/modules/subscriptions/hooks/list-subscriptions.hook.ts +8 -5
- package/src/modules/users/handlers/list-messages.handler.ts +39 -0
- package/src/modules/users/hooks/messages.hook.ts +10 -8
- package/src/route.ts +3 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { safeRouteHandler } from "../../../infra/route/safe-route-handler";
|
|
3
|
+
import { searchParamsToParams } from "../../../infra/route/search-params";
|
|
4
|
+
import { messagesService } from "../services/messages.service";
|
|
5
|
+
import { findWhitelabel } from "../../whitelabel/actions/find-whitelabel.action";
|
|
6
|
+
function createListMessagesHandler() {
|
|
7
|
+
return async function GET(req) {
|
|
8
|
+
return safeRouteHandler(async () => {
|
|
9
|
+
const params = searchParamsToParams(req.nextUrl.searchParams);
|
|
10
|
+
const [result, whitelabel] = await Promise.all([
|
|
11
|
+
messagesService.listMessages(params),
|
|
12
|
+
findWhitelabel()
|
|
13
|
+
]);
|
|
14
|
+
const urlMap = {
|
|
15
|
+
pages_url: whitelabel?.pages_url ?? "",
|
|
16
|
+
accounts_url: whitelabel?.accounts_url ?? "",
|
|
17
|
+
editor_url: whitelabel?.editor_url ?? ""
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
data: result.data.map((message) => ({
|
|
21
|
+
...message,
|
|
22
|
+
url: message.url.replace(
|
|
23
|
+
/\{(pages_url|accounts_url|editor_url)\}/g,
|
|
24
|
+
(_, key) => urlMap[key] ?? ""
|
|
25
|
+
)
|
|
26
|
+
})),
|
|
27
|
+
total: result.total,
|
|
28
|
+
totalUnread: result.totalUnread
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
createListMessagesHandler
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=list-messages.handler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/users/handlers/list-messages.handler.ts"],"sourcesContent":["import 'server-only';\n\nimport type { NextRequest } from 'next/server';\nimport { safeRouteHandler } from '../../../infra/route/safe-route-handler';\nimport { searchParamsToParams } from '../../../infra/route/search-params';\nimport { messagesService } from '../services/messages.service';\nimport type { FindMessagesParams } from '../schema/messages.schema';\nimport { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';\n\nexport function createListMessagesHandler() {\n return async function GET(req: NextRequest) {\n return safeRouteHandler(async () => {\n const params = searchParamsToParams<FindMessagesParams>(req.nextUrl.searchParams);\n\n const [result, whitelabel] = await Promise.all([\n messagesService.listMessages(params),\n findWhitelabel(),\n ]);\n\n const urlMap: Record<string, string> = {\n pages_url: whitelabel?.pages_url ?? '',\n accounts_url: whitelabel?.accounts_url ?? '',\n editor_url: whitelabel?.editor_url ?? '',\n };\n\n return {\n data: result.data.map((message) => ({\n ...message,\n url: message.url.replace(\n /\\{(pages_url|accounts_url|editor_url)\\}/g,\n (_, key) => urlMap[key] ?? ''\n ),\n })),\n total: result.total,\n totalUnread: result.totalUnread,\n };\n });\n };\n}\n"],"mappings":"AAAA,OAAO;AAGP,SAAS,wBAAwB;AACjC,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAEhC,SAAS,sBAAsB;AAExB,SAAS,4BAA4B;AAC1C,SAAO,eAAe,IAAI,KAAkB;AAC1C,WAAO,iBAAiB,YAAY;AAClC,YAAM,SAAS,qBAAyC,IAAI,QAAQ,YAAY;AAEhF,YAAM,CAAC,QAAQ,UAAU,IAAI,MAAM,QAAQ,IAAI;AAAA,QAC7C,gBAAgB,aAAa,MAAM;AAAA,QACnC,eAAe;AAAA,MACjB,CAAC;AAED,YAAM,SAAiC;AAAA,QACrC,WAAW,YAAY,aAAa;AAAA,QACpC,cAAc,YAAY,gBAAgB;AAAA,QAC1C,YAAY,YAAY,cAAc;AAAA,MACxC;AAEA,aAAO;AAAA,QACL,MAAM,OAAO,KAAK,IAAI,CAAC,aAAa;AAAA,UAClC,GAAG;AAAA,UACH,KAAK,QAAQ,IAAI;AAAA,YACf;AAAA,YACA,CAAC,GAAG,QAAQ,OAAO,GAAG,KAAK;AAAA,UAC7B;AAAA,QACF,EAAE;AAAA,QACF,OAAO,OAAO;AAAA,QACd,aAAa,OAAO;AAAA,MACtB;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
-
import {
|
|
3
|
+
import { apiFetch } from "../../../infra/http/api-fetch";
|
|
4
4
|
import { markMessageAsReadAction } from "../action/mark-message-as-read.action";
|
|
5
5
|
import { markAllMessagesAsReadAction } from "../action/mark-all-messages-as-read.action";
|
|
6
6
|
import { withAction } from "../../../utils/withAction";
|
|
@@ -11,20 +11,21 @@ function useMessages(params) {
|
|
|
11
11
|
const queryKey = useAuthQueryKey([...MESSAGES_QUERY_KEY, params]);
|
|
12
12
|
return useQuery({
|
|
13
13
|
queryKey,
|
|
14
|
-
queryFn:
|
|
14
|
+
queryFn: ({ signal }) => apiFetch("/api/messages", { params, signal })
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
function useInfiniteMessages(params) {
|
|
18
18
|
const queryKey = useAuthQueryKey([...MESSAGES_QUERY_KEY, "infinite", params]);
|
|
19
19
|
return useInfiniteQuery({
|
|
20
20
|
queryKey,
|
|
21
|
-
queryFn: ({ pageParam }) =>
|
|
22
|
-
|
|
21
|
+
queryFn: ({ pageParam, signal }) => apiFetch("/api/messages", {
|
|
22
|
+
params: {
|
|
23
23
|
...params,
|
|
24
24
|
page: pageParam,
|
|
25
25
|
limit: INFINITE_MESSAGES_PAGE_SIZE
|
|
26
|
-
}
|
|
27
|
-
|
|
26
|
+
},
|
|
27
|
+
signal
|
|
28
|
+
}),
|
|
28
29
|
getNextPageParam: (lastPage, allPages) => {
|
|
29
30
|
const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);
|
|
30
31
|
return loaded < lastPage.total ? allPages.length + 1 : void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/users/hooks/messages.hook.ts"],"sourcesContent":["'use client';\n\nimport { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/users/hooks/messages.hook.ts"],"sourcesContent":["'use client';\n\nimport { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { apiFetch } from '../../../infra/http/api-fetch';\nimport { markMessageAsReadAction } from '../action/mark-message-as-read.action';\nimport { markAllMessagesAsReadAction } from '../action/mark-all-messages-as-read.action';\nimport { withAction } from '../../../utils/withAction';\nimport type { FindMessagesParams, ListMessagesApiResponse } from '../schema/messages.schema';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const MESSAGES_QUERY_KEY = ['messages'] as const;\n\nconst INFINITE_MESSAGES_PAGE_SIZE = 10;\n\nexport function useMessages(params?: Partial<FindMessagesParams>) {\n const queryKey = useAuthQueryKey([...MESSAGES_QUERY_KEY, params]);\n\n return useQuery({\n queryKey,\n queryFn: ({ signal }) =>\n apiFetch<ListMessagesApiResponse>('/api/messages', { params, signal }),\n });\n}\n\nexport function useInfiniteMessages(params?: Partial<Omit<FindMessagesParams, 'page' | 'limit'>>) {\n const queryKey = useAuthQueryKey([...MESSAGES_QUERY_KEY, 'infinite', params]);\n\n return useInfiniteQuery({\n queryKey,\n queryFn: ({ pageParam, signal }) =>\n apiFetch<ListMessagesApiResponse>('/api/messages', {\n params: {\n ...params,\n page: pageParam as number,\n limit: INFINITE_MESSAGES_PAGE_SIZE,\n },\n signal,\n }),\n getNextPageParam: (lastPage, allPages) => {\n const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);\n return loaded < lastPage.total ? allPages.length + 1 : undefined;\n },\n initialPageParam: 1,\n });\n}\n\nexport function useMarkMessageAsRead() {\n const queryClient = useQueryClient();\n const messagesKey = useAuthQueryKey([...MESSAGES_QUERY_KEY]);\n\n return useMutation({\n mutationFn: withAction(markMessageAsReadAction),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: messagesKey });\n },\n });\n}\n\nexport function useMarkAllMessagesAsRead() {\n const queryClient = useQueryClient();\n const messagesKey = useAuthQueryKey([...MESSAGES_QUERY_KEY]);\n\n return useMutation({\n mutationFn: withAction(markAllMessagesAsReadAction),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: messagesKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,kBAAkB,aAAa,UAAU,sBAAsB;AACxE,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,mCAAmC;AAC5C,SAAS,kBAAkB;AAE3B,SAAS,uBAAuB;AAEzB,MAAM,qBAAqB,CAAC,UAAU;AAE7C,MAAM,8BAA8B;AAE7B,SAAS,YAAY,QAAsC;AAChE,QAAM,WAAW,gBAAgB,CAAC,GAAG,oBAAoB,MAAM,CAAC;AAEhE,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,CAAC,EAAE,OAAO,MACjB,SAAkC,iBAAiB,EAAE,QAAQ,OAAO,CAAC;AAAA,EACzE,CAAC;AACH;AAEO,SAAS,oBAAoB,QAA8D;AAChG,QAAM,WAAW,gBAAgB,CAAC,GAAG,oBAAoB,YAAY,MAAM,CAAC;AAE5E,SAAO,iBAAiB;AAAA,IACtB;AAAA,IACA,SAAS,CAAC,EAAE,WAAW,OAAO,MAC5B,SAAkC,iBAAiB;AAAA,MACjD,QAAQ;AAAA,QACN,GAAG;AAAA,QACH,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,kBAAkB,CAAC,UAAU,aAAa;AACxC,YAAM,SAAS,SAAS,OAAO,CAAC,KAAK,MAAM,MAAM,EAAE,KAAK,QAAQ,CAAC;AACjE,aAAO,SAAS,SAAS,QAAQ,SAAS,SAAS,IAAI;AAAA,IACzD;AAAA,IACA,kBAAkB;AAAA,EACpB,CAAC;AACH;AAEO,SAAS,uBAAuB;AACrC,QAAM,cAAc,eAAe;AACnC,QAAM,cAAc,gBAAgB,CAAC,GAAG,kBAAkB,CAAC;AAE3D,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,uBAAuB;AAAA,IAC9C,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,YAAY,CAAC;AAAA,IACzD;AAAA,EACF,CAAC;AACH;AAEO,SAAS,2BAA2B;AACzC,QAAM,cAAc,eAAe;AACnC,QAAM,cAAc,gBAAgB,CAAC,GAAG,kBAAkB,CAAC;AAE3D,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,2BAA2B;AAAA,IAClD,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,YAAY,CAAC;AAAA,IACzD;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/dist/route.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { safeRouteHandler } from "./infra/route/safe-route-handler";
|
|
2
|
+
import { searchParamsToParams } from "./infra/route/search-params";
|
|
3
|
+
import { parseId } from "./infra/route/parse-id";
|
|
4
|
+
export {
|
|
5
|
+
parseId,
|
|
6
|
+
safeRouteHandler,
|
|
7
|
+
searchParamsToParams
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=route.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/route.ts"],"sourcesContent":["export { safeRouteHandler } from './infra/route/safe-route-handler';\nexport { searchParamsToParams } from './infra/route/search-params';\nexport { parseId } from './infra/route/parse-id';\n"],"mappings":"AAAA,SAAS,wBAAwB;AACjC,SAAS,4BAA4B;AACrC,SAAS,eAAe;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greatapps/common",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.657",
|
|
4
4
|
"description": "Shared library for GreatApps frontend applications",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -16,6 +16,18 @@
|
|
|
16
16
|
"./middleware": {
|
|
17
17
|
"import": "./dist/middleware.mjs",
|
|
18
18
|
"types": "./src/middleware.ts"
|
|
19
|
+
},
|
|
20
|
+
"./route": {
|
|
21
|
+
"import": "./dist/route.mjs",
|
|
22
|
+
"types": "./src/route.ts"
|
|
23
|
+
},
|
|
24
|
+
"./http": {
|
|
25
|
+
"import": "./dist/http.mjs",
|
|
26
|
+
"types": "./src/http.ts"
|
|
27
|
+
},
|
|
28
|
+
"./handlers": {
|
|
29
|
+
"import": "./dist/handlers.mjs",
|
|
30
|
+
"types": "./src/handlers.ts"
|
|
19
31
|
}
|
|
20
32
|
},
|
|
21
33
|
"files": [
|
|
@@ -60,7 +60,7 @@ export function TokenSection() {
|
|
|
60
60
|
</div>
|
|
61
61
|
|
|
62
62
|
<a
|
|
63
|
-
href="https://documenter.getpostman.com/view/4861938/
|
|
63
|
+
href="https://documenter.getpostman.com/view/4861938/2sAYdoDmj4"
|
|
64
64
|
target="_blank"
|
|
65
65
|
rel="noopener noreferrer"
|
|
66
66
|
className="paragraph-small-medium text-gray-500 underline hover:text-gray-700 transition-colors w-fit"
|
|
@@ -73,33 +73,6 @@ export function openCrispChat() {
|
|
|
73
73
|
crispDo('chat:open');
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
function deliverFreePlanWelcome() {
|
|
77
|
-
sendCrispMessage(FREE_PLAN_WELCOME_MESSAGE);
|
|
78
|
-
openCrispChat();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Crisp substitui o array `$crisp` por um objeto com métodos quando o
|
|
82
|
-
// script termina de carregar — `is` só existe na API real.
|
|
83
|
-
function isCrispApiLoaded(): boolean {
|
|
84
|
-
try {
|
|
85
|
-
const $crisp = (window as any).$crisp;
|
|
86
|
-
return !!$crisp && typeof $crisp.is === 'function';
|
|
87
|
-
} catch {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Espera a Crisp carregar antes de exibir a mensagem. Diferente de
|
|
93
|
-
// `on session:loaded`, comandos `do` não dependem de um evento que pode
|
|
94
|
-
// já ter disparado — são executados na hora numa Crisp já carregada.
|
|
95
|
-
function deliverFreePlanWelcomeWhenReady(attemptsLeft: number) {
|
|
96
|
-
if (isCrispApiLoaded() || attemptsLeft <= 0) {
|
|
97
|
-
deliverFreePlanWelcome();
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
setTimeout(deliverFreePlanWelcomeWhenReady, 400, attemptsLeft - 1);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
76
|
export function updateCrispUser(data: {
|
|
104
77
|
email?: string;
|
|
105
78
|
name?: string;
|
|
@@ -222,7 +195,17 @@ export function CrispEmbed() {
|
|
|
222
195
|
const shownKey = `${FREE_PLAN_WELCOME_SHOWN_KEY}:${user.id}`;
|
|
223
196
|
if (window.localStorage.getItem(shownKey)) return;
|
|
224
197
|
|
|
225
|
-
|
|
198
|
+
// Defer to session:loaded para garantir que a Crisp está pronta antes
|
|
199
|
+
// de exibir a mensagem. Sem isso, comandos enfileirados pré-load podem
|
|
200
|
+
// ser descartados silenciosamente.
|
|
201
|
+
safeCrispPush([
|
|
202
|
+
'on',
|
|
203
|
+
'session:loaded',
|
|
204
|
+
() => {
|
|
205
|
+
sendCrispMessage(FREE_PLAN_WELCOME_MESSAGE);
|
|
206
|
+
openCrispChat();
|
|
207
|
+
},
|
|
208
|
+
]);
|
|
226
209
|
window.localStorage.setItem(shownKey, '1');
|
|
227
210
|
} catch {}
|
|
228
211
|
}, [user, shouldLoadCrisp, isFreshSignup, subscription?.id_plan]);
|
package/src/handlers.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { createListCardsHandler } from './modules/cards/handlers/list-cards.handler';
|
|
2
|
+
export { createFindCardByIdHandler } from './modules/cards/handlers/find-card-by-id.handler';
|
|
3
|
+
|
|
4
|
+
export { createListChargesHandler } from './modules/charges/handlers/list-charges.handler';
|
|
5
|
+
export { createFindChargeByIdHandler } from './modules/charges/handlers/find-charge-by-id.handler';
|
|
6
|
+
|
|
7
|
+
export { createListIaCreditsHandler } from './modules/ia-credits/handlers/list-ia-credits.handler';
|
|
8
|
+
|
|
9
|
+
export { createCountPagesHandler } from './modules/pages/handlers/count-pages.handler';
|
|
10
|
+
|
|
11
|
+
export { createListPlansHandler } from './modules/plans/handlers/list-plans.handler';
|
|
12
|
+
export { createFindPlanByIdHandler } from './modules/plans/handlers/find-plan-by-id.handler';
|
|
13
|
+
|
|
14
|
+
export { createListProjectsHandler } from './modules/projects/handlers/list-projects.handler';
|
|
15
|
+
export { createFindProjectHandler } from './modules/projects/handlers/find-project.handler';
|
|
16
|
+
export { createListProjectUsersHandler } from './modules/projects/handlers/list-project-users.handler';
|
|
17
|
+
export { createListAvailableUsersHandler } from './modules/projects/handlers/list-available-users.handler';
|
|
18
|
+
export { createListAllAccountUsersHandler } from './modules/projects/handlers/list-all-account-users.handler';
|
|
19
|
+
|
|
20
|
+
export { createListSubscriptionsHandler } from './modules/subscriptions/handlers/list-subscriptions.handler';
|
|
21
|
+
|
|
22
|
+
export { createListMessagesHandler } from './modules/users/handlers/list-messages.handler';
|
package/src/http.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { apiFetch } from './infra/http/api-fetch';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { buildQueryParams } from '../utils/params';
|
|
2
|
+
import type { ActionResult } from '../api/types';
|
|
3
|
+
|
|
4
|
+
type QueryParams = Parameters<typeof buildQueryParams>[0];
|
|
5
|
+
|
|
6
|
+
interface ApiFetchOptions {
|
|
7
|
+
params?: object;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function apiFetch<T>(path: string, options: ApiFetchOptions = {}): Promise<T> {
|
|
12
|
+
const { params, signal } = options;
|
|
13
|
+
const qs = params ? buildQueryParams(params as QueryParams) : '';
|
|
14
|
+
const url = qs ? `${path}?${qs}` : path;
|
|
15
|
+
|
|
16
|
+
const response = await fetch(url, {
|
|
17
|
+
method: 'GET',
|
|
18
|
+
credentials: 'same-origin',
|
|
19
|
+
headers: { Accept: 'application/json' },
|
|
20
|
+
signal,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
let message = `Erro ${response.status}`;
|
|
25
|
+
try {
|
|
26
|
+
const body = (await response.json()) as ActionResult<unknown>;
|
|
27
|
+
if (body && !body.success && body.error) message = body.error;
|
|
28
|
+
} catch {
|
|
29
|
+
// corpo não-JSON — mantém a mensagem genérica
|
|
30
|
+
}
|
|
31
|
+
throw new Error(message);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const body = (await response.json()) as ActionResult<T>;
|
|
35
|
+
if (!body.success) {
|
|
36
|
+
throw new Error(body.error ?? 'Erro desconhecido');
|
|
37
|
+
}
|
|
38
|
+
return body.data as T;
|
|
39
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import { ApiError } from '../api/types';
|
|
4
|
+
|
|
5
|
+
export async function safeRouteHandler<T>(fn: () => Promise<T>): Promise<Response> {
|
|
6
|
+
try {
|
|
7
|
+
const data = await fn();
|
|
8
|
+
return Response.json({ success: true, data });
|
|
9
|
+
} catch (error) {
|
|
10
|
+
if (error instanceof ApiError) {
|
|
11
|
+
return Response.json({ success: false, error: error.message }, { status: error.statusCode });
|
|
12
|
+
}
|
|
13
|
+
console.error('[safeRouteHandler] erro inesperado', error);
|
|
14
|
+
return Response.json({ success: false, error: 'Erro interno do servidor' }, { status: 500 });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function searchParamsToParams<T extends object>(
|
|
2
|
+
searchParams: URLSearchParams
|
|
3
|
+
): Partial<T> {
|
|
4
|
+
const params = Object.create(null) as Partial<Record<keyof T, string>>;
|
|
5
|
+
for (const [key, value] of searchParams.entries()) {
|
|
6
|
+
params[key as keyof T] = value;
|
|
7
|
+
}
|
|
8
|
+
return params as Partial<T>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import type { NextRequest } from 'next/server';
|
|
4
|
+
import { parseId } from '../../../infra/route/parse-id';
|
|
5
|
+
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
6
|
+
import { cardsService } from '../services/cards.service';
|
|
7
|
+
|
|
8
|
+
export function createFindCardByIdHandler() {
|
|
9
|
+
return async function GET(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
10
|
+
return safeRouteHandler(async () => {
|
|
11
|
+
const { id } = await params;
|
|
12
|
+
return cardsService.findCardById(parseId(id));
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
4
|
+
import { cardsService } from '../services/cards.service';
|
|
5
|
+
|
|
6
|
+
export function createListCardsHandler() {
|
|
7
|
+
return async function GET() {
|
|
8
|
+
return safeRouteHandler(() => cardsService.listCards());
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query';
|
|
4
|
-
import {
|
|
4
|
+
import { apiFetch } from '../../../infra/http/api-fetch';
|
|
5
|
+
import type { SuccessResult } from '../../../infra/api/types';
|
|
6
|
+
import type { Card } from '../types';
|
|
5
7
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
6
8
|
|
|
7
9
|
export function useCardById(id: number | undefined) {
|
|
@@ -9,10 +11,7 @@ export function useCardById(id: number | undefined) {
|
|
|
9
11
|
|
|
10
12
|
return useQuery({
|
|
11
13
|
queryKey: cardKey,
|
|
12
|
-
queryFn:
|
|
13
|
-
const { findCardByIdAction } = await import('../actions/find-card-by-id.action');
|
|
14
|
-
return withAction(findCardByIdAction)(id!);
|
|
15
|
-
},
|
|
14
|
+
queryFn: ({ signal }) => apiFetch<SuccessResult<Card>>(`/api/cards/${id}`, { signal }),
|
|
16
15
|
enabled: id != null,
|
|
17
16
|
});
|
|
18
17
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query';
|
|
4
|
-
import {
|
|
4
|
+
import { apiFetch } from '../../../infra/http/api-fetch';
|
|
5
|
+
import type { PaginatedSuccessResult } from '../../../infra/api/types';
|
|
6
|
+
import type { Card } from '../types';
|
|
5
7
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
6
8
|
|
|
7
9
|
export const CARDS_QUERY_KEY = ['cards'] as const;
|
|
@@ -11,10 +13,7 @@ export function useCards() {
|
|
|
11
13
|
|
|
12
14
|
return useQuery({
|
|
13
15
|
queryKey,
|
|
14
|
-
queryFn:
|
|
15
|
-
const { listCardsAction } = await import('../actions/list-cards.action');
|
|
16
|
-
return withAction(listCardsAction)();
|
|
17
|
-
},
|
|
16
|
+
queryFn: ({ signal }) => apiFetch<PaginatedSuccessResult<Card>>('/api/cards', { signal }),
|
|
18
17
|
select: (result) => ({
|
|
19
18
|
...result,
|
|
20
19
|
data: result.data.filter((card) => !card.deleted),
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import type { NextRequest } from 'next/server';
|
|
4
|
+
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
5
|
+
import { chargesService } from '../services/charges.service';
|
|
6
|
+
|
|
7
|
+
export function createFindChargeByIdHandler() {
|
|
8
|
+
return async function GET(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
9
|
+
return safeRouteHandler(async () => {
|
|
10
|
+
const { id } = await params;
|
|
11
|
+
return chargesService.findChargeById(id);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import type { NextRequest } from 'next/server';
|
|
4
|
+
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
5
|
+
import { searchParamsToParams } from '../../../infra/route/search-params';
|
|
6
|
+
import { chargesService } from '../services/charges.service';
|
|
7
|
+
import type { FindChargesParams } from '../types/charge.type';
|
|
8
|
+
|
|
9
|
+
export function createListChargesHandler() {
|
|
10
|
+
return async function GET(req: NextRequest) {
|
|
11
|
+
return safeRouteHandler(() =>
|
|
12
|
+
chargesService.listCharges(searchParamsToParams<FindChargesParams>(req.nextUrl.searchParams))
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query';
|
|
4
|
-
import {
|
|
4
|
+
import { apiFetch } from '../../../infra/http/api-fetch';
|
|
5
|
+
import type { SuccessResult } from '../../../infra/api/types';
|
|
5
6
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
6
|
-
import {
|
|
7
|
+
import { Charge } from '../types/charge.type';
|
|
7
8
|
import { CHARGES_QUERY_KEY } from '../../subscriptions/constants/query-keys.constants';
|
|
8
9
|
|
|
9
10
|
export function useChargeById(chargeId: string | number | null | undefined) {
|
|
@@ -11,7 +12,8 @@ export function useChargeById(chargeId: string | number | null | undefined) {
|
|
|
11
12
|
|
|
12
13
|
return useQuery({
|
|
13
14
|
queryKey: chargesKey,
|
|
14
|
-
queryFn: () =>
|
|
15
|
+
queryFn: ({ signal }) =>
|
|
16
|
+
apiFetch<SuccessResult<Charge>>(`/api/charges/${chargeId}`, { signal }),
|
|
15
17
|
enabled: !!chargeId,
|
|
16
18
|
});
|
|
17
19
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query';
|
|
4
|
-
import {
|
|
4
|
+
import { apiFetch } from '../../../infra/http/api-fetch';
|
|
5
|
+
import type { PaginatedSuccessResult } from '../../../infra/api/types';
|
|
5
6
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
6
|
-
import {
|
|
7
|
-
import { FindChargesParams } from '../types/charge.type';
|
|
7
|
+
import { Charge, FindChargesParams } from '../types/charge.type';
|
|
8
8
|
import { CHARGES_QUERY_KEY } from '../../subscriptions/constants/query-keys.constants';
|
|
9
9
|
|
|
10
10
|
export function useCharges(params?: Partial<FindChargesParams>) {
|
|
@@ -12,7 +12,8 @@ export function useCharges(params?: Partial<FindChargesParams>) {
|
|
|
12
12
|
|
|
13
13
|
return useQuery({
|
|
14
14
|
queryKey: chargesKey,
|
|
15
|
-
queryFn: () =>
|
|
15
|
+
queryFn: ({ signal }) =>
|
|
16
|
+
apiFetch<PaginatedSuccessResult<Charge>>('/api/charges', { params, signal }),
|
|
16
17
|
staleTime: 10_000,
|
|
17
18
|
});
|
|
18
19
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import type { NextRequest } from 'next/server';
|
|
4
|
+
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
5
|
+
import { iaCreditsService } from '../services/ia-credits.service';
|
|
6
|
+
|
|
7
|
+
export function createListIaCreditsHandler() {
|
|
8
|
+
return async function GET(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
9
|
+
return safeRouteHandler(async () => {
|
|
10
|
+
const { id } = await params;
|
|
11
|
+
return iaCreditsService.listOperations(id);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import { useQuery } from '@tanstack/react-query';
|
|
5
|
-
import {
|
|
5
|
+
import { apiFetch } from '../../../infra/http/api-fetch';
|
|
6
|
+
import type { PaginatedSuccessResult } from '../../../infra/api/types';
|
|
6
7
|
import type { IaCreditOperation, IaCreditsSummary } from '../types';
|
|
7
8
|
import { useActiveSubscription } from '../../subscriptions/hooks/find-active-subscription.hook';
|
|
8
|
-
import { withAction } from '../../../utils/withAction';
|
|
9
9
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
10
10
|
|
|
11
11
|
function calculateSummary(operations: IaCreditOperation[]): IaCreditsSummary {
|
|
@@ -77,7 +77,11 @@ export function useIaCredits() {
|
|
|
77
77
|
|
|
78
78
|
const query = useQuery({
|
|
79
79
|
queryKey,
|
|
80
|
-
queryFn:
|
|
80
|
+
queryFn: ({ signal }) =>
|
|
81
|
+
apiFetch<PaginatedSuccessResult<IaCreditOperation>>(
|
|
82
|
+
`/api/subscriptions/${subscriptionId}/ia-credits`,
|
|
83
|
+
{ signal }
|
|
84
|
+
),
|
|
81
85
|
enabled: subscriptionId != null,
|
|
82
86
|
});
|
|
83
87
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
4
|
+
import { pagesService } from '../services/pages.service';
|
|
5
|
+
|
|
6
|
+
export function createCountPagesHandler() {
|
|
7
|
+
return async function GET() {
|
|
8
|
+
return safeRouteHandler(async () => ({
|
|
9
|
+
total: await pagesService.countPages(),
|
|
10
|
+
}));
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query';
|
|
4
|
-
import {
|
|
4
|
+
import { apiFetch } from '../../../infra/http/api-fetch';
|
|
5
5
|
import { PAGES_QUERY_KEY } from '../constants/query-keys.constants';
|
|
6
|
-
import { withAction } from '../../../utils/withAction';
|
|
7
6
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
8
7
|
|
|
9
8
|
export const COUNT_PAGES_QUERY_KEY = [...PAGES_QUERY_KEY, 'count'] as const;
|
|
@@ -13,8 +12,8 @@ export function useCountPages() {
|
|
|
13
12
|
|
|
14
13
|
return useQuery({
|
|
15
14
|
queryKey,
|
|
16
|
-
queryFn: async () => {
|
|
17
|
-
const result = await
|
|
15
|
+
queryFn: async ({ signal }) => {
|
|
16
|
+
const result = await apiFetch<{ total: number }>('/api/pages/count', { signal });
|
|
18
17
|
return result.total;
|
|
19
18
|
},
|
|
20
19
|
staleTime: 30_000,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import type { NextRequest } from 'next/server';
|
|
4
|
+
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
5
|
+
import { plansService } from '../services/plans.service';
|
|
6
|
+
|
|
7
|
+
export function createFindPlanByIdHandler() {
|
|
8
|
+
return async function GET(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
9
|
+
return safeRouteHandler(async () => {
|
|
10
|
+
const { id } = await params;
|
|
11
|
+
return plansService.findById(id);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
4
|
+
import { plansService } from '../services/plans.service';
|
|
5
|
+
|
|
6
|
+
export function createListPlansHandler() {
|
|
7
|
+
return async function GET() {
|
|
8
|
+
return safeRouteHandler(async () => {
|
|
9
|
+
const { data: apiPlans } = await plansService.listPlans({
|
|
10
|
+
active: true,
|
|
11
|
+
search: 'client',
|
|
12
|
+
sort: 'id:ASC',
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (!apiPlans?.length) return [];
|
|
16
|
+
|
|
17
|
+
return [...apiPlans].sort((a, b) => a.value - b.value);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query';
|
|
4
|
-
import {
|
|
5
|
-
import { listPlansAction } from '../actions/list-plans.action';
|
|
4
|
+
import { apiFetch } from '../../../infra/http/api-fetch';
|
|
6
5
|
import type { Plan } from '../types/plan.type';
|
|
7
6
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
8
7
|
|
|
@@ -13,7 +12,7 @@ export function usePlans() {
|
|
|
13
12
|
|
|
14
13
|
return useQuery<Plan[]>({
|
|
15
14
|
queryKey,
|
|
16
|
-
queryFn:
|
|
15
|
+
queryFn: ({ signal }) => apiFetch<Plan[]>('/api/plans', { signal }),
|
|
17
16
|
staleTime: Infinity,
|
|
18
17
|
gcTime: Infinity,
|
|
19
18
|
refetchOnWindowFocus: false,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { apiFetch } from "../../../infra/http/api-fetch";
|
|
5
|
+
import type { SuccessResult } from "../../../infra/api/types";
|
|
6
6
|
import type { Plan } from "../types/plan.type";
|
|
7
7
|
import { PLANS_QUERY_KEY } from "./list-plans.hook";
|
|
8
8
|
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
@@ -13,7 +13,8 @@ export function usePlanById(idPlan?: number | string | null) {
|
|
|
13
13
|
|
|
14
14
|
return useQuery({
|
|
15
15
|
queryKey: [...plansKey, idPlan],
|
|
16
|
-
queryFn:
|
|
16
|
+
queryFn: ({ signal }) =>
|
|
17
|
+
apiFetch<SuccessResult<Plan>>(`/api/plans/${idPlan}`, { signal }),
|
|
17
18
|
initialData: () => {
|
|
18
19
|
const queries = queryClient.getQueriesData<Plan[]>({
|
|
19
20
|
queryKey: plansKey,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import type { NextRequest } from 'next/server';
|
|
4
|
+
import { parseId } from '../../../infra/route/parse-id';
|
|
5
|
+
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
6
|
+
import { projectsService } from '../services/projects.service';
|
|
7
|
+
|
|
8
|
+
export function createFindProjectHandler() {
|
|
9
|
+
return async function GET(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
10
|
+
return safeRouteHandler(async () => {
|
|
11
|
+
const { id } = await params;
|
|
12
|
+
return projectsService.findById(parseId(id));
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|