PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.1.13
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.1.13
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 / elementor / MeetingWidget / ElementorMeetingSelect.tsx

ElementorMeetingSelect.tsx in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.1.13, at scripts/elementor/MeetingWidget/ElementorMeetingSelect.tsx

123 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { Fragment, useState } from 'react';
2 import ElementorBanner from '../Common/ElementorBanner';
3 import UISpinner from '../../shared/UIComponents/UISpinner';
4 import ElementorMeetingWarning from './ElementorMeetingWarning';
5 import useMeetings, {
6 useSelectedMeetingCalendar,
7 } from '../../shared/Meeting/hooks/useMeetings';
8 import { __ } from '@wordpress/i18n';
9 import Raven from 'raven-js';
10 import {
11 BackgroudAppContext,
12 useBackgroundAppContext,
13 } from '../../iframe/useBackgroundApp';
14 import { refreshToken } from '../../constants/leadinConfig';
15 import { getOrCreateBackgroundApp } from '../../utils/backgroundAppUtils';
16
17 interface IElementorMeetingSelectProps {
18 url: string;
19 setAttributes: Function;
20 }
21
22 function ElementorMeetingSelect({
23 url,
24 setAttributes,
25 }: IElementorMeetingSelectProps) {
26 const {
27 mappedMeetings: meetings,
28 loading,
29 error,
30 reload,
31 connectCalendar,
32 } = useMeetings();
33 const selectedMeetingCalendar = useSelectedMeetingCalendar(url);
34 const [localUrl, setLocalUrl] = useState(url);
35
36 const handleConnectCalendar = () => {
37 return connectCalendar()
38 .then(() => {
39 reload();
40 })
41 .catch(error => {
42 Raven.captureMessage('Unable to connect calendar', {
43 extra: { error },
44 });
45 });
46 };
47
48 return (
49 <Fragment>
50 {loading ? (
51 <div>
52 <UISpinner />
53 </div>
54 ) : error ? (
55 <ElementorBanner type="danger">
56 {__(
57 'Please refresh your meetings or try again in a few minutes',
58 'leadin'
59 )}
60 </ElementorBanner>
61 ) : (
62 <Fragment>
63 {selectedMeetingCalendar && (
64 <ElementorMeetingWarning
65 status={selectedMeetingCalendar}
66 onConnectCalendar={connectCalendar}
67 />
68 )}
69 {meetings.length > 1 && (
70 <select
71 value={localUrl}
72 onChange={event => {
73 const newUrl = event.target.value;
74 setLocalUrl(newUrl);
75 setAttributes({
76 url: newUrl,
77 });
78 }}
79 >
80 <option value="" disabled={true} selected={true}>
81 {__('Select a meeting', 'leadin')}
82 </option>
83 {meetings.map(item => (
84 <option key={item.value} value={item.value}>
85 {item.label}
86 </option>
87 ))}
88 </select>
89 )}
90 </Fragment>
91 )}
92 </Fragment>
93 );
94 }
95
96 function ElementorMeetingSelectWrapper(props: IElementorMeetingSelectProps) {
97 const isBackgroundAppReady = useBackgroundAppContext();
98
99 return (
100 <Fragment>
101 {!isBackgroundAppReady ? (
102 <div>
103 <UISpinner />
104 </div>
105 ) : (
106 <ElementorMeetingSelect {...props} />
107 )}
108 </Fragment>
109 );
110 }
111
112 export default function ElementorMeetingsSelectContainer(
113 props: IElementorMeetingSelectProps
114 ) {
115 return (
116 <BackgroudAppContext.Provider
117 value={refreshToken && getOrCreateBackgroundApp(refreshToken)}
118 >
119 <ElementorMeetingSelectWrapper {...props} />
120 </BackgroudAppContext.Provider>
121 );
122 }
123