feat(users): add admin user management and bootstrap seed
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const userRoleSchema = z.enum(["ADMIN", "MANAGER", "STAFF", "VIEWER"])
|
||||
|
||||
const passwordSchema = z
|
||||
.string()
|
||||
.min(8, { error: "Password must be at least 8 characters" })
|
||||
|
||||
export const createUserSchema = z.object({
|
||||
username: z.string().trim().min(1, { error: "Username is required" }),
|
||||
name: z.string().trim().min(1, { error: "Name is required" }),
|
||||
email: z.email({ error: "Invalid email" }),
|
||||
password: passwordSchema,
|
||||
role: userRoleSchema,
|
||||
isActive: z.boolean(),
|
||||
})
|
||||
|
||||
export const updateUserSchema = z.object({
|
||||
id: z.string().min(1, { error: "User id is required" }),
|
||||
username: z.string().trim().min(1, { error: "Username is required" }),
|
||||
name: z.string().trim().min(1, { error: "Name is required" }),
|
||||
email: z.email({ error: "Invalid email" }),
|
||||
role: userRoleSchema,
|
||||
isActive: z.boolean(),
|
||||
})
|
||||
|
||||
export const setUserActiveSchema = z.object({
|
||||
id: z.string().min(1, { error: "User id is required" }),
|
||||
isActive: z.boolean(),
|
||||
})
|
||||
|
||||
export const resetUserPasswordSchema = z.object({
|
||||
id: z.string().min(1, { error: "User id is required" }),
|
||||
password: passwordSchema,
|
||||
})
|
||||
|
||||
export type CreateUserFormType = z.infer<typeof createUserSchema>
|
||||
export type UpdateUserFormType = z.infer<typeof updateUserSchema>
|
||||
export type SetUserActiveFormType = z.infer<typeof setUserActiveSchema>
|
||||
export type ResetUserPasswordFormType = z.infer<typeof resetUserPasswordSchema>
|
||||
Reference in New Issue
Block a user