mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-07 01:54:16 +01:00
(quality) add typing for status filter and settings
This commit is contained in:
parent
0d508839e5
commit
4800d4aee1
@ -1,6 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { FieldValues } from 'react-hook-form/dist/types/fields';
|
|
||||||
import { Control, FormState, UseFormRegister, UseFormGetValues } from 'react-hook-form';
|
import { Control, FormState, UseFormRegister, UseFormGetValues } from 'react-hook-form';
|
||||||
import { FormSwitch } from '../form/form-switch';
|
import { FormSwitch } from '../form/form-switch';
|
||||||
import { FormRichText } from '../form/form-rich-text';
|
import { FormRichText } from '../form/form-rich-text';
|
||||||
@ -14,7 +13,7 @@ interface EditorialBlockFormProps {
|
|||||||
formState: FormState<Record<SettingName, SettingValue>>,
|
formState: FormState<Record<SettingName, SettingValue>>,
|
||||||
info?: string
|
info?: string
|
||||||
keys: Record<EditorialKeys, SettingName>,
|
keys: Record<EditorialKeys, SettingName>,
|
||||||
getValues?: UseFormGetValues<FieldValues>,
|
getValues?: UseFormGetValues<Record<SettingName, SettingValue>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// regular expression to validate the input fields
|
// regular expression to validate the input fields
|
||||||
@ -23,7 +22,7 @@ const urlRegex = /^(https?:\/\/)([^.]+)\.(.{2,30})(\/.*)*\/?$/;
|
|||||||
/**
|
/**
|
||||||
* Allows to create a formatted text and optional cta button in a form block, to be included in a resource form managed by react-hook-form.
|
* Allows to create a formatted text and optional cta button in a form block, to be included in a resource form managed by react-hook-form.
|
||||||
*/
|
*/
|
||||||
export const EditorialBlockForm = <TFieldValues extends FieldValues>({ register, control, formState, info, keys, getValues }: EditorialBlockFormProps<TFieldValues>) => {
|
export const EditorialBlockForm: React.FC<EditorialBlockFormProps> = ({ register, control, formState, info, keys, getValues }) => {
|
||||||
const { t } = useTranslation('admin');
|
const { t } = useTranslation('admin');
|
||||||
|
|
||||||
const [isActiveTextBlock, setIsActiveTextBlock] = useState<boolean>(false);
|
const [isActiveTextBlock, setIsActiveTextBlock] = useState<boolean>(false);
|
||||||
|
@ -3,7 +3,7 @@ import * as React from 'react';
|
|||||||
import { FieldPathValue, UseFormGetValues } from 'react-hook-form';
|
import { FieldPathValue, UseFormGetValues } from 'react-hook-form';
|
||||||
import { debounce as _debounce } from 'lodash';
|
import { debounce as _debounce } from 'lodash';
|
||||||
import { FieldValues } from 'react-hook-form/dist/types/fields';
|
import { FieldValues } from 'react-hook-form/dist/types/fields';
|
||||||
import { FieldPath } from 'react-hook-form/dist/types/path';
|
import { Path, FieldPath } from 'react-hook-form/dist/types/path';
|
||||||
import { FormComponent } from '../../models/form-component';
|
import { FormComponent } from '../../models/form-component';
|
||||||
import { AbstractFormItem, AbstractFormItemProps } from './abstract-form-item';
|
import { AbstractFormItem, AbstractFormItemProps } from './abstract-form-item';
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ type FormInputProps<TFieldValues, TInputType> = FormComponent<TFieldValues> & Ab
|
|||||||
nullable?: boolean,
|
nullable?: boolean,
|
||||||
ariaLabel?: string,
|
ariaLabel?: string,
|
||||||
maxLength?: number,
|
maxLength?: number,
|
||||||
getValues?: UseFormGetValues<FieldValues>
|
getValues?: UseFormGetValues<TFieldValues>
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +73,7 @@ export const FormInput = <TFieldValues extends FieldValues, TInputType>({ id, re
|
|||||||
// If maxLength and getValues is provided, uses input ref to initiate the countdown of characters
|
// If maxLength and getValues is provided, uses input ref to initiate the countdown of characters
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (getValues && maxLength) {
|
if (getValues && maxLength) {
|
||||||
setCharacterCount(getValues(id).length);
|
setCharacterCount(getValues(id as Path<TFieldValues>).length);
|
||||||
}
|
}
|
||||||
}, [maxLength, getValues]);
|
}, [maxLength, getValues]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user