44 AccordionActions ,
55 AccordionDetails ,
66 AccordionSummary ,
7+ Backdrop ,
78 Button ,
89 CircularProgress ,
910 Divider ,
@@ -71,14 +72,23 @@ const CartItem: React.FC<{
7172 ) ;
7273} ;
7374
75+ type CartStatusStateType = {
76+ openDialog : boolean ;
77+ openBackdrop : boolean ;
78+ } ;
79+
7480export const CartStatus : React . FC < { onPaymentCompleted ?: ( ) => void } > = Suspense . with (
7581 { fallback : < CircularProgress /> } ,
7682 ( { onPaymentCompleted } ) => {
7783 const queryClient = useQueryClient ( ) ;
78- const { language } = ShopHooks . useShopContext ( ) ;
84+ const { language, shopImpAccountId } = ShopHooks . useShopContext ( ) ;
7985 const shopAPIClient = ShopHooks . useShopClient ( ) ;
8086 const cartOrderStartMutation = ShopHooks . usePrepareCartOrderMutation ( shopAPIClient ) ;
8187 const removeItemFromCartMutation = ShopHooks . useRemoveItemFromCartMutation ( shopAPIClient ) ;
88+ const [ state , setState ] = React . useState < CartStatusStateType > ( {
89+ openDialog : false ,
90+ openBackdrop : false ,
91+ } ) ;
8292
8393 const cartIsEmptyStr = language === "ko" ? "장바구니가 비어있어요!" : "Your cart is empty!" ;
8494 const totalPriceStr = language === "ko" ? "총 결제 금액" : "Total Payment Amount" ;
@@ -97,22 +107,32 @@ export const CartStatus: React.FC<{ onPaymentCompleted?: () => void }> = Suspens
97107 : "Failed to complete the cart order.\nPlease try again later.\n" ;
98108
99109 const removeItemFromCart = ( cartProductId : string ) => removeItemFromCartMutation . mutate ( { cartProductId } ) ;
100- const startCartOrder = ( ) =>
101- cartOrderStartMutation . mutate ( undefined , {
110+
111+ const openDialog = ( ) => setState ( ( ps ) => ( { ...ps , openDialog : true } ) ) ;
112+ const closeDialog = ( ) => setState ( ( ps ) => ( { ...ps , openDialog : false } ) ) ;
113+ const openBackdrop = ( ) => setState ( ( ps ) => ( { ...ps , openBackdrop : true } ) ) ;
114+ const closeBackdrop = ( ) => setState ( ( ps ) => ( { ...ps , openBackdrop : false } ) ) ;
115+
116+ const onFormSubmit = ( formData : ShopSchemas . CustomerInfo ) => {
117+ closeDialog ( ) ;
118+ openBackdrop ( ) ;
119+ cartOrderStartMutation . mutate ( formData , {
102120 onSuccess : ( order : ShopSchemas . Order ) => {
103121 ShopUtils . startPortOnePurchase (
122+ shopImpAccountId ,
104123 order ,
105124 ( ) => {
106125 queryClient . invalidateQueries ( ) ;
107126 queryClient . resetQueries ( ) ;
108127 onPaymentCompleted ?.( ) ;
109128 } ,
110129 ( response ) => alert ( failedToOrderStr + response . error_msg ) ,
111- ( ) => { }
130+ closeBackdrop
112131 ) ;
113132 } ,
114133 onError : ( error ) => alert ( error . message || errorWhilePreparingOrderStr ) ,
115134 } ) ;
135+ } ;
116136
117137 const disabled = removeItemFromCartMutation . isPending || cartOrderStartMutation . isPending ;
118138
@@ -125,6 +145,17 @@ export const CartStatus: React.FC<{ onPaymentCompleted?: () => void }> = Suspens
125145 </ Typography >
126146 ) : (
127147 < >
148+ < Backdrop
149+ sx = { ( theme ) => ( { zIndex : theme . zIndex . drawer + 1 } ) }
150+ open = { state . openBackdrop }
151+ onClick = { ( ) => { } }
152+ />
153+ < CommonComponents . CustomerInfoFormDialog
154+ open = { state . openDialog }
155+ closeFunc = { closeDialog }
156+ onSubmit = { onFormSubmit }
157+ defaultValue = { data . customer_info }
158+ />
128159 { data . products . map ( ( prodRel ) => (
129160 < CartItem
130161 language = { language }
@@ -139,7 +170,7 @@ export const CartStatus: React.FC<{ onPaymentCompleted?: () => void }> = Suspens
139170 < Typography variant = "h6" sx = { { textAlign : "end" } } >
140171 { totalPriceStr } : < CommonComponents . PriceDisplay price = { data . first_paid_price } />
141172 </ Typography >
142- < Button variant = "contained" color = "secondary" onClick = { startCartOrder } disabled = { disabled } >
173+ < Button variant = "contained" color = "secondary" onClick = { openDialog } disabled = { disabled } >
143174 { orderCartStr }
144175 </ Button >
145176 </ >
0 commit comments