diff --git a/frontend/src/components/AddEmailForm.tsx b/frontend/src/components/AddEmailForm.tsx index e8c413fcf..cf561eb59 100644 --- a/frontend/src/components/AddEmailForm.tsx +++ b/frontend/src/components/AddEmailForm.tsx @@ -12,15 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Control, Field, Root, Submit } from "@vector-im/compound-web"; +import { + Alert, + Control, + Field, + Label, + Root, + Submit, +} from "@vector-im/compound-web"; import { useAtom } from "jotai"; import { atomWithMutation } from "jotai-urql"; import { useRef, useTransition } from "react"; import { graphql } from "../gql"; -import Typography from "./Typography"; - const ADD_EMAIL_MUTATION = graphql(/* GraphQL */ ` mutation AddEmail($userId: ID!, $email: String!) { addEmail(input: { userId: $userId, email: $email }) { @@ -40,6 +45,7 @@ const AddEmailForm: React.FC<{ onAdd?: (id: string) => void; }> = ({ userId, onAdd }) => { const formRef = useRef(null); + const fieldRef = useRef(null); const [addEmailResult, addEmail] = useAtom(addUserEmailAtom); const [pending, startTransition] = useTransition(); @@ -50,8 +56,10 @@ const AddEmailForm: React.FC<{ const email = formData.get("email") as string; startTransition(() => { addEmail({ userId, email }).then((result) => { - // Don't clear the form if the email was invalid - if (result.data?.addEmail.status === "INVALID") { + // Don't clear the form if the email was invalid or already exists + if (result.data?.addEmail.status !== "ADDED") { + fieldRef.current?.focus(); + fieldRef.current?.select(); return; } @@ -69,35 +77,27 @@ const AddEmailForm: React.FC<{ }; const status = addEmailResult.data?.addEmail.status ?? null; - const emailAdded = status === "ADDED"; const emailExists = status === "EXISTS"; const emailInvalid = status === "INVALID"; return ( <> - {emailAdded && ( -
- Email added! -
- )} + + {emailExists && ( + + The entered email is already added to this account + + )} - {emailExists && ( -
- Email already exists! -
- )} + {emailInvalid && ( + + The entered email is invalid + + )} - {emailInvalid && ( -
- - Invalid email address - -
- )} - - - - + + + Add diff --git a/frontend/src/pages/Account.tsx b/frontend/src/pages/Account.tsx index 9bd918c40..531a33acc 100644 --- a/frontend/src/pages/Account.tsx +++ b/frontend/src/pages/Account.tsx @@ -21,11 +21,7 @@ import UserEmailList from "../components/UserEmailList"; import { isErr, unwrapErr, unwrapOk } from "../result"; const UserAccount: React.FC<{ id: string }> = ({ id }) => { - return ( -
- -
- ); + return ; }; const CurrentUserAccount: React.FC = () => {