UNPKG

@brightlayer-ui/react-native-auth-workflow

Version:

Re-usable workflow components for Authentication and Registration within Eaton applications.

57 lines (56 loc) 3.51 kB
/** * @packageDocumentation * @module AuthContextProvider */ var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { useEffect } from 'react'; import { AuthContext } from './context'; import { I18nextProvider, useTranslation } from 'react-i18next'; import { i18nAuthInstance } from './i18nAuthInstance'; import { ErrorContext } from '../ErrorContext'; import { AuthDictionaries } from './AuthDictionaries'; import { SharedDictionaries } from '../SharedDictionaries'; const AuthContextProviderContent = (props) => { var _a; const { t } = useTranslation(); const { children, errorConfig } = props, authContextProps = __rest(props, ["children", "errorConfig"]); const mergedErrorConfig = Object.assign(Object.assign({ t: t, title: 'bluiCommon:MESSAGES.ERROR', error: 'bluiAuth:LOGIN.INVALID_CREDENTIALS' }, errorConfig), { dialogConfig: Object.assign({ dismissLabel: 'bluiCommon:ACTIONS.OKAY' }, ((_a = errorConfig === null || errorConfig === void 0 ? void 0 : errorConfig.dialogConfig) !== null && _a !== void 0 ? _a : {})) }); return (React.createElement(AuthContext.Provider, { value: Object.assign({}, authContextProps) }, React.createElement(ErrorContext.Provider, { value: mergedErrorConfig }, children))); }; /** * AuthContextProvider allow you to access shared data / configuration / API definition for authentication screens * @param {AuthContextProviderProps} props - props for Auth Context Provider */ export const AuthContextProvider = (props) => { var _a; const i18nInstance = (_a = props.i18n) !== null && _a !== void 0 ? _a : i18nAuthInstance; const { language, i18n = i18nInstance, children } = props, other = __rest(props, ["language", "i18n", "children"]); if (props.i18n) { i18n.addResourceBundle('zh', 'bluiAuth', AuthDictionaries.chinese.translation, true, false); i18n.addResourceBundle('zh', 'bluiCommon', SharedDictionaries.chinese.translation, true, false); i18n.addResourceBundle('en', 'bluiAuth', AuthDictionaries.english.translation, true, false); i18n.addResourceBundle('en', 'bluiCommon', SharedDictionaries.english.translation, true, false); i18n.addResourceBundle('fr', 'bluiAuth', AuthDictionaries.french.translation, true, false); i18n.addResourceBundle('fr', 'bluiCommon', SharedDictionaries.french.translation, true, false); i18n.addResourceBundle('pt', 'bluiAuth', AuthDictionaries.portuguese.translation, true, false); i18n.addResourceBundle('pt', 'bluiCommon', SharedDictionaries.portuguese.translation, true, false); i18n.addResourceBundle('es', 'bluiAuth', AuthDictionaries.spanish.translation, true, false); i18n.addResourceBundle('es', 'bluiCommon', SharedDictionaries.spanish.translation, true, false); } useEffect(() => { void i18n.changeLanguage(language); }, [i18n, language]); return (React.createElement(I18nextProvider, { i18n: i18n }, React.createElement(AuthContextProviderContent, Object.assign({}, other, { language: language }), children))); };