From a62d3d1c1dc5baae920deb620f6e6e386ff40c7c Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Fri, 14 Jun 2024 07:17:36 +0530 Subject: [PATCH] Drop unused `context` from Form Fields due to unnecessary complexity (#7983) * Drop unused `context` from Form Fields as it was adding unnecessary complexity and decreased type-safety * try fixing storybook vite config * update vite config --- .storybook/vite.config.mts | 10 +-- .../Common/BloodPressureFormField.tsx | 2 +- .../PMJAYProcedurePackageAutocomplete.tsx | 2 +- .../Common/RouteToFacilitySelect.tsx | 2 +- .../Common/UserAutocompleteFormField.tsx | 4 +- src/Components/Form/FormContext.ts | 4 +- .../Form/FormFields/DateFormField.tsx | 2 +- .../Form/FormFields/DateRangeFormField.tsx | 2 +- src/Components/Form/FormFields/Month.tsx | 2 +- .../Form/FormFields/PhoneNumberFormField.tsx | 9 ++- .../Form/FormFields/TextAreaFormField.tsx | 2 +- .../Form/FormFields/TextFormField.tsx | 2 +- src/Components/Form/FormFields/Utils.ts | 62 +++---------------- src/Components/HCX/ClaimsItemsBuilder.tsx | 2 +- .../HCX/InsuranceDetailsBuilder.tsx | 2 +- src/Components/HCX/InsurerAutocomplete.tsx | 4 +- vite.config.mts | 6 +- 17 files changed, 38 insertions(+), 81 deletions(-) diff --git a/.storybook/vite.config.mts b/.storybook/vite.config.mts index 1e6e2445ffa..89e6222f220 100644 --- a/.storybook/vite.config.mts +++ b/.storybook/vite.config.mts @@ -1,8 +1,2 @@ -import { defineConfig } from "vite"; - -export default defineConfig({ - esbuild: { - loader: "tsx", - include: [/src\/.*\.[tj]sx?$/, /.storybook\/.*\.[tj]sx?$/], - }, -}); +/** @type {import('vite').UserConfig} */ +export default {}; diff --git a/src/Components/Common/BloodPressureFormField.tsx b/src/Components/Common/BloodPressureFormField.tsx index 3f7ecacce46..95dbad02f62 100644 --- a/src/Components/Common/BloodPressureFormField.tsx +++ b/src/Components/Common/BloodPressureFormField.tsx @@ -11,7 +11,7 @@ import { BloodPressure } from "../Patient/models"; type Props = FormFieldBaseProps; export default function BloodPressureFormField(props: Props) { - const field = useFormFieldPropsResolver(props as any); + const field = useFormFieldPropsResolver(props); const handleChange = (event: FieldChangeEvent) => { const value: BloodPressure = { diff --git a/src/Components/Common/PMJAYProcedurePackageAutocomplete.tsx b/src/Components/Common/PMJAYProcedurePackageAutocomplete.tsx index f99e07ab5db..1fee5599220 100644 --- a/src/Components/Common/PMJAYProcedurePackageAutocomplete.tsx +++ b/src/Components/Common/PMJAYProcedurePackageAutocomplete.tsx @@ -17,7 +17,7 @@ type PMJAYPackageItem = { type Props = FormFieldBaseProps; export default function PMJAYProcedurePackageAutocomplete(props: Props) { - const field = useFormFieldPropsResolver(props as any); + const field = useFormFieldPropsResolver(props); const { fetchOptions, isLoading, options } = useAsyncOptions("code"); diff --git a/src/Components/Common/RouteToFacilitySelect.tsx b/src/Components/Common/RouteToFacilitySelect.tsx index 0bd4e83100a..56ba5c528dc 100644 --- a/src/Components/Common/RouteToFacilitySelect.tsx +++ b/src/Components/Common/RouteToFacilitySelect.tsx @@ -19,7 +19,7 @@ export const keys = Object.keys(ROUTE_TO_FACILITY_OPTIONS).map((key) => type Props = FormFieldBaseProps; export default function RouteToFacilitySelect(props: Props) { - const field = useFormFieldPropsResolver(props as any); + const field = useFormFieldPropsResolver(props); return ( & { }; export default function UserAutocompleteFormField(props: Props) { - const field = useFormFieldPropsResolver(props as any); + const field = useFormFieldPropsResolver(props); const { fetchOptions, isLoading, options } = useAsyncOptions( "id", { queryResponseExtractor: (data) => data.results }, @@ -65,6 +65,8 @@ export default function UserAutocompleteFormField(props: Props) { = ( error: FieldError | undefined; }; -export type FormContext = Context>; - export const createFormContext = () => createContext>(undefined as any); diff --git a/src/Components/Form/FormFields/DateFormField.tsx b/src/Components/Form/FormFields/DateFormField.tsx index adb8c2538ae..3bec3712e2b 100644 --- a/src/Components/Form/FormFields/DateFormField.tsx +++ b/src/Components/Form/FormFields/DateFormField.tsx @@ -29,7 +29,7 @@ type Props = FormFieldBaseProps & { * ``` */ const DateFormField = (props: Props) => { - const field = useFormFieldPropsResolver(props as any); + const field = useFormFieldPropsResolver(props); return ( & { * ``` */ const DateRangeFormField = (props: Props) => { - const field = useFormFieldPropsResolver(props as any); + const field = useFormFieldPropsResolver(props); return ( { - const field = useFormFieldPropsResolver(props as any); + const field = useFormFieldPropsResolver(props); const [month, setMonth] = useState(field.value?.getMonth()); const [year, setYear] = useState(field.value?.getFullYear()); diff --git a/src/Components/Form/FormFields/PhoneNumberFormField.tsx b/src/Components/Form/FormFields/PhoneNumberFormField.tsx index a22254179f8..b2034507475 100644 --- a/src/Components/Form/FormFields/PhoneNumberFormField.tsx +++ b/src/Components/Form/FormFields/PhoneNumberFormField.tsx @@ -27,7 +27,7 @@ interface Props extends FormFieldBaseProps { } export default function PhoneNumberFormField(props: Props) { - const field = useFormFieldPropsResolver(props as any); + const field = useFormFieldPropsResolver(props); const [error, setError] = useState(); const [country, setCountry] = useState({ flag: "🇮🇳", @@ -183,8 +183,11 @@ const conditionPhoneCode = (code: string) => { return code.startsWith("+") ? code : "+" + code; }; -const formatPhoneNumber = (value: string, types: PhoneNumberType[]) => { - if (value === undefined || value === null) { +const formatPhoneNumber = ( + value: string | undefined, + types: PhoneNumberType[], +) => { + if (value == null) { return "+91 "; } diff --git a/src/Components/Form/FormFields/TextAreaFormField.tsx b/src/Components/Form/FormFields/TextAreaFormField.tsx index 20373900cd2..c19a8e3c1c9 100644 --- a/src/Components/Form/FormFields/TextAreaFormField.tsx +++ b/src/Components/Form/FormFields/TextAreaFormField.tsx @@ -19,7 +19,7 @@ const TextAreaFormField = forwardRef( { rows = 3, ...props }: TextAreaFormFieldProps, ref?: React.Ref, ) => { - const field = useFormFieldPropsResolver(props as any); + const field = useFormFieldPropsResolver(props); return (