mediahub-fe/components/partials/auth/forgot-pass.tsx

75 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-11-26 03:09:48 +00:00
"use client";
import React, { useState } from "react";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
type Inputs = {
example: string;
exampleRequired: string;
};
import { useForm, SubmitHandler } from "react-hook-form";
2025-01-15 15:59:19 +00:00
import { error, loading } from "@/config/swal";
import withReactContent from "sweetalert2-react-content";
import Swal from "sweetalert2";
import { useRouter } from "@/i18n/routing";
import { forgotPassword } from "@/service/landing/landing";
2024-11-26 03:09:48 +00:00
const ForgotPass = () => {
2025-01-15 15:59:19 +00:00
const [username, setUsername] = useState<any>();
const MySwal = withReactContent(Swal);
const router = useRouter();
const {
register,
handleSubmit,
watch,
formState: { errors },
} = useForm<Inputs>();
const onSubmit: SubmitHandler<Inputs> = (data) => console.log(data);
async function handleCheckUsername() {
loading();
const response = await forgotPassword(username);
if (response.error) {
error(response.message);
return false;
}
successSubmit();
return false;
}
function successSubmit() {
MySwal.fire({
title: "Email berhasil dikirim. Silahkan cek email Anda.",
icon: "success",
confirmButtonColor: "#3085d6",
confirmButtonText: "OK",
}).then((result: any) => {
if (result.isConfirmed) {
router.push("/admin");
}
});
}
2024-11-26 03:09:48 +00:00
return (
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4 ">
<div className="space-y-2">
2025-01-15 15:59:19 +00:00
<Label htmlFor="user-name">Username</Label>
<Input id="user-name" defaultValue="akun1234" className="h-[48px] text-sm text-default-900 " onChange={(e) => setUsername(e.target.value)} />
2024-11-26 03:09:48 +00:00
</div>
2025-01-15 15:59:19 +00:00
<Button type="submit" fullWidth onClick={handleCheckUsername}>
Check Username
</Button>
<Button type="submit" fullWidth onClick={handleCheckUsername}>
2025-01-16 01:03:10 +00:00
Kirim Ulang?{" "}
2024-11-26 03:09:48 +00:00
</Button>
</form>
);
};
export default ForgotPass;