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,16 +1,16 @@
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'}))
store.update(u => ({ ...u, status: "SUCCESS" }))
try {
const response = await api.get(url)
store.set({data: await response.json(), status: 'SUCCESS'})
store.set({ data: await response.json(), status: "SUCCESS" })
} catch (e) {
store.set({data: {}, error: e, status: 'ERROR'})
store.set({ data: {}, error: e, status: "ERROR" })
}
}

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,9 +1,9 @@
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 value = writable(initialValue || "")
const error = derived(value, $v => validate($v, validators))
const touchedStore = derived(value, () => {
if (!touched) {

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

View File

@ -24,7 +24,11 @@ export function createOrganisationStore() {
}
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

@ -16,19 +16,27 @@ export function createUsersStore() {
return await response.json()
}
async function acceptInvite(inviteCode, password) {
const response = await api.post("/api/admin/users/invite/accept", { inviteCode, password })
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,
}
}