import { LinearGradient } from 'expo-linear-gradient'; import { Stack, View, Text, Wrap, Image, Row, Column, ScrollView, useToast } from 'native-base'; import { FunctionComponent } from 'react'; import { Linking, Platform, useWindowDimensions } from 'react-native'; import ButtonBase from './ButtonBase'; import { translate } from '../../i18n/i18n'; import API, { APIError } from '../../API'; import SeparatorBase from './SeparatorBase'; import LinkBase from './LinkBase'; import { useDispatch } from '../../state/Store'; import { setAccessToken } from '../../state/UserSlice'; import useColorScheme from '../../hooks/colorScheme'; import { useAssets } from 'expo-asset'; import APKDownloadButton from '../APKDownloadButton'; const handleGuestLogin = async (apiSetter: (accessToken: string) => void): Promise => { const apiAccess = await API.createAndGetGuestAccount(); apiSetter(apiAccess); return translate('loggedIn'); }; interface ScaffoldAuthProps { title: string; description: string; form: React.ReactNode[]; submitButton: React.ReactNode; link: { text: string; label: string; onPress: () => void }; } const ScaffoldAuth: FunctionComponent = ({ title, description, form, submitButton, link, }) => { const layout = useWindowDimensions(); const dispatch = useDispatch(); const toast = useToast(); const colorScheme = useColorScheme(); const [logo] = useAssets( colorScheme == 'light' ? require('../../assets/icon_light.png') : require('../../assets/icon_dark.png') ); // eslint-disable-next-line @typescript-eslint/no-var-requires const [banner] = useAssets(require('../../assets/banner.jpg')); // eslint-disable-next-line @typescript-eslint/no-var-requires const [googleLogo] = useAssets(require('../../assets/google.png')); return ( Chromacase logo {layout.width > 650 && ( ChromaCase )} { try { handleGuestLogin((accessToken: string) => { dispatch(setAccessToken(accessToken)); }); } catch (error) { if (error instanceof APIError) { toast.show({ description: translate(error.userMessage) }); return; } toast.show({ description: error as string }); } }} /> {title} {description} Linking.openURL(`${API.baseUrl}/auth/login/google`)} /> or {form} {submitButton} {link.label} {Platform.OS === 'web' && } {layout.width > 650 && ( banner page )} {colorScheme === 'dark' && ( )} ); }; export default ScaffoldAuth;