Skip to content

Commit

Permalink
remove buttons when adding/updating a card (#1902)
Browse files Browse the repository at this point in the history
Co-authored-by: Tanmoy Basak Anjan <tanmoy3399@gmail.com>
  • Loading branch information
Tbaut and tanmoyAtb authored Feb 2, 2022
1 parent cd39d76 commit ed85d79
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ interface IPaymentMethodProps {
const PaymentMethodSelector = ({ selectedProductPrice, goBack, onSelectPaymentMethod }: IPaymentMethodProps) => {
const classes = useStyles()
const [paymentMethod, setPaymentMethod] = useState<"creditCard" | "crypto" | undefined>()
const [view, setView] = useState<"selectPaymentMethod" | "addCard">("selectPaymentMethod")
const [isCardFormOpen, setIsCardFormOpen] = useState(false)
const { defaultCard } = useBilling()

useEffect(() => {
Expand All @@ -110,10 +110,10 @@ const PaymentMethodSelector = ({ selectedProductPrice, goBack, onSelectPaymentMe
component="p"
className={classes.subHeading}
>
{view === "addCard" && <Trans>This card will become your default payment method</Trans>}
{isCardFormOpen && <Trans>This card will become your default payment method</Trans>}
</Typography>
<Divider className={classes.divider} />
{view === "selectPaymentMethod" && <>
{!isCardFormOpen && <>
<div className={classes.rowBox}>
<RadioInput
label={defaultCard ? `•••• •••• •••• ${defaultCard.last_four_digit}` : "Credit card"}
Expand All @@ -128,7 +128,7 @@ const PaymentMethodSelector = ({ selectedProductPrice, goBack, onSelectPaymentMe
variant="body1"
component="p"
className={classes.textButton}
onClick={() => setView("addCard")}
onClick={() => setIsCardFormOpen(true)}
data-cy={defaultCard ? "text-button-update-card" : "text-button-add-card"}
>
{defaultCard
Expand All @@ -149,17 +149,16 @@ const PaymentMethodSelector = ({ selectedProductPrice, goBack, onSelectPaymentMe
/>
</>
}
{view === "addCard" && <div className={classes.addCardWrapper}>
{isCardFormOpen && <div className={classes.addCardWrapper}>
<AddCard
submitText={t`Use this card`}
footerClassName={classes.footer}
onCardAdd={() => setView("selectPaymentMethod")}
goBack={() => setView("selectPaymentMethod")}
onCardAdd={() => setIsCardFormOpen(false)}
goBack={() => setIsCardFormOpen(false)}
/>
</div>
}
<Divider className={classes.divider} />
<section className={classes.bottomSection}>
{!isCardFormOpen && <section className={classes.bottomSection}>
<div className={classes.buttons}>
<Button
onClick={goBack}
Expand All @@ -170,14 +169,14 @@ const PaymentMethodSelector = ({ selectedProductPrice, goBack, onSelectPaymentMe
</Button>
<Button
variant="primary"
disabled={!paymentMethod || view === "addCard"}
disabled={!paymentMethod}
onClick={() => paymentMethod && onSelectPaymentMethod(paymentMethod)}
testId="select-payment-method"
>
<Trans>Select payment method</Trans>
</Button>
</div>
</section>
</section>}
</article>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { FormEvent, useMemo, useState } from "react"
import { Button, Grid, Typography, useToasts } from "@chainsafe/common-components"
import { Button, Typography, useToasts } from "@chainsafe/common-components"
import { createStyles, makeStyles, useTheme, useThemeSwitcher } from "@chainsafe/common-theme"
import { CSFTheme } from "../../../../../Themes/types"
import CustomButton from "../../../../Elements/CustomButton"
import { t, Trans } from "@lingui/macro"
import { useStripe,
import {
useStripe,
useElements,
CardNumberElement,
CardExpiryElement,
Expand Down Expand Up @@ -61,14 +62,14 @@ const useStyles = makeStyles(
marginTop: constants.generalUnit * 2,
color: palette.error.main
},
backButton: {
flex: 1,
buttons: {
display: "flex",
alignItems: "center"
},
linkButton: {
textDecoration: "underline",
cursor: "pointer"
flexDirection: "row",
alignItems: "center",
justifyContent: "flex-end",
"& > *": {
marginLeft: constants.generalUnit
}
}
})
}
Expand Down Expand Up @@ -168,7 +169,8 @@ const AddCard = ({ onClose, onCardAdd, footerClassName, submitText, goBack }: IA
color: theme.constants.addCard.placeholderColor
}
}
} }}
}
}}
onFocus={() => setFocusElement("number")}
onBlur={() => setFocusElement(undefined)}
onChange={() => setCardAddError(undefined)}
Expand All @@ -191,7 +193,8 @@ const AddCard = ({ onClose, onCardAdd, footerClassName, submitText, goBack }: IA
color: theme.constants.addCard.placeholderColor
}
}
} }}
}
}}
/>
<CardCvcElement
id="iframe-card-cvc"
Expand All @@ -210,7 +213,8 @@ const AddCard = ({ onClose, onCardAdd, footerClassName, submitText, goBack }: IA
color: theme.constants.addCard.placeholderColor
}
}
} }}
}
}}
/>
</div>
{cardAddError && <Typography
Expand All @@ -222,23 +226,15 @@ const AddCard = ({ onClose, onCardAdd, footerClassName, submitText, goBack }: IA
{cardAddError}
</Typography>
}
<Grid
item
flexDirection="row"
className={footerClassName}
>
<div className={classes.backButton}>
{goBack &&
<Typography
variant="body1"
component="p"
onClick={goBack}
className={classes.linkButton}
>
<Trans>Go back</Trans>
</Typography>
}
</div>
<div className={clsx(classes.buttons, footerClassName)} >
{goBack &&
<Button
variant="text"
onClick={goBack}
>
<Trans>Go back</Trans>
</Button>
}
{onClose &&
<CustomButton
onClick={onClose}
Expand All @@ -262,7 +258,7 @@ const AddCard = ({ onClose, onCardAdd, footerClassName, submitText, goBack }: IA
>
{submitText}
</Button>
</Grid>
</div>
</div>
</form>
)
Expand Down

0 comments on commit ed85d79

Please sign in to comment.