From 819582310a47c7d5f5109e57d7c180fd171a01e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Fri, 14 May 2021 16:09:07 +0200 Subject: [PATCH] lint fixes --- packages/builder/src/helpers/fetchData.js | 34 +++++++++---------- packages/builder/src/helpers/helpers.js | 2 -- packages/builder/src/helpers/index.js | 11 ++++-- .../builder/src/helpers/validation/index.js | 4 +-- .../src/helpers/validation/validation.js | 34 +++++++++---------- .../src/helpers/validation/validators.js | 21 ++++++++---- .../builder/src/stores/portal/organisation.js | 8 +++-- packages/builder/src/stores/portal/users.js | 22 ++++++++---- 8 files changed, 81 insertions(+), 55 deletions(-) diff --git a/packages/builder/src/helpers/fetchData.js b/packages/builder/src/helpers/fetchData.js index 0275230dc4..e34f13db81 100644 --- a/packages/builder/src/helpers/fetchData.js +++ b/packages/builder/src/helpers/fetchData.js @@ -1,20 +1,20 @@ -import { writable } from 'svelte/store' +import { writable } from "svelte/store" import api from "builderStore/api" export default function (url) { - const store = writable({status: 'LOADING', data: {}, error: {}}) - - async function get() { - store.update(u => ({...u, status: 'SUCCESS'})) - try { - const response = await api.get(url) - store.set({data: await response.json(), status: 'SUCCESS'}) - } catch(e) { - store.set({data: {}, error: e, status: 'ERROR'}) - } - } - - get() - - return {subscribe: store.subscribe, refresh: get} -} \ No newline at end of file + const store = writable({ status: "LOADING", data: {}, error: {} }) + + async function get() { + store.update(u => ({ ...u, status: "SUCCESS" })) + try { + const response = await api.get(url) + store.set({ data: await response.json(), status: "SUCCESS" }) + } catch (e) { + store.set({ data: {}, error: e, status: "ERROR" }) + } + } + + get() + + return { subscribe: store.subscribe, refresh: get } +} diff --git a/packages/builder/src/helpers/helpers.js b/packages/builder/src/helpers/helpers.js index 1fa2399840..89c7a0a6aa 100644 --- a/packages/builder/src/helpers/helpers.js +++ b/packages/builder/src/helpers/helpers.js @@ -22,5 +22,3 @@ export const capitalise = s => s.substring(0, 1).toUpperCase() + s.substring(1) export const get_name = s => (!s ? "" : last(s.split("/"))) export const get_capitalised_name = name => pipe(name, [get_name, capitalise]) - - diff --git a/packages/builder/src/helpers/index.js b/packages/builder/src/helpers/index.js index 8649e8c798..2c09cc19ca 100644 --- a/packages/builder/src/helpers/index.js +++ b/packages/builder/src/helpers/index.js @@ -1,2 +1,9 @@ -export { default as fetchData } from './fetchData' -export { buildStyle, convertCamel, pipe, capitalise, get_name, get_capitalised_name } from './helpers' \ No newline at end of file +export { default as fetchData } from "./fetchData" +export { + buildStyle, + convertCamel, + pipe, + capitalise, + get_name, + get_capitalised_name, +} from "./helpers" diff --git a/packages/builder/src/helpers/validation/index.js b/packages/builder/src/helpers/validation/index.js index 77363b89f5..5e9cfcca79 100644 --- a/packages/builder/src/helpers/validation/index.js +++ b/packages/builder/src/helpers/validation/index.js @@ -1,2 +1,2 @@ -export { emailValidator, requiredValidator } from './validators' -export { createValidationStore } from './validation' \ No newline at end of file +export { emailValidator, requiredValidator } from "./validators" +export { createValidationStore } from "./validation" diff --git a/packages/builder/src/helpers/validation/validation.js b/packages/builder/src/helpers/validation/validation.js index 9927d1129a..8d80d720a1 100644 --- a/packages/builder/src/helpers/validation/validation.js +++ b/packages/builder/src/helpers/validation/validation.js @@ -1,23 +1,23 @@ -import { writable, derived } from 'svelte/store' +import { writable, derived } from "svelte/store" export function createValidationStore(initialValue, ...validators) { - let touched = false - - const value = writable(initialValue || '') - const error = derived(value, $v => validate($v, validators)) - const touchedStore = derived(value, () => { - if (!touched) { - touched = true - return false - } - return touched - }) - - return [value, error, touchedStore] + let touched = false + + const value = writable(initialValue || "") + const error = derived(value, $v => validate($v, validators)) + const touchedStore = derived(value, () => { + if (!touched) { + touched = true + return false + } + return touched + }) + + return [value, error, touchedStore] } function validate(value, validators) { - const failing = validators.find(v => v(value) !== true) + const failing = validators.find(v => v(value) !== true) - return failing && failing(value) -} \ No newline at end of file + return failing && failing(value) +} diff --git a/packages/builder/src/helpers/validation/validators.js b/packages/builder/src/helpers/validation/validators.js index c2eaad82ff..036487fd50 100644 --- a/packages/builder/src/helpers/validation/validators.js +++ b/packages/builder/src/helpers/validation/validators.js @@ -1,7 +1,16 @@ -export function emailValidator (value) { - return (value && !!value.match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/)) || 'Please enter a valid email' - } +export function emailValidator(value) { + return ( + (value && + !!value.match( + /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ + )) || + "Please enter a valid email" + ) +} -export function requiredValidator (value) { - return (value !== undefined && value !== null && value !== '') || 'This field is required' - } \ No newline at end of file +export function requiredValidator(value) { + return ( + (value !== undefined && value !== null && value !== "") || + "This field is required" + ) +} diff --git a/packages/builder/src/stores/portal/organisation.js b/packages/builder/src/stores/portal/organisation.js index 250f9c09ff..97053897f9 100644 --- a/packages/builder/src/stores/portal/organisation.js +++ b/packages/builder/src/stores/portal/organisation.js @@ -19,12 +19,16 @@ export function createOrganisationStore() { if (json.status === 400) { set(FALLBACK_CONFIG) } else { - set({...json.config, _rev: json._rev}) + set({ ...json.config, _rev: json._rev }) } } async function save(config) { - const res = await api.post("/api/admin/configs", { type: "settings", config, _rev: get(store)._rev } ) + const res = await api.post("/api/admin/configs", { + type: "settings", + config, + _rev: get(store)._rev, + }) const json = await res.json() if (json.status) { return json diff --git a/packages/builder/src/stores/portal/users.js b/packages/builder/src/stores/portal/users.js index d3844b664c..4634373d63 100644 --- a/packages/builder/src/stores/portal/users.js +++ b/packages/builder/src/stores/portal/users.js @@ -12,23 +12,31 @@ export function createUsersStore() { } async function invite(email) { - const response = await api.post(`/api/admin/users/invite`, { email }) - return await response.json() + const response = await api.post(`/api/admin/users/invite`, { email }) + return await response.json() } async function acceptInvite(inviteCode, password) { - const response = await api.post("/api/admin/users/invite/accept", { inviteCode, password }) - return await response.json() + const response = await api.post("/api/admin/users/invite/accept", { + inviteCode, + password, + }) + return await response.json() } async function create({ email, password }) { - const response = await api.post("/api/admin/users", { email, password, builder: { global: true}, roles: {} }) + const response = await api.post("/api/admin/users", { + email, + password, + builder: { global: true }, + roles: {}, + }) init() return await response.json() } async function del(id) { const response = await api.delete(`/api/admin/users/${id}`) - update(users => (users.filter(user => user._id !== id))) + update(users => users.filter(user => user._id !== id)) return await response.json() } @@ -47,7 +55,7 @@ export function createUsersStore() { acceptInvite, create, updateRoles, - del + del, } }