PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.0.7
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.0.7
11.3.75 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 All 73 releases
leadin / scripts / shared / Meeting / MeetingController.tsx

MeetingController.tsx in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.0.7, at scripts/shared/Meeting/MeetingController.tsx

96 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { Fragment, useEffect } from 'react';
2 import LoadingBlock from '../Common/LoadingBlock';
3 import MeetingSelector from './MeetingSelector';
4 import MeetingWarning from './MeetingWarning';
5 import useMeetings, {
6 useSelectedMeeting,
7 useSelectedMeetingCalendar,
8 } from './hooks/useMeetings';
9 import HubspotWrapper from '../Common/HubspotWrapper';
10 import ErrorHandler from '../Common/ErrorHandler';
11 import { pluginPath } from '../../constants/leadinConfig';
12 import { __ } from '@wordpress/i18n';
13 import Raven from 'raven-js';
14
15 interface IMeetingControllerProps {
16 url: string;
17 handleChange: Function;
18 }
19
20 export default function MeetingController({
21 handleChange,
22 url,
23 }: IMeetingControllerProps) {
24 const {
25 mappedMeetings: meetings,
26 loading,
27 error,
28 reload,
29 connectCalendar,
30 } = useMeetings();
31 const selectedMeetingOption = useSelectedMeeting(url);
32 const selectedMeetingCalendar = useSelectedMeetingCalendar(url);
33
34 useEffect(() => {
35 if (!url && meetings.length > 0) {
36 handleChange(meetings[0].value);
37 }
38 }, [meetings, url, handleChange]);
39
40 const handleLocalChange = (option: { value: string }) => {
41 handleChange(option.value);
42 };
43
44 const handleConnectCalendar = () => {
45 return connectCalendar()
46 .then(() => {
47 reload();
48 })
49 .catch(error => {
50 Raven.captureMessage('Unable to connect calendar', {
51 extra: { error },
52 });
53 });
54 };
55
56 return (
57 <Fragment>
58 {loading ? (
59 <LoadingBlock />
60 ) : error ? (
61 <ErrorHandler
62 status={(error && error.status) || error}
63 resetErrorState={() => reload()}
64 errorInfo={{
65 header: __(
66 'There was a problem retrieving your meetings',
67 'leadin'
68 ),
69 message: __(
70 'Please refresh your meetings or try again in a few minutes.',
71 'leadin'
72 ),
73 action: __('Refresh meetings', 'leadin'),
74 }}
75 />
76 ) : (
77 <HubspotWrapper padding="90px 32px 24px" pluginPath={pluginPath}>
78 {selectedMeetingCalendar && (
79 <MeetingWarning
80 status={selectedMeetingCalendar}
81 onConnectCalendar={handleConnectCalendar}
82 />
83 )}
84 {meetings.length > 1 && (
85 <MeetingSelector
86 onChange={handleLocalChange}
87 options={meetings}
88 value={selectedMeetingOption}
89 />
90 )}
91 </HubspotWrapper>
92 )}
93 </Fragment>
94 );
95 }
96