gitscope
← marzneshin / v0.1.4 / app/dashboard/src/pages/users/dialog/form-schema.ts
https://dev.kronoz.win/r/marzneshin.git
app/dashboard/src/pages/users/dialog/form-schema.ts · TypeScript
Blame Raw
 1
 2import { z } from 'zod';
 3import { UserCreate } from 'types';
 4
 5export type FormType = Pick<UserCreate, keyof UserCreate>;
 6export const schema = z.object({
 7  username: z.string().min(1, { message: 'Username is required' }),
 8  note: z.string().nullable(),
 9  data_limit: z
10    .string()
11    .min(0, 'The minimum number is 0')
12    .or(z.number())
13    .nullable()
14    .transform((str) => {
15      if (str) return Number((parseFloat(String(str)) * 1073741824).toFixed(5));
16      return 0;
17    }),
18  expire: z.number().nullable(),
19  data_limit_reset_strategy: z.string(),
20  status: z.string(),
21  services: z.array(z.number()).nonempty({ message: 'At least one service is required' }),
22});