diff --git a/packages/api/src/controllers/user.test.ts b/packages/api/src/controllers/user.test.ts index 7a9827a113..041ed0c39c 100644 --- a/packages/api/src/controllers/user.test.ts +++ b/packages/api/src/controllers/user.test.ts @@ -363,8 +363,9 @@ describe("controllers/user", () => { let req = await client.post(`/user/password/reset-token`, { email: user.email, }); - expect(req.status).toBe(201); + // should return 201 when user email is valid + expect(req.status).toBe(201); const tokens = await db.passwordResetToken.find([ sql`password_reset_token.data->>'userId' = ${userRes.id}`, ]); diff --git a/packages/www/components/PaymentMethod/index.tsx b/packages/www/components/PaymentMethod/index.tsx index 0e7858b985..cb52878ffd 100644 --- a/packages/www/components/PaymentMethod/index.tsx +++ b/packages/www/components/PaymentMethod/index.tsx @@ -5,7 +5,7 @@ import "react-credit-cards/es/styles-compiled.css"; const PaymentMethod = ({ data }) => { return ( - {data && ( + {data?.card && ( { const { user, updateCustomerPaymentMethod } = useApi(); const [status, setStatus] = useState("initial"); + const [errorMessage, setErrorMessage] = useState(""); const stripe = useStripe(); const { register, handleSubmit } = useForm(); const elements = useElements(); @@ -47,6 +49,7 @@ const PaymentMethodDialog = ({ invalidateQuery }) => { const paymentMethod = result.paymentMethod; if (result.error) { setStatus("error"); + setErrorMessage(result.error.message); } else { updateCustomerPaymentMethod({ stripeCustomerId, @@ -54,7 +57,8 @@ const PaymentMethodDialog = ({ invalidateQuery }) => { }) // If the card is declined, display an error to the user. .then((result: any) => { - if (result.error) { + if (result.errors) { + setErrorMessage(result.errors?.[0]?.split("\n")[0]); setStatus("error"); // The card had an error when trying to attach it to a customer. throw result; @@ -64,6 +68,7 @@ const PaymentMethodDialog = ({ invalidateQuery }) => { .then(onPaymentChangeComplete) .catch((error) => { console.log(error); + setStatus("error"); }); } @@ -103,6 +108,10 @@ const PaymentMethodDialog = ({ invalidateQuery }) => { }); }; + useEffect(() => { + setErrorMessage(""); + }, [open]); + return ( setOpen(!open)}> @@ -131,7 +140,18 @@ const PaymentMethodDialog = ({ invalidateQuery }) => { - + {errorMessage && ( + + {errorMessage} + + )} + +