PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.6.6
LatePoint – Calendar Booking Plugin for Appointments and Events v5.6.6
5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / blocks / src / book-form / edit.js
latepoint / blocks / src / book-form Last commit date
block.json 3 weeks ago edit.js 1 week ago index-min.js 1 year ago index.js 1 year ago save.js 1 year ago
edit.js
420 lines
1 /**
2 * External dependencies
3 */
4 import styled from '@emotion/styled';
5
6 /**
7 * WordPress components that create the necessary UI elements for the block
8 *
9 * @see https://developer.wordpress.org/block-editor/packages/packages-components/
10 */
11 import {registerBlockType} from '@wordpress/blocks';
12 import {__} from '@wordpress/i18n';
13 import {
14 TextControl,
15 Button,
16 SelectControl,
17 ToggleControl,
18 FontSizePicker,
19 ColorIndicator,
20 Dropdown,
21 DropdownContentWrapper,
22 ColorPalette,
23 Flex,
24 FlexBlock,
25 __experimentalGrid as Grid,
26 __experimentalToggleGroupControl as ToggleGroupControl,
27 __experimentalToggleGroupControlOption as ToggleGroupControlOption
28 } from '@wordpress/components';
29
30 import {
31 __experimentalBoxControl as BoxControl,
32 __experimentalToolsPanel as ToolsPanel,
33 __experimentalToolsPanelItem as ToolsPanelItem,
34 __experimentalUnitControl as UnitControl,
35 } from '@wordpress/components';
36
37 import {Panel, PanelBody, PanelRow} from '@wordpress/components';
38 import {useState} from '@wordpress/element';
39
40
41 /**
42 * React hook that is used to mark the block wrapper element.
43 * It provides all the necessary props like the class name.
44 *
45 * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
46 */
47 import {
48 useBlockProps,
49 InspectorControls,
50 } from '@wordpress/block-editor';
51
52 import IframeEmotionCacheProvider from '../utils/IframeEmotionCacheProvider';
53
54 const LatepointBookFormWrapper = styled.div`
55 display: flex;
56 justify-content: space-around;
57 `;
58
59 const LatepointBookForm = styled.div`
60 display: flex;
61 box-shadow: 0px 2px 4px -1px rgba(0,0,0,0.1);
62 border-radius: 4px;
63 border: 1px solid #ddd;
64 border-bottom-color: #bbb;
65 background-color: #fff;
66 flex: 0;
67 `;
68
69 const SidePanel = styled.div`
70 flex: 0 0 180px;
71 width: 180px;
72 padding: 20px;
73 display: flex;
74 flex-direction: column;
75 gap: 40px;
76 border-right: 1px solid #eee;
77 `;
78
79 const StepSideImage = styled.div`
80 width: 40px;
81 height: 40px;
82 border-radius: 50%;
83 background-color: #eee;
84 margin: 0px auto;
85 `;
86
87 const StepSideContent = styled.div`
88 `;
89
90 const StepSideName = styled.div`
91 padding: 10px;
92 border-radius: 4px;
93 background-color: #eee;
94 margin-bottom: 10px;
95 `;
96
97 const StepSideDescription = styled.div`
98 padding: 20px;
99 border-radius: 4px;
100 background-color: #f8f8f8;
101 margin-bottom: 20px;
102 `;
103
104 const StepSideExtra = styled.div`
105 padding: 10px;
106 border-radius: 4px;
107 background-color: #f8f8f8;
108 `;
109
110
111 const MainPanel = styled.div`
112 padding: 20px;
113 flex: 1;
114 display: flex;
115 flex-direction: column;
116 justify-content: flex-start;
117 max-width: 400px;
118 `;
119 const StepMainName = styled.div`
120 padding: 10px;
121 border-radius: 4px;
122 background-color: #eee;
123 `;
124 const StepContent = styled.div`
125 display: flex;
126 gap: 20px;
127 margin-top: 15px;
128 padding-top: 15px;
129 border-top: 1px solid #eee;
130 margin-bottom: auto;
131 `;
132
133 const StepContentTile = styled.div`
134 padding: 40px;
135 border-radius: 4px;
136 background-color: #f8f8f8;
137 flex: 1;
138 `;
139
140 const StepButtons = styled.div`
141 margin-top: auto;
142 border-top: 1px solid #eee;
143 padding-top: 15px;
144 margin-top: 15px;
145 display: flex;
146 justify-content: space-between;
147 `;
148
149 const StepButtonPrev = styled.div`
150 padding: 10px 25px;
151 background-color: #eee;
152 border-radius: 4px;
153 `;
154
155 const StepButtonNext = styled.div`
156 padding: 10px 25px;
157 background-color: #b4c6f5;
158 border-radius: 4px;
159 `;
160
161 const SummaryPanel = styled.div`
162 flex: 0 0 180px;
163 width: 180px;
164 border-left: 1px solid #eee;
165 padding: 20px;
166 display: flex;
167 flex-direction: column;
168 `;
169
170 const SummaryHeading = styled.div`
171 padding: 10px;
172 border-radius: 4px;
173 background-color: #eee;
174 `;
175
176 const SummaryContent = styled.div`
177 border-top: 1px solid #eee;
178 margin-top: 15px;
179 padding-top: 15px;
180 `;
181 const SummaryTile = styled.div`
182 padding: 5px;
183 border-radius: 4px;
184 background-color: #f8f8f8;
185 margin-bottom: 10px;
186 `;
187 const SummaryFoot = styled.div`
188 margin-top: auto;
189 border-top: 1px solid #eee;
190 padding-top: 15px;
191 `;
192 const SummaryTotal = styled.div`
193 padding: 10px;
194 border-radius: 4px;
195 background-color: #eee;
196 `;
197
198
199 const ColorAttributesWrapper = styled.div`
200 margin-bottom: 15px;
201 border: 1px solid #eee;
202 `;
203
204 const PanelRowBlock = styled(PanelRow)`
205 display:block;
206 margin-bottom: 20px;
207 `;
208
209 const SingleColumnItem = styled(ToolsPanelItem)`
210 grid-column: span 1;
211 `;
212
213
214 /**
215 * The edit function describes the structure of your block in the context of the
216 * editor. This represents what the editor will render when the block is used.
217 *
218 * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit
219 *
220 * @param {Object} props Properties passed to the function.
221 * @param {Object} props.attributes Available block attributes.
222 * @param {Function} props.setAttributes Function that updates individual attributes.
223 *
224 * @return {WPElement} Element to render.
225 */
226 export default function Edit({attributes, setAttributes}) {
227 const blockProps = useBlockProps();
228
229 const colors = [
230 {
231 "name": "Black",
232 "color": "#000000"
233 },
234 {
235 "name": "White",
236 "color": "#ffffff"
237 },
238 {
239 "name": "Blue",
240 "color": "#5376ea"
241 }
242 ]
243
244 const renderTextColorPicker = () => (
245 <ColorPalette
246 value={attributes.text_color}
247 colors={colors}
248 onChange={(color) => setAttributes({text_color: color})}
249 />
250 );
251
252 const renderBgColorPicker = () => (
253 <ColorPalette
254 value={attributes.bg_color}
255 colors={colors}
256 onChange={(color) => setAttributes({bg_color: color})}
257 />
258 );
259
260 const generateStyles = () => {
261 let styles = {}
262 if (attributes.border_radius) styles.borderRadius = attributes.border_radius
263 if (attributes.bg_color) styles.backgroundColor = attributes.bg_color
264 if (attributes.text_color) styles.color = attributes.text_color
265 if (attributes.font_size) styles.fontSize = attributes.font_size
266 return styles
267 }
268
269
270 return (
271 <div {...blockProps}>
272 <InspectorControls>
273 <Panel>
274 <PanelBody title="Booking Form Settings">
275 <ToggleControl __nextHasNoMarginBottom
276 label="Hide Summary Panel"
277 checked={attributes.hide_summary}
278 onChange={(value) => setAttributes({hide_summary: value})}
279 />
280 <ToggleControl __nextHasNoMarginBottom
281 label="Hide Side Panel"
282 checked={attributes.hide_side_panel}
283 onChange={(value) => setAttributes({hide_side_panel: value})}
284 />
285 </PanelBody>
286 </Panel>
287 <Panel>
288 <PanelBody title="Step Settings" initialOpen={false}>
289 <SelectControl __nextHasNoMarginBottom __next40pxDefaultSize
290 label={__('Preselected Agent', 'latepoint')}
291 value={attributes.selected_agent}
292 onChange={(value) => setAttributes({selected_agent: value})}
293 options={latepoint_helper.selected_agents_options}
294 />
295 <SelectControl __nextHasNoMarginBottom __next40pxDefaultSize
296 label={__('Preselected Service', 'latepoint')}
297 value={attributes.selected_service}
298 onChange={(value) => setAttributes({selected_service: value})}
299 options={latepoint_helper.selected_services_options}
300 />
301 <SelectControl __nextHasNoMarginBottom __next40pxDefaultSize
302 label={__('Preselected Service Category', 'latepoint')}
303 value={attributes.selected_service_category}
304 onChange={(value) => setAttributes({selected_service_category: value})}
305 options={latepoint_helper.selected_service_categories_options}
306 />
307 <SelectControl __nextHasNoMarginBottom __next40pxDefaultSize
308 label={__('Preselected Location', 'latepoint')}
309 value={attributes.selected_location}
310 onChange={(value) => setAttributes({selected_location: value})}
311 options={latepoint_helper.selected_locations_options}
312 />
313 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
314 label={__('Preselected Booking Start Date', 'latepoint')}
315 value={attributes.selected_start_date || ''}
316 placeholder="YYYY-MM-DD"
317 onChange={(value) => setAttributes({selected_start_date: value})}
318 />
319 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
320 label={__('Preselected Booking Start Time', 'latepoint')}
321 value={attributes.selected_start_time || ''}
322 placeholder="Minutes"
323 onChange={(value) => setAttributes({selected_start_time: value})}
324 />
325 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
326 label={__('Preselected Duration', 'latepoint')}
327 value={attributes.selected_duration || ''}
328 placeholder="Minutes"
329 onChange={(value) => setAttributes({selected_duration: value})}
330 />
331 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
332 label={__('Preselected Total Attendees', 'latepoint')}
333 value={attributes.selected_total_attendees || ''}
334 placeholder="Number"
335 onChange={(value) => setAttributes({selected_total_attendees: value})}
336 />
337 </PanelBody>
338 </Panel>
339 <Panel>
340 <PanelBody title="Other Settings" initialOpen={false}>
341 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
342 label="Source ID"
343 value={attributes.source_id || ''}
344 onChange={(value) => setAttributes({source_id: value})}
345 />
346 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
347 label="Calendar Start Date"
348 value={attributes.calendar_start_date || ''}
349 placeholder="YYYY-MM-DD"
350 onChange={(value) => setAttributes({calendar_start_date: value})}
351 />
352 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
353 label="Show Services"
354 placeholder="Comma separated service IDs"
355 value={attributes.show_services || ''}
356 onChange={(value) => setAttributes({show_services: value})}
357 />
358 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
359 label="Show Service Categories"
360 placeholder="Comma separated category IDs"
361 value={attributes.show_service_categories || ''}
362 onChange={(value) => setAttributes({show_service_categories: value})}
363 />
364 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
365 label="Show Agents"
366 placeholder="Comma separated agent IDs"
367 value={attributes.show_agents || ''}
368 onChange={(value) => setAttributes({show_agents: value})}
369 />
370 <TextControl __nextHasNoMarginBottom __next40pxDefaultSize
371 label="Show Locations"
372 placeholder="Comma separated location IDs"
373 value={attributes.show_locations || ''}
374 onChange={(value) => setAttributes({show_locations: value})}
375 />
376 </PanelBody>
377 </Panel>
378 </InspectorControls>
379 <IframeEmotionCacheProvider>
380 <LatepointBookFormWrapper>
381 <LatepointBookForm style={generateStyles()}>
382 {!attributes.hide_side_panel && <SidePanel>
383 <StepSideImage></StepSideImage>
384 <StepSideContent>
385 <StepSideName></StepSideName>
386 <StepSideDescription></StepSideDescription>
387 </StepSideContent>
388 <StepSideExtra></StepSideExtra>
389 </SidePanel>}
390 <MainPanel>
391 <StepMainName></StepMainName>
392 <StepContent>
393 <StepContentTile></StepContentTile>
394 <StepContentTile></StepContentTile>
395 <StepContentTile></StepContentTile>
396 </StepContent>
397 <StepButtons>
398 <StepButtonPrev></StepButtonPrev>
399 <StepButtonNext></StepButtonNext>
400 </StepButtons>
401 </MainPanel>
402 {!attributes.hide_summary && <SummaryPanel>
403 <SummaryHeading></SummaryHeading>
404 <SummaryContent>
405 <SummaryTile></SummaryTile>
406 <SummaryTile></SummaryTile>
407 <SummaryTile></SummaryTile>
408 <SummaryTile></SummaryTile>
409 </SummaryContent>
410 <SummaryFoot>
411 <SummaryTotal></SummaryTotal>
412 </SummaryFoot>
413 </SummaryPanel>}
414 </LatepointBookForm>
415 </LatepointBookFormWrapper>
416 </IframeEmotionCacheProvider>
417 </div>
418 );
419 }
420