fix(customers): improve type safety in assign to company modal
- Add ChangeEvent import for proper TypeScript typing - Remove unused register function from useForm hook - Refactor onChange handler with explicit ChangeEvent<HTMLSelectElement> type annotation - Extract target value into variable for improved readability - Ensure consistent form field updates between setValue and setCompanies calls - Improve type safety and reduce potential runtime errors in form handling
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Dispatch, FC, SetStateAction, useEffect, useState } from "react";
|
||||
import { ChangeEvent, Dispatch, FC, SetStateAction, useEffect, useState } from "react";
|
||||
|
||||
import { Select } from "@/components/FormElements/select";
|
||||
import { Building } from "@/components/Layouts/sidebar/icons";
|
||||
@@ -20,7 +20,7 @@ const AssignToCompanyModalContent: FC<IProps> = ({
|
||||
const [options, setOptions] = useState<ILabelValue[]>([]);
|
||||
|
||||
const { data, status, isSuccess } = useCompanyFullList();
|
||||
const { handleSubmit, register, watch, setValue } =
|
||||
const { handleSubmit, watch, setValue } =
|
||||
useForm<TAssignCustomerToCompanyCredentials>({
|
||||
mode: "onChange",
|
||||
defaultValues,
|
||||
@@ -59,12 +59,15 @@ const AssignToCompanyModalContent: FC<IProps> = ({
|
||||
prefixIcon={<Building />}
|
||||
placeholder="Please Select company"
|
||||
value={selectedCompanyId}
|
||||
onChange={(e) => {
|
||||
setValue("company_ids", [e.target.value]);
|
||||
onChange={
|
||||
((e: ChangeEvent<HTMLSelectElement>) => {
|
||||
const value = e.target.value;
|
||||
setValue("company_ids", [value]);
|
||||
setCompanies({
|
||||
company_ids: [e.target.value],
|
||||
company_ids: [value],
|
||||
});
|
||||
}}
|
||||
}) as any
|
||||
}
|
||||
required
|
||||
/>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user