From 1def576973f9fc902746c544dc7078bdbfb31660 Mon Sep 17 00:00:00 2001
From: ilkin-overleaf <100852799+ilkin-overleaf@users.noreply.github.com>
Date: Fri, 29 Apr 2022 14:10:10 +0300
Subject: [PATCH] Merge pull request #7808 from overleaf/ii-settings-fixes-1
[SettingsPage] UI Fixes 1
GitOrigin-RevId: 0e0f605191218af4db70a801ff1e50b47f6e0b01
---
.../settings/components/emails-section.tsx | 14 +-
.../settings/components/emails/actions.tsx | 4 +-
.../components/emails/add-email-input.tsx | 38 +++-
.../settings/components/emails/add-email.tsx | 38 ++--
.../components/emails/country-input.tsx | 16 +-
.../components/emails/downshift-input.tsx | 17 +-
.../emails/institution-and-role.tsx | 26 ++-
.../resend-confirmation-email-button.tsx | 5 +-
.../settings/components/emails/row.tsx | 4 +-
.../settings/context/user-email-context.tsx | 3 +-
.../stylesheets/vendor/select/select.css | 170 +++++++++---------
.../emails/emails-section-actions.test.tsx | 4 +-
.../emails-section-add-new-email.test.tsx | 15 +-
.../components/emails/emails-section.test.tsx | 2 +-
14 files changed, 221 insertions(+), 135 deletions(-)
diff --git a/services/web/frontend/js/features/settings/components/emails-section.tsx b/services/web/frontend/js/features/settings/components/emails-section.tsx
index cc010d38e5..9cfdc72d38 100644
--- a/services/web/frontend/js/features/settings/components/emails-section.tsx
+++ b/services/web/frontend/js/features/settings/components/emails-section.tsx
@@ -18,6 +18,7 @@ function EmailsSectionContent() {
state: { data: userEmailsData },
isInitializing,
isInitializingError,
+ isInitializingSuccess,
} = useUserEmailsContext()
const userEmails = Object.values(userEmailsData.byId)
@@ -32,11 +33,13 @@ function EmailsSectionContent() {
-
+ <>
{isInitializing ? (
-
-
{t('loading')}...
+
) : (
<>
@@ -48,14 +51,14 @@ function EmailsSectionContent() {
))}
>
)}
-
+ {isInitializingSuccess &&
}
{isInitializingError && (
{' '}
{t('error_performing_request')}
)}
-
+ >
>
)
}
@@ -73,7 +76,6 @@ function EmailsSection() {
-
>
)
}
diff --git a/services/web/frontend/js/features/settings/components/emails/actions.tsx b/services/web/frontend/js/features/settings/components/emails/actions.tsx
index ef67d3d440..d8ef82ca87 100644
--- a/services/web/frontend/js/features/settings/components/emails/actions.tsx
+++ b/services/web/frontend/js/features/settings/components/emails/actions.tsx
@@ -2,7 +2,6 @@ import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import MakePrimary from './actions/make-primary'
import Remove from './actions/remove'
-import Icon from '../../../../shared/components/icon'
import useAsync from '../../../../shared/hooks/use-async'
import { useUserEmailsContext } from '../../context/user-email-context'
import { UserEmailData } from '../../../../../../types/user-email'
@@ -51,8 +50,7 @@ function Actions({ userEmailData }: ActionsProps) {
/>
{(makePrimaryAsync.isError || deleteEmailAsync.isError) && (
- {' '}
- {t('error_performing_request')}
+ {t('generic_something_went_wrong')}
)}
>
diff --git a/services/web/frontend/js/features/settings/components/emails/add-email-input.tsx b/services/web/frontend/js/features/settings/components/emails/add-email-input.tsx
index 6715ebd8d8..ddb5f0a32b 100644
--- a/services/web/frontend/js/features/settings/components/emails/add-email-input.tsx
+++ b/services/web/frontend/js/features/settings/components/emails/add-email-input.tsx
@@ -4,6 +4,7 @@ import {
useCallback,
useEffect,
useState,
+ forwardRef,
} from 'react'
import { getJSON } from '../../../../infrastructure/fetch-json'
import useAbortController from '../../../../shared/hooks/use-abort-controller'
@@ -38,13 +39,14 @@ export function clearDomainCache() {
type AddEmailInputProps = {
onChange: (value: string, institution?: InstitutionInfo) => void
+ inputRef?: React.ForwardedRef
}
-export function AddEmailInput({ onChange }: AddEmailInputProps) {
+function AddEmailInputBase({ onChange, inputRef }: AddEmailInputProps) {
const { signal } = useAbortController()
- const [suggestion, setSuggestion] = useState(null)
- const [inputValue, setInputValue] = useState(null)
+ const [suggestion, setSuggestion] = useState(null)
+ const [inputValue, setInputValue] = useState(null)
const [matchedInstitution, setMatchedInstitution] =
useState(null)
@@ -52,7 +54,10 @@ export function AddEmailInput({ onChange }: AddEmailInputProps) {
if (inputValue == null) {
return
}
- if (matchedInstitution && suggestion === inputValue) {
+ if (
+ matchedInstitution &&
+ inputValue.endsWith(matchedInstitution.hostname)
+ ) {
onChange(inputValue, matchedInstitution)
} else {
onChange(inputValue)
@@ -103,12 +108,23 @@ export function AddEmailInput({ onChange }: AddEmailInputProps) {
const handleKeyDownEvent = useCallback(
(event: KeyboardEvent) => {
- if (event.key === 'Tab' || event.key === 'Enter') {
+ const setInputValueAndResetSuggestion = () => {
+ setInputValue(suggestion)
+ setSuggestion(null)
+ }
+
+ if (event.key === 'Enter') {
event.preventDefault()
+
if (suggestion) {
- setInputValue(suggestion)
+ setInputValueAndResetSuggestion()
}
}
+
+ if (event.key === 'Tab' && suggestion) {
+ event.preventDefault()
+ setInputValueAndResetSuggestion()
+ }
},
[suggestion]
)
@@ -129,7 +145,17 @@ export function AddEmailInput({ onChange }: AddEmailInputProps) {
onKeyDown={handleKeyDownEvent}
value={inputValue || ''}
placeholder="e.g. johndoe@mit.edu"
+ ref={inputRef}
/>
)
}
+
+const AddEmailInput = forwardRef<
+ HTMLInputElement,
+ Omit