[feat]: Added test registration
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "../../../../lib/utils"
|
||||
|
||||
export interface TextareaProps
|
||||
extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}
|
||||
|
||||
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||
({ className, ...props }, ref) => {
|
||||
return (
|
||||
<textarea
|
||||
className={cn(
|
||||
"flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
)
|
||||
Textarea.displayName = "Textarea"
|
||||
|
||||
export { Textarea }
|
||||
@@ -6,10 +6,37 @@ export const submitLogin = (e: FormEvent<HTMLFormElement>) => {
|
||||
const formData = new FormData(e.currentTarget);
|
||||
const formProps = Object.fromEntries(formData);
|
||||
console.log(formProps)
|
||||
|
||||
}
|
||||
export const submitRegister = (e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
const formData = new FormData(e.currentTarget);
|
||||
const formProps = Object.fromEntries(formData);
|
||||
console.log(formProps)
|
||||
}
|
||||
|
||||
const apiUrl = "http://localhost:8080/api/registration/";
|
||||
|
||||
fetch(apiUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: formData
|
||||
})
|
||||
.then(response => {
|
||||
console.log(response.status)
|
||||
if (response.status === 201) {
|
||||
console.log('Создан:', response.headers.get('Location'));
|
||||
} else if (!(response.status === 201)) {
|
||||
throw new Error('Код ошибки: ' + response.status);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
console.log('Успешно:', data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Возникла ошибка с регой:', error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,42 +1,65 @@
|
||||
import { DialogContent, DialogTitle, DialogDescription } from "../../shared/ui/dialog";
|
||||
import { DialogContent, DialogTitle, DialogDescription, Dialog, DialogTrigger } from "../../shared/ui/dialog";
|
||||
import { Tabs, TabsList, TabsTrigger, TabsContent } from "../../shared/ui/tabs";
|
||||
import { t } from "i18next";
|
||||
import { Button } from "../../shared/ui/button";
|
||||
import { DialogHeader } from "../../shared/ui/dialog";
|
||||
import { Input } from "../../shared/ui/input";
|
||||
import { submitLogin, submitRegister } from "./AuthAPI";
|
||||
import { Textarea } from "../../shared/ui/textarea";
|
||||
|
||||
const AuthForm = () => {
|
||||
|
||||
|
||||
return (
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("entrance")}</DialogTitle>
|
||||
<Tabs defaultValue="account" className="w-[400px]">
|
||||
<TabsList>
|
||||
<TabsTrigger value="account">{t("login")}</TabsTrigger>
|
||||
<TabsTrigger value="password">{t("registration")}</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent value="account" >
|
||||
<form className="flex flex-col gap-y-1" onSubmit={submitLogin}>
|
||||
<Input type="email" name="email" placeholder="Email" />
|
||||
<Input type="password" name="password" placeholder="Password" />
|
||||
<Button className="mt-3">{t("buttonLoginInSystem")}</Button>
|
||||
</form>
|
||||
</TabsContent>
|
||||
<TabsContent value="password">
|
||||
<form className="flex flex-col gap-y-1 mb-2" onSubmit={submitRegister}>
|
||||
<Input type="text" className="m-to-2" name="username" placeholder="Username" />
|
||||
<Input type="email" name="email" placeholder="Email"/>
|
||||
<Input type="password" name="password" placeholder="Password"/>
|
||||
<Input type="password" name="repPassword" placeholder="Password"/>
|
||||
<Button className="mt-3">{t("buttonRegInSystemStep1")}</Button>
|
||||
</form>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</DialogHeader>
|
||||
</DialogContent>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("entrance")}</DialogTitle>
|
||||
<Tabs defaultValue="account" className="w-[400px]">
|
||||
<TabsList>
|
||||
<TabsTrigger value="account">{t("login")}</TabsTrigger>
|
||||
<TabsTrigger value="password">{t("registration")}</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent value="account" >
|
||||
<form className="flex flex-col gap-y-1" onSubmit={submitLogin}>
|
||||
<Input type="email" name="email" placeholder="Email" />
|
||||
<Input type="password" name="password" placeholder="Password" />
|
||||
<Button className="mt-3">{t("buttonLoginInSystem")}</Button>
|
||||
</form>
|
||||
</TabsContent>
|
||||
<TabsContent value="password">
|
||||
<form className="flex flex-col gap-y-1 mb-2" onSubmit={submitRegister}>
|
||||
<Input type="text" name="username" placeholder="Username" />
|
||||
<Input type="email" name="email" placeholder="Email" />
|
||||
<Input type="password" name="password" placeholder="Password" />
|
||||
<Input type="password" placeholder="Password" />
|
||||
<Button> qrefqwfqw</Button>
|
||||
<Dialog>
|
||||
<DialogTrigger className="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground shadow hover:bg-primary/90 h-9 px-4 py-2">{t("buttonRegInSystemStep1")}
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Еще немного!</DialogTitle>
|
||||
<Tabs defaultValue="account" className="w-[400px]">
|
||||
<DialogDescription>
|
||||
<Input type="text" name="first_name" placeholder="first name" />
|
||||
<Input type="text" name="last_name" placeholder="last name" />
|
||||
<Input type="number" name="experience" placeholder="experience" />
|
||||
<Input type="text" name="country" placeholder="country" />
|
||||
<Input type="text" name="city" placeholder="city" />
|
||||
<Input type="date" name="birthday" placeholder="birthday" />
|
||||
<Textarea name="bio" placeholder="bio" />
|
||||
|
||||
</DialogDescription>
|
||||
</Tabs>
|
||||
</DialogHeader>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</form>
|
||||
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</DialogHeader>
|
||||
</DialogContent>
|
||||
)
|
||||
}
|
||||
}
|
||||
export default AuthForm;
|
||||
Reference in New Issue
Block a user