PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.69
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.69
11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 11.1.22 All 72 releases
leadin / scripts / shared / Common / ErrorHandler.tsx

ErrorHandler.tsx in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.3.69, at scripts/shared/Common/ErrorHandler.tsx

56 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React from 'react';
2 import UIButton from '../UIComponents/UIButton';
3 import UIContainer from '../UIComponents/UIContainer';
4 import HubspotWrapper from './HubspotWrapper';
5 import { adminUrl, redirectNonce } from '../../constants/leadinConfig';
6 import { pluginPath } from '../../constants/leadinConfig';
7 import { __ } from '@wordpress/i18n';
8
9 interface IErrorHandlerProps {
10 status: number;
11 resetErrorState?: React.MouseEventHandler<HTMLButtonElement>;
12 errorInfo?: {
13 header: string;
14 message: string;
15 action: string;
16 };
17 }
18
19 function redirectToPlugin() {
20 window.location.href = `${adminUrl}admin.php?page=leadin&leadin_expired=${redirectNonce}`;
21 }
22
23 export default function ErrorHandler({
24 status,
25 resetErrorState,
26 errorInfo = { header: '', message: '', action: '' },
27 }: IErrorHandlerProps) {
28 const isUnauthorized = status === 401 || status === 403;
29 const errorHeader = isUnauthorized
30 ? __("Your plugin isn't authorized", 'leadin')
31 : errorInfo.header;
32 const errorMessage = isUnauthorized
33 ? __('Reauthorize your plugin to access your free HubSpot tools', 'leadin')
34 : errorInfo.message;
35
36 return (
37 <HubspotWrapper pluginPath={pluginPath}>
38 <UIContainer textAlign="center">
39 <h4>{errorHeader}</h4>
40 <p>
41 <b>{errorMessage}</b>
42 </p>
43 {isUnauthorized ? (
44 <UIButton data-test-id="authorize-button" onClick={redirectToPlugin}>
45 {__('Go to plugin', 'leadin')}
46 </UIButton>
47 ) : (
48 <UIButton data-test-id="retry-button" onClick={resetErrorState}>
49 {errorInfo.action}
50 </UIButton>
51 )}
52 </UIContainer>
53 </HubspotWrapper>
54 );
55 }
56