-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
169 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { t } from 'ttag'; | ||
import MenuItem from '@material-ui/core/MenuItem'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
|
||
import { getSpamReportUrl } from 'constants/urls'; | ||
import useCurrentUser from 'lib/useCurrentUser'; | ||
|
||
const useStyles = makeStyles({ | ||
link: { | ||
color: 'inherit', | ||
textDecoration: 'none', | ||
}, | ||
}); | ||
|
||
/** | ||
* | ||
* @param {string} itemUserId - the author's user ID of the item | ||
*/ | ||
export function useCanReportAbuse(itemUserId) { | ||
const currentUser = useCurrentUser(); | ||
return currentUser && currentUser.id !== itemUserId; | ||
} | ||
|
||
/** | ||
* @param {object} props | ||
* @param {string} props.userId - spammer's user ID | ||
* @param {'replyRequest' | 'articleReplyFeedback' | 'reply'} props.itemType - reported spam item type | ||
* @param {string} props.itemId - reply ID for reply; article ID for replyRequest; article ID,reply ID (separated in comma) for article reply feedback. | ||
* | ||
* @returns {string} Pre-filled URL to the google form that reports spam. | ||
*/ | ||
function ReportAbuseMenuItem(props) { | ||
const classes = useStyles(); | ||
const canReportAbuse = useCanReportAbuse(props.userId); | ||
|
||
if (!canReportAbuse) return null; | ||
|
||
return ( | ||
<a | ||
className={classes.link} | ||
href={getSpamReportUrl(props)} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
<MenuItem>{t`Report abuse`}</MenuItem> | ||
</a> | ||
); | ||
} | ||
|
||
export default ReportAbuseMenuItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
import ActionMenu from './ActionMenu'; | ||
export default ActionMenu; | ||
|
||
import ReportAbuseMenuItem, { useCanReportAbuse } from './ReportAbuseMenuItem'; | ||
export { ReportAbuseMenuItem, useCanReportAbuse }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters