Ease restrictions on URL inputs (#124)

This commit is contained in:
Quang Lam 2020-02-02 01:09:27 -06:00 committed by GitHub
parent cbd7179348
commit 23db4d0f4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 4 deletions

View file

@ -15,6 +15,13 @@ const kits = {
}
return null;
},
// accept link without protocol prefix
lessStrictUrl: (val, _, fieldName) => {
if (!isUrl(val) && !isUrl(`http://${val}`)) {
return '{fieldName} is not valid.'.replace('{fieldName}', fieldName);
}
return null;
},
licenseKey: (val, ruleVal, fieldName) => {
if (!isValidLicenseKey(val)) {
return '{fieldName} is not valid.'.replace('{fieldName}', fieldName);

View file

@ -13,6 +13,7 @@ import {
} from '../../constants/actions';
import validate from '../../helpers/validate';
import isUrl from '../../helpers/is-url';
import hasErrors from '../../helpers/has-errors';
import { requestCreateWorkspace } from '../../senders';
@ -182,9 +183,12 @@ export const save = () => (dispatch, getState) => {
return dispatch(updateForm(validatedChanges));
}
const url = form.homeUrl.trim();
const homeUrl = isUrl(url) ? url : `http://${url}`;
requestCreateWorkspace(
form.name,
form.homeUrl.trim(),
homeUrl,
form.internetIcon || form.picturePath,
Boolean(form.transparentBackground),
);

View file

@ -4,8 +4,9 @@ import {
UPDATE_EDIT_WORKSPACE_FORM,
} from '../../constants/actions';
import validate from '../../helpers/validate';
import hasErrors from '../../helpers/has-errors';
import isUrl from '../../helpers/is-url';
import validate from '../../helpers/validate';
import {
requestSetWorkspace,
@ -23,7 +24,7 @@ const getValidationRules = () => ({
homeUrl: {
fieldName: 'Home URL',
required: true,
url: true,
lessStrictUrl: true,
},
});
@ -93,12 +94,14 @@ export const save = () => (dispatch, getState) => {
}
const id = remote.getGlobal('editWorkspaceId');
const url = form.homeUrl.trim();
const homeUrl = isUrl(url) ? url : `http://${url}`;
requestSetWorkspace(
id,
{
name: form.name,
homeUrl: form.homeUrl.trim(),
homeUrl,
// prefs
disableAudio: Boolean(form.disableAudio),
disableNotifications: Boolean(form.disableNotifications),