@digitaldefiance/express-suite-react-components 2.1.36 → 2.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/package.json +1 -1
- package/src/auth/Private.js +11 -0
- package/src/auth/PrivateRoute.js +16 -0
- package/src/auth/UnAuthRoute.js +16 -0
- package/src/auth/index.js +6 -0
- package/src/components/ApiAccess.js +67 -0
- package/src/components/BackupCodeLoginForm.js +101 -0
- package/src/components/BackupCodesForm.js +107 -0
- package/src/components/ChangePasswordForm.js +65 -0
- package/src/components/ConfirmationDialog.js +9 -0
- package/src/components/CurrencyCodeSelector.js +30 -0
- package/src/components/CurrencyInput.js +28 -0
- package/src/components/DashboardPage.js +9 -0
- package/src/components/DropdownMenu.js +43 -0
- package/src/components/ExpirationSecondsSelector.js +31 -0
- package/src/components/Flag.js +29 -0
- package/src/components/ForgotPasswordForm.js +53 -0
- package/src/components/LoginForm.js +81 -0
- package/src/components/LogoutPage.js +15 -0
- package/src/components/RegisterForm.js +103 -0
- package/src/components/ResetPasswordForm.js +67 -0
- package/src/components/SideMenu.js +10 -0
- package/src/components/SideMenuListItem.js +38 -0
- package/src/components/TopMenu.js +14 -0
- package/src/components/TranslatedTitle.js +11 -0
- package/src/components/UserLanguageSelector.js +22 -0
- package/src/components/VerifyEmailPage.js +60 -0
- package/src/components/index.js +26 -0
- package/src/contexts/I18nProvider.js +46 -0
- package/src/contexts/ThemeProvider.js +33 -0
- package/src/contexts/index.js +5 -0
- package/src/enumerations/IncludeOnMenu.js +9 -0
- package/src/enumerations/index.js +4 -0
- package/src/hooks/index.js +5 -0
- package/src/hooks/useExpiringValue.js +53 -0
- package/src/hooks/useLocalStorage.js +15 -0
- package/src/index.js +12 -0
- package/src/interfaces/AppConfig.js +2 -0
- package/src/interfaces/IMenuOption.js +2 -0
- package/src/interfaces/index.js +5 -0
- package/src/services/api.js +14 -0
- package/src/services/authenticatedApi.js +18 -0
- package/src/services/index.js +5 -0
- package/src/types/expirationSeconds.js +17 -0
- package/src/types/index.js +5 -0
- package/src/types/translation.js +9 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ForgotPasswordForm = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const formik_1 = require("formik");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const Yup = tslib_1.__importStar(require("yup"));
|
|
10
|
+
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
11
|
+
const contexts_1 = require("../contexts");
|
|
12
|
+
const ForgotPasswordForm = ({ onSubmit, emailValidation, labels = {}, }) => {
|
|
13
|
+
const { t, tComponent } = (0, contexts_1.useI18n)();
|
|
14
|
+
const [success, setSuccess] = (0, react_1.useState)(false);
|
|
15
|
+
const [apiError, setApiError] = (0, react_1.useState)('');
|
|
16
|
+
const validation = {
|
|
17
|
+
email: emailValidation || Yup.string()
|
|
18
|
+
.email(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_InvalidEmail))
|
|
19
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
20
|
+
};
|
|
21
|
+
const translatedLabels = {
|
|
22
|
+
title: labels.title || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.ForgotPassword_Title),
|
|
23
|
+
email: labels.email || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Email),
|
|
24
|
+
sendResetLink: labels.sendResetLink || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.ForgotPassword_SendResetLink),
|
|
25
|
+
successMessage: labels.successMessage || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.PasswordReset_Success),
|
|
26
|
+
};
|
|
27
|
+
const formik = (0, formik_1.useFormik)({
|
|
28
|
+
initialValues: {
|
|
29
|
+
email: '',
|
|
30
|
+
},
|
|
31
|
+
validationSchema: Yup.object({
|
|
32
|
+
email: validation.email,
|
|
33
|
+
}),
|
|
34
|
+
onSubmit: async (values) => {
|
|
35
|
+
try {
|
|
36
|
+
await onSubmit(values);
|
|
37
|
+
setSuccess(true);
|
|
38
|
+
setApiError('');
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
setApiError(error.response?.data?.message || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.ForgotPassword_Error));
|
|
42
|
+
setSuccess(false);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Container, { maxWidth: "sm", children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
47
|
+
mt: 8,
|
|
48
|
+
display: 'flex',
|
|
49
|
+
flexDirection: 'column',
|
|
50
|
+
alignItems: 'center',
|
|
51
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h4", component: "h1", gutterBottom: true, children: translatedLabels.title }), (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "form", onSubmit: formik.handleSubmit, sx: { mt: 1, width: '100%' }, children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, id: "email", name: "email", label: translatedLabels.email, value: formik.values.email, onChange: formik.handleChange, onBlur: formik.handleBlur, error: Boolean(formik.touched.email && formik.errors.email), helperText: formik.touched.email && formik.errors.email, margin: "normal" }), apiError && ((0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", sx: { mt: 2, mb: 2 }, children: apiError })), success && ((0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "success", sx: { mt: 2, mb: 2 }, children: translatedLabels.successMessage })), (0, jsx_runtime_1.jsx)(material_1.Button, { type: "submit", fullWidth: true, variant: "contained", color: "primary", sx: { mt: 3, mb: 2 }, disabled: formik.isSubmitting, children: translatedLabels.sendResetLink })] })] }) }));
|
|
52
|
+
};
|
|
53
|
+
exports.ForgotPasswordForm = ForgotPasswordForm;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoginForm = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const icons_material_1 = require("@mui/icons-material");
|
|
7
|
+
const material_1 = require("@mui/material");
|
|
8
|
+
const formik_1 = require("formik");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const Yup = tslib_1.__importStar(require("yup"));
|
|
11
|
+
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
12
|
+
const contexts_1 = require("../contexts");
|
|
13
|
+
const LoginForm = ({ onSubmit, loginType: initialLoginType = 'email', authType: initialAuthType = 'password', allowLoginTypeToggle = true, allowAuthTypeToggle = true, showForgotPassword = true, showSignUp = true, forgotPasswordLink = '/forgot-password', signUpLink = '/register', emailLabel, usernameLabel, passwordLabel, mnemonicLabel, signInButtonText, forgotPasswordText, signUpText, useUsernameText, useEmailText, useMnemonicText, usePasswordText, toggleVisibilityLabel, titleText, emailValidation, usernameValidation, passwordValidation, mnemonicValidation, additionalFields, additionalInitialValues = {}, additionalValidation = {}, }) => {
|
|
14
|
+
const { t, tComponent } = (0, contexts_1.useI18n)();
|
|
15
|
+
const [loginType, setLoginType] = (0, react_1.useState)(initialLoginType);
|
|
16
|
+
const [authType, setAuthType] = (0, react_1.useState)(initialAuthType);
|
|
17
|
+
const [showSecret, setShowSecret] = (0, react_1.useState)(false);
|
|
18
|
+
// Use translations with fallbacks
|
|
19
|
+
const labels = {
|
|
20
|
+
title: titleText || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Login_Title),
|
|
21
|
+
email: emailLabel || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Email),
|
|
22
|
+
username: usernameLabel || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Username),
|
|
23
|
+
password: passwordLabel || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Password),
|
|
24
|
+
mnemonic: mnemonicLabel || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Mnemonic),
|
|
25
|
+
signIn: signInButtonText || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.SignInButton),
|
|
26
|
+
forgotPassword: forgotPasswordText || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Login_ForgotPassword),
|
|
27
|
+
signUp: signUpText || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Login_SignUp),
|
|
28
|
+
useUsername: useUsernameText || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Login_UseUsername),
|
|
29
|
+
useEmail: useEmailText || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Login_UseEmail),
|
|
30
|
+
useMnemonic: useMnemonicText || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_UseMnemonic),
|
|
31
|
+
usePassword: usePasswordText || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_UsePassword),
|
|
32
|
+
toggleVisibility: toggleVisibilityLabel || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.TogglePasswordVisibility),
|
|
33
|
+
};
|
|
34
|
+
const validation = {
|
|
35
|
+
email: emailValidation || Yup.string()
|
|
36
|
+
.email(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_InvalidEmail))
|
|
37
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
38
|
+
username: usernameValidation || Yup.string()
|
|
39
|
+
.matches(suite_core_lib_1.Constants.UsernameRegex, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_UsernameRegexErrorTemplate))
|
|
40
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
41
|
+
password: passwordValidation || Yup.string()
|
|
42
|
+
.min(1, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required))
|
|
43
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
44
|
+
mnemonic: mnemonicValidation || Yup.string()
|
|
45
|
+
.matches(suite_core_lib_1.Constants.MnemonicRegex, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_InvalidMnemonic))
|
|
46
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
47
|
+
};
|
|
48
|
+
const validationSchema = Yup.object({
|
|
49
|
+
[loginType]: loginType === 'email' ? validation.email : validation.username,
|
|
50
|
+
...(authType === 'mnemonic'
|
|
51
|
+
? { mnemonic: validation.mnemonic }
|
|
52
|
+
: { password: validation.password }),
|
|
53
|
+
...additionalValidation,
|
|
54
|
+
});
|
|
55
|
+
const formik = (0, formik_1.useFormik)({
|
|
56
|
+
initialValues: {
|
|
57
|
+
email: '',
|
|
58
|
+
username: '',
|
|
59
|
+
mnemonic: '',
|
|
60
|
+
password: '',
|
|
61
|
+
...additionalInitialValues,
|
|
62
|
+
},
|
|
63
|
+
validationSchema,
|
|
64
|
+
onSubmit,
|
|
65
|
+
});
|
|
66
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Container, { component: "main", maxWidth: "xs", children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
67
|
+
marginTop: 8,
|
|
68
|
+
display: 'flex',
|
|
69
|
+
flexDirection: 'column',
|
|
70
|
+
alignItems: 'center',
|
|
71
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h1", variant: "h5", children: labels.title }), (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "form", onSubmit: formik.handleSubmit, sx: { mt: 1, width: '100%' }, children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { margin: "normal", fullWidth: true, id: loginType, label: loginType === 'email' ? labels.email : labels.username, name: loginType, autoComplete: loginType === 'email' ? 'email' : 'username', autoFocus: true, value: loginType === 'email' ? formik.values.email : formik.values.username, onChange: formik.handleChange, error: formik.touched[loginType] && Boolean(formik.errors[loginType]), helperText: formik.touched[loginType] && formik.errors[loginType] }), authType === 'password' ? ((0, jsx_runtime_1.jsx)(material_1.TextField, { margin: "normal", required: true, fullWidth: true, name: "password", label: labels.password, id: "password", type: showSecret ? 'text' : 'password', value: formik.values.password, onChange: formik.handleChange, error: formik.touched.password && Boolean(formik.errors.password), helperText: formik.touched.password && formik.errors.password, slotProps: {
|
|
72
|
+
input: {
|
|
73
|
+
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, { position: "end", children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { "aria-label": labels.toggleVisibility, onClick: () => setShowSecret(!showSecret), edge: "end", children: showSecret ? (0, jsx_runtime_1.jsx)(icons_material_1.VisibilityOff, {}) : (0, jsx_runtime_1.jsx)(icons_material_1.Visibility, {}) }) })),
|
|
74
|
+
},
|
|
75
|
+
} })) : ((0, jsx_runtime_1.jsx)(material_1.TextField, { margin: "normal", required: true, fullWidth: true, name: "mnemonic", label: labels.mnemonic, id: "mnemonic", multiline: true, rows: 3, value: formik.values.mnemonic, onChange: formik.handleChange, error: formik.touched.mnemonic && Boolean(formik.errors.mnemonic), helperText: formik.touched.mnemonic && formik.errors.mnemonic, type: showSecret ? 'text' : 'password', slotProps: {
|
|
76
|
+
input: {
|
|
77
|
+
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, { position: "end", children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { "aria-label": labels.toggleVisibility, onClick: () => setShowSecret(!showSecret), edge: "end", children: showSecret ? (0, jsx_runtime_1.jsx)(icons_material_1.VisibilityOff, {}) : (0, jsx_runtime_1.jsx)(icons_material_1.Visibility, {}) }) })),
|
|
78
|
+
},
|
|
79
|
+
} })), additionalFields && additionalFields(formik), (0, jsx_runtime_1.jsx)(material_1.Button, { type: "submit", fullWidth: true, variant: "contained", sx: { mt: 3, mb: 2 }, disabled: formik.isSubmitting, children: labels.signIn }), (showForgotPassword || showSignUp) && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { display: 'flex', justifyContent: 'space-between' }, children: [showForgotPassword && ((0, jsx_runtime_1.jsx)(material_1.Link, { href: forgotPasswordLink, variant: "body2", children: labels.forgotPassword })), showSignUp && ((0, jsx_runtime_1.jsx)(material_1.Link, { href: signUpLink, variant: "body2", children: labels.signUp }))] })), (allowLoginTypeToggle || allowAuthTypeToggle) && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { display: 'flex', gap: 1, mt: 2 }, children: [allowLoginTypeToggle && ((0, jsx_runtime_1.jsx)(material_1.Button, { fullWidth: true, variant: "text", onClick: () => setLoginType(loginType === 'email' ? 'username' : 'email'), children: loginType === 'email' ? labels.useUsername : labels.useEmail })), allowAuthTypeToggle && ((0, jsx_runtime_1.jsx)(material_1.Button, { fullWidth: true, variant: "text", onClick: () => setAuthType(authType === 'password' ? 'mnemonic' : 'password'), children: authType === 'password' ? labels.useMnemonic : labels.usePassword }))] }))] })] }) }));
|
|
80
|
+
};
|
|
81
|
+
exports.LoginForm = LoginForm;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogoutPage = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const LogoutPage = ({ onLogout, onNavigate, redirectTo = '/login' }) => {
|
|
6
|
+
(0, react_1.useEffect)(() => {
|
|
7
|
+
const performLogout = async () => {
|
|
8
|
+
await onLogout();
|
|
9
|
+
onNavigate?.(redirectTo);
|
|
10
|
+
};
|
|
11
|
+
performLogout();
|
|
12
|
+
}, [onLogout, onNavigate, redirectTo]);
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
exports.LogoutPage = LogoutPage;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegisterForm = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const formik_1 = require("formik");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const Yup = tslib_1.__importStar(require("yup"));
|
|
10
|
+
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
11
|
+
const contexts_1 = require("../contexts");
|
|
12
|
+
const RegisterForm = ({ onSubmit, timezones, getInitialTimezone, usernameValidation, emailValidation, timezoneValidation, passwordValidation, confirmPasswordValidation, additionalFields, additionalInitialValues = {}, additionalValidation = {}, labels = {}, }) => {
|
|
13
|
+
const { t, tComponent } = (0, contexts_1.useI18n)();
|
|
14
|
+
const [apiErrors, setApiErrors] = (0, react_1.useState)({});
|
|
15
|
+
const [mnemonic, setMnemonic] = (0, react_1.useState)(null);
|
|
16
|
+
const [usePassword, setUsePassword] = (0, react_1.useState)(true);
|
|
17
|
+
const [registrationSuccess, setRegistrationSuccess] = (0, react_1.useState)(false);
|
|
18
|
+
const [registering, setRegistering] = (0, react_1.useState)(false);
|
|
19
|
+
const validation = {
|
|
20
|
+
username: usernameValidation || Yup.string()
|
|
21
|
+
.min(suite_core_lib_1.Constants.UsernameMinLength, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_UsernameMinLengthTemplate))
|
|
22
|
+
.max(suite_core_lib_1.Constants.UsernameMaxLength, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_UsernameMaxLengthTemplate))
|
|
23
|
+
.matches(suite_core_lib_1.Constants.UsernameRegex, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_UsernameRegexErrorTemplate))
|
|
24
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
25
|
+
email: emailValidation || Yup.string()
|
|
26
|
+
.email(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_InvalidEmail))
|
|
27
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
28
|
+
timezone: timezoneValidation || Yup.string()
|
|
29
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_TimezoneRequired))
|
|
30
|
+
.oneOf(timezones, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_TimezoneInvalid)),
|
|
31
|
+
password: passwordValidation || Yup.string()
|
|
32
|
+
.matches(suite_core_lib_1.Constants.PasswordRegex, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_PasswordRegexErrorTemplate))
|
|
33
|
+
.min(8, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_PasswordMinLengthTemplate))
|
|
34
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
35
|
+
confirmPassword: confirmPasswordValidation || Yup.string()
|
|
36
|
+
.oneOf([Yup.ref('password')], tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_PasswordMatch))
|
|
37
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
38
|
+
};
|
|
39
|
+
const formik = (0, formik_1.useFormik)({
|
|
40
|
+
initialValues: {
|
|
41
|
+
username: '',
|
|
42
|
+
email: '',
|
|
43
|
+
timezone: getInitialTimezone(),
|
|
44
|
+
password: '',
|
|
45
|
+
confirmPassword: '',
|
|
46
|
+
...additionalInitialValues,
|
|
47
|
+
},
|
|
48
|
+
enableReinitialize: true,
|
|
49
|
+
validationSchema: Yup.object({
|
|
50
|
+
username: validation.username,
|
|
51
|
+
email: validation.email,
|
|
52
|
+
timezone: validation.timezone,
|
|
53
|
+
...(usePassword
|
|
54
|
+
? {
|
|
55
|
+
password: validation.password,
|
|
56
|
+
confirmPassword: validation.confirmPassword,
|
|
57
|
+
}
|
|
58
|
+
: {}),
|
|
59
|
+
...additionalValidation,
|
|
60
|
+
}),
|
|
61
|
+
onSubmit: async (values, { setSubmitting, setFieldError, setTouched }) => {
|
|
62
|
+
setRegistering(true);
|
|
63
|
+
const registerResult = await onSubmit(values, usePassword);
|
|
64
|
+
if ('success' in registerResult && registerResult.success) {
|
|
65
|
+
setRegistrationSuccess(true);
|
|
66
|
+
if (!usePassword && registerResult?.mnemonic) {
|
|
67
|
+
setMnemonic(registerResult.mnemonic);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
setRegistrationSuccess(false);
|
|
72
|
+
const newApiErrors = {};
|
|
73
|
+
const fieldsToTouch = {};
|
|
74
|
+
if ('field' in registerResult && registerResult.field) {
|
|
75
|
+
setFieldError(registerResult.field, registerResult.error);
|
|
76
|
+
fieldsToTouch[registerResult.field] = true;
|
|
77
|
+
}
|
|
78
|
+
if ('errors' in registerResult && registerResult.errors) {
|
|
79
|
+
registerResult.errors.forEach((err) => {
|
|
80
|
+
if (err.path && err.msg) {
|
|
81
|
+
setFieldError(err.path, err.msg);
|
|
82
|
+
fieldsToTouch[err.path] = true;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if ('error' in registerResult && registerResult.error && !Object.keys(newApiErrors).length) {
|
|
87
|
+
newApiErrors.general = registerResult.error;
|
|
88
|
+
}
|
|
89
|
+
setApiErrors(newApiErrors);
|
|
90
|
+
setTouched(fieldsToTouch, false);
|
|
91
|
+
}
|
|
92
|
+
setSubmitting(false);
|
|
93
|
+
setRegistering(false);
|
|
94
|
+
setApiErrors({});
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Container, { maxWidth: "sm", children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { mt: 8, display: 'flex', flexDirection: 'column', alignItems: 'center' }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h4", component: "h1", gutterBottom: true, children: labels.title || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Registration) }), (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "form", onSubmit: formik.handleSubmit, sx: { mt: 1, width: '100%' }, children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, id: "username", name: "username", label: labels.username || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Username), value: formik.values.username, onChange: formik.handleChange, onBlur: formik.handleBlur, error: Boolean(formik.touched.username && (formik.errors.username || apiErrors.username)), helperText: formik.touched.username && (formik.errors.username || apiErrors.username), margin: "normal" }), (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, id: "email", name: "email", label: labels.email || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Email), value: formik.values.email, onChange: formik.handleChange, onBlur: formik.handleBlur, error: Boolean(formik.touched.email && (formik.errors.email || apiErrors.email)), helperText: formik.touched.email && (formik.errors.email || apiErrors.email), margin: "normal" }), (0, jsx_runtime_1.jsxs)(material_1.FormControl, { fullWidth: true, margin: "normal", children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, { id: "timezone-label", children: labels.timezone || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Timezone) }), (0, jsx_runtime_1.jsx)(material_1.Select, { labelId: "timezone-label", id: "timezone", name: "timezone", value: formik.values.timezone, onChange: formik.handleChange, onBlur: formik.handleBlur, error: formik.touched.timezone && Boolean(formik.errors.timezone), label: labels.timezone || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Timezone), children: timezones.map((tz) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: tz, children: tz }, tz))) }), formik.touched.timezone && (formik.errors.timezone || apiErrors.timezone) && ((0, jsx_runtime_1.jsx)(material_1.Typography, { color: "error", variant: "caption", children: formik.errors.timezone || apiErrors.timezone }))] }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: { display: 'flex', alignItems: 'center', mt: 2 }, children: (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "text", onClick: () => setUsePassword(!usePassword), children: usePassword
|
|
98
|
+
? labels.useMnemonic || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_UseMnemonic)
|
|
99
|
+
: labels.usePassword || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_UsePassword) }) }), usePassword && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, id: "password", name: "password", label: labels.password || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Password), type: "password", value: formik.values.password, onChange: formik.handleChange, onBlur: formik.handleBlur, error: Boolean(formik.touched.password && formik.errors.password), helperText: formik.touched.password && formik.errors.password, margin: "normal" }), (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, id: "confirmPassword", name: "confirmPassword", label: labels.confirmPassword || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_ConfirmNewPassword), type: "password", value: formik.values.confirmPassword, onChange: formik.handleChange, onBlur: formik.handleBlur, error: Boolean(formik.touched.confirmPassword && formik.errors.confirmPassword), helperText: formik.touched.confirmPassword && formik.errors.confirmPassword, margin: "normal" })] })), additionalFields && additionalFields(formik, usePassword), apiErrors.general && ((0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", sx: { mt: 2, mb: 2 }, children: apiErrors.general })), (0, jsx_runtime_1.jsx)(material_1.Button, { type: "submit", fullWidth: true, variant: "contained", color: "primary", sx: { mt: 3, mb: 2 }, disabled: formik.isSubmitting, children: registering
|
|
100
|
+
? labels.registering || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Registration_Registering)
|
|
101
|
+
: labels.register || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Registration_RegisterButton) }), registering && ((0, jsx_runtime_1.jsxs)(material_1.Alert, { severity: "success", sx: { mt: 2, mb: 2, whiteSpace: 'pre-wrap' }, children: [(0, jsx_runtime_1.jsx)(material_1.AlertTitle, { children: labels.registering || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Registration_Registering) }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", component: "div", children: tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Registration_RegisteringMessage) })] })), mnemonic && ((0, jsx_runtime_1.jsxs)(material_1.Alert, { severity: "success", sx: { mt: 2, mb: 2, whiteSpace: 'pre-wrap' }, children: [(0, jsx_runtime_1.jsx)(material_1.AlertTitle, { children: labels.successTitle || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Registration_SuccessTitle) }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", component: "div", children: [labels.mnemonicSuccess || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Registration_MnemonicSuccess), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body1", component: "div", sx: { mt: 1, fontFamily: 'monospace' }, children: mnemonic }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: { textAlign: 'center' }, children: (0, jsx_runtime_1.jsx)(material_1.Link, { href: "/login", children: labels.proceedToLogin || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.ProceedToLogin) }) })] })] })), registrationSuccess && ((0, jsx_runtime_1.jsxs)(material_1.Alert, { severity: "success", sx: { mt: 2, mb: 2 }, children: [(0, jsx_runtime_1.jsx)(material_1.AlertTitle, { children: labels.successTitle || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Registration_SuccessTitle) }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", component: "div", children: [tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Registration_Success), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: { textAlign: 'center' }, children: (0, jsx_runtime_1.jsx)(material_1.Link, { href: "/login", children: labels.proceedToLogin || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.ProceedToLogin) }) })] })] })), !mnemonic && !registrationSuccess && ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: { textAlign: 'center' }, children: (0, jsx_runtime_1.jsx)(material_1.Link, { href: "/login", variant: "body2", children: labels.loginLink || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Registration_LoginLink) }) }))] })] }) }));
|
|
102
|
+
};
|
|
103
|
+
exports.RegisterForm = RegisterForm;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResetPasswordForm = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const formik_1 = require("formik");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const Yup = tslib_1.__importStar(require("yup"));
|
|
10
|
+
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
11
|
+
const contexts_1 = require("../contexts");
|
|
12
|
+
const ResetPasswordForm = ({ token, onSubmit, passwordValidation, confirmPasswordValidation, labels = {}, }) => {
|
|
13
|
+
const { t, tComponent } = (0, contexts_1.useI18n)();
|
|
14
|
+
const [success, setSuccess] = (0, react_1.useState)(false);
|
|
15
|
+
const [apiError, setApiError] = (0, react_1.useState)('');
|
|
16
|
+
const validation = {
|
|
17
|
+
password: passwordValidation || Yup.string()
|
|
18
|
+
.min(suite_core_lib_1.Constants.PasswordMinLength, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_PasswordMinLengthTemplate))
|
|
19
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
20
|
+
confirmPassword: confirmPasswordValidation || Yup.string()
|
|
21
|
+
.oneOf([Yup.ref('password')], tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_PasswordMatch))
|
|
22
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
23
|
+
};
|
|
24
|
+
const translatedLabels = {
|
|
25
|
+
title: labels.title || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.PasswordReset_Title),
|
|
26
|
+
password: labels.password || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_NewPassword),
|
|
27
|
+
confirmPassword: labels.confirmPassword || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_ConfirmNewPassword),
|
|
28
|
+
resetButton: labels.resetButton || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.PasswordReset_Button),
|
|
29
|
+
successMessage: labels.successMessage || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.PasswordReset_Success),
|
|
30
|
+
invalidToken: labels.invalidToken || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.ForgotPassword_InvalidToken),
|
|
31
|
+
};
|
|
32
|
+
const formik = (0, formik_1.useFormik)({
|
|
33
|
+
initialValues: {
|
|
34
|
+
password: '',
|
|
35
|
+
confirmPassword: '',
|
|
36
|
+
},
|
|
37
|
+
validationSchema: Yup.object({
|
|
38
|
+
password: validation.password,
|
|
39
|
+
confirmPassword: validation.confirmPassword,
|
|
40
|
+
}),
|
|
41
|
+
onSubmit: async (values) => {
|
|
42
|
+
if (!token) {
|
|
43
|
+
setApiError(translatedLabels.invalidToken);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await onSubmit(token, values.password);
|
|
48
|
+
setSuccess(true);
|
|
49
|
+
setApiError('');
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
setApiError(error.response?.data?.message || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Error_PasswordChange));
|
|
53
|
+
setSuccess(false);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
if (!token) {
|
|
58
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Container, { maxWidth: "sm", children: (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", sx: { mt: 4 }, children: translatedLabels.invalidToken }) }));
|
|
59
|
+
}
|
|
60
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Container, { maxWidth: "sm", children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
61
|
+
mt: 8,
|
|
62
|
+
display: 'flex',
|
|
63
|
+
flexDirection: 'column',
|
|
64
|
+
alignItems: 'center',
|
|
65
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h4", component: "h1", gutterBottom: true, children: translatedLabels.title }), (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "form", onSubmit: formik.handleSubmit, sx: { mt: 1, width: '100%' }, children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, id: "password", name: "password", label: translatedLabels.password, type: "password", value: formik.values.password, onChange: formik.handleChange, onBlur: formik.handleBlur, error: Boolean(formik.touched.password && formik.errors.password), helperText: formik.touched.password && formik.errors.password, margin: "normal" }), (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, id: "confirmPassword", name: "confirmPassword", label: translatedLabels.confirmPassword, type: "password", value: formik.values.confirmPassword, onChange: formik.handleChange, onBlur: formik.handleBlur, error: Boolean(formik.touched.confirmPassword && formik.errors.confirmPassword), helperText: formik.touched.confirmPassword && formik.errors.confirmPassword, margin: "normal" }), apiError && ((0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", sx: { mt: 2, mb: 2 }, children: apiError })), success && ((0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "success", sx: { mt: 2, mb: 2 }, children: translatedLabels.successMessage })), (0, jsx_runtime_1.jsx)(material_1.Button, { type: "submit", fullWidth: true, variant: "contained", color: "primary", sx: { mt: 3, mb: 2 }, disabled: formik.isSubmitting, children: translatedLabels.resetButton })] })] }) }));
|
|
66
|
+
};
|
|
67
|
+
exports.ResetPasswordForm = ResetPasswordForm;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SideMenu = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const SideMenuListItem_1 = require("./SideMenuListItem");
|
|
7
|
+
const SideMenu = ({ isOpen, onClose, menuOptions, onNavigate }) => {
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Drawer, { anchor: "left", open: isOpen, onClose: onClose, children: (0, jsx_runtime_1.jsx)(material_1.List, { children: menuOptions.map((item) => ((0, jsx_runtime_1.jsx)(SideMenuListItem_1.SideMenuListItem, { menuItem: item, onClose: onClose, onNavigate: onNavigate }, item.id))) }) }));
|
|
9
|
+
};
|
|
10
|
+
exports.SideMenu = SideMenu;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SideMenuListItem = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const SideMenuListItem = ({ menuItem, onClose, onNavigate, }) => {
|
|
8
|
+
const handleMenuItemClick = (0, react_1.useCallback)((option) => (event) => {
|
|
9
|
+
event.stopPropagation();
|
|
10
|
+
if (option.action) {
|
|
11
|
+
option.action();
|
|
12
|
+
}
|
|
13
|
+
else if (option.link !== undefined && onNavigate) {
|
|
14
|
+
if (typeof option.link === 'string') {
|
|
15
|
+
onNavigate(option.link);
|
|
16
|
+
}
|
|
17
|
+
else if (typeof option.link === 'object' && 'pathname' in option.link && option.link.pathname) {
|
|
18
|
+
onNavigate({ pathname: option.link.pathname, state: option.link.state });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
onClose();
|
|
22
|
+
}, [onNavigate, onClose]);
|
|
23
|
+
if (menuItem.divider) {
|
|
24
|
+
return (0, jsx_runtime_1.jsx)(material_1.Divider, {}, menuItem.label);
|
|
25
|
+
}
|
|
26
|
+
else if (menuItem.link) {
|
|
27
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.ListItemButton, { onClick: handleMenuItemClick(menuItem), children: [menuItem.icon && (0, jsx_runtime_1.jsx)(material_1.ListItemIcon, { children: menuItem.icon }), (0, jsx_runtime_1.jsx)(material_1.ListItemText, { primary: menuItem.label })] }, menuItem.id));
|
|
28
|
+
}
|
|
29
|
+
else if (menuItem.action) {
|
|
30
|
+
const action = menuItem.action;
|
|
31
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.ListItemButton, { onClick: async () => {
|
|
32
|
+
await action();
|
|
33
|
+
onClose();
|
|
34
|
+
}, children: [menuItem.icon && (0, jsx_runtime_1.jsx)(material_1.ListItemIcon, { children: menuItem.icon }), (0, jsx_runtime_1.jsx)(material_1.ListItemText, { primary: menuItem.label })] }, menuItem.id));
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
38
|
+
exports.SideMenuListItem = SideMenuListItem;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TopMenu = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const Menu_1 = tslib_1.__importDefault(require("@mui/icons-material/Menu"));
|
|
7
|
+
const material_1 = require("@mui/material");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const SideMenu_1 = require("./SideMenu");
|
|
10
|
+
const TopMenu = ({ title, logo, logoAlt, isAuthenticated = false, menuOptions, authenticatedButtons, unauthenticatedButtons, rightContent, onNavigate, }) => {
|
|
11
|
+
const [isSideMenuOpen, setIsSideMenuOpen] = (0, react_1.useState)(false);
|
|
12
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.AppBar, { position: "fixed", sx: { top: 10 }, children: [(0, jsx_runtime_1.jsxs)(material_1.Toolbar, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "large", edge: "start", color: "inherit", "aria-label": "menu", sx: { mr: 2 }, onClick: () => setIsSideMenuOpen(true), children: (0, jsx_runtime_1.jsx)(Menu_1.default, {}) }), logo && ((0, jsx_runtime_1.jsx)(material_1.Box, { component: "img", sx: { height: 40, width: 40, marginRight: 2 }, alt: logoAlt || 'Logo', src: logo })), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", component: "div", sx: { flexGrow: 1 }, children: title }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { display: 'flex', alignItems: 'center' }, children: [isAuthenticated ? authenticatedButtons : unauthenticatedButtons, rightContent] })] }), (0, jsx_runtime_1.jsx)(SideMenu_1.SideMenu, { isOpen: isSideMenuOpen, onClose: () => setIsSideMenuOpen(false), menuOptions: menuOptions, onNavigate: onNavigate })] }));
|
|
13
|
+
};
|
|
14
|
+
exports.TopMenu = TopMenu;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TranslatedTitle = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const TranslatedTitle = ({ title, language }) => {
|
|
6
|
+
(0, react_1.useEffect)(() => {
|
|
7
|
+
document.title = title;
|
|
8
|
+
}, [title, language]);
|
|
9
|
+
return null;
|
|
10
|
+
};
|
|
11
|
+
exports.TranslatedTitle = TranslatedTitle;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserLanguageSelector = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const Flag_1 = require("./Flag");
|
|
8
|
+
const UserLanguageSelector = ({ currentLanguage, currentCountryCode, languages, onLanguageChange, }) => {
|
|
9
|
+
const [anchorEl, setAnchorEl] = (0, react_1.useState)(null);
|
|
10
|
+
const handleClick = (event) => {
|
|
11
|
+
setAnchorEl(event.currentTarget);
|
|
12
|
+
};
|
|
13
|
+
const handleClose = () => {
|
|
14
|
+
setAnchorEl(null);
|
|
15
|
+
};
|
|
16
|
+
const handleLanguageChange = (languageCode) => {
|
|
17
|
+
onLanguageChange(languageCode);
|
|
18
|
+
handleClose();
|
|
19
|
+
};
|
|
20
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, { onClick: handleClick, children: (0, jsx_runtime_1.jsx)(Flag_1.Flag, { languageCode: currentLanguage, countryCode: currentCountryCode }) }), (0, jsx_runtime_1.jsx)(material_1.Menu, { anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleClose, children: languages.map((lang) => ((0, jsx_runtime_1.jsxs)(material_1.MenuItem, { onClick: () => handleLanguageChange(lang.code), children: [(0, jsx_runtime_1.jsx)(Flag_1.Flag, { languageCode: lang.code, countryCode: lang.countryCode, sx: { mr: 1 } }), ' ', lang.name] }, lang.code))) })] }));
|
|
21
|
+
};
|
|
22
|
+
exports.UserLanguageSelector = UserLanguageSelector;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VerifyEmailPage = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
8
|
+
const contexts_1 = require("../contexts");
|
|
9
|
+
const VerifyEmailPage = ({ token, onVerify, labels = {}, loginLink = '/login', resendLink = '/resend-verification', }) => {
|
|
10
|
+
const { t, tComponent } = (0, contexts_1.useI18n)();
|
|
11
|
+
const [message, setMessage] = (0, react_1.useState)('');
|
|
12
|
+
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
13
|
+
const [verificationStatus, setVerificationStatus] = (0, react_1.useState)('pending');
|
|
14
|
+
const translatedLabels = {
|
|
15
|
+
title: labels.title || t(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_EmailVerification)),
|
|
16
|
+
success: labels.success || t(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.EmailVerification_Success)),
|
|
17
|
+
failed: labels.failed || t(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.EmailVerification_Failed)),
|
|
18
|
+
noToken: labels.noToken || t(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.NoVerificationTokenProvided)),
|
|
19
|
+
proceedToLogin: labels.proceedToLogin || t(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.ProceedToLogin)),
|
|
20
|
+
contactSupport: labels.contactSupport || t(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.HavingTroubleContactSupport)),
|
|
21
|
+
requestNewEmail: labels.requestNewEmail || t(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.RequestNewVerificationEmail)),
|
|
22
|
+
};
|
|
23
|
+
(0, react_1.useEffect)(() => {
|
|
24
|
+
const verifyEmail = async (verificationToken) => {
|
|
25
|
+
try {
|
|
26
|
+
const result = await onVerify(verificationToken);
|
|
27
|
+
if (result.success) {
|
|
28
|
+
setMessage(result.message || translatedLabels.success);
|
|
29
|
+
setVerificationStatus('success');
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
setMessage(result.message || translatedLabels.failed);
|
|
33
|
+
setVerificationStatus('error');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
setMessage(translatedLabels.failed);
|
|
38
|
+
setVerificationStatus('error');
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
setLoading(false);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
if (token) {
|
|
45
|
+
verifyEmail(token);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
setLoading(false);
|
|
49
|
+
setMessage(translatedLabels.noToken);
|
|
50
|
+
setVerificationStatus('error');
|
|
51
|
+
}
|
|
52
|
+
}, [token, onVerify, translatedLabels]);
|
|
53
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Container, { maxWidth: "sm", children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
54
|
+
mt: 8,
|
|
55
|
+
display: 'flex',
|
|
56
|
+
flexDirection: 'column',
|
|
57
|
+
alignItems: 'center',
|
|
58
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h4", component: "h1", gutterBottom: true, children: translatedLabels.title }), loading ? ((0, jsx_runtime_1.jsx)(material_1.CircularProgress, {})) : ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { width: '100%', mt: 2 }, children: [(0, jsx_runtime_1.jsx)(material_1.Alert, { severity: verificationStatus === 'success' ? 'success' : 'error', sx: { mb: 2 }, children: message }), verificationStatus === 'success' && ((0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", color: "primary", component: material_1.Link, href: loginLink, fullWidth: true, children: translatedLabels.proceedToLogin })), verificationStatus === 'error' && ((0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body1", children: [translatedLabels.contactSupport, ' ', (0, jsx_runtime_1.jsx)(material_1.Link, { href: resendLink, color: "primary", children: translatedLabels.requestNewEmail }), "."] }))] }))] }) }));
|
|
59
|
+
};
|
|
60
|
+
exports.VerifyEmailPage = VerifyEmailPage;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
// Component exports
|
|
5
|
+
tslib_1.__exportStar(require("./ApiAccess"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./BackupCodeLoginForm"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./BackupCodesForm"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./ChangePasswordForm"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./ConfirmationDialog"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./CurrencyCodeSelector"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./CurrencyInput"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./DashboardPage"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./DropdownMenu"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./ExpirationSecondsSelector"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./Flag"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./ForgotPasswordForm"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./LoginForm"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./LogoutPage"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./RegisterForm"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./ResetPasswordForm"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./SideMenu"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./SideMenuListItem"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./TopMenu"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./TranslatedTitle"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./UserLanguageSelector"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./VerifyEmailPage"), exports);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useI18n = exports.I18nProvider = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const i18n_lib_1 = require("@digitaldefiance/i18n-lib");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const I18nContext = (0, react_1.createContext)(undefined);
|
|
8
|
+
const I18nProvider = ({ children, i18nEngine, onLanguageChange, }) => {
|
|
9
|
+
const context = i18n_lib_1.GlobalActiveContext.getInstance();
|
|
10
|
+
const [currentLanguage, setCurrentLanguage] = (0, react_1.useState)(context.userLanguage);
|
|
11
|
+
const changeLanguage = (0, react_1.useCallback)(async (language) => {
|
|
12
|
+
const languageDetails = i18n_lib_1.LanguageRegistry.getLanguageByCode(language);
|
|
13
|
+
if (language && languageDetails) {
|
|
14
|
+
context.userLanguage = language;
|
|
15
|
+
i18nEngine.setLanguage(language);
|
|
16
|
+
localStorage.setItem('language', languageDetails.name);
|
|
17
|
+
localStorage.setItem('languageCode', language);
|
|
18
|
+
setCurrentLanguage(language);
|
|
19
|
+
if (onLanguageChange) {
|
|
20
|
+
await onLanguageChange(language);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}, [onLanguageChange, i18nEngine, context]);
|
|
24
|
+
const t = (0, react_1.useCallback)((key, vars, language) => {
|
|
25
|
+
return i18nEngine.t(key, vars, language);
|
|
26
|
+
}, [i18nEngine]);
|
|
27
|
+
const tComponent = (0, react_1.useCallback)((componentId, stringKey) => {
|
|
28
|
+
return i18nEngine.translate(componentId, stringKey, undefined, currentLanguage);
|
|
29
|
+
}, [currentLanguage, i18nEngine]);
|
|
30
|
+
const value = {
|
|
31
|
+
t,
|
|
32
|
+
tComponent,
|
|
33
|
+
changeLanguage,
|
|
34
|
+
currentLanguage,
|
|
35
|
+
};
|
|
36
|
+
return (0, jsx_runtime_1.jsx)(I18nContext.Provider, { value: value, children: children });
|
|
37
|
+
};
|
|
38
|
+
exports.I18nProvider = I18nProvider;
|
|
39
|
+
const useI18n = () => {
|
|
40
|
+
const context = (0, react_1.useContext)(I18nContext);
|
|
41
|
+
if (context === undefined) {
|
|
42
|
+
throw new Error('useI18n must be used within an I18nProvider');
|
|
43
|
+
}
|
|
44
|
+
return context;
|
|
45
|
+
};
|
|
46
|
+
exports.useI18n = useI18n;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThemeToggleButton = exports.AppThemeProvider = exports.useTheme = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const icons_material_1 = require("@mui/icons-material");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const ThemeContext = (0, react_1.createContext)(undefined);
|
|
9
|
+
const useTheme = () => {
|
|
10
|
+
const context = (0, react_1.useContext)(ThemeContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('useTheme must be used within an AppThemeProvider');
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
};
|
|
16
|
+
exports.useTheme = useTheme;
|
|
17
|
+
const AppThemeProvider = ({ children, customTheme }) => {
|
|
18
|
+
const [mode, setMode] = (0, react_1.useState)('light');
|
|
19
|
+
const colorMode = (0, react_1.useMemo)(() => ({
|
|
20
|
+
toggleColorMode: () => {
|
|
21
|
+
setMode((prevMode) => (prevMode === 'light' ? 'dark' : 'light'));
|
|
22
|
+
},
|
|
23
|
+
mode,
|
|
24
|
+
}), [mode]);
|
|
25
|
+
const theme = (0, react_1.useMemo)(() => (customTheme ? customTheme(mode) : (0, material_1.createTheme)({ palette: { mode } })), [mode, customTheme]);
|
|
26
|
+
return ((0, jsx_runtime_1.jsx)(ThemeContext.Provider, { value: colorMode, children: (0, jsx_runtime_1.jsx)(material_1.ThemeProvider, { theme: theme, children: children }) }));
|
|
27
|
+
};
|
|
28
|
+
exports.AppThemeProvider = AppThemeProvider;
|
|
29
|
+
const ThemeToggleButton = () => {
|
|
30
|
+
const { mode, toggleColorMode } = (0, exports.useTheme)();
|
|
31
|
+
return ((0, jsx_runtime_1.jsx)(material_1.IconButton, { onClick: toggleColorMode, color: "inherit", children: mode === 'dark' ? (0, jsx_runtime_1.jsx)(icons_material_1.Brightness7, {}) : (0, jsx_runtime_1.jsx)(icons_material_1.Brightness4, {}) }));
|
|
32
|
+
};
|
|
33
|
+
exports.ThemeToggleButton = ThemeToggleButton;
|