UNPKG

@equinor/mad-core

Version:

Core library for the Mobile App Delivery team

106 lines (103 loc) 3.76 kB
import { useNavigateFromLoginScreen } from "./chunk-6RPJUHBL.js"; import { getConfig, useAuthConfig, useDictionary, useLoginScreenConfig } from "./chunk-GEEFQMRN.js"; import { __spreadProps, __spreadValues } from "./chunk-CWMXXUWU.js"; // src/components/screens/LoginScreen.tsx import { Button, EDSProvider, EDSStyleSheet, useStyles } from "@equinor/mad-components"; import React, { useState } from "react"; import { Image, Platform, Pressable, View } from "react-native"; import { ExpoAuthSession, LoginButton } from "@equinor/mad-auth"; import { metricKeys, metricStatus, setUsername, track } from "@equinor/mad-insights"; var LoginScreen = ({ onAuthenticationSuccessful, onAuthenticationFailed }) => { var _a, _b; const dictionary = useDictionary(); const authConfig = useAuthConfig(); const navigate = useNavigateFromLoginScreen(); const { splash, backgroundColor } = useLoginScreenConfig(); const styles = useStyles(theme, backgroundColor); const [demoPressCount, setDemoPressCount] = useState(0); const shouldDisplayDemoButton = demoPressCount >= 5; const resizeMode = Platform.OS === "web" ? "contain" : "cover"; const loginButtonProps = __spreadProps(__spreadValues({}, authConfig), { onAuthenticationSuccessful: (result, type) => { setUsername(result.account.username, result.account.identifier); if (type === "AUTOMATIC") { void track(metricKeys.AUTHENTICATION_AUTOMATIC); } else { void track(metricKeys.AUTHENTICATION, metricStatus.SUCCESS); } onAuthenticationSuccessful == null ? void 0 : onAuthenticationSuccessful(result, type); navigate({ demoMode: false }); }, onAuthenticationFailed: (error) => { void track(metricKeys.AUTHENTICATION, metricStatus.FAILED, void 0, { error }); onAuthenticationFailed == null ? void 0 : onAuthenticationFailed(error); }, title: dictionary.login.logIn, enableAutomaticAuthentication: true, scopes: (_a = authConfig.scopes) != null ? _a : [] }); return /* @__PURE__ */ React.createElement(EDSProvider, { colorScheme: "light", density: "tablet" }, /* @__PURE__ */ React.createElement(View, { style: styles.container }, /* @__PURE__ */ React.createElement(Image, { source: splash, resizeMode, style: styles.fill }), /* @__PURE__ */ React.createElement(View, { style: styles.secretHitboxContainer }, /* @__PURE__ */ React.createElement( Pressable, { testID: "enable-demo-button", style: styles.fill, onPress: () => setDemoPressCount((count) => count + 1) } )), /* @__PURE__ */ React.createElement(View, { style: styles.buttonContainer }, ((_b = getConfig().experimental) == null ? void 0 : _b.useExpoAuthSession) ? /* @__PURE__ */ React.createElement(ExpoAuthSession.LoginButton, __spreadValues({}, loginButtonProps)) : /* @__PURE__ */ React.createElement(LoginButton, __spreadValues({}, loginButtonProps)), shouldDisplayDemoButton && /* @__PURE__ */ React.createElement( Button, { testID: "demo-button", title: dictionary.login.demo, variant: "outlined", onPress: () => { void track(metricKeys.AUTHENTICATION_DEMO); navigate({ demoMode: true }); } } )))); }; var theme = EDSStyleSheet.create((_, backgroundColor) => ({ container: { flex: 1, backgroundColor: backgroundColor != null ? backgroundColor : "#E6FAEC" }, secretHitboxContainer: { position: "absolute", top: 0, height: "55%", width: "100%", alignItems: "center" }, buttonContainer: { position: "absolute", top: "60%", width: "100%", alignItems: "center", gap: 8 }, fill: { width: "100%", height: "100%" } })); export { LoginScreen };