1 | /** |
---|
2 | * External dependencies |
---|
3 | */ |
---|
4 | import { ActionPopover, Text } from '@automattic/jetpack-components'; |
---|
5 | import { useDispatch } from '@wordpress/data'; |
---|
6 | import { __ } from '@wordpress/i18n'; |
---|
7 | import { addQueryArgs } from '@wordpress/url'; |
---|
8 | /** |
---|
9 | * Internal dependencies |
---|
10 | */ |
---|
11 | import { STORE_ID } from '../../../state'; |
---|
12 | import useVideo from '../../hooks/use-video'; |
---|
13 | import useVideos from '../../hooks/use-videos'; |
---|
14 | import styles from './styles.module.scss'; |
---|
15 | /** |
---|
16 | * Types |
---|
17 | */ |
---|
18 | import { PublishFirstVideoPopoverProps } from './types'; |
---|
19 | import type React from 'react'; |
---|
20 | |
---|
21 | /** |
---|
22 | * Publish First Video Popover component |
---|
23 | * |
---|
24 | * @param {PublishFirstVideoPopoverProps} props - Component props. |
---|
25 | * @returns {React.ReactNode} - PublishFirstVideoPopover react component. |
---|
26 | */ |
---|
27 | const PublishFirstVideoPopover = ( { |
---|
28 | id, |
---|
29 | position = null, |
---|
30 | anchor = null, |
---|
31 | }: PublishFirstVideoPopoverProps ) => { |
---|
32 | const dispatch = useDispatch( STORE_ID ); |
---|
33 | const { data } = useVideo( Number( id ) ); |
---|
34 | const { firstUploadedVideoId, firstVideoProcessed, dismissedFirstVideoPopover } = useVideos(); |
---|
35 | const showAddToPostPopover = |
---|
36 | Number( firstUploadedVideoId ) === Number( id ) && |
---|
37 | firstVideoProcessed && |
---|
38 | ! dismissedFirstVideoPopover; |
---|
39 | |
---|
40 | const closePopover = () => dispatch.dismissFirstVideoPopover(); |
---|
41 | |
---|
42 | const nonce = window.jetpackVideoPressInitialState?.contentNonce ?? ''; |
---|
43 | const newPostURL = addQueryArgs( 'post-new.php', { |
---|
44 | videopress_guid: data.guid, |
---|
45 | _wpnonce: nonce, |
---|
46 | } ); |
---|
47 | |
---|
48 | return ( |
---|
49 | showAddToPostPopover && ( |
---|
50 | <ActionPopover |
---|
51 | title={ __( 'Publish your new video', 'jetpack-videopress-pkg' ) } |
---|
52 | buttonContent={ __( 'Add video to post', 'jetpack-videopress-pkg' ) } |
---|
53 | buttonHref={ newPostURL } |
---|
54 | buttonExternalLink |
---|
55 | anchor={ anchor } |
---|
56 | onClose={ closePopover } |
---|
57 | onClick={ closePopover } |
---|
58 | noArrow={ false } |
---|
59 | className={ styles[ 'action-popover' ] } |
---|
60 | position={ position } |
---|
61 | > |
---|
62 | <Text> |
---|
63 | { __( |
---|
64 | "Now that your video has been uploaded to VideoPress, it's time to show it to the world.", |
---|
65 | 'jetpack-videopress-pkg' |
---|
66 | ) } |
---|
67 | </Text> |
---|
68 | </ActionPopover> |
---|
69 | ) |
---|
70 | ); |
---|
71 | }; |
---|
72 | |
---|
73 | export default PublishFirstVideoPopover; |
---|