@digitaldefiance/express-suite-react-components 2.9.37 → 2.9.38
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/LICENSE +21 -0
- package/package.json +4 -5
- package/src/auth/Private.tsx +17 -0
- package/src/auth/PrivateRoute.tsx +28 -0
- package/src/auth/UnAuth.tsx +16 -0
- package/src/auth/UnAuthRoute.tsx +30 -0
- package/src/auth/{index.d.ts → index.ts} +1 -2
- package/src/components/ApiAccess.tsx +174 -0
- package/src/components/BackupCodeLoginForm.tsx +488 -0
- package/src/components/BackupCodesForm.tsx +286 -0
- package/src/components/ChangePasswordForm.tsx +272 -0
- package/src/components/ConfirmationDialog.tsx +48 -0
- package/src/components/CurrencyCodeSelector.tsx +60 -0
- package/src/components/CurrencyInput.tsx +80 -0
- package/src/components/DashboardPage.tsx +24 -0
- package/src/components/DropdownMenu.tsx +92 -0
- package/src/components/ExpirationSecondsSelector.tsx +60 -0
- package/src/components/Flag.tsx +52 -0
- package/src/components/ForgotPasswordForm.tsx +173 -0
- package/src/components/LoginForm.tsx +455 -0
- package/src/components/LogoutPage.tsx +21 -0
- package/src/components/RegisterForm.tsx +602 -0
- package/src/components/ResetPasswordForm.tsx +246 -0
- package/src/components/SideMenu.tsx +46 -0
- package/src/components/SideMenuListItem.tsx +74 -0
- package/src/components/TopMenu.tsx +145 -0
- package/src/components/TranslatedTitle.tsx +29 -0
- package/src/components/UserLanguageSelector.tsx +45 -0
- package/src/components/UserMenu.tsx +15 -0
- package/src/components/UserSettingsForm.tsx +505 -0
- package/src/components/VerifyEmailPage.tsx +184 -0
- package/src/components/{index.d.ts → index.ts} +1 -1
- package/src/contexts/AuthProvider.spec.tsx +1195 -0
- package/src/contexts/AuthProvider.tsx +924 -0
- package/src/contexts/I18nProvider.tsx +114 -0
- package/src/contexts/MenuContext.tsx +398 -0
- package/src/contexts/SuiteConfigProvider.tsx +93 -0
- package/src/contexts/ThemeProvider.tsx +67 -0
- package/src/contexts/{index.d.ts → index.ts} +0 -1
- package/src/hooks/{index.d.ts → index.ts} +0 -1
- package/src/hooks/useBackupCodes.ts +105 -0
- package/src/hooks/useEmailVerification.ts +49 -0
- package/src/hooks/useExpiringValue.ts +78 -0
- package/src/hooks/useLocalStorage.ts +18 -0
- package/src/hooks/useUserSettings.ts +269 -0
- package/src/{index.d.ts → index.ts} +1 -1
- package/src/interfaces/IAppConfig.ts +5 -0
- package/src/interfaces/IMenuConfig.ts +11 -0
- package/src/interfaces/IMenuOption.ts +55 -0
- package/src/interfaces/index.ts +3 -0
- package/src/services/__mocks__/authService.ts +14 -0
- package/src/services/api.ts +13 -0
- package/src/services/authService.ts +500 -0
- package/src/services/authenticatedApi.ts +17 -0
- package/src/services/index.ts +3 -0
- package/src/types/MenuType.ts +15 -0
- package/src/types/expirationSeconds.ts +18 -0
- package/src/types/index.ts +1 -0
- package/src/types/translation.ts +20 -0
- package/src/wrappers/BackupCodeLoginWrapper.tsx +34 -0
- package/src/wrappers/BackupCodesWrapper.tsx +28 -0
- package/src/wrappers/ChangePasswordFormWrapper.tsx +34 -0
- package/src/wrappers/LoginFormWrapper.tsx +59 -0
- package/src/wrappers/LogoutPageWrapper.tsx +30 -0
- package/src/wrappers/RegisterFormWrapper.tsx +61 -0
- package/src/wrappers/UserSettingsFormWrapper.tsx +39 -0
- package/src/wrappers/VerifyEmailPageWrapper.tsx +27 -0
- package/src/wrappers/{index.d.ts → index.tsx} +8 -1
- package/src/auth/Private.d.ts +0 -6
- package/src/auth/Private.d.ts.map +0 -1
- package/src/auth/Private.js +0 -14
- package/src/auth/PrivateRoute.d.ts +0 -8
- package/src/auth/PrivateRoute.d.ts.map +0 -1
- package/src/auth/PrivateRoute.js +0 -23
- package/src/auth/UnAuth.d.ts +0 -6
- package/src/auth/UnAuth.d.ts.map +0 -1
- package/src/auth/UnAuth.js +0 -14
- package/src/auth/UnAuthRoute.d.ts +0 -8
- package/src/auth/UnAuthRoute.d.ts.map +0 -1
- package/src/auth/UnAuthRoute.js +0 -22
- package/src/auth/index.d.ts.map +0 -1
- package/src/auth/index.js +0 -10
- package/src/components/ApiAccess.d.ts +0 -16
- package/src/components/ApiAccess.d.ts.map +0 -1
- package/src/components/ApiAccess.js +0 -77
- package/src/components/BackupCodeLoginForm.d.ts +0 -43
- package/src/components/BackupCodeLoginForm.d.ts.map +0 -1
- package/src/components/BackupCodeLoginForm.js +0 -139
- package/src/components/BackupCodesForm.d.ts +0 -26
- package/src/components/BackupCodesForm.d.ts.map +0 -1
- package/src/components/BackupCodesForm.js +0 -120
- package/src/components/ChangePasswordForm.d.ts +0 -26
- package/src/components/ChangePasswordForm.d.ts.map +0 -1
- package/src/components/ChangePasswordForm.js +0 -78
- package/src/components/ConfirmationDialog.d.ts +0 -13
- package/src/components/ConfirmationDialog.d.ts.map +0 -1
- package/src/components/ConfirmationDialog.js +0 -10
- package/src/components/CurrencyCodeSelector.d.ts +0 -9
- package/src/components/CurrencyCodeSelector.d.ts.map +0 -1
- package/src/components/CurrencyCodeSelector.js +0 -31
- package/src/components/CurrencyInput.d.ts +0 -13
- package/src/components/CurrencyInput.d.ts.map +0 -1
- package/src/components/CurrencyInput.js +0 -22
- package/src/components/DashboardPage.d.ts +0 -8
- package/src/components/DashboardPage.d.ts.map +0 -1
- package/src/components/DashboardPage.js +0 -10
- package/src/components/DropdownMenu.d.ts +0 -9
- package/src/components/DropdownMenu.d.ts.map +0 -1
- package/src/components/DropdownMenu.js +0 -56
- package/src/components/ExpirationSecondsSelector.d.ts +0 -13
- package/src/components/ExpirationSecondsSelector.d.ts.map +0 -1
- package/src/components/ExpirationSecondsSelector.js +0 -32
- package/src/components/Flag.d.ts +0 -20
- package/src/components/Flag.d.ts.map +0 -1
- package/src/components/Flag.js +0 -43
- package/src/components/ForgotPasswordForm.d.ts +0 -18
- package/src/components/ForgotPasswordForm.d.ts.map +0 -1
- package/src/components/ForgotPasswordForm.js +0 -61
- package/src/components/LoginForm.d.ts +0 -44
- package/src/components/LoginForm.d.ts.map +0 -1
- package/src/components/LoginForm.js +0 -122
- package/src/components/LogoutPage.d.ts +0 -8
- package/src/components/LogoutPage.d.ts.map +0 -1
- package/src/components/LogoutPage.js +0 -16
- package/src/components/RegisterForm.d.ts +0 -56
- package/src/components/RegisterForm.d.ts.map +0 -1
- package/src/components/RegisterForm.js +0 -140
- package/src/components/ResetPasswordForm.d.ts +0 -23
- package/src/components/ResetPasswordForm.d.ts.map +0 -1
- package/src/components/ResetPasswordForm.js +0 -78
- package/src/components/SideMenu.d.ts +0 -8
- package/src/components/SideMenu.d.ts.map +0 -1
- package/src/components/SideMenu.js +0 -25
- package/src/components/SideMenuListItem.d.ts +0 -13
- package/src/components/SideMenuListItem.d.ts.map +0 -1
- package/src/components/SideMenuListItem.js +0 -44
- package/src/components/TopMenu.d.ts +0 -24
- package/src/components/TopMenu.d.ts.map +0 -1
- package/src/components/TopMenu.js +0 -35
- package/src/components/TranslatedTitle.d.ts +0 -7
- package/src/components/TranslatedTitle.d.ts.map +0 -1
- package/src/components/TranslatedTitle.js +0 -15
- package/src/components/UserLanguageSelector.d.ts +0 -4
- package/src/components/UserLanguageSelector.d.ts.map +0 -1
- package/src/components/UserLanguageSelector.js +0 -31
- package/src/components/UserMenu.d.ts +0 -4
- package/src/components/UserMenu.d.ts.map +0 -1
- package/src/components/UserMenu.js +0 -12
- package/src/components/UserSettingsForm.d.ts +0 -57
- package/src/components/UserSettingsForm.d.ts.map +0 -1
- package/src/components/UserSettingsForm.js +0 -126
- package/src/components/VerifyEmailPage.d.ts +0 -23
- package/src/components/VerifyEmailPage.d.ts.map +0 -1
- package/src/components/VerifyEmailPage.js +0 -70
- package/src/components/index.d.ts.map +0 -1
- package/src/components/index.js +0 -28
- package/src/contexts/AuthProvider.d.ts +0 -152
- package/src/contexts/AuthProvider.d.ts.map +0 -1
- package/src/contexts/AuthProvider.js +0 -502
- package/src/contexts/I18nProvider.d.ts +0 -16
- package/src/contexts/I18nProvider.d.ts.map +0 -1
- package/src/contexts/I18nProvider.js +0 -46
- package/src/contexts/MenuContext.d.ts +0 -20
- package/src/contexts/MenuContext.d.ts.map +0 -1
- package/src/contexts/MenuContext.js +0 -273
- package/src/contexts/SuiteConfigProvider.d.ts +0 -44
- package/src/contexts/SuiteConfigProvider.d.ts.map +0 -1
- package/src/contexts/SuiteConfigProvider.js +0 -43
- package/src/contexts/ThemeProvider.d.ts +0 -15
- package/src/contexts/ThemeProvider.d.ts.map +0 -1
- package/src/contexts/ThemeProvider.js +0 -36
- package/src/contexts/index.d.ts.map +0 -1
- package/src/contexts/index.js +0 -8
- package/src/hooks/index.d.ts.map +0 -1
- package/src/hooks/index.js +0 -8
- package/src/hooks/useBackupCodes.d.ts +0 -15
- package/src/hooks/useBackupCodes.d.ts.map +0 -1
- package/src/hooks/useBackupCodes.js +0 -74
- package/src/hooks/useEmailVerification.d.ts +0 -10
- package/src/hooks/useEmailVerification.d.ts.map +0 -1
- package/src/hooks/useEmailVerification.js +0 -40
- package/src/hooks/useExpiringValue.d.ts +0 -14
- package/src/hooks/useExpiringValue.d.ts.map +0 -1
- package/src/hooks/useExpiringValue.js +0 -53
- package/src/hooks/useLocalStorage.d.ts +0 -2
- package/src/hooks/useLocalStorage.d.ts.map +0 -1
- package/src/hooks/useLocalStorage.js +0 -15
- package/src/hooks/useUserSettings.d.ts +0 -48
- package/src/hooks/useUserSettings.d.ts.map +0 -1
- package/src/hooks/useUserSettings.js +0 -169
- package/src/index.d.ts.map +0 -1
- package/src/index.js +0 -12
- package/src/interfaces/IAppConfig.d.ts +0 -6
- package/src/interfaces/IAppConfig.d.ts.map +0 -1
- package/src/interfaces/IAppConfig.js +0 -2
- package/src/interfaces/IMenuConfig.d.ts +0 -11
- package/src/interfaces/IMenuConfig.d.ts.map +0 -1
- package/src/interfaces/IMenuConfig.js +0 -2
- package/src/interfaces/IMenuOption.d.ts +0 -58
- package/src/interfaces/IMenuOption.d.ts.map +0 -1
- package/src/interfaces/IMenuOption.js +0 -2
- package/src/interfaces/index.d.ts +0 -4
- package/src/interfaces/index.d.ts.map +0 -1
- package/src/interfaces/index.js +0 -6
- package/src/services/__mocks__/authService.d.ts +0 -21
- package/src/services/__mocks__/authService.d.ts.map +0 -1
- package/src/services/__mocks__/authService.js +0 -15
- package/src/services/api.d.ts +0 -3
- package/src/services/api.d.ts.map +0 -1
- package/src/services/api.js +0 -14
- package/src/services/authService.d.ts +0 -72
- package/src/services/authService.d.ts.map +0 -1
- package/src/services/authService.js +0 -335
- package/src/services/authenticatedApi.d.ts +0 -3
- package/src/services/authenticatedApi.d.ts.map +0 -1
- package/src/services/authenticatedApi.js +0 -18
- package/src/services/index.d.ts +0 -4
- package/src/services/index.d.ts.map +0 -1
- package/src/services/index.js +0 -6
- package/src/types/MenuType.d.ts +0 -11
- package/src/types/MenuType.d.ts.map +0 -1
- package/src/types/MenuType.js +0 -12
- package/src/types/expirationSeconds.d.ts +0 -3
- package/src/types/expirationSeconds.d.ts.map +0 -1
- package/src/types/expirationSeconds.js +0 -17
- package/src/types/index.d.ts +0 -2
- package/src/types/index.d.ts.map +0 -1
- package/src/types/index.js +0 -4
- package/src/types/translation.d.ts +0 -10
- package/src/types/translation.d.ts.map +0 -1
- package/src/types/translation.js +0 -9
- package/src/wrappers/BackupCodeLoginWrapper.d.ts +0 -8
- package/src/wrappers/BackupCodeLoginWrapper.d.ts.map +0 -1
- package/src/wrappers/BackupCodeLoginWrapper.js +0 -20
- package/src/wrappers/BackupCodesWrapper.d.ts +0 -7
- package/src/wrappers/BackupCodesWrapper.d.ts.map +0 -1
- package/src/wrappers/BackupCodesWrapper.js +0 -17
- package/src/wrappers/ChangePasswordFormWrapper.d.ts +0 -8
- package/src/wrappers/ChangePasswordFormWrapper.d.ts.map +0 -1
- package/src/wrappers/ChangePasswordFormWrapper.js +0 -21
- package/src/wrappers/LoginFormWrapper.d.ts +0 -9
- package/src/wrappers/LoginFormWrapper.d.ts.map +0 -1
- package/src/wrappers/LoginFormWrapper.js +0 -43
- package/src/wrappers/LogoutPageWrapper.d.ts +0 -9
- package/src/wrappers/LogoutPageWrapper.d.ts.map +0 -1
- package/src/wrappers/LogoutPageWrapper.js +0 -21
- package/src/wrappers/RegisterFormWrapper.d.ts +0 -9
- package/src/wrappers/RegisterFormWrapper.d.ts.map +0 -1
- package/src/wrappers/RegisterFormWrapper.js +0 -31
- package/src/wrappers/UserSettingsFormWrapper.d.ts +0 -8
- package/src/wrappers/UserSettingsFormWrapper.d.ts.map +0 -1
- package/src/wrappers/UserSettingsFormWrapper.js +0 -24
- package/src/wrappers/VerifyEmailPageWrapper.d.ts +0 -8
- package/src/wrappers/VerifyEmailPageWrapper.d.ts.map +0 -1
- package/src/wrappers/VerifyEmailPageWrapper.js +0 -20
- package/src/wrappers/index.d.ts.map +0 -1
- package/src/wrappers/index.js +0 -20
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Digital Defiance, Jessica Mulein
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitaldefiance/express-suite-react-components",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.38",
|
|
4
4
|
"homepage": "https://github.com/Digital-Defiance/react-components",
|
|
5
5
|
"description": "React MUI components for Digital Defiance Express Suite",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@digitaldefiance/i18n-lib": "3.8.16",
|
|
34
|
-
"@digitaldefiance/suite-core-lib": "3.6.
|
|
34
|
+
"@digitaldefiance/suite-core-lib": "3.6.49",
|
|
35
35
|
"@emotion/react": "^11.14.0",
|
|
36
36
|
"@emotion/styled": "^11.14.0",
|
|
37
37
|
"@mui/icons-material": "^7.0.2",
|
|
@@ -73,6 +73,5 @@
|
|
|
73
73
|
],
|
|
74
74
|
"author": "Digital Defiance",
|
|
75
75
|
"license": "MIT",
|
|
76
|
-
"packageManager": "yarn@4.10.3"
|
|
77
|
-
|
|
78
|
-
}
|
|
76
|
+
"packageManager": "yarn@4.10.3"
|
|
77
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FC, ReactNode, useContext } from 'react';
|
|
2
|
+
import { AuthContext } from '../contexts/AuthProvider';
|
|
3
|
+
export interface PrivateProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const Private: FC<PrivateProps> = ({
|
|
8
|
+
children,
|
|
9
|
+
}) => {
|
|
10
|
+
const { isAuthenticated, isCheckingAuth } = useContext(AuthContext);
|
|
11
|
+
|
|
12
|
+
if (isCheckingAuth || !isAuthenticated) {
|
|
13
|
+
return <></>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return <>{children}</>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FC, ReactNode, useContext } from 'react';
|
|
2
|
+
import { Navigate, useLocation } from 'react-router-dom';
|
|
3
|
+
import { AuthContext } from '../contexts/AuthProvider';
|
|
4
|
+
import { useI18n } from '../contexts';
|
|
5
|
+
import { SuiteCoreComponentId, SuiteCoreStringKey } from '@digitaldefiance/suite-core-lib';
|
|
6
|
+
|
|
7
|
+
interface PrivateRouteProps {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
redirectTo?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const PrivateRoute: FC<PrivateRouteProps> = ({ children, redirectTo }) => {
|
|
13
|
+
const { tComponent } = useI18n();
|
|
14
|
+
const { isAuthenticated, isCheckingAuth } = useContext(AuthContext);
|
|
15
|
+
const location = useLocation();
|
|
16
|
+
|
|
17
|
+
if (isCheckingAuth) {
|
|
18
|
+
return <div>{tComponent<SuiteCoreStringKey>(SuiteCoreComponentId, SuiteCoreStringKey.Common_CheckingAuthentication)}...</div>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!isAuthenticated) {
|
|
22
|
+
return <Navigate to={redirectTo ?? "/login"} state={{ from: location }} replace />;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return <>{children}</>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default PrivateRoute;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FC, ReactNode, useContext } from 'react';
|
|
2
|
+
import { AuthContext } from '../contexts/AuthProvider';
|
|
3
|
+
|
|
4
|
+
export interface UnAuthProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const UnAuth: FC<UnAuthProps> = ({ children }) => {
|
|
9
|
+
const { isAuthenticated, isCheckingAuth } = useContext(AuthContext);
|
|
10
|
+
|
|
11
|
+
if (isCheckingAuth || isAuthenticated) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return <>{children}</>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FC, ReactNode, useContext } from 'react';
|
|
2
|
+
import { Navigate, useLocation } from 'react-router-dom';
|
|
3
|
+
import { AuthContext, useI18n } from '../contexts';
|
|
4
|
+
import { SuiteCoreComponentId, SuiteCoreStringKey } from '@digitaldefiance/suite-core-lib';
|
|
5
|
+
|
|
6
|
+
export interface UnAuthRouteProps {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
redirectTo?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const UnAuthRoute: FC<UnAuthRouteProps> = ({
|
|
12
|
+
children,
|
|
13
|
+
redirectTo = '/dashboard',
|
|
14
|
+
}) => {
|
|
15
|
+
const { isAuthenticated, isCheckingAuth } = useContext(AuthContext);
|
|
16
|
+
const { tComponent } = useI18n();
|
|
17
|
+
const location = useLocation();
|
|
18
|
+
|
|
19
|
+
if (isCheckingAuth) {
|
|
20
|
+
return <div>{tComponent<SuiteCoreStringKey>(SuiteCoreComponentId, SuiteCoreStringKey.Common_CheckingAuthentication)}...</div>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (isAuthenticated) {
|
|
24
|
+
return <Navigate to={redirectTo ?? "/dashboard"} state={{ from: location }} replace />;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return <>{children}</>;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default UnAuthRoute;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SuiteCoreComponentId,
|
|
3
|
+
SuiteCoreStringKey,
|
|
4
|
+
} from '@digitaldefiance/suite-core-lib';
|
|
5
|
+
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
|
|
6
|
+
import {
|
|
7
|
+
Box,
|
|
8
|
+
Button,
|
|
9
|
+
Dialog,
|
|
10
|
+
DialogActions,
|
|
11
|
+
DialogContent,
|
|
12
|
+
DialogTitle,
|
|
13
|
+
styled,
|
|
14
|
+
TextField,
|
|
15
|
+
Typography,
|
|
16
|
+
} from '@mui/material';
|
|
17
|
+
import { FC, useState } from 'react';
|
|
18
|
+
import { useAuth, useI18n } from '../contexts';
|
|
19
|
+
|
|
20
|
+
const ApiAccessContainer = styled(Box)(({ theme }) => ({
|
|
21
|
+
display: 'flex',
|
|
22
|
+
flexDirection: 'column',
|
|
23
|
+
alignItems: 'center',
|
|
24
|
+
justifyContent: 'center',
|
|
25
|
+
minHeight: '100vh',
|
|
26
|
+
backgroundColor: theme.palette.background.default,
|
|
27
|
+
padding: theme.spacing(3),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
const ApiAccessContent = styled(Box)(({ theme }) => ({
|
|
31
|
+
maxWidth: '600px',
|
|
32
|
+
width: '100%',
|
|
33
|
+
backgroundColor: theme.palette.background.paper,
|
|
34
|
+
borderRadius: theme.shape.borderRadius,
|
|
35
|
+
padding: theme.spacing(4),
|
|
36
|
+
boxShadow: theme.shadows[3],
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
const ApiAccessTitle = styled(Typography)(({ theme }) => ({
|
|
40
|
+
marginBottom: theme.spacing(3),
|
|
41
|
+
color: theme.palette.primary.main,
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
export interface ApiAccessProps {
|
|
45
|
+
token?: string | null;
|
|
46
|
+
labels?: {
|
|
47
|
+
title?: string;
|
|
48
|
+
tokenNotAvailable?: string;
|
|
49
|
+
copyButton?: string;
|
|
50
|
+
notificationTitle?: string;
|
|
51
|
+
copied?: string;
|
|
52
|
+
copyFailed?: string;
|
|
53
|
+
ok?: string;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const ApiAccess: FC<ApiAccessProps> = ({
|
|
58
|
+
token: tokenProp,
|
|
59
|
+
labels = {},
|
|
60
|
+
}) => {
|
|
61
|
+
const { token: authToken } = useAuth();
|
|
62
|
+
const token = tokenProp !== undefined ? tokenProp : authToken;
|
|
63
|
+
const { tComponent } = useI18n();
|
|
64
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
65
|
+
const [isError, setIsError] = useState(false);
|
|
66
|
+
|
|
67
|
+
const translatedLabels = {
|
|
68
|
+
title:
|
|
69
|
+
labels.title ||
|
|
70
|
+
tComponent<SuiteCoreStringKey>(
|
|
71
|
+
SuiteCoreComponentId,
|
|
72
|
+
SuiteCoreStringKey.ApiAccess_Title
|
|
73
|
+
),
|
|
74
|
+
tokenNotAvailable:
|
|
75
|
+
labels.tokenNotAvailable ||
|
|
76
|
+
tComponent<SuiteCoreStringKey>(
|
|
77
|
+
SuiteCoreComponentId,
|
|
78
|
+
SuiteCoreStringKey.ApiAccess_TokenNotAvailable
|
|
79
|
+
),
|
|
80
|
+
copyButton:
|
|
81
|
+
labels.copyButton ||
|
|
82
|
+
tComponent<SuiteCoreStringKey>(
|
|
83
|
+
SuiteCoreComponentId,
|
|
84
|
+
SuiteCoreStringKey.Common_CopyToClipboard
|
|
85
|
+
),
|
|
86
|
+
notificationTitle:
|
|
87
|
+
labels.notificationTitle ||
|
|
88
|
+
tComponent<SuiteCoreStringKey>(
|
|
89
|
+
SuiteCoreComponentId,
|
|
90
|
+
SuiteCoreStringKey.Common_Notification
|
|
91
|
+
),
|
|
92
|
+
copied:
|
|
93
|
+
labels.copied ||
|
|
94
|
+
tComponent<SuiteCoreStringKey>(
|
|
95
|
+
SuiteCoreComponentId,
|
|
96
|
+
SuiteCoreStringKey.Common_CopiedToClipboard
|
|
97
|
+
),
|
|
98
|
+
copyFailed:
|
|
99
|
+
labels.copyFailed ||
|
|
100
|
+
tComponent<SuiteCoreStringKey>(
|
|
101
|
+
SuiteCoreComponentId,
|
|
102
|
+
SuiteCoreStringKey.Error_FailedToCopy
|
|
103
|
+
),
|
|
104
|
+
ok:
|
|
105
|
+
labels.ok ||
|
|
106
|
+
tComponent<SuiteCoreStringKey>(
|
|
107
|
+
SuiteCoreComponentId,
|
|
108
|
+
SuiteCoreStringKey.Common_OK
|
|
109
|
+
),
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const copyToClipboard = async () => {
|
|
113
|
+
if (token) {
|
|
114
|
+
try {
|
|
115
|
+
await navigator.clipboard.writeText(token);
|
|
116
|
+
setIsError(false);
|
|
117
|
+
setDialogOpen(true);
|
|
118
|
+
} catch {
|
|
119
|
+
setIsError(true);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const handleClose = () => {
|
|
125
|
+
setDialogOpen(false);
|
|
126
|
+
setIsError(false);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<ApiAccessContainer>
|
|
131
|
+
<ApiAccessContent>
|
|
132
|
+
<ApiAccessTitle variant="h4" align="center">
|
|
133
|
+
{translatedLabels.title}
|
|
134
|
+
</ApiAccessTitle>
|
|
135
|
+
<TextField
|
|
136
|
+
fullWidth
|
|
137
|
+
multiline
|
|
138
|
+
rows={4}
|
|
139
|
+
value={token || translatedLabels.tokenNotAvailable}
|
|
140
|
+
slotProps={{
|
|
141
|
+
input: {
|
|
142
|
+
readOnly: true,
|
|
143
|
+
},
|
|
144
|
+
}}
|
|
145
|
+
variant="outlined"
|
|
146
|
+
margin="normal"
|
|
147
|
+
/>
|
|
148
|
+
<Button
|
|
149
|
+
variant="contained"
|
|
150
|
+
color="primary"
|
|
151
|
+
startIcon={<ContentCopyIcon />}
|
|
152
|
+
onClick={copyToClipboard}
|
|
153
|
+
fullWidth
|
|
154
|
+
style={{ marginTop: '16px' }}
|
|
155
|
+
>
|
|
156
|
+
{translatedLabels.copyButton}
|
|
157
|
+
</Button>
|
|
158
|
+
</ApiAccessContent>
|
|
159
|
+
<Dialog open={dialogOpen} onClose={handleClose}>
|
|
160
|
+
<DialogTitle>{translatedLabels.notificationTitle}</DialogTitle>
|
|
161
|
+
<DialogContent>
|
|
162
|
+
{isError ? translatedLabels.copyFailed : translatedLabels.copied}
|
|
163
|
+
</DialogContent>
|
|
164
|
+
<DialogActions>
|
|
165
|
+
<Button onClick={handleClose} color="primary">
|
|
166
|
+
{translatedLabels.ok}
|
|
167
|
+
</Button>
|
|
168
|
+
</DialogActions>
|
|
169
|
+
</Dialog>
|
|
170
|
+
</ApiAccessContainer>
|
|
171
|
+
);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export default ApiAccess;
|