2022-01-10 14:17:52 -08:00
import React from 'react' ;
2020-03-27 13:59:38 -07:00
import { FormattedMessage } from 'react-intl' ;
2021-10-13 12:35:34 -07:00
import { Link } from 'react-router-dom' ;
2022-01-10 14:25:06 -08:00
2022-09-14 11:01:00 -07:00
import { useAppSelector , useCompose } from 'soapbox/hooks' ;
2022-09-10 14:52:06 -07:00
2022-01-10 14:01:24 -08:00
import Warning from '../components/warning' ;
2020-03-27 13:59:38 -07:00
const APPROX_HASHTAG_RE = /(?:^|[^\/\)\w])#(\w*[a-zA-Z·]\w*)/i ;
2022-09-10 14:52:06 -07:00
interface IWarningWrapper {
composeId : string ,
}
const WarningWrapper : React.FC < IWarningWrapper > = ( { composeId } ) = > {
2022-09-14 11:01:00 -07:00
const compose = useCompose ( composeId ) ;
2022-09-10 14:52:06 -07:00
const me = useAppSelector ( ( state ) = > state . me ) ;
2022-09-14 11:01:00 -07:00
const needsLockWarning = useAppSelector ( ( state ) = > compose . privacy === 'private' && ! state . accounts . get ( me ) ! . locked ) ;
const hashtagWarning = compose . privacy !== 'public' && APPROX_HASHTAG_RE . test ( compose . text ) ;
const directMessageWarning = compose . privacy === 'direct' ;
2020-03-27 13:59:38 -07:00
if ( needsLockWarning ) {
2021-10-13 12:35:34 -07:00
return < Warning message = { < FormattedMessage id = 'compose_form.lock_disclaimer' defaultMessage = 'Your account is not {locked}. Anyone can follow you to view your follower-only posts.' values = { { locked : < Link to = '/settings/profile' > < FormattedMessage id = 'compose_form.lock_disclaimer.lock' defaultMessage = 'locked' / > < / Link > } } / > } / > ;
2020-03-27 13:59:38 -07:00
}
if ( hashtagWarning ) {
return < Warning message = { < FormattedMessage id = 'compose_form.hashtag_warning' defaultMessage = "This post won't be listed under any hashtag as it is unlisted. Only public posts can be searched by hashtag." / > } / > ;
}
if ( directMessageWarning ) {
const message = (
< span >
2021-10-13 12:32:38 -07:00
< FormattedMessage id = 'compose_form.direct_message_warning' defaultMessage = 'This post will only be sent to the mentioned users.' / >
{ /* <a href='/about/tos' target='_blank'><FormattedMessage id='compose_form.direct_message_warning_learn_more' defaultMessage='Learn more' /></a> */ }
2020-03-27 13:59:38 -07:00
< / span >
) ;
return < Warning message = { message } / > ;
}
return null ;
} ;
2022-09-10 14:52:06 -07:00
export default WarningWrapper ;