From b7e2d3e0a7d96770991a849f193ac6464aaa879c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 11 Aug 2022 19:38:09 -0500 Subject: [PATCH] Add inert oauth consumer buttons --- .../auth_login/components/consumer-button.tsx | 46 +++++++++++++++++++ .../auth_login/components/login_form.tsx | 19 ++++++-- 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 app/soapbox/features/auth_login/components/consumer-button.tsx diff --git a/app/soapbox/features/auth_login/components/consumer-button.tsx b/app/soapbox/features/auth_login/components/consumer-button.tsx new file mode 100644 index 0000000000..63ca9d3df0 --- /dev/null +++ b/app/soapbox/features/auth_login/components/consumer-button.tsx @@ -0,0 +1,46 @@ +import React from 'react'; +import { useIntl, defineMessages } from 'react-intl'; + +import { IconButton, Tooltip } from 'soapbox/components/ui'; + +const messages = defineMessages({ + tooltip: { id: 'oauth_consumer.tooltip', defaultMessage: 'Sign in with {provider}' }, +}); + +/** Map between OAuth providers and brand icons. */ +const BRAND_ICONS: Record = { + twitter: require('@tabler/icons/brand-twitter.svg'), + facebook: require('@tabler/icons/brand-facebook.svg'), + google: require('@tabler/icons/brand-google.svg'), + microsoft: require('@tabler/icons/brand-windows.svg'), + slack: require('@tabler/icons/brand-slack.svg'), + github: require('@tabler/icons/brand-github.svg'), +}; + +/** Capitalize the first letter of a string. */ +// https://stackoverflow.com/a/1026087 +function capitalize(str: string) { + return str.charAt(0).toUpperCase() + str.slice(1); +} + +interface IConsumerButton { + provider: string, +} + +/** OAuth consumer button for logging in with a third-party service. */ +const ConsumerButton: React.FC = ({ provider }) => { + const intl = useIntl(); + const icon = BRAND_ICONS[provider] || require('@tabler/icons/key.svg'); + + return ( + + + + ); +}; + +export default ConsumerButton; diff --git a/app/soapbox/features/auth_login/components/login_form.tsx b/app/soapbox/features/auth_login/components/login_form.tsx index 9e8b1dc357..44b8e6df5b 100644 --- a/app/soapbox/features/auth_login/components/login_form.tsx +++ b/app/soapbox/features/auth_login/components/login_form.tsx @@ -1,8 +1,12 @@ +import { List as ImmutableList } from 'immutable'; import React from 'react'; import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; import { Link } from 'react-router-dom'; -import { Button, Form, FormActions, FormGroup, Input } from 'soapbox/components/ui'; +import { Button, Form, FormActions, FormGroup, HStack, Input, Stack } from 'soapbox/components/ui'; +import { useAppSelector } from 'soapbox/hooks'; + +import ConsumerButton from './consumer-button'; const messages = defineMessages({ username: { @@ -22,6 +26,7 @@ interface ILoginForm { const LoginForm: React.FC = ({ isLoading, handleSubmit }) => { const intl = useIntl(); + const providers = useAppSelector(state => ImmutableList(state.instance.pleroma.get('oauth_consumer_strategies'))); return (
@@ -29,7 +34,7 @@ const LoginForm: React.FC = ({ isLoading, handleSubmit }) => {

-
+
= ({ isLoading, handleSubmit }) => { -
+ + {(providers.size > 0) && ( + + {providers.map(provider => ( + + ))} + + )} + ); };