@navservice/assinatura 1.38.0 → 1.41.0
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.
|
@@ -18,7 +18,7 @@ interface AssinaturaState {
|
|
|
18
18
|
checkout: t.Controller.Assinatura.CriarCheckoutSession.Output | null;
|
|
19
19
|
loading: boolean;
|
|
20
20
|
}
|
|
21
|
-
declare
|
|
21
|
+
export declare const contexto_assinatura: {
|
|
22
22
|
api: {
|
|
23
23
|
criar: (props: t.Controller.Assinatura.Criar.Input) => Promise<t.Controller.Assinatura.Criar.Output | null>;
|
|
24
24
|
buscar_pelo_id: (props: t.Controller.Assinatura.BuscarPeloId.Input) => Promise<t.Controller.Assinatura.BuscarPeloId.Output | null>;
|
|
@@ -32,6 +32,5 @@ declare class contexto_assinatura {
|
|
|
32
32
|
get get_jsx(): AssinaturaState;
|
|
33
33
|
get get_state(): AssinaturaState;
|
|
34
34
|
set_state: (updater: (state: AssinaturaState) => void) => void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default _default;
|
|
35
|
+
};
|
|
36
|
+
export {};
|
package/build/es/index.js
CHANGED
|
@@ -19333,7 +19333,7 @@ const criar_estado_inicial = ()=>({
|
|
|
19333
19333
|
const contexto_assinatura_store = react_create()(immer_immer(()=>({
|
|
19334
19334
|
states: criar_estado_inicial()
|
|
19335
19335
|
})));
|
|
19336
|
-
|
|
19336
|
+
const contexto_assinatura = new class {
|
|
19337
19337
|
api = {
|
|
19338
19338
|
criar: async (props)=>{
|
|
19339
19339
|
try {
|
|
@@ -19533,8 +19533,7 @@ class contexto_assinatura {
|
|
|
19533
19533
|
updater(s.states);
|
|
19534
19534
|
});
|
|
19535
19535
|
};
|
|
19536
|
-
}
|
|
19537
|
-
const contexto_contexto_assinatura = new contexto_assinatura();
|
|
19536
|
+
};
|
|
19538
19537
|
function ButtonGerarUrl({ input, label = "Gerar link de pagamento", setUpgradePlano }) {
|
|
19539
19538
|
const [isLoading, setIsLoading] = (0, external_React_.useState)(false);
|
|
19540
19539
|
const [hasError, setHasError] = (0, external_React_.useState)(false);
|
|
@@ -19544,7 +19543,7 @@ function ButtonGerarUrl({ input, label = "Gerar link de pagamento", setUpgradePl
|
|
|
19544
19543
|
try {
|
|
19545
19544
|
setIsLoading(true);
|
|
19546
19545
|
setHasError(false);
|
|
19547
|
-
const resultado = await
|
|
19546
|
+
const resultado = await contexto_assinatura.api.criar_checkout_session(input);
|
|
19548
19547
|
const url = resultado?.data?.checkout?.url;
|
|
19549
19548
|
if (resultado?.data?.checkout?.tipo_evento === "upgrade") return window.location.reload();
|
|
19550
19549
|
if ("string" == typeof url && url.length > 0) window.location.href = url;
|
|
@@ -19633,11 +19632,11 @@ function labelPeriodo(interval, count) {
|
|
|
19633
19632
|
return `${count} ${interval}`;
|
|
19634
19633
|
}
|
|
19635
19634
|
function CheckoutAssinaturaStripe() {
|
|
19636
|
-
const { data, loading, periodo_selecionado, produto_id, periodos } =
|
|
19635
|
+
const { data, loading, periodo_selecionado, produto_id, periodos } = contexto_assinatura.get_jsx.produto;
|
|
19637
19636
|
const isMobile = src_utils.hooks.use_is_mobile();
|
|
19638
19637
|
const selecionadoManual = (0, external_React_.useRef)(false);
|
|
19639
19638
|
(0, external_React_.useEffect)(()=>{
|
|
19640
|
-
|
|
19639
|
+
contexto_assinatura.api.buscar_produto_stripe();
|
|
19641
19640
|
}, []);
|
|
19642
19641
|
const planoAtualPriceId = data?.plano_atual?.price_id ?? null;
|
|
19643
19642
|
const planoAtualEhFree = null === planoAtualPriceId;
|
|
@@ -19659,12 +19658,12 @@ function CheckoutAssinaturaStripe() {
|
|
|
19659
19658
|
(0, external_React_.useEffect)(()=>{
|
|
19660
19659
|
if (!data?.produtos?.length) return;
|
|
19661
19660
|
if (selecionadoManual.current) return;
|
|
19662
|
-
if (!planoAtualEhFree && planoAtualPriceId) return void
|
|
19661
|
+
if (!planoAtualEhFree && planoAtualPriceId) return void contexto_assinatura.set_state((store)=>{
|
|
19663
19662
|
store.produto.produto_id = planoAtualPriceId;
|
|
19664
19663
|
});
|
|
19665
19664
|
if (planoAtualEhFree) {
|
|
19666
19665
|
const primeiroZero = data.produtos.flatMap((p)=>p.precos).find((p)=>0 === p.unit_amount);
|
|
19667
|
-
if (primeiroZero)
|
|
19666
|
+
if (primeiroZero) contexto_assinatura.set_state((store)=>{
|
|
19668
19667
|
store.produto.produto_id = primeiroZero.id;
|
|
19669
19668
|
});
|
|
19670
19669
|
}
|
|
@@ -19722,7 +19721,7 @@ function CheckoutAssinaturaStripe() {
|
|
|
19722
19721
|
const ativo = periodo_selecionado === id;
|
|
19723
19722
|
return /*#__PURE__*/ (0, jsx_runtime.jsx)("button", {
|
|
19724
19723
|
type: "button",
|
|
19725
|
-
onClick: ()=>
|
|
19724
|
+
onClick: ()=>contexto_assinatura.set_state((store)=>{
|
|
19726
19725
|
store.produto.periodo_selecionado = id;
|
|
19727
19726
|
store.produto.produto_id = null;
|
|
19728
19727
|
selecionadoManual.current = false;
|
|
@@ -19752,7 +19751,7 @@ function CheckoutAssinaturaStripe() {
|
|
|
19752
19751
|
return /*#__PURE__*/ (0, jsx_runtime.jsxs)("article", {
|
|
19753
19752
|
onClick: ()=>{
|
|
19754
19753
|
selecionadoManual.current = true;
|
|
19755
|
-
|
|
19754
|
+
contexto_assinatura.set_state((store)=>{
|
|
19756
19755
|
store.produto.produto_id = precoAtivo.id;
|
|
19757
19756
|
});
|
|
19758
19757
|
},
|
|
@@ -19952,4 +19951,4 @@ function CheckoutAssinaturaStripe() {
|
|
|
19952
19951
|
]
|
|
19953
19952
|
});
|
|
19954
19953
|
}
|
|
19955
|
-
export { CheckoutAssinaturaStripe, CheckoutStripe };
|
|
19954
|
+
export { CheckoutAssinaturaStripe, CheckoutStripe, contexto_assinatura };
|