@greatapps/common 1.1.522 → 1.1.525
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/ConfigurationsMyAccountModal.mjs +4 -10
- package/dist/components/account/ConfigurationsMyAccountModal.mjs.map +1 -1
- package/dist/components/account/hooks/useDisableTwoFactorAuthForm.mjs +1 -3
- package/dist/components/account/hooks/useDisableTwoFactorAuthForm.mjs.map +1 -1
- package/dist/components/account/sections/ChangeEmailModal.mjs +1 -3
- package/dist/components/account/sections/ChangeEmailModal.mjs.map +1 -1
- package/dist/components/account/sections/ChangePhoneModal.mjs +1 -3
- package/dist/components/account/sections/ChangePhoneModal.mjs.map +1 -1
- package/dist/components/account/sections/MyProfileSection.mjs +1 -2
- package/dist/components/account/sections/MyProfileSection.mjs.map +1 -1
- package/dist/components/embeds/EmbedWidgets.mjs +1 -3
- package/dist/components/embeds/EmbedWidgets.mjs.map +1 -1
- package/dist/components/layouts/AppMobileNavBar.mjs +1 -3
- package/dist/components/layouts/AppMobileNavBar.mjs.map +1 -1
- package/dist/components/layouts/AppNavBar.mjs +8 -4
- package/dist/components/layouts/AppNavBar.mjs.map +1 -1
- package/dist/components/layouts/NavBar.mjs +9 -10
- package/dist/components/layouts/NavBar.mjs.map +1 -1
- package/dist/components/layouts/NotificationsPopover.mjs +2 -5
- package/dist/components/layouts/NotificationsPopover.mjs.map +1 -1
- package/dist/components/layouts/ProfilePopover.mjs +2 -4
- package/dist/components/layouts/ProfilePopover.mjs.map +1 -1
- package/dist/components/layouts/SideBarNavigation.mjs +1 -4
- package/dist/components/layouts/SideBarNavigation.mjs.map +1 -1
- package/dist/components/modals/BuyCreditsModal.mjs +9 -26
- package/dist/components/modals/BuyCreditsModal.mjs.map +1 -1
- package/dist/components/modals/cards/AddCardModal.mjs +1 -3
- package/dist/components/modals/cards/AddCardModal.mjs.map +1 -1
- package/dist/components/navigation/CancelledSubscriptionBanner.mjs +1 -1
- package/dist/components/navigation/CancelledSubscriptionBanner.mjs.map +1 -1
- package/dist/components/navigation/ProjectSelectorPopover.mjs +6 -7
- package/dist/components/navigation/ProjectSelectorPopover.mjs.map +1 -1
- package/dist/components/navigation/subcomponents/ProjectSelector.mjs +19 -39
- package/dist/components/navigation/subcomponents/ProjectSelector.mjs.map +1 -1
- package/dist/components/navigation/types.mjs +1 -0
- package/dist/components/navigation/types.mjs.map +1 -0
- package/dist/components/pages/NotFoundPage.mjs +2 -2
- package/dist/components/pages/NotFoundPage.mjs.map +1 -1
- package/dist/components/ui/buttons/Button.mjs +2 -7
- package/dist/components/ui/buttons/Button.mjs.map +1 -1
- package/dist/components/ui/data-display/CardItem.mjs +1 -1
- package/dist/components/ui/data-display/CardItem.mjs.map +1 -1
- package/dist/components/ui/data-display/PaymentInfoCard.mjs +2 -4
- package/dist/components/ui/data-display/PaymentInfoCard.mjs.map +1 -1
- package/dist/components/ui/data-display/UserAvatar.mjs +2 -6
- package/dist/components/ui/data-display/UserAvatar.mjs.map +1 -1
- package/dist/components/ui/feedback/DefaultCircularProgress.mjs +1 -4
- package/dist/components/ui/feedback/DefaultCircularProgress.mjs.map +1 -1
- package/dist/components/ui/feedback/Toast.mjs +2 -7
- package/dist/components/ui/feedback/Toast.mjs.map +1 -1
- package/dist/components/ui/form/FormField.mjs +1 -1
- package/dist/components/ui/form/FormField.mjs.map +1 -1
- package/dist/components/ui/form/Select.mjs +1 -1
- package/dist/components/ui/form/Select.mjs.map +1 -1
- package/dist/components/ui/overlay/Popover.mjs +1 -1
- package/dist/components/ui/overlay/Popover.mjs.map +1 -1
- package/dist/components/ui/overlay/Sheet.mjs +6 -8
- package/dist/components/ui/overlay/Sheet.mjs.map +1 -1
- package/dist/components/widgets/ImageUpload/ImageUpload.mjs +1 -2
- package/dist/components/widgets/ImageUpload/ImageUpload.mjs.map +1 -1
- package/dist/components/widgets/notifications/NotificationCard.mjs +1 -4
- package/dist/components/widgets/notifications/NotificationCard.mjs.map +1 -1
- package/dist/enums/AccountSectionType.mjs +0 -1
- package/dist/enums/AccountSectionType.mjs.map +1 -1
- package/dist/index.mjs +8 -90
- package/dist/index.mjs.map +1 -1
- package/dist/modules/accounts/hooks/current-account.hook.mjs +2 -5
- package/dist/modules/accounts/hooks/current-account.hook.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useAccountManagement.mjs +9 -19
- package/dist/modules/accounts/hooks/useAccountManagement.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useCurrencies.mjs +1 -3
- package/dist/modules/accounts/hooks/useCurrencies.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useTimezones.mjs +1 -3
- package/dist/modules/accounts/hooks/useTimezones.mjs.map +1 -1
- package/dist/modules/auth/hooks/useUserQuery.mjs +6 -15
- package/dist/modules/auth/hooks/useUserQuery.mjs.map +1 -1
- package/dist/modules/cards/hooks/cards.hook.mjs +3 -11
- package/dist/modules/cards/hooks/cards.hook.mjs.map +1 -1
- package/dist/modules/cards/hooks/create-card.hook.mjs +2 -13
- package/dist/modules/cards/hooks/create-card.hook.mjs.map +1 -1
- package/dist/modules/cards/services/cards.service.mjs +4 -45
- package/dist/modules/cards/services/cards.service.mjs.map +1 -1
- package/dist/modules/cards/types.mjs +3 -11
- package/dist/modules/cards/types.mjs.map +1 -1
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs +1 -3
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs.map +1 -1
- package/dist/modules/plans/hooks/list-plans.hook.mjs +1 -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 -4
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs.map +1 -1
- package/dist/modules/plans/services/plans.service.mjs +2 -4
- package/dist/modules/plans/services/plans.service.mjs.map +1 -1
- package/dist/modules/plans/types/plan.type.mjs.map +1 -1
- package/dist/modules/plans/utils/map-api-plan-to-ui.mjs +10 -20
- package/dist/modules/plans/utils/map-api-plan-to-ui.mjs.map +1 -1
- package/dist/modules/projects/hooks/add-project-user.hook.mjs +12 -15
- package/dist/modules/projects/hooks/add-project-user.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-all-account-users.hook.mjs +1 -3
- package/dist/modules/projects/hooks/list-all-account-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-available-users.hook.mjs +1 -3
- package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-project-users.hook.mjs +1 -3
- package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/remove-project-user.hook.mjs +12 -15
- package/dist/modules/projects/hooks/remove-project-user.hook.mjs.map +1 -1
- package/dist/modules/projects/types.mjs +4 -19
- package/dist/modules/projects/types.mjs.map +1 -1
- package/dist/modules/subscriptions/constants/query-keys.constants.mjs +0 -2
- package/dist/modules/subscriptions/constants/query-keys.constants.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +2 -5
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +1 -3
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/update-subscription-plan.hook.mjs +3 -6
- package/dist/modules/subscriptions/hooks/update-subscription-plan.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/types/calculate-subscription.type.mjs +2 -29
- package/dist/modules/subscriptions/types/calculate-subscription.type.mjs.map +1 -1
- package/dist/modules/subscriptions/utils/periodicity.mjs +0 -7
- package/dist/modules/subscriptions/utils/periodicity.mjs.map +1 -1
- package/dist/modules/users/action/list-messages.action.mjs +2 -14
- package/dist/modules/users/action/list-messages.action.mjs.map +1 -1
- package/dist/modules/users/hooks/messages.hook.mjs +4 -9
- package/dist/modules/users/hooks/messages.hook.mjs.map +1 -1
- package/dist/modules/users/services/messages.service.mjs.map +1 -1
- package/dist/providers/auth.provider.mjs +4 -6
- package/dist/providers/auth.provider.mjs.map +1 -1
- package/dist/providers/query.provider.mjs +2 -2
- package/dist/providers/query.provider.mjs.map +1 -1
- package/dist/providers/whitelabel.provider.mjs +0 -5
- package/dist/providers/whitelabel.provider.mjs.map +1 -1
- package/dist/server.mjs +0 -14
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/widgets/ImageUpload/ImageCropModal.tsx +10 -37
- package/dist/components/account/sections/TokenSection.mjs +0 -72
- package/dist/components/account/sections/TokenSection.mjs.map +0 -1
- package/dist/components/embeds/ClarityEmbed.mjs +0 -55
- package/dist/components/embeds/ClarityEmbed.mjs.map +0 -1
- package/dist/hooks/useAuthQueryKey.mjs +0 -23
- package/dist/hooks/useAuthQueryKey.mjs.map +0 -1
- package/dist/infra/utils/array.mjs +0 -34
- package/dist/infra/utils/array.mjs.map +0 -1
- package/dist/modules/accounts/actions/get-account-token.action.mjs +0 -10
- package/dist/modules/accounts/actions/get-account-token.action.mjs.map +0 -1
- package/dist/modules/accounts/hooks/use-account-token.hook.mjs +0 -15
- package/dist/modules/accounts/hooks/use-account-token.hook.mjs.map +0 -1
- package/dist/modules/accounts/services/account-token.service.mjs +0 -32
- package/dist/modules/accounts/services/account-token.service.mjs.map +0 -1
- package/dist/modules/cards/actions/delete-card.action.mjs +0 -10
- package/dist/modules/cards/actions/delete-card.action.mjs.map +0 -1
- package/dist/modules/cards/actions/find-card-by-id.action.mjs +0 -10
- package/dist/modules/cards/actions/find-card-by-id.action.mjs.map +0 -1
- package/dist/modules/cards/actions/set-default-card.action.mjs +0 -10
- package/dist/modules/cards/actions/set-default-card.action.mjs.map +0 -1
- package/dist/modules/cards/hooks/card-by-id.hook.mjs +0 -22
- package/dist/modules/cards/hooks/card-by-id.hook.mjs.map +0 -1
- package/dist/modules/cards/hooks/delete-card.hook.mjs +0 -50
- package/dist/modules/cards/hooks/delete-card.hook.mjs.map +0 -1
- package/dist/modules/cards/hooks/set-default-card.hook.mjs +0 -51
- package/dist/modules/cards/hooks/set-default-card.hook.mjs.map +0 -1
- package/dist/modules/projects/actions/create-project.action.mjs +0 -10
- package/dist/modules/projects/actions/create-project.action.mjs.map +0 -1
- package/dist/modules/projects/actions/delete-project.action.mjs +0 -10
- package/dist/modules/projects/actions/delete-project.action.mjs.map +0 -1
- package/dist/modules/projects/actions/find-project.action.mjs +0 -10
- package/dist/modules/projects/actions/find-project.action.mjs.map +0 -1
- package/dist/modules/projects/actions/list-projects.action.mjs +0 -10
- package/dist/modules/projects/actions/list-projects.action.mjs.map +0 -1
- package/dist/modules/projects/actions/update-project.action.mjs +0 -10
- package/dist/modules/projects/actions/update-project.action.mjs.map +0 -1
- package/dist/modules/projects/hooks/create-project.hook.mjs +0 -71
- package/dist/modules/projects/hooks/create-project.hook.mjs.map +0 -1
- package/dist/modules/projects/hooks/delete-project.hook.mjs +0 -53
- package/dist/modules/projects/hooks/delete-project.hook.mjs.map +0 -1
- package/dist/modules/projects/hooks/find-project.hook.mjs +0 -19
- package/dist/modules/projects/hooks/find-project.hook.mjs.map +0 -1
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs +0 -39
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs.map +0 -1
- package/dist/modules/projects/hooks/list-projects.hook.mjs +0 -22
- package/dist/modules/projects/hooks/list-projects.hook.mjs.map +0 -1
- package/dist/modules/projects/hooks/update-project.hook.mjs +0 -70
- package/dist/modules/projects/hooks/update-project.hook.mjs.map +0 -1
- package/dist/modules/projects/services/projects.service.mjs +0 -99
- package/dist/modules/projects/services/projects.service.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/projects/hooks/list-all-account-users.hook.ts"],"sourcesContent":["'use client';\n\nimport { useInfiniteQuery } from '@tanstack/react-query';\nimport { listAllAccountUsersAction } from '../actions/list-all-account-users.action';\nimport { withAction } from '../../../utils/withAction';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/projects/hooks/list-all-account-users.hook.ts"],"sourcesContent":["'use client';\n\nimport { useInfiniteQuery } from '@tanstack/react-query';\nimport { listAllAccountUsersAction } from '../actions/list-all-account-users.action';\nimport { withAction } from '../../../utils/withAction';\n\nconst PAGE_SIZE = 20;\n\nexport const LIST_ALL_ACCOUNT_USERS_BASE_KEY = () => ['account-users', 'all'];\nexport const LIST_ALL_ACCOUNT_USERS_QUERY_KEY = (search: string = '', projectId?: number) => [\n ...LIST_ALL_ACCOUNT_USERS_BASE_KEY(),\n search,\n projectId,\n];\n\nexport function useListAllAccountUsers(search: string = '', projectId?: number) {\n return useInfiniteQuery({\n queryKey: LIST_ALL_ACCOUNT_USERS_QUERY_KEY(search, projectId),\n queryFn: ({ pageParam }) =>\n withAction(() =>\n listAllAccountUsersAction({\n search: search || undefined,\n page: pageParam as number,\n limit: PAGE_SIZE,\n inProject: projectId,\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"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,iCAAiC;AAC1C,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,kCAAkC,MAAM,CAAC,iBAAiB,KAAK;AACrE,MAAM,mCAAmC,CAAC,SAAiB,IAAI,cAAuB;AAAA,EAC3F,GAAG,gCAAgC;AAAA,EACnC;AAAA,EACA;AACF;AAEO,SAAS,uBAAuB,SAAiB,IAAI,WAAoB;AAC9E,SAAO,iBAAiB;AAAA,IACtB,UAAU,iCAAiC,QAAQ,SAAS;AAAA,IAC5D,SAAS,CAAC,EAAE,UAAU,MACpB;AAAA,MAAW,MACT,0BAA0B;AAAA,QACxB,QAAQ,UAAU;AAAA,QAClB,MAAM;AAAA,QACN,OAAO;AAAA,QACP,WAAW;AAAA,MACb,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;","names":[]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
3
3
|
import { listAvailableUsersAction } from "../actions/list-available-users.action";
|
|
4
4
|
import { withAction } from "../../../utils/withAction";
|
|
5
|
-
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
6
5
|
const PAGE_SIZE = 20;
|
|
7
6
|
const LIST_AVAILABLE_USERS_BASE_KEY = (projectId) => ["project-users", projectId, "out"];
|
|
8
7
|
const LIST_AVAILABLE_USERS_QUERY_KEY = (projectId, search = "") => [
|
|
@@ -10,9 +9,8 @@ const LIST_AVAILABLE_USERS_QUERY_KEY = (projectId, search = "") => [
|
|
|
10
9
|
search
|
|
11
10
|
];
|
|
12
11
|
function useListAvailableUsers(projectId, search = "") {
|
|
13
|
-
const queryKey = useAuthQueryKey([...LIST_AVAILABLE_USERS_QUERY_KEY(projectId, search)]);
|
|
14
12
|
return useInfiniteQuery({
|
|
15
|
-
queryKey,
|
|
13
|
+
queryKey: LIST_AVAILABLE_USERS_QUERY_KEY(projectId, search),
|
|
16
14
|
queryFn: ({ pageParam }) => withAction(
|
|
17
15
|
() => listAvailableUsersAction(projectId, {
|
|
18
16
|
search: search || void 0,
|
|
@@ -1 +1 @@
|
|
|
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';\
|
|
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":[]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
3
3
|
import { listProjectUsersAction } from "../actions/list-project-users.action";
|
|
4
4
|
import { withAction } from "../../../utils/withAction";
|
|
5
|
-
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
6
5
|
const PAGE_SIZE = 20;
|
|
7
6
|
const LIST_PROJECT_USERS_BASE_KEY = (projectId) => ["project-users", projectId, "in"];
|
|
8
7
|
const LIST_PROJECT_USERS_QUERY_KEY = (projectId, search = "") => [
|
|
@@ -10,9 +9,8 @@ const LIST_PROJECT_USERS_QUERY_KEY = (projectId, search = "") => [
|
|
|
10
9
|
search
|
|
11
10
|
];
|
|
12
11
|
function useListProjectUsers(projectId, search = "") {
|
|
13
|
-
const queryKey = useAuthQueryKey([...LIST_PROJECT_USERS_QUERY_KEY(projectId, search)]);
|
|
14
12
|
return useInfiniteQuery({
|
|
15
|
-
queryKey,
|
|
13
|
+
queryKey: LIST_PROJECT_USERS_QUERY_KEY(projectId, search),
|
|
16
14
|
queryFn: ({ pageParam }) => withAction(
|
|
17
15
|
() => listProjectUsersAction(projectId, {
|
|
18
16
|
search: search || void 0,
|
|
@@ -1 +1 @@
|
|
|
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';\
|
|
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":[]}
|
|
@@ -3,24 +3,21 @@ import { useQueryClient, useMutation } from "@tanstack/react-query";
|
|
|
3
3
|
import { removeProjectUserAction } from "../actions/remove-project-user.action";
|
|
4
4
|
import { LIST_PROJECT_USERS_BASE_KEY } from "./list-project-users.hook";
|
|
5
5
|
import { LIST_ALL_ACCOUNT_USERS_BASE_KEY } from "./list-all-account-users.hook";
|
|
6
|
-
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
7
6
|
function useRemoveProjectUser(projectId) {
|
|
8
7
|
const queryClient = useQueryClient();
|
|
9
|
-
const allAccountUsersKey = useAuthQueryKey([...LIST_ALL_ACCOUNT_USERS_BASE_KEY()]);
|
|
10
|
-
const projectUsersKey = useAuthQueryKey([...LIST_PROJECT_USERS_BASE_KEY(projectId)]);
|
|
11
8
|
return useMutation({
|
|
12
|
-
mutationFn: (
|
|
13
|
-
onMutate: async (
|
|
14
|
-
await queryClient.cancelQueries({ queryKey:
|
|
15
|
-
await queryClient.cancelQueries({ queryKey:
|
|
9
|
+
mutationFn: (userId) => removeProjectUserAction({ projectId, users: [userId] }),
|
|
10
|
+
onMutate: async (userId) => {
|
|
11
|
+
await queryClient.cancelQueries({ queryKey: LIST_ALL_ACCOUNT_USERS_BASE_KEY() });
|
|
12
|
+
await queryClient.cancelQueries({ queryKey: LIST_PROJECT_USERS_BASE_KEY(projectId) });
|
|
16
13
|
const prevAccountUsers = queryClient.getQueriesData({
|
|
17
|
-
queryKey:
|
|
14
|
+
queryKey: LIST_ALL_ACCOUNT_USERS_BASE_KEY()
|
|
18
15
|
});
|
|
19
16
|
const prevProjectUsers = queryClient.getQueriesData({
|
|
20
|
-
queryKey:
|
|
17
|
+
queryKey: LIST_PROJECT_USERS_BASE_KEY(projectId)
|
|
21
18
|
});
|
|
22
19
|
queryClient.setQueriesData(
|
|
23
|
-
{ queryKey:
|
|
20
|
+
{ queryKey: LIST_ALL_ACCOUNT_USERS_BASE_KEY(), exact: false },
|
|
24
21
|
(old) => {
|
|
25
22
|
if (!old) return old;
|
|
26
23
|
return {
|
|
@@ -28,14 +25,14 @@ function useRemoveProjectUser(projectId) {
|
|
|
28
25
|
pages: old.pages.map((page) => ({
|
|
29
26
|
...page,
|
|
30
27
|
data: page.data.map(
|
|
31
|
-
(u) => u.id ===
|
|
28
|
+
(u) => u.id === userId ? { ...u, in_project: false } : u
|
|
32
29
|
)
|
|
33
30
|
}))
|
|
34
31
|
};
|
|
35
32
|
}
|
|
36
33
|
);
|
|
37
34
|
queryClient.setQueriesData(
|
|
38
|
-
{ queryKey:
|
|
35
|
+
{ queryKey: LIST_PROJECT_USERS_BASE_KEY(projectId), exact: false },
|
|
39
36
|
(old) => {
|
|
40
37
|
if (!old?.pages.length) return old;
|
|
41
38
|
return {
|
|
@@ -48,13 +45,13 @@ function useRemoveProjectUser(projectId) {
|
|
|
48
45
|
);
|
|
49
46
|
return { prevAccountUsers, prevProjectUsers };
|
|
50
47
|
},
|
|
51
|
-
onError: (_err,
|
|
48
|
+
onError: (_err, _userId, ctx) => {
|
|
52
49
|
ctx?.prevAccountUsers.forEach(([key, data]) => queryClient.setQueryData(key, data));
|
|
53
50
|
ctx?.prevProjectUsers.forEach(([key, data]) => queryClient.setQueryData(key, data));
|
|
54
51
|
},
|
|
55
52
|
onSettled: () => {
|
|
56
|
-
queryClient.invalidateQueries({ queryKey:
|
|
57
|
-
queryClient.invalidateQueries({ queryKey:
|
|
53
|
+
queryClient.invalidateQueries({ queryKey: LIST_PROJECT_USERS_BASE_KEY(projectId) });
|
|
54
|
+
queryClient.invalidateQueries({ queryKey: LIST_ALL_ACCOUNT_USERS_BASE_KEY() });
|
|
58
55
|
}
|
|
59
56
|
});
|
|
60
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/projects/hooks/remove-project-user.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQueryClient, useMutation, InfiniteData } from '@tanstack/react-query';\nimport { removeProjectUserAction } from '../actions/remove-project-user.action';\nimport { LIST_PROJECT_USERS_BASE_KEY } from './list-project-users.hook';\nimport { LIST_ALL_ACCOUNT_USERS_BASE_KEY } from './list-all-account-users.hook';\nimport type { UsersPage, AccountUser, ProjectUser } from '../types';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/projects/hooks/remove-project-user.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQueryClient, useMutation, InfiniteData } from '@tanstack/react-query';\nimport { removeProjectUserAction } from '../actions/remove-project-user.action';\nimport { LIST_PROJECT_USERS_BASE_KEY } from './list-project-users.hook';\nimport { LIST_ALL_ACCOUNT_USERS_BASE_KEY } from './list-all-account-users.hook';\nimport type { UsersPage, AccountUser, ProjectUser } from '../types';\n\nexport function useRemoveProjectUser(projectId: number) {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: (userId: number) =>\n removeProjectUserAction({ projectId, users: [userId] }),\n\n onMutate: async (userId) => {\n await queryClient.cancelQueries({ queryKey: LIST_ALL_ACCOUNT_USERS_BASE_KEY() });\n await queryClient.cancelQueries({ queryKey: LIST_PROJECT_USERS_BASE_KEY(projectId) });\n\n const prevAccountUsers = queryClient.getQueriesData<InfiniteData<UsersPage<AccountUser>>>({\n queryKey: LIST_ALL_ACCOUNT_USERS_BASE_KEY(),\n });\n const prevProjectUsers = queryClient.getQueriesData<InfiniteData<UsersPage<ProjectUser>>>({\n queryKey: LIST_PROJECT_USERS_BASE_KEY(projectId),\n });\n\n queryClient.setQueriesData<InfiniteData<UsersPage<AccountUser>>>(\n { queryKey: LIST_ALL_ACCOUNT_USERS_BASE_KEY(), exact: false },\n (old) => {\n if (!old) return old;\n return {\n ...old,\n pages: old.pages.map((page) => ({\n ...page,\n data: page.data.map((u) =>\n u.id === userId ? { ...u, in_project: false } : u\n ),\n })),\n };\n }\n );\n\n queryClient.setQueriesData<InfiniteData<UsersPage<ProjectUser>>>(\n { queryKey: LIST_PROJECT_USERS_BASE_KEY(projectId), exact: false },\n (old) => {\n if (!old?.pages.length) return old;\n return {\n ...old,\n pages: old.pages.map((page, i) =>\n i === 0 ? { ...page, total: page.total - 1 } : page\n ),\n };\n }\n );\n\n return { prevAccountUsers, prevProjectUsers };\n },\n\n onError: (_err, _userId, ctx) => {\n ctx?.prevAccountUsers.forEach(([key, data]) => queryClient.setQueryData(key, data));\n ctx?.prevProjectUsers.forEach(([key, data]) => queryClient.setQueryData(key, data));\n },\n\n onSettled: () => {\n queryClient.invalidateQueries({ queryKey: LIST_PROJECT_USERS_BASE_KEY(projectId) });\n queryClient.invalidateQueries({ queryKey: LIST_ALL_ACCOUNT_USERS_BASE_KEY() });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB,mBAAiC;AAC1D,SAAS,+BAA+B;AACxC,SAAS,mCAAmC;AAC5C,SAAS,uCAAuC;AAGzC,SAAS,qBAAqB,WAAmB;AACtD,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,WACX,wBAAwB,EAAE,WAAW,OAAO,CAAC,MAAM,EAAE,CAAC;AAAA,IAExD,UAAU,OAAO,WAAW;AAC1B,YAAM,YAAY,cAAc,EAAE,UAAU,gCAAgC,EAAE,CAAC;AAC/E,YAAM,YAAY,cAAc,EAAE,UAAU,4BAA4B,SAAS,EAAE,CAAC;AAEpF,YAAM,mBAAmB,YAAY,eAAqD;AAAA,QACxF,UAAU,gCAAgC;AAAA,MAC5C,CAAC;AACD,YAAM,mBAAmB,YAAY,eAAqD;AAAA,QACxF,UAAU,4BAA4B,SAAS;AAAA,MACjD,CAAC;AAED,kBAAY;AAAA,QACV,EAAE,UAAU,gCAAgC,GAAG,OAAO,MAAM;AAAA,QAC5D,CAAC,QAAQ;AACP,cAAI,CAAC,IAAK,QAAO;AACjB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,OAAO,IAAI,MAAM,IAAI,CAAC,UAAU;AAAA,cAC9B,GAAG;AAAA,cACH,MAAM,KAAK,KAAK;AAAA,gBAAI,CAAC,MACnB,EAAE,OAAO,SAAS,EAAE,GAAG,GAAG,YAAY,MAAM,IAAI;AAAA,cAClD;AAAA,YACF,EAAE;AAAA,UACJ;AAAA,QACF;AAAA,MACF;AAEA,kBAAY;AAAA,QACV,EAAE,UAAU,4BAA4B,SAAS,GAAG,OAAO,MAAM;AAAA,QACjE,CAAC,QAAQ;AACP,cAAI,CAAC,KAAK,MAAM,OAAQ,QAAO;AAC/B,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,OAAO,IAAI,MAAM;AAAA,cAAI,CAAC,MAAM,MAC1B,MAAM,IAAI,EAAE,GAAG,MAAM,OAAO,KAAK,QAAQ,EAAE,IAAI;AAAA,YACjD;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA,aAAO,EAAE,kBAAkB,iBAAiB;AAAA,IAC9C;AAAA,IAEA,SAAS,CAAC,MAAM,SAAS,QAAQ;AAC/B,WAAK,iBAAiB,QAAQ,CAAC,CAAC,KAAK,IAAI,MAAM,YAAY,aAAa,KAAK,IAAI,CAAC;AAClF,WAAK,iBAAiB,QAAQ,CAAC,CAAC,KAAK,IAAI,MAAM,YAAY,aAAa,KAAK,IAAI,CAAC;AAAA,IACpF;AAAA,IAEA,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,4BAA4B,SAAS,EAAE,CAAC;AAClF,kBAAY,kBAAkB,EAAE,UAAU,gCAAgC,EAAE,CAAC;AAAA,IAC/E;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
const ProjectSchema = z.object({
|
|
3
|
-
id: z.coerce.number(),
|
|
4
|
-
id_wl: z.coerce.number(),
|
|
5
|
-
id_account: z.coerce.number(),
|
|
6
|
-
title: z.string(),
|
|
7
|
-
photo: z.string().nullable().optional(),
|
|
8
|
-
id_api: z.coerce.number().nullable().optional(),
|
|
9
|
-
id_form_integration: z.coerce.number().nullable().optional(),
|
|
10
|
-
total_users: z.coerce.number().optional().default(0),
|
|
11
|
-
deleted: z.union([z.boolean(), z.number()]).transform((v) => Boolean(v)).default(false),
|
|
12
|
-
datetime_add: z.string().nullable().optional(),
|
|
13
|
-
datetime_alt: z.string().nullable().optional(),
|
|
14
|
-
datetime_del: z.string().nullable().optional()
|
|
15
|
-
});
|
|
16
2
|
const ProjectUserSchema = z.object({
|
|
17
|
-
id_user: z.
|
|
18
|
-
id_account: z.
|
|
19
|
-
id_project: z.
|
|
3
|
+
id_user: z.union([z.number(), z.string()]).transform(Number),
|
|
4
|
+
id_account: z.union([z.number(), z.string()]).transform(Number),
|
|
5
|
+
id_project: z.union([z.number(), z.string()]).transform(Number),
|
|
20
6
|
name: z.string().nullable(),
|
|
21
7
|
email: z.string().nullable(),
|
|
22
8
|
profile: z.string().nullable().optional().default("viewer"),
|
|
23
9
|
photo: z.string().nullable().optional()
|
|
24
10
|
});
|
|
25
11
|
const AccountUserSchema = z.object({
|
|
26
|
-
id: z.
|
|
12
|
+
id: z.union([z.number(), z.string()]).transform(Number),
|
|
27
13
|
name: z.string().nullable(),
|
|
28
14
|
email: z.string().nullable(),
|
|
29
15
|
profile: z.string().nullable().optional().default("viewer"),
|
|
@@ -32,7 +18,6 @@ const AccountUserSchema = z.object({
|
|
|
32
18
|
});
|
|
33
19
|
export {
|
|
34
20
|
AccountUserSchema,
|
|
35
|
-
ProjectSchema,
|
|
36
21
|
ProjectUserSchema
|
|
37
22
|
};
|
|
38
23
|
//# sourceMappingURL=types.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/modules/projects/types.ts"],"sourcesContent":["import { z } from \"zod\";\r\n\r\
|
|
1
|
+
{"version":3,"sources":["../../../src/modules/projects/types.ts"],"sourcesContent":["import { z } from \"zod\";\r\n\r\nexport const ProjectUserSchema = z.object({\r\n id_user: z.union([z.number(), z.string()]).transform(Number),\r\n id_account: z.union([z.number(), z.string()]).transform(Number),\r\n id_project: z.union([z.number(), z.string()]).transform(Number),\r\n name: z.string().nullable(),\r\n email: z.string().nullable(),\r\n profile: z.string().nullable().optional().default(\"viewer\"),\r\n photo: z.string().nullable().optional(),\r\n});\r\n\r\nexport type ProjectUser = z.infer<typeof ProjectUserSchema>;\r\n\r\nexport const AccountUserSchema = z.object({\r\n id: z.union([z.number(), z.string()]).transform(Number),\r\n name: z.string().nullable(),\r\n email: z.string().nullable(),\r\n profile: z.string().nullable().optional().default(\"viewer\"),\r\n photo: z.string().nullable().optional(),\r\n in_project: z.boolean().optional(),\r\n});\r\n\r\nexport type AccountUser = z.infer<typeof AccountUserSchema>;\r\n\r\nexport interface AddRemoveProjectUsersParams {\r\n projectId: number;\r\n users: number[];\r\n}\r\n\r\nexport interface ListUsersParams {\r\n search?: string;\r\n page?: number;\r\n limit?: number;\r\n inProject?: number;\r\n}\r\n\r\nexport interface UsersPage<T> {\r\n data: T[];\r\n total: number;\r\n page: number;\r\n}\r\n"],"mappings":"AAAA,SAAS,SAAS;AAEX,MAAM,oBAAoB,EAAE,OAAO;AAAA,EACxC,SAAS,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,UAAU,MAAM;AAAA,EAC3D,YAAY,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,UAAU,MAAM;AAAA,EAC9D,YAAY,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,UAAU,MAAM;AAAA,EAC9D,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,QAAQ;AAAA,EAC1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AACxC,CAAC;AAIM,MAAM,oBAAoB,EAAE,OAAO;AAAA,EACxC,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,UAAU,MAAM;AAAA,EACtD,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,QAAQ;AAAA,EAC1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EACtC,YAAY,EAAE,QAAQ,EAAE,SAAS;AACnC,CAAC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/constants/query-keys.constants.ts"],"sourcesContent":["export const SUBSCRIPTIONS_QUERY_KEY = ['subscriptions']
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/constants/query-keys.constants.ts"],"sourcesContent":["export const SUBSCRIPTIONS_QUERY_KEY = ['subscriptions'];\n"],"mappings":"AAAO,MAAM,0BAA0B,CAAC,eAAe;","names":[]}
|
|
@@ -3,15 +3,12 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
3
3
|
import { listSubscriptionsAction } from "../actions/list-subscriptions.action";
|
|
4
4
|
import { SUBSCRIPTIONS_QUERY_KEY } from "../constants/query-keys.constants";
|
|
5
5
|
import { withAction } from "../../../utils/withAction";
|
|
6
|
-
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
7
6
|
function useActiveSubscription() {
|
|
8
|
-
const queryKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY, "active"]);
|
|
9
7
|
return useQuery({
|
|
10
|
-
queryKey,
|
|
8
|
+
queryKey: [...SUBSCRIPTIONS_QUERY_KEY, "active"],
|
|
11
9
|
queryFn: async () => {
|
|
12
10
|
return await withAction(listSubscriptionsAction)({ limit: 1 });
|
|
13
|
-
}
|
|
14
|
-
staleTime: 1e4
|
|
11
|
+
}
|
|
15
12
|
});
|
|
16
13
|
}
|
|
17
14
|
export {
|
|
@@ -1 +1 @@
|
|
|
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 { SUBSCRIPTIONS_QUERY_KEY } from \"../constants/query-keys.constants\";\nimport { withAction } from \"../../../utils/withAction\";\
|
|
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 { SUBSCRIPTIONS_QUERY_KEY } from \"../constants/query-keys.constants\";\nimport { withAction } from \"../../../utils/withAction\";\n\nexport function useActiveSubscription() {\n return useQuery({\n queryKey: [...SUBSCRIPTIONS_QUERY_KEY, \"active\"],\n queryFn: async () => {\n return await withAction(listSubscriptionsAction)({ limit: 1 });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,+BAA+B;AACxC,SAAS,kBAAkB;AAEpB,SAAS,wBAAwB;AACtC,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,GAAG,yBAAyB,QAAQ;AAAA,IAC/C,SAAS,YAAY;AACnB,aAAO,MAAM,WAAW,uBAAuB,EAAE,EAAE,OAAO,EAAE,CAAC;AAAA,IAC/D;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -5,11 +5,9 @@ import { parseResult } from "../../../infra/utils/parser";
|
|
|
5
5
|
import { SubscriptionSchema } from "../types/subscription.type";
|
|
6
6
|
import { withAction } from "../../../utils/withAction";
|
|
7
7
|
import { SUBSCRIPTIONS_QUERY_KEY } from "../constants/query-keys.constants";
|
|
8
|
-
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
9
8
|
function useSubscriptions(params) {
|
|
10
|
-
const queryKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY, params]);
|
|
11
9
|
return useQuery({
|
|
12
|
-
queryKey,
|
|
10
|
+
queryKey: [...SUBSCRIPTIONS_QUERY_KEY, params],
|
|
13
11
|
queryFn: async () => parseResult(SubscriptionSchema, await withAction(() => listSubscriptionsAction(params))())
|
|
14
12
|
});
|
|
15
13
|
}
|
|
@@ -1 +1 @@
|
|
|
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/subscription.type';\nimport { withAction } from '../../../utils/withAction';\nimport { SUBSCRIPTIONS_QUERY_KEY } from '../constants/query-keys.constants';\
|
|
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/subscription.type';\nimport { withAction } from '../../../utils/withAction';\nimport { SUBSCRIPTIONS_QUERY_KEY } from '../constants/query-keys.constants';\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;AAC3B,SAAS,+BAA+B;AAEjC,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":[]}
|
|
@@ -2,20 +2,17 @@
|
|
|
2
2
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
3
|
import { withAction } from "../../../utils/withAction";
|
|
4
4
|
import { updateSubscriptionPlanAction } from "../actions/update-subscription-plan.action";
|
|
5
|
-
import { SUBSCRIPTIONS_QUERY_KEY
|
|
6
|
-
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
5
|
+
import { SUBSCRIPTIONS_QUERY_KEY } from "../constants/query-keys.constants";
|
|
7
6
|
function useUpdateSubscriptionPlan() {
|
|
8
7
|
const queryClient = useQueryClient();
|
|
9
|
-
const subscriptionsKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY]);
|
|
10
|
-
const chargesKey = useAuthQueryKey([...CHARGES_QUERY_KEY]);
|
|
11
8
|
return useMutation({
|
|
12
9
|
mutationFn: ({
|
|
13
10
|
subscriptionId,
|
|
14
11
|
data
|
|
15
12
|
}) => withAction(updateSubscriptionPlanAction)(subscriptionId, data),
|
|
16
13
|
onSuccess: () => {
|
|
17
|
-
queryClient.invalidateQueries({ queryKey:
|
|
18
|
-
queryClient.invalidateQueries({ queryKey:
|
|
14
|
+
queryClient.invalidateQueries({ queryKey: SUBSCRIPTIONS_QUERY_KEY });
|
|
15
|
+
queryClient.invalidateQueries({ queryKey: ["charges"] });
|
|
19
16
|
}
|
|
20
17
|
});
|
|
21
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/update-subscription-plan.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { updateSubscriptionPlanAction } from '../actions/update-subscription-plan.action';\nimport { SUBSCRIPTIONS_QUERY_KEY
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/update-subscription-plan.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { updateSubscriptionPlanAction } from '../actions/update-subscription-plan.action';\nimport { SUBSCRIPTIONS_QUERY_KEY } from '../constants/query-keys.constants';\nimport type { UpdateSubscriptionPlanRequest } from '../types/calculate-subscription.type';\n\nexport function useUpdateSubscriptionPlan() {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({\n subscriptionId,\n data,\n }: {\n subscriptionId: number | string;\n data: UpdateSubscriptionPlanRequest;\n }) => withAction(updateSubscriptionPlanAction)(subscriptionId, data),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: SUBSCRIPTIONS_QUERY_KEY });\n queryClient.invalidateQueries({ queryKey: ['charges'] });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,oCAAoC;AAC7C,SAAS,+BAA+B;AAGjC,SAAS,4BAA4B;AAC1C,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC;AAAA,MACX;AAAA,MACA;AAAA,IACF,MAGM,WAAW,4BAA4B,EAAE,gBAAgB,IAAI;AAAA,IACnE,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,wBAAwB,CAAC;AACnE,kBAAY,kBAAkB,EAAE,UAAU,CAAC,SAAS,EAAE,CAAC;AAAA,IACzD;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -10,12 +10,7 @@ const CalculateSubscriptionRequestSchema = z.object({
|
|
|
10
10
|
id_plan: z.number().optional(),
|
|
11
11
|
id_subscription: z.union([z.number(), z.string()]).optional(),
|
|
12
12
|
id_coupon: z.number().optional(),
|
|
13
|
-
plan_extras: z.array(
|
|
14
|
-
CalculateSubscriptionPlanExtraRequestSchema.partial({
|
|
15
|
-
value: true,
|
|
16
|
-
currency: true
|
|
17
|
-
})
|
|
18
|
-
).optional()
|
|
13
|
+
plan_extras: z.array(CalculateSubscriptionPlanExtraRequestSchema.partial({ value: true })).optional()
|
|
19
14
|
});
|
|
20
15
|
const CalculateSubscriptionPlanExtraResponseSchema = z.object({
|
|
21
16
|
id_addon: z.number(),
|
|
@@ -25,27 +20,6 @@ const CalculateSubscriptionPlanExtraResponseSchema = z.object({
|
|
|
25
20
|
quantity: z.number(),
|
|
26
21
|
currency: z.string()
|
|
27
22
|
});
|
|
28
|
-
const ImmediateChargeItemSchema = z.object({
|
|
29
|
-
type: z.string(),
|
|
30
|
-
description: z.string(),
|
|
31
|
-
value: z.number(),
|
|
32
|
-
id_addon: z.number().optional(),
|
|
33
|
-
quantity: z.number().optional()
|
|
34
|
-
});
|
|
35
|
-
const ImmediateChargeSchema = z.object({
|
|
36
|
-
total: z.number(),
|
|
37
|
-
items: z.array(ImmediateChargeItemSchema)
|
|
38
|
-
});
|
|
39
|
-
const CalculateSubscriptionTargetSchema = z.object({
|
|
40
|
-
id_subscription: z.string().optional(),
|
|
41
|
-
current_plan_id: z.number().optional(),
|
|
42
|
-
current_plan_name: z.string().optional(),
|
|
43
|
-
current_periodicity: z.number().optional(),
|
|
44
|
-
current_date_due: z.string().optional(),
|
|
45
|
-
days_remaining: z.number().optional(),
|
|
46
|
-
days_total: z.number().optional(),
|
|
47
|
-
immediate_charge: ImmediateChargeSchema.optional()
|
|
48
|
-
});
|
|
49
23
|
const CalculateSubscriptionResponseSchema = z.object({
|
|
50
24
|
name: z.string(),
|
|
51
25
|
month: z.number(),
|
|
@@ -67,8 +41,7 @@ const CalculateSubscriptionResponseSchema = z.object({
|
|
|
67
41
|
year_original: z.number(),
|
|
68
42
|
year_original_discount: z.number().optional().default(0),
|
|
69
43
|
year_original_discount_cupom: z.number().optional().default(0),
|
|
70
|
-
plan_extras: z.array(CalculateSubscriptionPlanExtraResponseSchema)
|
|
71
|
-
target: CalculateSubscriptionTargetSchema.optional().nullable()
|
|
44
|
+
plan_extras: z.array(CalculateSubscriptionPlanExtraResponseSchema)
|
|
72
45
|
});
|
|
73
46
|
const UpdateSubscriptionPlanExtraSchema = z.object({
|
|
74
47
|
id_addon: z.number(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/types/calculate-subscription.type.ts"],"sourcesContent":["import z from
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/types/calculate-subscription.type.ts"],"sourcesContent":["import z from 'zod';\n\nexport const CalculateSubscriptionPlanExtraRequestSchema = z.object({\n id_addon: z.number(),\n value: z.number(),\n quantity: z.number(),\n currency: z.string(),\n});\n\nexport const CalculateSubscriptionRequestSchema = z.object({\n id_product: z.number(),\n id_plan: z.number().optional(),\n id_subscription: z.union([z.number(), z.string()]).optional(),\n id_coupon: z.number().optional(),\n plan_extras: z.array(CalculateSubscriptionPlanExtraRequestSchema.partial({ value: true })).optional(),\n});\n\nexport type CalculateSubscriptionRequest = z.infer<typeof CalculateSubscriptionRequestSchema>;\n\nexport const CalculateSubscriptionPlanExtraResponseSchema = z.object({\n id_addon: z.number(),\n value: z.number(),\n value_original: z.number().optional().default(0),\n value_discount: z.number().optional().default(0),\n quantity: z.number(),\n currency: z.string(),\n});\n\nexport const CalculateSubscriptionResponseSchema = z.object({\n name: z.string(),\n month: z.number(),\n month_discount: z.number(),\n month_discount_coupom: z.number().optional().default(0),\n month_original: z.number(),\n month_original_discount: z.number().optional().default(0),\n month_original_discount_cupom: z.number().optional().default(0),\n semmester: z.number(),\n semmester_price: z.number().optional().default(0),\n semmester_discount: z.number(),\n semmester_discount_coupom: z.number().optional().default(0),\n semmester_original: z.number(),\n semmester_original_discount: z.number().optional().default(0),\n semmester_original_discount_cupom: z.number().optional().default(0),\n year: z.number(),\n year_discount: z.number(),\n year_discount_coupom: z.number().optional().default(0),\n year_original: z.number(),\n year_original_discount: z.number().optional().default(0),\n year_original_discount_cupom: z.number().optional().default(0),\n plan_extras: z.array(CalculateSubscriptionPlanExtraResponseSchema),\n});\n\nexport type CalculateSubscriptionResponse = z.infer<typeof CalculateSubscriptionResponseSchema>;\n\nexport const UpdateSubscriptionPlanExtraSchema = z.object({\n id_addon: z.number(),\n value: z.number().optional(),\n quantity: z.number(),\n price: z.string().optional(),\n trial: z.boolean().optional(),\n trial_days: z.number().optional(),\n});\n\nexport const UpdateSubscriptionPlanRequestSchema = z.object({\n id_plan: z.number().optional(),\n id_coupon: z.union([z.number(), z.null()]).optional(),\n date_due: z.string().optional(),\n type: z.string().optional(),\n active: z.boolean().optional(),\n periodicity: z.number().optional(),\n plan_extras: z.array(UpdateSubscriptionPlanExtraSchema).optional(),\n enable_charge: z.boolean().optional(),\n});\n\nexport type UpdateSubscriptionPlanRequest = z.infer<typeof UpdateSubscriptionPlanRequestSchema>;\n"],"mappings":"AAAA,OAAO,OAAO;AAEP,MAAM,8CAA8C,EAAE,OAAO;AAAA,EAClE,UAAU,EAAE,OAAO;AAAA,EACnB,OAAO,EAAE,OAAO;AAAA,EAChB,UAAU,EAAE,OAAO;AAAA,EACnB,UAAU,EAAE,OAAO;AACrB,CAAC;AAEM,MAAM,qCAAqC,EAAE,OAAO;AAAA,EACzD,YAAY,EAAE,OAAO;AAAA,EACrB,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,iBAAiB,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS;AAAA,EAC5D,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,EAC/B,aAAa,EAAE,MAAM,4CAA4C,QAAQ,EAAE,OAAO,KAAK,CAAC,CAAC,EAAE,SAAS;AACtG,CAAC;AAIM,MAAM,+CAA+C,EAAE,OAAO;AAAA,EACnE,UAAU,EAAE,OAAO;AAAA,EACnB,OAAO,EAAE,OAAO;AAAA,EAChB,gBAAgB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC/C,gBAAgB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC/C,UAAU,EAAE,OAAO;AAAA,EACnB,UAAU,EAAE,OAAO;AACrB,CAAC;AAEM,MAAM,sCAAsC,EAAE,OAAO;AAAA,EAC1D,MAAM,EAAE,OAAO;AAAA,EACf,OAAO,EAAE,OAAO;AAAA,EAChB,gBAAgB,EAAE,OAAO;AAAA,EACzB,uBAAuB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EACtD,gBAAgB,EAAE,OAAO;AAAA,EACzB,yBAAyB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EACxD,+BAA+B,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC9D,WAAW,EAAE,OAAO;AAAA,EACpB,iBAAiB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EAChD,oBAAoB,EAAE,OAAO;AAAA,EAC7B,2BAA2B,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC1D,oBAAoB,EAAE,OAAO;AAAA,EAC7B,6BAA6B,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC5D,mCAAmC,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EAClE,MAAM,EAAE,OAAO;AAAA,EACf,eAAe,EAAE,OAAO;AAAA,EACxB,sBAAsB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EACrD,eAAe,EAAE,OAAO;AAAA,EACxB,wBAAwB,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EACvD,8BAA8B,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC7D,aAAa,EAAE,MAAM,4CAA4C;AACnE,CAAC;AAIM,MAAM,oCAAoC,EAAE,OAAO;AAAA,EACxD,UAAU,EAAE,OAAO;AAAA,EACnB,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,UAAU,EAAE,OAAO;AAAA,EACnB,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,OAAO,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC5B,YAAY,EAAE,OAAO,EAAE,SAAS;AAClC,CAAC;AAEM,MAAM,sCAAsC,EAAE,OAAO;AAAA,EAC1D,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,WAAW,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,SAAS;AAAA,EACpD,UAAU,EAAE,OAAO,EAAE,SAAS;AAAA,EAC9B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,QAAQ,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC7B,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,EACjC,aAAa,EAAE,MAAM,iCAAiC,EAAE,SAAS;AAAA,EACjE,eAAe,EAAE,QAAQ,EAAE,SAAS;AACtC,CAAC;","names":[]}
|
|
@@ -36,18 +36,11 @@ function getPriceFromCalculatedData(data, periodicity) {
|
|
|
36
36
|
if (period === "semiannual") return data.semmester;
|
|
37
37
|
return data.month;
|
|
38
38
|
}
|
|
39
|
-
function getOriginalPriceFromCalculatedData(data, periodicity) {
|
|
40
|
-
const period = periodicityToBillingPeriod(periodicity);
|
|
41
|
-
if (period === "annual") return data.year_original;
|
|
42
|
-
if (period === "semiannual") return data.semmester_original;
|
|
43
|
-
return data.month_original;
|
|
44
|
-
}
|
|
45
39
|
export {
|
|
46
40
|
billingPeriodToNumeric,
|
|
47
41
|
getBillingPeriodLabel,
|
|
48
42
|
getBillingPeriodMonths,
|
|
49
43
|
getBillingPeriodSuffix,
|
|
50
|
-
getOriginalPriceFromCalculatedData,
|
|
51
44
|
getPeriodicityLabel,
|
|
52
45
|
getPriceFromCalculatedData,
|
|
53
46
|
periodicityToBillingPeriod
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/utils/periodicity.ts"],"sourcesContent":["import type { BillingPeriod } from '../types/billing-period.type';\nimport type { CalculateSubscriptionResponse } from '../types/calculate-subscription.type';\n\nexport function periodicityToBillingPeriod(\n periodicity: number | string | null | undefined\n): BillingPeriod | null {\n if (periodicity === 30 || periodicity === 1 || periodicity === 'monthly') return 'monthly';\n if (periodicity === 180 || periodicity === 3 || periodicity === 'semiannual') return 'semiannual';\n if (periodicity === 365 || periodicity === 2 || periodicity === 'annual') return 'annual';\n return null;\n}\n\nexport function billingPeriodToNumeric(billingPeriod: BillingPeriod): 30 | 180 | 365 {\n if (billingPeriod === 'semiannual') return 180;\n if (billingPeriod === 'annual') return 365;\n return 30;\n}\n\nexport function getPeriodicityLabel(periodicity: number | string | null | undefined): string {\n const period = periodicityToBillingPeriod(periodicity);\n if (period === 'semiannual') return 'Semestral';\n if (period === 'annual') return 'Anual';\n return 'Mensal';\n}\n\nexport function getBillingPeriodSuffix(billingPeriod: BillingPeriod): string {\n if (billingPeriod === 'semiannual') return '/semestre';\n if (billingPeriod === 'annual') return '/ano';\n return '/mês';\n}\n\nexport function getBillingPeriodLabel(billingPeriod: BillingPeriod): string {\n if (billingPeriod === 'semiannual') return 'semestral';\n if (billingPeriod === 'annual') return 'anual';\n return 'mensal';\n}\n\nexport function getBillingPeriodMonths(billingPeriod: BillingPeriod): number {\n if (billingPeriod === 'semiannual') return 6;\n if (billingPeriod === 'annual') return 12;\n return 1;\n}\n\nexport function getPriceFromCalculatedData(\n data: CalculateSubscriptionResponse,\n periodicity: number | string | null | undefined\n): number {\n const period = periodicityToBillingPeriod(periodicity);\n if (period === 'annual') return data.year;\n if (period === 'semiannual') return data.semmester;\n return data.month;\n}\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/utils/periodicity.ts"],"sourcesContent":["import type { BillingPeriod } from '../types/billing-period.type';\nimport type { CalculateSubscriptionResponse } from '../types/calculate-subscription.type';\n\nexport function periodicityToBillingPeriod(\n periodicity: number | string | null | undefined\n): BillingPeriod | null {\n if (periodicity === 30 || periodicity === 1 || periodicity === 'monthly') return 'monthly';\n if (periodicity === 180 || periodicity === 3 || periodicity === 'semiannual') return 'semiannual';\n if (periodicity === 365 || periodicity === 2 || periodicity === 'annual') return 'annual';\n return null;\n}\n\nexport function billingPeriodToNumeric(billingPeriod: BillingPeriod): 30 | 180 | 365 {\n if (billingPeriod === 'semiannual') return 180;\n if (billingPeriod === 'annual') return 365;\n return 30;\n}\n\nexport function getPeriodicityLabel(periodicity: number | string | null | undefined): string {\n const period = periodicityToBillingPeriod(periodicity);\n if (period === 'semiannual') return 'Semestral';\n if (period === 'annual') return 'Anual';\n return 'Mensal';\n}\n\nexport function getBillingPeriodSuffix(billingPeriod: BillingPeriod): string {\n if (billingPeriod === 'semiannual') return '/semestre';\n if (billingPeriod === 'annual') return '/ano';\n return '/mês';\n}\n\nexport function getBillingPeriodLabel(billingPeriod: BillingPeriod): string {\n if (billingPeriod === 'semiannual') return 'semestral';\n if (billingPeriod === 'annual') return 'anual';\n return 'mensal';\n}\n\nexport function getBillingPeriodMonths(billingPeriod: BillingPeriod): number {\n if (billingPeriod === 'semiannual') return 6;\n if (billingPeriod === 'annual') return 12;\n return 1;\n}\n\nexport function getPriceFromCalculatedData(\n data: CalculateSubscriptionResponse,\n periodicity: number | string | null | undefined\n): number {\n const period = periodicityToBillingPeriod(periodicity);\n if (period === 'annual') return data.year;\n if (period === 'semiannual') return data.semmester;\n return data.month;\n}\n"],"mappings":"AAGO,SAAS,2BACd,aACsB;AACtB,MAAI,gBAAgB,MAAM,gBAAgB,KAAK,gBAAgB,UAAW,QAAO;AACjF,MAAI,gBAAgB,OAAO,gBAAgB,KAAK,gBAAgB,aAAc,QAAO;AACrF,MAAI,gBAAgB,OAAO,gBAAgB,KAAK,gBAAgB,SAAU,QAAO;AACjF,SAAO;AACT;AAEO,SAAS,uBAAuB,eAA8C;AACnF,MAAI,kBAAkB,aAAc,QAAO;AAC3C,MAAI,kBAAkB,SAAU,QAAO;AACvC,SAAO;AACT;AAEO,SAAS,oBAAoB,aAAyD;AAC3F,QAAM,SAAS,2BAA2B,WAAW;AACrD,MAAI,WAAW,aAAc,QAAO;AACpC,MAAI,WAAW,SAAU,QAAO;AAChC,SAAO;AACT;AAEO,SAAS,uBAAuB,eAAsC;AAC3E,MAAI,kBAAkB,aAAc,QAAO;AAC3C,MAAI,kBAAkB,SAAU,QAAO;AACvC,SAAO;AACT;AAEO,SAAS,sBAAsB,eAAsC;AAC1E,MAAI,kBAAkB,aAAc,QAAO;AAC3C,MAAI,kBAAkB,SAAU,QAAO;AACvC,SAAO;AACT;AAEO,SAAS,uBAAuB,eAAsC;AAC3E,MAAI,kBAAkB,aAAc,QAAO;AAC3C,MAAI,kBAAkB,SAAU,QAAO;AACvC,SAAO;AACT;AAEO,SAAS,2BACd,MACA,aACQ;AACR,QAAM,SAAS,2BAA2B,WAAW;AACrD,MAAI,WAAW,SAAU,QAAO,KAAK;AACrC,MAAI,WAAW,aAAc,QAAO,KAAK;AACzC,SAAO,KAAK;AACd;","names":[]}
|
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
3
3
|
import { messagesService } from "../services/messages.service";
|
|
4
|
-
import { findWhitelabel } from "../../whitelabel/actions/find-whitelabel.action";
|
|
5
4
|
async function listMessagesAction(params) {
|
|
6
5
|
return safeServerAction(async () => {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
findWhitelabel()
|
|
10
|
-
]);
|
|
11
|
-
const urlMap = {
|
|
12
|
-
pages_url: whitelabel?.pages_url ?? "",
|
|
13
|
-
accounts_url: whitelabel?.accounts_url ?? "",
|
|
14
|
-
editor_url: whitelabel?.editor_url ?? ""
|
|
15
|
-
};
|
|
16
|
-
return { data: result.data.map((message) => ({
|
|
17
|
-
...message,
|
|
18
|
-
url: message.url.replace(/\{(pages_url|accounts_url|editor_url)\}/g, (_, key) => urlMap[key] ?? "")
|
|
19
|
-
})), total: result.total, totalUnread: result.totalUnread };
|
|
6
|
+
const result = await messagesService.listMessages(params);
|
|
7
|
+
return { data: result.data, total: result.total, totalUnread: result.totalUnread };
|
|
20
8
|
});
|
|
21
9
|
}
|
|
22
10
|
export {
|
|
@@ -1 +1 @@
|
|
|
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';\
|
|
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 async 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;AAGhC,eAAsB,mBAAmB,QAAsC;AAC7E,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":[]}
|
|
@@ -4,20 +4,17 @@ 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
6
|
import { withAction } from "../../../utils/withAction";
|
|
7
|
-
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
8
7
|
const MESSAGES_QUERY_KEY = ["messages"];
|
|
9
8
|
const INFINITE_MESSAGES_PAGE_SIZE = 10;
|
|
10
9
|
function useMessages(params) {
|
|
11
|
-
const queryKey = useAuthQueryKey([...MESSAGES_QUERY_KEY, params]);
|
|
12
10
|
return useQuery({
|
|
13
|
-
queryKey,
|
|
11
|
+
queryKey: [...MESSAGES_QUERY_KEY, params],
|
|
14
12
|
queryFn: withAction(() => listMessagesAction(params))
|
|
15
13
|
});
|
|
16
14
|
}
|
|
17
15
|
function useInfiniteMessages(params) {
|
|
18
|
-
const queryKey = useAuthQueryKey([...MESSAGES_QUERY_KEY, "infinite", params]);
|
|
19
16
|
return useInfiniteQuery({
|
|
20
|
-
queryKey,
|
|
17
|
+
queryKey: [...MESSAGES_QUERY_KEY, "infinite", params],
|
|
21
18
|
queryFn: ({ pageParam }) => withAction(
|
|
22
19
|
() => listMessagesAction({
|
|
23
20
|
...params,
|
|
@@ -34,21 +31,19 @@ function useInfiniteMessages(params) {
|
|
|
34
31
|
}
|
|
35
32
|
function useMarkMessageAsRead() {
|
|
36
33
|
const queryClient = useQueryClient();
|
|
37
|
-
const messagesKey = useAuthQueryKey([...MESSAGES_QUERY_KEY]);
|
|
38
34
|
return useMutation({
|
|
39
35
|
mutationFn: withAction(markMessageAsReadAction),
|
|
40
36
|
onSuccess: () => {
|
|
41
|
-
queryClient.invalidateQueries({ queryKey:
|
|
37
|
+
queryClient.invalidateQueries({ queryKey: MESSAGES_QUERY_KEY });
|
|
42
38
|
}
|
|
43
39
|
});
|
|
44
40
|
}
|
|
45
41
|
function useMarkAllMessagesAsRead() {
|
|
46
42
|
const queryClient = useQueryClient();
|
|
47
|
-
const messagesKey = useAuthQueryKey([...MESSAGES_QUERY_KEY]);
|
|
48
43
|
return useMutation({
|
|
49
44
|
mutationFn: withAction(markAllMessagesAsReadAction),
|
|
50
45
|
onSuccess: () => {
|
|
51
|
-
queryClient.invalidateQueries({ queryKey:
|
|
46
|
+
queryClient.invalidateQueries({ queryKey: MESSAGES_QUERY_KEY });
|
|
52
47
|
}
|
|
53
48
|
});
|
|
54
49
|
}
|
|
@@ -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 { 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';\
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/users/services/messages.service.ts"],"sourcesContent":["import 'server-only';\n\nimport { api } from '../../../infra/api/client';\nimport { buildQueryParams } from '../../../infra/utils/params';\nimport { getUserContext } from '../../auth/utils/get-user-context';\nimport {\n FindMessagesParams,\n ListMessagesApiResponse,\n MarkAsReadApiResponse,\n MarkAllAsReadApiResponse,\n} from '../schema/messages.schema';\n\nclass MessagesService {\n async listMessages(\n params?: Partial<FindMessagesParams>\n ): Promise<ListMessagesApiResponse> {\n const { id_account, id_user } = await getUserContext();\n\n const query = buildQueryParams({\n id_account,\n id_user,\n type: 'notification',\n limit: 20,\n page: 1,\n order: 'desc',\n ...params,\n });\n\n const url = `/accounts/${id_account}/messages${query ? `?${query}` : ''}`;\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/users/services/messages.service.ts"],"sourcesContent":["import 'server-only';\n\nimport { api } from '../../../infra/api/client';\nimport { buildQueryParams } from '../../../infra/utils/params';\nimport { getUserContext } from '../../auth/utils/get-user-context';\nimport {\n FindMessagesParams,\n ListMessagesApiResponse,\n MarkAsReadApiResponse,\n MarkAllAsReadApiResponse,\n} from '../schema/messages.schema';\n\nclass MessagesService {\n async listMessages(\n params?: Partial<FindMessagesParams>\n ): Promise<ListMessagesApiResponse> {\n const { id_account, id_user } = await getUserContext();\n\n const query = buildQueryParams({\n id_account,\n id_user,\n type: 'notification',\n limit: 20,\n page: 1,\n order: 'desc',\n ...params,\n });\n\n const url = `/accounts/${id_account}/messages${query ? `?${query}` : ''}`;\n return api.apps.get<ListMessagesApiResponse>(url);\n }\n\n async markAsRead(messageId: string): Promise<MarkAsReadApiResponse> {\n const { id_account } = await getUserContext();\n\n const url = `/accounts/${id_account}/messages/${messageId}/action/markAsRead`;\n return api.apps.put<MarkAsReadApiResponse>(url);\n }\n\n async markAllAsRead(): Promise<MarkAllAsReadApiResponse> {\n const { id_account, id_user } = await getUserContext();\n\n const url = `/accounts/${id_account}/messages/action/markAllAsRead`;\n return api.apps.put<MarkAllAsReadApiResponse>(url, { id_user });\n }\n}\n\nexport const messagesService = new MessagesService();\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,WAAW;AACpB,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAQ/B,MAAM,gBAAgB;AAAA,EACpB,MAAM,aACJ,QACkC;AAClC,UAAM,EAAE,YAAY,QAAQ,IAAI,MAAM,eAAe;AAErD,UAAM,QAAQ,iBAAiB;AAAA,MAC7B;AAAA,MACA;AAAA,MACA,MAAM;AAAA,MACN,OAAO;AAAA,MACP,MAAM;AAAA,MACN,OAAO;AAAA,MACP,GAAG;AAAA,IACL,CAAC;AAED,UAAM,MAAM,aAAa,UAAU,YAAY,QAAQ,IAAI,KAAK,KAAK,EAAE;AACvE,WAAO,IAAI,KAAK,IAA6B,GAAG;AAAA,EAClD;AAAA,EAEA,MAAM,WAAW,WAAmD;AAClE,UAAM,EAAE,WAAW,IAAI,MAAM,eAAe;AAE5C,UAAM,MAAM,aAAa,UAAU,aAAa,SAAS;AACzD,WAAO,IAAI,KAAK,IAA2B,GAAG;AAAA,EAChD;AAAA,EAEA,MAAM,gBAAmD;AACvD,UAAM,EAAE,YAAY,QAAQ,IAAI,MAAM,eAAe;AAErD,UAAM,MAAM,aAAa,UAAU;AACnC,WAAO,IAAI,KAAK,IAA8B,KAAK,EAAE,QAAQ,CAAC;AAAA,EAChE;AACF;AAEO,MAAM,kBAAkB,IAAI,gBAAgB;","names":[]}
|