feat(CreateCustomer): add password visibility toggle and enhance form handling
- Integrated EyeIcon for password visibility toggle in the CreateCustomer component. - Updated useCreateCustomerPresenter to manage password visibility state. - Improved form handling by adding showPassword and setShowPassword to the presenter.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { GlobeIcon } from "@/assets/icons";
|
import { EyeIcon, GlobeIcon } from "@/assets/icons";
|
||||||
import InputGroup from "@/components/FormElements/InputGroup";
|
import InputGroup from "@/components/FormElements/InputGroup";
|
||||||
import MultiSelect from "@/components/FormElements/MultiSelect";
|
import MultiSelect from "@/components/FormElements/MultiSelect";
|
||||||
import { Select } from "@/components/FormElements/select";
|
import { Select } from "@/components/FormElements/select";
|
||||||
@@ -20,8 +20,16 @@ interface IProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const CreateCustomer = ({ defaultValues, editMode, id }: IProps) => {
|
const CreateCustomer = ({ defaultValues, editMode, id }: IProps) => {
|
||||||
const { errors, handleSubmit, register, watch, onSubmit, companies, router } =
|
const {
|
||||||
useCreateCustomerPresenter({ defaultValues, editMode, id });
|
errors,
|
||||||
|
handleSubmit,
|
||||||
|
register,
|
||||||
|
watch,
|
||||||
|
onSubmit,
|
||||||
|
companies,
|
||||||
|
showPassword,
|
||||||
|
setShowPassword,
|
||||||
|
} = useCreateCustomerPresenter({ defaultValues, editMode, id });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className="grid grid-cols-1 gap-9" onSubmit={handleSubmit(onSubmit)}>
|
<form className="grid grid-cols-1 gap-9" onSubmit={handleSubmit(onSubmit)}>
|
||||||
@@ -120,8 +128,19 @@ const CreateCustomer = ({ defaultValues, editMode, id }: IProps) => {
|
|||||||
})}
|
})}
|
||||||
disabled={editMode}
|
disabled={editMode}
|
||||||
name="password"
|
name="password"
|
||||||
|
icon={
|
||||||
|
<span
|
||||||
|
className="cursor-pointer"
|
||||||
|
onClick={() => {
|
||||||
|
setShowPassword(!showPassword);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<EyeIcon />
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
iconPosition="right"
|
||||||
label="Password"
|
label="Password"
|
||||||
type="password"
|
type={showPassword ? "text" : "password"}
|
||||||
placeholder="Enter password"
|
placeholder="Enter password"
|
||||||
required={!editMode}
|
required={!editMode}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
} from "@/hooks/queries";
|
} from "@/hooks/queries";
|
||||||
import { CreateCustomerCredentials } from "@/lib/api";
|
import { CreateCustomerCredentials } from "@/lib/api";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SubmitHandler, useForm } from "react-hook-form";
|
import { SubmitHandler, useForm } from "react-hook-form";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
@@ -33,6 +33,7 @@ const useCreateCustomerPresenter = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const [showPassword, setShowPassword] = useState(false);
|
||||||
const { mutate: createCustomer, isPending: isCreating } = useCreateCustomer();
|
const { mutate: createCustomer, isPending: isCreating } = useCreateCustomer();
|
||||||
const { mutate: updateCustomer, isPending: isUpdating } = useUpdateCustomer(
|
const { mutate: updateCustomer, isPending: isUpdating } = useUpdateCustomer(
|
||||||
id as string,
|
id as string,
|
||||||
@@ -69,6 +70,8 @@ const useCreateCustomerPresenter = ({
|
|||||||
onSubmit,
|
onSubmit,
|
||||||
companies: companies?.data.companies,
|
companies: companies?.data.companies,
|
||||||
router,
|
router,
|
||||||
|
showPassword,
|
||||||
|
setShowPassword,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user