Skip to content

Commit

Permalink
Handle Pool Error (#3147)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskerr authored Sep 3, 2024
1 parent 9c21253 commit b64dd21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 2 additions & 0 deletions apps/zui/src/core/view-handler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {Dispatch, State, Store} from "src/js/state/types"
import {ipc} from "src/modules/bullet/view"
import {invoke} from "./invoke"
import toast from "react-hot-toast"

type Selector = (state: State, ...args: any) => any

export class ViewHandler {
static store: Store
static invoke = invoke
protected invoke = invoke
protected toast = toast

protected get store() {
return ViewHandler.store
Expand Down
18 changes: 8 additions & 10 deletions apps/zui/src/views/new-pool-modal/controller.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import {poolPath} from "src/app/router/utils/paths"
import {createHandler} from "src/core/handlers"
import {ViewHandler} from "src/core/view-handler"
import Tabs from "src/js/state/Tabs"
import {getFormData} from "src/util/get-form-data"

const createPool = createHandler(async ({invoke, dispatch, toast}, data) => {
const id = await invoke("pools.create", data.name, data)
dispatch(Tabs.activateUrl(poolPath(id)))
toast.success("Pool Created")
})

export class NewPoolModalController {
constructor(private close, private state) {}
export class NewPoolModalController extends ViewHandler {
constructor(private close, private state) {
super()
}

async onSubmit(e) {
try {
const data = getFormData(e)
createPool(data)
const id = await this.invoke("pools.create", data.name, data)
this.dispatch(Tabs.activateUrl(poolPath(id)))
this.toast.success("Pool Created")
this.close()
} catch (e) {
this.state.setError(e)
Expand Down

0 comments on commit b64dd21

Please sign in to comment.