@greatapps/common 1.1.683 → 1.1.684
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.
|
@@ -4,7 +4,7 @@ import { UserProfile } from "../../users/schema";
|
|
|
4
4
|
import { useAuth } from "../../../providers/auth.provider";
|
|
5
5
|
import { useModalManager } from "../../../store/useModalManager";
|
|
6
6
|
import { useActiveSubscription } from "./find-active-subscription.hook";
|
|
7
|
-
import {
|
|
7
|
+
import { getSubscriptionCancellationState } from "../utils/get-subscription-cancellation-state";
|
|
8
8
|
function useCancelledSubscriptionGuard() {
|
|
9
9
|
const { user } = useAuth();
|
|
10
10
|
const { openModal } = useModalManager();
|
|
@@ -12,8 +12,7 @@ function useCancelledSubscriptionGuard() {
|
|
|
12
12
|
data: { data: [subscription] = [] } = {}
|
|
13
13
|
} = useActiveSubscription();
|
|
14
14
|
const isViewer = user?.profile === UserProfile.viewer;
|
|
15
|
-
const
|
|
16
|
-
const isCancelledSubscription = !!expiryDate && Date.now() >= expiryDate.getTime();
|
|
15
|
+
const isCancelledSubscription = getSubscriptionCancellationState(subscription) === "cancelled";
|
|
17
16
|
const shouldBlockManagementAction = !isViewer && isCancelledSubscription;
|
|
18
17
|
const guardAction = useCallback(
|
|
19
18
|
(action) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/use-cancelled-subscription-guard.ts"],"sourcesContent":["'use client';\n\nimport { useCallback } from 'react';\nimport { UserProfile } from '../../users/schema';\nimport { useAuth } from '../../../providers/auth.provider';\nimport { useModalManager } from '../../../store/useModalManager';\nimport { useActiveSubscription } from './find-active-subscription.hook';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/use-cancelled-subscription-guard.ts"],"sourcesContent":["'use client';\n\nimport { useCallback } from 'react';\nimport { UserProfile } from '../../users/schema';\nimport { useAuth } from '../../../providers/auth.provider';\nimport { useModalManager } from '../../../store/useModalManager';\nimport { useActiveSubscription } from './find-active-subscription.hook';\nimport { getSubscriptionCancellationState } from '../utils/get-subscription-cancellation-state';\n\nexport function useCancelledSubscriptionGuard() {\n const { user } = useAuth();\n const { openModal } = useModalManager();\n const {\n data: { data: [subscription] = [] } = {},\n } = useActiveSubscription();\n\n const isViewer = user?.profile === UserProfile.viewer;\n // Efetivamente cancelada: active === false (ex.: baixa por falha de pagamento)\n // ou cancelamento cujo período já terminou. Mesma fonte da verdade do\n // SubscriptionBanner — não bloqueia só por data (date_due pode estar no futuro\n // apontando pra uma fatura não paga).\n const isCancelledSubscription =\n getSubscriptionCancellationState(subscription) === 'cancelled';\n const shouldBlockManagementAction = !isViewer && isCancelledSubscription;\n\n const guardAction = useCallback(\n (action?: () => void) => {\n if (shouldBlockManagementAction) {\n openModal('subscriptionExpiredModal');\n return false;\n }\n\n action?.();\n return true;\n },\n [openModal, shouldBlockManagementAction]\n );\n\n return {\n isCancelledSubscription,\n shouldBlockManagementAction,\n guardAction,\n };\n}\n"],"mappings":";AAEA,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,wCAAwC;AAE1C,SAAS,gCAAgC;AAC9C,QAAM,EAAE,KAAK,IAAI,QAAQ;AACzB,QAAM,EAAE,UAAU,IAAI,gBAAgB;AACtC,QAAM;AAAA,IACJ,MAAM,EAAE,MAAM,CAAC,YAAY,IAAI,CAAC,EAAE,IAAI,CAAC;AAAA,EACzC,IAAI,sBAAsB;AAE1B,QAAM,WAAW,MAAM,YAAY,YAAY;AAK/C,QAAM,0BACJ,iCAAiC,YAAY,MAAM;AACrD,QAAM,8BAA8B,CAAC,YAAY;AAEjD,QAAM,cAAc;AAAA,IAClB,CAAC,WAAwB;AACvB,UAAI,6BAA6B;AAC/B,kBAAU,0BAA0B;AACpC,eAAO;AAAA,MACT;AAEA,eAAS;AACT,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,2BAA2B;AAAA,EACzC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import { UserProfile } from '../../users/schema';
|
|
|
5
5
|
import { useAuth } from '../../../providers/auth.provider';
|
|
6
6
|
import { useModalManager } from '../../../store/useModalManager';
|
|
7
7
|
import { useActiveSubscription } from './find-active-subscription.hook';
|
|
8
|
-
import {
|
|
8
|
+
import { getSubscriptionCancellationState } from '../utils/get-subscription-cancellation-state';
|
|
9
9
|
|
|
10
10
|
export function useCancelledSubscriptionGuard() {
|
|
11
11
|
const { user } = useAuth();
|
|
@@ -15,8 +15,12 @@ export function useCancelledSubscriptionGuard() {
|
|
|
15
15
|
} = useActiveSubscription();
|
|
16
16
|
|
|
17
17
|
const isViewer = user?.profile === UserProfile.viewer;
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
// Efetivamente cancelada: active === false (ex.: baixa por falha de pagamento)
|
|
19
|
+
// ou cancelamento cujo período já terminou. Mesma fonte da verdade do
|
|
20
|
+
// SubscriptionBanner — não bloqueia só por data (date_due pode estar no futuro
|
|
21
|
+
// apontando pra uma fatura não paga).
|
|
22
|
+
const isCancelledSubscription =
|
|
23
|
+
getSubscriptionCancellationState(subscription) === 'cancelled';
|
|
20
24
|
const shouldBlockManagementAction = !isViewer && isCancelledSubscription;
|
|
21
25
|
|
|
22
26
|
const guardAction = useCallback(
|