upgrade Nodemailer to v10

fix dead code with knip

upgrade TS to v6 and fix linting errors

auto apply oxfmt rules

fix linting errors - unused deps etc

ignore file

remove all ignored files in knip

add knip - dead code analysis tool

swap prettier and eslint of oxfmt and oxlint

fix: fix map rendering in react strict mode

fix: headlessUI float replace

fix: disable Matomo if not URL and SITE ID exist

upgrade: 1st pass upgrade to Next.js v16

deps: upgrade react to v19
This commit is contained in:
2026-10-05 16:15:25 +02:00
committed by owenrees
parent df3a73df88
commit feadb465eb
122 changed files with 39491 additions and 32785 deletions
+44 -46
View File
@@ -5,55 +5,53 @@ import { collections, dbConnect } from "@/server/mongodb";
import { actionClient } from "@/server/safeAction";
import { errorLog } from "@/utils/logger";
export const addClub = actionClient
.schema(addClubSchema)
.action(async (input) => {
try {
const { name, email, message, club } = input.parsedInput;
export const addClub = actionClient.schema(addClubSchema).action(async (input) => {
try {
const { name, email, message, club } = input.parsedInput;
console.log(club);
console.log(club);
const clubData = {
name: club.name ?? "",
address: club.address ?? "",
email: club.email ?? "",
website: club.website ?? "",
coordinates: club.coordinates as [number, number],
manual_entry: true,
pending: true,
};
const clubData = {
name: club.name ?? "",
address: club.address ?? "",
email: club.email ?? "",
website: club.website ?? "",
coordinates: club.coordinates as [number, number],
manual_entry: true,
pending: true,
};
await dbConnect();
await dbConnect();
const result = await collections.clubs!.insertOne(clubData);
const result = await collections.clubs!.insertOne(clubData);
if (result.insertedId) {
await fetch(process.env.DISCORD_WEBHOOK_ADD_CLUB_URL as string, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
embeds: [
{
title: "Club Submitted",
fields: [
{ name: "Name", value: club.name ?? "" },
{ name: "Email", value: club.email ?? "" },
{ name: "Address", value: club.address ?? "" },
{ name: "Website", value: club.website ?? "" },
{ name: "Sender", value: name ?? "" },
{ name: "Sender Email", value: email ?? "" },
{ name: "Message", value: message ?? "" },
{ name: "ID", value: result.insertedId ?? "" },
],
},
],
}),
});
}
} catch (error) {
errorLog(error);
throw error;
if (result.insertedId) {
await fetch(process.env.DISCORD_WEBHOOK_ADD_CLUB_URL as string, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
embeds: [
{
title: "Club Submitted",
fields: [
{ name: "Name", value: club.name ?? "" },
{ name: "Email", value: club.email ?? "" },
{ name: "Address", value: club.address ?? "" },
{ name: "Website", value: club.website ?? "" },
{ name: "Sender", value: name ?? "" },
{ name: "Sender Email", value: email ?? "" },
{ name: "Message", value: message ?? "" },
{ name: "ID", value: result.insertedId ?? "" },
],
},
],
}),
});
}
});
} catch (error) {
errorLog(error);
throw error;
}
});
+48 -55
View File
@@ -17,68 +17,61 @@ const tcMap: Record<TimeControl, TournamentModel["time_control"]> = {
[TimeControl.Other]: "Other",
};
export const addTournament = actionClient
.schema(addTournamentSchema)
.action(async (input) => {
try {
await dbConnect();
export const addTournament = actionClient.schema(addTournamentSchema).action(async (input) => {
try {
await dbConnect();
const { name, email, message, tournament } = input.parsedInput;
const { name, email, message, tournament } = input.parsedInput;
const tournamentData: Omit<TournamentModel, "_id" | "tournament_id"> = {
...tournament,
date: format(tournament.date, "dd/MM/yyyy"),
start_date: format(tournament.date, "dd/MM/yyyy"),
end_date: format(tournament.date, "dd/MM/yyyy"),
time_control: tcMap[tournament.time_control],
coordinates: tournament.coordinates as [number, number],
entry_method: "manual",
pending: true,
status: "scheduled",
};
const tournamentData: Omit<TournamentModel, "_id" | "tournament_id"> = {
...tournament,
date: format(tournament.date, "dd/MM/yyyy"),
start_date: format(tournament.date, "dd/MM/yyyy"),
end_date: format(tournament.date, "dd/MM/yyyy"),
time_control: tcMap[tournament.time_control],
coordinates: tournament.coordinates as [number, number],
entry_method: "manual",
pending: true,
status: "scheduled",
};
const result = await collections.tournaments!.insertOne(tournamentData);
const result = await collections.tournaments!.insertOne(tournamentData);
if (result.insertedId) {
const { tournament, country, date, time_control } = tournamentData;
if (result.insertedId) {
const { tournament, country, date, time_control } = tournamentData;
if (
typeof process.env.DISCORD_WEBHOOK_ADD_TOURNAMENT_URL === "string"
) {
await fetch(
process.env.DISCORD_WEBHOOK_ADD_TOURNAMENT_URL as string,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
embeds: [
if (typeof process.env.DISCORD_WEBHOOK_ADD_TOURNAMENT_URL === "string") {
await fetch(process.env.DISCORD_WEBHOOK_ADD_TOURNAMENT_URL as string, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
embeds: [
{
title: "Tournament Submitted",
fields: [
{ name: "Tournament", value: tournament },
{ name: "Country", value: country },
{ name: "Date", value: date },
{
title: "Tournament Submitted",
fields: [
{ name: "Tournament", value: tournament },
{ name: "Country", value: country },
{ name: "Date", value: date },
{
name: "Time Control",
value: time_control,
},
{ name: "Sender", value: name },
{ name: "Sender Email", value: email },
{ name: "Message", value: message ?? "" },
],
name: "Time Control",
value: time_control,
},
{ name: "Sender", value: name },
{ name: "Sender Email", value: email },
{ name: "Message", value: message ?? "" },
],
}),
},
);
}
return true;
},
],
}),
});
}
} catch (error) {
errorLog(error);
throw error;
return true;
}
});
} catch (error) {
errorLog(error);
throw error;
}
});
+27 -31
View File
@@ -1,38 +1,34 @@
"use server";
import { z } from "zod";
import { contactUsSchema } from "@/schemas";
import { errorLog } from "@/utils/logger";
import { actionClient } from "./safeAction";
export const contactUs = actionClient
.schema(contactUsSchema)
.action(async (input) => {
try {
const { email, subject, message } = input.parsedInput;
await fetch(process.env.DISCORD_WEBHOOK_CONTACT_URL as string, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
embeds: [
{
title: "Contact",
fields: [
{ name: "Email", value: email },
{ name: "Subject", value: subject },
{ name: "Message", value: message },
],
},
],
}),
});
return true;
} catch (error) {
errorLog(error);
throw error;
}
});
export const contactUs = actionClient.schema(contactUsSchema).action(async (input) => {
try {
const { email, subject, message } = input.parsedInput;
await fetch(process.env.DISCORD_WEBHOOK_CONTACT_URL as string, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
embeds: [
{
title: "Contact",
fields: [
{ name: "Email", value: email },
{ name: "Subject", value: subject },
{ name: "Message", value: message },
],
},
],
}),
});
return true;
} catch (error) {
errorLog(error);
throw error;
}
});
+24 -26
View File
@@ -10,31 +10,29 @@ import { errorLog } from "@/utils/logger";
import { ZoneModel } from "./models/zoneModel";
import { actionClient } from "./safeAction";
export const createZone = actionClient
.schema(zoneSchema)
.action(async (input) => {
try {
await dbConnect();
export const createZone = actionClient.schema(zoneSchema).action(async (input) => {
try {
await dbConnect();
const user = await auth();
if (!user?.user) {
throw new Error("You must be logged in to create a zone");
}
const zoneData: ZoneModel = {
...input.parsedInput,
userId: new ObjectId(user.user!.id!),
};
const result = await collections.zones!.insertOne(zoneData);
if (!result.acknowledged) {
throw new Error("ERR_ZONE_INSERT_FAILED");
}
return true;
} catch (error) {
errorLog(error);
throw error;
const user = await auth();
if (!user?.user) {
throw new Error("You must be logged in to create a zone");
}
});
const zoneData: ZoneModel = {
...input.parsedInput,
userId: new ObjectId(user.user!.id!),
};
const result = await collections.zones!.insertOne(zoneData);
if (!result.acknowledged) {
throw new Error("ERR_ZONE_INSERT_FAILED");
}
return true;
} catch (error) {
errorLog(error);
throw error;
}
});
-1
View File
@@ -1,7 +1,6 @@
"use server";
import { ObjectId } from "mongodb";
import { z } from "zod";
import { adapter, auth } from "@/auth";
import { collections, dbConnect } from "@/server/mongodb";
+23 -25
View File
@@ -13,31 +13,29 @@ const deleteZoneSchema = z.object({
id: z.string(),
});
export const deleteZone = actionClient
.schema(deleteZoneSchema)
.action(async (input) => {
const { id } = input.parsedInput;
export const deleteZone = actionClient.schema(deleteZoneSchema).action(async (input) => {
const { id } = input.parsedInput;
try {
await dbConnect();
try {
await dbConnect();
const user = await auth();
if (!user?.user) {
throw new Error("You must be logged in to create a zone");
}
const result = await collections.zones!.deleteOne({
_id: new ObjectId(id),
userId: new ObjectId(user.user!.id!),
});
if (!result || result.deletedCount !== 1) {
throw new Error("ERR_ZONE_DELETE_FAILED");
}
return true;
} catch (error) {
errorLog(error);
throw error;
const user = await auth();
if (!user?.user) {
throw new Error("You must be logged in to create a zone");
}
});
const result = await collections.zones!.deleteOne({
_id: new ObjectId(id),
userId: new ObjectId(user.user!.id!),
});
if (!result || result.deletedCount !== 1) {
throw new Error("ERR_ZONE_DELETE_FAILED");
}
return true;
} catch (error) {
errorLog(error);
throw error;
}
});
+32 -34
View File
@@ -17,39 +17,37 @@ const editZoneSchema = z.object({
zone: zoneSchema,
});
export const editZone = actionClient
.schema(editZoneSchema)
.action(async (input) => {
const { id, zone } = input.parsedInput;
try {
await dbConnect();
export const editZone = actionClient.schema(editZoneSchema).action(async (input) => {
const { id, zone } = input.parsedInput;
try {
await dbConnect();
const user = await auth();
if (!user?.user) {
throw new Error("You must be logged in to create a zone");
}
const zoneData: ZoneModel = {
...zone,
userId: new ObjectId(user.user!.id!),
};
const result = await collections.zones!.findOneAndUpdate(
{ _id: new ObjectId(id), userId: new ObjectId(user.user!.id!) },
{ $set: { _id: new ObjectId(id), ...zoneData } },
);
if (!result) {
throw new Error("ERR_ZONE_UPDATE_FAILED");
}
return {
...omit(result, ["_id"]),
id: result._id.toString(),
userId: result.userId.toString(),
};
} catch (error) {
errorLog(error);
throw error;
const user = await auth();
if (!user?.user) {
throw new Error("You must be logged in to create a zone");
}
});
const zoneData: ZoneModel = {
...zone,
userId: new ObjectId(user.user!.id!),
};
const result = await collections.zones!.findOneAndUpdate(
{ _id: new ObjectId(id), userId: new ObjectId(user.user!.id!) },
{ $set: { _id: new ObjectId(id), ...zoneData } },
);
if (!result) {
throw new Error("ERR_ZONE_UPDATE_FAILED");
}
return {
...omit(result, ["_id"]),
id: result._id.toString(),
userId: result.userId.toString(),
};
} catch (error) {
errorLog(error);
throw error;
}
});
+6 -19
View File
@@ -58,9 +58,7 @@ const getEloDetails = (elo: string | null) => {
};
};
const getResultDetails = (
results: z.infer<typeof dbSchema>[number]["results"][number],
) => {
const getResultDetails = (results: z.infer<typeof dbSchema>[number]["results"][number]) => {
if (results.opponent_name === null) {
return { result: 0, lostByForfeit: true, wonByForfeit: false };
}
@@ -118,12 +116,9 @@ export const fetchTournamentResults = actionClient
headers.append("api-key", apiKey);
}
const rawResults = await fetch(
`${process.env.RESULTS_SCRAPER_URL}${id}`,
{
headers: headers,
},
);
const rawResults = await fetch(`${process.env.RESULTS_SCRAPER_URL}${id}`, {
headers: headers,
});
if (rawResults.status >= 500) {
throw new Error("ERR_TOURNAMENT_RESULTS_NOT_AVAILABLE");
@@ -143,12 +138,7 @@ export const fetchTournamentResults = actionClient
name: player.name,
...getEloDetails(player.elo),
results: player.results.map((result) => ({
colour:
result.colour === "B"
? "white"
: result.colour === "N"
? "black"
: "",
colour: result.colour === "B" ? "white" : result.colour === "N" ? "black" : "",
opponent: result.opponent_name,
...getResultDetails(result),
...getEloDetails(result.opponent_elo),
@@ -156,10 +146,7 @@ export const fetchTournamentResults = actionClient
})),
);
} catch (error: any) {
if (
!("message" in error) ||
error.message !== "ERR_TOURNAMENT_NOT_FOUND"
) {
if (!("message" in error) || error.message !== "ERR_TOURNAMENT_NOT_FOUND") {
reportFetchError(id, error);
errorLog(JSON.stringify(error, null, 2));
}
+28 -30
View File
@@ -12,35 +12,33 @@ const inputSchema = z.object({
ffeId: z.string(),
});
export const getTournamentDetails = actionClient
.schema(inputSchema)
.action(async (input) => {
const { ffeId } = input.parsedInput;
try {
await dbConnect();
const t = await collections.tournaments!.findOne({
tournament_id: ffeId,
});
export const getTournamentDetails = actionClient.schema(inputSchema).action(async (input) => {
const { ffeId } = input.parsedInput;
try {
await dbConnect();
const t = await collections.tournaments!.findOne({
tournament_id: ffeId,
});
if (t === null) {
return null;
}
const timeControl = tcMap[t.time_control] ?? TimeControl.Other;
return {
id: t._id.toString(),
ffeId: t.tournament_id!,
tournament: t.tournament,
town: t.town,
department: t.department,
date: t.date,
url: t.url,
timeControl,
status: t.status,
};
} catch (error) {
errorLog(JSON.stringify(error, null, 2));
throw error;
if (t === null) {
return null;
}
});
const timeControl = tcMap[t.time_control] ?? TimeControl.Other;
return {
id: t._id.toString(),
ffeId: t.tournament_id!,
tournament: t.tournament,
town: t.town,
department: t.department,
date: t.date,
url: t.url,
timeControl,
status: t.status,
};
} catch (error) {
errorLog(JSON.stringify(error, null, 2));
throw error;
}
});
+1 -3
View File
@@ -23,9 +23,7 @@ export const myZones = actionClient.action(async () => {
throw new Error("You must be logged in to fetch your zones");
}
const zones = await collections
.zones!.find({ userId: new ObjectId(user.user!.id!) })
.toArray();
const zones = await collections.zones!.find({ userId: new ObjectId(user.user!.id!) }).toArray();
const result: Zone[] = zones.map((zone) => ({
...omit(zone, ["_id", "userId"]),
+56 -66
View File
@@ -17,80 +17,70 @@ const inputSchema = z.object({
export type SearchedTournament = Pick<
Tournament,
| "id"
| "ffeId"
| "date"
| "department"
| "status"
| "timeControl"
| "tournament"
| "town"
| "url"
"id" | "ffeId" | "date" | "department" | "status" | "timeControl" | "tournament" | "town" | "url"
>;
export const searchTournaments = actionClient
.schema(inputSchema)
.action(async (input) => {
const { searchValue, limit } = input.parsedInput;
try {
await dbConnect();
export const searchTournaments = actionClient.schema(inputSchema).action(async (input) => {
const { searchValue, limit } = input.parsedInput;
try {
await dbConnect();
const searchTerms = searchValue
.split(" ")
.map((s) => removeDiacritics(s.trim()))
.filter((s) => s !== "")
.map((s) => ({ tournament_index: { $regex: s, $options: "i" } }));
const searchTerms = searchValue
.split(" ")
.map((s) => removeDiacritics(s.trim()))
.filter((s) => s !== "")
.map((s) => ({ tournament_index: { $regex: s, $options: "i" } }));
const data = await collections
.tournaments!.aggregate([
{
$addFields: {
dateParts: {
$dateFromString: {
dateString: "$start_date",
format: "%d/%m/%Y",
},
const data = await collections
.tournaments!.aggregate([
{
$addFields: {
dateParts: {
$dateFromString: {
dateString: "$start_date",
format: "%d/%m/%Y",
},
},
},
{
$match: {
$and: [
{ federation: { $eq: "FFE" } },
{ dateParts: { $lte: endOfDay(new Date()) } },
...searchTerms,
],
},
},
{
$match: {
$and: [
{ federation: { $eq: "FFE" } },
{ dateParts: { $lte: endOfDay(new Date()) } },
...searchTerms,
],
},
{
$sort: {
dateParts: -1,
},
},
{
$sort: {
dateParts: -1,
},
{ $limit: limit ?? 20 },
{
$unset: "dateParts",
},
])
.toArray();
},
{ $limit: limit ?? 20 },
{
$unset: "dateParts",
},
])
.toArray();
return data.map<SearchedTournament>((t) => {
const timeControl = tcMap[t.time_control] ?? TimeControl.Other;
return data.map<SearchedTournament>((t) => {
const timeControl = tcMap[t.time_control] ?? TimeControl.Other;
return {
id: t._id.toString(),
ffeId: t.tournament_id,
tournament: t.tournament,
town: t.town,
department: t.department,
date: t.start_date,
url: t.url,
timeControl,
status: t.status,
};
});
} catch (error) {
errorLog(JSON.stringify(error, null, 2));
throw error;
}
});
return {
id: t._id.toString(),
ffeId: t.tournament_id,
tournament: t.tournament,
town: t.town,
department: t.department,
date: t.start_date,
url: t.url,
timeControl,
status: t.status,
};
});
} catch (error) {
errorLog(JSON.stringify(error, null, 2));
throw error;
}
});
+18 -20
View File
@@ -9,25 +9,23 @@ import { errorLog } from "@/utils/logger";
import { actionClient } from "./safeAction";
export const setUserLocale = actionClient
.schema(z.string())
.action(async (input) => {
try {
await dbConnect();
export const setUserLocale = actionClient.schema(z.string()).action(async (input) => {
try {
await dbConnect();
const user = await auth();
if (!user?.user) {
throw new Error("You must be logged update your locale");
}
await collections.users!.findOneAndUpdate(
{ _id: new ObjectId(user.user.id) },
{ $set: { locale: input.parsedInput } },
);
return true;
} catch (error) {
errorLog(error);
throw error;
const user = await auth();
if (!user?.user) {
throw new Error("You must be logged update your locale");
}
});
await collections.users!.findOneAndUpdate(
{ _id: new ObjectId(user.user.id) },
{ $set: { locale: input.parsedInput } },
);
return true;
} catch (error) {
errorLog(error);
throw error;
}
});