mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26:57 +00:00
Fix Select types
This commit is contained in:
@@ -1,7 +1,13 @@
|
|||||||
|
import gd from "date-fns/locale/gd";
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { IoAdd } from "react-icons/io5";
|
import { IoAdd } from "react-icons/io5";
|
||||||
import { GroupBase, OptionsOrGroups, SingleValue } from "react-select";
|
import {
|
||||||
|
GroupBase,
|
||||||
|
OnChangeValue,
|
||||||
|
OptionsOrGroups,
|
||||||
|
SingleValue,
|
||||||
|
} from "react-select";
|
||||||
|
|
||||||
import { regionFilterAtom } from "@/atoms";
|
import { regionFilterAtom } from "@/atoms";
|
||||||
import { BaseOption, Select, SelectProps } from "@/components/form/Select";
|
import { BaseOption, Select, SelectProps } from "@/components/form/Select";
|
||||||
@@ -9,7 +15,10 @@ import { useZones } from "@/hooks/useZones";
|
|||||||
import { Zone } from "@/server/myZones";
|
import { Zone } from "@/server/myZones";
|
||||||
import { useRouter } from "@/utils/navigation";
|
import { useRouter } from "@/utils/navigation";
|
||||||
|
|
||||||
type RegionSelectProps = Omit<SelectProps, "options" | "value" | "onChange"> & {
|
type RegionSelectProps = Omit<
|
||||||
|
SelectProps<false, string, Zone | null>,
|
||||||
|
"options" | "value" | "onChange"
|
||||||
|
> & {
|
||||||
syncTitle: string;
|
syncTitle: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -55,7 +64,9 @@ export const RegionSelect = ({
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const onChange = (option: SingleValue<RegionOption>) => {
|
const onChange = (
|
||||||
|
option: OnChangeValue<BaseOption<string, Zone | null>, false>,
|
||||||
|
) => {
|
||||||
if (!option) return;
|
if (!option) return;
|
||||||
if (option.value === "create") {
|
if (option.value === "create") {
|
||||||
router.push("/zones/create");
|
router.push("/zones/create");
|
||||||
@@ -99,9 +110,10 @@ export const RegionSelect = ({
|
|||||||
? o.value === regionFilter
|
? o.value === regionFilter
|
||||||
: o.value === regionFilter.id,
|
: o.value === regionFilter.id,
|
||||||
)}
|
)}
|
||||||
formatGroupLabel={(g) => formatGroupLabel(g as GroupedOption)}
|
isMulti={false}
|
||||||
formatOptionLabel={(o) => formatOptionLabel(o as RegionOption)}
|
formatGroupLabel={formatGroupLabel}
|
||||||
onChange={(v) => onChange(v as SingleValue<RegionOption>)}
|
formatOptionLabel={formatOptionLabel}
|
||||||
|
onChange={onChange}
|
||||||
{...selectProps}
|
{...selectProps}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ import AsyncSelect from "react-select/async";
|
|||||||
import { Prettify } from "@/types";
|
import { Prettify } from "@/types";
|
||||||
|
|
||||||
import { Field, GenericFieldProps } from "./Field";
|
import { Field, GenericFieldProps } from "./Field";
|
||||||
import { classNames } from "./Select";
|
import { BaseOption, classNames } from "./Select";
|
||||||
import { BaseOption } from "./SelectField";
|
|
||||||
|
|
||||||
export type AsyncSelectFieldProps<
|
export type AsyncSelectFieldProps<
|
||||||
TFieldValues extends FieldValues = FieldValues,
|
TFieldValues extends FieldValues = FieldValues,
|
||||||
|
|||||||
@@ -62,10 +62,7 @@ export type SelectProps<
|
|||||||
T = string,
|
T = string,
|
||||||
D = unknown,
|
D = unknown,
|
||||||
> = Prettify<
|
> = Prettify<
|
||||||
Omit<
|
Omit<Props<BaseOption<T, D>, IsMulti>, "classNames"> & {
|
||||||
Props<BaseOption<T, D>, IsMulti, GroupBase<BaseOption<T, D>>>,
|
|
||||||
"classNames"
|
|
||||||
> & {
|
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
separators?: boolean;
|
separators?: boolean;
|
||||||
hasError?: boolean;
|
hasError?: boolean;
|
||||||
|
|||||||
@@ -10,18 +10,11 @@ import {
|
|||||||
} from "react-hook-form";
|
} from "react-hook-form";
|
||||||
import { GroupBase, OnChangeValue } from "react-select";
|
import { GroupBase, OnChangeValue } from "react-select";
|
||||||
|
|
||||||
import { Select, SelectProps } from "@/components/form/Select";
|
import { BaseOption, Select, SelectProps } from "@/components/form/Select";
|
||||||
import { Prettify } from "@/types";
|
import { Prettify } from "@/types";
|
||||||
|
|
||||||
import { Field, GenericFieldProps } from "./Field";
|
import { Field, GenericFieldProps } from "./Field";
|
||||||
|
|
||||||
export type BaseOption<T = string, D = unknown> = {
|
|
||||||
value: T;
|
|
||||||
label: string | JSX.Element;
|
|
||||||
disabled?: boolean;
|
|
||||||
data?: D;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type SelectFieldProps<
|
export type SelectFieldProps<
|
||||||
TFieldValues extends FieldValues = FieldValues,
|
TFieldValues extends FieldValues = FieldValues,
|
||||||
TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||||
|
|||||||
Reference in New Issue
Block a user