lint fixes
This commit is contained in:
parent
7a4b6850a8
commit
47bc197b45
|
@ -1,20 +1,20 @@
|
||||||
import { writable } from 'svelte/store'
|
import { writable } from "svelte/store"
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
|
|
||||||
export default function (url) {
|
export default function (url) {
|
||||||
const store = writable({status: 'LOADING', data: {}, error: {}})
|
const store = writable({ status: "LOADING", data: {}, error: {} })
|
||||||
|
|
||||||
async function get() {
|
async function get() {
|
||||||
store.update(u => ({...u, status: 'SUCCESS'}))
|
store.update(u => ({ ...u, status: "SUCCESS" }))
|
||||||
try {
|
try {
|
||||||
const response = await api.get(url)
|
const response = await api.get(url)
|
||||||
store.set({data: await response.json(), status: 'SUCCESS'})
|
store.set({ data: await response.json(), status: "SUCCESS" })
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
store.set({data: {}, error: e, status: 'ERROR'})
|
store.set({ data: {}, error: e, status: "ERROR" })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get()
|
get()
|
||||||
|
|
||||||
return {subscribe: store.subscribe, refresh: get}
|
return { subscribe: store.subscribe, refresh: get }
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_name = s => (!s ? "" : last(s.split("/")))
|
||||||
|
|
||||||
export const get_capitalised_name = name => pipe(name, [get_name, capitalise])
|
export const get_capitalised_name = name => pipe(name, [get_name, capitalise])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,9 @@
|
||||||
export { default as fetchData } from './fetchData'
|
export { default as fetchData } from "./fetchData"
|
||||||
export { buildStyle, convertCamel, pipe, capitalise, get_name, get_capitalised_name } from './helpers'
|
export {
|
||||||
|
buildStyle,
|
||||||
|
convertCamel,
|
||||||
|
pipe,
|
||||||
|
capitalise,
|
||||||
|
get_name,
|
||||||
|
get_capitalised_name,
|
||||||
|
} from "./helpers"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
export { emailValidator, requiredValidator } from './validators'
|
export { emailValidator, requiredValidator } from "./validators"
|
||||||
export { createValidationStore } from './validation'
|
export { createValidationStore } from "./validation"
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
import { writable, derived } from 'svelte/store'
|
import { writable, derived } from "svelte/store"
|
||||||
|
|
||||||
export function createValidationStore(initialValue, ...validators) {
|
export function createValidationStore(initialValue, ...validators) {
|
||||||
let touched = false
|
let touched = false
|
||||||
|
|
||||||
const value = writable(initialValue || '')
|
const value = writable(initialValue || "")
|
||||||
const error = derived(value, $v => validate($v, validators))
|
const error = derived(value, $v => validate($v, validators))
|
||||||
const touchedStore = derived(value, () => {
|
const touchedStore = derived(value, () => {
|
||||||
if (!touched) {
|
if (!touched) {
|
||||||
touched = true
|
touched = true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return touched
|
return touched
|
||||||
})
|
})
|
||||||
|
|
||||||
return [value, error, touchedStore]
|
return [value, error, touchedStore]
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate(value, validators) {
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
export function emailValidator (value) {
|
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) {
|
export function requiredValidator(value) {
|
||||||
return (value !== undefined && value !== null && value !== '') || 'This field is required'
|
return (
|
||||||
}
|
(value !== undefined && value !== null && value !== "") ||
|
||||||
|
"This field is required"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -19,12 +19,16 @@ export function createOrganisationStore() {
|
||||||
if (json.status === 400) {
|
if (json.status === 400) {
|
||||||
set(FALLBACK_CONFIG)
|
set(FALLBACK_CONFIG)
|
||||||
} else {
|
} else {
|
||||||
set({...json.config, _rev: json._rev})
|
set({ ...json.config, _rev: json._rev })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function save(config) {
|
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()
|
const json = await res.json()
|
||||||
if (json.status) {
|
if (json.status) {
|
||||||
return json
|
return json
|
||||||
|
|
|
@ -12,23 +12,31 @@ export function createUsersStore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function invite(email) {
|
async function invite(email) {
|
||||||
const response = await api.post(`/api/admin/users/invite`, { email })
|
const response = await api.post(`/api/admin/users/invite`, { email })
|
||||||
return await response.json()
|
return await response.json()
|
||||||
}
|
}
|
||||||
async function acceptInvite(inviteCode, password) {
|
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", {
|
||||||
return await response.json()
|
inviteCode,
|
||||||
|
password,
|
||||||
|
})
|
||||||
|
return await response.json()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function create({ email, password }) {
|
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()
|
init()
|
||||||
return await response.json()
|
return await response.json()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function del(id) {
|
async function del(id) {
|
||||||
const response = await api.delete(`/api/admin/users/${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()
|
return await response.json()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +55,7 @@ export function createUsersStore() {
|
||||||
acceptInvite,
|
acceptInvite,
|
||||||
create,
|
create,
|
||||||
updateRoles,
|
updateRoles,
|
||||||
del
|
del,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue