import { Switch } from '@headlessui/react'; import { Dispatch, FunctionComponent } from 'react'; import { SubmitHandler, useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { z } from 'zod'; import { UpdatePasswordSchema } from '@/services/users/auth/schema/CreateUserValidationSchemas'; import { AccountPageState, AccountPageAction } from '@/reducers/accountPageReducer'; import toast from 'react-hot-toast'; import createErrorToast from '@/util/createErrorToast'; import { sendUpdatePasswordRequest } from '@/requests/users/auth'; import FormError from '../ui/forms/FormError'; import FormInfo from '../ui/forms/FormInfo'; import FormLabel from '../ui/forms/FormLabel'; import FormTextInput from '../ui/forms/FormTextInput'; interface SecurityProps { pageState: AccountPageState; dispatch: Dispatch; } const Security: FunctionComponent = ({ dispatch, pageState }) => { const { register, handleSubmit, formState, reset } = useForm< z.infer >({ resolver: zodResolver(UpdatePasswordSchema), }); const onSubmit: SubmitHandler> = async (data) => { const loadingToast = toast.loading('Changing password.'); try { await sendUpdatePasswordRequest(data); toast.remove(loadingToast); toast.success('Password changed successfully.'); dispatch({ type: 'CLOSE_ALL' }); } catch (error) { dispatch({ type: 'CLOSE_ALL' }); createErrorToast(error); } }; return (

Change Your Password

Update your password to maintain the safety of your account.

{ dispatch({ type: 'TOGGLE_SECURITY_VISIBILITY' }); reset(); }} />
{pageState.securityOpen && (
New Password {formState.errors.password?.message} Confirm Password {formState.errors.confirmPassword?.message} )}
); }; export default Security;