diff --git a/src/client/actions/settings.actions.tsx b/src/client/actions/settings.actions.tsx index 194506f..6b1200d 100644 --- a/src/client/actions/settings.actions.tsx +++ b/src/client/actions/settings.actions.tsx @@ -16,7 +16,6 @@ export const saveSettings = method: "POST", data: { settingsPayload, settingsObjectId }, }); - console.log(result.data); dispatch({ type: SETTINGS_OBJECT_FETCHED, data: result.data, diff --git a/src/client/components/AirDCPPSettings/AirDCPPSettingsForm.tsx b/src/client/components/AirDCPPSettings/AirDCPPSettingsForm.tsx index c0e3734..b2aea7e 100644 --- a/src/client/components/AirDCPPSettings/AirDCPPSettingsForm.tsx +++ b/src/client/components/AirDCPPSettings/AirDCPPSettingsForm.tsx @@ -4,11 +4,25 @@ import { useDispatch } from "react-redux"; import { saveSettings, deleteSettings } from "../../actions/settings.actions"; import { AirDCPPSettingsConfirmation } from "./AirDCPPSettingsConfirmation"; import { AirDCPPSocketContext } from "../../context/AirDCPPSocket"; -import { isUndefined, isEmpty } from "lodash"; +import { isUndefined, isEmpty, isNil } from "lodash"; export const AirDCPPSettingsForm = (): ReactElement => { const dispatch = useDispatch(); const airDCPPSettings = useContext(AirDCPPSocketContext); + + const hostValidator = (hostname: string): string | null => { + const hostnameRegex = /[\W]+/gm; + try { + if (!isUndefined(hostname)) { + const matches = hostname.match(hostnameRegex); + return (isNil(matches) && matches.length !== 0) ? hostname : "Invalid hostname; it should not contain special characters"; + } + } + catch { + return null; + } + + } const onSubmit = useCallback(async (values) => { try { airDCPPSettings.setSettings(values); @@ -52,14 +66,18 @@ export const AirDCPPSettingsForm = (): ReactElement => {

-

+

-

+ validate={hostValidator}> + {({ input, meta }) => ( +
+ + {meta.error && meta.touched && {meta.error}} +
+ )} +
+

{ } = configuration; const initializedAirDCPPSocket = new AirDCPPSocket({ protocol: `${host.protocol}`, - hostname: `${host.hostname}`, + hostname: `${host.hostname}:${host.port}`, }); const socketConnectionInformation = await initializedAirDCPPSocket.connect(