Improve SSO display on login page (#150)
authorZalax <contact@zalax.xyz>
Wed, 27 Oct 2021 13:39:35 +0000 (15:39 +0200)
committerGitHub <noreply@github.com>
Wed, 27 Oct 2021 13:39:35 +0000 (19:09 +0530)
sort SSO providers by alphabetical order, and reset provider list on homeserver change (to avoid having them if the homeserver is invalid)

src/app/molecules/sso-buttons/SSOButtons.jsx

index 47d001c7163755e9c5e3ba902f473a0c9aa1a0f6..af6cb927acdf87972f9e4af9854c77d0f1962b6b 100644 (file)
@@ -10,6 +10,9 @@ function SSOButtons({ homeserver }) {
   const [identityProviders, setIdentityProviders] = useState([]);
 
   useEffect(() => {
+    // Reset sso proviers to avoid displaying sso icons if the homeserver is not valid
+    setIdentityProviders([]);
+
     // If the homeserver passed in is not a fully-qualified domain name, do not update.
     if (!homeserver.match('^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\\.[a-zA-Z]{2,})+$')) {
       return;
@@ -49,16 +52,19 @@ function SSOButtons({ homeserver }) {
         <Text>OR</Text>
       </div>
       <div className="sso-buttons__container">
-        {identityProviders.sort((idp) => !!idp.imageSrc).map((idp) => (
-          <SSOButton
-            key={idp.id}
-            homeserver={idp.homeserver}
-            id={idp.id}
-            name={idp.name}
-            type={idp.type}
-            imageSrc={idp.imageSrc}
-          />
-        ))}
+        {identityProviders
+          // Sort by alphabetical order
+          .sort((idp, idp2) => !!idp.imageSrc && idp.name > idp2.name)
+          .map((idp) => (
+            <SSOButton
+              key={idp.id}
+              homeserver={idp.homeserver}
+              id={idp.id}
+              name={idp.name}
+              type={idp.type}
+              imageSrc={idp.imageSrc}
+            />
+          ))}
       </div>
     </div>
   );