mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 12:36:57 +00:00
add /add-club route
remove commented out code dismiss success dialog - onClick was missing locale for add-club url prefer manual entry club if both auto and manual entry versions exist, only if pending = false change manual entry field to a boolean filter out clubs that are pending approval from manual entry add info message on success tournament form adds to DB and send discord message ping discord with club submission details i18n for add club update map to allow coordinate update depending on tournament/club page basic add club form with reusable map component
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
"use server";
|
||||
|
||||
import { addClubSchema } from "@/schemas";
|
||||
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;
|
||||
|
||||
const clubData = {
|
||||
name: club.name ?? "",
|
||||
address: club.address ?? "",
|
||||
coordinates: club.coordinates as [number, number],
|
||||
manual_entry: true,
|
||||
pending: true,
|
||||
};
|
||||
|
||||
await dbConnect();
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
@@ -1,11 +1,10 @@
|
||||
import { ObjectId } from "mongodb";
|
||||
|
||||
export type ClubModel = {
|
||||
_id: ObjectId;
|
||||
name: string;
|
||||
url?: string;
|
||||
address?: string;
|
||||
email?: string;
|
||||
website?: string;
|
||||
coordinates: [number, number];
|
||||
manual_entry?: boolean;
|
||||
pending?: boolean;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { ObjectId } from "mongodb";
|
||||
import { z } from "zod";
|
||||
|
||||
export const tournamentModelSchema = z.object({
|
||||
|
||||
Reference in New Issue
Block a user