Merge pull request #1526 from Budibase/ak-fixes

AK fixes
This commit is contained in:
Andrew Kingston 2021-05-21 15:44:58 +01:00 committed by GitHub
commit b00895c7b4
14 changed files with 78 additions and 48 deletions

View File

@ -12,15 +12,7 @@
export let size = "M" export let size = "M"
export let url = "" export let url = ""
export let disabled = false export let disabled = false
export let name = "John Doe" export let initials = "JD"
function getInitials(name) {
let parts = name.split(" ")
if (parts.length > 0) {
return parts.map(name => name[0]).join("")
}
return name
}
</script> </script>
{#if url} {#if url}
@ -38,7 +30,7 @@
size size
)}); font-size: calc(var({sizes.get(size)}) / 2)" )}); font-size: calc(var({sizes.get(size)}) / 2)"
> >
{getInitials(name)} {initials || ""}
</div> </div>
{/if} {/if}
@ -52,5 +44,6 @@
border-radius: 50%; border-radius: 50%;
overflow: hidden; overflow: hidden;
user-select: none; user-select: none;
text-transform: uppercase;
} }
</style> </style>

View File

@ -82,6 +82,7 @@
on:blur on:blur
on:focus on:focus
on:input on:input
on:keyup
on:blur={onBlur} on:blur={onBlur}
on:focus={onFocus} on:focus={onFocus}
on:input={onInput} on:input={onInput}

View File

@ -34,5 +34,6 @@
on:input on:input
on:blur on:blur
on:focus on:focus
on:keyup
/> />
</Field> </Field>

View File

@ -8,7 +8,7 @@
const updatePassword = async () => { const updatePassword = async () => {
try { try {
await auth.updateSelf({ ...$auth.user, password }) await auth.updateSelf({ password })
notifications.success("Password changed successfully") notifications.success("Password changed successfully")
} catch (error) { } catch (error) {
notifications.error("Failed to update password") notifications.error("Failed to update password")

View File

@ -10,7 +10,7 @@
const updateInfo = async () => { const updateInfo = async () => {
try { try {
await auth.updateSelf({ ...$auth.user, ...$values }) await auth.updateSelf($values)
notifications.success("Information updated successfully") notifications.success("Information updated successfully")
} catch (error) { } catch (error) {
notifications.error("Failed to update information") notifications.error("Failed to update information")

View File

@ -10,8 +10,10 @@
import { goto } from "@roxi/routify" import { goto } from "@roxi/routify"
import api from "builderStore/api" import api from "builderStore/api"
import { admin, organisation } from "stores/portal" import { admin, organisation } from "stores/portal"
import PasswordRepeatInput from "components/common/users/PasswordRepeatInput.svelte"
let adminUser = {} let adminUser = {}
let error
async function save() { async function save() {
try { try {
@ -42,13 +44,11 @@
</Layout> </Layout>
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<Input label="Email" bind:value={adminUser.email} /> <Input label="Email" bind:value={adminUser.email} />
<Input <PasswordRepeatInput bind:password={adminUser.password} bind:error />
label="Password"
type="password"
bind:value={adminUser.password}
/>
</Layout> </Layout>
<Button cta on:click={save}>Create super admin user</Button> <Button cta disabled={error} on:click={save}>
Create super admin user
</Button>
</Layout> </Layout>
</div> </div>
</section> </section>

View File

@ -51,7 +51,7 @@
</Layout> </Layout>
<ActionMenu align="right"> <ActionMenu align="right">
<div slot="control" class="avatar"> <div slot="control" class="avatar">
<Avatar size="M" name="John Doe" /> <Avatar size="M" initials={$auth.initials} />
<Icon size="XL" name="ChevronDown" /> <Icon size="XL" name="ChevronDown" />
</div> </div>
<MenuItem icon="UserEdit" on:click={() => userInfoModal.show()}> <MenuItem icon="UserEdit" on:click={() => userInfoModal.show()}>

View File

@ -13,7 +13,6 @@
try { try {
if (forceResetPassword) { if (forceResetPassword) {
await auth.updateSelf({ await auth.updateSelf({
...$auth.user,
password, password,
forceResetPassword: false, forceResetPassword: false,
}) })

View File

@ -3,7 +3,6 @@
import { import {
Icon, Icon,
Avatar, Avatar,
Search,
Layout, Layout,
SideNavigation as Navigation, SideNavigation as Navigation,
SideNavigationItem as Item, SideNavigationItem as Item,
@ -77,7 +76,7 @@
<div /> <div />
<ActionMenu align="right"> <ActionMenu align="right">
<div slot="control" class="avatar"> <div slot="control" class="avatar">
<Avatar size="M" name="John Doe" /> <Avatar size="M" initials={$auth.initials} />
<Icon size="XL" name="ChevronDown" /> <Icon size="XL" name="ChevronDown" />
</div> </div>
<MenuItem icon="UserEdit" on:click={() => userInfoModal.show()}> <MenuItem icon="UserEdit" on:click={() => userInfoModal.show()}>

View File

@ -41,8 +41,8 @@
const enrichedApps = apps.map(app => ({ const enrichedApps = apps.map(app => ({
...app, ...app,
deployed: app.status === AppStatus.DEPLOYED, deployed: app.status === AppStatus.DEPLOYED,
lockedYou: app.lockedBy?.email === user.email, lockedYou: app.lockedBy && app.lockedBy.email === user?.email,
lockedOther: app.lockedBy && app.lockedBy.email !== user.email, lockedOther: app.lockedBy && app.lockedBy.email !== user?.email,
})) }))
if (sortBy === "status") { if (sortBy === "status") {
return enrichedApps.sort((a, b) => { return enrichedApps.sort((a, b) => {

View File

@ -4,7 +4,6 @@
Button, Button,
Heading, Heading,
Divider, Divider,
Page,
Label, Label,
notifications, notifications,
Layout, Layout,
@ -23,6 +22,13 @@
const ConfigFields = { const ConfigFields = {
Google: ["clientID", "clientSecret", "callbackURL"], Google: ["clientID", "clientSecret", "callbackURL"],
} }
const ConfigLabels = {
Google: {
clientID: "Client ID",
clientSecret: "Client secret",
callbackURL: "Callback URL",
},
}
let google let google
@ -85,7 +91,7 @@
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
{#each ConfigFields.Google as field} {#each ConfigFields.Google as field}
<div class="form-row"> <div class="form-row">
<Label size="L">{field}</Label> <Label size="L">{ConfigLabels.Google[field]}</Label>
<Input bind:value={google.config[field]} /> <Input bind:value={google.config[field]} />
</div> </div>
{/each} {/each}

View File

@ -84,7 +84,7 @@
<Heading>User: {$userFetch?.data?.email}</Heading> <Heading>User: {$userFetch?.data?.email}</Heading>
<Body> <Body>
Change user settings and update their app roles. Also contains the ability Change user settings and update their app roles. Also contains the ability
to delete the user as well as force reset their password.. to delete the user as well as force reset their password.
</Body> </Body>
</Layout> </Layout>
<Divider size="S" /> <Divider size="S" />
@ -108,7 +108,7 @@
<Input disabled thin value={$userFetch?.data?.lastName} /> <Input disabled thin value={$userFetch?.data?.lastName} />
</div> </div>
<div class="field"> <div class="field">
<Label size="L">Development access?</Label> <Label size="L">Development access</Label>
<Toggle <Toggle
text="" text=""
value={$userFetch?.data?.builder?.global} value={$userFetch?.data?.builder?.global}

View File

@ -9,13 +9,26 @@
$: leftover = roles.length - tags.length $: leftover = roles.length - tags.length
</script> </script>
<Tags> <div class="tag-renderer">
<Tags>
{#each tags as tag} {#each tags as tag}
<Tag disabled> <Tag>
{tag} {tag}
</Tag> </Tag>
{/each} {/each}
{#if leftover} {#if leftover}
<Tag>+{leftover} more</Tag> <Tag>+{leftover} more</Tag>
{/if} {/if}
</Tags> </Tags>
</div>
<style>
.tag-renderer :global(.spectrum-Tags-item:hover) {
color: var(--spectrum-alias-label-text-color);
border-color: var(--spectrum-alias-border-color-darker-default);
cursor: pointer;
}
.tag-renderer :global(.spectrum-Tags-itemLabel) {
cursor: pointer;
}
</style>

View File

@ -1,25 +1,42 @@
import { writable } from "svelte/store" import { derived, writable, get } from "svelte/store"
import api from "../../builderStore/api" import api from "../../builderStore/api"
export function createAuthStore() { export function createAuthStore() {
const store = writable({ user: null }) const user = writable(null)
const store = derived(user, $user => {
let initials = null
if ($user) {
if ($user.firstName) {
initials = $user.firstName[0]
if ($user.lastName) {
initials += $user.lastName[0]
}
} else {
initials = $user.email[0]
}
}
return {
user: $user,
initials,
}
})
return { return {
subscribe: store.subscribe, subscribe: store.subscribe,
checkAuth: async () => { checkAuth: async () => {
const response = await api.get("/api/admin/users/self") const response = await api.get("/api/admin/users/self")
if (response.status !== 200) { if (response.status !== 200) {
store.update(state => ({ ...state, user: null })) user.set(null)
} else { } else {
const user = await response.json() const json = await response.json()
store.update(state => ({ ...state, user })) user.set(json)
} }
}, },
login: async creds => { login: async creds => {
const response = await api.post(`/api/admin/auth`, creds) const response = await api.post(`/api/admin/auth`, creds)
const json = await response.json() const json = await response.json()
if (response.status === 200) { if (response.status === 200) {
store.update(state => ({ ...state, user: json.user })) user.set(json.user)
} else { } else {
throw "Invalid credentials" throw "Invalid credentials"
} }
@ -31,12 +48,13 @@ export function createAuthStore() {
throw "Unable to create logout" throw "Unable to create logout"
} }
await response.json() await response.json()
store.update(state => ({ ...state, user: null })) user.set(null)
}, },
updateSelf: async user => { updateSelf: async fields => {
const response = await api.post("/api/admin/users/self", user) const newUser = { ...get(user), ...fields }
const response = await api.post("/api/admin/users/self", newUser)
if (response.status === 200) { if (response.status === 200) {
store.update(state => ({ ...state, user: { ...state.user, ...user } })) user.set(newUser)
} else { } else {
throw "Unable to update user details" throw "Unable to update user details"
} }