Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan-Roberts123 committed Jun 5, 2024
1 parent 9de2363 commit 32e2029
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/app/auth/components/base-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import { InputText } from "primereact/inputtext";
import { Button } from "primereact/button";
import { Password } from "primereact/password";
import { classNames } from "primereact/utils";
import { TSigninFormState, TSignupFormState } from "@/lib/types";

const BaseForm = ({
children,
control,
errors,
}: {
children?: React.ReactNode;
control: Control<any>;
errors: FieldErrors<any>;
control: Control<TSignupFormState>;
errors: FieldErrors<TSigninFormState | TSignupFormState>;
}) => {
return (
<form className="p-fluid">
Expand Down
6 changes: 2 additions & 4 deletions src/app/auth/signin/components/signin-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import BaseForm from "../../components/base-form";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { InputText } from "primereact/inputtext";
import { TSignupFormState } from "@/lib/types";

const SigninForm = () => {
const [showMessage, setShowMessage] = useState(false);
Expand All @@ -11,15 +11,13 @@ const SigninForm = () => {
const defaultValues = {
email: "",
password: "",
confirm_password: "",
};

const {
control,
formState: { errors },
handleSubmit,
reset,
} = useForm({ defaultValues });
} = useForm<TSignupFormState>({ defaultValues });

return <BaseForm control={control} errors={errors} />;
};
Expand Down
9 changes: 2 additions & 7 deletions src/app/auth/signup/components/signup-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,22 @@ import BaseForm from "../../components/base-form";
import { useForm, Controller } from "react-hook-form";
import { classNames } from "primereact/utils";
import { Password } from "primereact/password";
import { TSignupFormState } from "@/lib/types";

const SignupForm = () => {
const [showMessage, setShowMessage] = useState(false);
const [formData, setFormData] = useState({});

const defaultValues = {
name: "",
email: "",
password: "",
confirm_password: "",
date: null,
country: null,
accept: false,
};

const {
control,
formState: { errors },
handleSubmit,
reset,
} = useForm({ defaultValues });
} = useForm<TSignupFormState>();
return (
<BaseForm control={control} errors={errors}>
<div className="field">
Expand Down
10 changes: 5 additions & 5 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { string, z } from "zod";
export const ZSignupFormState = z.object({
email: z.string().trim().min(1).email(),
password: z.string().min(4),
confirm_password: z.string(),
confirm_password: z.string().optional(),
});
export type TSignupFormState = z.infer<typeof ZSignupFormState>;

export const ZSigninFormState = ZSignupFormState.omit({
confirm_password: true,
});
export type TSigninFormState = z.infer<typeof ZSigninFormState>;
// export const ZSigninFormState = ZSignupFormState.omit({
// confirm_password: true,
// });
// export type TSigninFormState = z.infer<typeof ZSigninFormState>;

export type TBoard = {
id: string;
Expand Down

0 comments on commit 32e2029

Please sign in to comment.