mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-11-18 07:22:06 +00:00
auto apply oxfmt rules
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -75,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,
|
||||
(v) => valueOptions.current.find((o) => o.value === value) === undefined,
|
||||
);
|
||||
|
||||
if (unFetchedValues.length > 0) {
|
||||
@@ -95,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
|
||||
@@ -119,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;
|
||||
|
||||
@@ -5,12 +5,7 @@ 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";
|
||||
@@ -93,11 +88,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 +115,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>
|
||||
|
||||
|
||||
@@ -11,8 +11,7 @@ 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,
|
||||
|
||||
@@ -3,23 +3,14 @@ import { twMerge } from "tailwind-merge";
|
||||
import { Prettify } from "@/types";
|
||||
|
||||
type LabelProps = Prettify<
|
||||
React.DetailedHTMLProps<
|
||||
React.LabelHTMLAttributes<HTMLLabelElement>,
|
||||
HTMLLabelElement
|
||||
> & {
|
||||
React.DetailedHTMLProps<React.LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement> & {
|
||||
required?: boolean;
|
||||
className?: string;
|
||||
tooltip?: React.ReactNode;
|
||||
}
|
||||
>;
|
||||
|
||||
export const Label = ({
|
||||
required,
|
||||
className,
|
||||
children,
|
||||
tooltip,
|
||||
...labelProps
|
||||
}: LabelProps) => {
|
||||
export const Label = ({ required, className, children, tooltip, ...labelProps }: LabelProps) => {
|
||||
return (
|
||||
<label
|
||||
{...labelProps}
|
||||
|
||||
@@ -3,12 +3,7 @@ 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";
|
||||
|
||||
@@ -14,11 +14,7 @@ export type BaseOption<T = string, D = unknown> = {
|
||||
};
|
||||
|
||||
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,29 +59,17 @@ 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,
|
||||
>({
|
||||
export const Select = <IsMulti extends boolean = false, T = string, D = unknown>({
|
||||
size,
|
||||
placeholder,
|
||||
separators,
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import { flatMap, get, isArray, isNil, isObject } from "lodash";
|
||||
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";
|
||||
@@ -20,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;
|
||||
}
|
||||
@@ -57,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;
|
||||
@@ -84,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,11 +1,7 @@
|
||||
import React from "react";
|
||||
|
||||
import { Switch, SwitchProps } from "@headlessui/react";
|
||||
import {
|
||||
Controller,
|
||||
FieldPath,
|
||||
FieldValues,
|
||||
} from "react-hook-form";
|
||||
import { Controller, FieldPath, FieldValues } from "react-hook-form";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { Prettify } from "@/types";
|
||||
@@ -15,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,
|
||||
@@ -26,16 +19,8 @@ export const SwitchField = <
|
||||
>(
|
||||
props: SwitchFieldProps<TFieldValues, TFieldName>,
|
||||
) => {
|
||||
const {
|
||||
name,
|
||||
control,
|
||||
label,
|
||||
disabled,
|
||||
className,
|
||||
labelClassName,
|
||||
...rest
|
||||
} = props;
|
||||
return (
|
||||
const { name, control, label, disabled, className, labelClassName, ...rest } = props;
|
||||
return (
|
||||
<Field
|
||||
{...{
|
||||
name,
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import type {HTMLProps, ReactNode} 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";
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -6,10 +6,7 @@ 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";
|
||||
|
||||
@@ -17,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"
|
||||
>;
|
||||
|
||||
@@ -35,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 });
|
||||
|
||||
@@ -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