/
yup.ts
68 lines (63 loc) 路 2.38 KB
/
yup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as yup from 'yup';
import { LatLong, StepOneData, StepThreeData, StepTwoData } from '@/types';
export const stepOneSchema: yup.SchemaOf<StepOneData> = yup.object().shape({
name: yup.string().required('Name is required'),
email: yup
.string()
.email('Need to be a valid email')
.required('Email is required'),
password: yup
.string()
.required('Password is required')
.min(8, 'Password must be at least 8 characters long'),
age: yup
.number()
.typeError('Must be a number')
.positive('Must be a positive value')
.integer('Must be a number')
.required('Age is required'),
phone: yup
.string()
.matches(/^\+628[1-9][0-9]{8,11}$/, 'Must use +62 format')
.required('Phone is required'),
});
// @ts-ignore - file type still not found
// TODO Should be ArraySchema<ObjectSchemaOf<FileWithPreview> | Lazy<ObjectSchemaOf<FileWithPreview>, any>, AnyObject
export const stepTwoSchema: yup.SchemaOf<StepTwoData> = yup.object().shape({
score_1: yup
.number()
.typeError('Must be a number')
.positive('Must be a positive value')
.lessThan(101, 'Max score is 100')
.required('Age is required'),
score_2: yup
.number()
.typeError('Must be a number')
.positive('Must be a positive value')
.lessThan(101, 'Max score is 100')
.required('Age is required'),
score_3: yup
.number()
.typeError('Must be a number')
.positive('Must be a positive value')
.lessThan(101, 'Max score is 100')
.required('Age is required'),
identity_card: yup.mixed().required('File is required'),
score_file: yup.mixed().required('File is required'),
});
// @ts-ignore - override correct yup type
// https://github.com/jquense/yup/issues/1183
export const requiredDateSchema: yup.SchemaOf<Date> = yup
.date()
.required('Birth date is required');
export const stepThreeSchema: yup.SchemaOf<StepThreeData> = yup.object().shape({
// yup date
birth_date: requiredDateSchema,
gender: yup.string().required('Gender is required'),
lat: yup.number().typeError('Must be a number').required('Lat is required'),
lng: yup.number().typeError('Must be a number').required('Long is required'),
});
export const mapSchema: yup.SchemaOf<LatLong> = yup.object().shape({
lat: yup.number().typeError('Must be a number').required('Lat is required'),
lng: yup.number().typeError('Must be a number').required('Long is required'),
});