lint fixes

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-14 16:09:07 +02:00
parent 7a4b6850a8
commit 47bc197b45
8 changed files with 81 additions and 55 deletions

View File

@ -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: {}})
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'})
}
}
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()
get()
return {subscribe: store.subscribe, refresh: get}
return { subscribe: store.subscribe, refresh: get }
}

View File

@ -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])

View File

@ -1,2 +1,9 @@
export { default as fetchData } from './fetchData'
export { buildStyle, convertCamel, pipe, capitalise, get_name, get_capitalised_name } from './helpers'
export { default as fetchData } from "./fetchData"
export {
buildStyle,
convertCamel,
pipe,
capitalise,
get_name,
get_capitalised_name,
} from "./helpers"

View File

@ -1,2 +1,2 @@
export { emailValidator, requiredValidator } from './validators'
export { createValidationStore } from './validation'
export { emailValidator, requiredValidator } from "./validators"
export { createValidationStore } from "./validation"

View File

@ -1,23 +1,23 @@
import { writable, derived } from 'svelte/store'
import { writable, derived } from "svelte/store"
export function createValidationStore(initialValue, ...validators) {
let touched = false
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
})
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]
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)
return failing && failing(value)
}

View File

@ -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'
}
export function requiredValidator(value) {
return (
(value !== undefined && value !== null && value !== "") ||
"This field is required"
)
}

View File

@ -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

View File

@ -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,
}
}