diff --git a/.vscode/settings.json b/.vscode/settings.json
index 0bbb0e8..1685de1 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -9,5 +9,6 @@
"[\"'`]([^\"'`]*).*?[\"'`]"
]
],
- "editor.formatOnSave": true
+ "editor.formatOnSave": true,
+ "editor.tabSize": 2
}
\ No newline at end of file
diff --git a/src/app.tsx b/src/app.tsx
index 7d2b50e..ec71cd7 100644
--- a/src/app.tsx
+++ b/src/app.tsx
@@ -5,6 +5,7 @@ import { addLocale, locale, PrimeReactProvider } from "primereact/api";
import { useMountEffect } from "primereact/hooks";
import Page404 from "./pages/404";
import LoginPage from "./pages/login";
+import RegisterPage from "./pages/register";
import { AppProvider, useAppContext } from "./providers/AuthProvider";
const HomePage: FunctionComponent = () => {
@@ -32,6 +33,7 @@ export function App() {
+
import("./pages/profile"))} />
} />
diff --git a/src/pages/login.tsx b/src/pages/login.tsx
index eb742c6..6501ba6 100644
--- a/src/pages/login.tsx
+++ b/src/pages/login.tsx
@@ -23,6 +23,7 @@ const LoginPage: FunctionComponent = () => {
});
const login: SubmitHandler = async (data) => {
try {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
const response = await apiClient<{ success: boolean; user?: any; error?: string }>(
"/api/login/",
{
@@ -42,6 +43,7 @@ const LoginPage: FunctionComponent = () => {
setError("login", { message: errorMessage });
setError("password", { message: " " });
}
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
console.error("Login failed:", error);
const errorMessage =
@@ -88,6 +90,17 @@ const LoginPage: FunctionComponent = () => {
Войти
+
+ Еще нет аккаунта?{" "}
+
+
) : (
diff --git a/src/pages/register.tsx b/src/pages/register.tsx
new file mode 100644
index 0000000..edb2150
--- /dev/null
+++ b/src/pages/register.tsx
@@ -0,0 +1,132 @@
+import Button from "@/components/ui/Button";
+import Input from "@/components/ui/Input";
+import { withTitle } from "@/constructors/Component";
+import { UrlsTitle } from "@/enums/urls";
+import { useAppContext } from "@/providers/AuthProvider";
+import apiClient from "@/services/api";
+import { FunctionComponent } from "preact";
+import { useLocation } from "preact-iso";
+import "preact/debug";
+import { Controller, SubmitHandler, useForm } from "react-hook-form";
+import { ILoginForm } from "./login.dto";
+import classes from "./login.module.scss";
+
+interface IRegisterForm extends ILoginForm {
+ confirmPassword: string;
+}
+
+const RegisterPage: FunctionComponent = () => {
+ const { isLoggedIn } = useAppContext();
+ const { route } = useLocation();
+ const { control, handleSubmit, formState, setError } = useForm({
+ defaultValues: {
+ login: "",
+ password: "",
+ confirmPassword: "",
+ },
+ mode: "onChange",
+ });
+ const register: SubmitHandler = async (data) => {
+ if (data.password !== data.confirmPassword) {
+ setError("confirmPassword", { message: "Пароли не совпадают" });
+ return;
+ }
+ try {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const response = await apiClient<{ success: boolean; user?: any; error?: string }>("/api/register/", {
+ method: "POST",
+ body: JSON.stringify({ username: data.login, password: data.password }),
+ needsCsrf: true,
+ });
+
+ if (response.success) {
+ route("/login", true);
+ } else {
+ const errorMessage = response.error || "Неверный логин или пароль";
+ setError("login", { message: errorMessage });
+ setError("password", { message: " " });
+ setError("confirmPassword", { message: " " });
+ }
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ } catch (error: any) {
+ console.error("Register failed:", error);
+ const errorMessage = "Ошибка входа. Попробуйте позже.";
+ setError("login", { message: errorMessage });
+ setError("password", { message: " " });
+ setError("confirmPassword", { message: " " });
+ }
+ };
+ if (isLoggedIn.value) route("/profile/tasks", true);
+ return !isLoggedIn.value ? (
+
+
+
Антихвост
+
+
+ Уже есть аккаунт?{" "}
+
+
+
+
+ ) : (
+ Redirecting...
+ );
+};
+
+export default withTitle(UrlsTitle.REGISTER, RegisterPage);