mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-01 15:48:23 -05:00
Move app to apps/web-react in pnpm workspace layout
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useMatches } from "react-router";
|
||||
import { SendouDialog } from "~/components/elements/Dialog";
|
||||
import { toastQueue } from "~/components/elements/Toast";
|
||||
import { FormMessage } from "~/components/FormMessage";
|
||||
import { SendouForm } from "~/form";
|
||||
import { userReportPage } from "~/utils/urls";
|
||||
import { reportUserSchema } from "../user-report-schemas";
|
||||
|
||||
const SENDOUQ_MATCH_ROUTE_ID = "features/sendouq-match/routes/q.match.$id";
|
||||
|
||||
/**
|
||||
* Modal for reporting a user to the staff, posting to the `/user-report/:id` resource
|
||||
* route. Re-reporting the same user overwrites the previous report. Rendered wherever
|
||||
* a `UserCard` lives.
|
||||
*/
|
||||
export function ReportUserDialog({
|
||||
userId,
|
||||
username,
|
||||
onClose,
|
||||
}: {
|
||||
userId: number;
|
||||
username: string;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation(["user"]);
|
||||
const prefilledMatchId = useSendouQMatchIdFromRoute();
|
||||
|
||||
return (
|
||||
<SendouDialog
|
||||
heading={t("user:card.report.header", { name: username })}
|
||||
onClose={onClose}
|
||||
>
|
||||
<SendouForm
|
||||
schema={reportUserSchema}
|
||||
action={userReportPage(userId)}
|
||||
defaultValues={{ matchId: prefilledMatchId }}
|
||||
onSuccess={() => {
|
||||
toastQueue.add(
|
||||
{ message: "Report sent to the staff", variant: "success" },
|
||||
{ timeout: 5000 },
|
||||
);
|
||||
onClose();
|
||||
}}
|
||||
>
|
||||
{({ FormField }) => (
|
||||
<>
|
||||
<FormField name="category" />
|
||||
<FormField name="description" />
|
||||
<FormField name="matchId" />
|
||||
<FormMessage type="info">
|
||||
{t("user:card.report.falseReportsWarning")}
|
||||
</FormMessage>
|
||||
</>
|
||||
)}
|
||||
</SendouForm>
|
||||
</SendouDialog>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the SendouQ match id from the current route so a report opened from a match page
|
||||
* prefills its "Match ID" field. Returns `undefined` on any other page.
|
||||
*/
|
||||
function useSendouQMatchIdFromRoute() {
|
||||
const matches = useMatches();
|
||||
|
||||
const matchRoute = matches.find(
|
||||
(match) => match.id === SENDOUQ_MATCH_ROUTE_ID,
|
||||
);
|
||||
|
||||
return matchRoute?.params.id;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
.container {
|
||||
height: 200px;
|
||||
background-color: var(--color-bg-high);
|
||||
border-radius: var(--radius-box);
|
||||
padding: var(--s-2);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import {
|
||||
BarElement,
|
||||
CategoryScale,
|
||||
Chart as ChartJS,
|
||||
LinearScale,
|
||||
Tooltip,
|
||||
} from "chart.js";
|
||||
import { format } from "date-fns";
|
||||
import { Bar } from "react-chartjs-2";
|
||||
import { useHydrated } from "~/hooks/useHydrated";
|
||||
import { useThemeColors } from "~/hooks/useThemeColors";
|
||||
import styles from "./ReportsBarChart.module.css";
|
||||
|
||||
ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip);
|
||||
|
||||
/**
|
||||
* Bar graph of reports made against a user, one bar per calendar month.
|
||||
* Theme colors are read from CSS variables like `app/components/Chart.tsx` does.
|
||||
*/
|
||||
export function ReportsBarChart({
|
||||
monthlyCounts,
|
||||
}: {
|
||||
monthlyCounts: Array<{
|
||||
/** Start of the calendar month as a JavaScript timestamp */
|
||||
month: number;
|
||||
count: number;
|
||||
}>;
|
||||
}) {
|
||||
const isHydrated = useHydrated();
|
||||
|
||||
const colors = useThemeColors({
|
||||
bar: "--color-text-accent",
|
||||
border: "--color-border",
|
||||
borderHigh: "--color-border-high",
|
||||
text: "--color-text-high",
|
||||
});
|
||||
|
||||
if (!isHydrated) {
|
||||
return <div className={styles.container} />;
|
||||
}
|
||||
|
||||
const scaleDefaults = {
|
||||
grid: { color: colors.border },
|
||||
border: { color: colors.borderHigh },
|
||||
ticks: { color: colors.text },
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Bar
|
||||
data={{
|
||||
labels: monthlyCounts.map(({ month }) =>
|
||||
format(new Date(month), "MMM yy"),
|
||||
),
|
||||
datasets: [
|
||||
{
|
||||
data: monthlyCounts.map(({ count }) => count),
|
||||
backgroundColor: colors.bar,
|
||||
},
|
||||
],
|
||||
}}
|
||||
options={{
|
||||
animation: false,
|
||||
maintainAspectRatio: false,
|
||||
scales: {
|
||||
x: {
|
||||
...scaleDefaults,
|
||||
grid: { display: false },
|
||||
ticks: { ...scaleDefaults.ticks, maxRotation: 0 },
|
||||
},
|
||||
y: {
|
||||
...scaleDefaults,
|
||||
beginAtZero: true,
|
||||
ticks: { ...scaleDefaults.ticks, precision: 0 },
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
legend: { display: false },
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user