2023-10-16 12:10:52 -05:00
|
|
|
import SettingsLayout from "@/layouts/SettingsLayout";
|
2023-10-18 16:50:55 -05:00
|
|
|
import { useState } from "react";
|
|
|
|
import useAccountStore from "@/store/account";
|
|
|
|
import SubmitButton from "@/components/SubmitButton";
|
|
|
|
import { toast } from "react-hot-toast";
|
|
|
|
import TextInput from "@/components/TextInput";
|
2023-10-16 12:10:52 -05:00
|
|
|
|
2023-10-18 23:09:28 -05:00
|
|
|
export default function Password() {
|
2023-10-18 16:50:55 -05:00
|
|
|
const [newPassword, setNewPassword1] = useState("");
|
|
|
|
const [newPassword2, setNewPassword2] = useState("");
|
|
|
|
|
|
|
|
const [submitLoader, setSubmitLoader] = useState(false);
|
|
|
|
|
|
|
|
const { account, updateAccount } = useAccountStore();
|
|
|
|
|
|
|
|
const submit = async () => {
|
|
|
|
if (newPassword == "" || newPassword2 == "") {
|
2023-10-24 14:57:37 -05:00
|
|
|
return toast.error("Please fill all the fields.");
|
2023-10-18 16:50:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (newPassword !== newPassword2)
|
|
|
|
return toast.error("Passwords do not match.");
|
|
|
|
else if (newPassword.length < 8)
|
|
|
|
return toast.error("Passwords must be at least 8 characters.");
|
|
|
|
|
|
|
|
setSubmitLoader(true);
|
|
|
|
|
|
|
|
const load = toast.loading("Applying...");
|
|
|
|
|
|
|
|
const response = await updateAccount({
|
|
|
|
...account,
|
|
|
|
newPassword,
|
|
|
|
});
|
|
|
|
|
|
|
|
toast.dismiss(load);
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
toast.success("Settings Applied!");
|
|
|
|
setNewPassword1("");
|
|
|
|
setNewPassword2("");
|
|
|
|
} else toast.error(response.data as string);
|
|
|
|
|
|
|
|
setSubmitLoader(false);
|
|
|
|
};
|
|
|
|
|
2023-10-16 12:10:52 -05:00
|
|
|
return (
|
|
|
|
<SettingsLayout>
|
2023-11-20 11:48:41 -06:00
|
|
|
<p className="capitalize text-3xl font-thin inline">Change Password</p>
|
|
|
|
|
2023-12-01 11:01:56 -06:00
|
|
|
<div className="divider my-3"></div>
|
2023-11-20 11:48:41 -06:00
|
|
|
|
2023-10-18 16:50:55 -05:00
|
|
|
<p className="mb-3">
|
|
|
|
To change your password, please fill out the following. Your password
|
|
|
|
should be at least 8 characters.
|
|
|
|
</p>
|
|
|
|
<div className="w-full flex flex-col gap-2 justify-between">
|
2023-11-24 07:39:55 -06:00
|
|
|
<p>New Password</p>
|
2023-10-18 16:50:55 -05:00
|
|
|
|
|
|
|
<TextInput
|
|
|
|
value={newPassword}
|
2023-12-01 13:00:52 -06:00
|
|
|
className="bg-base-200"
|
2023-10-18 16:50:55 -05:00
|
|
|
onChange={(e) => setNewPassword1(e.target.value)}
|
|
|
|
placeholder="••••••••••••••"
|
|
|
|
type="password"
|
|
|
|
/>
|
|
|
|
|
2023-11-24 07:39:55 -06:00
|
|
|
<p>Confirm New Password</p>
|
2023-10-18 16:50:55 -05:00
|
|
|
|
|
|
|
<TextInput
|
|
|
|
value={newPassword2}
|
2023-12-01 13:00:52 -06:00
|
|
|
className="bg-base-200"
|
2023-10-18 16:50:55 -05:00
|
|
|
onChange={(e) => setNewPassword2(e.target.value)}
|
|
|
|
placeholder="••••••••••••••"
|
|
|
|
type="password"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<SubmitButton
|
|
|
|
onClick={submit}
|
|
|
|
loading={submitLoader}
|
2024-01-19 07:01:21 -06:00
|
|
|
label="Save Changes"
|
|
|
|
className="mt-2 w-full sm:w-fit"
|
2023-10-18 16:50:55 -05:00
|
|
|
/>
|
|
|
|
</div>
|
2023-10-16 12:10:52 -05:00
|
|
|
</SettingsLayout>
|
|
|
|
);
|
|
|
|
}
|