({
+ mode: 'onChange',
+ defaultValues: {
+ host: initialValues?.host || '',
+ clientId: initialValues?.clientId || '',
+ protocol: initialValues?.protocol || MOBILE_CONFIG_LINKS.DOT,
+ port: initialValues?.port || undefined,
+ },
+ });
- const { host, clientId, protocol, port } = formValues;
-
- const githubLink = (
-
- text
-
- );
+ const protocol = watch('protocol');
+ const host = watch('host');
+ const clientId = watch('clientId');
+ const port = watch('port');
const getHostName = () => {
if (port && port !== STANDARD_HTTPS_PORT && protocol === MOBILE_CONFIG_LINKS.DOH) {
@@ -79,14 +95,20 @@ const MobileConfigForm = ({ invalid }: MobileConfigFormProps) => {
{i18next.t('dhcp_table_hostname')}
-
+ {errors.host && (
+
+ {errors.host.message}
+
+ )}
{protocol === MOBILE_CONFIG_LINKS.DOH && (
@@ -94,15 +116,25 @@ const MobileConfigForm = ({ invalid }: MobileConfigFormProps) => {
{i18next.t('encryption_https')}
-
toNumber(val),
+ validate: {
+ range: (value) => validatePort(value) || true,
+ safety: (value) => validateIsSafePort(value) || true,
+ },
+ })}
/>
+
+ {errors.port && (
+
+ {errors.port.message}
+
+ )}
)}
@@ -117,14 +149,21 @@ const MobileConfigForm = ({ invalid }: MobileConfigFormProps) => {
client_id_desc
-
+
+ {errors.clientId && (
+
+ {errors.clientId.message}
+
+ )}
@@ -132,17 +171,18 @@ const MobileConfigForm = ({ invalid }: MobileConfigFormProps) => {
{i18next.t('protocol')}
-
+
+
- {getDownloadLink(getHostName(), clientId, protocol, invalid)}
+ {getDownloadLink(getHostName(), clientId, protocol, !isValid)}
);
};
-
-export default reduxForm({ form: FORM_NAME.MOBILE_CONFIG })(MobileConfigForm);
diff --git a/client/src/helpers/validators.ts b/client/src/helpers/validators.ts
index 87d441ee..3815339a 100644
--- a/client/src/helpers/validators.ts
+++ b/client/src/helpers/validators.ts
@@ -180,7 +180,7 @@ export const validateConfigClientId = (value: any) => {
}
const formattedValue = value.trim();
if (formattedValue && !R_CLIENT_ID.test(formattedValue)) {
- return 'form_error_client_id_format';
+ return i18next.t('form_error_client_id_format');
}
return undefined;
};
@@ -195,7 +195,7 @@ export const validateServerName = (value: any) => {
}
const formattedValue = value ? value.trim() : value;
if (formattedValue && !R_DOMAIN.test(formattedValue)) {
- return 'form_error_server_name';
+ return i18next.t('form_error_server_name');
}
return undefined;
};
@@ -239,7 +239,7 @@ export const validateMac = (value: any) => {
*/
export const validatePort = (value: any) => {
if ((value || value === 0) && (value < STANDARD_WEB_PORT || value > MAX_PORT)) {
- return 'form_error_port_range';
+ return i18next.t('form_error_port_range');
}
return undefined;
};
@@ -281,7 +281,7 @@ export const validatePortQuic = validatePortTLS;
*/
export const validateIsSafePort = (value: any) => {
if (UNSAFE_PORTS.includes(value)) {
- return 'form_error_port_unsafe';
+ return i18next.t('form_error_port_unsafe');
}
return undefined;
};