-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(payment): update payment details
- Loading branch information
1 parent
bb0f745
commit f978779
Showing
23 changed files
with
673 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@use '../../styles/variables'; | ||
@use '../../styles/theme'; | ||
|
||
.backButton { | ||
position: absolute; | ||
top: 16px; | ||
left: 16px; | ||
z-index: 1; | ||
pointer-events: auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import classNames from 'classnames'; | ||
|
||
import IconButton from '../IconButton/IconButton'; | ||
import ArrowLeft from '../../icons/ArrowLeft'; | ||
|
||
import styles from './BackButton.module.scss'; | ||
|
||
type Props = { | ||
className?: string; | ||
onClick: () => void; | ||
}; | ||
|
||
const BackButton: React.FC<Props> = ({ className, onClick }: Props) => { | ||
const { t } = useTranslation('common'); | ||
|
||
return ( | ||
<IconButton onClick={onClick} className={classNames(styles.backButton, className)} aria-label={t('common:back')}> | ||
<ArrowLeft /> | ||
</IconButton> | ||
); | ||
}; | ||
|
||
export default BackButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/components/PaymentMethodForm/PaymentMethodForm.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
@use '../../styles/variables'; | ||
@use '../../styles/theme'; | ||
@use '../../styles/mixins/responsive'; | ||
|
||
|
||
.title { | ||
margin-bottom: 24px; | ||
font-weight: var(--body-font-weight-bold); | ||
font-size: 24px; | ||
} | ||
|
||
.success { | ||
margin-bottom: 12px; | ||
} | ||
|
||
.paymentMethodsInputs { | ||
display: flex; | ||
flex-direction: column; | ||
margin: 0 -4px 24px; | ||
} | ||
|
||
.paymentMethod { | ||
flex: 1; | ||
margin: 6px 4px; | ||
} | ||
|
||
.radio { | ||
position: absolute; | ||
width: 1px; | ||
height: 1px; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
clip: rect(0 0 0 0); | ||
clip-path: inset(50%); | ||
|
||
:focus, | ||
:active { | ||
+ .paymentMethodLabel { | ||
border-color: variables.$white; | ||
} | ||
} | ||
|
||
&:checked + .paymentMethodLabel { | ||
color: variables.$black; | ||
background-color: variables.$white; | ||
border-color: variables.$white; | ||
|
||
svg { | ||
fill: variables.$black; | ||
} | ||
} | ||
} | ||
|
||
.paymentMethodLabel { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
padding: 16px; | ||
font-weight: var(--body-font-weight-bold); | ||
font-size: 24px; | ||
background-color: rgba(variables.$black, 0.34); | ||
border: 1px solid rgba(variables.$white, 0.34); | ||
border-radius: 4px; | ||
cursor: pointer; | ||
transition: border 0.2s ease, background 0.2s ease; | ||
|
||
> svg { | ||
margin-right: 4px; | ||
} | ||
} | ||
|
||
.backButton { | ||
margin-top: 4px; | ||
margin-left: 4px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import styles from './PaymentMethodForm.module.scss'; | ||
|
||
import CreditCard from '#src/icons/CreditCard'; | ||
import PayPal from '#src/icons/PayPal'; | ||
import BackButton from '#components/BackButton/BackButton'; | ||
import Button from '#components/Button/Button'; | ||
import LoadingOverlay from '#components/LoadingOverlay/LoadingOverlay'; | ||
import type { PaymentMethod } from '#types/checkout'; | ||
|
||
type Props = { | ||
paymentMethodId?: number; | ||
onBackButtonClick: () => void; | ||
onCloseButtonClick: () => void; | ||
paymentMethods?: PaymentMethod[]; | ||
onPaymentMethodChange: React.ChangeEventHandler<HTMLInputElement>; | ||
renderPaymentMethod?: () => JSX.Element | null; | ||
submitting: boolean; | ||
updateSuccess: boolean; | ||
}; | ||
|
||
const PaymentMethodForm: React.FC<Props> = ({ | ||
paymentMethodId, | ||
paymentMethods, | ||
onBackButtonClick, | ||
onCloseButtonClick, | ||
onPaymentMethodChange, | ||
renderPaymentMethod, | ||
submitting, | ||
updateSuccess, | ||
}) => { | ||
const { t } = useTranslation('account'); | ||
|
||
const cardPaymentMethod = paymentMethods?.find((method) => method.methodName === 'card'); | ||
const paypalPaymentMethod = paymentMethods?.find((method) => method.methodName === 'paypal'); | ||
|
||
return ( | ||
<> | ||
<h1 className={styles.title}>{t('payment.update_payment_details')}</h1> | ||
{updateSuccess ? ( | ||
<> | ||
<p className={styles.success}>{t('payment.update_payment_success')}</p> | ||
<Button label={t('payment.back_to_profile')} onClick={onCloseButtonClick} color="primary" fullWidth /> | ||
</> | ||
) : ( | ||
<> | ||
<div className={styles.paymentMethodsInputs}> | ||
{cardPaymentMethod ? ( | ||
<div className={styles.paymentMethod}> | ||
<input | ||
className={styles.radio} | ||
type="radio" | ||
name="paymentMethod" | ||
value={cardPaymentMethod.id} | ||
id="card" | ||
checked={paymentMethodId === cardPaymentMethod.id} | ||
onChange={onPaymentMethodChange} | ||
/> | ||
<label className={styles.paymentMethodLabel} htmlFor="card"> | ||
<CreditCard /> | ||
{t('payment.credit_card')} | ||
</label> | ||
</div> | ||
) : null} | ||
{paypalPaymentMethod ? ( | ||
<div className={styles.paymentMethod}> | ||
<input | ||
className={styles.radio} | ||
type="radio" | ||
name="paymentMethod" | ||
value={paypalPaymentMethod.id} | ||
id="paypal" | ||
checked={paymentMethodId === paypalPaymentMethod.id} | ||
onChange={onPaymentMethodChange} | ||
/> | ||
<label className={styles.paymentMethodLabel} htmlFor="paypal"> | ||
<PayPal /> {t('payment.paypal')} | ||
</label> | ||
</div> | ||
) : null} | ||
</div> | ||
<div>{renderPaymentMethod ? renderPaymentMethod() : null}</div> | ||
{submitting && <LoadingOverlay transparentBackground inline />} | ||
|
||
<BackButton className={styles.backButton} onClick={onBackButtonClick} /> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default PaymentMethodForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.