Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…NTAURI into front
  • Loading branch information
fabinsz committed Jun 26, 2024
2 parents c255ce2 + 6df5f55 commit c65812e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
15 changes: 15 additions & 0 deletions projeto/client/actions/cadastro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use server";

import * as z from "zod";

import { CadastroSchema } from "@/schemas";

export const register = async (values: z.infer<typeof CadastroSchema>) => {
const validatedFields = CadastroSchema.safeParse(values);

if(!validatedFields.success) {
return { error: "Campos inválidos!" };
}

return { success: "Bem vindo!" };
};
15 changes: 15 additions & 0 deletions projeto/client/actions/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use server";

import * as z from "zod";

import { LoginSchema } from "@/schemas";

export const login = async (values: z.infer<typeof LoginSchema>) => {
const validatedFields = LoginSchema.safeParse(values);

if(!validatedFields.success) {
return { error: "Campos inválidos!" };
}

return { success: "Bem vindo!" };
};
9 changes: 7 additions & 2 deletions projeto/client/components/auth/cadastro-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as z from "zod";

import { useState, useTransition } from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";

Expand All @@ -15,13 +16,13 @@ import {
FormLabel,
FormMessage,
} from "@/components/ui/form";
import React from "react";

import Select from "react-select";
import { CardWrapper } from "./card-register"
import { Button } from "@/components/ui/button";
import { FormError } from "@/components/form-error";
import { FormSuccess } from "@/components/form-sucess";
import { Label } from "../ui/label";
import { cadastro } from "@/actions/cadastro";

const TimeSelect = [
{ value: "America_Mineiro", label: "America Mineiro" },
Expand Down Expand Up @@ -49,6 +50,10 @@ const TimeSelect = [


export const CadastroForm = () => {
const [error, setError] = useState<string | undefined>("");
const [success, setSuccess] = useState<string | undefined>("");
const [isPending, startTransition] = useTransition();

const form = useForm<z.infer<typeof CadastroSchema>>({
resolver: zodResolver(CadastroSchema),
defaultValues: {
Expand Down
2 changes: 1 addition & 1 deletion projeto/client/components/auth/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Header = ({
<div className="w-full flex flex-col gap-y-4 items-center justify-center">
<img src="/logo.png" alt="Login Icon" className="w-12 h-auto" />
<h1 className={cn("text-3xl font-semibold", font.className)}>
Onde é o Jogo?
Onde é o Jogo?
</h1>
<p className="text-muted-foreground text-sm">
{label}
Expand Down
17 changes: 16 additions & 1 deletion projeto/client/components/auth/login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as z from "zod";

import { useState, useTransition } from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";

Expand All @@ -20,8 +21,13 @@ import { CardWrapper } from "./card-wrapper";
import { Button } from "@/components/ui/button";
import { FormError } from "@/components/form-error";
import { FormSuccess } from "@/components/form-sucess";
import { login } from "@/actions/login";

export const LoginForm = () => {
const [error, setError] = useState<string | undefined>("");
const [success, setSuccess] = useState<string | undefined>("");
const [isPending, startTransition] = useTransition();

const form = useForm<z.infer<typeof LoginSchema>>({
resolver: zodResolver(LoginSchema),
defaultValues: {
Expand All @@ -31,7 +37,16 @@ export const LoginForm = () => {
});

const onSubmit = (values: z.infer<typeof LoginSchema>) => {
console.log(values);
setError("");
setSuccess("");

startTransition(() => {
login(values)
.then((data) => {
setError(data.error);
setSuccess(data.success);
})
});
}

return (
Expand Down

0 comments on commit c65812e

Please sign in to comment.