From 9ad1874fefa56cca55d876a4df19261a8abc2ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Baumruck?= Date: Thu, 11 Apr 2024 11:17:47 +0200 Subject: [PATCH 1/5] add facebook button and logic --- app.json | 9 ++++ package.json | 3 +- .../FacebookButton/NativeFacebookButton.tsx | 41 +++++++++++++++++++ .../SocialButtons/FacebookButton/index.tsx | 9 ++++ .../molecules/SocialButtons/index.ts | 1 + src/screens/auth/SignInScreen.tsx | 2 + yarn.lock | 13 ++++-- 7 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 src/components/molecules/SocialButtons/FacebookButton/NativeFacebookButton.tsx create mode 100644 src/components/molecules/SocialButtons/FacebookButton/index.tsx diff --git a/app.json b/app.json index 0844c12f..65dde140 100644 --- a/app.json +++ b/app.json @@ -43,6 +43,15 @@ "useFrameworks": "static" } } + ], + [ + "react-native-fbsdk-next", + { + "appID": "974812100702878", + "clientToken": "434baaffa008eb537185c49ff516e3a8", + "displayName": "BACA", + "scheme": "fb974812100702878" + } ] ], "web": { diff --git a/package.json b/package.json index 981bf60f..5646b495 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,8 @@ "react-dom": "18.2.0", "react-hook-form": "^7.49.3", "react-i18next": "^14.0.1", - "react-native": "0.73.5", + "react-native": "0.73.6", + "react-native-fbsdk-next": "^12.1.4", "react-native-gesture-handler": "~2.14.0", "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-notificated": "^0.0.1-beta.2", diff --git a/src/components/molecules/SocialButtons/FacebookButton/NativeFacebookButton.tsx b/src/components/molecules/SocialButtons/FacebookButton/NativeFacebookButton.tsx new file mode 100644 index 00000000..b2c1a3d3 --- /dev/null +++ b/src/components/molecules/SocialButtons/FacebookButton/NativeFacebookButton.tsx @@ -0,0 +1,41 @@ +import { useAuthFacebookControllerLogin } from '@baca/api/query/auth-social/auth-social' +import { isExpoGo, isWeb } from '@baca/constants' +import { assignPushToken, setToken } from '@baca/services' +import { isSignedInAtom, store } from '@baca/store' + +import { SocialButton } from '../SocialButton' + +export const NativeFacebookButton = () => { + const { mutate: loginWithFacebook } = useAuthFacebookControllerLogin() + + if (isExpoGo || isWeb) return null + + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { AccessToken, LoginManager } = require('react-native-fbsdk-next') + + const handleLogin = async () => { + await LoginManager.logInWithPermissions(['email', 'public_profile'], 'enabled') + + const { accessToken } = (await AccessToken.getCurrentAccessToken()) || {} + + accessToken && + loginWithFacebook( + { data: { accessToken } }, + { + onSuccess: async (response) => { + const { user, ...token } = response + if (token) { + await setToken(token) + } + store.set(isSignedInAtom, true) + + // Send push token to backend + await assignPushToken() + }, + } + ) + } + + // eslint-disable-next-line react/jsx-no-bind + return +} diff --git a/src/components/molecules/SocialButtons/FacebookButton/index.tsx b/src/components/molecules/SocialButtons/FacebookButton/index.tsx new file mode 100644 index 00000000..e80b4363 --- /dev/null +++ b/src/components/molecules/SocialButtons/FacebookButton/index.tsx @@ -0,0 +1,9 @@ +import { isExpoGo, isWeb } from '@baca/constants' + +import { NativeFacebookButton } from './NativeFacebookButton' + +export const FacebookButton = () => { + if (isExpoGo || isWeb) return undefined //TODO: Add facebook button for web + + return +} diff --git a/src/components/molecules/SocialButtons/index.ts b/src/components/molecules/SocialButtons/index.ts index e81f3f99..84472267 100644 --- a/src/components/molecules/SocialButtons/index.ts +++ b/src/components/molecules/SocialButtons/index.ts @@ -1,2 +1,3 @@ export * from './GoogleButton' +export * from './FacebookButton' export * from './SocialButton' diff --git a/src/screens/auth/SignInScreen.tsx b/src/screens/auth/SignInScreen.tsx index 7a0c41b7..889ddf88 100644 --- a/src/screens/auth/SignInScreen.tsx +++ b/src/screens/auth/SignInScreen.tsx @@ -1,6 +1,7 @@ import { CompanyLogo, ControlledField, + FacebookButton, FormWrapper, GoogleButton, LanguagePicker, @@ -107,6 +108,7 @@ export const SignInScreen = (): JSX.Element => { + diff --git a/yarn.lock b/yarn.lock index 685d71c9..f7ac0fb6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11485,6 +11485,11 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== +react-native-fbsdk-next@^12.1.4: + version "12.1.4" + resolved "https://registry.yarnpkg.com/react-native-fbsdk-next/-/react-native-fbsdk-next-12.1.4.tgz#b5525df79ca3181f3e1868eb3c7fa316c6297a8d" + integrity sha512-6fC+RTG0kwkZkjO/FYNvva1O60EmmvK/8+ifLmLf+eOHybkjKdcSsnbEk7iODyjZALhyAvDaYYyq27yyJo1X5Q== + react-native-flipper@^0.164.0: version "0.164.0" resolved "https://registry.yarnpkg.com/react-native-flipper/-/react-native-flipper-0.164.0.tgz#64f6269a86a13a72e30f53ba9f5281d2073a7697" @@ -11576,10 +11581,10 @@ react-native-web@~0.19.6: postcss-value-parser "^4.2.0" styleq "^0.1.3" -react-native@0.73.5: - version "0.73.5" - resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.73.5.tgz#724fd1ae8ec8fee1dcf619c82bdd1695d3cff463" - integrity sha512-iHgDArmF4CrhL0qTj+Rn+CBN5pZWUL9lUGl8ub+V9Hwu/vnzQQh8rTMVSwVd2sV6N76KjpE5a4TfIAHkpIHhKg== +react-native@0.73.6: + version "0.73.6" + resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.73.6.tgz#ed4c675e205a34bd62c4ce8b9bd1ca5c85126d5b" + integrity sha512-oqmZe8D2/VolIzSPZw+oUd6j/bEmeRHwsLn1xLA5wllEYsZ5zNuMsDus235ONOnCRwexqof/J3aztyQswSmiaA== dependencies: "@jest/create-cache-key-function" "^29.6.3" "@react-native-community/cli" "12.3.6" From 76d616fc67bb0624ea500623f282d8f07497026c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Baumruck?= Date: Thu, 11 Apr 2024 11:20:35 +0200 Subject: [PATCH 2/5] add back button on not found screen --- src/screens/NotFoundScreen.tsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/screens/NotFoundScreen.tsx b/src/screens/NotFoundScreen.tsx index 488ad025..db9025ac 100644 --- a/src/screens/NotFoundScreen.tsx +++ b/src/screens/NotFoundScreen.tsx @@ -1,5 +1,12 @@ -import { Center, Text } from '@baca/design-system' +import { Box, Button, Text } from '@baca/design-system' import { useScreenOptions, useTranslation } from '@baca/hooks' +import { router } from 'expo-router' +import { StyleSheet } from 'react-native' +import { SafeAreaView } from 'react-native-safe-area-context' + +const navigateToLogin = () => { + router.navigate('/sign-in') +} export const NotFoundScreen = (): JSX.Element => { const { t } = useTranslation() @@ -9,8 +16,15 @@ export const NotFoundScreen = (): JSX.Element => { }) return ( -
- {t('errors.screen_not_found')} -
+ + + {t('errors.screen_not_found')} +