@greatapps/common 1.1.525 → 1.1.526
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 +10 -4
- package/dist/components/account/ConfigurationsMyAccountModal.mjs.map +1 -1
- package/dist/components/account/hooks/useDisableTwoFactorAuthForm.mjs +3 -1
- package/dist/components/account/hooks/useDisableTwoFactorAuthForm.mjs.map +1 -1
- package/dist/components/account/sections/ChangeEmailModal.mjs +3 -1
- package/dist/components/account/sections/ChangeEmailModal.mjs.map +1 -1
- package/dist/components/account/sections/ChangePhoneModal.mjs +3 -1
- package/dist/components/account/sections/ChangePhoneModal.mjs.map +1 -1
- package/dist/components/account/sections/MyProfileSection.mjs +2 -1
- package/dist/components/account/sections/MyProfileSection.mjs.map +1 -1
- package/dist/components/account/sections/TokenSection.mjs +72 -0
- package/dist/components/account/sections/TokenSection.mjs.map +1 -0
- package/dist/components/embeds/ClarityEmbed.mjs +55 -0
- package/dist/components/embeds/ClarityEmbed.mjs.map +1 -0
- package/dist/components/embeds/EmbedWidgets.mjs +3 -1
- package/dist/components/embeds/EmbedWidgets.mjs.map +1 -1
- package/dist/components/layouts/AppMobileNavBar.mjs +3 -1
- package/dist/components/layouts/AppMobileNavBar.mjs.map +1 -1
- package/dist/components/layouts/AppNavBar.mjs +4 -8
- package/dist/components/layouts/AppNavBar.mjs.map +1 -1
- package/dist/components/layouts/NavBar.mjs +10 -9
- package/dist/components/layouts/NavBar.mjs.map +1 -1
- package/dist/components/layouts/NotificationsPopover.mjs +5 -2
- package/dist/components/layouts/NotificationsPopover.mjs.map +1 -1
- package/dist/components/layouts/ProfilePopover.mjs +4 -2
- package/dist/components/layouts/ProfilePopover.mjs.map +1 -1
- package/dist/components/layouts/SideBarNavigation.mjs +4 -1
- package/dist/components/layouts/SideBarNavigation.mjs.map +1 -1
- package/dist/components/modals/BuyCreditsModal.mjs +26 -9
- package/dist/components/modals/BuyCreditsModal.mjs.map +1 -1
- package/dist/components/modals/cards/AddCardModal.mjs +3 -1
- 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 +7 -6
- package/dist/components/navigation/ProjectSelectorPopover.mjs.map +1 -1
- package/dist/components/navigation/subcomponents/ProjectSelector.mjs +39 -19
- package/dist/components/navigation/subcomponents/ProjectSelector.mjs.map +1 -1
- package/dist/components/pages/NotFoundPage.mjs +2 -2
- package/dist/components/pages/NotFoundPage.mjs.map +1 -1
- package/dist/components/ui/buttons/Button.mjs +7 -2
- 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 +4 -2
- package/dist/components/ui/data-display/PaymentInfoCard.mjs.map +1 -1
- package/dist/components/ui/data-display/UserAvatar.mjs +6 -2
- package/dist/components/ui/data-display/UserAvatar.mjs.map +1 -1
- package/dist/components/ui/feedback/DefaultCircularProgress.mjs +4 -1
- package/dist/components/ui/feedback/DefaultCircularProgress.mjs.map +1 -1
- package/dist/components/ui/feedback/Toast.mjs +7 -2
- 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 +8 -6
- package/dist/components/ui/overlay/Sheet.mjs.map +1 -1
- package/dist/components/widgets/ImageUpload/ImageCropModal.mjs +11 -37
- package/dist/components/widgets/ImageUpload/ImageCropModal.mjs.map +1 -1
- package/dist/components/widgets/ImageUpload/ImageUpload.mjs +2 -1
- package/dist/components/widgets/ImageUpload/ImageUpload.mjs.map +1 -1
- package/dist/components/widgets/notifications/NotificationCard.mjs +4 -1
- package/dist/components/widgets/notifications/NotificationCard.mjs.map +1 -1
- package/dist/enums/AccountSectionType.mjs +1 -0
- package/dist/enums/AccountSectionType.mjs.map +1 -1
- package/dist/hooks/useAuthQueryKey.mjs +23 -0
- package/dist/hooks/useAuthQueryKey.mjs.map +1 -0
- package/dist/index.mjs +90 -8
- package/dist/index.mjs.map +1 -1
- package/dist/infra/utils/array.mjs +34 -0
- package/dist/infra/utils/array.mjs.map +1 -0
- package/dist/modules/accounts/actions/get-account-token.action.mjs +10 -0
- package/dist/modules/accounts/actions/get-account-token.action.mjs.map +1 -0
- package/dist/modules/accounts/hooks/current-account.hook.mjs +5 -2
- package/dist/modules/accounts/hooks/current-account.hook.mjs.map +1 -1
- package/dist/modules/accounts/hooks/use-account-token.hook.mjs +15 -0
- package/dist/modules/accounts/hooks/use-account-token.hook.mjs.map +1 -0
- package/dist/modules/accounts/hooks/useAccountManagement.mjs +19 -9
- package/dist/modules/accounts/hooks/useAccountManagement.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useCurrencies.mjs +3 -1
- package/dist/modules/accounts/hooks/useCurrencies.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useTimezones.mjs +3 -1
- package/dist/modules/accounts/hooks/useTimezones.mjs.map +1 -1
- package/dist/modules/accounts/services/account-token.service.mjs +32 -0
- package/dist/modules/accounts/services/account-token.service.mjs.map +1 -0
- package/dist/modules/auth/hooks/useUserQuery.mjs +15 -6
- package/dist/modules/auth/hooks/useUserQuery.mjs.map +1 -1
- package/dist/modules/cards/actions/delete-card.action.mjs +10 -0
- package/dist/modules/cards/actions/delete-card.action.mjs.map +1 -0
- package/dist/modules/cards/actions/find-card-by-id.action.mjs +10 -0
- package/dist/modules/cards/actions/find-card-by-id.action.mjs.map +1 -0
- package/dist/modules/cards/actions/set-default-card.action.mjs +10 -0
- package/dist/modules/cards/actions/set-default-card.action.mjs.map +1 -0
- package/dist/modules/cards/hooks/card-by-id.hook.mjs +22 -0
- package/dist/modules/cards/hooks/card-by-id.hook.mjs.map +1 -0
- package/dist/modules/cards/hooks/cards.hook.mjs +11 -3
- package/dist/modules/cards/hooks/cards.hook.mjs.map +1 -1
- package/dist/modules/cards/hooks/create-card.hook.mjs +13 -2
- package/dist/modules/cards/hooks/create-card.hook.mjs.map +1 -1
- package/dist/modules/cards/hooks/delete-card.hook.mjs +50 -0
- package/dist/modules/cards/hooks/delete-card.hook.mjs.map +1 -0
- package/dist/modules/cards/hooks/set-default-card.hook.mjs +51 -0
- package/dist/modules/cards/hooks/set-default-card.hook.mjs.map +1 -0
- package/dist/modules/cards/services/cards.service.mjs +45 -4
- package/dist/modules/cards/services/cards.service.mjs.map +1 -1
- package/dist/modules/cards/types.mjs +11 -3
- package/dist/modules/cards/types.mjs.map +1 -1
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs +3 -1
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs.map +1 -1
- package/dist/modules/plans/hooks/list-plans.hook.mjs +3 -1
- package/dist/modules/plans/hooks/list-plans.hook.mjs.map +1 -1
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs +4 -2
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs.map +1 -1
- package/dist/modules/plans/services/plans.service.mjs +4 -2
- 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 +20 -10
- package/dist/modules/plans/utils/map-api-plan-to-ui.mjs.map +1 -1
- package/dist/modules/projects/actions/create-project.action.mjs +10 -0
- package/dist/modules/projects/actions/create-project.action.mjs.map +1 -0
- package/dist/modules/projects/actions/delete-project.action.mjs +10 -0
- package/dist/modules/projects/actions/delete-project.action.mjs.map +1 -0
- package/dist/modules/projects/actions/find-project.action.mjs +10 -0
- package/dist/modules/projects/actions/find-project.action.mjs.map +1 -0
- package/dist/modules/projects/actions/list-projects.action.mjs +10 -0
- package/dist/modules/projects/actions/list-projects.action.mjs.map +1 -0
- package/dist/modules/projects/actions/update-project.action.mjs +10 -0
- package/dist/modules/projects/actions/update-project.action.mjs.map +1 -0
- package/dist/modules/projects/hooks/add-project-user.hook.mjs +15 -12
- package/dist/modules/projects/hooks/add-project-user.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/create-project.hook.mjs +71 -0
- package/dist/modules/projects/hooks/create-project.hook.mjs.map +1 -0
- package/dist/modules/projects/hooks/delete-project.hook.mjs +53 -0
- package/dist/modules/projects/hooks/delete-project.hook.mjs.map +1 -0
- package/dist/modules/projects/hooks/find-project.hook.mjs +19 -0
- package/dist/modules/projects/hooks/find-project.hook.mjs.map +1 -0
- package/dist/modules/projects/hooks/list-all-account-users.hook.mjs +3 -1
- package/dist/modules/projects/hooks/list-all-account-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-available-users.hook.mjs +3 -1
- package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs +39 -0
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs.map +1 -0
- package/dist/modules/projects/hooks/list-project-users.hook.mjs +3 -1
- package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-projects.hook.mjs +22 -0
- package/dist/modules/projects/hooks/list-projects.hook.mjs.map +1 -0
- package/dist/modules/projects/hooks/remove-project-user.hook.mjs +15 -12
- package/dist/modules/projects/hooks/remove-project-user.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/update-project.hook.mjs +70 -0
- package/dist/modules/projects/hooks/update-project.hook.mjs.map +1 -0
- package/dist/modules/projects/services/projects.service.mjs +99 -0
- package/dist/modules/projects/services/projects.service.mjs.map +1 -0
- package/dist/modules/projects/types.mjs +19 -4
- package/dist/modules/projects/types.mjs.map +1 -1
- package/dist/modules/subscriptions/constants/query-keys.constants.mjs +2 -0
- package/dist/modules/subscriptions/constants/query-keys.constants.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +5 -2
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +3 -1
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/update-subscription-plan.hook.mjs +6 -3
- package/dist/modules/subscriptions/hooks/update-subscription-plan.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/types/calculate-subscription.type.mjs +29 -2
- package/dist/modules/subscriptions/types/calculate-subscription.type.mjs.map +1 -1
- package/dist/modules/subscriptions/utils/periodicity.mjs +7 -0
- package/dist/modules/subscriptions/utils/periodicity.mjs.map +1 -1
- package/dist/modules/users/action/list-messages.action.mjs +14 -2
- package/dist/modules/users/action/list-messages.action.mjs.map +1 -1
- package/dist/modules/users/hooks/messages.hook.mjs +9 -4
- 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 +6 -4
- 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 +5 -0
- package/dist/providers/whitelabel.provider.mjs.map +1 -1
- package/dist/server.mjs +14 -0
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/components/navigation/types.mjs +0 -1
- package/dist/components/navigation/types.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/accounts/actions/get-account-token.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { accountTokenService } from '../services/account-token.service';\n\nexport async function getAccountTokenAction() {\n return safeServerAction(() => accountTokenService.getOrCreateToken());\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AAEpC,eAAsB,wBAAwB;AAC5C,SAAO,iBAAiB,MAAM,oBAAoB,iBAAiB,CAAC;AACtE;","names":[]}
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
3
|
import { findCurrentAccount } from "../actions/find-current-account.action";
|
|
4
4
|
import { withAction } from "../../../utils/withAction";
|
|
5
|
+
import { useWlQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
5
6
|
const ACCOUNT_QUERY_KEY = ["account"];
|
|
6
7
|
function useCurrentAccount() {
|
|
8
|
+
const queryKey = useWlQueryKey([...ACCOUNT_QUERY_KEY]);
|
|
7
9
|
return useQuery({
|
|
8
|
-
queryKey
|
|
10
|
+
queryKey,
|
|
9
11
|
queryFn: withAction(findCurrentAccount),
|
|
10
12
|
staleTime: 0,
|
|
11
13
|
gcTime: 10 * 60 * 1e3,
|
|
@@ -14,7 +16,8 @@ function useCurrentAccount() {
|
|
|
14
16
|
}
|
|
15
17
|
function useInvalidateAccount() {
|
|
16
18
|
const queryClient = useQueryClient();
|
|
17
|
-
|
|
19
|
+
const accountKey = useWlQueryKey([...ACCOUNT_QUERY_KEY]);
|
|
20
|
+
return () => queryClient.invalidateQueries({ queryKey: accountKey });
|
|
18
21
|
}
|
|
19
22
|
export {
|
|
20
23
|
ACCOUNT_QUERY_KEY,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/accounts/hooks/current-account.hook.tsx"],"sourcesContent":["'use client';\n\nimport { useQuery, useQueryClient } from '@tanstack/react-query';\nimport { findCurrentAccount } from '../actions/find-current-account.action';\nimport { withAction } from '../../../utils/withAction';\n\nexport const ACCOUNT_QUERY_KEY = ['account'];\n\nexport function useCurrentAccount() {\n return useQuery({\n queryKey
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/accounts/hooks/current-account.hook.tsx"],"sourcesContent":["'use client';\n\nimport { useQuery, useQueryClient } from '@tanstack/react-query';\nimport { findCurrentAccount } from '../actions/find-current-account.action';\nimport { withAction } from '../../../utils/withAction';\nimport { useWlQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const ACCOUNT_QUERY_KEY = ['account'] as const;\n\nexport function useCurrentAccount() {\n const queryKey = useWlQueryKey([...ACCOUNT_QUERY_KEY]);\n\n return useQuery({\n queryKey,\n queryFn: withAction(findCurrentAccount),\n staleTime: 0,\n gcTime: 10 * 60 * 1000,\n retry: false,\n });\n}\n\nexport function useInvalidateAccount() {\n const queryClient = useQueryClient();\n const accountKey = useWlQueryKey([...ACCOUNT_QUERY_KEY]);\n return () => queryClient.invalidateQueries({ queryKey: accountKey });\n}\n"],"mappings":";AAEA,SAAS,UAAU,sBAAsB;AACzC,SAAS,0BAA0B;AACnC,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAEvB,MAAM,oBAAoB,CAAC,SAAS;AAEpC,SAAS,oBAAoB;AAClC,QAAM,WAAW,cAAc,CAAC,GAAG,iBAAiB,CAAC;AAErD,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,WAAW,kBAAkB;AAAA,IACtC,WAAW;AAAA,IACX,QAAQ,KAAK,KAAK;AAAA,IAClB,OAAO;AAAA,EACT,CAAC;AACH;AAEO,SAAS,uBAAuB;AACrC,QAAM,cAAc,eAAe;AACnC,QAAM,aAAa,cAAc,CAAC,GAAG,iBAAiB,CAAC;AACvD,SAAO,MAAM,YAAY,kBAAkB,EAAE,UAAU,WAAW,CAAC;AACrE;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { withAction } from "../../../utils/withAction";
|
|
4
|
+
import { getAccountTokenAction } from "../actions/get-account-token.action";
|
|
5
|
+
const ACCOUNT_TOKEN_QUERY_KEY = ["account-token"];
|
|
6
|
+
function useAccountToken() {
|
|
7
|
+
return useQuery({
|
|
8
|
+
queryKey: ACCOUNT_TOKEN_QUERY_KEY,
|
|
9
|
+
queryFn: withAction(getAccountTokenAction)
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
useAccountToken
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=use-account-token.hook.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/accounts/hooks/use-account-token.hook.tsx"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { getAccountTokenAction } from '../actions/get-account-token.action';\n\nconst ACCOUNT_TOKEN_QUERY_KEY = ['account-token'];\n\nexport function useAccountToken() {\n return useQuery({\n queryKey: ACCOUNT_TOKEN_QUERY_KEY,\n queryFn: withAction(getAccountTokenAction),\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,MAAM,0BAA0B,CAAC,eAAe;AAEzC,SAAS,kBAAkB;AAChC,SAAO,SAAS;AAAA,IACd,UAAU;AAAA,IACV,SAAS,WAAW,qBAAqB;AAAA,EAC3C,CAAC;AACH;","names":[]}
|
|
@@ -10,48 +10,57 @@ import {
|
|
|
10
10
|
deleteAccountAction
|
|
11
11
|
} from "../actions/account-management.action";
|
|
12
12
|
import { withAction } from "../../../utils/withAction";
|
|
13
|
+
import { useAuthQueryKey, useWlQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
13
14
|
const ACCOUNT_USERS_QUERY_KEY = ["account-users"];
|
|
14
15
|
function useUpdateAccount() {
|
|
15
16
|
const queryClient = useQueryClient();
|
|
17
|
+
const accountUsersKey = useAuthQueryKey([...ACCOUNT_USERS_QUERY_KEY]);
|
|
18
|
+
const accountKey = useWlQueryKey([...ACCOUNT_QUERY_KEY]);
|
|
19
|
+
const userKey = useWlQueryKey([...USER_QUERY_KEY]);
|
|
16
20
|
return useMutation({
|
|
17
21
|
mutationFn: withAction(updateAccountAction),
|
|
18
22
|
onSuccess: () => {
|
|
19
|
-
queryClient.invalidateQueries({ queryKey:
|
|
20
|
-
queryClient.invalidateQueries({ queryKey:
|
|
21
|
-
queryClient.invalidateQueries({ queryKey:
|
|
23
|
+
queryClient.invalidateQueries({ queryKey: accountUsersKey });
|
|
24
|
+
queryClient.invalidateQueries({ queryKey: accountKey });
|
|
25
|
+
queryClient.invalidateQueries({ queryKey: userKey });
|
|
22
26
|
}
|
|
23
27
|
});
|
|
24
28
|
}
|
|
25
29
|
function useUpdateAccountUser() {
|
|
26
30
|
const queryClient = useQueryClient();
|
|
31
|
+
const accountUsersKey = useAuthQueryKey([...ACCOUNT_USERS_QUERY_KEY]);
|
|
32
|
+
const accountKey = useWlQueryKey([...ACCOUNT_QUERY_KEY]);
|
|
33
|
+
const userKey = useWlQueryKey([...USER_QUERY_KEY]);
|
|
27
34
|
return useMutation({
|
|
28
35
|
mutationFn: withAction(updateUserAction),
|
|
29
36
|
onSuccess: () => {
|
|
30
|
-
queryClient.invalidateQueries({ queryKey:
|
|
31
|
-
queryClient.invalidateQueries({ queryKey:
|
|
32
|
-
queryClient.invalidateQueries({ queryKey:
|
|
37
|
+
queryClient.invalidateQueries({ queryKey: accountUsersKey });
|
|
38
|
+
queryClient.invalidateQueries({ queryKey: accountKey });
|
|
39
|
+
queryClient.invalidateQueries({ queryKey: userKey });
|
|
33
40
|
}
|
|
34
41
|
});
|
|
35
42
|
}
|
|
36
43
|
function useUpdateAccountUserById() {
|
|
37
44
|
const queryClient = useQueryClient();
|
|
45
|
+
const accountUsersKey = useAuthQueryKey([...ACCOUNT_USERS_QUERY_KEY]);
|
|
38
46
|
return useMutation({
|
|
39
47
|
mutationFn: withAction(
|
|
40
|
-
({ userId, ...user }) => updateAccountUserByIdAction(
|
|
48
|
+
({ userId: targetUserId, ...user }) => updateAccountUserByIdAction(targetUserId, user)
|
|
41
49
|
),
|
|
42
50
|
onSuccess: () => {
|
|
43
|
-
queryClient.invalidateQueries({ queryKey:
|
|
51
|
+
queryClient.invalidateQueries({ queryKey: accountUsersKey });
|
|
44
52
|
}
|
|
45
53
|
});
|
|
46
54
|
}
|
|
47
55
|
function useDeleteAccountUser(options) {
|
|
48
56
|
const queryClient = useQueryClient();
|
|
57
|
+
const accountUsersKey = useAuthQueryKey([...ACCOUNT_USERS_QUERY_KEY]);
|
|
49
58
|
return useMutation({
|
|
50
59
|
mutationFn: withAction(deleteAccountUserAction),
|
|
51
60
|
...options,
|
|
52
61
|
onSuccess: (...params) => {
|
|
53
62
|
options?.onSuccess?.(...params);
|
|
54
|
-
queryClient.invalidateQueries({ queryKey:
|
|
63
|
+
queryClient.invalidateQueries({ queryKey: accountUsersKey });
|
|
55
64
|
}
|
|
56
65
|
});
|
|
57
66
|
}
|
|
@@ -62,6 +71,7 @@ function useDeleteAccount(options) {
|
|
|
62
71
|
});
|
|
63
72
|
}
|
|
64
73
|
export {
|
|
74
|
+
ACCOUNT_USERS_QUERY_KEY,
|
|
65
75
|
useDeleteAccount,
|
|
66
76
|
useDeleteAccountUser,
|
|
67
77
|
useUpdateAccount,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/accounts/hooks/useAccountManagement.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { USER_QUERY_KEY } from '../../auth/hooks/useUserQuery';\nimport { ACCOUNT_QUERY_KEY } from './current-account.hook';\nimport type {\n UpdateAccountRequest,\n UpdateAccountUserRequest,\n DeleteAccountUserResponse,\n DeleteAccountResponse,\n} from '../types';\nimport {\n updateUserAction,\n updateAccountAction,\n updateAccountUserByIdAction,\n deleteAccountUserAction,\n deleteAccountAction,\n} from '../actions/account-management.action';\nimport { withAction } from '../../../utils/withAction';\nimport type { UseMutationOptions } from '@tanstack/react-query';\n\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/accounts/hooks/useAccountManagement.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { USER_QUERY_KEY } from '../../auth/hooks/useUserQuery';\nimport { ACCOUNT_QUERY_KEY } from './current-account.hook';\nimport type {\n UpdateAccountRequest,\n UpdateAccountUserRequest,\n DeleteAccountUserResponse,\n DeleteAccountResponse,\n} from '../types';\nimport {\n updateUserAction,\n updateAccountAction,\n updateAccountUserByIdAction,\n deleteAccountUserAction,\n deleteAccountAction,\n} from '../actions/account-management.action';\nimport { withAction } from '../../../utils/withAction';\nimport type { UseMutationOptions } from '@tanstack/react-query';\nimport { useAuthQueryKey, useWlQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const ACCOUNT_USERS_QUERY_KEY = ['account-users'] as const;\n\nexport function useUpdateAccount() {\n const queryClient = useQueryClient();\n const accountUsersKey = useAuthQueryKey([...ACCOUNT_USERS_QUERY_KEY]);\n const accountKey = useWlQueryKey([...ACCOUNT_QUERY_KEY]);\n const userKey = useWlQueryKey([...USER_QUERY_KEY]);\n\n return useMutation({\n mutationFn: withAction(updateAccountAction),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: accountUsersKey });\n queryClient.invalidateQueries({ queryKey: accountKey });\n queryClient.invalidateQueries({ queryKey: userKey });\n },\n });\n}\n\nexport function useUpdateAccountUser() {\n const queryClient = useQueryClient();\n const accountUsersKey = useAuthQueryKey([...ACCOUNT_USERS_QUERY_KEY]);\n const accountKey = useWlQueryKey([...ACCOUNT_QUERY_KEY]);\n const userKey = useWlQueryKey([...USER_QUERY_KEY]);\n\n return useMutation({\n mutationFn: withAction(updateUserAction),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: accountUsersKey });\n queryClient.invalidateQueries({ queryKey: accountKey });\n queryClient.invalidateQueries({ queryKey: userKey });\n },\n });\n}\n\nexport function useUpdateAccountUserById() {\n const queryClient = useQueryClient();\n const accountUsersKey = useAuthQueryKey([...ACCOUNT_USERS_QUERY_KEY]);\n\n return useMutation({\n mutationFn: withAction(({ userId: targetUserId, ...user }: UpdateAccountUserRequest & { userId: number }) =>\n updateAccountUserByIdAction(targetUserId, user)\n ),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: accountUsersKey });\n },\n });\n}\n\nexport function useDeleteAccountUser(\n options?: UseMutationOptions<DeleteAccountUserResponse, Error, number>\n) {\n const queryClient = useQueryClient();\n const accountUsersKey = useAuthQueryKey([...ACCOUNT_USERS_QUERY_KEY]);\n\n return useMutation({\n mutationFn: withAction(deleteAccountUserAction),\n ...options,\n onSuccess: (...params) => {\n options?.onSuccess?.(...params);\n queryClient.invalidateQueries({ queryKey: accountUsersKey });\n },\n });\n}\n\nexport function useDeleteAccount(\n options?: UseMutationOptions<DeleteAccountResponse, Error, void>\n) {\n return useMutation({\n mutationFn: withAction(deleteAccountAction),\n ...options,\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAsB;AAC5C,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAOlC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB;AAE3B,SAAS,iBAAiB,qBAAqB;AAExC,MAAM,0BAA0B,CAAC,eAAe;AAEhD,SAAS,mBAAmB;AACjC,QAAM,cAAc,eAAe;AACnC,QAAM,kBAAkB,gBAAgB,CAAC,GAAG,uBAAuB,CAAC;AACpE,QAAM,aAAa,cAAc,CAAC,GAAG,iBAAiB,CAAC;AACvD,QAAM,UAAU,cAAc,CAAC,GAAG,cAAc,CAAC;AAEjD,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,mBAAmB;AAAA,IAC1C,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,gBAAgB,CAAC;AAC3D,kBAAY,kBAAkB,EAAE,UAAU,WAAW,CAAC;AACtD,kBAAY,kBAAkB,EAAE,UAAU,QAAQ,CAAC;AAAA,IACrD;AAAA,EACF,CAAC;AACH;AAEO,SAAS,uBAAuB;AACrC,QAAM,cAAc,eAAe;AACnC,QAAM,kBAAkB,gBAAgB,CAAC,GAAG,uBAAuB,CAAC;AACpE,QAAM,aAAa,cAAc,CAAC,GAAG,iBAAiB,CAAC;AACvD,QAAM,UAAU,cAAc,CAAC,GAAG,cAAc,CAAC;AAEjD,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,gBAAgB;AAAA,IACvC,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,gBAAgB,CAAC;AAC3D,kBAAY,kBAAkB,EAAE,UAAU,WAAW,CAAC;AACtD,kBAAY,kBAAkB,EAAE,UAAU,QAAQ,CAAC;AAAA,IACrD;AAAA,EACF,CAAC;AACH;AAEO,SAAS,2BAA2B;AACzC,QAAM,cAAc,eAAe;AACnC,QAAM,kBAAkB,gBAAgB,CAAC,GAAG,uBAAuB,CAAC;AAEpE,SAAO,YAAY;AAAA,IACjB,YAAY;AAAA,MAAW,CAAC,EAAE,QAAQ,cAAc,GAAG,KAAK,MACtD,4BAA4B,cAAc,IAAI;AAAA,IAChD;AAAA,IACA,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,gBAAgB,CAAC;AAAA,IAC7D;AAAA,EACF,CAAC;AACH;AAEO,SAAS,qBACd,SACA;AACA,QAAM,cAAc,eAAe;AACnC,QAAM,kBAAkB,gBAAgB,CAAC,GAAG,uBAAuB,CAAC;AAEpE,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,uBAAuB;AAAA,IAC9C,GAAG;AAAA,IACH,WAAW,IAAI,WAAW;AACxB,eAAS,YAAY,GAAG,MAAM;AAC9B,kBAAY,kBAAkB,EAAE,UAAU,gBAAgB,CAAC;AAAA,IAC7D;AAAA,EACF,CAAC;AACH;AAEO,SAAS,iBACd,SACA;AACA,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,mBAAmB;AAAA,IAC1C,GAAG;AAAA,EACL,CAAC;AACH;","names":[]}
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
import { useQuery } from "@tanstack/react-query";
|
|
3
3
|
import { listCurrenciesAction } from "../actions/list-currencies.action";
|
|
4
4
|
import { withAction } from "../../../utils/withAction";
|
|
5
|
+
import { useWlQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
5
6
|
const CURRENCIES_QUERY_KEY = ["currencies"];
|
|
6
7
|
function useCurrencies() {
|
|
8
|
+
const queryKey = useWlQueryKey([...CURRENCIES_QUERY_KEY]);
|
|
7
9
|
return useQuery({
|
|
8
|
-
queryKey
|
|
10
|
+
queryKey,
|
|
9
11
|
queryFn: withAction(listCurrenciesAction),
|
|
10
12
|
staleTime: Infinity
|
|
11
13
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/accounts/hooks/useCurrencies.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { listCurrenciesAction } from '../actions/list-currencies.action';\nimport { withAction } from '../../../utils/withAction';\n\nexport const CURRENCIES_QUERY_KEY = ['currencies'];\n\nexport function useCurrencies() {\n return useQuery({\n queryKey
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/accounts/hooks/useCurrencies.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { listCurrenciesAction } from '../actions/list-currencies.action';\nimport { withAction } from '../../../utils/withAction';\nimport { useWlQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const CURRENCIES_QUERY_KEY = ['currencies'] as const;\n\nexport function useCurrencies() {\n const queryKey = useWlQueryKey([...CURRENCIES_QUERY_KEY]);\n\n return useQuery({\n queryKey,\n queryFn: withAction(listCurrenciesAction),\n staleTime: Infinity,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,4BAA4B;AACrC,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAEvB,MAAM,uBAAuB,CAAC,YAAY;AAE1C,SAAS,gBAAgB;AAC9B,QAAM,WAAW,cAAc,CAAC,GAAG,oBAAoB,CAAC;AAExD,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,WAAW,oBAAoB;AAAA,IACxC,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
import { useQuery } from "@tanstack/react-query";
|
|
3
3
|
import { listTimezonesAction } from "../actions/list-timezones.action";
|
|
4
4
|
import { withAction } from "../../../utils/withAction";
|
|
5
|
+
import { useWlQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
5
6
|
const TIMEZONES_QUERY_KEY = ["timezones"];
|
|
6
7
|
function useTimezones() {
|
|
8
|
+
const queryKey = useWlQueryKey([...TIMEZONES_QUERY_KEY]);
|
|
7
9
|
return useQuery({
|
|
8
|
-
queryKey
|
|
10
|
+
queryKey,
|
|
9
11
|
queryFn: withAction(listTimezonesAction),
|
|
10
12
|
staleTime: Infinity
|
|
11
13
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/accounts/hooks/useTimezones.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { listTimezonesAction } from '../actions/list-timezones.action';\nimport { withAction } from '../../../utils/withAction';\n\nexport const TIMEZONES_QUERY_KEY = ['timezones'];\n\nexport function useTimezones() {\n return useQuery({\n queryKey
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/accounts/hooks/useTimezones.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { listTimezonesAction } from '../actions/list-timezones.action';\nimport { withAction } from '../../../utils/withAction';\nimport { useWlQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const TIMEZONES_QUERY_KEY = ['timezones'] as const;\n\nexport function useTimezones() {\n const queryKey = useWlQueryKey([...TIMEZONES_QUERY_KEY]);\n\n return useQuery({\n queryKey,\n queryFn: withAction(listTimezonesAction),\n staleTime: Infinity,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AACpC,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAEvB,MAAM,sBAAsB,CAAC,WAAW;AAExC,SAAS,eAAe;AAC7B,QAAM,WAAW,cAAc,CAAC,GAAG,mBAAmB,CAAC;AAEvD,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,WAAW,mBAAmB;AAAA,IACvC,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { api } from "../../../infra/api/client";
|
|
3
|
+
import { ApiError } from "../../../infra/api/types";
|
|
4
|
+
import { getUserContext } from "../../auth/utils/get-user-context";
|
|
5
|
+
class AccountTokenService {
|
|
6
|
+
async getOrCreateToken() {
|
|
7
|
+
const { id_account } = await getUserContext();
|
|
8
|
+
const listResponse = await api.apps.get(
|
|
9
|
+
`/accounts/${id_account}/tokens?active=true&id_product=1&limit=1`
|
|
10
|
+
);
|
|
11
|
+
if (listResponse.status === 1 && listResponse.data?.length) {
|
|
12
|
+
return listResponse.data[0].token;
|
|
13
|
+
}
|
|
14
|
+
const createResponse = await api.apps.post(
|
|
15
|
+
`/accounts/${id_account}/tokens`,
|
|
16
|
+
{ name: "GreatPages", active: true, id_product: 1 }
|
|
17
|
+
);
|
|
18
|
+
if (createResponse.status === 0 || !createResponse.data?.length) {
|
|
19
|
+
throw new ApiError(
|
|
20
|
+
createResponse.message || "Erro ao criar token da conta",
|
|
21
|
+
"CREATE_TOKEN_FAILED",
|
|
22
|
+
400
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return createResponse.data[0].token;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const accountTokenService = new AccountTokenService();
|
|
29
|
+
export {
|
|
30
|
+
accountTokenService
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=account-token.service.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/accounts/services/account-token.service.ts"],"sourcesContent":["import 'server-only';\n\nimport { api } from '../../../infra/api/client';\nimport { ApiError } from '../../../infra/api/types';\nimport { getUserContext } from '../../auth/utils/get-user-context';\n\ninterface AccountToken {\n token: string;\n}\n\ninterface ListTokensResponse {\n status: 0 | 1;\n message?: string;\n data?: AccountToken[];\n}\n\ninterface CreateTokenResponse {\n status: 0 | 1;\n message?: string;\n data?: AccountToken[];\n}\n\nclass AccountTokenService {\n async getOrCreateToken(): Promise<string> {\n const { id_account } = await getUserContext();\n\n const listResponse = await api.apps.get<ListTokensResponse>(\n `/accounts/${id_account}/tokens?active=true&id_product=1&limit=1`\n );\n\n if (listResponse.status === 1 && listResponse.data?.length) {\n return listResponse.data[0].token;\n }\n\n const createResponse = await api.apps.post<CreateTokenResponse>(\n `/accounts/${id_account}/tokens`,\n { name: 'GreatPages', active: true, id_product: 1 }\n );\n\n if (createResponse.status === 0 || !createResponse.data?.length) {\n throw new ApiError(\n createResponse.message || 'Erro ao criar token da conta',\n 'CREATE_TOKEN_FAILED',\n 400\n );\n }\n\n return createResponse.data[0].token;\n }\n}\n\nexport const accountTokenService = new AccountTokenService();\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,WAAW;AACpB,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAkB/B,MAAM,oBAAoB;AAAA,EACxB,MAAM,mBAAoC;AACxC,UAAM,EAAE,WAAW,IAAI,MAAM,eAAe;AAE5C,UAAM,eAAe,MAAM,IAAI,KAAK;AAAA,MAClC,aAAa,UAAU;AAAA,IACzB;AAEA,QAAI,aAAa,WAAW,KAAK,aAAa,MAAM,QAAQ;AAC1D,aAAO,aAAa,KAAK,CAAC,EAAE;AAAA,IAC9B;AAEA,UAAM,iBAAiB,MAAM,IAAI,KAAK;AAAA,MACpC,aAAa,UAAU;AAAA,MACvB,EAAE,MAAM,cAAc,QAAQ,MAAM,YAAY,EAAE;AAAA,IACpD;AAEA,QAAI,eAAe,WAAW,KAAK,CAAC,eAAe,MAAM,QAAQ;AAC/D,YAAM,IAAI;AAAA,QACR,eAAe,WAAW;AAAA,QAC1B;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,eAAe,KAAK,CAAC,EAAE;AAAA,EAChC;AACF;AAEO,MAAM,sBAAsB,IAAI,oBAAoB;","names":[]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
3
|
import { withAction } from "../../../utils/withAction";
|
|
4
|
+
import { useWlQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
4
5
|
const USER_QUERY_KEY = ["user"];
|
|
6
|
+
const USER_VALIDATE_SESSION_KEY = ["user-validate-session"];
|
|
5
7
|
async function fetchUser() {
|
|
6
8
|
const { findUserById: getUserDataAction } = await import("../../users/action/find-user-by-id.action");
|
|
7
9
|
const result = await getUserDataAction();
|
|
@@ -12,8 +14,9 @@ async function validateUserSession() {
|
|
|
12
14
|
return await validateSessionAction();
|
|
13
15
|
}
|
|
14
16
|
function useUserQuery() {
|
|
17
|
+
const queryKey = useWlQueryKey([...USER_QUERY_KEY]);
|
|
15
18
|
return useQuery({
|
|
16
|
-
queryKey
|
|
19
|
+
queryKey,
|
|
17
20
|
queryFn: fetchUser,
|
|
18
21
|
staleTime: 5 * 60 * 1e3,
|
|
19
22
|
gcTime: 10 * 60 * 1e3,
|
|
@@ -21,8 +24,9 @@ function useUserQuery() {
|
|
|
21
24
|
});
|
|
22
25
|
}
|
|
23
26
|
function useUserValidateSession(options) {
|
|
27
|
+
const queryKey = useWlQueryKey([...USER_VALIDATE_SESSION_KEY]);
|
|
24
28
|
return useQuery({
|
|
25
|
-
queryKey
|
|
29
|
+
queryKey,
|
|
26
30
|
queryFn: validateUserSession,
|
|
27
31
|
retry: false,
|
|
28
32
|
staleTime: 5 * 60 * 1e3,
|
|
@@ -33,27 +37,32 @@ function useUserValidateSession(options) {
|
|
|
33
37
|
}
|
|
34
38
|
function useTwoFactorVerify() {
|
|
35
39
|
const queryClient = useQueryClient();
|
|
40
|
+
const userKey = useWlQueryKey([...USER_QUERY_KEY]);
|
|
41
|
+
const twoFactorKey = useWlQueryKey(["two-factor-pending"]);
|
|
36
42
|
return useMutation({
|
|
37
43
|
mutationFn: async ({ cookie, code, window }) => {
|
|
38
44
|
const { verifyTwoFactorAction } = await import("../actions/verify-two-factor.action");
|
|
39
45
|
return withAction(() => verifyTwoFactorAction(cookie, code, window))();
|
|
40
46
|
},
|
|
41
47
|
onSuccess: () => {
|
|
42
|
-
queryClient.invalidateQueries({ queryKey:
|
|
43
|
-
queryClient.invalidateQueries({ queryKey:
|
|
48
|
+
queryClient.invalidateQueries({ queryKey: userKey });
|
|
49
|
+
queryClient.invalidateQueries({ queryKey: twoFactorKey });
|
|
44
50
|
}
|
|
45
51
|
});
|
|
46
52
|
}
|
|
47
53
|
function useInvalidateUser() {
|
|
48
54
|
const queryClient = useQueryClient();
|
|
49
|
-
|
|
55
|
+
const userKey = useWlQueryKey([...USER_QUERY_KEY]);
|
|
56
|
+
return () => queryClient.invalidateQueries({ queryKey: userKey });
|
|
50
57
|
}
|
|
51
58
|
function useSetUserData() {
|
|
52
59
|
const queryClient = useQueryClient();
|
|
53
|
-
|
|
60
|
+
const userKey = useWlQueryKey([...USER_QUERY_KEY]);
|
|
61
|
+
return (user) => queryClient.setQueryData(userKey, user);
|
|
54
62
|
}
|
|
55
63
|
export {
|
|
56
64
|
USER_QUERY_KEY,
|
|
65
|
+
USER_VALIDATE_SESSION_KEY,
|
|
57
66
|
useInvalidateUser,
|
|
58
67
|
useSetUserData,
|
|
59
68
|
useTwoFactorVerify,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/hooks/useUserQuery.ts"],"sourcesContent":["'use client';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/auth/hooks/useUserQuery.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query';\nimport { User } from '../../users/schema';\nimport { withAction } from '../../../utils/withAction';\nimport { useWlQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const USER_QUERY_KEY = ['user'] as const;\nexport const USER_VALIDATE_SESSION_KEY = ['user-validate-session'] as const;\n\nasync function fetchUser(): Promise<User | null> {\n const { findUserById: getUserDataAction } = await import('../../users/action/find-user-by-id.action');\n const result = await getUserDataAction();\n return result.success && result.data ? result.data : null;\n}\n\nasync function validateUserSession(): Promise<boolean> {\n const { validateSessionAction } = await import('../actions/validate-session.action');\n return await validateSessionAction();\n}\n\nexport function useUserQuery() {\n const queryKey = useWlQueryKey([...USER_QUERY_KEY]);\n\n return useQuery({\n queryKey,\n queryFn: fetchUser,\n staleTime: 5 * 60 * 1000,\n gcTime: 10 * 60 * 1000,\n retry: false,\n });\n}\n\nexport function useUserValidateSession(options?: UseQueryOptions) {\n const queryKey = useWlQueryKey([...USER_VALIDATE_SESSION_KEY]);\n\n return useQuery({\n queryKey,\n queryFn: validateUserSession,\n retry: false,\n staleTime: 5 * 60 * 1000,\n ...options,\n refetchOnMount: 'always',\n refetchOnWindowFocus: true,\n });\n}\n\nexport function useTwoFactorVerify() {\n const queryClient = useQueryClient();\n const userKey = useWlQueryKey([...USER_QUERY_KEY]);\n const twoFactorKey = useWlQueryKey(['two-factor-pending']);\n\n return useMutation({\n mutationFn: async ({ cookie, code, window }: { cookie: string; code: string; window?: number }) => {\n const { verifyTwoFactorAction } = await import('../actions/verify-two-factor.action');\n return withAction(() => verifyTwoFactorAction(cookie, code, window))();\n },\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: userKey });\n queryClient.invalidateQueries({ queryKey: twoFactorKey });\n },\n });\n}\n\nexport function useInvalidateUser() {\n const queryClient = useQueryClient();\n const userKey = useWlQueryKey([...USER_QUERY_KEY]);\n return () => queryClient.invalidateQueries({ queryKey: userKey });\n}\n\nexport function useSetUserData() {\n const queryClient = useQueryClient();\n const userKey = useWlQueryKey([...USER_QUERY_KEY]);\n return (user: User | null) => queryClient.setQueryData(userKey, user);\n}\n"],"mappings":";AAEA,SAAS,aAAa,UAAU,sBAAuC;AAEvE,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAEvB,MAAM,iBAAiB,CAAC,MAAM;AAC9B,MAAM,4BAA4B,CAAC,uBAAuB;AAEjE,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,QAAM,WAAW,cAAc,CAAC,GAAG,cAAc,CAAC;AAElD,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS;AAAA,IACT,WAAW,IAAI,KAAK;AAAA,IACpB,QAAQ,KAAK,KAAK;AAAA,IAClB,OAAO;AAAA,EACT,CAAC;AACH;AAEO,SAAS,uBAAuB,SAA2B;AAChE,QAAM,WAAW,cAAc,CAAC,GAAG,yBAAyB,CAAC;AAE7D,SAAO,SAAS;AAAA,IACd;AAAA,IACA,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;AACnC,QAAM,UAAU,cAAc,CAAC,GAAG,cAAc,CAAC;AACjD,QAAM,eAAe,cAAc,CAAC,oBAAoB,CAAC;AAEzD,SAAO,YAAY;AAAA,IACjB,YAAY,OAAO,EAAE,QAAQ,MAAM,OAAO,MAAyD;AACjG,YAAM,EAAE,sBAAsB,IAAI,MAAM,OAAO,qCAAqC;AACpF,aAAO,WAAW,MAAM,sBAAsB,QAAQ,MAAM,MAAM,CAAC,EAAE;AAAA,IACvE;AAAA,IACA,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,QAAQ,CAAC;AACnD,kBAAY,kBAAkB,EAAE,UAAU,aAAa,CAAC;AAAA,IAC1D;AAAA,EACF,CAAC;AACH;AAEO,SAAS,oBAAoB;AAClC,QAAM,cAAc,eAAe;AACnC,QAAM,UAAU,cAAc,CAAC,GAAG,cAAc,CAAC;AACjD,SAAO,MAAM,YAAY,kBAAkB,EAAE,UAAU,QAAQ,CAAC;AAClE;AAEO,SAAS,iBAAiB;AAC/B,QAAM,cAAc,eAAe;AACnC,QAAM,UAAU,cAAc,CAAC,GAAG,cAAc,CAAC;AACjD,SAAO,CAAC,SAAsB,YAAY,aAAa,SAAS,IAAI;AACtE;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
3
|
+
import { cardsService } from "../services/cards.service";
|
|
4
|
+
async function deleteCardAction(id) {
|
|
5
|
+
return safeServerAction(() => cardsService.deleteCard(id));
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
deleteCardAction
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=delete-card.action.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/cards/actions/delete-card.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { cardsService } from '../services/cards.service';\n\nexport async function deleteCardAction(id: string) {\n return safeServerAction(() => cardsService.deleteCard(id));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAE7B,eAAsB,iBAAiB,IAAY;AACjD,SAAO,iBAAiB,MAAM,aAAa,WAAW,EAAE,CAAC;AAC3D;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
3
|
+
import { cardsService } from "../services/cards.service";
|
|
4
|
+
async function findCardByIdAction(id) {
|
|
5
|
+
return safeServerAction(() => cardsService.findCardById(id));
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
findCardByIdAction
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=find-card-by-id.action.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/cards/actions/find-card-by-id.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { cardsService } from '../services/cards.service';\n\nexport async function findCardByIdAction(id: number) {\n return safeServerAction(() => cardsService.findCardById(id));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAE7B,eAAsB,mBAAmB,IAAY;AACnD,SAAO,iBAAiB,MAAM,aAAa,aAAa,EAAE,CAAC;AAC7D;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
3
|
+
import { cardsService } from "../services/cards.service";
|
|
4
|
+
async function setDefaultCardAction(cardId) {
|
|
5
|
+
return safeServerAction(() => cardsService.setDefaultCard(cardId));
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
setDefaultCardAction
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=set-default-card.action.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/cards/actions/set-default-card.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { cardsService } from '../services/cards.service';\n\nexport async function setDefaultCardAction(cardId: string) {\n return safeServerAction(() => cardsService.setDefaultCard(cardId));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAE7B,eAAsB,qBAAqB,QAAgB;AACzD,SAAO,iBAAiB,MAAM,aAAa,eAAe,MAAM,CAAC;AACnE;","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { withAction } from "../../../utils/withAction";
|
|
4
|
+
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
5
|
+
import { useAuth } from "../../../providers/auth.provider";
|
|
6
|
+
function useCardById(id) {
|
|
7
|
+
const { account } = useAuth();
|
|
8
|
+
const isVindi = account?.gateway === "vindi";
|
|
9
|
+
const cardKey = useAuthQueryKey(["card", id]);
|
|
10
|
+
return useQuery({
|
|
11
|
+
queryKey: cardKey,
|
|
12
|
+
queryFn: async () => {
|
|
13
|
+
const { findCardByIdAction } = await import("../actions/find-card-by-id.action");
|
|
14
|
+
return withAction(findCardByIdAction)(id);
|
|
15
|
+
},
|
|
16
|
+
enabled: id != null && !isVindi
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
useCardById
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=card-by-id.hook.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/cards/hooks/card-by-id.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\nimport { useAuth } from '../../../providers/auth.provider';\n\nexport function useCardById(id: number | undefined) {\n const { account } = useAuth();\n const isVindi = account?.gateway === 'vindi';\n const cardKey = useAuthQueryKey(['card', id]);\n\n return useQuery({\n queryKey: cardKey,\n queryFn: async () => {\n const { findCardByIdAction } = await import('../actions/find-card-by-id.action');\n return withAction(findCardByIdAction)(id!);\n },\n enabled: id != null && !isVindi,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,eAAe;AAEjB,SAAS,YAAY,IAAwB;AAClD,QAAM,EAAE,QAAQ,IAAI,QAAQ;AAC5B,QAAM,UAAU,SAAS,YAAY;AACrC,QAAM,UAAU,gBAAgB,CAAC,QAAQ,EAAE,CAAC;AAE5C,SAAO,SAAS;AAAA,IACd,UAAU;AAAA,IACV,SAAS,YAAY;AACnB,YAAM,EAAE,mBAAmB,IAAI,MAAM,OAAO,mCAAmC;AAC/E,aAAO,WAAW,kBAAkB,EAAE,EAAG;AAAA,IAC3C;AAAA,IACA,SAAS,MAAM,QAAQ,CAAC;AAAA,EAC1B,CAAC;AACH;","names":[]}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useQuery } from "@tanstack/react-query";
|
|
3
3
|
import { withAction } from "../../../utils/withAction";
|
|
4
|
-
import {
|
|
4
|
+
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
5
|
+
import { useAuth } from "../../../providers/auth.provider";
|
|
5
6
|
const CARDS_QUERY_KEY = ["cards"];
|
|
6
7
|
function useCards() {
|
|
8
|
+
const { account } = useAuth();
|
|
9
|
+
const isVindi = account?.gateway === "vindi";
|
|
10
|
+
const queryKey = useAuthQueryKey([...CARDS_QUERY_KEY]);
|
|
7
11
|
return useQuery({
|
|
8
|
-
queryKey
|
|
9
|
-
queryFn:
|
|
12
|
+
queryKey,
|
|
13
|
+
queryFn: async () => {
|
|
14
|
+
const { listCardsAction } = await import("../actions/list-cards.action");
|
|
15
|
+
return withAction(listCardsAction)();
|
|
16
|
+
},
|
|
17
|
+
enabled: !isVindi
|
|
10
18
|
});
|
|
11
19
|
}
|
|
12
20
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/cards/hooks/cards.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/cards/hooks/cards.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\nimport { useAuth } from '../../../providers/auth.provider';\n\nexport const CARDS_QUERY_KEY = ['cards'] as const;\n\nexport function useCards() {\n const { account } = useAuth();\n const isVindi = account?.gateway === 'vindi';\n const queryKey = useAuthQueryKey([...CARDS_QUERY_KEY]);\n\n return useQuery({\n queryKey,\n queryFn: async () => {\n const { listCardsAction } = await import('../actions/list-cards.action');\n return withAction(listCardsAction)();\n },\n enabled: !isVindi,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,eAAe;AAEjB,MAAM,kBAAkB,CAAC,OAAO;AAEhC,SAAS,WAAW;AACzB,QAAM,EAAE,QAAQ,IAAI,QAAQ;AAC5B,QAAM,UAAU,SAAS,YAAY;AACrC,QAAM,WAAW,gBAAgB,CAAC,GAAG,eAAe,CAAC;AAErD,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,YAAY;AACnB,YAAM,EAAE,gBAAgB,IAAI,MAAM,OAAO,8BAA8B;AACvE,aAAO,WAAW,eAAe,EAAE;AAAA,IACrC;AAAA,IACA,SAAS,CAAC;AAAA,EACZ,CAAC;AACH;","names":[]}
|
|
@@ -3,12 +3,23 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
|
3
3
|
import { withAction } from "../../../utils/withAction";
|
|
4
4
|
import { createCardAction } from "../actions/create-card.action";
|
|
5
5
|
import { CARDS_QUERY_KEY } from "./cards.hook";
|
|
6
|
+
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
6
7
|
function useCreateCard() {
|
|
7
8
|
const queryClient = useQueryClient();
|
|
9
|
+
const cardsKey = useAuthQueryKey([...CARDS_QUERY_KEY]);
|
|
8
10
|
return useMutation({
|
|
9
11
|
mutationFn: (data) => withAction(createCardAction)(data),
|
|
10
|
-
onSuccess: () => {
|
|
11
|
-
|
|
12
|
+
onSuccess: (result) => {
|
|
13
|
+
if (result?.data) {
|
|
14
|
+
queryClient.setQueriesData(
|
|
15
|
+
{ queryKey: cardsKey },
|
|
16
|
+
(old) => {
|
|
17
|
+
if (!old?.data) return old;
|
|
18
|
+
return { ...old, data: [...old.data, result.data] };
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
queryClient.invalidateQueries({ queryKey: cardsKey });
|
|
12
23
|
}
|
|
13
24
|
});
|
|
14
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/cards/hooks/create-card.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { createCardAction } from '../actions/create-card.action';\nimport { CreateCardRequest } from '../types';\nimport { CARDS_QUERY_KEY } from './cards.hook';\n\nexport function useCreateCard() {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: (data: CreateCardRequest) => withAction(createCardAction)(data),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey:
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/cards/hooks/create-card.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { createCardAction } from '../actions/create-card.action';\nimport type { CreateCardRequest, Card } from '../types';\nimport type { PaginatedSuccessResult } from '../../../infra/api/types';\nimport { CARDS_QUERY_KEY } from './cards.hook';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport function useCreateCard() {\n const queryClient = useQueryClient();\n const cardsKey = useAuthQueryKey([...CARDS_QUERY_KEY]);\n\n return useMutation({\n mutationFn: (data: CreateCardRequest) => withAction(createCardAction)(data),\n onSuccess: (result) => {\n if (result?.data) {\n queryClient.setQueriesData<PaginatedSuccessResult<Card>>(\n { queryKey: cardsKey },\n (old) => {\n if (!old?.data) return old;\n return { ...old, data: [...old.data, result.data!] };\n }\n );\n }\n queryClient.invalidateQueries({ queryKey: cardsKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB;AAGjC,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAEzB,SAAS,gBAAgB;AAC9B,QAAM,cAAc,eAAe;AACnC,QAAM,WAAW,gBAAgB,CAAC,GAAG,eAAe,CAAC;AAErD,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,SAA4B,WAAW,gBAAgB,EAAE,IAAI;AAAA,IAC1E,WAAW,CAAC,WAAW;AACrB,UAAI,QAAQ,MAAM;AAChB,oBAAY;AAAA,UACV,EAAE,UAAU,SAAS;AAAA,UACrB,CAAC,QAAQ;AACP,gBAAI,CAAC,KAAK,KAAM,QAAO;AACvB,mBAAO,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,IAAI,MAAM,OAAO,IAAK,EAAE;AAAA,UACrD;AAAA,QACF;AAAA,MACF;AACA,kBAAY,kBAAkB,EAAE,UAAU,SAAS,CAAC;AAAA,IACtD;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { withAction } from "../../../utils/withAction";
|
|
4
|
+
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
5
|
+
import { CARDS_QUERY_KEY } from "./cards.hook";
|
|
6
|
+
function useDeleteCard() {
|
|
7
|
+
const queryClient = useQueryClient();
|
|
8
|
+
const cardsKey = useAuthQueryKey([...CARDS_QUERY_KEY]);
|
|
9
|
+
const cardKey = useAuthQueryKey(["card"]);
|
|
10
|
+
return useMutation({
|
|
11
|
+
mutationFn: async (id) => {
|
|
12
|
+
const { deleteCardAction } = await import("../actions/delete-card.action");
|
|
13
|
+
return withAction(deleteCardAction)(id);
|
|
14
|
+
},
|
|
15
|
+
onMutate: async (id) => {
|
|
16
|
+
await queryClient.cancelQueries({ queryKey: cardsKey });
|
|
17
|
+
const previousQueries = queryClient.getQueriesData({
|
|
18
|
+
queryKey: cardsKey
|
|
19
|
+
});
|
|
20
|
+
queryClient.setQueriesData(
|
|
21
|
+
{ queryKey: cardsKey },
|
|
22
|
+
(old) => {
|
|
23
|
+
if (!old?.data) return old;
|
|
24
|
+
return {
|
|
25
|
+
...old,
|
|
26
|
+
data: old.data.map(
|
|
27
|
+
(card) => card.id.toString() === id ? { ...card, deleted: true } : card
|
|
28
|
+
)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
return { previousQueries };
|
|
33
|
+
},
|
|
34
|
+
onError: (_err, _id, context) => {
|
|
35
|
+
if (context?.previousQueries) {
|
|
36
|
+
for (const [queryKey, data] of context.previousQueries) {
|
|
37
|
+
queryClient.setQueryData(queryKey, data);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
onSettled: () => {
|
|
42
|
+
queryClient.invalidateQueries({ queryKey: cardsKey });
|
|
43
|
+
queryClient.invalidateQueries({ queryKey: cardKey });
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
useDeleteCard
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=delete-card.hook.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/cards/hooks/delete-card.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\nimport { CARDS_QUERY_KEY } from './cards.hook';\nimport type { PaginatedSuccessResult } from '../../../infra/api/types';\nimport type { Card } from '../types';\n\nexport function useDeleteCard() {\n const queryClient = useQueryClient();\n const cardsKey = useAuthQueryKey([...CARDS_QUERY_KEY]);\n const cardKey = useAuthQueryKey(['card']);\n\n return useMutation({\n mutationFn: async (id: string) => {\n const { deleteCardAction } = await import('../actions/delete-card.action');\n return withAction(deleteCardAction)(id);\n },\n onMutate: async (id: string) => {\n await queryClient.cancelQueries({ queryKey: cardsKey });\n\n const previousQueries = queryClient.getQueriesData<PaginatedSuccessResult<Card>>({\n queryKey: cardsKey,\n });\n\n queryClient.setQueriesData<PaginatedSuccessResult<Card>>(\n { queryKey: cardsKey },\n (old) => {\n if (!old?.data) return old;\n return {\n ...old,\n data: old.data.map((card) =>\n card.id.toString() === id ? { ...card, deleted: true } : card\n ),\n };\n }\n );\n\n return { previousQueries };\n },\n onError: (_err, _id, context) => {\n if (context?.previousQueries) {\n for (const [queryKey, data] of context.previousQueries) {\n queryClient.setQueryData(queryKey, data);\n }\n }\n },\n onSettled: () => {\n queryClient.invalidateQueries({ queryKey: cardsKey });\n queryClient.invalidateQueries({ queryKey: cardKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAIzB,SAAS,gBAAgB;AAC9B,QAAM,cAAc,eAAe;AACnC,QAAM,WAAW,gBAAgB,CAAC,GAAG,eAAe,CAAC;AACrD,QAAM,UAAU,gBAAgB,CAAC,MAAM,CAAC;AAExC,SAAO,YAAY;AAAA,IACjB,YAAY,OAAO,OAAe;AAChC,YAAM,EAAE,iBAAiB,IAAI,MAAM,OAAO,+BAA+B;AACzE,aAAO,WAAW,gBAAgB,EAAE,EAAE;AAAA,IACxC;AAAA,IACA,UAAU,OAAO,OAAe;AAC9B,YAAM,YAAY,cAAc,EAAE,UAAU,SAAS,CAAC;AAEtD,YAAM,kBAAkB,YAAY,eAA6C;AAAA,QAC/E,UAAU;AAAA,MACZ,CAAC;AAED,kBAAY;AAAA,QACV,EAAE,UAAU,SAAS;AAAA,QACrB,CAAC,QAAQ;AACP,cAAI,CAAC,KAAK,KAAM,QAAO;AACvB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,MAAM,IAAI,KAAK;AAAA,cAAI,CAAC,SAClB,KAAK,GAAG,SAAS,MAAM,KAAK,EAAE,GAAG,MAAM,SAAS,KAAK,IAAI;AAAA,YAC3D;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA,aAAO,EAAE,gBAAgB;AAAA,IAC3B;AAAA,IACA,SAAS,CAAC,MAAM,KAAK,YAAY;AAC/B,UAAI,SAAS,iBAAiB;AAC5B,mBAAW,CAAC,UAAU,IAAI,KAAK,QAAQ,iBAAiB;AACtD,sBAAY,aAAa,UAAU,IAAI;AAAA,QACzC;AAAA,MACF;AAAA,IACF;AAAA,IACA,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,SAAS,CAAC;AACpD,kBAAY,kBAAkB,EAAE,UAAU,QAAQ,CAAC;AAAA,IACrD;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { withAction } from "../../../utils/withAction";
|
|
4
|
+
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
5
|
+
import { CARDS_QUERY_KEY } from "./cards.hook";
|
|
6
|
+
function useSetDefaultCard() {
|
|
7
|
+
const queryClient = useQueryClient();
|
|
8
|
+
const cardsKey = useAuthQueryKey([...CARDS_QUERY_KEY]);
|
|
9
|
+
const cardKey = useAuthQueryKey(["card"]);
|
|
10
|
+
return useMutation({
|
|
11
|
+
mutationFn: async (cardId) => {
|
|
12
|
+
const { setDefaultCardAction } = await import("../actions/set-default-card.action");
|
|
13
|
+
return withAction(setDefaultCardAction)(cardId);
|
|
14
|
+
},
|
|
15
|
+
onMutate: async (cardId) => {
|
|
16
|
+
await queryClient.cancelQueries({ queryKey: cardsKey });
|
|
17
|
+
const previousQueries = queryClient.getQueriesData({
|
|
18
|
+
queryKey: cardsKey
|
|
19
|
+
});
|
|
20
|
+
queryClient.setQueriesData(
|
|
21
|
+
{ queryKey: cardsKey },
|
|
22
|
+
(old) => {
|
|
23
|
+
if (!old?.data) return old;
|
|
24
|
+
return {
|
|
25
|
+
...old,
|
|
26
|
+
data: old.data.map((card) => ({
|
|
27
|
+
...card,
|
|
28
|
+
is_default: card.id.toString() === cardId
|
|
29
|
+
}))
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
return { previousQueries };
|
|
34
|
+
},
|
|
35
|
+
onError: (_err, _cardId, context) => {
|
|
36
|
+
if (context?.previousQueries) {
|
|
37
|
+
for (const [queryKey, data] of context.previousQueries) {
|
|
38
|
+
queryClient.setQueryData(queryKey, data);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
onSettled: () => {
|
|
43
|
+
queryClient.invalidateQueries({ queryKey: cardsKey });
|
|
44
|
+
queryClient.invalidateQueries({ queryKey: cardKey });
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
useSetDefaultCard
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=set-default-card.hook.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/cards/hooks/set-default-card.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\nimport { CARDS_QUERY_KEY } from './cards.hook';\nimport type { PaginatedSuccessResult } from '../../../infra/api/types';\nimport type { Card } from '../types';\n\nexport function useSetDefaultCard() {\n const queryClient = useQueryClient();\n const cardsKey = useAuthQueryKey([...CARDS_QUERY_KEY]);\n const cardKey = useAuthQueryKey(['card']);\n\n return useMutation({\n mutationFn: async (cardId: string) => {\n const { setDefaultCardAction } = await import('../actions/set-default-card.action');\n return withAction(setDefaultCardAction)(cardId);\n },\n onMutate: async (cardId: string) => {\n await queryClient.cancelQueries({ queryKey: cardsKey });\n\n const previousQueries = queryClient.getQueriesData<PaginatedSuccessResult<Card>>({\n queryKey: cardsKey,\n });\n\n queryClient.setQueriesData<PaginatedSuccessResult<Card>>(\n { queryKey: cardsKey },\n (old) => {\n if (!old?.data) return old;\n return {\n ...old,\n data: old.data.map((card) => ({\n ...card,\n is_default: card.id.toString() === cardId,\n })),\n };\n }\n );\n\n return { previousQueries };\n },\n onError: (_err, _cardId, context) => {\n if (context?.previousQueries) {\n for (const [queryKey, data] of context.previousQueries) {\n queryClient.setQueryData(queryKey, data);\n }\n }\n },\n onSettled: () => {\n queryClient.invalidateQueries({ queryKey: cardsKey });\n queryClient.invalidateQueries({ queryKey: cardKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAIzB,SAAS,oBAAoB;AAClC,QAAM,cAAc,eAAe;AACnC,QAAM,WAAW,gBAAgB,CAAC,GAAG,eAAe,CAAC;AACrD,QAAM,UAAU,gBAAgB,CAAC,MAAM,CAAC;AAExC,SAAO,YAAY;AAAA,IACjB,YAAY,OAAO,WAAmB;AACpC,YAAM,EAAE,qBAAqB,IAAI,MAAM,OAAO,oCAAoC;AAClF,aAAO,WAAW,oBAAoB,EAAE,MAAM;AAAA,IAChD;AAAA,IACA,UAAU,OAAO,WAAmB;AAClC,YAAM,YAAY,cAAc,EAAE,UAAU,SAAS,CAAC;AAEtD,YAAM,kBAAkB,YAAY,eAA6C;AAAA,QAC/E,UAAU;AAAA,MACZ,CAAC;AAED,kBAAY;AAAA,QACV,EAAE,UAAU,SAAS;AAAA,QACrB,CAAC,QAAQ;AACP,cAAI,CAAC,KAAK,KAAM,QAAO;AACvB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,MAAM,IAAI,KAAK,IAAI,CAAC,UAAU;AAAA,cAC5B,GAAG;AAAA,cACH,YAAY,KAAK,GAAG,SAAS,MAAM;AAAA,YACrC,EAAE;AAAA,UACJ;AAAA,QACF;AAAA,MACF;AAEA,aAAO,EAAE,gBAAgB;AAAA,IAC3B;AAAA,IACA,SAAS,CAAC,MAAM,SAAS,YAAY;AACnC,UAAI,SAAS,iBAAiB;AAC5B,mBAAW,CAAC,UAAU,IAAI,KAAK,QAAQ,iBAAiB;AACtD,sBAAY,aAAa,UAAU,IAAI;AAAA,QACzC;AAAA,MACF;AAAA,IACF;AAAA,IACA,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,SAAS,CAAC;AACpD,kBAAY,kBAAkB,EAAE,UAAU,QAAQ,CAAC;AAAA,IACrD;AAAA,EACF,CAAC;AACH;","names":[]}
|