mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-11-18 07:22:06 +00:00
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:
+39
-44
@@ -1,52 +1,50 @@
|
||||
import { type ComponentProps } from 'react'
|
||||
import { type VariantProps, cva } from "class-variance-authority";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export const buttonVariants = cva(
|
||||
"flex items-center justify-center transition-all duration-200",
|
||||
{
|
||||
variants: {
|
||||
intent: {
|
||||
primary: [
|
||||
"text-center",
|
||||
"text-white",
|
||||
"focus:outline-none focus:ring-2 focus:ring-primary-500",
|
||||
"bg-primary-600",
|
||||
"hover:bg-primary-800",
|
||||
"disabled:opacity-25",
|
||||
"dark:text-white dark:hover:bg-primary-700",
|
||||
],
|
||||
export const buttonVariants = cva("flex items-center justify-center transition-all duration-200", {
|
||||
variants: {
|
||||
intent: {
|
||||
primary: [
|
||||
"text-center",
|
||||
"text-white",
|
||||
"focus:outline-none focus:ring-2 focus:ring-primary-500",
|
||||
"bg-primary-600",
|
||||
"hover:bg-primary-800",
|
||||
"disabled:opacity-25",
|
||||
"dark:text-white dark:hover:bg-primary-700",
|
||||
],
|
||||
|
||||
secondary: [
|
||||
"text-primary dark:text-white",
|
||||
"hover:text-white dark:hover:text-white",
|
||||
"hover:bg-primary hover:text-white",
|
||||
"border border-primary",
|
||||
"focus:outline-none focus:ring-2 focus:ring-primary-500",
|
||||
"disabled:opacity-25",
|
||||
],
|
||||
secondary: [
|
||||
"text-primary dark:text-white",
|
||||
"hover:text-white dark:hover:text-white",
|
||||
"hover:bg-primary hover:text-white",
|
||||
"border border-primary",
|
||||
"focus:outline-none focus:ring-2 focus:ring-primary-500",
|
||||
"disabled:opacity-25",
|
||||
],
|
||||
|
||||
tertiary: [
|
||||
"text-gray-900 dark:text-neutral-400",
|
||||
"hover:text-primary dark:hover:text-white",
|
||||
"focus:outline-none focus:ring-2 focus:ring-primary-500",
|
||||
"disabled:opacity-25",
|
||||
],
|
||||
},
|
||||
size: {
|
||||
small: ["text-sm font-medium", "px-3 py-2", "sm:w-fit", "rounded-lg"],
|
||||
medium: ["text-sm font-medium", "px-5 py-3", "sm:w-fit", "rounded-lg"],
|
||||
compacted: ["rounded-none", "px-0 py-0"],
|
||||
},
|
||||
tertiary: [
|
||||
"text-gray-900 dark:text-neutral-400",
|
||||
"hover:text-primary dark:hover:text-white",
|
||||
"focus:outline-none focus:ring-2 focus:ring-primary-500",
|
||||
"disabled:opacity-25",
|
||||
],
|
||||
},
|
||||
defaultVariants: {
|
||||
intent: "primary",
|
||||
size: "medium",
|
||||
size: {
|
||||
small: ["text-sm font-medium", "px-3 py-2", "sm:w-fit", "rounded-lg"],
|
||||
medium: ["text-sm font-medium", "px-5 py-3", "sm:w-fit", "rounded-lg"],
|
||||
compacted: ["rounded-none", "px-0 py-0"],
|
||||
},
|
||||
},
|
||||
);
|
||||
defaultVariants: {
|
||||
intent: "primary",
|
||||
size: "medium",
|
||||
},
|
||||
});
|
||||
|
||||
export type ButtonVariants = VariantProps<typeof buttonVariants>;
|
||||
export type ButtonProps = React.ComponentProps<"button"> & ButtonVariants;
|
||||
type ButtonVariants = VariantProps<typeof buttonVariants>;
|
||||
export type ButtonProps = ComponentProps<"button"> & ButtonVariants;
|
||||
|
||||
export const Button = ({
|
||||
className,
|
||||
@@ -54,8 +52,5 @@ export const Button = ({
|
||||
size,
|
||||
...props
|
||||
}: ButtonProps & { className?: string }) => (
|
||||
<button
|
||||
className={twMerge(buttonVariants({ intent, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
<button className={twMerge(buttonVariants({ intent, size, className }))} {...props} />
|
||||
);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import React from "react";
|
||||
|
||||
import { Float } from "@headlessui-float/react";
|
||||
import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/react";
|
||||
import { IoMdMore } from "react-icons/io";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
@@ -18,54 +17,43 @@ type DropdownMenuProps = {
|
||||
containerClassName?: string;
|
||||
};
|
||||
|
||||
export const DropdownMenu = ({
|
||||
items,
|
||||
buttonComponent,
|
||||
containerClassName,
|
||||
}: DropdownMenuProps) => {
|
||||
export const DropdownMenu = ({ items, buttonComponent, containerClassName }: DropdownMenuProps) => {
|
||||
return (
|
||||
<Menu as="div" className={twMerge("relative", containerClassName)}>
|
||||
<Float
|
||||
portal
|
||||
placement="bottom-end"
|
||||
offset={15}
|
||||
enter="transition ease-out duration-100"
|
||||
enterFrom="transform opacity-0 scale-95"
|
||||
enterTo="transform opacity-100 scale-100"
|
||||
leave="transition ease-in duration-75"
|
||||
leaveFrom="transform opacity-100 scale-100"
|
||||
leaveTo="transform opacity-0 scale-95"
|
||||
>
|
||||
{buttonComponent ?? (
|
||||
<MenuButton>
|
||||
<IoMdMore />
|
||||
</MenuButton>
|
||||
)}
|
||||
{buttonComponent ?? (
|
||||
<MenuButton>
|
||||
<IoMdMore />
|
||||
</MenuButton>
|
||||
)}
|
||||
|
||||
<MenuItems className="z-20 flex w-auto items-start overflow-hidden rounded-md bg-neutral-200 focus:outline-none dark:bg-neutral-600">
|
||||
<div className="flex flex-col px-1 py-1">
|
||||
{items.map(({ title, onClick, className, disabled }, i) => (
|
||||
<MenuItem key={i}>
|
||||
<button
|
||||
type="button"
|
||||
className={twMerge(
|
||||
"w-full whitespace-nowrap rounded-md px-2.5 py-2 text-left text-sm text-black dark:text-white",
|
||||
!disabled && "hover:bg-white dark:hover:bg-neutral-700",
|
||||
disabled && "text-neutral-500 dark:text-neutral-500",
|
||||
className,
|
||||
)}
|
||||
disabled={disabled ?? false}
|
||||
onClick={() => {
|
||||
if (!disabled) onClick();
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</button>
|
||||
</MenuItem>
|
||||
))}
|
||||
</div>
|
||||
</MenuItems>
|
||||
</Float>
|
||||
<MenuItems
|
||||
anchor={{ to: "bottom end", gap: 15 }}
|
||||
portal
|
||||
transition
|
||||
className="z-20 flex w-auto items-start overflow-hidden rounded-md bg-neutral-200 transition ease-out data-[closed]:scale-95 data-[closed]:opacity-0 focus:outline-none dark:bg-neutral-600"
|
||||
>
|
||||
<div className="flex flex-col px-1 py-1">
|
||||
{items.map(({ title, onClick, className, disabled }, i) => (
|
||||
<MenuItem key={i}>
|
||||
<button
|
||||
type="button"
|
||||
className={twMerge(
|
||||
"w-full whitespace-nowrap rounded-md px-2.5 py-2 text-left text-sm text-black dark:text-white",
|
||||
!disabled && "hover:bg-white dark:hover:bg-neutral-700",
|
||||
disabled && "text-neutral-500 dark:text-neutral-500",
|
||||
className,
|
||||
)}
|
||||
disabled={disabled ?? false}
|
||||
onClick={() => {
|
||||
if (!disabled) onClick();
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</button>
|
||||
</MenuItem>
|
||||
))}
|
||||
</div>
|
||||
</MenuItems>
|
||||
</Menu>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { type ReactNode } from "react";
|
||||
|
||||
import {
|
||||
HiCheckCircle,
|
||||
HiInformationCircle,
|
||||
HiXCircle,
|
||||
HiXMark,
|
||||
} from "react-icons/hi2";
|
||||
import { HiCheckCircle, HiInformationCircle, HiXCircle, HiXMark } from "react-icons/hi2";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export type InfoMessageType = "success" | "error" | "info";
|
||||
@@ -74,11 +69,7 @@ const InfoMessage = ({
|
||||
button,
|
||||
)}
|
||||
>
|
||||
<HiXMark
|
||||
aria-hidden="true"
|
||||
className="h-5 w-5"
|
||||
onClick={onDismiss}
|
||||
/>
|
||||
<HiXMark aria-hidden="true" className="h-5 w-5" onClick={onDismiss} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
import { Spinner } from "./Spinner";
|
||||
|
||||
const LoadingMap = () => {
|
||||
const t = useTranslations("Tournaments");
|
||||
return (
|
||||
<div className="mt-20 flex h-content justify-center bg-white pt-20 text-center text-gray-900 dark:bg-gray-800 dark:text-white">
|
||||
<Spinner />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, type ReactNode } from "react";
|
||||
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useLocale } from "next-intl";
|
||||
@@ -10,11 +10,11 @@ import { setUserLocale } from "@/server/setUserLocale";
|
||||
import { usePathname, useRouter } from "@/utils/routing";
|
||||
|
||||
type LocaleCheckerProps = {
|
||||
children?: React.ReactNode;
|
||||
children?: ReactNode;
|
||||
};
|
||||
|
||||
export const LocaleChecker = ({ children }: LocaleCheckerProps) => {
|
||||
const { data: sessionData, status, update } = useSession();
|
||||
const { data: sessionData, status } = useSession();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const params = useParams();
|
||||
@@ -30,23 +30,14 @@ export const LocaleChecker = ({ children }: LocaleCheckerProps) => {
|
||||
|
||||
// If the user is authenticated and has a preferred locale that is different from the user's locale,
|
||||
// then we update redirect to the user's preference
|
||||
if (
|
||||
status === "authenticated" &&
|
||||
userLocale !== undefined &&
|
||||
userLocale !== locale
|
||||
) {
|
||||
if (status === "authenticated" && userLocale !== undefined && userLocale !== locale) {
|
||||
router.push({ pathname, params: params as any }, { locale: userLocale });
|
||||
}
|
||||
}, [locale, sessionData, status, params, pathname, router, userLocale]);
|
||||
|
||||
// To avoid flickering, we don't render the children until we have the user's locale
|
||||
if (status === "loading") return null;
|
||||
if (
|
||||
status === "authenticated" &&
|
||||
userLocale !== undefined &&
|
||||
userLocale !== locale
|
||||
)
|
||||
return null;
|
||||
if (status === "authenticated" && userLocale !== undefined && userLocale !== locale) return null;
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
+18
-29
@@ -12,6 +12,8 @@ import "leaflet/dist/leaflet.css";
|
||||
import { FaAngleDoubleDown } from "react-icons/fa";
|
||||
import { LayerGroup, MapContainer, TileLayer } from "react-leaflet";
|
||||
import MarkerClusterGroup from "react-leaflet-cluster";
|
||||
import "react-leaflet-cluster/lib/assets/MarkerCluster.css";
|
||||
import "react-leaflet-cluster/lib/assets/MarkerCluster.Default.css";
|
||||
|
||||
import { debouncedHoveredListIdAtom, mapBoundsAtom } from "@/atoms";
|
||||
import { MapEvents } from "@/components/MapEvents";
|
||||
@@ -57,12 +59,7 @@ type MapProps = {
|
||||
iconCreateFunction?: L.MarkerClusterGroupOptions["iconCreateFunction"];
|
||||
};
|
||||
|
||||
export const Map = ({
|
||||
filters,
|
||||
legend,
|
||||
markers: markers,
|
||||
iconCreateFunction,
|
||||
}: MapProps) => {
|
||||
export const Map = ({ filters, legend, markers, iconCreateFunction }: MapProps) => {
|
||||
const setMapBounds = useSetAtom(mapBoundsAtom);
|
||||
|
||||
const hoveredListTournamentId = useAtomValue(debouncedHoveredListIdAtom);
|
||||
@@ -80,17 +77,13 @@ export const Map = ({
|
||||
|
||||
const expandAndBounceIfNeeded = useCallback(() => {
|
||||
if (hoveredListTournamentId) {
|
||||
const marker = markers.find((m) =>
|
||||
m.tableIds.includes(hoveredListTournamentId),
|
||||
);
|
||||
const marker = markers.find((m) => m.tableIds.includes(hoveredListTournamentId));
|
||||
|
||||
if (marker) {
|
||||
const markerRef = markerRefs.current[marker.markerId];
|
||||
if (markerRef) {
|
||||
if (clusterRef.current) {
|
||||
const visibleMarker = clusterRef.current.getVisibleParent(
|
||||
markerRef.getMarker(),
|
||||
);
|
||||
const visibleMarker = clusterRef.current.getVisibleParent(markerRef.getMarker());
|
||||
if (!visibleMarker) return;
|
||||
|
||||
// @ts-ignore
|
||||
@@ -138,9 +131,7 @@ export const Map = ({
|
||||
// Once expanded, bounce the appropriate marker
|
||||
|
||||
if (hoveredListTournamentId) {
|
||||
const marker = markers.find((m) =>
|
||||
m.tableIds.includes(hoveredListTournamentId),
|
||||
);
|
||||
const marker = markers.find((m) => m.tableIds.includes(hoveredListTournamentId));
|
||||
if (!marker) return;
|
||||
|
||||
expandedClusterMarkerRef.current = e.cluster;
|
||||
@@ -157,8 +148,7 @@ export const Map = ({
|
||||
|
||||
const onUnSpiderified = useCallback(
|
||||
(e: L.MarkerClusterSpiderfyEvent) => {
|
||||
if (expandedClusterMarkerRef.current === e.cluster)
|
||||
expandedClusterMarkerRef.current = null;
|
||||
if (expandedClusterMarkerRef.current === e.cluster) expandedClusterMarkerRef.current = null;
|
||||
|
||||
// Once closed, we can expand the next group if needed
|
||||
expandAndBounceIfNeeded();
|
||||
@@ -186,18 +176,22 @@ export const Map = ({
|
||||
// Expand/contract as hoveredListTournamentId changes
|
||||
if (expandAndBounceIfNeeded()) return;
|
||||
|
||||
if (expandedClusterMarkerRef.current)
|
||||
expandedClusterMarkerRef.current.unspiderfy();
|
||||
if (expandedClusterMarkerRef.current) expandedClusterMarkerRef.current.unspiderfy();
|
||||
}, [expandAndBounceIfNeeded, hoveredListTournamentId]);
|
||||
|
||||
const referencedMarkers = useMemo(
|
||||
() =>
|
||||
markers.map((marker) =>
|
||||
React.cloneElement(marker.component, {
|
||||
ref: (ref: MarkerRef) => {
|
||||
markerRefs.current[marker.markerId] = ref;
|
||||
React.cloneElement(
|
||||
marker.component as React.ReactElement<{
|
||||
ref?: (ref: MarkerRef) => void;
|
||||
}>,
|
||||
{
|
||||
ref: (ref: MarkerRef) => {
|
||||
markerRefs.current[marker.markerId] = ref;
|
||||
},
|
||||
},
|
||||
}),
|
||||
),
|
||||
),
|
||||
[markers],
|
||||
);
|
||||
@@ -240,12 +234,7 @@ export const Map = ({
|
||||
</MapContainer>
|
||||
|
||||
<div className="flex items-center justify-center lg:hidden">
|
||||
<Button
|
||||
intent="tertiary"
|
||||
size="compacted"
|
||||
className="p-3"
|
||||
onClick={onScrollToTable}
|
||||
>
|
||||
<Button intent="tertiary" size="compacted" className="p-3" onClick={onScrollToTable}>
|
||||
<FaAngleDoubleDown />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -14,10 +14,7 @@ import { mapBoundsAtom } from "@/atoms";
|
||||
L.Map.addInitHook("addHandler", "gestureHandling", GestureHandling);
|
||||
|
||||
const worldBounds = L.latLngBounds(L.latLng(-90, -180), L.latLng(90, 180));
|
||||
const franceBounds = L.latLngBounds(
|
||||
L.latLng(42.08, -5.12),
|
||||
L.latLng(51.17, 9.53),
|
||||
);
|
||||
const franceBounds = L.latLngBounds(L.latLng(42.08, -5.12), L.latLng(51.17, 9.53));
|
||||
|
||||
type MapEventsProps = {
|
||||
bounds?: L.LatLngBounds;
|
||||
@@ -32,7 +29,7 @@ export const MapEvents = ({
|
||||
const t = useTranslations("Map");
|
||||
const map = useMap();
|
||||
const setMapBounds = useSetAtom(mapBoundsAtom);
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const [_isPending, startTransition] = useTransition();
|
||||
|
||||
useMapEvent("moveend", () => {
|
||||
if (!updateMapBoundsAtom) return;
|
||||
@@ -49,17 +46,12 @@ export const MapEvents = ({
|
||||
map.setView(bounds.getCenter(), zoom === Infinity ? 10 : zoom);
|
||||
map.setMaxBounds(worldBounds);
|
||||
map.options.maxBoundsViscosity = 1.0; // Prevents going past bounds while dragging
|
||||
|
||||
map.addHandler("gestureHandling", GestureHandling);
|
||||
|
||||
map.gestureHandling?.enable();
|
||||
}, [bounds, map]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
"gestureHandlingOptions" in map.options &&
|
||||
map.options.gestureHandlingOptions
|
||||
) {
|
||||
if ("gestureHandlingOptions" in map.options && map.options.gestureHandlingOptions) {
|
||||
map.options.gestureHandlingOptions.text = {
|
||||
touch: t("touch"),
|
||||
scroll: t("scroll"),
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
|
||||
import { trackAppRouter } from "@socialgouv/matomo-next";
|
||||
import { usePathname, useSearchParams } from "next/navigation";
|
||||
import { useEffect } from "react";
|
||||
|
||||
const MATOMO_URL = process.env.NEXT_PUBLIC_MATOMO_URL;
|
||||
const MATOMO_SITE_ID = process.env.NEXT_PUBLIC_MATOMO_SITE_ID;
|
||||
const isMatomoEnabled = Boolean(MATOMO_URL && MATOMO_SITE_ID);
|
||||
|
||||
export function MatomoAnalytics() {
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isMatomoEnabled) return;
|
||||
|
||||
trackAppRouter({
|
||||
url: MATOMO_URL || "",
|
||||
siteId: MATOMO_SITE_ID || "",
|
||||
url: MATOMO_URL as string,
|
||||
siteId: MATOMO_SITE_ID as string,
|
||||
pathname,
|
||||
searchParams, // Pass URLSearchParams object directly
|
||||
// Optional: Enable additional features
|
||||
searchParams,
|
||||
enableHeatmapSessionRecording: false,
|
||||
enableHeartBeatTimer: true,
|
||||
cleanUrl: true,
|
||||
@@ -27,4 +30,4 @@ export function MatomoAnalytics() {
|
||||
}, [pathname, searchParams]);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +30,7 @@ export const Modal = ({
|
||||
...dialogProps
|
||||
}: ModalProps) => (
|
||||
<Transition appear show={open} as={Fragment}>
|
||||
<Dialog
|
||||
as="div"
|
||||
className="relative z-[2000]"
|
||||
onClose={onClose}
|
||||
{...dialogProps}
|
||||
>
|
||||
<Dialog as="div" className="relative z-[2000]" onClose={onClose} {...dialogProps}>
|
||||
<Transition.Child
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
@@ -45,9 +40,7 @@ export const Modal = ({
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<div
|
||||
className={twMerge("fixed inset-0 bg-neutral-900/50", overlayClass)}
|
||||
/>
|
||||
<div className={twMerge("fixed inset-0 bg-neutral-900/50", overlayClass)} />
|
||||
</Transition.Child>
|
||||
|
||||
<div className="fixed inset-0 overflow-y-auto">
|
||||
|
||||
@@ -22,10 +22,7 @@ type RegionSelectProps = Omit<
|
||||
type RegionOption = BaseOption<string, Zone | null>;
|
||||
type GroupedOption = GroupBase<RegionOption>;
|
||||
|
||||
export const RegionSelect = ({
|
||||
syncTitle,
|
||||
...selectProps
|
||||
}: RegionSelectProps) => {
|
||||
export const RegionSelect = ({ syncTitle, ...selectProps }: RegionSelectProps) => {
|
||||
const t = useTranslations("Zones");
|
||||
const router = useRouter();
|
||||
const [regionFilter, setRegionFilter] = useAtom(regionFilterAtom);
|
||||
@@ -67,9 +64,7 @@ export const RegionSelect = ({
|
||||
},
|
||||
];
|
||||
|
||||
const onChange = (
|
||||
option: OnChangeValue<BaseOption<string, Zone | null>, false>,
|
||||
) => {
|
||||
const onChange = (option: OnChangeValue<BaseOption<string, Zone | null>, false>) => {
|
||||
if (!option) return;
|
||||
|
||||
if (option.value === "create") {
|
||||
@@ -114,11 +109,7 @@ export const RegionSelect = ({
|
||||
);
|
||||
|
||||
const getValue = () => {
|
||||
if (
|
||||
regionFilter === "all" ||
|
||||
regionFilter === "map" ||
|
||||
regionFilter === "region"
|
||||
) {
|
||||
if (regionFilter === "all" || regionFilter === "map" || regionFilter === "region") {
|
||||
return allOptions.find((o) => o.value === regionFilter);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
|
||||
import {
|
||||
type Feature,
|
||||
GeoJsonProperties,
|
||||
MultiPolygon,
|
||||
Polygon,
|
||||
} from "geojson";
|
||||
import { type Feature, GeoJsonProperties, MultiPolygon, Polygon } from "geojson";
|
||||
import { useSetAtom } from "jotai";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { IoClose } from "react-icons/io5";
|
||||
@@ -20,10 +15,7 @@ interface IProps {
|
||||
setIsRegionModalOpen: Dispatch<SetStateAction<boolean>>;
|
||||
}
|
||||
|
||||
export const RegionSelectModal = ({
|
||||
isRegionModalOpen,
|
||||
setIsRegionModalOpen,
|
||||
}: IProps) => {
|
||||
export const RegionSelectModal = ({ isRegionModalOpen, setIsRegionModalOpen }: IProps) => {
|
||||
const t = useTranslations("Zones");
|
||||
const setRegionFilter = useSetAtom(regionFilterAtom);
|
||||
|
||||
@@ -32,13 +24,9 @@ export const RegionSelectModal = ({
|
||||
};
|
||||
|
||||
const handleRegionSelect = (region: string) => {
|
||||
const regionData = regionGeoJson.features.find(
|
||||
(f) => f.properties.nom === region,
|
||||
);
|
||||
const regionData = regionGeoJson.features.find((f) => f.properties.nom === region);
|
||||
if (regionData) {
|
||||
setRegionFilter(
|
||||
regionData as Feature<Polygon | MultiPolygon, GeoJsonProperties>,
|
||||
);
|
||||
setRegionFilter(regionData as Feature<Polygon | MultiPolygon, GeoJsonProperties>);
|
||||
handleCloseModal();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,7 +3,6 @@ import { useTransition } from "react";
|
||||
import { useAtom } from "jotai/index";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { IoCloseOutline } from "react-icons/io5";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { searchStringAtom } from "@/atoms";
|
||||
|
||||
@@ -14,10 +13,11 @@ type SearchBarProps = {
|
||||
className?: string;
|
||||
};
|
||||
|
||||
// oxlint-disable-next-line no-unused-vars
|
||||
const SearchBar = ({ className }: SearchBarProps) => {
|
||||
const t = useTranslations("Tournaments");
|
||||
const [searchString, setSearchString] = useAtom(searchStringAtom);
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const [_isPending, startTransition] = useTransition();
|
||||
|
||||
const updateSearchString = (str: string) => {
|
||||
startTransition(() => {
|
||||
@@ -53,11 +53,7 @@ const SearchBar = ({ className }: SearchBarProps) => {
|
||||
}
|
||||
endIcon={
|
||||
searchString !== "" && (
|
||||
<Button
|
||||
intent="tertiary"
|
||||
size="compacted"
|
||||
onClick={() => setSearchString("")}
|
||||
>
|
||||
<Button intent="tertiary" size="compacted" onClick={() => setSearchString("")}>
|
||||
<IoCloseOutline className="h-5 w-5" />
|
||||
</Button>
|
||||
)
|
||||
|
||||
@@ -97,10 +97,7 @@ export const SignInForm = ({ callbackPath }: SignInFormProps) => {
|
||||
</Button>
|
||||
|
||||
{responseMessage && (
|
||||
<InfoMessage
|
||||
message={responseMessage.message}
|
||||
type={responseMessage.type}
|
||||
/>
|
||||
<InfoMessage message={responseMessage.message} type={responseMessage.type} />
|
||||
)}
|
||||
</form>
|
||||
</FormProvider>
|
||||
|
||||
@@ -2,13 +2,7 @@ import React, { useEffect, useRef, useState } from "react";
|
||||
|
||||
import { get, isArray, isNil } from "lodash";
|
||||
import { useTranslations } from "next-intl";
|
||||
import {
|
||||
Controller,
|
||||
FieldPath,
|
||||
FieldValues,
|
||||
useFormContext,
|
||||
useWatch,
|
||||
} from "react-hook-form";
|
||||
import { Controller, FieldPath, FieldValues, useFormContext, useWatch } from "react-hook-form";
|
||||
import { ActionMeta, GroupBase, OnChangeValue, Props } from "react-select";
|
||||
import AsyncSelect from "react-select/async";
|
||||
|
||||
@@ -52,19 +46,16 @@ export const AsyncSelectField = <
|
||||
hideErrorMessage,
|
||||
required,
|
||||
size,
|
||||
|
||||
loadOption,
|
||||
loadOptions,
|
||||
onInformChange,
|
||||
|
||||
placeholder,
|
||||
separators,
|
||||
|
||||
...selectProps
|
||||
}: AsyncSelectFieldProps<TFieldValues, TFieldName, IsMulti, T, D>) => {
|
||||
const t = useTranslations("App");
|
||||
const [loadingValues, setLoadingValues] = useState(false);
|
||||
const [loadedInitialValues, setLoadedInitialValues] = useState(false);
|
||||
const [_loadedInitialValues, setLoadedInitialValues] = useState(false);
|
||||
const [loadingOptions, setLoadingOptions] = useState(false);
|
||||
const valueOptions = useRef<BaseOption<T, D>[]>([]);
|
||||
const searchOptions = useRef<BaseOption<T, D>[]>([]);
|
||||
@@ -78,8 +69,7 @@ export const AsyncSelectField = <
|
||||
const values = !value ? [] : isArray(value) ? value : [value];
|
||||
|
||||
const unFetchedValues = values.filter(
|
||||
(v) =>
|
||||
valueOptions.current.find((o) => o.value === value) === undefined,
|
||||
() => valueOptions.current.find((o) => o.value === value) === undefined,
|
||||
);
|
||||
|
||||
if (unFetchedValues.length > 0) {
|
||||
@@ -98,9 +88,10 @@ export const AsyncSelectField = <
|
||||
setLoadingValues(false);
|
||||
|
||||
onInformChange?.(
|
||||
values.map(
|
||||
(v) => valueOptions.current.find((o) => o.value === v)!,
|
||||
) as BaseOption<T, D>[],
|
||||
values.map((v) => valueOptions.current.find((o) => o.value === v)!) as BaseOption<
|
||||
T,
|
||||
D
|
||||
>[],
|
||||
);
|
||||
|
||||
// This forced a state update, which enures that the select is updated once the query has finished
|
||||
@@ -122,9 +113,10 @@ export const AsyncSelectField = <
|
||||
const hasError = !!get(errors, name)?.message;
|
||||
|
||||
const valueToOption = (value: T) =>
|
||||
[...valueOptions.current, ...searchOptions.current].find(
|
||||
(o) => o.value === value,
|
||||
) ?? { value, label: "" };
|
||||
[...valueOptions.current, ...searchOptions.current].find((o) => o.value === value) ?? {
|
||||
value,
|
||||
label: "",
|
||||
};
|
||||
|
||||
const fetchOptions = async (searchString?: string) => {
|
||||
setLoadingOptions(true);
|
||||
|
||||
@@ -12,10 +12,7 @@ interface InputProps {
|
||||
}
|
||||
|
||||
type AllProps = Omit<
|
||||
React.DetailedHTMLProps<
|
||||
React.InputHTMLAttributes<HTMLInputElement>,
|
||||
HTMLInputElement
|
||||
>,
|
||||
React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>,
|
||||
"ref"
|
||||
> &
|
||||
InputProps;
|
||||
@@ -24,12 +21,13 @@ export const InputDatePicker = forwardRef<HTMLInputElement, AllProps>(
|
||||
(
|
||||
{
|
||||
error,
|
||||
// oxlint-disable-next-line no-unused-vars
|
||||
className,
|
||||
// oxlint-disable-next-line no-unused-vars
|
||||
children,
|
||||
inputContainerClass,
|
||||
inputClass,
|
||||
mask,
|
||||
|
||||
...props
|
||||
},
|
||||
inputRef,
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import React, { useRef } from "react";
|
||||
import { useRef } from "react";
|
||||
|
||||
import { getYear, isValid, parse } from "date-fns";
|
||||
import fr from "date-fns/locale/fr";
|
||||
import { get } from "lodash";
|
||||
import { useLocale, useTranslations } from "next-intl";
|
||||
import DatePicker, { registerLocale } from "react-datepicker";
|
||||
import {
|
||||
Controller,
|
||||
FieldPath,
|
||||
FieldValues,
|
||||
useFormContext,
|
||||
} from "react-hook-form";
|
||||
import { Controller, FieldPath, FieldValues, useFormContext } from "react-hook-form";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { Prettify } from "@/types";
|
||||
@@ -45,10 +40,8 @@ export const DateField = <
|
||||
dateFormat = "dd/MM/yyyy",
|
||||
className,
|
||||
datePickerPopperClass,
|
||||
|
||||
name,
|
||||
control,
|
||||
required,
|
||||
...otherFieldProps
|
||||
}: DateFieldProps<TFieldValues, TFieldName>) => {
|
||||
const locale = useLocale();
|
||||
@@ -93,11 +86,7 @@ export const DateField = <
|
||||
// Called when the user types in the input
|
||||
if (e?.currentTarget && "value" in e.currentTarget) {
|
||||
const value = e.currentTarget.value;
|
||||
const date = parse(
|
||||
value as string,
|
||||
at("dateParseFormat"),
|
||||
new Date(),
|
||||
);
|
||||
const date = parse(value as string, at("dateParseFormat"), new Date());
|
||||
if (
|
||||
isValid(date) &&
|
||||
date.getFullYear() >= min &&
|
||||
@@ -124,9 +113,7 @@ export const DateField = <
|
||||
minDate={minDate}
|
||||
showFullMonthYearPicker
|
||||
maxDate={maxDate}
|
||||
renderCustomHeader={(props) => (
|
||||
<DatePickerCustomHeader {...props} />
|
||||
)}
|
||||
renderCustomHeader={(props) => <DatePickerCustomHeader {...props} />}
|
||||
customInput={
|
||||
<InputDatePicker
|
||||
mask={at("dateMask")}
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { ReactNode } from "react";
|
||||
|
||||
import { get } from "lodash";
|
||||
import {
|
||||
Control,
|
||||
FieldPath,
|
||||
FieldValues,
|
||||
useFormContext,
|
||||
} from "react-hook-form";
|
||||
import { Control, FieldPath, FieldValues, useFormContext } from "react-hook-form";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { Prettify } from "@/types";
|
||||
@@ -70,13 +65,7 @@ export const Field = <
|
||||
</Label>
|
||||
) : null}
|
||||
|
||||
<div
|
||||
className={twMerge(
|
||||
"flex w-full",
|
||||
label && "mt-2",
|
||||
childrenWrapperClassName,
|
||||
)}
|
||||
>
|
||||
<div className={twMerge("flex w-full", label && "mt-2", childrenWrapperClassName)}>
|
||||
{children}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
import React from "react";
|
||||
|
||||
import type { ReactNode } from 'react'
|
||||
import { Switch, SwitchProps } from "@headlessui/react";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export const InlineSwitch = (
|
||||
props: {
|
||||
label?: React.ReactNode;
|
||||
label?: ReactNode;
|
||||
tooltip?: string;
|
||||
tooltipId?: string;
|
||||
} & SwitchProps<"button">,
|
||||
) => {
|
||||
const {
|
||||
label,
|
||||
tooltip,
|
||||
tooltipId,
|
||||
disabled,
|
||||
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
import React from "react";
|
||||
|
||||
import { SwitchProps } from "@headlessui/react";
|
||||
import { Controller, FieldPath, FieldValues } from "react-hook-form";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { Field, GenericFieldProps } from "@/components/form/Field";
|
||||
|
||||
import { InlineSwitch } from "./InlineSwitch";
|
||||
|
||||
type InlineSwitchFieldProps<
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
> = GenericFieldProps<TFieldValues, TFieldName> &
|
||||
Omit<SwitchProps<"button">, "name">;
|
||||
> = GenericFieldProps<TFieldValues, TFieldName> & Omit<SwitchProps<"button">, "name">;
|
||||
|
||||
export const InlineSwitchField = <
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { ComponentProps, ReactNode } from 'react'
|
||||
import { VariantProps, cva } from "class-variance-authority";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
@@ -26,12 +27,12 @@ export const inputVariants = cva(
|
||||
},
|
||||
);
|
||||
|
||||
export type InputVariants = VariantProps<typeof inputVariants>;
|
||||
export type InputProps = Omit<React.ComponentProps<"input">, "size"> &
|
||||
type InputVariants = VariantProps<typeof inputVariants>;
|
||||
export type InputProps = Omit<ComponentProps<"input">, "size"> &
|
||||
Omit<InputVariants, "state"> & {
|
||||
hasError?: boolean;
|
||||
startIcon?: React.ReactNode;
|
||||
endIcon?: React.ReactNode;
|
||||
startIcon?: ReactNode;
|
||||
endIcon?: ReactNode;
|
||||
};
|
||||
|
||||
export const Input = ({
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
import type { LabelHTMLAttributes, ReactNode, DetailedHTMLProps } from "react";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { Prettify } from "@/types";
|
||||
|
||||
type LabelProps = Prettify<
|
||||
React.DetailedHTMLProps<
|
||||
React.LabelHTMLAttributes<HTMLLabelElement>,
|
||||
HTMLLabelElement
|
||||
> & {
|
||||
DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement> & {
|
||||
required?: boolean;
|
||||
className?: string;
|
||||
tooltip?: React.ReactNode;
|
||||
tooltip?: ReactNode;
|
||||
}
|
||||
>;
|
||||
|
||||
export const Label = ({
|
||||
required,
|
||||
className,
|
||||
children,
|
||||
tooltip,
|
||||
...labelProps
|
||||
}: LabelProps) => {
|
||||
export const Label = ({ required, className, children, ...labelProps }: LabelProps) => {
|
||||
return (
|
||||
<label
|
||||
{...labelProps}
|
||||
|
||||
@@ -1,23 +1,14 @@
|
||||
import React from "react";
|
||||
|
||||
import { RadioGroup } from "@headlessui/react";
|
||||
import { isNil } from "lodash";
|
||||
import { useTranslations } from "next-intl";
|
||||
import {
|
||||
Controller,
|
||||
FieldPath,
|
||||
FieldValues,
|
||||
useFormContext,
|
||||
} from "react-hook-form";
|
||||
import { Controller, FieldPath, FieldValues, useFormContext } from "react-hook-form";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { Prettify } from "@/types";
|
||||
|
||||
import { Field, GenericFieldProps } from "./Field";
|
||||
|
||||
export type BaseOption<T = string, D = unknown> = {
|
||||
type BaseOption<T = string, D = unknown> = {
|
||||
value: T;
|
||||
label: string | JSX.Element;
|
||||
label: string | React.JSX.Element;
|
||||
disabled?: boolean;
|
||||
data?: D;
|
||||
};
|
||||
@@ -51,16 +42,13 @@ export const RadioGroupField = <
|
||||
|
||||
options,
|
||||
}: RadioGroupFieldProps<TFieldValues, TFieldName, T, D>) => {
|
||||
const t = useTranslations("App");
|
||||
const form = useFormContext<TFieldValues>();
|
||||
|
||||
const {
|
||||
// oxlint-disable-next-line no-unused-vars
|
||||
formState: { errors },
|
||||
} = form;
|
||||
|
||||
const valueToOption = (value: T): BaseOption<T, D> =>
|
||||
options.find((o) => o.value === value) ?? { value, label: "" };
|
||||
|
||||
return (
|
||||
<Field
|
||||
{...{
|
||||
@@ -78,8 +66,6 @@ export const RadioGroupField = <
|
||||
name={name}
|
||||
control={control}
|
||||
render={({ field: { onChange, value } }) => {
|
||||
const optionValue = isNil(value) ? null : valueToOption(value);
|
||||
|
||||
return (
|
||||
<RadioGroup
|
||||
value={value}
|
||||
|
||||
@@ -8,17 +8,13 @@ import { Prettify } from "@/types";
|
||||
|
||||
export type BaseOption<T = string, D = unknown> = {
|
||||
value: T;
|
||||
label: string | JSX.Element;
|
||||
label: string | React.JSX.Element;
|
||||
disabled?: boolean;
|
||||
data?: D;
|
||||
};
|
||||
|
||||
export const createSelectClassNamesFn =
|
||||
<Option, IsMulti extends boolean = false>({
|
||||
size,
|
||||
}: {
|
||||
size?: "small" | "medium";
|
||||
}) =>
|
||||
<Option, IsMulti extends boolean = false>({ size }: { size?: "small" | "medium" }) =>
|
||||
(
|
||||
hasError: boolean,
|
||||
separators: boolean,
|
||||
@@ -26,8 +22,7 @@ export const createSelectClassNamesFn =
|
||||
container: () => "w-full",
|
||||
valueContainer: () => "text-gray-900 dark:text-white",
|
||||
indicatorsContainer: () => "flex items-center self-stretch shrink-0",
|
||||
clearIndicator: () =>
|
||||
"flex items-center pr-2 text-gray-900 dark:text-white",
|
||||
clearIndicator: () => "flex items-center pr-2 text-gray-900 dark:text-white",
|
||||
dropdownIndicator: () =>
|
||||
"pointer-events-none flex items-center pr-2 text-gray-900 dark:text-white",
|
||||
indicatorSeparator: () => "w-px text-gray-900 dark:text-white",
|
||||
@@ -45,8 +40,7 @@ export const createSelectClassNamesFn =
|
||||
multiValue: () => "bg-fieldGray border rounded-lg flex space-x-1 pl-1 m-1",
|
||||
multiValueLabel: () => "",
|
||||
multiValueRemove: () => "items-center px-1 hover:text-primary",
|
||||
placeholder: () =>
|
||||
"block truncate pr-2 placeholder-gray dark:placeholder-gray-400",
|
||||
placeholder: () => "block truncate pr-2 placeholder-gray dark:placeholder-gray-400",
|
||||
menu: () =>
|
||||
twMerge(
|
||||
"!z-30 mt-2 rounded-lg border border-gray-200 bg-white p-1",
|
||||
@@ -65,33 +59,18 @@ export const createSelectClassNamesFn =
|
||||
"text-textGray p-2 bg-gray-50 border border-dashed border-gray-200 rounded-sm",
|
||||
});
|
||||
|
||||
export type SelectProps<
|
||||
IsMulti extends boolean = false,
|
||||
T = string,
|
||||
D = unknown,
|
||||
> = Prettify<
|
||||
export type SelectProps<IsMulti extends boolean = false, T = string, D = unknown> = Prettify<
|
||||
Omit<Props<BaseOption<T, D>, IsMulti>, "classNames"> & {
|
||||
required?: boolean;
|
||||
separators?: boolean;
|
||||
hasError?: boolean;
|
||||
size?: "small" | "medium";
|
||||
classNameOverrides?: ClassNamesConfig<
|
||||
BaseOption<T, D>,
|
||||
IsMulti,
|
||||
GroupBase<BaseOption<T, D>>
|
||||
>;
|
||||
classNameOverrides?: ClassNamesConfig<BaseOption<T, D>, IsMulti, GroupBase<BaseOption<T, D>>>;
|
||||
}
|
||||
>;
|
||||
|
||||
export const Select = <
|
||||
IsMulti extends boolean = false,
|
||||
T = string,
|
||||
D = unknown,
|
||||
>({
|
||||
className,
|
||||
required,
|
||||
export const Select = <IsMulti extends boolean = false, T = string, D = unknown>({
|
||||
size,
|
||||
|
||||
placeholder,
|
||||
separators,
|
||||
hasError,
|
||||
@@ -121,7 +100,7 @@ export const Select = <
|
||||
}}
|
||||
classNames={{
|
||||
...classNames(hasError ?? false, separators ?? false),
|
||||
...(classNameOverrides ?? {}),
|
||||
...classNameOverrides,
|
||||
}}
|
||||
{...selectProps}
|
||||
/>
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
import React from "react";
|
||||
|
||||
import { flatMap, get, isArray, isNil, isObject } from "lodash";
|
||||
import { useTranslations } from "next-intl";
|
||||
import {
|
||||
Controller,
|
||||
FieldPath,
|
||||
FieldValues,
|
||||
useFormContext,
|
||||
} from "react-hook-form";
|
||||
import { Controller, FieldPath, FieldValues, useFormContext } from "react-hook-form";
|
||||
import { GroupBase, OnChangeValue } from "react-select";
|
||||
|
||||
import { BaseOption, Select, SelectProps } from "@/components/form/Select";
|
||||
@@ -23,10 +15,7 @@ export type SelectFieldProps<
|
||||
D = unknown,
|
||||
> = Prettify<
|
||||
GenericFieldProps<TFieldValues, TFieldName> &
|
||||
Omit<
|
||||
SelectProps<IsMulti, T, D>,
|
||||
"onChange" | "value" | "classNames" | "name"
|
||||
> & {
|
||||
Omit<SelectProps<IsMulti, T, D>, "onChange" | "value" | "classNames" | "name"> & {
|
||||
required?: boolean;
|
||||
separators?: boolean;
|
||||
}
|
||||
@@ -47,13 +36,9 @@ export const SelectField = <
|
||||
label,
|
||||
hideErrorMessage,
|
||||
required,
|
||||
|
||||
placeholder,
|
||||
separators,
|
||||
options,
|
||||
...selectProps
|
||||
}: SelectFieldProps<TFieldValues, TFieldName, IsMulti, T, D>) => {
|
||||
const t = useTranslations("App");
|
||||
const form = useFormContext<TFieldValues>();
|
||||
|
||||
const {
|
||||
@@ -64,8 +49,7 @@ export const SelectField = <
|
||||
|
||||
const isGroup = (
|
||||
option: BaseOption<T, D> | GroupBase<BaseOption<T, D>>,
|
||||
): option is GroupBase<BaseOption<T, D>> =>
|
||||
isObject(option) && "options" in option;
|
||||
): option is GroupBase<BaseOption<T, D>> => isObject(option) && "options" in option;
|
||||
|
||||
const flattenedOptions = flatMap(options, (option) => {
|
||||
return isGroup(option) ? option.options : option;
|
||||
@@ -91,9 +75,7 @@ export const SelectField = <
|
||||
name={name}
|
||||
control={control}
|
||||
render={({ field: { onChange, value } }) => {
|
||||
const onSelectChange = (
|
||||
newValue: OnChangeValue<BaseOption<T, D>, IsMulti>,
|
||||
) => {
|
||||
const onSelectChange = (newValue: OnChangeValue<BaseOption<T, D>, IsMulti>) => {
|
||||
if (isNil(newValue)) onChange(null);
|
||||
else if (isArray(newValue)) {
|
||||
onChange(newValue.map((option) => option.value));
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import React from "react";
|
||||
|
||||
import { Switch, SwitchProps } from "@headlessui/react";
|
||||
import {
|
||||
Controller,
|
||||
FieldPath,
|
||||
FieldValues,
|
||||
useFormContext,
|
||||
} from "react-hook-form";
|
||||
import { Controller, FieldPath, FieldValues } from "react-hook-form";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { Prettify } from "@/types";
|
||||
@@ -16,10 +11,7 @@ import { Field, GenericFieldProps } from "./Field";
|
||||
type SwitchFieldProps<
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
> = Prettify<
|
||||
GenericFieldProps<TFieldValues, TFieldName> &
|
||||
Omit<SwitchProps<"button">, "name">
|
||||
>;
|
||||
> = Prettify<GenericFieldProps<TFieldValues, TFieldName> & Omit<SwitchProps<"button">, "name">>;
|
||||
|
||||
export const SwitchField = <
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
@@ -27,21 +19,7 @@ export const SwitchField = <
|
||||
>(
|
||||
props: SwitchFieldProps<TFieldValues, TFieldName>,
|
||||
) => {
|
||||
const {
|
||||
name,
|
||||
control,
|
||||
label,
|
||||
disabled,
|
||||
className,
|
||||
labelClassName,
|
||||
|
||||
childrenWrapperClassName,
|
||||
hideErrorMessage,
|
||||
|
||||
...rest
|
||||
} = props;
|
||||
const form = useFormContext<TFieldValues>();
|
||||
|
||||
const { name, control, label, disabled, className, labelClassName, ...rest } = props;
|
||||
return (
|
||||
<Field
|
||||
{...{
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import React from "react";
|
||||
import type { HTMLProps, ReactNode } from "react";
|
||||
|
||||
import { get } from "lodash";
|
||||
import {
|
||||
Controller,
|
||||
FieldPath,
|
||||
FieldValues,
|
||||
useFormContext,
|
||||
} from "react-hook-form";
|
||||
import { Controller, FieldPath, FieldValues, useFormContext } from "react-hook-form";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { Prettify } from "@/types";
|
||||
@@ -19,9 +14,9 @@ type TextAreaFieldProps<
|
||||
TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
> = Prettify<
|
||||
GenericFieldProps<TFieldValues, TFieldName> &
|
||||
Omit<React.HTMLProps<HTMLTextAreaElement>, "ref" | "name"> & {
|
||||
Omit<HTMLProps<HTMLTextAreaElement>, "ref" | "name"> & {
|
||||
handleChanged?: (props: { name: string }) => void;
|
||||
startIcon?: React.ReactNode;
|
||||
startIcon?: ReactNode;
|
||||
required?: boolean;
|
||||
}
|
||||
>;
|
||||
@@ -40,11 +35,7 @@ export const TextAreaField = <
|
||||
labelClassName,
|
||||
childrenWrapperClassName,
|
||||
hideErrorMessage = false,
|
||||
|
||||
startIcon,
|
||||
handleChanged,
|
||||
required,
|
||||
|
||||
disabled,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import React from "react";
|
||||
|
||||
import { get } from "lodash";
|
||||
import {
|
||||
Controller,
|
||||
FieldPath,
|
||||
FieldValues,
|
||||
useFormContext,
|
||||
} from "react-hook-form";
|
||||
import { Controller, FieldPath, FieldValues, useFormContext } from "react-hook-form";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { Prettify } from "@/types";
|
||||
@@ -57,11 +52,7 @@ export const TextField = <
|
||||
const hasError = !!get(errors, name)?.message;
|
||||
|
||||
const input = (value: string | number) => {
|
||||
return typeof value === "number"
|
||||
? isNaN(value)
|
||||
? ""
|
||||
: value.toString()
|
||||
: (value ?? "");
|
||||
return typeof value === "number" ? (isNaN(value) ? "" : value.toString()) : (value ?? "");
|
||||
};
|
||||
|
||||
const output =
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import { on } from "events";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { FieldPath, FieldValues } from "react-hook-form";
|
||||
import { FaExternalLinkAlt } from "react-icons/fa";
|
||||
|
||||
import { TimeControlColours } from "@/constants";
|
||||
import { getTournamentDetails } from "@/server/getTournamentDetails";
|
||||
import {
|
||||
SearchedTournament,
|
||||
searchTournaments,
|
||||
} from "@/server/searchTournaments";
|
||||
import { SearchedTournament, searchTournaments } from "@/server/searchTournaments";
|
||||
|
||||
import { AsyncSelectField, AsyncSelectFieldProps } from "./AsyncSelectField";
|
||||
|
||||
@@ -18,13 +14,7 @@ type TournamentSelectFieldProps<
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
> = Omit<
|
||||
AsyncSelectFieldProps<
|
||||
TFieldValues,
|
||||
TFieldName,
|
||||
false,
|
||||
string,
|
||||
SearchedTournament
|
||||
>,
|
||||
AsyncSelectFieldProps<TFieldValues, TFieldName, false, string, SearchedTournament>,
|
||||
"loadOptions" | "loadOption" | "separators"
|
||||
>;
|
||||
|
||||
@@ -36,8 +26,7 @@ export const TournamentSelectField = <
|
||||
...rest
|
||||
}: TournamentSelectFieldProps<TFieldValues, TFieldName>) => {
|
||||
const at = useTranslations("App");
|
||||
const [selectedTournament, setSelectedTournament] =
|
||||
useState<SearchedTournament | null>(null);
|
||||
const [selectedTournament, setSelectedTournament] = useState<SearchedTournament | null>(null);
|
||||
|
||||
const loadOption = async (ffeId: string) => {
|
||||
const result = await getTournamentDetails({ ffeId });
|
||||
@@ -91,7 +80,7 @@ export const TournamentSelectField = <
|
||||
background: `${TimeControlColours[option.data!.timeControl]}`,
|
||||
}}
|
||||
>
|
||||
{at("timeControlEnum", { tc: option.data?.timeControl })}
|
||||
{at("timeControlEnum", { tc: option.data!.timeControl })}
|
||||
</div>
|
||||
<div className="text-xs">{option.data?.date}</div>
|
||||
</div>
|
||||
|
||||
@@ -18,9 +18,9 @@ export type ZoneEditorProps = {
|
||||
onChange: (geoJson: FeatureCollection) => void;
|
||||
};
|
||||
|
||||
export const ZoneEditor = ({ value, onChange }: ZoneEditorProps) => {
|
||||
const ZoneEditor = ({ value, onChange }: ZoneEditorProps) => {
|
||||
const initialFeatures = React.useRef(value?.features);
|
||||
const featureGroup = React.useRef<L.FeatureGroup>();
|
||||
const featureGroup = React.useRef<L.FeatureGroup | null>(null);
|
||||
|
||||
const setFeatureCollectionRef = (element: L.FeatureGroup) => {
|
||||
featureGroup.current = element;
|
||||
@@ -52,11 +52,7 @@ export const ZoneEditor = ({ value, onChange }: ZoneEditorProps) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<MapContainer
|
||||
center={center}
|
||||
zoom={5}
|
||||
style={{ height: "600px", flexGrow: 1 }}
|
||||
>
|
||||
<MapContainer center={center} zoom={5} style={{ height: "600px", flexGrow: 1 }}>
|
||||
<MapEvents
|
||||
bounds={
|
||||
(initialFeatures.current ?? []).length > 0
|
||||
|
||||
@@ -20,8 +20,7 @@ type ZoneEditorFieldProps<
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
> = Prettify<
|
||||
GenericFieldProps<TFieldValues, TFieldName> &
|
||||
Omit<ZoneEditorProps, "value" | "onChange">
|
||||
GenericFieldProps<TFieldValues, TFieldName> & Omit<ZoneEditorProps, "value" | "onChange">
|
||||
>;
|
||||
|
||||
export const ZoneEditorField = <
|
||||
|
||||
Reference in New Issue
Block a user