Files
front-AT/app/Components/auth/ChangePassword/changePassword.tsx
T

88 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-09-24 14:05:51 -06:00
"use client";
2025-10-08 12:01:52 -06:00
import apiClient from "@/app/lib/apiClient";
2025-09-24 14:05:51 -06:00
import { useState } from "react";
2026-01-15 13:16:38 -06:00
import toast from "react-hot-toast";
2025-09-05 18:24:12 -04:00
2025-09-24 14:05:51 -06:00
export default function ChangePassword() {
2026-01-15 13:16:38 -06:00
const [password, setPass] = useState("");
const [newPassword, setNewPass] = useState("");
2025-09-24 14:05:51 -06:00
const [confirmNewPass, setconfirmNewPass] = useState("");
2025-09-05 18:24:12 -04:00
2025-10-06 17:26:14 -06:00
const handleChangePass = async (e: React.FormEvent<HTMLFormElement>) => {
2026-01-15 13:16:38 -06:00
e.preventDefault();
const data = { password, newPassword };
2025-10-06 17:26:14 -06:00
2026-01-15 13:16:38 -06:00
try{
const response = await apiClient.post("/user/changePassword", data);
toast.success( `${response.data.message}`)
setPass('');
setNewPass('');
setconfirmNewPass('');
2026-01-15 13:16:38 -06:00
}catch{
toast.error( `No es la contraseña actual`)
}
2025-09-24 14:05:51 -06:00
};
2025-09-05 18:24:12 -04:00
2025-09-24 14:05:51 -06:00
return (
<section className="centerGrid containerSection">
2025-09-24 16:22:31 -06:00
<form onSubmit={handleChangePass} className="pass">
2025-09-24 14:05:51 -06:00
<div className="containerInput relative">
<label className="label">Contraseña actual</label>
<input
placeholder="Coloca tu contraseña..."
2026-01-15 13:16:38 -06:00
value={password}
type="password"
2025-09-24 14:05:51 -06:00
onChange={(e) => {
setPass(e.target.value);
}}
/>
<span />
</div>
2025-09-05 18:24:12 -04:00
2025-09-24 14:05:51 -06:00
<div className="containerInput relative">
<label className="label">Nueva contraseña</label>
<input
placeholder="Coloca tu nueva contraseña..."
2026-01-15 13:16:38 -06:00
value={newPassword}
type="password"
2025-09-24 14:05:51 -06:00
onChange={(e) => {
setNewPass(e.target.value);
}}
/>
<span />
</div>
2025-09-05 18:24:12 -04:00
2025-09-24 14:05:51 -06:00
<div className="containerInput relative">
<label className="label">Confirmar la contraña</label>
<input
2025-09-24 17:51:54 -06:00
placeholder="Coloca tu nueva contraseña..."
2025-09-24 14:05:51 -06:00
value={confirmNewPass}
2026-01-15 13:16:38 -06:00
type="password"
2025-09-24 14:05:51 -06:00
onChange={(e) => {
setconfirmNewPass(e.target.value);
}}
/>
<span />
</div>
2025-09-05 18:24:12 -04:00
2025-09-24 14:05:51 -06:00
<div className="containerButton">
<button
className="button buttonSearch"
style={{ maxWidth: "100%", width: "100%" }}
>
Confirmar
</button>
2025-09-05 18:24:12 -04:00
2025-09-24 14:05:51 -06:00
<button
2025-09-24 18:34:13 -06:00
className="button buttonCancel"
2025-09-24 14:05:51 -06:00
style={{ maxWidth: "100%", width: "100%" }}
>
Cancelar
</button>
</div>
</form>
</section>
);
2025-09-05 18:24:12 -04:00
}
2026-01-15 13:16:38 -06:00
//IO