mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-06 02:36:44 -05:00
adding userRegistrationForm and updating users table
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { getMuzzleDevices } from "@queries/PSA";
|
||||
import PageHero from "@components/PageHero";
|
||||
import styles from '../styles.module.css';
|
||||
|
||||
import SortTable from "@components/SortTable";
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { getStocks } from "@queries/PSA";
|
||||
import { psa } from '@schemas/schema';
|
||||
import partTypes from 'src/data/parts_cats.json';
|
||||
import styles from '../styles.module.css';
|
||||
import PageHero from "@components/PageHero";
|
||||
import ProductTable from "@components/ProductTable";
|
||||
import SortTable from "@components/SortTable";
|
||||
|
||||
export default async function StocksPage() {
|
||||
|
||||
4
src/app/UserRegister/page.tsx
Normal file
4
src/app/UserRegister/page.tsx
Normal file
@@ -0,0 +1,4 @@
|
||||
import RegistrationForm from "@components/RegistrationForm";
|
||||
export default function RegisterPage() {
|
||||
return <RegistrationForm />;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { db } from '../../../../db';
|
||||
import { users } from '../../../../drizzle/schema';
|
||||
import { db } from '@db/index';
|
||||
import { users } from '@schemas/schema';
|
||||
import bcrypt from 'bcryptjs';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
import React, { useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import PageHero from '../../components/PageHero';
|
||||
import PageHero from '@components/PageHero';
|
||||
import Link from 'next/link';
|
||||
|
||||
export default function RegisterPage() {
|
||||
|
||||
122
src/components/RegistrationForm/index.tsx
Normal file
122
src/components/RegistrationForm/index.tsx
Normal file
@@ -0,0 +1,122 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
|
||||
export default function RegistrationForm() {
|
||||
const router = useRouter()
|
||||
const [error, setError] = useState('')
|
||||
const [formData, setFormData] = useState({
|
||||
name: '',
|
||||
email: '',
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setError('')
|
||||
|
||||
if (formData.password !== formData.confirmPassword) {
|
||||
setError('Passwords do not match')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// Add your registration API call here
|
||||
console.log('Form submitted:', formData)
|
||||
router.push('/login') // Redirect to login after successful registration
|
||||
} catch (err) {
|
||||
setError('Failed to register user')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
|
||||
<div className="max-w-md w-full space-y-8">
|
||||
<div>
|
||||
<h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">
|
||||
Create your account
|
||||
</h2>
|
||||
</div>
|
||||
<form className="mt-8 space-y-6" onSubmit={handleSubmit}>
|
||||
<div className="rounded-md shadow-sm space-y-4">
|
||||
<div>
|
||||
<label htmlFor="name" className="sr-only">
|
||||
Full Name
|
||||
</label>
|
||||
<input
|
||||
id="name"
|
||||
name="name"
|
||||
type="text"
|
||||
required
|
||||
className="appearance-none rounded-md relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
|
||||
placeholder="Full Name"
|
||||
value={formData.name}
|
||||
onChange={(e) => setFormData({...formData, name: e.target.value})}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="email" className="sr-only">
|
||||
Email address
|
||||
</label>
|
||||
<input
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
required
|
||||
className="appearance-none rounded-md relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
|
||||
placeholder="Email address"
|
||||
value={formData.email}
|
||||
onChange={(e) => setFormData({...formData, email: e.target.value})}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="password" className="sr-only">
|
||||
Password
|
||||
</label>
|
||||
<input
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
required
|
||||
className="appearance-none rounded-md relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
|
||||
placeholder="Password"
|
||||
value={formData.password}
|
||||
onChange={(e) => setFormData({...formData, password: e.target.value})}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="confirmPassword" className="sr-only">
|
||||
Confirm Password
|
||||
</label>
|
||||
<input
|
||||
id="confirmPassword"
|
||||
name="confirmPassword"
|
||||
type="password"
|
||||
required
|
||||
className="appearance-none rounded-md relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
|
||||
placeholder="Confirm Password"
|
||||
value={formData.confirmPassword}
|
||||
onChange={(e) => setFormData({...formData, confirmPassword: e.target.value})}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="text-red-500 text-sm text-center">{error}</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<button
|
||||
type="submit"
|
||||
className="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
|
||||
>
|
||||
Register
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
// components/UserRegistration.js
|
||||
import { useState } from 'react';
|
||||
import { useToast } from '@chakra-ui/toast';
|
||||
import { FormControl, FormLabel, } from '@chakra-ui/form-control';
|
||||
import { Input, Button, Stack, Heading } from '@chakra-ui/react';
|
||||
import { drizzle } from 'drizzle-orm/node-postgres';
|
||||
import { users } from '@schemas/schema';
|
||||
|
||||
|
||||
export default function UserRegistration() {
|
||||
const [formData, setFormData] = useState({
|
||||
username: '',
|
||||
email: '',
|
||||
password: '',
|
||||
});
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
const handleChange = (e) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData({ ...formData, [name]: value });
|
||||
};
|
||||
|
||||
const handleSubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
// Example of database interaction using drizzle-orm:
|
||||
const db = drizzle(/* your database connection logic */);
|
||||
|
||||
try {
|
||||
// Replace 'users' with your actual table name
|
||||
await db.insert(users).values(formData);
|
||||
toast({
|
||||
title: 'Account created.',
|
||||
description: "We've created your account successfully!",
|
||||
status: 'success',
|
||||
duration: 5000,
|
||||
isClosable: true,
|
||||
});
|
||||
|
||||
// Reset the form
|
||||
setFormData({ username: '', email: '', password: '' });
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: 'An error occurred.',
|
||||
description: error.message,
|
||||
status: 'error',
|
||||
duration: 5000,
|
||||
isClosable: true,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Stack spacing={4} w="400px" mx="auto" mt={10}>
|
||||
<Heading as="h2" size="lg">User Registration</Heading>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<FormControl isRequired>
|
||||
<FormLabel>Username</FormLabel>
|
||||
<Input
|
||||
name="username"
|
||||
value={formData.username}
|
||||
onChange={handleChange}
|
||||
placeholder="Enter your username"
|
||||
/>
|
||||
</FormControl>
|
||||
|
||||
<FormControl isRequired>
|
||||
<FormLabel>Email</FormLabel>
|
||||
<Input
|
||||
type="email"
|
||||
name="email"
|
||||
value={formData.email}
|
||||
onChange={handleChange}
|
||||
placeholder="Enter your email"
|
||||
/>
|
||||
</FormControl>
|
||||
|
||||
<FormControl isRequired>
|
||||
<FormLabel>Password</FormLabel>
|
||||
<Input
|
||||
type="password"
|
||||
name="password"
|
||||
value={formData.password}
|
||||
onChange={handleChange}
|
||||
placeholder="Enter your password"
|
||||
/>
|
||||
</FormControl>
|
||||
|
||||
<Button
|
||||
mt={4}
|
||||
colorScheme="teal"
|
||||
type="submit">
|
||||
Create Account
|
||||
</Button>
|
||||
</form>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
@@ -23,6 +23,7 @@ export const users = pgTable("users", {
|
||||
name: text("name"),
|
||||
email: text("email").unique(),
|
||||
emailVerified: timestamp("emailVerified", { mode: "date" }),
|
||||
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
||||
image: text("image"),
|
||||
})
|
||||
|
||||
@@ -30,6 +31,7 @@ export const userskeep = pgTable("users-keep", {
|
||||
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
|
||||
username: varchar({ length: 50 }).notNull(),
|
||||
email: varchar({ length: 255 }).notNull(),
|
||||
|
||||
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
||||
firstName: varchar("first_name", { length: 50 }),
|
||||
lastName: varchar("last_name", { length: 50 }),
|
||||
@@ -50,6 +52,33 @@ export const userskeep = pgTable("users-keep", {
|
||||
usersBuildPrivacySettingCheck: check("users_build_privacy_setting_check", sql`build_privacy_setting = ANY (ARRAY['private'::text, 'public'::text])`),
|
||||
}
|
||||
});
|
||||
export const usersMerged = pgTable("users-merged", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
username: varchar({ length: 50 }).notNull(),
|
||||
email: varchar({ length: 255 }).notNull(),
|
||||
emailVerifiedOn: timestamp("emailVerified", { mode: "date" }),
|
||||
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
||||
firstName: varchar("first_name", { length: 50 }),
|
||||
lastName: varchar("last_name", { length: 50 }),
|
||||
profilePicture: varchar("profile_picture", { length: 255 }),
|
||||
dateOfBirth: date("date_of_birth"),
|
||||
phoneNumber: varchar("phone_number", { length: 20 }),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
isAdmin: boolean("is_admin").default(false),
|
||||
lastLogin: timestamp("last_login", { mode: 'string' }),
|
||||
emailVerified: boolean("email_verified").default(false),
|
||||
buildPrivacySetting: text("build_privacy_setting").default('public'),
|
||||
uuid: uuid().defaultRandom(),
|
||||
}, (table) => {
|
||||
return {
|
||||
usersUsernameKey: unique("users-merged_username_key").on(table.username),
|
||||
usersEmailKey: unique("users-merged_email_key").on(table.email),
|
||||
usersBuildPrivacySettingCheck: check("users-merged_build_privacy_setting_check", sql`build_privacy_setting = ANY (ARRAY['private'::text, 'public'::text])`),
|
||||
}
|
||||
});
|
||||
|
||||
export const categories = pgTable("categories", {
|
||||
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "categories_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||
|
||||
Reference in New Issue
Block a user