@@ -42,38 +78,78 @@ const PaymentMethodView: FC = () => {
Company (Optional)
-
+
Street and House Number
-
+
Apartment, Suite, Etc. (Optional)
-
+
Country/Region
-
+
Hong Kong
diff --git a/components/checkout/PaymentWidget/PaymentWidget.tsx b/components/checkout/PaymentWidget/PaymentWidget.tsx
index e1892934e..f3e89c730 100644
--- a/components/checkout/PaymentWidget/PaymentWidget.tsx
+++ b/components/checkout/PaymentWidget/PaymentWidget.tsx
@@ -1,26 +1,41 @@
import { FC } from 'react'
import s from './PaymentWidget.module.css'
-import { ChevronRight, CreditCard } from '@components/icons'
+import { ChevronRight, CreditCard, Trash } from '@components/icons'
+import { useUI } from '@components/ui/context'
interface ComponentProps {
onClick?: () => any
}
const PaymentWidget: FC
= ({ onClick }) => {
- /* Shipping Address
- Only available with checkout set to true -
+ const { paymentMethodDetails } = useUI()
+
+ console.log(paymentMethodDetails)
+
+ /* Shipping Address
+ Only available with checkout set to true -
This means that the provider does offer checkout functionality. */
return (
-
- Add Payment Method
-
- {/*
VISA #### #### #### 2345 */}
+
+ {paymentMethodDetails?.paymentMethod ?
+
+ {paymentMethodDetails.address.cardholderName}
+ {paymentMethodDetails.paymentMethod.card.brand.toUpperCase()} **** **** **** {paymentMethodDetails.paymentMethod.card.last4}
+
+ :
+ Add Payment Method
+ }
+
-
+ {paymentMethodDetails?.paymentMethod ?
+
+ :
+
+ }
)
diff --git a/components/common/Layout/Layout.tsx b/components/common/Layout/Layout.tsx
index 736ce3ce6..67276aa8b 100644
--- a/components/common/Layout/Layout.tsx
+++ b/components/common/Layout/Layout.tsx
@@ -84,7 +84,8 @@ const SidebarView: FC<{ sidebarView: string; closeSidebar(): any }> = ({
}
const SidebarUI: FC = () => {
- const { displaySidebar, closeSidebar, sidebarView } = useUI()
+ const { displaySidebar, closeSidebar, sidebarView, paymentMethodDetails } = useUI()
+ console.log("paymentMethodDetails", paymentMethodDetails)
return displaySidebar ? (
) : null
diff --git a/components/ui/context.tsx b/components/ui/context.tsx
index ca2bfd7ed..490761a7a 100644
--- a/components/ui/context.tsx
+++ b/components/ui/context.tsx
@@ -8,15 +8,30 @@ export interface State {
sidebarView: string
modalView: string
userAvatar: string
+ paymentMethodDetails: PAYMENT_METHOD_DETAILS
}
-const initialState = {
+export const initialState = {
displaySidebar: false,
displayDropdown: false,
displayModal: false,
modalView: 'LOGIN_VIEW',
sidebarView: 'CART_VIEW',
userAvatar: '',
+ paymentMethodDetails: {
+ address: {
+ cardholderName: '',
+ firstName: '',
+ lastName: '',
+ company: '',
+ addressLine1: '',
+ addressLine2: '',
+ postalCode: '',
+ city: '',
+ countryOrRegion: '',
+ },
+ paymentMethod: null,
+ },
}
type Action =
@@ -50,6 +65,10 @@ type Action =
type: 'SET_USER_AVATAR'
value: string
}
+ | {
+ type: 'SET_PAYMENT_METHOD_DETAILS',
+ paymentMethodDetails: PAYMENT_METHOD_DETAILS
+ }
type MODAL_VIEWS =
| 'SIGNUP_VIEW'
@@ -60,6 +79,11 @@ type MODAL_VIEWS =
type SIDEBAR_VIEWS = 'CART_VIEW' | 'CHECKOUT_VIEW' | 'PAYMENT_METHOD_VIEW'
+type PAYMENT_METHOD_DETAILS = {
+ address: object,
+ paymentMethod: object,
+}
+
export const UIContext = React.createContext(initialState)
UIContext.displayName = 'UIContext'
@@ -121,6 +145,12 @@ function uiReducer(state: State, action: Action) {
userAvatar: action.value,
}
}
+ case 'SET_PAYMENT_METHOD_DETAILS': {
+ return {
+ ...state,
+ paymentMethodDetails: action.paymentMethodDetails
+ }
+ }
}
}
@@ -180,6 +210,11 @@ export const UIProvider: FC = (props) => {
[dispatch]
)
+ const setPaymentMethodDetails = useCallback(
+ (paymentMethodDetails: PAYMENT_METHOD_DETAILS) => dispatch({ type: 'SET_PAYMENT_METHOD_DETAILS', paymentMethodDetails }),
+ [dispatch]
+ )
+
const value = useMemo(
() => ({
...state,
@@ -192,6 +227,7 @@ export const UIProvider: FC = (props) => {
openModal,
closeModal,
setModalView,
+ setPaymentMethodDetails,
setSidebarView,
setUserAvatar,
}),
diff --git a/framework/reactioncommerce/cart/use-cart.tsx b/framework/reactioncommerce/cart/use-cart.tsx
index 89ce14c70..1881f79c3 100644
--- a/framework/reactioncommerce/cart/use-cart.tsx
+++ b/framework/reactioncommerce/cart/use-cart.tsx
@@ -32,7 +32,7 @@ export const handler: SWRHook<
Object.create(response, {
isEmpty: {
get() {
- return (response.data?.lineItems.length ?? 0) <= 0
+ return (response.data?.lineItems?.length ?? 0) <= 0
},
enumerable: true,
},