-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathproxies-validation-schema.ts
73 lines (72 loc) · 2.36 KB
/
proxies-validation-schema.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
69
70
71
72
73
import { useTranslation } from "react-i18next";
import * as yup from "yup";
import { ProxyFormValues } from "./proxy-form";
export const useProxyFormValidationSchema =
(): yup.SchemaOf<ProxyFormValues> => {
const { t } = useTranslation();
return yup.object().shape({
// http
isHttpProxyEnabled: yup.boolean().defined(),
httpHost: yup
.string()
.defined()
.when("isHttpProxyEnabled", (isHttpProxyEnabled, schema) =>
isHttpProxyEnabled
? schema
.required(t("validation.required"))
.min(3, t("validation.minLength", { length: 3 }))
.max(120, t("validation.maxLength", { length: 120 }))
: schema
),
httpPort: yup
.string()
.defined()
.when("isHttpProxyEnabled", (isHttpProxyEnabled, schema) =>
isHttpProxyEnabled
? schema.required(t("validation.required"))
: schema
),
isHttpIdentityRequired: yup.boolean().defined(),
httpIdentity: yup
.string()
.defined()
.nullable()
.when("isHttpIdentityRequired", (isHttpIdentityRequired, schema) =>
isHttpIdentityRequired
? schema.required(t("validation.required"))
: schema
),
// https
isHttpsProxyEnabled: yup.boolean().defined(),
httpsHost: yup
.string()
.defined()
.when("isHttpsProxyEnabled", (isHttpsProxyEnabled, schema) =>
isHttpsProxyEnabled
? schema
.required(t("validation.required"))
.min(3, t("validation.minLength", { length: 3 }))
.max(120, t("validation.maxLength", { length: 120 }))
: schema
),
httpsPort: yup
.string()
.defined()
.when("isHttpsProxyEnabled", (isHttpsProxyEnabled, schema) =>
isHttpsProxyEnabled
? schema.required(t("validation.required"))
: schema
),
isHttpsIdentityRequired: yup.boolean().defined(),
httpsIdentity: yup
.string()
.defined()
.nullable()
.when("isHttpsIdentityRequired", (isHttpsIdentityRequired, schema) =>
isHttpsIdentityRequired
? schema.required(t("validation.required"))
: schema
),
excluded: yup.string().defined(),
});
};