diff --git a/src/components/form/autocomplete/form-autocomplete.tsx b/src/components/form/autocomplete/form-autocomplete.tsx index e82393af..4b76435b 100644 --- a/src/components/form/autocomplete/form-autocomplete.tsx +++ b/src/components/form/autocomplete/form-autocomplete.tsx @@ -1,6 +1,6 @@ "use client"; -import { ForwardedRef, forwardRef } from "react"; +import { Ref } from "react"; import { Controller, ControllerProps, @@ -26,19 +26,19 @@ export type AutocompleteInputProps = { getOptionLabel: (option: T) => string; }; -function AutocompleteInputRaw( +function AutocompleteInput( props: AutocompleteInputProps & { name: string; value: T | undefined | null; onChange: (value: T) => void; onBlur: () => void; - }, - ref?: ForwardedRef + ref?: Ref; + } ) { return ( ( ); } -const AutocompleteInput = forwardRef(AutocompleteInputRaw) as never as ( - props: AutocompleteInputProps & { - name: string; - value: T | undefined | null; - onChange: (value: T) => void; - onBlur: () => void; - } & { ref?: ForwardedRef } -) => ReturnType; - function FormAutocompleteInput< TFieldValues extends FieldValues = FieldValues, T = unknown, diff --git a/src/components/form/checkbox-boolean/form-checkbox-boolean.tsx b/src/components/form/checkbox-boolean/form-checkbox-boolean.tsx index 2d11efdb..5faa2b65 100644 --- a/src/components/form/checkbox-boolean/form-checkbox-boolean.tsx +++ b/src/components/form/checkbox-boolean/form-checkbox-boolean.tsx @@ -1,6 +1,6 @@ "use client"; -import { ChangeEvent, ForwardedRef, forwardRef } from "react"; +import { ChangeEvent, Ref } from "react"; import { Controller, ControllerProps, @@ -23,14 +23,14 @@ export type CheckboxBooleanInputProps = { testId?: string; }; -function CheckboxBooleanInputRaw( +function CheckboxBooleanInput( props: CheckboxBooleanInputProps & { name: string; value: boolean | null; onChange: (value: boolean) => void; onBlur: () => void; - }, - ref?: ForwardedRef + ref?: Ref; + } ) { const value = props.value ?? false; const onChange = ( @@ -46,7 +46,7 @@ function CheckboxBooleanInputRaw( variant="standard" error={!!props.error} > - + void; - onBlur: () => void; - } & { ref?: ForwardedRef } -) => ReturnType; - function FormCheckboxBooleanInput< TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath, diff --git a/src/components/form/checkbox/form-checkbox.tsx b/src/components/form/checkbox/form-checkbox.tsx index c12e5f3e..12fcc2c5 100644 --- a/src/components/form/checkbox/form-checkbox.tsx +++ b/src/components/form/checkbox/form-checkbox.tsx @@ -1,6 +1,6 @@ "use client"; -import { ForwardedRef, forwardRef } from "react"; +import { Ref } from "react"; import { Controller, ControllerProps, @@ -28,14 +28,14 @@ export type CheckboxInputProps = { renderOption: (option: T) => React.ReactNode; }; -function CheckboxInputRaw( +function CheckboxInput( props: CheckboxInputProps & { name: string; value: T[] | undefined | null; onChange: (value: T[]) => void; onBlur: () => void; - }, - ref?: ForwardedRef + ref?: Ref; + } ) { const value = props.value ?? []; const onChange = (checkboxValue: T) => () => { @@ -61,7 +61,7 @@ function CheckboxInputRaw( {props.label} - + {props.options.map((option) => ( ( ); } -const CheckboxInput = forwardRef(CheckboxInputRaw) as never as ( - props: CheckboxInputProps & { - name: string; - value: T[] | undefined | null; - onChange: (value: T[]) => void; - onBlur: () => void; - } & { ref?: ForwardedRef } -) => ReturnType; - function FormCheckboxInput< TFieldValues extends FieldValues = FieldValues, T = unknown, diff --git a/src/components/form/date-pickers/date-picker.tsx b/src/components/form/date-pickers/date-picker.tsx index 32f8d20a..07049b7e 100644 --- a/src/components/form/date-pickers/date-picker.tsx +++ b/src/components/form/date-pickers/date-picker.tsx @@ -10,7 +10,7 @@ import { FieldPath, FieldValues, } from "react-hook-form"; -import { ForwardedRef, forwardRef } from "react"; +import { Ref } from "react"; import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFns"; import useLanguage from "@/services/i18n/use-language"; import { getValueByKey } from "@/components/form/date-pickers/helper"; @@ -29,23 +29,15 @@ type DatePickerFieldProps = { error?: string; defaultValue?: ValueDateType; }; -const DatePickerInput = forwardRef(DatePickerInputRaw) as never as ( - props: DatePickerFieldProps & { - name: string; - value: ValueDateType; - onChange: (value: ValueDateType) => void; - onBlur: () => void; - } & { ref?: ForwardedRef } -) => ReturnType; -function DatePickerInputRaw( +function DatePickerInput( props: DatePickerFieldProps & { name: string; value: ValueDateType; onChange: (value: ValueDateType) => void; onBlur: () => void; - }, - ref?: ForwardedRef + ref?: Ref; + } ) { const language = useLanguage(); @@ -55,7 +47,7 @@ function DatePickerInputRaw( adapterLocale={getValueByKey(language)} > ); } + function FormDatePickerInput< TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath, diff --git a/src/components/form/date-pickers/date-time-picker.tsx b/src/components/form/date-pickers/date-time-picker.tsx index 7429a3af..1b7c0caf 100644 --- a/src/components/form/date-pickers/date-time-picker.tsx +++ b/src/components/form/date-pickers/date-time-picker.tsx @@ -10,7 +10,7 @@ import { FieldPath, FieldValues, } from "react-hook-form"; -import { ForwardedRef, forwardRef } from "react"; +import { Ref } from "react"; import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFns"; import useLanguage from "@/services/i18n/use-language"; import { getValueByKey } from "@/components/form/date-pickers/helper"; @@ -29,23 +29,15 @@ type DateTimePickerFieldProps = { error?: string; defaultValue?: ValueDateType; }; -const DateTimePickerInput = forwardRef(DateTimePickerInputRaw) as never as ( - props: DateTimePickerFieldProps & { - name: string; - value: ValueDateType; - onChange: (value: ValueDateType) => void; - onBlur: () => void; - } & { ref?: ForwardedRef } -) => ReturnType; -function DateTimePickerInputRaw( +function DateTimePickerInput( props: DateTimePickerFieldProps & { name: string; value: ValueDateType; onChange: (value: ValueDateType) => void; onBlur: () => void; - }, - ref?: ForwardedRef + ref?: Ref; + } ) { const language = useLanguage(); @@ -55,7 +47,7 @@ function DateTimePickerInputRaw( adapterLocale={getValueByKey(language)} > ); } + function FormDateTimePickerInput< TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath, diff --git a/src/components/form/date-pickers/time-picker.tsx b/src/components/form/date-pickers/time-picker.tsx index 5c8c9b75..990a585c 100644 --- a/src/components/form/date-pickers/time-picker.tsx +++ b/src/components/form/date-pickers/time-picker.tsx @@ -11,7 +11,7 @@ import { FieldPath, FieldValues, } from "react-hook-form"; -import { ForwardedRef, forwardRef } from "react"; +import { Ref } from "react"; import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFns"; import useLanguage from "@/services/i18n/use-language"; import { getValueByKey } from "@/components/form/date-pickers/helper"; @@ -33,23 +33,14 @@ type TimePickerFieldProps = { timeSteps?: TimeStepOptions | undefined; }; -const TimePickerInput = forwardRef(TimePickerInputRaw) as never as ( +function TimePickerInput( props: TimePickerFieldProps & { name: string; value: ValueDateType; onChange: (value: ValueDateType) => void; onBlur: () => void; - } & { ref?: ForwardedRef } -) => ReturnType; - -function TimePickerInputRaw( - props: TimePickerFieldProps & { - name: string; - value: ValueDateType; - onChange: (value: ValueDateType) => void; - onBlur: () => void; - }, - ref?: ForwardedRef + ref?: Ref; + } ) { const language = useLanguage(); @@ -59,7 +50,7 @@ function TimePickerInputRaw( adapterLocale={getValueByKey(language)} > ); } + function FormTimePickerInput< TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath, diff --git a/src/components/form/multiple-select-extended/form-multiple-select-extended.tsx b/src/components/form/multiple-select-extended/form-multiple-select-extended.tsx index 67668684..f1350b1a 100644 --- a/src/components/form/multiple-select-extended/form-multiple-select-extended.tsx +++ b/src/components/form/multiple-select-extended/form-multiple-select-extended.tsx @@ -6,13 +6,7 @@ import Card from "@mui/material/Card"; import CardContent from "@mui/material/CardContent"; import TextField from "@mui/material/TextField"; import ClickAwayListener from "@mui/material/ClickAwayListener"; -import React, { - ForwardedRef, - forwardRef, - useState, - useRef, - useEffect, -} from "react"; +import React, { Ref, useState, useRef, useEffect } from "react"; import { Controller, ControllerProps, @@ -47,20 +41,21 @@ type MultipleSelectExtendedInputProps = { ); const MUIComponents = { - List: forwardRef(function MuiList( - { style, children }, - listRef - ) { + List: function MuiList({ + style, + children, + ref, + }: ListProps & { ref?: Ref }) { return ( {children} ); - }), + }, Item: ({ children, ...props }: ItemProps) => { return ( @@ -71,14 +66,14 @@ const MUIComponents = { }, }; -function MultipleSelectExtendedInputRaw( +function MultipleSelectExtendedInput( props: MultipleSelectExtendedInputProps & { name: string; value: T[] | null; onChange: (value: T[]) => void; onBlur: () => void; - }, - ref?: ForwardedRef + ref?: Ref; + } ) { const [isOpen, setIsOpen] = useState(false); const boxRef = useRef(null); @@ -96,7 +91,7 @@ function MultipleSelectExtendedInputRaw(
( ); } -const MultipleSelectExtendedInput = forwardRef( - MultipleSelectExtendedInputRaw -) as never as ( - props: MultipleSelectExtendedInputProps & { - name: string; - value: T[] | null; - onChange: (value: T[]) => void; - onBlur: () => void; - } & { ref?: ForwardedRef } -) => ReturnType; - function FormMultipleSelectExtendedInput< TFieldValues extends FieldValues = FieldValues, T extends object = object, diff --git a/src/components/form/multiple-select/form-multiple-select.tsx b/src/components/form/multiple-select/form-multiple-select.tsx index ff316ab7..4dc8045c 100644 --- a/src/components/form/multiple-select/form-multiple-select.tsx +++ b/src/components/form/multiple-select/form-multiple-select.tsx @@ -1,6 +1,6 @@ "use client"; -import { ForwardedRef, forwardRef } from "react"; +import { Ref } from "react"; import { Controller, ControllerProps, @@ -28,20 +28,20 @@ type MultipleSelectInputProps = { renderOption: (option: T) => React.ReactNode; }; -function MultipleSelectInputRaw( +function MultipleSelectInput( props: MultipleSelectInputProps & { name: string; value: T[] | undefined | null; onChange: (value: T[]) => void; onBlur: () => void; - }, - ref?: ForwardedRef + ref?: Ref; + } ) { return ( {props.label} ( ); } -const SelectInput = forwardRef(SelectInputRaw) as never as ( - props: SelectInputProps & { - name: string; - value: T | undefined | null; - onChange: (value: T) => void; - onBlur: () => void; - } & { ref?: ForwardedRef } -) => ReturnType; - function FormSelectInput< TFieldValues extends FieldValues = FieldValues, T extends object = object, diff --git a/src/components/form/switch/form-switch.tsx b/src/components/form/switch/form-switch.tsx index 36c5e30c..7ad43055 100644 --- a/src/components/form/switch/form-switch.tsx +++ b/src/components/form/switch/form-switch.tsx @@ -13,7 +13,7 @@ import FormLabel from "@mui/material/FormLabel"; import FormControlLabel from "@mui/material/FormControlLabel"; import FormGroup from "@mui/material/FormGroup"; import Switch from "@mui/material/Switch"; -import { ForwardedRef, forwardRef } from "react"; +import { Ref } from "react"; export type SwitchInputProps = { label: string; @@ -28,14 +28,14 @@ export type SwitchInputProps = { renderOption: (option: T) => React.ReactNode; }; -function SwitchInputRaw( +function SwitchInput( props: SwitchInputProps & { name: string; value: T[] | undefined | null; onChange: (value: T[]) => void; onBlur: () => void; - }, - ref?: ForwardedRef + ref?: Ref; + } ) { const value = props.value ?? []; @@ -63,7 +63,7 @@ function SwitchInputRaw( {props.label} - + {props.options.map((option) => ( ( ); } -const SwitchInput = forwardRef(SwitchInputRaw) as never as ( - props: SwitchInputProps & { - name: string; - value: T[] | undefined | null; - onChange: (value: T[]) => void; - onBlur: () => void; - } & { ref?: ForwardedRef } -) => ReturnType; - function FormSwitchInput< TFieldValues extends FieldValues = FieldValues, T = unknown, diff --git a/src/components/form/text-input/form-text-input.tsx b/src/components/form/text-input/form-text-input.tsx index 53d62f10..ae266725 100644 --- a/src/components/form/text-input/form-text-input.tsx +++ b/src/components/form/text-input/form-text-input.tsx @@ -4,7 +4,7 @@ import Visibility from "@mui/icons-material/Visibility"; import IconButton from "@mui/material/IconButton"; import InputAdornment from "@mui/material/InputAdornment"; import TextField from "@mui/material/TextField"; -import React, { ChangeEvent, forwardRef, useState } from "react"; +import React, { ChangeEvent, Ref, useState } from "react"; import { Controller, ControllerProps, @@ -29,17 +29,17 @@ type TextInputProps = { size?: "small" | "medium"; }; -const TextInput = forwardRef< - HTMLDivElement | null, - TextInputProps & { +function TextInput( + props: TextInputProps & { name: string; value: string; onChange: ( value: ChangeEvent ) => void; onBlur: () => void; + ref?: Ref; } ->(function TextInput(props, ref) { +) { const [isShowPassword, setIsShowPassword] = useState(false); const handleClickShowPassword = () => setIsShowPassword((show) => !show); @@ -51,7 +51,7 @@ const TextInput = forwardRef< }; return ( ); -}); +} function FormTextInput< TFieldValues extends FieldValues = FieldValues, diff --git a/src/components/link.tsx b/src/components/link.tsx index 564e3acc..7786f323 100644 --- a/src/components/link.tsx +++ b/src/components/link.tsx @@ -6,46 +6,44 @@ import { // Need for leave page logic // eslint-disable-next-line no-restricted-imports import NextLink, { LinkProps } from "next/link"; -import { forwardRef, useContext } from "react"; +import { Ref, useContext } from "react"; -const Link = forwardRef( - function Link(props, ref) { - const language = useLanguage(); - const { isLeavePage } = useContext(LeavePageContext); - const { setLeavePage, openModal } = useContext(LeavePageActionsContext); - let href = props.href; +function Link(props: LinkProps & { ref?: Ref }) { + const language = useLanguage(); + const { isLeavePage } = useContext(LeavePageContext); + const { setLeavePage, openModal } = useContext(LeavePageActionsContext); + let href = props.href; - if (typeof href === "string" && href.startsWith("/")) { - href = `/${language}${href}`; - } else if (typeof href === "object" && href !== null) { - const pathname = href.pathname - ? `/${language}${href.pathname}` - : href.pathname; - href = { - ...href, - pathname, - }; - } - - return ( - { - if (isLeavePage) { - e.preventDefault(); - setLeavePage({ - [props.replace ? "replace" : "push"]: href, - }); - openModal(); - } else { - props.onClick?.(e); - } - }} - /> - ); + if (typeof href === "string" && href.startsWith("/")) { + href = `/${language}${href}`; + } else if (typeof href === "object" && href !== null) { + const pathname = href.pathname + ? `/${language}${href.pathname}` + : href.pathname; + href = { + ...href, + pathname, + }; } -); + + return ( + { + if (isLeavePage) { + e.preventDefault(); + setLeavePage({ + [props.replace ? "replace" : "push"]: href, + }); + openModal(); + } else { + props.onClick?.(e); + } + }} + /> + ); +} export default Link; diff --git a/src/components/table/table-components.tsx b/src/components/table/table-components.tsx index 8b2d5af0..2da7c1ca 100644 --- a/src/components/table/table-components.tsx +++ b/src/components/table/table-components.tsx @@ -1,4 +1,4 @@ -import { forwardRef } from "react"; +import { Ref } from "react"; import Table, { TableProps } from "@mui/material/Table"; import TableBody, { TableBodyProps } from "@mui/material/TableBody"; import TableContainer from "@mui/material/TableContainer"; @@ -6,23 +6,28 @@ import TableHead from "@mui/material/TableHead"; import TableFooter from "@mui/material/TableFooter"; import TableRow from "@mui/material/TableRow"; import Paper from "@mui/material/Paper"; -import { TableComponents as TableComponentsType } from "react-virtuoso"; +import { + ScrollerProps, + TableComponents as TableComponentsType, +} from "react-virtuoso"; const TableComponents = { - Scroller: forwardRef(function Scroller(props, ref) { - return ; - }), + Scroller: function Scroller( + props: ScrollerProps & { ref?: Ref } + ) { + return ; + }, Table: (props: TableProps) => ( ), TableHead: TableHead as unknown as TableComponentsType["TableHead"], TableFoot: TableFooter as unknown as TableComponentsType["TableFoot"], TableRow: TableRow, - TableBody: forwardRef( - function BodyTable(props, ref) { - return ; - } - ), + TableBody: function BodyTable( + props: TableBodyProps & { ref?: Ref } + ) { + return ; + }, }; export default TableComponents;