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