| 1 |
import React from 'react'; |
| 2 |
import * as WpBlocksApi from '@wordpress/blocks'; |
| 3 |
import CalendarIcon from '../Common/CalendarIcon'; |
| 4 |
import { connectionStatus } from '../../constants/leadinConfig'; |
| 5 |
import MeetingGutenbergPreview from './MeetingGutenbergPreview'; |
| 6 |
import MeetingSaveBlock from './MeetingSaveBlock'; |
| 7 |
import MeetingEdit from '../../shared/Meeting/MeetingEdit'; |
| 8 |
import ErrorHandler from '../../shared/Common/ErrorHandler'; |
| 9 |
import { __ } from '@wordpress/i18n'; |
| 10 |
import { isFullSiteEditor } from '../../utils/withMetaData'; |
| 11 |
|
| 12 |
const ConnectionStatus = { |
| 13 |
Connected: 'Connected', |
| 14 |
NotConnected: 'NotConnected', |
| 15 |
}; |
| 16 |
|
| 17 |
export interface IMeetingBlockAttributes { |
| 18 |
attributes: { |
| 19 |
url: string; |
| 20 |
preview?: boolean; |
| 21 |
}; |
| 22 |
} |
| 23 |
|
| 24 |
export interface IMeetingBlockProps extends IMeetingBlockAttributes { |
| 25 |
setAttributes: Function; |
| 26 |
isSelected: boolean; |
| 27 |
} |
| 28 |
|
| 29 |
export default function registerMeetingBlock() { |
| 30 |
const editComponent = (props: IMeetingBlockProps) => { |
| 31 |
if (props.attributes.preview) { |
| 32 |
return <MeetingGutenbergPreview />; |
| 33 |
} else if (connectionStatus === ConnectionStatus.Connected) { |
| 34 |
return <MeetingEdit {...props} preview={true} origin="gutenberg" />; |
| 35 |
} else { |
| 36 |
return <ErrorHandler status={401} />; |
| 37 |
} |
| 38 |
}; |
| 39 |
|
| 40 |
// We do not support the full site editor: https://issues.hubspotcentral.com/browse/WP-1033 |
| 41 |
if (!WpBlocksApi || isFullSiteEditor()) { |
| 42 |
return null; |
| 43 |
} |
| 44 |
|
| 45 |
WpBlocksApi.registerBlockType('leadin/hubspot-meeting-block', { |
| 46 |
title: __('Hubspot Meetings Scheduler', 'leadin'), |
| 47 |
description: __( |
| 48 |
'Schedule meetings faster and forget the back-and-forth emails Your calendar stays full, and you stay productive', |
| 49 |
'leadin' |
| 50 |
), |
| 51 |
icon: CalendarIcon, |
| 52 |
category: 'leadin-blocks', |
| 53 |
attributes: { |
| 54 |
url: { |
| 55 |
type: 'string', |
| 56 |
default: '', |
| 57 |
} as WpBlocksApi.BlockAttribute<string>, |
| 58 |
preview: { |
| 59 |
type: 'boolean', |
| 60 |
default: false, |
| 61 |
} as WpBlocksApi.BlockAttribute<boolean>, |
| 62 |
}, |
| 63 |
example: { |
| 64 |
attributes: { |
| 65 |
preview: true, |
| 66 |
}, |
| 67 |
}, |
| 68 |
edit: editComponent, |
| 69 |
save: props => <MeetingSaveBlock {...props} />, |
| 70 |
}); |
| 71 |
} |
| 72 |
|