Skip to content

Commit

Permalink
Merge pull request online-go#2714 from LForchini/cancel-cm-report
Browse files Browse the repository at this point in the history
Allow CMs to cancel their own reports
  • Loading branch information
anoek authored Jun 20, 2024
2 parents 1289bbd + f7ad4c1 commit 3bd634a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export function IncidentReportTracker(): JSX.Element | null {
)}
</div>
)}
{filtered_reports.map((report, index) => (
{filtered_reports.map((report: Report, index) => (
<div className="incident" key={report.id}>
<div className="report-header">
<div
Expand Down
4 changes: 2 additions & 2 deletions src/lib/report_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export interface Report {
retyped: boolean;
source: string;
report_type: ReportType;
reporting_user: any;
reported_user: any;
reporting_user: PlayerCacheEntry;
reported_user: PlayerCacheEntry;
reported_game: number;
reported_game_move?: number;
reported_review: number;
Expand Down
8 changes: 8 additions & 0 deletions src/views/ReportsCenter/ModerationActionSelector.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.ModerationActionSelector {

.action-buttons {
display: flex;
justify-content: flex-end;
}

}
41 changes: 29 additions & 12 deletions src/views/ReportsCenter/ModerationActionSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ import * as React from "react";
import { _, pgettext } from "translate";

import * as DynamicHelp from "react-dynamic-help";
import { useUser } from "hooks";
import { Report } from "report_util";

interface ModerationActionSelectorProps {
available_actions: string[];
vote_counts: { [action: string]: number };
enable: boolean;
report: Report;
claim: () => void;
submit: (action: string, note: string) => void;
}
Expand Down Expand Up @@ -106,9 +109,13 @@ export function ModerationActionSelector({
available_actions,
vote_counts,
enable,
report,
claim,
submit,
}: ModerationActionSelectorProps): JSX.Element {
const user = useUser();
const reportedBySelf = user.id === report.reporting_user.id;

const [selectedOption, setSelectedOption] = React.useState("");
const [mod_note, setModNote] = React.useState("");
const [voted, setVoted] = React.useState(false);
Expand Down Expand Up @@ -175,18 +182,28 @@ export function ModerationActionSelector({
onChange={(ev) => setModNote(ev.target.value)}
/>
)}
{((action_choices && enable) || null) && (
<button
className="success"
disabled={voted || !selectedOption}
onClick={() => {
setVoted(true);
submit(selectedOption, mod_note);
}}
>
{pgettext("A label on a button for submitting a vote", "Vote")}
</button>
)}
<span className="action-buttons">
{((reportedBySelf && enable) || null) && (
<button className="reject" onClick={report.cancel}>
{pgettext(
"A button for cancelling a report created by yourself",
"Cancel Report",
)}
</button>
)}
{((action_choices && enable) || null) && (
<button
className="success"
disabled={voted || !selectedOption}
onClick={() => {
setVoted(true);
submit(selectedOption, mod_note);
}}
>
{pgettext("A label on a button for submitting a vote", "Vote")}
</button>
)}
</span>
</div>
);
}
1 change: 1 addition & 0 deletions src/views/ReportsCenter/ViewReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ export function ViewReport({ report_id, reports, onChange }: ViewReportProps): J
enable={report.state === "pending" && !report.escalated}
// clear the selection for subsequent reports
key={report.id}
report={report}
/>
</div>
)}
Expand Down

0 comments on commit 3bd634a

Please sign in to comment.