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

134 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 { useGetEmbedder } from '../../utils/useGetEmbedder';
15
16 interface IElementorMeetingSelectProps {
17 url: string;
18 setAttributes: Function;
19 }
20
21 function ElementorMeetingSelect({
22 url,
23 setAttributes,
24 }: IElementorMeetingSelectProps) {
25 const {
26 mappedMeetings: meetings,
27 loading,
28 error,
29 reload,
30 connectCalendar,
31 } = useMeetings();
32 const selectedMeetingCalendar = useSelectedMeetingCalendar(url);
33 const [localUrl, setLocalUrl] = useState(url);
34
35 const handleConnectCalendar = () => {
36 return connectCalendar()
37 .then(() => {
38 reload();
39 })
40 .catch(error => {
41 Raven.captureMessage('Unable to connect calendar', {
42 extra: { error },
43 });
44 });
45 };
46
47 return (
48 <Fragment>
49 {loading ? (
50 <div>
51 <UISpinner />
52 </div>
53 ) : error ? (
54 <ElementorBanner type="danger">
55 {__(
56 'Please refresh your meetings or try again in a few minutes',
57 'leadin'
58 )}
59 </ElementorBanner>
60 ) : (
61 <Fragment>
62 {selectedMeetingCalendar && (
63 <ElementorMeetingWarning
64 status={selectedMeetingCalendar}
65 onConnectCalendar={connectCalendar}
66 />
67 )}
68 {meetings.length > 1 && (
69 <select
70 value={localUrl}
71 onChange={event => {
72 const newUrl = event.target.value;
73 setLocalUrl(newUrl);
74 setAttributes({
75 url: newUrl,
76 });
77 }}
78 >
79 <option value="" disabled={true} selected={true}>
80 {__('Select a meeting', 'leadin')}
81 </option>
82 {meetings.map(item => (
83 <option key={item.value} value={item.value}>
84 {item.label}
85 </option>
86 ))}
87 </select>
88 )}
89 </Fragment>
90 )}
91 </Fragment>
92 );
93 }
94
95 function ElementorMeetingSelectWrapper(props: IElementorMeetingSelectProps) {
96 const isBackgroundAppReady = useBackgroundAppContext();
97
98 return (
99 <Fragment>
100 {!isBackgroundAppReady ? (
101 <div>
102 <UISpinner />
103 </div>
104 ) : (
105 <ElementorMeetingSelect {...props} />
106 )}
107 </Fragment>
108 );
109 }
110
111 export default function ElementorMeetingsSelectContainer(
112 props: IElementorMeetingSelectProps
113 ) {
114 const { embedder, errorElement, isLoading } = useGetEmbedder();
115
116 if (errorElement) {
117 return errorElement;
118 }
119
120 if (isLoading) {
121 return (
122 <div>
123 <UISpinner />
124 </div>
125 );
126 }
127
128 return (
129 <BackgroudAppContext.Provider value={embedder}>
130 <ElementorMeetingSelectWrapper {...props} />
131 </BackgroudAppContext.Provider>
132 );
133 }
134