mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-12 01:57:36 +03:00
fix types
This commit is contained in:
parent
3052d1968f
commit
229ce5b0f0
@ -1,4 +1,4 @@
|
|||||||
import { Control } from "react-hook-form";
|
import { Control, FieldValues, Path, PathValue } from "react-hook-form";
|
||||||
import {
|
import {
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
@ -13,11 +13,11 @@ import { useFormContext } from "react-hook-form";
|
|||||||
import { generateFixedHash, isValidId } from "@/utils/stringUtil";
|
import { generateFixedHash, isValidId } from "@/utils/stringUtil";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
type NameAndIdFieldsProps = {
|
type NameAndIdFieldsProps<T extends FieldValues = FieldValues> = {
|
||||||
control: Control<any>;
|
control: Control<T>;
|
||||||
type?: string;
|
type?: string;
|
||||||
nameField: string;
|
nameField: Path<T>;
|
||||||
idField: string;
|
idField: Path<T>;
|
||||||
nameLabel: string;
|
nameLabel: string;
|
||||||
nameDescription?: string;
|
nameDescription?: string;
|
||||||
idLabel?: string;
|
idLabel?: string;
|
||||||
@ -27,7 +27,7 @@ type NameAndIdFieldsProps = {
|
|||||||
placeholderId?: string;
|
placeholderId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function NameAndIdFields({
|
export default function NameAndIdFields<T extends FieldValues = FieldValues>({
|
||||||
control,
|
control,
|
||||||
type,
|
type,
|
||||||
nameField,
|
nameField,
|
||||||
@ -39,9 +39,9 @@ export default function NameAndIdFields({
|
|||||||
processId,
|
processId,
|
||||||
placeholderName,
|
placeholderName,
|
||||||
placeholderId,
|
placeholderId,
|
||||||
}: NameAndIdFieldsProps) {
|
}: NameAndIdFieldsProps<T>) {
|
||||||
const { t } = useTranslation(["common"]);
|
const { t } = useTranslation(["common"]);
|
||||||
const { watch, setValue, trigger } = useFormContext();
|
const { watch, setValue, trigger } = useFormContext<T>();
|
||||||
const [isIdVisible, setIsIdVisible] = useState(false);
|
const [isIdVisible, setIsIdVisible] = useState(false);
|
||||||
|
|
||||||
const defaultProcessId = (name: string) => {
|
const defaultProcessId = (name: string) => {
|
||||||
@ -59,7 +59,7 @@ export default function NameAndIdFields({
|
|||||||
const subscription = watch((value, { name }) => {
|
const subscription = watch((value, { name }) => {
|
||||||
if (name === nameField) {
|
if (name === nameField) {
|
||||||
const processedId = effectiveProcessId(value[nameField] || "");
|
const processedId = effectiveProcessId(value[nameField] || "");
|
||||||
setValue(idField, processedId);
|
setValue(idField, processedId as PathValue<T, Path<T>>);
|
||||||
trigger(idField);
|
trigger(idField);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user