/** * "On your website": a campaign's web version, as a row for Review and the * report. On, the email becomes a page in the site's newsletter archive * when it goes out (at once for one already sent); off, only subscribers * get it. */ import { __ } from '@wordpress/i18n'; import { useUi } from '../runtime'; import { useWebVersion } from '../hooks/use-campaigns'; import { errorText } from '../lib/format'; /** * What the row says. * * @param {Object} campaign `{ web_version, web_url }`. * @return {string} The line. */ export function webLine( campaign ) { if ( ! campaign?.web_version ) { return __( 'Off. Only subscribers get it. On, it becomes a page in your newsletter archive.', 'mailpuff' ); } return campaign.web_url ? __( 'On. It is a page in your newsletter archive.', 'mailpuff' ) : __( 'On. It goes up in your newsletter archive when it is sent.', 'mailpuff' ); } /** * @param {Object} props * @param {Object} props.campaign The campaign. * @param {boolean} props.alone In a list of its own (the report). * @return {Element} The row. */ export default function WebVersionRow( { campaign, alone = false } ) { const { ui } = useUi(); const web = useWebVersion(); const on = !! campaign?.web_version; const toggle = ( next ) => web.mutate( { id: campaign.id, on: next }, { onSuccess: () => ui.toast.success( next ? __( 'It will be on your website.', 'mailpuff' ) : __( 'It is off your website.', 'mailpuff' ) ), onError: ( err ) => ui.toast.error( errorText( err, __( 'Could not change it.', 'mailpuff' ) ) ), } ); const row = ( { webLine( campaign ) } { campaign?.web_url && ( <> { ' ' } { __( 'View the page', 'mailpuff' ) } ) } } actions={ } /> ); return alone ? { row } : row; }