Skip to content

Commit

Permalink
fix: replace inline destructure of apiResponse w conditional key opti…
Browse files Browse the repository at this point in the history
…on-chain check
  • Loading branch information
trevor-anderson committed May 18, 2023
1 parent a1e128d commit a346969
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/pages/CheckoutPage/CheckoutForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@ import type { PaymentMethod } from "@stripe/stripe-js";
/**
* Displays a form with a Stripe card input.
*/
export const CheckoutForm = ({
onCompleteCheckout,
}: {
onCompleteCheckout: (success: boolean) => Promise<void>;
}) => {
export const CheckoutForm = ({ onCompleteCheckout }: CheckoutFormProps) => {
const { selectedSubscription, promoCode } = checkoutValuesStore.useSubToStore() as CheckoutValues;
const { submitPaymentForSubscription } = useStripeService();

const handleSubmit = async (paymentMethod: PaymentMethod) => {
const { success } = await submitPaymentForSubscription({
const apiResponse = await submitPaymentForSubscription({
selectedSubscription,
paymentMethodID: paymentMethod.id,
...(!!promoCode && { promoCode }),
});

await onCompleteCheckout(success);
await onCompleteCheckout(apiResponse?.success ?? false);
};

return (
Expand All @@ -36,3 +32,7 @@ export const CheckoutForm = ({
/>
);
};

export type CheckoutFormProps = {
onCompleteCheckout: (success: boolean) => Promise<void>;
};
4 changes: 2 additions & 2 deletions src/pages/LoginPage/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const LoginForm = () => {
const nav = useNavigate();

const onSubmit = async (credentials: LoginParams) => {
const { success } = await login(credentials);
if (success) {
const apiResponse = await login(credentials);
if (apiResponse?.success === true) {
toast.success("Welcome back!", { toastId: "login-success" });
nav("/home");
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/RegisterPage/RegisterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export const RegisterForm = () => {

const handleSubmit = async (values: RegisterNewUserParams) => {
// Add "@" prefix to "handle"
const { success } = await registerNewUser({ ...values, handle: `@${values.handle}` });
const apiResponse = await registerNewUser({ ...values, handle: `@${values.handle}` });

if (success) {
if (apiResponse?.success === true) {
/* If the user registered AFTER selecting a subscription from the /products page,
locationState will contain their selectedSub in locationState.sub, which needs to
be provided to the checkout page. If that property does not yet exist, nav to the
Expand Down

0 comments on commit a346969

Please sign in to comment.