@greatapps/common 1.1.98 → 1.1.100
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/hooks/useTwoFactorAuthForm.mjs +5 -13
- package/dist/components/account/hooks/useTwoFactorAuthForm.mjs.map +1 -1
- package/dist/components/account/sections/MyProfileSection.mjs +30 -19
- package/dist/components/account/sections/MyProfileSection.mjs.map +1 -1
- package/dist/components/account/sections/PreferencesSection.mjs +11 -10
- package/dist/components/account/sections/PreferencesSection.mjs.map +1 -1
- package/dist/index.mjs +3 -1
- package/dist/index.mjs.map +1 -1
- package/dist/modules/accounts/actions/account-management.action.mjs +36 -168
- package/dist/modules/accounts/actions/account-management.action.mjs.map +1 -1
- package/dist/modules/accounts/actions/find-current-account.action.mjs +3 -2
- package/dist/modules/accounts/actions/find-current-account.action.mjs.map +1 -1
- package/dist/modules/accounts/actions/list-currencies.action.mjs +3 -2
- package/dist/modules/accounts/actions/list-currencies.action.mjs.map +1 -1
- package/dist/modules/accounts/actions/list-timezones.action.mjs +3 -2
- package/dist/modules/accounts/actions/list-timezones.action.mjs.map +1 -1
- package/dist/modules/accounts/hooks/current-account.hook.mjs +2 -1
- package/dist/modules/accounts/hooks/current-account.hook.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useAccountManagement.mjs +8 -5
- package/dist/modules/accounts/hooks/useAccountManagement.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useCurrencies.mjs +2 -1
- package/dist/modules/accounts/hooks/useCurrencies.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useTimezones.mjs +2 -1
- package/dist/modules/accounts/hooks/useTimezones.mjs.map +1 -1
- package/dist/modules/auth/actions/logout.action.mjs +6 -3
- package/dist/modules/auth/actions/logout.action.mjs.map +1 -1
- package/dist/modules/auth/actions/register.action.mjs +6 -3
- package/dist/modules/auth/actions/register.action.mjs.map +1 -1
- package/dist/modules/auth/actions/verify-two-factor.action.mjs +5 -10
- package/dist/modules/auth/actions/verify-two-factor.action.mjs.map +1 -1
- package/dist/modules/auth/hooks/logout.hook.mjs +2 -1
- package/dist/modules/auth/hooks/logout.hook.mjs.map +1 -1
- package/dist/modules/auth/hooks/register.hook.mjs +2 -1
- package/dist/modules/auth/hooks/register.hook.mjs.map +1 -1
- package/dist/modules/auth/hooks/useUserQuery.mjs +2 -2
- package/dist/modules/auth/hooks/useUserQuery.mjs.map +1 -1
- package/dist/modules/ia-credits/actions/list-ia-credits.action.mjs +3 -2
- package/dist/modules/ia-credits/actions/list-ia-credits.action.mjs.map +1 -1
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs +2 -1
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs.map +1 -1
- package/dist/modules/projects/actions/add-project-user.action.mjs +3 -2
- package/dist/modules/projects/actions/add-project-user.action.mjs.map +1 -1
- package/dist/modules/projects/actions/list-available-users.action.mjs +3 -2
- package/dist/modules/projects/actions/list-available-users.action.mjs.map +1 -1
- package/dist/modules/projects/actions/list-project-users.action.mjs +3 -2
- package/dist/modules/projects/actions/list-project-users.action.mjs.map +1 -1
- package/dist/modules/projects/actions/remove-project-user.action.mjs +3 -2
- package/dist/modules/projects/actions/remove-project-user.action.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-available-users.hook.mjs +8 -1
- package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-project-users.hook.mjs +8 -1
- package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs +3 -2
- package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +5 -1
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +2 -1
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -1
- package/dist/modules/users/action/find-user-by-id.action.mjs +3 -14
- package/dist/modules/users/action/find-user-by-id.action.mjs.map +1 -1
- package/dist/modules/users/action/list-messages.action.mjs +6 -2
- package/dist/modules/users/action/list-messages.action.mjs.map +1 -1
- package/dist/modules/users/action/mark-all-messages-as-read.action.mjs +3 -2
- package/dist/modules/users/action/mark-all-messages-as-read.action.mjs.map +1 -1
- package/dist/modules/users/action/mark-message-as-read.action.mjs +3 -2
- package/dist/modules/users/action/mark-message-as-read.action.mjs.map +1 -1
- package/dist/modules/users/hooks/messages.hook.mjs +11 -9
- package/dist/modules/users/hooks/messages.hook.mjs.map +1 -1
- package/dist/utils/safeServerAction.mjs +10 -16
- package/dist/utils/safeServerAction.mjs.map +1 -1
- package/dist/utils/withAction.mjs +13 -0
- package/dist/utils/withAction.mjs.map +1 -0
- package/package.json +1 -1
- package/src/components/account/hooks/useTwoFactorAuthForm.tsx +101 -114
- package/src/components/account/sections/MyProfileSection.tsx +29 -26
- package/src/components/account/sections/PreferencesSection.tsx +10 -16
- package/src/index.ts +2 -0
- package/src/modules/accounts/actions/account-management.action.ts +90 -261
- package/src/modules/accounts/actions/find-current-account.action.ts +5 -4
- package/src/modules/accounts/actions/list-currencies.action.ts +8 -7
- package/src/modules/accounts/actions/list-timezones.action.ts +8 -7
- package/src/modules/accounts/hooks/current-account.hook.tsx +6 -5
- package/src/modules/accounts/hooks/useAccountManagement.ts +85 -83
- package/src/modules/accounts/hooks/useCurrencies.ts +15 -14
- package/src/modules/accounts/hooks/useTimezones.ts +15 -14
- package/src/modules/auth/actions/logout.action.ts +8 -7
- package/src/modules/auth/actions/register.action.ts +9 -6
- package/src/modules/auth/actions/verify-two-factor.action.ts +8 -21
- package/src/modules/auth/hooks/logout.hook.tsx +2 -1
- package/src/modules/auth/hooks/register.hook.tsx +2 -1
- package/src/modules/auth/hooks/useUserQuery.ts +2 -2
- package/src/modules/ia-credits/actions/list-ia-credits.action.ts +8 -11
- package/src/modules/ia-credits/hooks/ia-credits.hook.ts +2 -1
- package/src/modules/projects/actions/add-project-user.action.ts +9 -8
- package/src/modules/projects/actions/list-available-users.action.ts +9 -8
- package/src/modules/projects/actions/list-project-users.action.ts +9 -8
- package/src/modules/projects/actions/remove-project-user.action.ts +9 -8
- package/src/modules/projects/hooks/list-available-users.hook.ts +33 -26
- package/src/modules/projects/hooks/list-project-users.hook.ts +33 -26
- package/src/modules/subscriptions/actions/list-subscriptions.action.ts +9 -11
- package/src/modules/subscriptions/hooks/find-active-subscription.hook.ts +19 -15
- package/src/modules/subscriptions/hooks/list-subscriptions.hook.ts +17 -15
- package/src/modules/users/action/find-user-by-id.action.ts +8 -25
- package/src/modules/users/action/list-messages.action.ts +12 -10
- package/src/modules/users/action/mark-all-messages-as-read.action.ts +8 -8
- package/src/modules/users/action/mark-message-as-read.action.ts +8 -8
- package/src/modules/users/hooks/messages.hook.ts +60 -58
- package/src/utils/safeServerAction.ts +18 -24
- package/src/utils/withAction.ts +13 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/hooks/useUserQuery.ts"],"sourcesContent":["'use client';\r\n\r\nimport { useMutation, useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query';\r\nimport { User } from '../../users/schema';\r\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/auth/hooks/useUserQuery.ts"],"sourcesContent":["'use client';\r\n\r\nimport { useMutation, useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query';\r\nimport { User } from '../../users/schema';\r\nimport { withAction } from '../../../utils/withAction';\r\n\r\nexport const USER_QUERY_KEY = ['user'];\r\n\r\nasync function fetchUser(): Promise<User | null> {\r\n const { findUserById: getUserDataAction } = await import('../../users/action/find-user-by-id.action');\r\n const result = await getUserDataAction();\r\n return result.success && result.data ? result.data : null;\r\n}\r\n\r\nasync function validateUserSession(): Promise<boolean> {\r\n const { validateSessionAction } = await import('../actions/validate-session.action');\r\n return await validateSessionAction();\r\n}\r\n\r\nexport function useUserQuery() {\r\n return useQuery({\r\n queryKey: USER_QUERY_KEY,\r\n queryFn: fetchUser,\r\n staleTime: 5 * 60 * 1000,\r\n gcTime: 10 * 60 * 1000,\r\n retry: false,\r\n });\r\n}\r\n\r\nexport function useUserValidateSession(options?: UseQueryOptions) {\r\n return useQuery({\r\n queryKey: ['user-validate-session'],\r\n queryFn: validateUserSession,\r\n retry: false,\r\n staleTime: 5 * 60 * 1000,\r\n ...options,\r\n refetchOnMount: 'always',\r\n refetchOnWindowFocus: true,\r\n });\r\n}\r\n\r\nexport function useTwoFactorVerify() {\r\n const queryClient = useQueryClient();\r\n\r\n return useMutation({\r\n mutationFn: async ({ cookie, code }: { cookie: string; code: string }) => {\r\n const { verifyTwoFactorAction } = await import('../actions/verify-two-factor.action');\r\n return withAction(() => verifyTwoFactorAction(cookie, code))();\r\n },\r\n onSuccess: () => {\r\n queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });\r\n queryClient.invalidateQueries({ queryKey: ['two-factor-pending'] });\r\n },\r\n });\r\n}\r\n\r\nexport function useInvalidateUser() {\r\n const queryClient = useQueryClient();\r\n return () => queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });\r\n}\r\n\r\nexport function useSetUserData() {\r\n const queryClient = useQueryClient();\r\n return (user: User | null) => queryClient.setQueryData(USER_QUERY_KEY, user);\r\n}\r\n"],"mappings":";AAEA,SAAS,aAAa,UAAU,sBAAuC;AAEvE,SAAS,kBAAkB;AAEpB,MAAM,iBAAiB,CAAC,MAAM;AAErC,eAAe,YAAkC;AAC/C,QAAM,EAAE,cAAc,kBAAkB,IAAI,MAAM,OAAO,2CAA2C;AACpG,QAAM,SAAS,MAAM,kBAAkB;AACvC,SAAO,OAAO,WAAW,OAAO,OAAO,OAAO,OAAO;AACvD;AAEA,eAAe,sBAAwC;AACrD,QAAM,EAAE,sBAAsB,IAAI,MAAM,OAAO,oCAAoC;AACnF,SAAO,MAAM,sBAAsB;AACrC;AAEO,SAAS,eAAe;AAC7B,SAAO,SAAS;AAAA,IACd,UAAU;AAAA,IACV,SAAS;AAAA,IACT,WAAW,IAAI,KAAK;AAAA,IACpB,QAAQ,KAAK,KAAK;AAAA,IAClB,OAAO;AAAA,EACT,CAAC;AACH;AAEO,SAAS,uBAAuB,SAA2B;AAChE,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,uBAAuB;AAAA,IAClC,SAAS;AAAA,IACT,OAAO;AAAA,IACP,WAAW,IAAI,KAAK;AAAA,IACpB,GAAG;AAAA,IACH,gBAAgB;AAAA,IAChB,sBAAsB;AAAA,EACxB,CAAC;AACH;AAEO,SAAS,qBAAqB;AACnC,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY;AAAA,IACjB,YAAY,OAAO,EAAE,QAAQ,KAAK,MAAwC;AACxE,YAAM,EAAE,sBAAsB,IAAI,MAAM,OAAO,qCAAqC;AACpF,aAAO,WAAW,MAAM,sBAAsB,QAAQ,IAAI,CAAC,EAAE;AAAA,IAC/D;AAAA,IACA,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,eAAe,CAAC;AAC1D,kBAAY,kBAAkB,EAAE,UAAU,CAAC,oBAAoB,EAAE,CAAC;AAAA,IACpE;AAAA,EACF,CAAC;AACH;AAEO,SAAS,oBAAoB;AAClC,QAAM,cAAc,eAAe;AACnC,SAAO,MAAM,YAAY,kBAAkB,EAAE,UAAU,eAAe,CAAC;AACzE;AAEO,SAAS,iBAAiB;AAC/B,QAAM,cAAc,eAAe;AACnC,SAAO,CAAC,SAAsB,YAAY,aAAa,gBAAgB,IAAI;AAC7E;","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
2
3
|
import { iaCreditsService } from "../services/ia-credits.service";
|
|
3
|
-
|
|
4
|
-
return iaCreditsService.listOperations(subscriptionId);
|
|
4
|
+
function listIaCreditsAction(subscriptionId) {
|
|
5
|
+
return safeServerAction(() => iaCreditsService.listOperations(subscriptionId));
|
|
5
6
|
}
|
|
6
7
|
export {
|
|
7
8
|
listIaCreditsAction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/ia-credits/actions/list-ia-credits.action.ts"],"sourcesContent":["'use server';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/ia-credits/actions/list-ia-credits.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { iaCreditsService } from '../services/ia-credits.service';\n\nexport function listIaCreditsAction(subscriptionId: number | string) {\n return safeServerAction(() => iaCreditsService.listOperations(subscriptionId));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AAE1B,SAAS,oBAAoB,gBAAiC;AACnE,SAAO,iBAAiB,MAAM,iBAAiB,eAAe,cAAc,CAAC;AAC/E;","names":[]}
|
|
@@ -3,6 +3,7 @@ import { useMemo } from "react";
|
|
|
3
3
|
import { useQuery } from "@tanstack/react-query";
|
|
4
4
|
import { listIaCreditsAction } from "../actions/list-ia-credits.action";
|
|
5
5
|
import { useActiveSubscription } from "../../subscriptions/hooks/find-active-subscription.hook";
|
|
6
|
+
import { withAction } from "../../../utils/withAction";
|
|
6
7
|
function calculateSummary(operations) {
|
|
7
8
|
const today = /* @__PURE__ */ new Date();
|
|
8
9
|
const todayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate());
|
|
@@ -53,7 +54,7 @@ function useIaCredits() {
|
|
|
53
54
|
const subscriptionId = subscription?.id;
|
|
54
55
|
const query = useQuery({
|
|
55
56
|
queryKey: ["ia-credits", subscriptionId],
|
|
56
|
-
queryFn: () => listIaCreditsAction(subscriptionId),
|
|
57
|
+
queryFn: withAction(() => listIaCreditsAction(subscriptionId)),
|
|
57
58
|
enabled: subscriptionId != null
|
|
58
59
|
});
|
|
59
60
|
const operations = query.data?.data ?? [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/ia-credits/hooks/ia-credits.hook.ts"],"sourcesContent":["'use client';\r\n\r\nimport { useMemo } from 'react';\r\nimport { useQuery } from '@tanstack/react-query';\r\nimport { listIaCreditsAction } from '../actions/list-ia-credits.action';\r\nimport type { IaCreditOperation, IaCreditsSummary } from '../types';\r\nimport { useActiveSubscription } from '../../subscriptions/hooks/find-active-subscription.hook';\r\n\r\nfunction calculateSummary(operations: IaCreditOperation[]): IaCreditsSummary {\r\n const today = new Date();\r\n const todayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate());\r\n\r\n const adds = operations.filter((op) => op.operation === 'add');\r\n const subtracts = operations.filter((op) => op.operation === 'subtract');\r\n\r\n let totalCredits = 0;\r\n let usedCredits = 0;\r\n let nextExpirationInDays: number | null = null;\r\n let nextExpiringCredits: number | null = null;\r\n\r\n for (const add of adds) {\r\n const expirationRaw = add.expiration_time;\r\n if (!expirationRaw) continue;\r\n\r\n const expiration = new Date(expirationRaw);\r\n const expirationDate = new Date(\r\n expiration.getFullYear(),\r\n expiration.getMonth(),\r\n expiration.getDate()\r\n );\r\n\r\n const expiredByDate = expirationDate.getTime() < todayDate.getTime();\r\n const hasExpired = add.has_expired || expiredByDate;\r\n\r\n if (hasExpired) continue;\r\n\r\n const addedCredits = add.operation_value;\r\n\r\n const consumedForAdd = subtracts\r\n .filter((sub) => String(sub.consumed_from_add_id) === String(add.id))\r\n .reduce((sum, sub) => sum + sub.operation_value, 0);\r\n\r\n const remainingForAdd = Math.max(0, addedCredits - consumedForAdd);\r\n\r\n totalCredits += addedCredits;\r\n usedCredits += consumedForAdd;\r\n\r\n const diffMs = expirationDate.getTime() - todayDate.getTime();\r\n const days = Math.max(0, Math.ceil(diffMs / (1000 * 60 * 60 * 24)));\r\n\r\n if (remainingForAdd > 0) {\r\n if (nextExpirationInDays === null || days < nextExpirationInDays) {\r\n nextExpirationInDays = days;\r\n nextExpiringCredits = remainingForAdd;\r\n }\r\n }\r\n }\r\n\r\n const availableCredits = Math.max(0, totalCredits - usedCredits);\r\n\r\n return {\r\n totalCredits,\r\n usedCredits,\r\n availableCredits,\r\n nextExpiringCredits,\r\n nextExpirationInDays,\r\n };\r\n}\r\n\r\nexport function useIaCredits() {\r\n const { data: subscriptionData, isPending: isSubscriptionLoading } = useActiveSubscription();\r\n const subscription = subscriptionData?.data?.[0] ?? null;\r\n const subscriptionId = subscription?.id;\r\n\r\n const query = useQuery({\r\n queryKey: ['ia-credits', subscriptionId],\r\n queryFn: () => listIaCreditsAction(subscriptionId!),\r\n enabled: subscriptionId != null,\r\n });\r\n\r\n const operations = query.data?.data ?? [];\r\n\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n const summary = useMemo(() => calculateSummary(operations), [operations]);\r\n\r\n return {\r\n subscription,\r\n operations,\r\n summary,\r\n isLoading: isSubscriptionLoading || query.isPending,\r\n isSubscriptionLoading,\r\n isCreditsLoading: query.isPending,\r\n isError: query.isError,\r\n error: query.error,\r\n };\r\n}\r\n"],"mappings":";AAEA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AAEpC,SAAS,6BAA6B;
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/ia-credits/hooks/ia-credits.hook.ts"],"sourcesContent":["'use client';\r\n\r\nimport { useMemo } from 'react';\r\nimport { useQuery } from '@tanstack/react-query';\r\nimport { listIaCreditsAction } from '../actions/list-ia-credits.action';\r\nimport type { IaCreditOperation, IaCreditsSummary } from '../types';\r\nimport { useActiveSubscription } from '../../subscriptions/hooks/find-active-subscription.hook';\r\nimport { withAction } from '../../../utils/withAction';\r\n\r\nfunction calculateSummary(operations: IaCreditOperation[]): IaCreditsSummary {\r\n const today = new Date();\r\n const todayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate());\r\n\r\n const adds = operations.filter((op) => op.operation === 'add');\r\n const subtracts = operations.filter((op) => op.operation === 'subtract');\r\n\r\n let totalCredits = 0;\r\n let usedCredits = 0;\r\n let nextExpirationInDays: number | null = null;\r\n let nextExpiringCredits: number | null = null;\r\n\r\n for (const add of adds) {\r\n const expirationRaw = add.expiration_time;\r\n if (!expirationRaw) continue;\r\n\r\n const expiration = new Date(expirationRaw);\r\n const expirationDate = new Date(\r\n expiration.getFullYear(),\r\n expiration.getMonth(),\r\n expiration.getDate()\r\n );\r\n\r\n const expiredByDate = expirationDate.getTime() < todayDate.getTime();\r\n const hasExpired = add.has_expired || expiredByDate;\r\n\r\n if (hasExpired) continue;\r\n\r\n const addedCredits = add.operation_value;\r\n\r\n const consumedForAdd = subtracts\r\n .filter((sub) => String(sub.consumed_from_add_id) === String(add.id))\r\n .reduce((sum, sub) => sum + sub.operation_value, 0);\r\n\r\n const remainingForAdd = Math.max(0, addedCredits - consumedForAdd);\r\n\r\n totalCredits += addedCredits;\r\n usedCredits += consumedForAdd;\r\n\r\n const diffMs = expirationDate.getTime() - todayDate.getTime();\r\n const days = Math.max(0, Math.ceil(diffMs / (1000 * 60 * 60 * 24)));\r\n\r\n if (remainingForAdd > 0) {\r\n if (nextExpirationInDays === null || days < nextExpirationInDays) {\r\n nextExpirationInDays = days;\r\n nextExpiringCredits = remainingForAdd;\r\n }\r\n }\r\n }\r\n\r\n const availableCredits = Math.max(0, totalCredits - usedCredits);\r\n\r\n return {\r\n totalCredits,\r\n usedCredits,\r\n availableCredits,\r\n nextExpiringCredits,\r\n nextExpirationInDays,\r\n };\r\n}\r\n\r\nexport function useIaCredits() {\r\n const { data: subscriptionData, isPending: isSubscriptionLoading } = useActiveSubscription();\r\n const subscription = subscriptionData?.data?.[0] ?? null;\r\n const subscriptionId = subscription?.id;\r\n\r\n const query = useQuery({\r\n queryKey: ['ia-credits', subscriptionId],\r\n queryFn: withAction(() => listIaCreditsAction(subscriptionId!)),\r\n enabled: subscriptionId != null,\r\n });\r\n\r\n const operations = query.data?.data ?? [];\r\n\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n const summary = useMemo(() => calculateSummary(operations), [operations]);\r\n\r\n return {\r\n subscription,\r\n operations,\r\n summary,\r\n isLoading: isSubscriptionLoading || query.isPending,\r\n isSubscriptionLoading,\r\n isCreditsLoading: query.isPending,\r\n isError: query.isError,\r\n error: query.error,\r\n };\r\n}\r\n"],"mappings":";AAEA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AAEpC,SAAS,6BAA6B;AACtC,SAAS,kBAAkB;AAE3B,SAAS,iBAAiB,YAAmD;AAC3E,QAAM,QAAQ,oBAAI,KAAK;AACvB,QAAM,YAAY,IAAI,KAAK,MAAM,YAAY,GAAG,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC;AAEjF,QAAM,OAAO,WAAW,OAAO,CAAC,OAAO,GAAG,cAAc,KAAK;AAC7D,QAAM,YAAY,WAAW,OAAO,CAAC,OAAO,GAAG,cAAc,UAAU;AAEvE,MAAI,eAAe;AACnB,MAAI,cAAc;AAClB,MAAI,uBAAsC;AAC1C,MAAI,sBAAqC;AAEzC,aAAW,OAAO,MAAM;AACtB,UAAM,gBAAgB,IAAI;AAC1B,QAAI,CAAC,cAAe;AAEpB,UAAM,aAAa,IAAI,KAAK,aAAa;AACzC,UAAM,iBAAiB,IAAI;AAAA,MACzB,WAAW,YAAY;AAAA,MACvB,WAAW,SAAS;AAAA,MACpB,WAAW,QAAQ;AAAA,IACrB;AAEA,UAAM,gBAAgB,eAAe,QAAQ,IAAI,UAAU,QAAQ;AACnE,UAAM,aAAa,IAAI,eAAe;AAEtC,QAAI,WAAY;AAEhB,UAAM,eAAe,IAAI;AAEzB,UAAM,iBAAiB,UACpB,OAAO,CAAC,QAAQ,OAAO,IAAI,oBAAoB,MAAM,OAAO,IAAI,EAAE,CAAC,EACnE,OAAO,CAAC,KAAK,QAAQ,MAAM,IAAI,iBAAiB,CAAC;AAEpD,UAAM,kBAAkB,KAAK,IAAI,GAAG,eAAe,cAAc;AAEjE,oBAAgB;AAChB,mBAAe;AAEf,UAAM,SAAS,eAAe,QAAQ,IAAI,UAAU,QAAQ;AAC5D,UAAM,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,UAAU,MAAO,KAAK,KAAK,GAAG,CAAC;AAElE,QAAI,kBAAkB,GAAG;AACvB,UAAI,yBAAyB,QAAQ,OAAO,sBAAsB;AAChE,+BAAuB;AACvB,8BAAsB;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AAEA,QAAM,mBAAmB,KAAK,IAAI,GAAG,eAAe,WAAW;AAE/D,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,eAAe;AAC7B,QAAM,EAAE,MAAM,kBAAkB,WAAW,sBAAsB,IAAI,sBAAsB;AAC3F,QAAM,eAAe,kBAAkB,OAAO,CAAC,KAAK;AACpD,QAAM,iBAAiB,cAAc;AAErC,QAAM,QAAQ,SAAS;AAAA,IACrB,UAAU,CAAC,cAAc,cAAc;AAAA,IACvC,SAAS,WAAW,MAAM,oBAAoB,cAAe,CAAC;AAAA,IAC9D,SAAS,kBAAkB;AAAA,EAC7B,CAAC;AAED,QAAM,aAAa,MAAM,MAAM,QAAQ,CAAC;AAGxC,QAAM,UAAU,QAAQ,MAAM,iBAAiB,UAAU,GAAG,CAAC,UAAU,CAAC;AAExE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,yBAAyB,MAAM;AAAA,IAC1C;AAAA,IACA,kBAAkB,MAAM;AAAA,IACxB,SAAS,MAAM;AAAA,IACf,OAAO,MAAM;AAAA,EACf;AACF;","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
2
3
|
import { projectUsersService } from "../services/project-users.service";
|
|
3
|
-
|
|
4
|
-
return projectUsersService.addToProject(params);
|
|
4
|
+
function addProjectUserAction(params) {
|
|
5
|
+
return safeServerAction(() => projectUsersService.addToProject(params));
|
|
5
6
|
}
|
|
6
7
|
export {
|
|
7
8
|
addProjectUserAction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/projects/actions/add-project-user.action.ts"],"sourcesContent":["'use server';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/projects/actions/add-project-user.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { projectUsersService } from '../services/project-users.service';\nimport type { AddRemoveProjectUsersParams } from '../types';\n\nexport function addProjectUserAction(params: AddRemoveProjectUsersParams) {\n return safeServerAction(() => projectUsersService.addToProject(params));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AAG7B,SAAS,qBAAqB,QAAqC;AACxE,SAAO,iBAAiB,MAAM,oBAAoB,aAAa,MAAM,CAAC;AACxE;","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
2
3
|
import { projectUsersService } from "../services/project-users.service";
|
|
3
|
-
|
|
4
|
-
return projectUsersService.listNotInProject(projectId, params);
|
|
4
|
+
function listAvailableUsersAction(projectId, params = {}) {
|
|
5
|
+
return safeServerAction(() => projectUsersService.listNotInProject(projectId, params));
|
|
5
6
|
}
|
|
6
7
|
export {
|
|
7
8
|
listAvailableUsersAction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/projects/actions/list-available-users.action.ts"],"sourcesContent":["'use server';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/projects/actions/list-available-users.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { projectUsersService } from '../services/project-users.service';\nimport type { ListUsersParams } from '../types';\n\nexport function listAvailableUsersAction(projectId: number, params: ListUsersParams = {}) {\n return safeServerAction(() => projectUsersService.listNotInProject(projectId, params));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AAG7B,SAAS,yBAAyB,WAAmB,SAA0B,CAAC,GAAG;AACxF,SAAO,iBAAiB,MAAM,oBAAoB,iBAAiB,WAAW,MAAM,CAAC;AACvF;","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
2
3
|
import { projectUsersService } from "../services/project-users.service";
|
|
3
|
-
|
|
4
|
-
return projectUsersService.listInProject(projectId, params);
|
|
4
|
+
function listProjectUsersAction(projectId, params = {}) {
|
|
5
|
+
return safeServerAction(() => projectUsersService.listInProject(projectId, params));
|
|
5
6
|
}
|
|
6
7
|
export {
|
|
7
8
|
listProjectUsersAction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/projects/actions/list-project-users.action.ts"],"sourcesContent":["'use server';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/projects/actions/list-project-users.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { projectUsersService } from '../services/project-users.service';\nimport type { ListUsersParams } from '../types';\n\nexport function listProjectUsersAction(projectId: number, params: ListUsersParams = {}) {\n return safeServerAction(() => projectUsersService.listInProject(projectId, params));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AAG7B,SAAS,uBAAuB,WAAmB,SAA0B,CAAC,GAAG;AACtF,SAAO,iBAAiB,MAAM,oBAAoB,cAAc,WAAW,MAAM,CAAC;AACpF;","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
2
3
|
import { projectUsersService } from "../services/project-users.service";
|
|
3
|
-
|
|
4
|
-
return projectUsersService.removeFromProject(params);
|
|
4
|
+
function removeProjectUserAction(params) {
|
|
5
|
+
return safeServerAction(() => projectUsersService.removeFromProject(params));
|
|
5
6
|
}
|
|
6
7
|
export {
|
|
7
8
|
removeProjectUserAction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/projects/actions/remove-project-user.action.ts"],"sourcesContent":["'use server';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/projects/actions/remove-project-user.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { projectUsersService } from '../services/project-users.service';\nimport type { AddRemoveProjectUsersParams } from '../types';\n\nexport function removeProjectUserAction(params: AddRemoveProjectUsersParams) {\n return safeServerAction(() => projectUsersService.removeFromProject(params));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AAG7B,SAAS,wBAAwB,QAAqC;AAC3E,SAAO,iBAAiB,MAAM,oBAAoB,kBAAkB,MAAM,CAAC;AAC7E;","names":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
3
3
|
import { listAvailableUsersAction } from "../actions/list-available-users.action";
|
|
4
|
+
import { withAction } from "../../../utils/withAction";
|
|
4
5
|
const PAGE_SIZE = 20;
|
|
5
6
|
const LIST_AVAILABLE_USERS_BASE_KEY = (projectId) => ["project-users", projectId, "out"];
|
|
6
7
|
const LIST_AVAILABLE_USERS_QUERY_KEY = (projectId, search = "") => [
|
|
@@ -10,7 +11,13 @@ const LIST_AVAILABLE_USERS_QUERY_KEY = (projectId, search = "") => [
|
|
|
10
11
|
function useListAvailableUsers(projectId, search = "") {
|
|
11
12
|
return useInfiniteQuery({
|
|
12
13
|
queryKey: LIST_AVAILABLE_USERS_QUERY_KEY(projectId, search),
|
|
13
|
-
queryFn: ({ pageParam }) =>
|
|
14
|
+
queryFn: ({ pageParam }) => withAction(
|
|
15
|
+
() => listAvailableUsersAction(projectId, {
|
|
16
|
+
search: search || void 0,
|
|
17
|
+
page: pageParam,
|
|
18
|
+
limit: PAGE_SIZE
|
|
19
|
+
})
|
|
20
|
+
)(),
|
|
14
21
|
getNextPageParam: (lastPage, allPages) => {
|
|
15
22
|
const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);
|
|
16
23
|
return loaded < lastPage.total ? allPages.length + 1 : void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/projects/hooks/list-available-users.hook.ts"],"sourcesContent":["'use client';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/projects/hooks/list-available-users.hook.ts"],"sourcesContent":["'use client';\n\nimport { useInfiniteQuery } from '@tanstack/react-query';\nimport { listAvailableUsersAction } from '../actions/list-available-users.action';\nimport { withAction } from '../../../utils/withAction';\n\nconst PAGE_SIZE = 20;\n\nexport const LIST_AVAILABLE_USERS_BASE_KEY = (projectId: number) => ['project-users', projectId, 'out'];\nexport const LIST_AVAILABLE_USERS_QUERY_KEY = (projectId: number, search: string = '') => [\n ...LIST_AVAILABLE_USERS_BASE_KEY(projectId),\n search,\n];\n\nexport function useListAvailableUsers(projectId: number, search: string = '') {\n return useInfiniteQuery({\n queryKey: LIST_AVAILABLE_USERS_QUERY_KEY(projectId, search),\n queryFn: ({ pageParam }) =>\n withAction(() =>\n listAvailableUsersAction(projectId, {\n search: search || undefined,\n page: pageParam as number,\n limit: PAGE_SIZE,\n })\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 enabled: !!projectId,\n });\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,gCAAgC;AACzC,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,gCAAgC,CAAC,cAAsB,CAAC,iBAAiB,WAAW,KAAK;AAC/F,MAAM,iCAAiC,CAAC,WAAmB,SAAiB,OAAO;AAAA,EACxF,GAAG,8BAA8B,SAAS;AAAA,EAC1C;AACF;AAEO,SAAS,sBAAsB,WAAmB,SAAiB,IAAI;AAC5E,SAAO,iBAAiB;AAAA,IACtB,UAAU,+BAA+B,WAAW,MAAM;AAAA,IAC1D,SAAS,CAAC,EAAE,UAAU,MACpB;AAAA,MAAW,MACT,yBAAyB,WAAW;AAAA,QAClC,QAAQ,UAAU;AAAA,QAClB,MAAM;AAAA,QACN,OAAO;AAAA,MACT,CAAC;AAAA,IACH,EAAE;AAAA,IACJ,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,IAClB,SAAS,CAAC,CAAC;AAAA,EACb,CAAC;AACH;","names":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
3
3
|
import { listProjectUsersAction } from "../actions/list-project-users.action";
|
|
4
|
+
import { withAction } from "../../../utils/withAction";
|
|
4
5
|
const PAGE_SIZE = 20;
|
|
5
6
|
const LIST_PROJECT_USERS_BASE_KEY = (projectId) => ["project-users", projectId, "in"];
|
|
6
7
|
const LIST_PROJECT_USERS_QUERY_KEY = (projectId, search = "") => [
|
|
@@ -10,7 +11,13 @@ const LIST_PROJECT_USERS_QUERY_KEY = (projectId, search = "") => [
|
|
|
10
11
|
function useListProjectUsers(projectId, search = "") {
|
|
11
12
|
return useInfiniteQuery({
|
|
12
13
|
queryKey: LIST_PROJECT_USERS_QUERY_KEY(projectId, search),
|
|
13
|
-
queryFn: ({ pageParam }) =>
|
|
14
|
+
queryFn: ({ pageParam }) => withAction(
|
|
15
|
+
() => listProjectUsersAction(projectId, {
|
|
16
|
+
search: search || void 0,
|
|
17
|
+
page: pageParam,
|
|
18
|
+
limit: PAGE_SIZE
|
|
19
|
+
})
|
|
20
|
+
)(),
|
|
14
21
|
getNextPageParam: (lastPage, allPages) => {
|
|
15
22
|
const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);
|
|
16
23
|
return loaded < lastPage.total ? allPages.length + 1 : void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/projects/hooks/list-project-users.hook.ts"],"sourcesContent":["'use client';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/projects/hooks/list-project-users.hook.ts"],"sourcesContent":["'use client';\n\nimport { useInfiniteQuery } from '@tanstack/react-query';\nimport { listProjectUsersAction } from '../actions/list-project-users.action';\nimport { withAction } from '../../../utils/withAction';\n\nconst PAGE_SIZE = 20;\n\nexport const LIST_PROJECT_USERS_BASE_KEY = (projectId: number) => ['project-users', projectId, 'in'];\nexport const LIST_PROJECT_USERS_QUERY_KEY = (projectId: number, search: string = '') => [\n ...LIST_PROJECT_USERS_BASE_KEY(projectId),\n search,\n];\n\nexport function useListProjectUsers(projectId: number, search: string = '') {\n return useInfiniteQuery({\n queryKey: LIST_PROJECT_USERS_QUERY_KEY(projectId, search),\n queryFn: ({ pageParam }) =>\n withAction(() =>\n listProjectUsersAction(projectId, {\n search: search || undefined,\n page: pageParam as number,\n limit: PAGE_SIZE,\n })\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 enabled: !!projectId,\n });\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,8BAA8B;AACvC,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,8BAA8B,CAAC,cAAsB,CAAC,iBAAiB,WAAW,IAAI;AAC5F,MAAM,+BAA+B,CAAC,WAAmB,SAAiB,OAAO;AAAA,EACtF,GAAG,4BAA4B,SAAS;AAAA,EACxC;AACF;AAEO,SAAS,oBAAoB,WAAmB,SAAiB,IAAI;AAC1E,SAAO,iBAAiB;AAAA,IACtB,UAAU,6BAA6B,WAAW,MAAM;AAAA,IACxD,SAAS,CAAC,EAAE,UAAU,MACpB;AAAA,MAAW,MACT,uBAAuB,WAAW;AAAA,QAChC,QAAQ,UAAU;AAAA,QAClB,MAAM;AAAA,QACN,OAAO;AAAA,MACT,CAAC;AAAA,IACH,EAAE;AAAA,IACJ,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,IAClB,SAAS,CAAC,CAAC;AAAA,EACb,CAAC;AACH;","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
2
3
|
import { subscriptionsService } from "../services/subscriptions.service";
|
|
3
|
-
|
|
4
|
-
return subscriptionsService.listSubscriptions(params);
|
|
4
|
+
function listSubscriptionsAction(params) {
|
|
5
|
+
return safeServerAction(() => subscriptionsService.listSubscriptions(params));
|
|
5
6
|
}
|
|
6
7
|
export {
|
|
7
8
|
listSubscriptionsAction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/actions/list-subscriptions.action.ts"],"sourcesContent":["'use server';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/actions/list-subscriptions.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport type { FindSubscriptionsParams } from '../types';\nimport { subscriptionsService } from '../services/subscriptions.service';\n\nexport function listSubscriptionsAction(params?: Partial<FindSubscriptionsParams>) {\n return safeServerAction(() => subscriptionsService.listSubscriptions(params));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AAEjC,SAAS,4BAA4B;AAE9B,SAAS,wBAAwB,QAA2C;AACjF,SAAO,iBAAiB,MAAM,qBAAqB,kBAAkB,MAAM,CAAC;AAC9E;","names":[]}
|
|
@@ -4,10 +4,14 @@ import { listSubscriptionsAction } from "../actions/list-subscriptions.action";
|
|
|
4
4
|
import { parseResult } from "../../../infra/utils/parser";
|
|
5
5
|
import { SubscriptionSchema } from "../types";
|
|
6
6
|
import { SUBSCRIPTIONS_QUERY_KEY } from "./list-subscriptions.hook";
|
|
7
|
+
import { withAction } from "../../../utils/withAction";
|
|
7
8
|
function useActiveSubscription() {
|
|
8
9
|
return useQuery({
|
|
9
10
|
queryKey: [...SUBSCRIPTIONS_QUERY_KEY, "active"],
|
|
10
|
-
queryFn: async () => parseResult(
|
|
11
|
+
queryFn: async () => parseResult(
|
|
12
|
+
SubscriptionSchema,
|
|
13
|
+
await withAction(() => listSubscriptionsAction({ active: true }))()
|
|
14
|
+
)
|
|
11
15
|
});
|
|
12
16
|
}
|
|
13
17
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/find-active-subscription.hook.ts"],"sourcesContent":["'use client';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/find-active-subscription.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { listSubscriptionsAction } from '../actions/list-subscriptions.action';\nimport { parseResult } from '../../../infra/utils/parser';\nimport { SubscriptionSchema } from '../types';\nimport { SUBSCRIPTIONS_QUERY_KEY } from './list-subscriptions.hook';\nimport { withAction } from '../../../utils/withAction';\n\nexport function useActiveSubscription() {\n return useQuery({\n queryKey: [...SUBSCRIPTIONS_QUERY_KEY, 'active'],\n queryFn: async () =>\n parseResult(\n SubscriptionSchema,\n await withAction(() => listSubscriptionsAction({ active: true }))()\n ),\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,kBAAkB;AAEpB,SAAS,wBAAwB;AACtC,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,GAAG,yBAAyB,QAAQ;AAAA,IAC/C,SAAS,YACP;AAAA,MACE;AAAA,MACA,MAAM,WAAW,MAAM,wBAAwB,EAAE,QAAQ,KAAK,CAAC,CAAC,EAAE;AAAA,IACpE;AAAA,EACJ,CAAC;AACH;","names":[]}
|
|
@@ -3,11 +3,12 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
3
3
|
import { listSubscriptionsAction } from "../actions/list-subscriptions.action";
|
|
4
4
|
import { parseResult } from "../../../infra/utils/parser";
|
|
5
5
|
import { SubscriptionSchema } from "../types";
|
|
6
|
+
import { withAction } from "../../../utils/withAction";
|
|
6
7
|
const SUBSCRIPTIONS_QUERY_KEY = ["subscriptions"];
|
|
7
8
|
function useSubscriptions(params) {
|
|
8
9
|
return useQuery({
|
|
9
10
|
queryKey: [...SUBSCRIPTIONS_QUERY_KEY, params],
|
|
10
|
-
queryFn: async () => parseResult(SubscriptionSchema, await listSubscriptionsAction(params))
|
|
11
|
+
queryFn: async () => parseResult(SubscriptionSchema, await withAction(() => listSubscriptionsAction(params))())
|
|
11
12
|
});
|
|
12
13
|
}
|
|
13
14
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/list-subscriptions.hook.ts"],"sourcesContent":["'use client';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/list-subscriptions.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { listSubscriptionsAction } from '../actions/list-subscriptions.action';\nimport { parseResult } from '../../../infra/utils/parser';\nimport { SubscriptionSchema, type FindSubscriptionsParams } from '../types';\nimport { withAction } from '../../../utils/withAction';\n\nexport const SUBSCRIPTIONS_QUERY_KEY = ['subscriptions'];\n\nexport function useSubscriptions(params?: Partial<FindSubscriptionsParams>) {\n return useQuery({\n queryKey: [...SUBSCRIPTIONS_QUERY_KEY, params],\n queryFn: async () =>\n parseResult(SubscriptionSchema, await withAction(() => listSubscriptionsAction(params))()),\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,mBAAmB;AAC5B,SAAS,0BAAwD;AACjE,SAAS,kBAAkB;AAEpB,MAAM,0BAA0B,CAAC,eAAe;AAEhD,SAAS,iBAAiB,QAA2C;AAC1E,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,GAAG,yBAAyB,MAAM;AAAA,IAC7C,SAAS,YACP,YAAY,oBAAoB,MAAM,WAAW,MAAM,wBAAwB,MAAM,CAAC,EAAE,CAAC;AAAA,EAC7F,CAAC;AACH;","names":[]}
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
2
3
|
import { userService } from "../services/user.service";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const user = await userService.findById();
|
|
6
|
-
return {
|
|
7
|
-
success: true,
|
|
8
|
-
data: user
|
|
9
|
-
};
|
|
10
|
-
} catch (error) {
|
|
11
|
-
console.error("[findUserById] Error:", error);
|
|
12
|
-
return {
|
|
13
|
-
success: false,
|
|
14
|
-
error: error instanceof Error ? error.message : "Erro desconhecido"
|
|
15
|
-
};
|
|
16
|
-
}
|
|
4
|
+
function findUserById() {
|
|
5
|
+
return safeServerAction(() => userService.findById());
|
|
17
6
|
}
|
|
18
7
|
export {
|
|
19
8
|
findUserById
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/users/action/find-user-by-id.action.ts"],"sourcesContent":["'use server';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/users/action/find-user-by-id.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { userService } from '../services/user.service';\n\nexport function findUserById() {\n return safeServerAction(() => userService.findById());\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAErB,SAAS,eAAe;AAC7B,SAAO,iBAAiB,MAAM,YAAY,SAAS,CAAC;AACtD;","names":[]}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
2
3
|
import { messagesService } from "../services/messages.service";
|
|
3
|
-
|
|
4
|
-
return
|
|
4
|
+
function listMessagesAction(params) {
|
|
5
|
+
return safeServerAction(async () => {
|
|
6
|
+
const result = await messagesService.listMessages(params);
|
|
7
|
+
return { data: result.data, total: result.total, totalUnread: result.totalUnread };
|
|
8
|
+
});
|
|
5
9
|
}
|
|
6
10
|
export {
|
|
7
11
|
listMessagesAction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/users/action/list-messages.action.ts"],"sourcesContent":["'use server';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/users/action/list-messages.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { messagesService } from '../services/messages.service';\nimport type { FindMessagesParams } from '../schema/messages.schema';\n\nexport function listMessagesAction(params?: Partial<FindMessagesParams>) {\n return safeServerAction(async () => {\n const result = await messagesService.listMessages(params);\n return { data: result.data, total: result.total, totalUnread: result.totalUnread };\n });\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAGzB,SAAS,mBAAmB,QAAsC;AACvE,SAAO,iBAAiB,YAAY;AAClC,UAAM,SAAS,MAAM,gBAAgB,aAAa,MAAM;AACxD,WAAO,EAAE,MAAM,OAAO,MAAM,OAAO,OAAO,OAAO,aAAa,OAAO,YAAY;AAAA,EACnF,CAAC;AACH;","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
2
3
|
import { messagesService } from "../services/messages.service";
|
|
3
|
-
|
|
4
|
-
return messagesService.markAllAsRead();
|
|
4
|
+
function markAllMessagesAsReadAction() {
|
|
5
|
+
return safeServerAction(() => messagesService.markAllAsRead());
|
|
5
6
|
}
|
|
6
7
|
export {
|
|
7
8
|
markAllMessagesAsReadAction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/users/action/mark-all-messages-as-read.action.ts"],"sourcesContent":["'use server';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/users/action/mark-all-messages-as-read.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { messagesService } from '../services/messages.service';\n\nexport function markAllMessagesAsReadAction() {\n return safeServerAction(() => messagesService.markAllAsRead());\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAEzB,SAAS,8BAA8B;AAC5C,SAAO,iBAAiB,MAAM,gBAAgB,cAAc,CAAC;AAC/D;","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
2
3
|
import { messagesService } from "../services/messages.service";
|
|
3
|
-
|
|
4
|
-
return messagesService.markAsRead(messageId);
|
|
4
|
+
function markMessageAsReadAction(messageId) {
|
|
5
|
+
return safeServerAction(() => messagesService.markAsRead(messageId));
|
|
5
6
|
}
|
|
6
7
|
export {
|
|
7
8
|
markMessageAsReadAction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/users/action/mark-message-as-read.action.ts"],"sourcesContent":["'use server';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/users/action/mark-message-as-read.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { messagesService } from '../services/messages.service';\n\nexport function markMessageAsReadAction(messageId: string) {\n return safeServerAction(() => messagesService.markAsRead(messageId));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAEzB,SAAS,wBAAwB,WAAmB;AACzD,SAAO,iBAAiB,MAAM,gBAAgB,WAAW,SAAS,CAAC;AACrE;","names":[]}
|
|
@@ -3,23 +3,25 @@ import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tansta
|
|
|
3
3
|
import { listMessagesAction } from "../action/list-messages.action";
|
|
4
4
|
import { markMessageAsReadAction } from "../action/mark-message-as-read.action";
|
|
5
5
|
import { markAllMessagesAsReadAction } from "../action/mark-all-messages-as-read.action";
|
|
6
|
-
import {
|
|
6
|
+
import { withAction } from "../../../utils/withAction";
|
|
7
7
|
const MESSAGES_QUERY_KEY = ["messages"];
|
|
8
8
|
const INFINITE_MESSAGES_PAGE_SIZE = 10;
|
|
9
9
|
function useMessages(params) {
|
|
10
10
|
return useQuery({
|
|
11
11
|
queryKey: [...MESSAGES_QUERY_KEY, params],
|
|
12
|
-
queryFn: () =>
|
|
12
|
+
queryFn: withAction(() => listMessagesAction(params))
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
function useInfiniteMessages(params) {
|
|
16
16
|
return useInfiniteQuery({
|
|
17
17
|
queryKey: [...MESSAGES_QUERY_KEY, "infinite", params],
|
|
18
|
-
queryFn: ({ pageParam }) =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
queryFn: ({ pageParam }) => withAction(
|
|
19
|
+
() => listMessagesAction({
|
|
20
|
+
...params,
|
|
21
|
+
page: pageParam,
|
|
22
|
+
limit: INFINITE_MESSAGES_PAGE_SIZE
|
|
23
|
+
})
|
|
24
|
+
)(),
|
|
23
25
|
getNextPageParam: (lastPage, allPages) => {
|
|
24
26
|
const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);
|
|
25
27
|
return loaded < lastPage.total ? allPages.length + 1 : void 0;
|
|
@@ -30,7 +32,7 @@ function useInfiniteMessages(params) {
|
|
|
30
32
|
function useMarkMessageAsRead() {
|
|
31
33
|
const queryClient = useQueryClient();
|
|
32
34
|
return useMutation({
|
|
33
|
-
mutationFn: (
|
|
35
|
+
mutationFn: withAction(markMessageAsReadAction),
|
|
34
36
|
onSuccess: () => {
|
|
35
37
|
queryClient.invalidateQueries({ queryKey: MESSAGES_QUERY_KEY });
|
|
36
38
|
}
|
|
@@ -39,7 +41,7 @@ function useMarkMessageAsRead() {
|
|
|
39
41
|
function useMarkAllMessagesAsRead() {
|
|
40
42
|
const queryClient = useQueryClient();
|
|
41
43
|
return useMutation({
|
|
42
|
-
mutationFn: (
|
|
44
|
+
mutationFn: withAction(markAllMessagesAsReadAction),
|
|
43
45
|
onSuccess: () => {
|
|
44
46
|
queryClient.invalidateQueries({ queryKey: MESSAGES_QUERY_KEY });
|
|
45
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/users/hooks/messages.hook.ts"],"sourcesContent":["'use client';\
|
|
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 { listMessagesAction } from '../action/list-messages.action';\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 } from '../schema/messages.schema';\n\nexport const MESSAGES_QUERY_KEY = ['messages'];\n\nconst INFINITE_MESSAGES_PAGE_SIZE = 10;\n\nexport function useMessages(params?: Partial<FindMessagesParams>) {\n return useQuery({\n queryKey: [...MESSAGES_QUERY_KEY, params],\n queryFn: withAction(() => listMessagesAction(params)),\n });\n}\n\nexport function useInfiniteMessages(params?: Partial<Omit<FindMessagesParams, 'page' | 'limit'>>) {\n return useInfiniteQuery({\n queryKey: [...MESSAGES_QUERY_KEY, 'infinite', params],\n queryFn: ({ pageParam }) =>\n withAction(() =>\n listMessagesAction({\n ...params,\n page: pageParam as number,\n limit: INFINITE_MESSAGES_PAGE_SIZE,\n })\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\n return useMutation({\n mutationFn: withAction(markMessageAsReadAction),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: MESSAGES_QUERY_KEY });\n },\n });\n}\n\nexport function useMarkAllMessagesAsRead() {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: withAction(markAllMessagesAsReadAction),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: MESSAGES_QUERY_KEY });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,kBAAkB,aAAa,UAAU,sBAAsB;AACxE,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,mCAAmC;AAC5C,SAAS,kBAAkB;AAGpB,MAAM,qBAAqB,CAAC,UAAU;AAE7C,MAAM,8BAA8B;AAE7B,SAAS,YAAY,QAAsC;AAChE,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,GAAG,oBAAoB,MAAM;AAAA,IACxC,SAAS,WAAW,MAAM,mBAAmB,MAAM,CAAC;AAAA,EACtD,CAAC;AACH;AAEO,SAAS,oBAAoB,QAA8D;AAChG,SAAO,iBAAiB;AAAA,IACtB,UAAU,CAAC,GAAG,oBAAoB,YAAY,MAAM;AAAA,IACpD,SAAS,CAAC,EAAE,UAAU,MACpB;AAAA,MAAW,MACT,mBAAmB;AAAA,QACjB,GAAG;AAAA,QACH,MAAM;AAAA,QACN,OAAO;AAAA,MACT,CAAC;AAAA,IACH,EAAE;AAAA,IACJ,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;AAEnC,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,uBAAuB;AAAA,IAC9C,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,mBAAmB,CAAC;AAAA,IAChE;AAAA,EACF,CAAC;AACH;AAEO,SAAS,2BAA2B;AACzC,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,2BAA2B;AAAA,IAClD,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,mBAAmB,CAAC;AAAA,IAChE;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { isRedirectError } from "next/dist/client/components/redirect-error";
|
|
2
|
+
import { ApiError } from "../infra/api/types";
|
|
3
|
+
async function safeServerAction(fn) {
|
|
4
|
+
try {
|
|
5
|
+
const data = await fn();
|
|
6
|
+
return { success: true, data };
|
|
7
|
+
} catch (error) {
|
|
8
|
+
if (isRedirectError(error)) throw error;
|
|
9
|
+
const message = error instanceof ApiError ? error.message : error instanceof Error ? error.message : "Erro desconhecido";
|
|
10
|
+
return { success: false, error: message };
|
|
7
11
|
}
|
|
8
12
|
}
|
|
9
|
-
async function safeServerAction(action, ...args) {
|
|
10
|
-
const result = await action(...args);
|
|
11
|
-
if (result.status === 0 || result.result === "error" || result.error) {
|
|
12
|
-
const msg = result.message || result.error || "Erro na a\xE7\xE3o";
|
|
13
|
-
throw new ServerActionError(msg, result.status || 0);
|
|
14
|
-
}
|
|
15
|
-
const { error, ...successData } = result;
|
|
16
|
-
return successData;
|
|
17
|
-
}
|
|
18
13
|
export {
|
|
19
|
-
ServerActionError,
|
|
20
14
|
safeServerAction
|
|
21
15
|
};
|
|
22
16
|
//# sourceMappingURL=safeServerAction.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/safeServerAction.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/utils/safeServerAction.ts"],"sourcesContent":["import { isRedirectError } from 'next/dist/client/components/redirect-error';\nimport { ApiError } from '../infra/api/types';\nimport type { ActionResult } from '../infra/api/types';\n\nexport async function safeServerAction<T>(\n fn: () => Promise<T>\n): Promise<ActionResult<T>> {\n try {\n const data = await fn();\n return { success: true, data };\n } catch (error) {\n if (isRedirectError(error)) throw error;\n const message =\n error instanceof ApiError\n ? error.message\n : error instanceof Error\n ? error.message\n : 'Erro desconhecido';\n return { success: false, error: message };\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAChC,SAAS,gBAAgB;AAGzB,eAAsB,iBACpB,IAC0B;AAC1B,MAAI;AACF,UAAM,OAAO,MAAM,GAAG;AACtB,WAAO,EAAE,SAAS,MAAM,KAAK;AAAA,EAC/B,SAAS,OAAO;AACd,QAAI,gBAAgB,KAAK,EAAG,OAAM;AAClC,UAAM,UACJ,iBAAiB,WACb,MAAM,UACN,iBAAiB,QACf,MAAM,UACN;AACR,WAAO,EAAE,SAAS,OAAO,OAAO,QAAQ;AAAA,EAC1C;AACF;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function withAction(action) {
|
|
2
|
+
return async (...args) => {
|
|
3
|
+
const result = await action(...args);
|
|
4
|
+
if (!result.success) {
|
|
5
|
+
throw new Error(result.error ?? "Erro desconhecido");
|
|
6
|
+
}
|
|
7
|
+
return result.data;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
withAction
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=withAction.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/withAction.ts"],"sourcesContent":["import type { ActionResult } from '../infra/api/types';\n\nexport function withAction<TArgs extends any[], TData>(\n action: (...args: TArgs) => Promise<ActionResult<TData>>\n): (...args: TArgs) => Promise<TData> {\n return async (...args) => {\n const result = await action(...args);\n if (!result.success) {\n throw new Error(result.error ?? 'Erro desconhecido');\n }\n return result.data as TData;\n };\n}\n"],"mappings":"AAEO,SAAS,WACd,QACoC;AACpC,SAAO,UAAU,SAAS;AACxB,UAAM,SAAS,MAAM,OAAO,GAAG,IAAI;AACnC,QAAI,CAAC,OAAO,SAAS;AACnB,YAAM,IAAI,MAAM,OAAO,SAAS,mBAAmB;AAAA,IACrD;AACA,WAAO,OAAO;AAAA,EAChB;AACF;","names":[]}
|