Fix notifications for profile and password changes in client apps
This commit is contained in:
parent
64e92e91ac
commit
383b799e3e
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
export let compact: boolean = false
|
export let compact: boolean = false
|
||||||
|
|
||||||
const { authStore, environmentStore } = getContext("sdk")
|
const { authStore, environmentStore, notificationStore } = getContext("sdk")
|
||||||
|
|
||||||
let profileModal: any
|
let profileModal: any
|
||||||
let changePasswordModal: any
|
let changePasswordModal: any
|
||||||
|
@ -87,13 +87,17 @@
|
||||||
{API}
|
{API}
|
||||||
user={$authStore}
|
user={$authStore}
|
||||||
on:save={() => authStore.actions.fetchUser()}
|
on:save={() => authStore.actions.fetchUser()}
|
||||||
|
notifySuccess={notificationStore.actions.success}
|
||||||
|
notifyError={notificationStore.actions.error}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
<Modal bind:this={changePasswordModal}>
|
<Modal bind:this={changePasswordModal}>
|
||||||
<ChangePasswordModal
|
<ChangePasswordModal
|
||||||
{API}
|
{API}
|
||||||
passwordMinLength={$environmentStore.passwordMinLength}
|
passwordMinLength={$environmentStore.passwordMinLength}
|
||||||
on:save={() => authStore.actions.fetchUser()}
|
on:save={() => authStore.actions.logOut()}
|
||||||
|
notifySuccess={notificationStore.actions.success}
|
||||||
|
notifyError={notificationStore.actions.error}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
hoverStore,
|
hoverStore,
|
||||||
stateStore,
|
stateStore,
|
||||||
routeStore,
|
routeStore,
|
||||||
|
notificationStore,
|
||||||
} from "@/stores"
|
} from "@/stores"
|
||||||
import { get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
import { initWebsocket } from "@/websocket"
|
import { initWebsocket } from "@/websocket"
|
||||||
|
@ -83,6 +84,7 @@ export interface SDK {
|
||||||
generateGoldenSample: any
|
generateGoldenSample: any
|
||||||
authStore: typeof authStore
|
authStore: typeof authStore
|
||||||
environmentStore: typeof environmentStore
|
environmentStore: typeof environmentStore
|
||||||
|
notificationStore: typeof notificationStore
|
||||||
builderStore: Readable<{
|
builderStore: Readable<{
|
||||||
inBuilder: boolean
|
inBuilder: boolean
|
||||||
}> & {
|
}> & {
|
||||||
|
|
|
@ -46,6 +46,7 @@ const createAuthStore = () => {
|
||||||
const logOut = async () => {
|
const logOut = async () => {
|
||||||
try {
|
try {
|
||||||
await API.logOut()
|
await API.logOut()
|
||||||
|
window.location.href = "/"
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
export let API: APIClient
|
export let API: APIClient
|
||||||
export let passwordMinLength: string | undefined = undefined
|
export let passwordMinLength: string | undefined = undefined
|
||||||
|
export let notifySuccess = notifications.success
|
||||||
|
export let notifyError = notifications.error
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
|
@ -15,10 +17,10 @@
|
||||||
const updatePassword = async () => {
|
const updatePassword = async () => {
|
||||||
try {
|
try {
|
||||||
await API.updateSelf({ password })
|
await API.updateSelf({ password })
|
||||||
notifications.success("Password changed successfully")
|
notifySuccess("Password changed successfully")
|
||||||
dispatch("save")
|
dispatch("save")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifications.error("Failed to update password")
|
notifyError("Failed to update password")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
export let user: User | ContextUser | undefined = undefined
|
export let user: User | ContextUser | undefined = undefined
|
||||||
export let API: APIClient
|
export let API: APIClient
|
||||||
|
export let notifySuccess = notifications.success
|
||||||
|
export let notifyError = notifications.error
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
|
@ -18,11 +20,11 @@
|
||||||
const updateInfo = async () => {
|
const updateInfo = async () => {
|
||||||
try {
|
try {
|
||||||
await API.updateSelf($values)
|
await API.updateSelf($values)
|
||||||
notifications.success("Information updated successfully")
|
notifySuccess("Information updated successfully")
|
||||||
dispatch("save")
|
dispatch("save")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
notifications.error("Failed to update information")
|
notifyError("Failed to update information")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue