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 { Select } from "@/components/FormElements/select";
|
||||||
import { Building } from "@/components/Layouts/sidebar/icons";
|
import { Building } from "@/components/Layouts/sidebar/icons";
|
||||||
@@ -20,7 +20,7 @@ const AssignToCompanyModalContent: FC<IProps> = ({
|
|||||||
const [options, setOptions] = useState<ILabelValue[]>([]);
|
const [options, setOptions] = useState<ILabelValue[]>([]);
|
||||||
|
|
||||||
const { data, status, isSuccess } = useCompanyFullList();
|
const { data, status, isSuccess } = useCompanyFullList();
|
||||||
const { handleSubmit, register, watch, setValue } =
|
const { handleSubmit, watch, setValue } =
|
||||||
useForm<TAssignCustomerToCompanyCredentials>({
|
useForm<TAssignCustomerToCompanyCredentials>({
|
||||||
mode: "onChange",
|
mode: "onChange",
|
||||||
defaultValues,
|
defaultValues,
|
||||||
@@ -59,12 +59,15 @@ const AssignToCompanyModalContent: FC<IProps> = ({
|
|||||||
prefixIcon={<Building />}
|
prefixIcon={<Building />}
|
||||||
placeholder="Please Select company"
|
placeholder="Please Select company"
|
||||||
value={selectedCompanyId}
|
value={selectedCompanyId}
|
||||||
onChange={(e) => {
|
onChange={
|
||||||
setValue("company_ids", [e.target.value]);
|
((e: ChangeEvent<HTMLSelectElement>) => {
|
||||||
setCompanies({
|
const value = e.target.value;
|
||||||
company_ids: [e.target.value],
|
setValue("company_ids", [value]);
|
||||||
});
|
setCompanies({
|
||||||
}}
|
company_ids: [value],
|
||||||
|
});
|
||||||
|
}) as any
|
||||||
|
}
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user