Skip to content

Commit

Permalink
Merge pull request #80 from TEDx-SJEC/bug_fix
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
gdsc-sjec-github authored Nov 25, 2024
2 parents 9ce58c3 + 115df60 commit c2358eb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
8 changes: 4 additions & 4 deletions src/components/common/registration-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function RegistrationForm() {
resolver: zodResolver(baseSchema),
defaultValues: {
designation: getSjecMemberType(session?.user.email!),
name: session?.user.name!,
name:session?.user.name!,
email: session?.user.email!,
phone: "",
entityName: "",
Expand Down Expand Up @@ -249,7 +249,7 @@ export default function RegistrationForm() {
const handleNext = async () => {
let isValid = false;
if (step === 1) {
isValid = await form.trigger(["designation", "foodPreference"]);
isValid = await form.trigger(["designation", "foodPreference","name"]);
} else if (step === 2) {
const designation = form.getValues("designation");
if (designation === "student") {
Expand Down Expand Up @@ -314,9 +314,9 @@ export default function RegistrationForm() {
<Input
placeholder="John Doe"
{...field}
value={session?.user.name!}
disabled
autoFocus
/>

</FormControl>
<FormMessage />
</FormItem>
Expand Down
68 changes: 33 additions & 35 deletions src/utils/zod-schemas.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,52 @@
import { z } from "zod";

export const RegistrationFormSchema = z.object({
name: z.string().min(1, "Name is required"),
usn: z.string().optional(),
email: z.string().email("Invalid email format"),
contact: z.string().length(10, "Contact must be exactly 10 digits"),
designation: z
.string()
.refine((value) => ["Student", "Faculty", "Employee"].includes(value), {
message: "Invalid designation",
name: z.string().min(1, "Name is required"),
usn: z.string().optional(),
email: z.string().email("Invalid email format"),
contact: z.string().length(10, "Contact must be exactly 10 digits"),
designation: z.string().refine((value) => ["Student", "Faculty", "Employee"].includes(value), {
message: "Invalid designation",
}),
photo: z.string().optional(),
collegeIdCard: z.string().optional(),
entityName: z.string().min(1, "Entity name is required"),
referralUsed: z.string().optional(),
createdById: z.string(),
photo: z.string().optional(),
collegeIdCard: z.string().optional(),
entityName: z.string().min(1, "Entity name is required"),
referralUsed: z.string().optional(),
createdById: z.string(),
});

export type TRegistrationForm = z.infer<typeof RegistrationFormSchema>;

export const emailSchema = z.object({
email: z.string().email(),
name: z.string().min(1),
email: z.string().email(),
name: z.string().min(1),
});

export const baseSchema = z.object({
designation: z.enum(["student", "faculty", "external"]),
name: z.string().min(2, { message: "Name must be at least 2 characters." }),
email: z.string().email({ message: "Invalid email address." }),
phone: z
.string()
.regex(/^\d{10}$/, { message: "Phone number must be 10 digits." }),
photo: z.string(),
entityName: z.string().optional(),
couponCode: z.string().optional(),
foodPreference: z.enum(["veg", "non-veg"]),
designation: z.enum(["student", "faculty", "external"]),
name: z.string().min(2, { message: "Name must be at least 2 characters." }),
email: z.string().email({ message: "Invalid email address." }),
phone: z.string().regex(/^\d{10}$/, { message: "Phone number must be 10 digits." }),
photo: z.string(),
entityName: z.string().optional(),
couponCode: z.string().optional(),
foodPreference: z.enum(["veg", "non-veg"]),
});

export const studentSchema = baseSchema.extend({
usn: z.string().min(1, { message: "USN is required for students." }),
idCard: z.string().min(1, { message: "ID Card is required for students." }),
usn: z.string().min(1, { message: "USN is required for students." }),
idCard: z.string().min(1, { message: "ID Card is required for students." }),
});

export const studentFormSchema = z.object({
name: z.string().min(2, { message: "Name must be at least 2 characters." }),
email: z.string().email({ message: "Invalid email address." }),
phone: z
.string()
.regex(/^\d{10}$/, { message: "Phone number must be 10 digits." }),
usn: z.string().min(1, { message: "USN is required for students." }),
idCard: z.string().min(1, { message: "ID Card is required for students." }),
photo: z.string().min(1, { message: "Photo is required." }),
name: z.string().min(2, { message: "Name must be at least 2 characters." }),
email: z.string().email({ message: "Invalid email address." }),
phone: z.string().regex(/^\d{10}$/, { message: "Phone number must be 10 digits." }),
usn: z
.string()
.min(10, { message: "USN is required for students." })
.max(10, { message: "USN must be exactly 10 characters long." })
.regex(/^[A-Z0-9]+$/, { message: "USN must be in uppercase." }),
idCard: z.string().min(1, { message: "ID Card is required for students." }),
photo: z.string().min(1, { message: "Photo is required." }),
});

0 comments on commit c2358eb

Please sign in to comment.