@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
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Private = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const Private = ({ children, isAuthenticated, isCheckingAuth, }) => {
|
|
6
|
+
if (isCheckingAuth || !isAuthenticated) {
|
|
7
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
|
|
8
|
+
}
|
|
9
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
10
|
+
};
|
|
11
|
+
exports.Private = Private;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrivateRoute = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_router_dom_1 = require("react-router-dom");
|
|
6
|
+
const PrivateRoute = ({ children, isAuthenticated, isCheckingAuth, redirectTo = '/login', loadingComponent = (0, jsx_runtime_1.jsx)("div", { children: "Checking authentication..." }), }) => {
|
|
7
|
+
const location = (0, react_router_dom_1.useLocation)();
|
|
8
|
+
if (isCheckingAuth) {
|
|
9
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: loadingComponent });
|
|
10
|
+
}
|
|
11
|
+
if (!isAuthenticated) {
|
|
12
|
+
return (0, jsx_runtime_1.jsx)(react_router_dom_1.Navigate, { to: redirectTo, state: { from: location }, replace: true });
|
|
13
|
+
}
|
|
14
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
15
|
+
};
|
|
16
|
+
exports.PrivateRoute = PrivateRoute;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnAuthRoute = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_router_dom_1 = require("react-router-dom");
|
|
6
|
+
const UnAuthRoute = ({ children, isAuthenticated, isCheckingAuth, redirectTo = '/dashboard', loadingComponent = (0, jsx_runtime_1.jsx)("div", { children: "Checking authentication..." }), }) => {
|
|
7
|
+
const location = (0, react_router_dom_1.useLocation)();
|
|
8
|
+
if (isCheckingAuth) {
|
|
9
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: loadingComponent });
|
|
10
|
+
}
|
|
11
|
+
if (isAuthenticated) {
|
|
12
|
+
return (0, jsx_runtime_1.jsx)(react_router_dom_1.Navigate, { to: redirectTo, state: { from: location }, replace: true });
|
|
13
|
+
}
|
|
14
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
15
|
+
};
|
|
16
|
+
exports.UnAuthRoute = UnAuthRoute;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./PrivateRoute"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./UnAuthRoute"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./Private"), exports);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiAccess = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const ContentCopy_1 = tslib_1.__importDefault(require("@mui/icons-material/ContentCopy"));
|
|
7
|
+
const material_1 = require("@mui/material");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
10
|
+
const contexts_1 = require("../contexts");
|
|
11
|
+
const ApiAccessContainer = (0, material_1.styled)(material_1.Box)(({ theme }) => ({
|
|
12
|
+
display: 'flex',
|
|
13
|
+
flexDirection: 'column',
|
|
14
|
+
alignItems: 'center',
|
|
15
|
+
justifyContent: 'center',
|
|
16
|
+
minHeight: '100vh',
|
|
17
|
+
backgroundColor: theme.palette.background.default,
|
|
18
|
+
padding: theme.spacing(3),
|
|
19
|
+
}));
|
|
20
|
+
const ApiAccessContent = (0, material_1.styled)(material_1.Box)(({ theme }) => ({
|
|
21
|
+
maxWidth: '600px',
|
|
22
|
+
width: '100%',
|
|
23
|
+
backgroundColor: theme.palette.background.paper,
|
|
24
|
+
borderRadius: theme.shape.borderRadius,
|
|
25
|
+
padding: theme.spacing(4),
|
|
26
|
+
boxShadow: theme.shadows[3],
|
|
27
|
+
}));
|
|
28
|
+
const ApiAccessTitle = (0, material_1.styled)(material_1.Typography)(({ theme }) => ({
|
|
29
|
+
marginBottom: theme.spacing(3),
|
|
30
|
+
color: theme.palette.primary.main,
|
|
31
|
+
}));
|
|
32
|
+
const ApiAccess = ({ token, labels = {}, }) => {
|
|
33
|
+
const { t, tComponent } = (0, contexts_1.useI18n)();
|
|
34
|
+
const [dialogOpen, setDialogOpen] = (0, react_1.useState)(false);
|
|
35
|
+
const [isError, setIsError] = (0, react_1.useState)(false);
|
|
36
|
+
const translatedLabels = {
|
|
37
|
+
title: labels.title || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.ApiAccess_Title),
|
|
38
|
+
tokenNotAvailable: labels.tokenNotAvailable || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.ApiAccess_TokenNotAvailable),
|
|
39
|
+
copyButton: labels.copyButton || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_CopyToClipboard),
|
|
40
|
+
notificationTitle: labels.notificationTitle || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Notification),
|
|
41
|
+
copied: labels.copied || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_CopiedToClipboard),
|
|
42
|
+
copyFailed: labels.copyFailed || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Error_FailedToCopy),
|
|
43
|
+
ok: labels.ok || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_OK),
|
|
44
|
+
};
|
|
45
|
+
const copyToClipboard = async () => {
|
|
46
|
+
if (token) {
|
|
47
|
+
try {
|
|
48
|
+
await navigator.clipboard.writeText(token);
|
|
49
|
+
setIsError(false);
|
|
50
|
+
setDialogOpen(true);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
setIsError(true);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const handleClose = () => {
|
|
58
|
+
setDialogOpen(false);
|
|
59
|
+
setIsError(false);
|
|
60
|
+
};
|
|
61
|
+
return ((0, jsx_runtime_1.jsxs)(ApiAccessContainer, { children: [(0, jsx_runtime_1.jsxs)(ApiAccessContent, { children: [(0, jsx_runtime_1.jsx)(ApiAccessTitle, { variant: "h4", align: "center", children: translatedLabels.title }), (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, multiline: true, rows: 4, value: token || translatedLabels.tokenNotAvailable, slotProps: {
|
|
62
|
+
input: {
|
|
63
|
+
readOnly: true,
|
|
64
|
+
},
|
|
65
|
+
}, variant: "outlined", margin: "normal" }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", color: "primary", startIcon: (0, jsx_runtime_1.jsx)(ContentCopy_1.default, {}), onClick: copyToClipboard, fullWidth: true, style: { marginTop: '16px' }, children: translatedLabels.copyButton })] }), (0, jsx_runtime_1.jsxs)(material_1.Dialog, { open: dialogOpen, onClose: handleClose, children: [(0, jsx_runtime_1.jsx)(material_1.DialogTitle, { children: translatedLabels.notificationTitle }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: isError ? translatedLabels.copyFailed : translatedLabels.copied }), (0, jsx_runtime_1.jsx)(material_1.DialogActions, { children: (0, jsx_runtime_1.jsx)(material_1.Button, { onClick: handleClose, color: "primary", children: translatedLabels.ok }) })] })] }));
|
|
66
|
+
};
|
|
67
|
+
exports.ApiAccess = ApiAccess;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BackupCodeLoginForm = 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 BackupCodeLoginForm = ({ onSubmit, onNavigate, isAuthenticated = false, emailValidation, usernameValidation, codeValidation, passwordValidation, confirmPasswordValidation, labels = {}, }) => {
|
|
13
|
+
const { t, tComponent } = (0, contexts_1.useI18n)();
|
|
14
|
+
const [loginType, setLoginType] = (0, react_1.useState)('email');
|
|
15
|
+
const [loginError, setLoginError] = (0, react_1.useState)(null);
|
|
16
|
+
const [recoveredMnemonic, setRecoveredMnemonic] = (0, react_1.useState)(null);
|
|
17
|
+
const [successMessage, setSuccessMessage] = (0, react_1.useState)(null);
|
|
18
|
+
const [codesRemaining, setCodesRemaining] = (0, react_1.useState)(null);
|
|
19
|
+
const validation = {
|
|
20
|
+
email: emailValidation || Yup.string()
|
|
21
|
+
.email(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_InvalidEmail))
|
|
22
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
23
|
+
username: usernameValidation || Yup.string()
|
|
24
|
+
.matches(suite_core_lib_1.Constants.UsernameRegex, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_UsernameRegexErrorTemplate))
|
|
25
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
26
|
+
code: codeValidation || Yup.string()
|
|
27
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required))
|
|
28
|
+
.matches(suite_core_lib_1.Constants.BACKUP_CODES.DisplayRegex, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_InvalidBackupCode)),
|
|
29
|
+
password: passwordValidation || Yup.string()
|
|
30
|
+
.matches(suite_core_lib_1.Constants.PasswordRegex, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_PasswordRegexErrorTemplate)),
|
|
31
|
+
confirmPassword: confirmPasswordValidation || Yup.string()
|
|
32
|
+
.oneOf([Yup.ref('newPassword')], tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_PasswordMatch)),
|
|
33
|
+
};
|
|
34
|
+
const translatedLabels = {
|
|
35
|
+
title: labels.title || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.BackupCodeRecovery_Title),
|
|
36
|
+
email: labels.email || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Email),
|
|
37
|
+
username: labels.username || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Username),
|
|
38
|
+
code: labels.code || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_BackupCode),
|
|
39
|
+
newPassword: labels.newPassword || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_NewPassword),
|
|
40
|
+
confirmPassword: labels.confirmPassword || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_ConfirmNewPassword),
|
|
41
|
+
recoverMnemonic: labels.recoverMnemonic || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.BackupCodeRecovery_RecoverMnemonic),
|
|
42
|
+
login: labels.login || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.BackupCodeRecovery_Login),
|
|
43
|
+
useUsername: labels.useUsername || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Login_UseUsername),
|
|
44
|
+
useEmail: labels.useEmail || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Login_UseEmail),
|
|
45
|
+
dashboard: labels.dashboard || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Dashboard),
|
|
46
|
+
generateNewCodes: labels.generateNewCodes || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.BackupCodeRecovery_GenerateNewCodes),
|
|
47
|
+
mnemonicLabel: labels.mnemonicLabel || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Mnemonic),
|
|
48
|
+
codesRemaining: labels.codesRemaining || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.BackupCodeRecovery_CodesRemainingTemplate),
|
|
49
|
+
unexpectedError: tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_UnexpectedError),
|
|
50
|
+
};
|
|
51
|
+
const validationSchema = Yup.object({
|
|
52
|
+
[loginType]: loginType === 'email' ? validation.email : validation.username,
|
|
53
|
+
code: validation.code,
|
|
54
|
+
newPassword: validation.password,
|
|
55
|
+
confirmNewPassword: validation.confirmPassword,
|
|
56
|
+
});
|
|
57
|
+
const formik = (0, formik_1.useFormik)({
|
|
58
|
+
initialValues: {
|
|
59
|
+
email: '',
|
|
60
|
+
username: '',
|
|
61
|
+
code: '',
|
|
62
|
+
newPassword: '',
|
|
63
|
+
confirmNewPassword: '',
|
|
64
|
+
recoverMnemonic: false,
|
|
65
|
+
},
|
|
66
|
+
validationSchema,
|
|
67
|
+
onSubmit: async (values, { setSubmitting }) => {
|
|
68
|
+
try {
|
|
69
|
+
const loginResult = await onSubmit(loginType === 'email' ? values.email : values.username, values.code, loginType === 'email', values.recoverMnemonic, values.newPassword && values.newPassword.length > 0 ? values.newPassword : undefined);
|
|
70
|
+
if ('error' in loginResult) {
|
|
71
|
+
setLoginError(loginResult.error);
|
|
72
|
+
setCodesRemaining(null);
|
|
73
|
+
setRecoveredMnemonic(null);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
setLoginError(null);
|
|
77
|
+
if (loginResult.codeCount) {
|
|
78
|
+
setCodesRemaining(loginResult.codeCount);
|
|
79
|
+
}
|
|
80
|
+
if (loginResult.mnemonic) {
|
|
81
|
+
setRecoveredMnemonic(loginResult.mnemonic);
|
|
82
|
+
}
|
|
83
|
+
if (loginResult.message) {
|
|
84
|
+
setSuccessMessage(loginResult.message);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
setLoginError(translatedLabels.unexpectedError);
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
setSubmitting(false);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
if (isAuthenticated && recoveredMnemonic === null && codesRemaining === null) {
|
|
96
|
+
onNavigate?.('/dashboard');
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Container, { component: "main", maxWidth: "xs", children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { marginTop: 8, display: 'flex', flexDirection: 'column', alignItems: 'center' }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h1", variant: "h5", children: translatedLabels.title }), (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "form", onSubmit: formik.handleSubmit, sx: { mt: 1, width: '100%' }, children: [!isAuthenticated && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { margin: "normal", fullWidth: true, id: loginType, label: loginType === 'email' ? translatedLabels.email : translatedLabels.username, name: loginType, autoComplete: loginType === 'email' ? 'email' : 'username', autoFocus: true, value: loginType === 'email' ? formik.values.email : formik.values.username, onChange: formik.handleChange, onBlur: formik.handleBlur, error: formik.touched[loginType] && Boolean(formik.errors[loginType]), helperText: formik.touched[loginType] && formik.errors[loginType], disabled: isAuthenticated }), (0, jsx_runtime_1.jsx)(material_1.TextField, { margin: "normal", required: true, fullWidth: true, name: "code", label: translatedLabels.code, id: "code", value: formik.values.code, onChange: formik.handleChange, onBlur: formik.handleBlur, error: formik.touched.code && Boolean(formik.errors.code), helperText: formik.touched.code && formik.errors.code, disabled: isAuthenticated }), (0, jsx_runtime_1.jsx)(material_1.TextField, { margin: "normal", fullWidth: true, name: "newPassword", label: translatedLabels.newPassword, type: "password", id: "newPassword", value: formik.values.newPassword, onChange: formik.handleChange, onBlur: formik.handleBlur, error: formik.touched.newPassword && Boolean(formik.errors.newPassword), helperText: formik.touched.newPassword && formik.errors.newPassword, disabled: isAuthenticated }), (0, jsx_runtime_1.jsx)(material_1.TextField, { margin: "normal", fullWidth: true, name: "confirmNewPassword", label: translatedLabels.confirmPassword, type: "password", id: "confirmNewPassword", value: formik.values.confirmNewPassword, onChange: formik.handleChange, onBlur: formik.handleBlur, error: formik.touched.confirmNewPassword && Boolean(formik.errors.confirmNewPassword), helperText: formik.touched.confirmNewPassword && formik.errors.confirmNewPassword, disabled: isAuthenticated }), (0, jsx_runtime_1.jsx)(material_1.FormControlLabel, { control: (0, jsx_runtime_1.jsx)(material_1.Checkbox, { checked: formik.values.recoverMnemonic, onChange: formik.handleChange, onBlur: formik.handleBlur, name: "recoverMnemonic" }), label: translatedLabels.recoverMnemonic, disabled: isAuthenticated })] })), successMessage && ((0, jsx_runtime_1.jsx)(material_1.Typography, { color: "success.main", variant: "body2", sx: { mt: 1 }, children: successMessage })), recoveredMnemonic && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { mt: 2, p: 2, bgcolor: 'grey.100', borderRadius: 1 }, children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "subtitle2", gutterBottom: true, children: [translatedLabels.mnemonicLabel, ":"] }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", sx: { fontFamily: 'monospace' }, children: recoveredMnemonic }), (0, jsx_runtime_1.jsx)(material_1.Button, { fullWidth: true, variant: "contained", sx: { mt: 2 }, onClick: () => onNavigate?.('/dashboard'), children: translatedLabels.dashboard })] })), codesRemaining !== null && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { mt: 2 }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", children: translatedLabels.codesRemaining.replace('{count}', String(codesRemaining)) }), (0, jsx_runtime_1.jsx)(material_1.Button, { fullWidth: true, variant: "contained", sx: { mt: 2 }, onClick: () => onNavigate?.('/backup-codes', { codeCount: codesRemaining }), children: translatedLabels.generateNewCodes })] })), loginError && ((0, jsx_runtime_1.jsx)(material_1.Typography, { color: "error", variant: "body2", sx: { mt: 1 }, children: loginError })), !isAuthenticated && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, { type: "submit", fullWidth: true, variant: "contained", sx: { mt: 3, mb: 2 }, disabled: formik.isSubmitting, children: translatedLabels.login }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: { display: 'flex', justifyContent: 'center' }, children: (0, jsx_runtime_1.jsx)(material_1.Button, { fullWidth: true, variant: "text", onClick: () => setLoginType(loginType === 'email' ? 'username' : 'email'), children: loginType === 'email' ? translatedLabels.useUsername : translatedLabels.useEmail }) })] }))] })] }) }));
|
|
100
|
+
};
|
|
101
|
+
exports.BackupCodeLoginForm = BackupCodeLoginForm;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BackupCodesForm = 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 BackupCodesForm = ({ onSubmit, backupCodesRemaining = null, mnemonicValidation, passwordValidation, labels = {}, }) => {
|
|
13
|
+
const { t, tComponent } = (0, contexts_1.useI18n)();
|
|
14
|
+
const [apiError, setApiError] = (0, react_1.useState)(null);
|
|
15
|
+
const [apiSuccess, setApiSuccess] = (0, react_1.useState)(null);
|
|
16
|
+
const [backupCodes, setBackupCodes] = (0, react_1.useState)(null);
|
|
17
|
+
const validation = {
|
|
18
|
+
mnemonic: mnemonicValidation || Yup.string()
|
|
19
|
+
.trim()
|
|
20
|
+
.matches(suite_core_lib_1.Constants.MnemonicRegex, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_MnemonicRegex))
|
|
21
|
+
.optional(),
|
|
22
|
+
password: passwordValidation || Yup.string()
|
|
23
|
+
.trim()
|
|
24
|
+
.matches(suite_core_lib_1.Constants.PasswordRegex, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_PasswordRegexErrorTemplate))
|
|
25
|
+
.optional(),
|
|
26
|
+
};
|
|
27
|
+
const translatedLabels = {
|
|
28
|
+
codesRemaining: labels.codesRemaining || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.BackupCodeRecovery_CodesRemainingTemplate),
|
|
29
|
+
mnemonic: labels.mnemonic || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Mnemonic),
|
|
30
|
+
password: labels.password || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_Password),
|
|
31
|
+
generateButton: labels.generateButton || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.BackupCodeRecovery_GenerateNewCodes),
|
|
32
|
+
successTitle: labels.successTitle || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.BackupCodeRecovery_YourNewCodes),
|
|
33
|
+
xorError: tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_MnemonicOrPasswordRequired),
|
|
34
|
+
unexpectedError: tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_UnexpectedError),
|
|
35
|
+
};
|
|
36
|
+
const validationSchema = Yup.object({
|
|
37
|
+
mnemonic: validation.mnemonic,
|
|
38
|
+
password: validation.password,
|
|
39
|
+
})
|
|
40
|
+
.test('xor-mnemonic-password-mnemonic', translatedLabels.xorError, function (value) {
|
|
41
|
+
const mnemonic = value?.mnemonic?.trim() ?? '';
|
|
42
|
+
const password = value?.password?.trim() ?? '';
|
|
43
|
+
const hasMnemonic = mnemonic.length > 0;
|
|
44
|
+
const hasPassword = password.length > 0;
|
|
45
|
+
if (!hasMnemonic && !hasPassword) {
|
|
46
|
+
return this.createError({
|
|
47
|
+
path: 'mnemonic',
|
|
48
|
+
message: translatedLabels.xorError,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (hasMnemonic && hasPassword) {
|
|
52
|
+
return this.createError({
|
|
53
|
+
path: 'mnemonic',
|
|
54
|
+
message: translatedLabels.xorError,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
})
|
|
59
|
+
.test('xor-mnemonic-password-password', translatedLabels.xorError, function (value) {
|
|
60
|
+
const mnemonic = value?.mnemonic?.trim() ?? '';
|
|
61
|
+
const password = value?.password?.trim() ?? '';
|
|
62
|
+
const hasMnemonic = mnemonic.length > 0;
|
|
63
|
+
const hasPassword = password.length > 0;
|
|
64
|
+
if (!hasMnemonic && !hasPassword) {
|
|
65
|
+
return this.createError({
|
|
66
|
+
path: 'password',
|
|
67
|
+
message: translatedLabels.xorError,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (hasMnemonic && hasPassword) {
|
|
71
|
+
return this.createError({
|
|
72
|
+
path: 'password',
|
|
73
|
+
message: translatedLabels.xorError,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
});
|
|
78
|
+
const formik = (0, formik_1.useFormik)({
|
|
79
|
+
initialValues: {
|
|
80
|
+
password: '',
|
|
81
|
+
mnemonic: '',
|
|
82
|
+
},
|
|
83
|
+
validationSchema,
|
|
84
|
+
onSubmit: async (values, { setSubmitting }) => {
|
|
85
|
+
try {
|
|
86
|
+
const result = await onSubmit(values);
|
|
87
|
+
if (result && result.backupCodes) {
|
|
88
|
+
setApiSuccess(translatedLabels.successTitle);
|
|
89
|
+
setBackupCodes(result.backupCodes);
|
|
90
|
+
}
|
|
91
|
+
if (result && result.message) {
|
|
92
|
+
setApiSuccess(result.message);
|
|
93
|
+
}
|
|
94
|
+
setApiError(null);
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
setApiSuccess(null);
|
|
98
|
+
setApiError(e.response?.data?.message ?? translatedLabels.unexpectedError);
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
setSubmitting(false);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Container, { component: "main", maxWidth: "xs", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h1", variant: "h5", children: translatedLabels.codesRemaining.replace('{count}', String(backupCodesRemaining ?? 0)) }) }), (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: "mnemonic", label: translatedLabels.mnemonic, type: "password", name: "mnemonic", autoComplete: "mnemonic", autoFocus: true, value: formik.values.mnemonic, onChange: formik.handleChange, onBlur: formik.handleBlur, error: (formik.touched.mnemonic || formik.submitCount > 0) && Boolean(formik.errors.mnemonic), helperText: (formik.touched.mnemonic || formik.submitCount > 0) && formik.errors.mnemonic }), (0, jsx_runtime_1.jsx)(material_1.TextField, { margin: "normal", fullWidth: true, name: "password", label: translatedLabels.password, type: "password", id: "password", value: formik.values.password, onChange: formik.handleChange, onBlur: formik.handleBlur, error: (formik.touched.password || formik.submitCount > 0) && Boolean(formik.errors.password), helperText: (formik.touched.password || formik.submitCount > 0) && formik.errors.password }), (0, jsx_runtime_1.jsx)(material_1.Button, { type: "submit", fullWidth: true, variant: "contained", sx: { mt: 2 }, children: translatedLabels.generateButton })] }), apiError && ((0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", sx: { mt: 2, mb: 2 }, children: apiError })), backupCodes && apiSuccess && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { mt: 2, mb: 2 }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h2", variant: "h6", children: apiSuccess }), (0, jsx_runtime_1.jsx)("ul", { children: backupCodes.map((code, index) => ((0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsx)("pre", { children: code }) }, index))) })] }))] }));
|
|
106
|
+
};
|
|
107
|
+
exports.BackupCodesForm = BackupCodesForm;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChangePasswordForm = 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 ChangePasswordForm = ({ onSubmit, titleText, currentPasswordLabel, newPasswordLabel, confirmPasswordLabel, submitButtonText, submittingButtonText, successMessage, currentPasswordValidation, newPasswordValidation, confirmPasswordValidation, }) => {
|
|
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
|
+
currentPassword: currentPasswordValidation || Yup.string().required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
18
|
+
newPassword: newPasswordValidation || Yup.string()
|
|
19
|
+
.min(suite_core_lib_1.Constants.PasswordMinLength, tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_PasswordMinLengthTemplate))
|
|
20
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
21
|
+
confirmPassword: confirmPasswordValidation || Yup.string()
|
|
22
|
+
.oneOf([Yup.ref('newPassword')], tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_PasswordMatch))
|
|
23
|
+
.required(tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Validation_Required)),
|
|
24
|
+
};
|
|
25
|
+
const labels = {
|
|
26
|
+
title: titleText || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_ChangePassword),
|
|
27
|
+
currentPassword: currentPasswordLabel || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_CurrentPassword),
|
|
28
|
+
newPassword: newPasswordLabel || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_NewPassword),
|
|
29
|
+
confirmPassword: confirmPasswordLabel || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_ConfirmNewPassword),
|
|
30
|
+
submitButton: submitButtonText || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_ChangePassword),
|
|
31
|
+
submittingButton: submittingButtonText || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.Common_ChangingPassword),
|
|
32
|
+
success: successMessage || tComponent(suite_core_lib_1.SuiteCoreComponentId, suite_core_lib_1.SuiteCoreStringKey.PasswordChange_Success),
|
|
33
|
+
};
|
|
34
|
+
const formik = (0, formik_1.useFormik)({
|
|
35
|
+
initialValues: {
|
|
36
|
+
currentPassword: '',
|
|
37
|
+
newPassword: '',
|
|
38
|
+
confirmPassword: '',
|
|
39
|
+
},
|
|
40
|
+
validationSchema: Yup.object({
|
|
41
|
+
currentPassword: validation.currentPassword,
|
|
42
|
+
newPassword: validation.newPassword,
|
|
43
|
+
confirmPassword: validation.confirmPassword,
|
|
44
|
+
}),
|
|
45
|
+
onSubmit: async (values, { resetForm }) => {
|
|
46
|
+
const result = await onSubmit(values);
|
|
47
|
+
if ('success' in result) {
|
|
48
|
+
setSuccess(true);
|
|
49
|
+
setApiError('');
|
|
50
|
+
resetForm();
|
|
51
|
+
}
|
|
52
|
+
else if ('error' in result && result.error) {
|
|
53
|
+
setApiError(result.error);
|
|
54
|
+
setSuccess(false);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Container, { maxWidth: "sm", children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
59
|
+
mt: 8,
|
|
60
|
+
display: 'flex',
|
|
61
|
+
flexDirection: 'column',
|
|
62
|
+
alignItems: 'center',
|
|
63
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h4", component: "h1", gutterBottom: true, 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, { fullWidth: true, id: "currentPassword", name: "currentPassword", label: labels.currentPassword, type: "password", value: formik.values.currentPassword, onChange: formik.handleChange, onBlur: formik.handleBlur, error: Boolean(formik.touched.currentPassword && formik.errors.currentPassword), helperText: formik.touched.currentPassword && formik.errors.currentPassword, margin: "normal" }), (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, id: "newPassword", name: "newPassword", label: labels.newPassword, type: "password", value: formik.values.newPassword, onChange: formik.handleChange, onBlur: formik.handleBlur, error: Boolean(formik.touched.newPassword && formik.errors.newPassword), helperText: formik.touched.newPassword && formik.errors.newPassword, margin: "normal" }), (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, id: "confirmPassword", name: "confirmPassword", label: labels.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: labels.success })), (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: formik.isSubmitting ? labels.submittingButton : labels.submitButton })] })] }) }));
|
|
64
|
+
};
|
|
65
|
+
exports.ChangePasswordForm = ChangePasswordForm;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfirmationDialog = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const ConfirmationDialog = ({ open, title, message, confirmText = 'Confirm', cancelText = 'Cancel', onConfirm, onCancel, }) => {
|
|
7
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Dialog, { open: open, onClose: onCancel, children: [(0, jsx_runtime_1.jsx)(material_1.DialogTitle, { children: title }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, { children: message }) }), (0, jsx_runtime_1.jsxs)(material_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, { onClick: onCancel, color: "primary", children: cancelText }), (0, jsx_runtime_1.jsx)(material_1.Button, { onClick: onConfirm, color: "primary", children: confirmText })] })] }));
|
|
8
|
+
};
|
|
9
|
+
exports.ConfirmationDialog = ConfirmationDialog;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrencyCodeSelector = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const i18n_lib_1 = require("@digitaldefiance/i18n-lib");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const formik_1 = require("formik");
|
|
8
|
+
const CurrencyCodeSelector = ({ name, label, onCurrencyChange, }) => {
|
|
9
|
+
return ((0, jsx_runtime_1.jsx)(formik_1.Field, { name: name, children: ({ field, form }) => ((0, jsx_runtime_1.jsx)(material_1.TextField, { select: true, fullWidth: true, label: label, ...field, onChange: (event) => {
|
|
10
|
+
const selectedCode = event.target.value;
|
|
11
|
+
form.setFieldValue(name, selectedCode);
|
|
12
|
+
onCurrencyChange?.(selectedCode);
|
|
13
|
+
}, error: form.touched[name] && Boolean(form.errors[name]), helperText: form.touched[name] && form.errors[name], sx: {
|
|
14
|
+
'& .MuiSelect-select': {
|
|
15
|
+
paddingRight: '32px',
|
|
16
|
+
},
|
|
17
|
+
'& .MuiOutlinedInput-root': {
|
|
18
|
+
'& fieldset': {
|
|
19
|
+
borderColor: 'rgba(0, 0, 0, 0.23)',
|
|
20
|
+
},
|
|
21
|
+
'&:hover fieldset': {
|
|
22
|
+
borderColor: 'rgba(0, 0, 0, 0.87)',
|
|
23
|
+
},
|
|
24
|
+
'&.Mui-focused fieldset': {
|
|
25
|
+
borderColor: 'primary.main',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}, children: i18n_lib_1.CurrencyCode.getAll().map((code) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: code, children: code }, code))) })) }));
|
|
29
|
+
};
|
|
30
|
+
exports.CurrencyCodeSelector = CurrencyCodeSelector;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrencyInput = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const react_number_format_1 = require("react-number-format");
|
|
7
|
+
function getCurrencyFormat(currencyCode = 'USD') {
|
|
8
|
+
return {
|
|
9
|
+
symbol: '$',
|
|
10
|
+
position: 'prefix',
|
|
11
|
+
groupSeparator: ',',
|
|
12
|
+
decimalSeparator: '.',
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const CurrencyInput = ({ value, onChange, currencyCode = 'USD', label, error, helperText, name, }) => {
|
|
16
|
+
const format = getCurrencyFormat(currencyCode);
|
|
17
|
+
if (format.position === 'infix') {
|
|
18
|
+
const [whole, decimal] = value.toString().split('.');
|
|
19
|
+
const displayValue = `${whole}${format.symbol}${format.decimalSeparator}${decimal || '00'}`;
|
|
20
|
+
return ((0, jsx_runtime_1.jsx)(react_number_format_1.NumericFormat, { customInput: material_1.TextField, fullWidth: true, margin: "normal", label: label, value: displayValue, thousandSeparator: format.groupSeparator, decimalSeparator: format.decimalSeparator, decimalScale: 2, fixedDecimalScale: true, valueIsNumericString: true, onValueChange: (values) => {
|
|
21
|
+
onChange(values.floatValue || 0);
|
|
22
|
+
}, error: error, helperText: helperText, name: name }));
|
|
23
|
+
}
|
|
24
|
+
return ((0, jsx_runtime_1.jsx)(react_number_format_1.NumericFormat, { customInput: material_1.TextField, fullWidth: true, margin: "normal", label: label, value: value, thousandSeparator: format.groupSeparator, decimalSeparator: format.decimalSeparator, decimalScale: 2, fixedDecimalScale: true, prefix: format.position === 'prefix' ? format.symbol + ' ' : undefined, suffix: format.position === 'postfix' ? ' ' + format.symbol : undefined, valueIsNumericString: true, onValueChange: (values) => {
|
|
25
|
+
onChange(values.floatValue || 0);
|
|
26
|
+
}, error: error, helperText: helperText, name: name }));
|
|
27
|
+
};
|
|
28
|
+
exports.CurrencyInput = CurrencyInput;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DashboardPage = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const DashboardPage = ({ title = 'Dashboard', children }) => {
|
|
7
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Container, { maxWidth: "md", children: (0, jsx_runtime_1.jsxs)(material_1.Box, { my: 4, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h4", component: "h1", gutterBottom: true, align: "center", children: title }), (0, jsx_runtime_1.jsx)(material_1.Box, { display: "flex", justifyContent: "center", mt: 3, children: children })] }) }));
|
|
8
|
+
};
|
|
9
|
+
exports.DashboardPage = DashboardPage;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DropdownMenu = 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 DropdownMenu = ({ menuIcon, options, onNavigate }) => {
|
|
8
|
+
const [anchorEl, setAnchorEl] = (0, react_1.useState)(null);
|
|
9
|
+
const handleClose = (0, react_1.useCallback)(() => {
|
|
10
|
+
setAnchorEl(null);
|
|
11
|
+
}, []);
|
|
12
|
+
const handleMenuItemClick = (0, react_1.useCallback)((option) => (event) => {
|
|
13
|
+
event.stopPropagation();
|
|
14
|
+
if (option.action) {
|
|
15
|
+
option.action();
|
|
16
|
+
}
|
|
17
|
+
else if (option.link && onNavigate) {
|
|
18
|
+
onNavigate(option.link);
|
|
19
|
+
}
|
|
20
|
+
handleClose();
|
|
21
|
+
}, [onNavigate, handleClose]);
|
|
22
|
+
const handleClick = (0, react_1.useCallback)((event) => {
|
|
23
|
+
setAnchorEl(event.currentTarget);
|
|
24
|
+
}, []);
|
|
25
|
+
if (options.length === 0) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, { color: "inherit", onClick: handleClick, children: menuIcon }), (0, jsx_runtime_1.jsx)(material_1.Menu, { anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleClose, TransitionComponent: material_1.Fade, sx: {
|
|
29
|
+
'& .MuiPopover-paper': {
|
|
30
|
+
opacity: 0.5,
|
|
31
|
+
overflow: 'visible',
|
|
32
|
+
},
|
|
33
|
+
}, children: options.map((option) => ((0, jsx_runtime_1.jsxs)(material_1.MenuItem, { component: "li", onClick: handleMenuItemClick(option), sx: {
|
|
34
|
+
display: 'flex',
|
|
35
|
+
alignItems: 'center',
|
|
36
|
+
'& > svg': {
|
|
37
|
+
marginRight: 2,
|
|
38
|
+
width: 24,
|
|
39
|
+
height: 24,
|
|
40
|
+
},
|
|
41
|
+
}, children: [option.icon, option.label] }, option.id))) })] }));
|
|
42
|
+
};
|
|
43
|
+
exports.DropdownMenu = DropdownMenu;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExpirationSecondsSelector = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const ExpirationSecondsSelector = ({ name, label, formik, optionValues, optionNames, onChange, }) => {
|
|
7
|
+
return ((0, jsx_runtime_1.jsx)(material_1.TextField, { select: true, fullWidth: true, label: label, name: name, value: formik.values[name] ?? '', onChange: (event) => {
|
|
8
|
+
const selectedValue = event.target.value;
|
|
9
|
+
formik.setFieldValue(name, selectedValue);
|
|
10
|
+
if (onChange) {
|
|
11
|
+
onChange(parseInt(selectedValue));
|
|
12
|
+
}
|
|
13
|
+
}, error: formik.touched[name] && Boolean(formik.errors[name]), helperText: formik.touched[name] && formik.errors[name], sx: {
|
|
14
|
+
mt: 1,
|
|
15
|
+
'& .MuiSelect-select': {
|
|
16
|
+
paddingRight: '32px',
|
|
17
|
+
},
|
|
18
|
+
'& .MuiOutlinedInput-root': {
|
|
19
|
+
'& fieldset': {
|
|
20
|
+
borderColor: 'rgba(0, 0, 0, 0.23)',
|
|
21
|
+
},
|
|
22
|
+
'&:hover fieldset': {
|
|
23
|
+
borderColor: 'rgba(0, 0, 0, 0.87)',
|
|
24
|
+
},
|
|
25
|
+
'&.Mui-focused fieldset': {
|
|
26
|
+
borderColor: 'primary.main',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
}, children: optionNames.map((name, index) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: optionValues[index], children: name }, name))) }));
|
|
30
|
+
};
|
|
31
|
+
exports.ExpirationSecondsSelector = ExpirationSecondsSelector;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Flag = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const Flag = ({ languageCode, countryCode, sx }) => {
|
|
7
|
+
if (!countryCode) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { component: "span", "aria-label": `Flag for ${languageCode}`, sx: {
|
|
11
|
+
fontSize: '1.5rem',
|
|
12
|
+
lineHeight: 1,
|
|
13
|
+
verticalAlign: 'middle',
|
|
14
|
+
'&::before': {
|
|
15
|
+
content: `" "`,
|
|
16
|
+
display: 'inline-block',
|
|
17
|
+
width: '1em',
|
|
18
|
+
height: '1em',
|
|
19
|
+
backgroundImage: `url(https://flagcdn.com/${countryCode.toLowerCase()}.svg)`,
|
|
20
|
+
backgroundSize: 'contain',
|
|
21
|
+
backgroundRepeat: 'no-repeat',
|
|
22
|
+
backgroundPosition: 'center',
|
|
23
|
+
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
24
|
+
borderRadius: '2px',
|
|
25
|
+
},
|
|
26
|
+
...sx,
|
|
27
|
+
} }));
|
|
28
|
+
};
|
|
29
|
+
exports.Flag = Flag;
|