Skip to content

Commit 1d76530

Browse files
committed
Make About functional
1 parent 0cdf1dc commit 1d76530

File tree

10 files changed

+352
-80
lines changed

10 files changed

+352
-80
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ yarn-error.log*
2626
.pnpm-debug.log*
2727

2828
# local env files
29-
.env*.local
29+
.env
30+
.env.local
3031

3132
# vercel
3233
.vercel

example.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEXT_PUBLIC_BACKEND_URL=https://backend.commitrocket.com

package-lock.json

+83-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
},
1010
"dependencies": {
1111
"@heroicons/react": "^2.0.16",
12+
"@hookform/error-message": "^2.0.1",
13+
"@hookform/resolvers": "^2.9.11",
1214
"@types/node": "18.15.0",
1315
"@types/react": "18.0.28",
1416
"@types/react-dom": "18.0.11",
@@ -17,8 +19,11 @@
1719
"next": "13.2.4",
1820
"react": "18.2.0",
1921
"react-dom": "18.2.0",
22+
"react-hook-form": "^7.43.5",
2023
"tailwind-merge": "^1.10.0",
21-
"typescript": "4.9.5"
24+
"typescript": "4.9.5",
25+
"wretch": "^2.5.1",
26+
"zod": "^3.21.4"
2227
},
2328
"devDependencies": {
2429
"autoprefixer": "^10.4.14",

src/api/models/Response.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { z } from "zod";
2+
3+
export const backendResponseSchema = z.object({
4+
success: z.boolean(),
5+
message: z.string()
6+
});
7+
8+
export type BackendResponse = z.infer<typeof backendResponseSchema>;

src/components/controls/Button.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HTMLAttributes, useMemo } from "react";;
1+
import { ButtonHTMLAttributes, DetailedHTMLProps, HTMLAttributes, useMemo } from "react";;
22
import { cva, VariantProps as GetVariantProps } from "class-variance-authority";
33
import { twMerge } from "tailwind-merge";
44

@@ -17,7 +17,7 @@ export type VariantProps = GetVariantProps<typeof style>;
1717
type ButtonProps = {
1818

1919
} & RequiredKeys<VariantProps, "color">
20-
& HTMLAttributes<HTMLButtonElement>;
20+
& DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
2121

2222
const Button = ({ className, color, ...props }: ButtonProps) => {
2323

src/components/controls/Error.tsx

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { ErrorMessage } from "@hookform/error-message";
2+
import { FieldValuesFromFieldErrors } from "@hookform/error-message/dist/types";
3+
import React from "react";
4+
import { FieldErrors, FieldName, UseFormReturn } from "react-hook-form";
5+
import { twMerge } from "tailwind-merge";
6+
7+
interface ErrorProps<Name extends string, FieldValues extends Record<Name, any>> {
8+
className?: string;
9+
state: UseFormReturn<FieldValues, any>["formState"];
10+
name: Name;
11+
}
12+
13+
const Error = <Name extends string, FieldValues extends Record<Name, any>>({ className, state, name }: ErrorProps<Name, FieldValues>) => {
14+
const errors = state.errors;
15+
16+
return (
17+
<ErrorMessage
18+
errors={errors}
19+
name={name as unknown as FieldName<FieldValuesFromFieldErrors<FieldErrors<FieldValues>>>}
20+
render={({ message }) => (
21+
<p role="alert" className={twMerge("text-red-600 font-semibold", className)}>
22+
{message}
23+
</p>
24+
)}
25+
/>
26+
);
27+
};
28+
29+
export default Error;

0 commit comments

Comments
 (0)