diff --git a/packages/libs/web-common/src/controllers/PaymentController.tsx b/packages/libs/web-common/src/controllers/PaymentController.tsx
index a1c7dd7138..61f577a9a9 100644
--- a/packages/libs/web-common/src/controllers/PaymentController.tsx
+++ b/packages/libs/web-common/src/controllers/PaymentController.tsx
@@ -9,6 +9,8 @@ interface AutoSubmitFormProps {
params: any;
}
+type ErrorKey = 'amount' | 'invoiceNumber' | 'general';
+
function AutoSubmitForm(props: AutoSubmitFormProps) {
// submit form as soon as it is rendered
const formRef = useRef
Do not use commas for decimals.
>
- );
- setIsSubmitting(false);
- } else {
- setErrorMessage('');
- // console.log('Submitting form with payment amount $' + amountNum.toFixed(2));
+ ),
+ }));
- // optionally update UI with trimmed amount
- // (will only be visible for a short time, so potentially panic-inducing?)
- // setAmount(amountNum.toFixed(2));
+ if (amountIsValid && invoiceNumberIsValid) {
+ // submit to our service
+ // clear all errors including 'general'
+ setErrors({});
- getFormData(amountNum.toFixed(2))
+ // console.log('Submitting form with payment amount $' + amountNum.toFixed(2));
+ setIsSubmitting(true);
+ getFormData(amountNum.toFixed(2), invoiceNumber)
.then((formData) => {
setFormData(formData);
})
.catch((error) => {
console.error(error);
- setErrorMessage(
- <>
- Cannot connect to payment system.
- Please{' '}
-
- let us know
- {' '}
- about this.
- >
- );
+ setErrors((errors) => ({
+ ...errors,
+ general: (
+ <>
+ Cannot connect to payment system.
+ Please{' '}
+
+ let us know
+ {' '}
+ about this.
+ >
+ ),
+ }));
setIsSubmitting(false);
});
}
@@ -123,19 +158,41 @@ export default function PaymentController() {
{errorMessage}
+{errors.amount}
- Please enter the amount from your invoice in USD: - setAmount(e.target.value)} - /> -
+ +{errors.invoiceNumber}
+{errors.general}
+* indicates required field
(Clicking the button will take you to secure.cybersource.com.)
diff --git a/packages/libs/web-common/src/styles/Payment.scss b/packages/libs/web-common/src/styles/Payment.scss index 4cc78e7ac1..329aa8947d 100644 --- a/packages/libs/web-common/src/styles/Payment.scss +++ b/packages/libs/web-common/src/styles/Payment.scss @@ -11,19 +11,50 @@ div.payment-container { margin-top: 3.5em; text-align: center; - div.amount { - p { - font-size: 142%; + div.form-row { + display: flex; + flex-direction: row; + justify-content: space-between; + width: 20em; + margin-left: auto; + margin-right: auto; + align-items: center; + margin-bottom: 1em; + font-size: 1.5em; + + label { + margin-bottom: 0.3em; + } + + &.optional input { + border: 1px solid #eee !important; + + &::placeholder { + color: #666; + } + } - input { - width: 5em; + input { + padding: 0.4em; + width: 12em; + border-radius: 0.25em; + border: 1px solid #666 !important; - &.hasError { - border: 0.5px solid red !important; - } + &.hasError { + border: 0.5px solid red !important; /* more important than the .optional grey */ } } + + input#amount { + text-align: right; + width: 6em; + } + + &.optional label { + color: #666; + } } + div.button { input { width: 12em;