Update packages

This commit is contained in:
Timothy Armes
2024-09-26 16:45:40 +02:00
parent 75fd05a3d7
commit 1c7ad63e03
33 changed files with 1822 additions and 1351 deletions
+1 -1
View File
@@ -1 +1 @@
18.17 18.18
Vendored
+333
View File
@@ -1,4 +1,337 @@
import * as L from "leaflet";
// Use type safe message keys with `next-intl` // Use type safe message keys with `next-intl`
type Messages = typeof import("./src/messages/fr.json"); type Messages = typeof import("./src/messages/fr.json");
declare interface IntlMessages extends Messages {} declare interface IntlMessages extends Messages {}
// For some reason, @types/leaflet.markercluster isn't being recognized
// I'm including it here by hand
declare module "leaflet" {
class MarkerCluster extends Marker {
/*
* Recursively retrieve all child markers of this cluster.
*/
getAllChildMarkers(): Marker[];
/*
* Returns the count of how many child markers we have.
*/
getChildCount(): number;
/*
* Zoom to the minimum of showing all of the child markers, or the extents of this cluster.
*/
zoomToBounds(options?: FitBoundsOptions): void;
/*
* Returns the cluster bounds.
*/
getBounds(): LatLngBounds;
/*
* Spiderfies the child markers of this cluster.
*/
spiderfy(): void;
/*
* Unspiderfies a cluster (opposite of spiderfy).
*/
unspiderfy(): void;
}
interface MarkerClusterGroupOptions extends LayerOptions {
/*
* The maximum radius that a cluster will cover from the central marker (in pixels). Default 80.
* Decreasing will make more, smaller clusters. You can also use a function that accepts
* the current map zoom and returns the maximum cluster radius in pixels
*/
maxClusterRadius?: number | ((zoom: number) => number) | undefined;
/*
* Function used to create the cluster icon
*/
iconCreateFunction?:
| ((cluster: MarkerCluster) => Icon | DivIcon)
| undefined;
/*
* Map pane where the cluster icons will be added.
* Defaults to L.Marker's default (currently 'markerPane')
*/
clusterPane?: string | undefined;
/*
* When you click a cluster at any zoom level we spiderfy it
* so you can see all of its markers.
*/
spiderfyOnEveryZoom?: boolean | undefined;
/*
* When you click a cluster at the bottom zoom level we spiderfy it
* so you can see all of its markers.
*/
spiderfyOnMaxZoom?: boolean | undefined;
/*
* When you mouse over a cluster it shows the bounds of its markers.
*/
showCoverageOnHover?: boolean | undefined;
/*
* When you click a cluster we zoom to its bounds.
*/
zoomToBoundsOnClick?: boolean | undefined;
/*
* If set to true, overrides the icon for all added markers to make them appear as a 1 size cluster.
*/
singleMarkerMode?: boolean | undefined;
/*
* If set, at this zoom level and below markers will not be clustered. This defaults to disabled.
*/
disableClusteringAtZoom?: number | undefined;
/*
* Clusters and markers too far from the viewport are removed from the map
* for performance.
*/
removeOutsideVisibleBounds?: boolean | undefined;
/*
* Smoothly split / merge cluster children when zooming and spiderfying.
* If L.DomUtil.TRANSITION is false, this option has no effect (no animation is possible).
*/
animate?: boolean | undefined;
/*
* If set to true (and animate option is also true) then adding individual markers to the
* MarkerClusterGroup after it has been added to the map will add the marker and animate it
* into the cluster. Defaults to false as this gives better performance when bulk adding markers.
* addLayers does not support this, only addLayer with individual Markers.
*/
animateAddingMarkers?: boolean | undefined;
/*
* Custom function to calculate spiderfy shape positions
*/
spiderfyShapePositions?:
| ((count: number, centerPoint: Point) => Point[])
| undefined;
/*
* Increase from 1 to increase the distance away from the center that spiderfied markers are placed.
* Use if you are using big marker icons (Default: 1).
*/
spiderfyDistanceMultiplier?: number | undefined;
/*
* Allows you to specify PolylineOptions to style spider legs.
* By default, they are { weight: 1.5, color: '#222', opacity: 0.5 }.
*/
spiderLegPolylineOptions?: PolylineOptions | undefined;
/*
* Boolean to split the addLayers processing in to small intervals so that the page does not freeze.
*/
chunkedLoading?: boolean | undefined;
/*
* Time delay (in ms) between consecutive periods of processing for addLayers. Default to 50ms.
*/
chunkDelay?: number | undefined;
/*
* Time interval (in ms) during which addLayers works before pausing to let the rest of the page process.
* In particular, this prevents the page from freezing while adding a lot of markers. Defaults to 200ms.
*/
chunkInterval?: number | undefined;
/*
* Callback function that is called at the end of each chunkInterval.
* Typically used to implement a progress indicator. Defaults to null.
*/
chunkProgress?:
| ((
processedMarkers: number,
totalMarkers: number,
elapsedTime: number,
) => void)
| undefined;
/*
* Options to pass when creating the L.Polygon(points, options) to show the bounds of a cluster.
* Defaults to empty
*/
polygonOptions?: PolylineOptions | undefined;
}
/*
* Cluster-related handler functions.
*/
type AnimationEndEventHandlerFn = (event: LeafletEvent) => void;
type SpiderfyEventHandlerFn = (event: MarkerClusterSpiderfyEvent) => void;
/*
* Event fired on spiderfy cluster actions.
*/
interface MarkerClusterSpiderfyEvent extends LeafletEvent {
/*
* The cluster that fired the event.
*/
cluster: MarkerCluster;
/*
* The markers in the cluster that fired the event.
*/
markers: Marker[];
}
/*
* Extend existing event handler function map to include cluster events.
*/
interface LeafletEventHandlerFnMap {
/*
* Fires when overlapping markers get spiderified.
*/
spiderfied?: SpiderfyEventHandlerFn | undefined;
/*
* Fires when overlapping markers get unspiderified.
*/
unspiderfied?: SpiderfyEventHandlerFn | undefined;
/*
* Fires when marker clustering/unclustering animation has completed.
*/
animationend?: AnimationEndEventHandlerFn | undefined;
}
/*
* Extend Evented to include cluster events.
*/
interface Evented {
on(
type: "spiderfied" | "unspiderfied",
fn?: SpiderfyEventHandlerFn,
context?: any,
): this;
on(
type: "animationend",
fn?: AnimationEndEventHandlerFn,
context?: any,
): this;
off(
type: "spiderfied" | "unspiderfied",
fn?: SpiderfyEventHandlerFn,
context?: any,
): this;
off(
type: "animationend",
fn?: AnimationEndEventHandlerFn,
context?: any,
): this;
once(
type: "spiderfied" | "unspiderfied",
fn?: SpiderfyEventHandlerFn,
context?: any,
): this;
once(
type: "animationend",
fn?: AnimationEndEventHandlerFn,
context?: any,
): this;
addEventListener(
type: "spiderfied" | "unspiderfied",
fn?: SpiderfyEventHandlerFn,
context?: any,
): this;
addEventListener(
type: "animationend",
fn?: AnimationEndEventHandlerFn,
context?: any,
): this;
removeEventListener(
type: "spiderfied" | "unspiderfied",
fn?: SpiderfyEventHandlerFn,
context?: any,
): this;
removeEventListener(
type: "animationend",
fn?: AnimationEndEventHandlerFn,
context?: any,
): this;
addOneTimeEventListener(
type: "spiderfied" | "unspiderfied",
fn?: SpiderfyEventHandlerFn,
context?: any,
): this;
addOneTimeEventListener(
type: "animationend",
fn?: AnimationEndEventHandlerFn,
context?: any,
): this;
}
class MarkerClusterGroup extends FeatureGroup {
constructor(options?: MarkerClusterGroupOptions);
/*
* Bulk methods for adding and removing markers and should be favoured over the
* single versions when doing bulk addition/removal of markers.
*/
addLayers(layers: Layer[], skipLayerAddEvent?: boolean): this;
removeLayers(layers: Layer[]): this;
clearLayers(): this;
/*
* If you have a marker in your MarkerClusterGroup and you want to get the visible
* parent of it
*/
getVisibleParent(marker: Marker): Marker;
/*
* If you have customized the clusters icon to use some data from the contained markers,
* and later that data changes, use this method to force a refresh of the cluster icons.
*/
refreshClusters(
clusters?: Marker | Marker[] | LayerGroup | { [index: string]: Layer },
): this;
/*
* Returns the total number of markers contained within that cluster.
*/
getChildCount(): number;
/*
* Returns the array of total markers contained within that cluster.
*/
getAllChildMarkers(): Marker[];
/*
* Returns true if the given layer (marker) is in the cluster.
*/
hasLayer(layer: Layer): boolean;
/*
* Zooms to show the given marker (spiderfying if required),
* calls the callback when the marker is visible on the map.
*/
zoomToShowLayer(layer: Layer, callback?: () => void): void;
}
/*
* Create a marker cluster group, optionally given marker cluster group options.
*/
function markerClusterGroup(
options?: MarkerClusterGroupOptions,
): MarkerClusterGroup;
}
+18 -21
View File
@@ -12,20 +12,19 @@
"format:fix": "prettier --write \"**/*.{js,jsx,ts,tsx}\"" "format:fix": "prettier --write \"**/*.{js,jsx,ts,tsx}\""
}, },
"dependencies": { "dependencies": {
"@auth/mongodb-adapter": "^2.5.0", "@auth/mongodb-adapter": "^3.5.2",
"@headlessui-float/react": "^0.13.3", "@headlessui-float/react": "^0.15.0",
"@headlessui/react": "^1.7.18", "@headlessui/react": "^2.1.8",
"@headlessui/tailwindcss": "^0.2.0", "@headlessui/tailwindcss": "^0.2.1",
"@hookform/resolvers": "^3.3.3", "@hookform/resolvers": "^3.9.0",
"@infra-blocks/zod-utils": "^0.4.2", "@infra-blocks/zod-utils": "^0.4.2",
"@kodingdotninja/use-tailwind-breakpoint": "^0.0.5",
"@next/bundle-analyzer": "^14.0.4", "@next/bundle-analyzer": "^14.0.4",
"@tanstack/react-query": "^5.29.0", "@tanstack/react-query": "^5.29.0",
"@trivago/prettier-plugin-sort-imports": "^4.2.0", "@trivago/prettier-plugin-sort-imports": "^4.2.0",
"@turf/boolean-point-in-polygon": "^7.0.0-alpha.114", "@turf/boolean-point-in-polygon": "^7.0.0-alpha.114",
"@types/node": "^20.8.4", "@types/node": "^22.7.2",
"autoprefixer": "^10.4.16", "autoprefixer": "^10.4.16",
"date-fns": "^2.30.0", "date-fns": "^4.1.0",
"geojson": "^0.5.0", "geojson": "^0.5.0",
"jotai": "^2.6.1", "jotai": "^2.6.1",
"leaflet": "^1.9.4", "leaflet": "^1.9.4",
@@ -33,22 +32,22 @@
"leaflet-gesture-handling": "^1.2.2", "leaflet-gesture-handling": "^1.2.2",
"leaflet-draw": "^1.0.4", "leaflet-draw": "^1.0.4",
"leaflet.markercluster": "^1.5.3", "leaflet.markercluster": "^1.5.3",
"leaflet.smooth_marker_bouncing": "^3.0.3", "leaflet.smooth_marker_bouncing": "3.0.3",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"mongodb": "^6.4.0", "mongodb": "^6.4.0",
"next": "^14.0.4", "next": "^14.0.4",
"next-auth": "^5.0.0-beta.16", "next-auth": "^5.0.0-beta.16",
"next-intl": "^3.3.2", "next-intl": "^3.3.2",
"next-pwa": "^5.6.0", "next-pwa": "^5.6.0",
"next-safe-action": "^6.2.0", "next-safe-action": "^7.9.3",
"nodemailer": "^6.9.12", "nodemailer": "^6.9.12",
"postcss": "8.4.33", "postcss": "^8.4.47",
"react": "^18.2.0", "react": "^18.2.0",
"react-date-range": "^1.4.0", "react-date-range": "^2.0.1",
"react-datepicker": "^4.18.0", "react-datepicker": "^7.4.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-hook-form": "^7.46.1", "react-hook-form": "^7.46.1",
"react-icons": "^4.10.1", "react-icons": "^5.3.0",
"react-input-mask": "^2.0.4", "react-input-mask": "^2.0.4",
"react-leaflet": "^4.2.1", "react-leaflet": "^4.2.1",
"react-leaflet-cluster": "^2.1.0", "react-leaflet-cluster": "^2.1.0",
@@ -63,25 +62,23 @@
"zod": "^3.22.4" "zod": "^3.22.4"
}, },
"devDependencies": { "devDependencies": {
"@swc-jotai/react-refresh": "^0.1.0", "@swc-jotai/react-refresh": "^0.2.0",
"@tailwindcss/forms": "^0.5.4", "@tailwindcss/forms": "^0.5.4",
"@testing-library/jest-dom": "^6.1.2", "@testing-library/jest-dom": "^6.1.2",
"@testing-library/react": "^14.0.0", "@types/leaflet": "^1.9.12",
"@types/leaflet": "^1.9.3", "@types/leaflet.markercluster": "^1.5.4",
"@types/leaflet.markercluster": "^1.5.1",
"@types/lodash": "^4.14.195", "@types/lodash": "^4.14.195",
"@types/nodemailer": "^6.4.8", "@types/nodemailer": "^6.4.8",
"@types/react": "^18.2.27", "@types/react": "^18.2.27",
"@types/react-date-range": "^1.4.9", "@types/react-date-range": "^1.4.9",
"@types/react-datepicker": "^4.15.0",
"@types/react-dom": "^18.2.18", "@types/react-dom": "^18.2.18",
"@types/react-input-mask": "^3.0.2", "@types/react-input-mask": "^3.0.2",
"eslint": "^8.54.0", "eslint": "8",
"eslint-config-next": "^14.0.4", "eslint-config-next": "^14.0.4",
"eslint-config-prettier": "^9.0.0", "eslint-config-prettier": "^9.0.0",
"eslint-plugin-react-hooks": "^5.0.0-canary-7118f5dd7-20230705", "eslint-plugin-react-hooks": "^5.0.0-canary-7118f5dd7-20230705",
"prettier": "^3.1.1", "prettier": "^3.1.1",
"prettier-plugin-tailwindcss": "^0.5.3" "prettier-plugin-tailwindcss": "^0.6.8"
}, },
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610" "packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
} }
@@ -23,7 +23,9 @@ export default function Contact() {
setDeleting(true); setDeleting(true);
const result = await deleteAccount(); const result = await deleteAccount();
if (result.serverError) { if (result?.validationErrors) {
throw new Error("ERR_VALIDATION");
} else if (result?.serverError) {
throw new Error(result.serverError); throw new Error(result.serverError);
} }
@@ -41,7 +41,9 @@ const EditZone = () => {
zone: data, zone: data,
}); });
if (updatedZone.serverError) { if (updatedZone?.validationErrors) {
throw new Error("ERR_VALIDATION");
} else if (updatedZone?.serverError) {
throw new Error(updatedZone.serverError); throw new Error(updatedZone.serverError);
} }
+2 -7
View File
@@ -4,12 +4,7 @@ import { useCallback, useEffect, useMemo, useRef } from "react";
import React from "react"; import React from "react";
import { useAtomValue, useSetAtom } from "jotai"; import { useAtomValue, useSetAtom } from "jotai";
import L, { import L, { DomUtil, LatLngLiteral, Marker } from "leaflet";
DomUtil,
LatLngLiteral,
Marker,
MarkerClusterGroupOptions,
} from "leaflet";
import "leaflet-defaulticon-compatibility"; import "leaflet-defaulticon-compatibility";
import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.css"; import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.css";
import "leaflet.smooth_marker_bouncing"; import "leaflet.smooth_marker_bouncing";
@@ -70,7 +65,7 @@ type MapProps = {
filters?: React.ReactNode; filters?: React.ReactNode;
legend?: React.ReactNode; legend?: React.ReactNode;
markers: MapMarker[]; markers: MapMarker[];
iconCreateFunction?: MarkerClusterGroupOptions["iconCreateFunction"]; iconCreateFunction?: L.MarkerClusterGroupOptions["iconCreateFunction"];
}; };
export const Map = ({ export const Map = ({
+2 -2
View File
@@ -79,8 +79,8 @@ export const RegionSelect = ({
}; };
const formatGroupLabel = (data: GroupedOption) => ( const formatGroupLabel = (data: GroupedOption) => (
<div className="relative -translate-y-1/2 border-b-2 border-primary-500 text-xs font-bold uppercase text-primary-500 "> <div className="relative -translate-y-1/2 border-b-2 border-primary-500 text-xs font-bold uppercase text-primary-500">
<div className="relative top-1/2 inline-block translate-y-1/2 bg-gray-50 pr-2 dark:bg-gray-700 "> <div className="relative top-1/2 inline-block translate-y-1/2 bg-gray-50 pr-2 dark:bg-gray-700">
{data.label} {data.label}
</div> </div>
</div> </div>
+1 -1
View File
@@ -47,7 +47,7 @@ export const SignInForm = ({ callbackPath }: SignInFormProps) => {
} }
}); });
return () => subscription.unsubscribe(); return () => subscription.unsubscribe();
}, [form, form.watch]); }, [form, form.watch, responseMessage.message]);
const onSubmit = async ({ email }: SignInFormValues) => { const onSubmit = async ({ email }: SignInFormValues) => {
try { try {
@@ -39,7 +39,7 @@ export const InputDatePicker = forwardRef<HTMLInputElement, AllProps>(
className={twMerge( className={twMerge(
"flex w-full content-center rounded-lg border p-3", "flex w-full content-center rounded-lg border p-3",
"border-gray-300 bg-gray-50 text-gray-900 shadow-sm", "border-gray-300 bg-gray-50 text-gray-900 shadow-sm",
"dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 ", "dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400",
!error && !error &&
"focus-within:border-primary-500 focus-within:ring-primary-500 dark:focus-within:border-primary-500 dark:focus-within:ring-primary-500", "focus-within:border-primary-500 focus-within:ring-primary-500 dark:focus-within:border-primary-500 dark:focus-within:ring-primary-500",
error && "!border-orange-700 focus:!border-orange-700", error && "!border-orange-700 focus:!border-orange-700",
+7 -7
View File
@@ -78,11 +78,7 @@ export const DateField = <
portalId="calendar-portal" portalId="calendar-portal"
dateFormat={dateFormat} dateFormat={dateFormat}
disabledKeyboardNavigation={true} disabledKeyboardNavigation={true}
formatWeekDay={(day: string) => ( formatWeekDay={(day: string) => day.slice(0, 3)}
<div className="flex h-8 flex-col items-center justify-center">
{day.slice(0, 3)}
</div>
)}
weekDayClassName={() => weekDayClassName={() =>
"text-xs h-8 w-8 flex-1 bg-gray-50 text-gray-900 dark:bg-gray-700 dark:text-white" "text-xs h-8 w-8 flex-1 bg-gray-50 text-gray-900 dark:bg-gray-700 dark:text-white"
} }
@@ -95,9 +91,13 @@ export const DateField = <
onChange={field.onChange} onChange={field.onChange}
onChangeRaw={(e) => { onChangeRaw={(e) => {
// Called when the user types in the input // Called when the user types in the input
if (e.currentTarget.value) { if (e?.currentTarget && "value" in e.currentTarget) {
const value = e.currentTarget.value; const value = e.currentTarget.value;
const date = parse(value, at("dateParseFormat"), new Date()); const date = parse(
value as string,
at("dateParseFormat"),
new Date(),
);
if ( if (
isValid(date) && isValid(date) &&
date.getFullYear() >= min && date.getFullYear() >= min &&
+1 -1
View File
@@ -60,7 +60,7 @@ export const TextField = <
? isNaN(value) ? isNaN(value)
? "" ? ""
: value.toString() : value.toString()
: value ?? ""; : (value ?? "");
}; };
const output = const output =
@@ -40,7 +40,8 @@ export const TournamentSelectField = <
useState<SearchedTournament | null>(null); useState<SearchedTournament | null>(null);
const loadOption = async (ffeId: string) => { const loadOption = async (ffeId: string) => {
const { data: tournament } = await getTournamentDetails({ ffeId }); const result = await getTournamentDetails({ ffeId });
const tournament = result?.data;
return !tournament return !tournament
? undefined ? undefined
@@ -52,10 +53,12 @@ export const TournamentSelectField = <
}; };
const loadOptions = async (searchValue?: string) => { const loadOptions = async (searchValue?: string) => {
const { data: tournaments } = await searchTournaments({ const result = await searchTournaments({
searchValue: searchValue ?? "", searchValue: searchValue ?? "",
}); });
const tournaments = result?.data ?? [];
return (tournaments ?? []).map((tournament) => ({ return (tournaments ?? []).map((tournament) => ({
value: tournament.ffeId, value: tournament.ffeId,
label: tournament.tournament, label: tournament.tournament,
@@ -73,7 +76,7 @@ export const TournamentSelectField = <
loadOptions={loadOptions} loadOptions={loadOptions}
isClearable={true} isClearable={true}
onInformChange={(data) => { onInformChange={(data) => {
setSelectedTournament(data ? data[0].data ?? null : null); setSelectedTournament(data ? (data[0].data ?? null) : null);
onInformChange?.(data); onInformChange?.(data);
}} }}
formatOptionLabel={(option, context) => { formatOptionLabel={(option, context) => {
+14 -7
View File
@@ -8,7 +8,7 @@ import { TimeControl } from "@/types";
import { errorLog } from "@/utils/logger"; import { errorLog } from "@/utils/logger";
import { TournamentModel } from "./models/tournamentModel"; import { TournamentModel } from "./models/tournamentModel";
import { action } from "./safeAction"; import { actionClient } from "./safeAction";
const tcMap: Record<TimeControl, TournamentModel["time_control"]> = { const tcMap: Record<TimeControl, TournamentModel["time_control"]> = {
[TimeControl.Classic]: "Cadence Lente", [TimeControl.Classic]: "Cadence Lente",
@@ -17,11 +17,13 @@ const tcMap: Record<TimeControl, TournamentModel["time_control"]> = {
[TimeControl.Other]: "Other", [TimeControl.Other]: "Other",
}; };
export const addTournament = action(addTournamentSchema, async (input) => { export const addTournament = actionClient
.schema(addTournamentSchema)
.action(async (input) => {
try { try {
await dbConnect(); await dbConnect();
const { name, email, message, tournament } = input; const { name, email, message, tournament } = input.parsedInput;
const tournamentData: Omit<TournamentModel, "_id" | "tournament_id"> = { const tournamentData: Omit<TournamentModel, "_id" | "tournament_id"> = {
...tournament, ...tournament,
@@ -40,8 +42,12 @@ export const addTournament = action(addTournamentSchema, async (input) => {
if (result.insertedId) { if (result.insertedId) {
const { tournament, country, date, time_control } = tournamentData; const { tournament, country, date, time_control } = tournamentData;
if (typeof process.env.DISCORD_WEBHOOK_ADD_TOURNAMENT_URL === "string") { if (
await fetch(process.env.DISCORD_WEBHOOK_ADD_TOURNAMENT_URL as string, { typeof process.env.DISCORD_WEBHOOK_ADD_TOURNAMENT_URL === "string"
) {
await fetch(
process.env.DISCORD_WEBHOOK_ADD_TOURNAMENT_URL as string,
{
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -65,7 +71,8 @@ export const addTournament = action(addTournamentSchema, async (input) => {
}, },
], ],
}), }),
}); },
);
} }
return true; return true;
@@ -74,4 +81,4 @@ export const addTournament = action(addTournamentSchema, async (input) => {
errorLog(error); errorLog(error);
throw error; throw error;
} }
}); });
+6 -4
View File
@@ -5,11 +5,13 @@ import { z } from "zod";
import { contactUsSchema } from "@/schemas"; import { contactUsSchema } from "@/schemas";
import { errorLog } from "@/utils/logger"; import { errorLog } from "@/utils/logger";
import { action } from "./safeAction"; import { actionClient } from "./safeAction";
export const contactUs = action(contactUsSchema, async (input) => { export const contactUs = actionClient
.schema(contactUsSchema)
.action(async (input) => {
try { try {
const { email, subject, message } = input; const { email, subject, message } = input.parsedInput;
await fetch(process.env.DISCORD_WEBHOOK_CONTACT_URL as string, { await fetch(process.env.DISCORD_WEBHOOK_CONTACT_URL as string, {
method: "POST", method: "POST",
headers: { headers: {
@@ -33,4 +35,4 @@ export const contactUs = action(contactUsSchema, async (input) => {
errorLog(error); errorLog(error);
throw error; throw error;
} }
}); });
+6 -4
View File
@@ -8,9 +8,11 @@ import { collections, dbConnect } from "@/server/mongodb";
import { errorLog } from "@/utils/logger"; import { errorLog } from "@/utils/logger";
import { ZoneModel } from "./models/zoneModel"; import { ZoneModel } from "./models/zoneModel";
import { action } from "./safeAction"; import { actionClient } from "./safeAction";
export const createZone = action(zoneSchema, async (input) => { export const createZone = actionClient
.schema(zoneSchema)
.action(async (input) => {
try { try {
await dbConnect(); await dbConnect();
@@ -20,7 +22,7 @@ export const createZone = action(zoneSchema, async (input) => {
} }
const zoneData: ZoneModel = { const zoneData: ZoneModel = {
...input, ...input.parsedInput,
userId: new ObjectId(user.user!.id!), userId: new ObjectId(user.user!.id!),
}; };
@@ -35,4 +37,4 @@ export const createZone = action(zoneSchema, async (input) => {
errorLog(error); errorLog(error);
throw error; throw error;
} }
}); });
+2 -2
View File
@@ -7,9 +7,9 @@ import { adapter, auth } from "@/auth";
import { collections, dbConnect } from "@/server/mongodb"; import { collections, dbConnect } from "@/server/mongodb";
import { errorLog } from "@/utils/logger"; import { errorLog } from "@/utils/logger";
import { action } from "./safeAction"; import { actionClient } from "./safeAction";
export const deleteAccount = action(z.void(), async () => { export const deleteAccount = actionClient.action(async () => {
try { try {
await dbConnect(); await dbConnect();
+7 -3
View File
@@ -7,13 +7,17 @@ import { auth } from "@/auth";
import { collections, dbConnect } from "@/server/mongodb"; import { collections, dbConnect } from "@/server/mongodb";
import { errorLog } from "@/utils/logger"; import { errorLog } from "@/utils/logger";
import { action } from "./safeAction"; import { actionClient } from "./safeAction";
const deleteZoneSchema = z.object({ const deleteZoneSchema = z.object({
id: z.string(), id: z.string(),
}); });
export const deleteZone = action(deleteZoneSchema, async ({ id }) => { export const deleteZone = actionClient
.schema(deleteZoneSchema)
.action(async (input) => {
const { id } = input.parsedInput;
try { try {
await dbConnect(); await dbConnect();
@@ -36,4 +40,4 @@ export const deleteZone = action(deleteZoneSchema, async ({ id }) => {
errorLog(error); errorLog(error);
throw error; throw error;
} }
}); });
+6 -3
View File
@@ -10,14 +10,17 @@ import { collections, dbConnect } from "@/server/mongodb";
import { errorLog } from "@/utils/logger"; import { errorLog } from "@/utils/logger";
import { ZoneModel } from "./models/zoneModel"; import { ZoneModel } from "./models/zoneModel";
import { action } from "./safeAction"; import { actionClient } from "./safeAction";
const editZoneSchema = z.object({ const editZoneSchema = z.object({
id: z.string(), id: z.string(),
zone: zoneSchema, zone: zoneSchema,
}); });
export const editZone = action(editZoneSchema, async ({ id, zone }) => { export const editZone = actionClient
.schema(editZoneSchema)
.action(async (input) => {
const { id, zone } = input.parsedInput;
try { try {
await dbConnect(); await dbConnect();
@@ -49,4 +52,4 @@ export const editZone = action(editZoneSchema, async ({ id, zone }) => {
errorLog(error); errorLog(error);
throw error; throw error;
} }
}); });
+8 -8
View File
@@ -5,7 +5,7 @@ import { z } from "zod";
import { fetchTournamentResultsSchema } from "@/schemas"; import { fetchTournamentResultsSchema } from "@/schemas";
import { errorLog } from "@/utils/logger"; import { errorLog } from "@/utils/logger";
import { action } from "./safeAction"; import { actionClient } from "./safeAction";
const dbSchema = z.array( const dbSchema = z.array(
z.object({ z.object({
@@ -106,9 +106,10 @@ const reportFetchError = async (url: string, error: any) => {
} }
}; };
export const fetchTournamentResults = action( export const fetchTournamentResults = actionClient
fetchTournamentResultsSchema, .schema(fetchTournamentResultsSchema)
async (input) => { .action(async (input) => {
const { id } = input.parsedInput;
try { try {
const headers = new Headers(); const headers = new Headers();
const apiKey = process.env.RESULTS_API_KEY; const apiKey = process.env.RESULTS_API_KEY;
@@ -118,7 +119,7 @@ export const fetchTournamentResults = action(
} }
const rawResults = await fetch( const rawResults = await fetch(
`${process.env.RESULTS_SCRAPER_URL}${input.id}`, `${process.env.RESULTS_SCRAPER_URL}${id}`,
{ {
headers: headers, headers: headers,
}, },
@@ -155,9 +156,8 @@ export const fetchTournamentResults = action(
})), })),
); );
} catch (error) { } catch (error) {
reportFetchError(input.id, error); reportFetchError(id, error);
errorLog(JSON.stringify(error, null, 2)); errorLog(JSON.stringify(error, null, 2));
throw error; throw error;
} }
}, });
);
+7 -4
View File
@@ -6,17 +6,20 @@ import { collections, dbConnect } from "@/server/mongodb";
import { TimeControl, tcMap } from "@/types"; import { TimeControl, tcMap } from "@/types";
import { errorLog } from "@/utils/logger"; import { errorLog } from "@/utils/logger";
import { action } from "./safeAction"; import { actionClient } from "./safeAction";
const inputSchema = z.object({ const inputSchema = z.object({
ffeId: z.string(), ffeId: z.string(),
}); });
export const getTournamentDetails = action(inputSchema, async (input) => { export const getTournamentDetails = actionClient
.schema(inputSchema)
.action(async (input) => {
const { ffeId } = input.parsedInput;
try { try {
await dbConnect(); await dbConnect();
const t = await collections.tournaments!.findOne({ const t = await collections.tournaments!.findOne({
tournament_id: input.ffeId, tournament_id: ffeId,
}); });
if (t === null) { if (t === null) {
@@ -40,4 +43,4 @@ export const getTournamentDetails = action(inputSchema, async (input) => {
errorLog(JSON.stringify(error, null, 2)); errorLog(JSON.stringify(error, null, 2));
throw error; throw error;
} }
}); });
+2 -3
View File
@@ -3,20 +3,19 @@
import { FeatureCollection } from "geojson"; import { FeatureCollection } from "geojson";
import { omit } from "lodash"; import { omit } from "lodash";
import { ObjectId } from "mongodb"; import { ObjectId } from "mongodb";
import { z } from "zod";
import { auth } from "@/auth"; import { auth } from "@/auth";
import { collections, dbConnect } from "@/server/mongodb"; import { collections, dbConnect } from "@/server/mongodb";
import { ZoneModel } from "./models/zoneModel"; import { ZoneModel } from "./models/zoneModel";
import { action } from "./safeAction"; import { actionClient } from "./safeAction";
export type Zone = Omit<ZoneModel, "userId" | "features"> & { export type Zone = Omit<ZoneModel, "userId" | "features"> & {
id: string; id: string;
features: FeatureCollection; features: FeatureCollection;
}; };
export const myZones = action(z.void(), async () => { export const myZones = actionClient.action(async () => {
await dbConnect(); await dbConnect();
const user = await auth(); const user = await auth();
+8 -5
View File
@@ -8,7 +8,7 @@ import { TimeControl, Tournament, tcMap } from "@/types";
import { errorLog } from "@/utils/logger"; import { errorLog } from "@/utils/logger";
import { removeDiacritics } from "@/utils/string"; import { removeDiacritics } from "@/utils/string";
import { action } from "./safeAction"; import { actionClient } from "./safeAction";
const inputSchema = z.object({ const inputSchema = z.object({
searchValue: z.string(), searchValue: z.string(),
@@ -28,11 +28,14 @@ export type SearchedTournament = Pick<
| "url" | "url"
>; >;
export const searchTournaments = action(inputSchema, async (input) => { export const searchTournaments = actionClient
.schema(inputSchema)
.action(async (input) => {
const { searchValue, limit } = input.parsedInput;
try { try {
await dbConnect(); await dbConnect();
const searchTerms = input.searchValue const searchTerms = searchValue
.split(" ") .split(" ")
.map((s) => removeDiacritics(s.trim())) .map((s) => removeDiacritics(s.trim()))
.filter((s) => s !== "") .filter((s) => s !== "")
@@ -64,7 +67,7 @@ export const searchTournaments = action(inputSchema, async (input) => {
dateParts: -1, dateParts: -1,
}, },
}, },
{ $limit: input.limit ?? 20 }, { $limit: limit ?? 20 },
{ {
$unset: "dateParts", $unset: "dateParts",
}, },
@@ -90,4 +93,4 @@ export const searchTournaments = action(inputSchema, async (input) => {
errorLog(JSON.stringify(error, null, 2)); errorLog(JSON.stringify(error, null, 2));
throw error; throw error;
} }
}); });
+1 -4
View File
@@ -1,5 +1,4 @@
import { LatLngLiteral } from "leaflet"; import { LatLngLiteral } from "leaflet";
import { SafeAction } from "next-safe-action";
import { TournamentModel } from "./server/models/tournamentModel"; import { TournamentModel } from "./server/models/tournamentModel";
@@ -65,7 +64,5 @@ export type Path<T, K extends keyof T = keyof T> = K extends string
? T[K] extends Record<string, unknown> ? T[K] extends Record<string, unknown>
? `${K}.${Path<T[K], keyof T[K]>}` ? `${K}.${Path<T[K], keyof T[K]>}`
: K : K
: never;
export type ExtractSafeActionResult<T> = : never;
T extends SafeAction<infer Schema, infer Result> ? Result : never;
+1 -1
View File
@@ -110,7 +110,7 @@ export interface NodemailerConfig extends EmailConfig {
theme: any; theme: any;
request: Request; request: Request;
}) => Awaitable<void>; }) => Awaitable<void>;
options: NodemailerUserConfig; options?: NodemailerUserConfig;
} }
export type NodemailerUserConfig = Omit< export type NodemailerUserConfig = Omit<
+1151 -1032
View File
File diff suppressed because it is too large Load Diff