@@ -32,6 +32,20 @@ export const elementsAppearance = {
3232import { useState , useEffect } from 'react'
3333import ky from 'ky'
3434
35+ const api = ky . create ( {
36+ prefixUrl : import . meta. env . VITE_API_URL || 'http://localhost:3333' ,
37+ hooks : {
38+ beforeRequest : [
39+ request => {
40+ const token = localStorage . getItem ( 'auth:token' )
41+ if ( token ) {
42+ request . headers . set ( 'Authorization' , `Bearer ${ token } ` )
43+ }
44+ } ,
45+ ] ,
46+ } ,
47+ } )
48+
3549export function useSubscription ( ) {
3650 const [ subscription , setSubscription ] = useState ( null )
3751 const [ loading , setLoading ] = useState ( true )
@@ -40,7 +54,7 @@ export function useSubscription() {
4054 const fetchSubscription = async ( ) => {
4155 setLoading ( true )
4256 try {
43- const data = await ky . get ( '/ api/billing/subscription' ) . json ( )
57+ const data = await api . get ( 'api/billing/subscription' ) . json ( )
4458 setSubscription ( data )
4559 setError ( null )
4660 } catch ( err ) {
@@ -77,35 +91,52 @@ import { IconCheck } from '@tabler/icons-react'
7791import { useState } from 'react'
7892import ky from 'ky'
7993
94+ // Importar do arquivo de configuração centralizado
95+ // import { STRIPE_PRICES } from '../config/stripe-prices'
96+
8097const plans = [
8198 {
8299 name : 'Starter' ,
83- priceId : 'price_starter_monthly' ,
100+ priceId : 'price_starter_monthly' , // Substituir pelo valor de STRIPE_PRICES.starter.priceId
84101 price : 29 ,
85102 features : [ '5 projetos' , 'Suporte por email' , '1GB de storage' ]
86103 } ,
87104 {
88105 name : 'Pro' ,
89- priceId : 'price_pro_monthly' ,
106+ priceId : 'price_pro_monthly' , // Substituir pelo valor de STRIPE_PRICES.pro.priceId
90107 price : 99 ,
91108 popular : true ,
92109 features : [ 'Projetos ilimitados' , 'Suporte prioritário' , '10GB de storage' , 'API access' ]
93110 } ,
94111 {
95112 name : 'Enterprise' ,
96- priceId : 'price_enterprise_monthly' ,
113+ priceId : 'price_enterprise_monthly' , // Substituir pelo valor de STRIPE_PRICES.enterprise.priceId
97114 price : 299 ,
98115 features : [ 'Tudo do Pro' , 'Suporte dedicado' , 'Storage ilimitado' , 'SLA garantido' ]
99116 }
100117]
101118
119+ const api = ky . create ( {
120+ prefixUrl : import . meta. env . VITE_API_URL || 'http://localhost:3333' ,
121+ hooks : {
122+ beforeRequest : [
123+ request => {
124+ const token = localStorage . getItem ( 'auth:token' )
125+ if ( token ) {
126+ request . headers . set ( 'Authorization' , `Bearer ${ token } ` )
127+ }
128+ } ,
129+ ] ,
130+ } ,
131+ } )
132+
102133export default function Pricing ( ) {
103134 const [ loading , setLoading ] = useState ( null )
104135
105136 const handleCheckout = async ( priceId ) => {
106137 setLoading ( priceId )
107138 try {
108- const { url } = await ky . post ( '/ api/billing/checkout' , {
139+ const { url } = await api . post ( 'api/billing/checkout' , {
109140 json : { priceId, mode : 'subscription' }
110141 } ) . json ( )
111142 window . location . href = url
@@ -178,20 +209,34 @@ import { Button, Card, Group, Stack, Text, Title, Badge, Divider } from '@mantin
178209import { useState , useEffect } from 'react'
179210import ky from 'ky'
180211
212+ const api = ky . create ( {
213+ prefixUrl : import . meta. env . VITE_API_URL || 'http://localhost:3333' ,
214+ hooks : {
215+ beforeRequest : [
216+ request => {
217+ const token = localStorage . getItem ( 'auth:token' )
218+ if ( token ) {
219+ request . headers . set ( 'Authorization' , `Bearer ${ token } ` )
220+ }
221+ } ,
222+ ] ,
223+ } ,
224+ } )
225+
181226export default function BillingSettings ( ) {
182227 const [ subscription , setSubscription ] = useState ( null )
183228 const [ loading , setLoading ] = useState ( false )
184229
185230 useEffect ( ( ) => {
186- ky . get ( '/ api/billing/subscription' ) . json ( )
231+ api . get ( 'api/billing/subscription' ) . json ( )
187232 . then ( setSubscription )
188233 . catch ( console . error )
189234 } , [ ] )
190235
191236 const openPortal = async ( ) => {
192237 setLoading ( true )
193238 try {
194- const { url } = await ky . post ( '/ api/billing/portal' ) . json ( )
239+ const { url } = await api . post ( 'api/billing/portal' ) . json ( )
195240 window . location . href = url
196241 } finally {
197242 setLoading ( false )
@@ -201,9 +246,9 @@ export default function BillingSettings() {
201246 const cancelSubscription = async ( ) => {
202247 setLoading ( true )
203248 try {
204- await ky . post ( '/ api/billing/subscription/cancel' ) . json ( )
249+ await api . post ( 'api/billing/subscription/cancel' ) . json ( )
205250 // Refresh subscription data
206- const data = await ky . get ( '/ api/billing/subscription' ) . json ( )
251+ const data = await api . get ( 'api/billing/subscription' ) . json ( )
207252 setSubscription ( data )
208253 } finally {
209254 setLoading ( false )
@@ -356,12 +401,26 @@ import { IconDownload } from '@tabler/icons-react'
356401import { useState , useEffect } from 'react'
357402import ky from 'ky'
358403
404+ const api = ky . create ( {
405+ prefixUrl : import . meta. env . VITE_API_URL || 'http://localhost:3333' ,
406+ hooks : {
407+ beforeRequest : [
408+ request => {
409+ const token = localStorage . getItem ( 'auth:token' )
410+ if ( token ) {
411+ request . headers . set ( 'Authorization' , `Bearer ${ token } ` )
412+ }
413+ } ,
414+ ] ,
415+ } ,
416+ } )
417+
359418export default function InvoiceList ( ) {
360419 const [ invoices , setInvoices ] = useState ( [ ] )
361420 const [ loading , setLoading ] = useState ( true )
362421
363422 useEffect ( ( ) => {
364- ky . get ( '/ api/billing/invoices' ) . json ( )
423+ api . get ( 'api/billing/invoices' ) . json ( )
365424 . then ( ( { data } ) => setInvoices ( data ) )
366425 . catch ( console . error )
367426 . finally ( ( ) => setLoading ( false ) )
0 commit comments