@brightlayer-ui/react-native-auth-workflow
Version:
Re-usable workflow components for Authentication and Registration within Eaton applications.
49 lines (48 loc) • 3.3 kB
JavaScript
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 { OktaAuthContext } from './context';
import { I18nextProvider, useTranslation } from 'react-i18next';
import { ErrorContext } from '../ErrorContext';
import { AuthDictionaries } from '../AuthContext/AuthDictionaries';
import { SharedDictionaries } from '../SharedDictionaries';
import { i18nAuthInstance } from '../AuthContext/i18nAuthInstance';
const OktaAuthContextProviderContent = (props) => {
var _a;
const { children, errorConfig } = props, oktaAuthContextProps = __rest(props, ["children", "errorConfig"]);
const { t } = useTranslation();
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(OktaAuthContext.Provider, { value: Object.assign({}, oktaAuthContextProps) },
React.createElement(ErrorContext.Provider, { value: mergedErrorConfig }, children)));
};
export const OktaAuthContextProvider = (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('zh', 'bluiAuth', AuthDictionaries.english.translation, true, false);
i18n.addResourceBundle('en', 'bluiCommon', SharedDictionaries.english.translation, true, false);
i18n.addResourceBundle('zh', 'bluiAuth', AuthDictionaries.french.translation, true, false);
i18n.addResourceBundle('fr', 'bluiCommon', SharedDictionaries.french.translation, true, false);
i18n.addResourceBundle('zh', 'bluiAuth', AuthDictionaries.portuguese.translation, true, false);
i18n.addResourceBundle('pt', 'bluiCommon', SharedDictionaries.portuguese.translation, true, false);
i18n.addResourceBundle('zh', '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(OktaAuthContextProviderContent, Object.assign({}, other, { language: language }), children)));
};