@@ -5,12 +5,13 @@ import {useCreateOrGetStripeConnectDetails} from "../../../../../../queries/useC
55import { useGetAccount } from "../../../../../../queries/useGetAccount.ts" ;
66import { LoadingMask } from "../../../../../common/LoadingMask" ;
77import { Anchor , Button , Grid , Group , Text , ThemeIcon , Title } from "@mantine/core" ;
8- import { StripeConnectDetails } from "../../../../../../types.ts" ;
8+ import { Account } from "../../../../../../types.ts" ;
99import paymentClasses from "./PaymentSettings.module.scss" ;
1010import classes from "../../ManageAccount.module.scss" ;
1111import { useEffect , useState } from "react" ;
1212import { IconAlertCircle , IconBrandStripe , IconCheck , IconExternalLink } from '@tabler/icons-react' ;
1313import { formatCurrency } from "../../../../../../utilites/currency.ts" ;
14+ import { showSuccess } from "../../../../../../utilites/notifications.tsx" ;
1415
1516interface FeePlanDisplayProps {
1617 configuration ?: {
@@ -45,26 +46,30 @@ const FeePlanDisplay = ({configuration}: FeePlanDisplayProps) => {
4546 < Card variant = { 'lightGray' } >
4647 < Title order = { 4 } > { configuration . name } </ Title >
4748 < Grid >
48- < Grid . Col span = { { base : 12 , sm : 6 } } >
49- < Group gap = "xs" wrap = { 'nowrap' } >
50- < Text size = "sm" >
51- { t `Transaction Fee:` } { ' ' }
52- < Text span fw = { 600 } >
53- { formatPercentage ( configuration . application_fees . percentage ) }
49+ { configuration . application_fees . percentage > 0 && (
50+ < Grid . Col span = { { base : 12 , sm : 6 } } >
51+ < Group gap = "xs" wrap = { 'nowrap' } >
52+ < Text size = "sm" >
53+ { t `Transaction Fee:` } { ' ' }
54+ < Text span fw = { 600 } >
55+ { formatPercentage ( configuration . application_fees . percentage ) }
56+ </ Text >
5457 </ Text >
55- </ Text >
56- </ Group >
57- </ Grid . Col >
58- < Grid . Col span = { { base : 12 , sm : 6 } } >
59- < Group gap = "xs" wrap = { 'nowrap' } >
60- < Text size = "sm" >
61- { t `Fixed Fee:` } { ' ' }
62- < Text span fw = { 600 } >
63- { formatCurrency ( configuration . application_fees . fixed ) }
58+ </ Group >
59+ </ Grid . Col >
60+ ) }
61+ { configuration . application_fees . fixed > 0 && (
62+ < Grid . Col span = { { base : 12 , sm : 6 } } >
63+ < Group gap = "xs" wrap = { 'nowrap' } >
64+ < Text size = "sm" >
65+ { t `Fixed Fee:` } { ' ' }
66+ < Text span fw = { 600 } >
67+ { formatCurrency ( configuration . application_fees . fixed ) }
68+ </ Text >
6469 </ Text >
65- </ Text >
66- </ Group >
67- </ Grid . Col >
70+ </ Group >
71+ </ Grid . Col >
72+ ) }
6873 </ Grid >
6974 </ Card >
7075
@@ -79,8 +84,16 @@ const FeePlanDisplay = ({configuration}: FeePlanDisplayProps) => {
7984 ) ;
8085} ;
8186
82- const ConnectStatus = ( props : { stripeDetails : StripeConnectDetails } ) => {
87+ const ConnectStatus = ( { account} : { account : Account } ) => {
88+ const [ fetchStripeDetails , setFetchStripeDetails ] = useState ( false ) ;
8389 const [ isReturningFromStripe , setIsReturningFromStripe ] = useState ( false ) ;
90+ const stripeDetailsQuery = useCreateOrGetStripeConnectDetails (
91+ account . id ,
92+ ! ! account ?. stripe_account_id || fetchStripeDetails
93+ ) ;
94+
95+ const stripeDetails = stripeDetailsQuery . data ;
96+ const error = stripeDetailsQuery . error as any ;
8497
8598 useEffect ( ( ) => {
8699 if ( typeof window === 'undefined' ) {
@@ -91,11 +104,40 @@ const ConnectStatus = (props: { stripeDetails: StripeConnectDetails }) => {
91104 ) ;
92105 } , [ ] ) ;
93106
107+ useEffect ( ( ) => {
108+ if ( fetchStripeDetails && ! stripeDetailsQuery . isLoading ) {
109+ setFetchStripeDetails ( false ) ;
110+ showSuccess ( t `Redirecting to Stripe...` ) ;
111+ window . location . href = String ( stripeDetails ?. connect_url ) ;
112+ }
113+
114+ } , [ fetchStripeDetails , stripeDetailsQuery . isFetched ] ) ;
115+
116+ if ( error ?. response ?. status === 403 ) {
117+ return (
118+ < >
119+ < Card className = { classes . tabContent } >
120+ < div className = { paymentClasses . stripeInfo } >
121+ < Group gap = "xs" mb = "md" >
122+ < ThemeIcon size = "lg" radius = "md" variant = "light" >
123+ < IconAlertCircle size = { 20 } />
124+ </ ThemeIcon >
125+ < Title order = { 2 } > { t `Access Denied` } </ Title >
126+ </ Group >
127+ < Text size = "md" >
128+ { error ?. response ?. data ?. message }
129+ </ Text >
130+ </ div >
131+ </ Card >
132+ </ >
133+ ) ;
134+ }
135+
94136 return (
95137 < div className = { paymentClasses . stripeInfo } >
96138 < Title mb = { 10 } order = { 3 } > { t `Payment Processing` } </ Title >
97139
98- { props . stripeDetails ?. is_connect_setup_complete ? (
140+ { stripeDetails ?. is_connect_setup_complete ? (
99141 < >
100142 < Group gap = "xs" mb = "md" >
101143 < ThemeIcon size = "sm" variant = "light" radius = "xl" color = "green" >
@@ -145,12 +187,19 @@ const ConnectStatus = (props: { stripeDetails: StripeConnectDetails }) => {
145187 size = "sm"
146188 leftSection = { < IconBrandStripe size = { 20 } /> }
147189 onClick = { ( ) => {
148- if ( typeof window !== 'undefined' )
149- window . location . href = String ( props . stripeDetails ?. connect_url ) ;
190+ if ( ! stripeDetails ) {
191+ setFetchStripeDetails ( true ) ;
192+ return ;
193+ } else {
194+ if ( typeof window !== 'undefined' ) {
195+ showSuccess ( t `Redirecting to Stripe...` ) ;
196+ window . location . href = String ( stripeDetails ?. connect_url )
197+ }
198+ }
150199 } }
151200 >
152- { ( ! isReturningFromStripe ) && t `Connect with Stripe` }
153- { ( isReturningFromStripe ) && t `Complete Stripe Setup` }
201+ { ( ! isReturningFromStripe && ! account ?. stripe_account_id ) && t `Connect with Stripe` }
202+ { ( isReturningFromStripe || account ?. stripe_account_id ) && t `Complete Stripe Setup` }
154203 </ Button >
155204 < Group gap = "xs" >
156205 < Anchor
@@ -184,29 +233,6 @@ const ConnectStatus = (props: { stripeDetails: StripeConnectDetails }) => {
184233
185234const PaymentSettings = ( ) => {
186235 const accountQuery = useGetAccount ( ) ;
187- const stripeDetailsQuery = useCreateOrGetStripeConnectDetails ( accountQuery . data ?. id ) ;
188- const stripeDetails = stripeDetailsQuery . data ;
189- const error = stripeDetailsQuery . error as any ;
190-
191- if ( error ?. response ?. status === 403 ) {
192- return (
193- < >
194- < Card className = { classes . tabContent } >
195- < div className = { paymentClasses . stripeInfo } >
196- < Group gap = "xs" mb = "md" >
197- < ThemeIcon size = "lg" radius = "md" variant = "light" >
198- < IconAlertCircle size = { 20 } />
199- </ ThemeIcon >
200- < Title order = { 2 } > { t `Access Denied` } </ Title >
201- </ Group >
202- < Text size = "md" >
203- { error ?. response ?. data ?. message }
204- </ Text >
205- </ div >
206- </ Card >
207- </ >
208- ) ;
209- }
210236
211237 return (
212238 < >
@@ -216,10 +242,12 @@ const PaymentSettings = () => {
216242 />
217243 < Card className = { classes . tabContent } >
218244 < LoadingMask />
219- { ( accountQuery . data ?. configuration || stripeDetails ) && (
245+ { ( accountQuery . data ?. configuration ) && (
220246 < Grid gutter = "xl" >
221247 < Grid . Col span = { { base : 12 , md : 6 } } >
222- { stripeDetails && < ConnectStatus stripeDetails = { stripeDetails } /> }
248+ { accountQuery . isFetched && (
249+ < ConnectStatus account = { accountQuery . data } />
250+ ) }
223251 </ Grid . Col >
224252 < Grid . Col span = { { base : 12 , md : 6 } } >
225253 { accountQuery . data ?. configuration && (
0 commit comments