schema adjustments
This commit is contained in:
parent
83de08ddd9
commit
8bd1a3f3e8
File diff suppressed because it is too large
Load Diff
|
|
@ -1,6 +1,6 @@
|
|||
import { useState } from "react";
|
||||
import { Calendar } from "@/components/ui/calendar";
|
||||
import { Class, insertBookingSchema } from "@shared/schema";
|
||||
import { Class, insertBookingSchema } from "@/lib/schema";
|
||||
import { apiRequest, queryClient } from "@/lib/queryClient";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Class } from "@shared/schema";
|
||||
import { Class } from "@/lib/schema";
|
||||
import { Link } from "wouter";
|
||||
import FadiaGardenImage from "@assets/fadia-garden_1749836720986.jpg";
|
||||
import PilatesClassImage from "@assets/pilates_class_1749837680834.jpeg";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { ClassCard } from "./class-card";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Class } from "@shared/schema";
|
||||
import { Class } from "@/lib/schema";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import FadiaClassImage from "../../assets/Fadia-156.jpg";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useState } from "react";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { apiRequest } from "@/lib/queryClient";
|
||||
import { insertNewsletterSchema } from "@shared/schema";
|
||||
import { insertNewsletterSchema } from "@/lib/schema";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { Loader2 } from "lucide-react";
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,11 @@ import {
|
|||
useMutation,
|
||||
UseMutationResult,
|
||||
} from "@tanstack/react-query";
|
||||
import { insertUserSchema, User as SelectUser, InsertUser, Login } from "@shared/schema";
|
||||
import { getQueryFn, apiRequest, queryClient } from "../lib/queryClient";
|
||||
import { apiRequest, getQueryFn, queryClient } from "@/lib/queryClient";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { z } from "zod";
|
||||
|
||||
type User = Omit<SelectUser, "password">;
|
||||
import { insertUserSchema, User, InsertUser, Login } from "@/lib/schema";
|
||||
import { Loader2 } from "lucide-react";
|
||||
|
||||
type AuthContextType = {
|
||||
user: User | null;
|
||||
|
|
@ -52,7 +51,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||
queryClient.setQueryData(["/api/user"], user);
|
||||
toast({
|
||||
title: "Login successful",
|
||||
description: `Welcome back, ${user.fullName || user.username}!`,
|
||||
description: `Welcome back, ${user.name}!`,
|
||||
});
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,75 @@
|
|||
import { z } from "zod";
|
||||
|
||||
// User schemas
|
||||
export const insertUserSchema = z.object({
|
||||
email: z.string().email(),
|
||||
password: z.string().min(8),
|
||||
name: z.string().min(2).max(100),
|
||||
role: z.enum(["user", "admin"]).default("user"),
|
||||
});
|
||||
|
||||
export type InsertUser = z.infer<typeof insertUserSchema>;
|
||||
|
||||
export const userSchema = insertUserSchema.extend({
|
||||
id: z.number(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
});
|
||||
|
||||
export type User = z.infer<typeof userSchema>;
|
||||
|
||||
// Login schema
|
||||
export const loginSchema = z.object({
|
||||
email: z.string().email(),
|
||||
password: z.string(),
|
||||
});
|
||||
|
||||
export type Login = z.infer<typeof loginSchema>;
|
||||
|
||||
// Class schemas
|
||||
export const classSchema = z.object({
|
||||
id: z.number(),
|
||||
name: z.string(),
|
||||
description: z.string(),
|
||||
duration: z.number(),
|
||||
price: z.number(),
|
||||
maxCapacity: z.number(),
|
||||
instructor: z.string(),
|
||||
category: z.string(),
|
||||
level: z.enum(["beginner", "intermediate", "advanced"]),
|
||||
classType: z.enum(["group", "small-group", "private", "online"]),
|
||||
imageUrl: z.string().optional(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
});
|
||||
|
||||
export type Class = z.infer<typeof classSchema>;
|
||||
|
||||
// Booking schemas
|
||||
export const insertBookingSchema = z.object({
|
||||
classId: z.number(),
|
||||
userId: z.number(),
|
||||
date: z.string(),
|
||||
paid: z.boolean().default(false),
|
||||
status: z.enum(["pending", "confirmed", "cancelled"]).default("pending"),
|
||||
});
|
||||
|
||||
export type InsertBooking = z.infer<typeof insertBookingSchema>;
|
||||
|
||||
// Newsletter schemas
|
||||
export const insertNewsletterSchema = z.object({
|
||||
email: z.string().email(),
|
||||
agreedToTerms: z.boolean(),
|
||||
});
|
||||
|
||||
export type InsertNewsletter = z.infer<typeof insertNewsletterSchema>;
|
||||
|
||||
// Contact message schemas
|
||||
export const insertContactMessageSchema = z.object({
|
||||
name: z.string().min(2).max(100),
|
||||
email: z.string().email(),
|
||||
subject: z.string().min(2).max(200).optional(),
|
||||
message: z.string().min(10).max(2000),
|
||||
});
|
||||
|
||||
export type InsertContactMessage = z.infer<typeof insertContactMessageSchema>;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from "zod";
|
||||
import { insertUserSchema, insertContactMessageSchema, insertNewsletterSchema } from "@shared/schema";
|
||||
import { insertUserSchema, insertContactMessageSchema, insertNewsletterSchema } from "@/lib/schema";
|
||||
|
||||
/**
|
||||
* Extended registration schema with password confirmation
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { useForm } from "react-hook-form";
|
|||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useAuth, registrationSchema, RegistrationData } from "@/hooks/use-auth";
|
||||
import { useLocation } from "wouter";
|
||||
import { loginSchema, Login } from "@shared/schema";
|
||||
import { loginSchema, Login } from "@/lib/schema";
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
|
|
@ -44,7 +44,7 @@ export default function AuthPage() {
|
|||
const loginForm = useForm<Login>({
|
||||
resolver: zodResolver(loginSchema),
|
||||
defaultValues: {
|
||||
username: "",
|
||||
email: "",
|
||||
password: "",
|
||||
},
|
||||
});
|
||||
|
|
@ -53,9 +53,8 @@ export default function AuthPage() {
|
|||
const registerForm = useForm<RegistrationData>({
|
||||
resolver: zodResolver(registrationSchema),
|
||||
defaultValues: {
|
||||
username: "",
|
||||
email: "",
|
||||
fullName: "",
|
||||
name: "",
|
||||
password: "",
|
||||
confirmPassword: "",
|
||||
},
|
||||
|
|
@ -104,12 +103,12 @@ export default function AuthPage() {
|
|||
<form onSubmit={loginForm.handleSubmit(onLoginSubmit)} className="space-y-6">
|
||||
<FormField
|
||||
control={loginForm.control}
|
||||
name="username"
|
||||
name="email"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Username</FormLabel>
|
||||
<FormLabel>Email</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Enter your username" {...field} />
|
||||
<Input placeholder="Enter your email" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -164,19 +163,6 @@ export default function AuthPage() {
|
|||
<CardContent>
|
||||
<Form {...registerForm}>
|
||||
<form onSubmit={registerForm.handleSubmit(onRegisterSubmit)} className="space-y-6">
|
||||
<FormField
|
||||
control={registerForm.control}
|
||||
name="username"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Username</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Choose a username" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={registerForm.control}
|
||||
name="email"
|
||||
|
|
@ -192,12 +178,12 @@ export default function AuthPage() {
|
|||
/>
|
||||
<FormField
|
||||
control={registerForm.control}
|
||||
name="fullName"
|
||||
name="name"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Full Name</FormLabel>
|
||||
<FormLabel>Name</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Enter your full name" {...field} value={typeof field.value === 'string' ? field.value : ''} />
|
||||
<Input placeholder="Enter your name" {...field} value={typeof field.value === 'string' ? field.value : ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue