@greatapps/common 1.1.799 → 1.1.800
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/modules/accounts/hooks/use-required-billing-data.hook.mjs +2 -2
- package/dist/modules/accounts/hooks/use-required-billing-data.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/utils/has-paid-subscription.mjs +1 -1
- package/dist/modules/subscriptions/utils/has-paid-subscription.mjs.map +1 -1
- package/package.json +1 -1
- package/src/modules/accounts/hooks/use-required-billing-data.hook.ts +9 -2
- package/src/modules/subscriptions/utils/has-paid-subscription.ts +13 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useCurrentAccount } from "./current-account.hook";
|
|
3
|
-
import {
|
|
3
|
+
import { useCurrentSubscription } from "../../subscriptions/hooks/use-current-subscription.hook";
|
|
4
4
|
import { hasPaidSubscription } from "../../subscriptions/utils/has-paid-subscription";
|
|
5
5
|
import { useManagementPermissions } from "../../auth/hooks/useManagementPermissions";
|
|
6
6
|
import { hasCompleteBillingData, isBrazilianBillingAccount } from "../utils/billing-data";
|
|
@@ -10,7 +10,7 @@ function useRequiredBillingData() {
|
|
|
10
10
|
const {
|
|
11
11
|
data: { data: [subscription] = [] } = {},
|
|
12
12
|
isPending: isSubscriptionPending
|
|
13
|
-
} =
|
|
13
|
+
} = useCurrentSubscription();
|
|
14
14
|
const isLoading = isAccountPending || isSubscriptionPending;
|
|
15
15
|
const isRequired = !isLoading && isOwnerOrAdmin && isBrazilianBillingAccount(account) && hasPaidSubscription(subscription) && !hasCompleteBillingData(account);
|
|
16
16
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/accounts/hooks/use-required-billing-data.hook.ts"],"sourcesContent":["'use client';\n\nimport { useCurrentAccount } from './current-account.hook';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/accounts/hooks/use-required-billing-data.hook.ts"],"sourcesContent":["'use client';\n\nimport { useCurrentAccount } from './current-account.hook';\nimport { useCurrentSubscription } from '../../subscriptions/hooks/use-current-subscription.hook';\nimport { hasPaidSubscription } from '../../subscriptions/utils/has-paid-subscription';\nimport { useManagementPermissions } from '../../auth/hooks/useManagementPermissions';\nimport { hasCompleteBillingData, isBrazilianBillingAccount } from '../utils/billing-data';\n\n/**\n * Contas que já pagaram mas nunca preencheram o cadastro de cobrança ficam sem\n * nota fiscal (chamado \"Nota fiscal não emitida em pagamentos confirmados\").\n * Este hook diz quando o preenchimento vira obrigatório — o modal que ele\n * alimenta é bloqueante, então só liga com os dados já carregados e só para\n * quem consegue resolver: owner/admin de conta brasileira.\n *\n * A assinatura vem de `useCurrentSubscription`, não de `useActiveSubscription`:\n * o segundo é `GET /subscriptions?limit=1` sem regra de escolha, então numa conta\n * com trial antiga a trial volta na frente da assinatura paga e o gate se cala.\n * Foi o que aconteceu na conta 428409, que pagou R$ 1.918 sem nota e nunca viu o\n * modal. O `current` aplica o ranqueamento do backend (cliente viva > trial viva >\n * free > encerrada) e devolve a mesma forma paginada.\n */\nexport function useRequiredBillingData() {\n const { isOwnerOrAdmin } = useManagementPermissions();\n const { data: account, isPending: isAccountPending } = useCurrentAccount();\n const {\n data: { data: [subscription] = [] } = {},\n isPending: isSubscriptionPending,\n } = useCurrentSubscription();\n\n const isLoading = isAccountPending || isSubscriptionPending;\n\n const isRequired =\n !isLoading &&\n isOwnerOrAdmin &&\n isBrazilianBillingAccount(account) &&\n hasPaidSubscription(subscription) &&\n !hasCompleteBillingData(account);\n\n return {\n isRequired,\n isLoading,\n account,\n };\n}\n"],"mappings":";AAEA,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,SAAS,gCAAgC;AACzC,SAAS,wBAAwB,iCAAiC;AAgB3D,SAAS,yBAAyB;AACvC,QAAM,EAAE,eAAe,IAAI,yBAAyB;AACpD,QAAM,EAAE,MAAM,SAAS,WAAW,iBAAiB,IAAI,kBAAkB;AACzE,QAAM;AAAA,IACJ,MAAM,EAAE,MAAM,CAAC,YAAY,IAAI,CAAC,EAAE,IAAI,CAAC;AAAA,IACvC,WAAW;AAAA,EACb,IAAI,uBAAuB;AAE3B,QAAM,YAAY,oBAAoB;AAEtC,QAAM,aACJ,CAAC,aACD,kBACA,0BAA0B,OAAO,KACjC,oBAAoB,YAAY,KAChC,CAAC,uBAAuB,OAAO;AAEjC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/utils/has-paid-subscription.ts"],"sourcesContent":["import type { Subscription } from '../types/subscription.type';\nimport { FREE_PLAN_ID } from '../constants/subscription.constants';\n\ntype PaidSubscriptionSnapshot = Pick<Subscription, 'type' | 'id_plan'
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/utils/has-paid-subscription.ts"],"sourcesContent":["import type { Subscription } from '../types/subscription.type';\nimport { FREE_PLAN_ID } from '../constants/subscription.constants';\n\ntype PaidSubscriptionSnapshot = Pick<Subscription, 'type' | 'id_plan'>;\n\n/**\n * A assinatura é de plano pago — o que basta para a conta precisar de cadastro\n * fiscal, porque a cobrança vem e a nota tem que sair com ela.\n *\n * Não olha mais `charged`. O campo é escrito no `bill_paid`, evento do fluxo\n * Vindi, e na prática só a Stripe o preenche: das 7.528 assinaturas ativas de\n * plano pago com cobrança paga, 812 estão sem ele, e 806 dessas são Vindi (96%\n * da base Vindi). Exigi-lo deixava o gate cego justamente para a parte antiga da\n * base — a conta 428409 pagou R$ 1.918 sem nota com `charged = false`.\n *\n * Não exigir pagamento confirmado também alcança a conta ANTES da primeira\n * cobrança, que é quando o dado fiscal ainda dá tempo de evitar nota perdida.\n *\n * Free e trial ficam de fora: não geram cobrança a documentar.\n */\nexport function hasPaidSubscription(\n subscription: PaidSubscriptionSnapshot | undefined | null,\n): boolean {\n if (!subscription) return false;\n if (subscription.type === 'free' || subscription.id_plan === FREE_PLAN_ID) {\n return false;\n }\n if (subscription.type === 'trial') return false;\n\n return true;\n}\n"],"mappings":"AACA,SAAS,oBAAoB;AAmBtB,SAAS,oBACd,cACS;AACT,MAAI,CAAC,aAAc,QAAO;AAC1B,MAAI,aAAa,SAAS,UAAU,aAAa,YAAY,cAAc;AACzE,WAAO;AAAA,EACT;AACA,MAAI,aAAa,SAAS,QAAS,QAAO;AAE1C,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useCurrentAccount } from './current-account.hook';
|
|
4
|
-
import {
|
|
4
|
+
import { useCurrentSubscription } from '../../subscriptions/hooks/use-current-subscription.hook';
|
|
5
5
|
import { hasPaidSubscription } from '../../subscriptions/utils/has-paid-subscription';
|
|
6
6
|
import { useManagementPermissions } from '../../auth/hooks/useManagementPermissions';
|
|
7
7
|
import { hasCompleteBillingData, isBrazilianBillingAccount } from '../utils/billing-data';
|
|
@@ -12,6 +12,13 @@ import { hasCompleteBillingData, isBrazilianBillingAccount } from '../utils/bill
|
|
|
12
12
|
* Este hook diz quando o preenchimento vira obrigatório — o modal que ele
|
|
13
13
|
* alimenta é bloqueante, então só liga com os dados já carregados e só para
|
|
14
14
|
* quem consegue resolver: owner/admin de conta brasileira.
|
|
15
|
+
*
|
|
16
|
+
* A assinatura vem de `useCurrentSubscription`, não de `useActiveSubscription`:
|
|
17
|
+
* o segundo é `GET /subscriptions?limit=1` sem regra de escolha, então numa conta
|
|
18
|
+
* com trial antiga a trial volta na frente da assinatura paga e o gate se cala.
|
|
19
|
+
* Foi o que aconteceu na conta 428409, que pagou R$ 1.918 sem nota e nunca viu o
|
|
20
|
+
* modal. O `current` aplica o ranqueamento do backend (cliente viva > trial viva >
|
|
21
|
+
* free > encerrada) e devolve a mesma forma paginada.
|
|
15
22
|
*/
|
|
16
23
|
export function useRequiredBillingData() {
|
|
17
24
|
const { isOwnerOrAdmin } = useManagementPermissions();
|
|
@@ -19,7 +26,7 @@ export function useRequiredBillingData() {
|
|
|
19
26
|
const {
|
|
20
27
|
data: { data: [subscription] = [] } = {},
|
|
21
28
|
isPending: isSubscriptionPending,
|
|
22
|
-
} =
|
|
29
|
+
} = useCurrentSubscription();
|
|
23
30
|
|
|
24
31
|
const isLoading = isAccountPending || isSubscriptionPending;
|
|
25
32
|
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import type { Subscription } from '../types/subscription.type';
|
|
2
2
|
import { FREE_PLAN_ID } from '../constants/subscription.constants';
|
|
3
3
|
|
|
4
|
-
type PaidSubscriptionSnapshot = Pick<Subscription, 'type' | 'id_plan'
|
|
4
|
+
type PaidSubscriptionSnapshot = Pick<Subscription, 'type' | 'id_plan'>;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* A
|
|
7
|
+
* A assinatura é de plano pago — o que basta para a conta precisar de cadastro
|
|
8
|
+
* fiscal, porque a cobrança vem e a nota tem que sair com ela.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Não olha mais `charged`. O campo é escrito no `bill_paid`, evento do fluxo
|
|
11
|
+
* Vindi, e na prática só a Stripe o preenche: das 7.528 assinaturas ativas de
|
|
12
|
+
* plano pago com cobrança paga, 812 estão sem ele, e 806 dessas são Vindi (96%
|
|
13
|
+
* da base Vindi). Exigi-lo deixava o gate cego justamente para a parte antiga da
|
|
14
|
+
* base — a conta 428409 pagou R$ 1.918 sem nota com `charged = false`.
|
|
13
15
|
*
|
|
14
|
-
*
|
|
16
|
+
* Não exigir pagamento confirmado também alcança a conta ANTES da primeira
|
|
17
|
+
* cobrança, que é quando o dado fiscal ainda dá tempo de evitar nota perdida.
|
|
18
|
+
*
|
|
19
|
+
* Free e trial ficam de fora: não geram cobrança a documentar.
|
|
15
20
|
*/
|
|
16
21
|
export function hasPaidSubscription(
|
|
17
22
|
subscription: PaidSubscriptionSnapshot | undefined | null,
|
|
@@ -22,5 +27,5 @@ export function hasPaidSubscription(
|
|
|
22
27
|
}
|
|
23
28
|
if (subscription.type === 'trial') return false;
|
|
24
29
|
|
|
25
|
-
return
|
|
30
|
+
return true;
|
|
26
31
|
}
|