Skip to content

Commit

Permalink
Merge branch 'main' into MNTOR-3465
Browse files Browse the repository at this point in the history
  • Loading branch information
mansaj authored Aug 21, 2024
2 parents 29a31c5 + 46cb9a8 commit 1c1a894
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

"use client";

import { ChangeEvent, useEffect, useState } from "react";
import { ChangeEvent, useEffect, useRef, useState } from "react";
import { useFormState } from "react-dom";
import { useOverlayTriggerState } from "react-stately";
import { useOverlayTrigger } from "react-aria";
Expand Down Expand Up @@ -84,6 +84,7 @@ export const EmailAddressAdder = () => {
const EmailAddressAddForm = () => {
const l10n = useL10n();
const recordTelemetry = useTelemetry();
const formRef = useRef<HTMLFormElement>(null);
const [formState, formAction] = useFormState(onAddEmail, {});
const [hasPressedButton, setHasPressedButton] = useState(false);
const [email, setEmail] = useState("");
Expand All @@ -101,11 +102,7 @@ const EmailAddressAddForm = () => {
};

const isEmailValid = () => {
// Regex for checking email format
// ensuring it contains a local part, an "@" symbol,
// and a domain part.
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
return email.length > 0 && (formRef.current?.reportValidity() ?? false);
};

return !formState.success ? (
Expand All @@ -115,7 +112,11 @@ const EmailAddressAddForm = () => {
total: CONST_MAX_NUM_ADDRESSES,
})}
</p>
<form action={formAction} className={styles.newEmailAddressForm}>
<form
action={formAction}
ref={formRef}
className={styles.newEmailAddressForm}
>
<label htmlFor="newEmailAddress">
{l10n.getString("add-email-address-input-label")}
</label>
Expand All @@ -131,7 +132,9 @@ const EmailAddressAddForm = () => {
className={styles.btn}
disabled={!isEmailValid()}
onPress={() => {
setHasPressedButton(true);
if (isEmailValid()) {
setHasPressedButton(true);
}
}}
isLoading={hasPressedButton}
>
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/client/Confetti.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const Confetti = () => {
if (canvasRef.current) {
confetti = create(canvasRef.current, {
resize: true,
useWorker: true,
useWorker: false,
});

// Confetti options: https://github.com/catdad/canvas-confetti#options
Expand Down

0 comments on commit 1c1a894

Please sign in to comment.