Skip to content

Commit

Permalink
feat: reload page when saving the settings (#14)
Browse files Browse the repository at this point in the history
Relative to #13
  • Loading branch information
ojacquemart authored Oct 13, 2021
1 parent 9685775 commit 0293f8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 13 additions & 4 deletions samples/ui/src/components/modal/ModalDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ import { Store } from 'vuex'
import { FormControl, FormControlValidators } from '@/components/modal/FormControl'

const DEFAULT_VALIDATOR = (controls: FormControl[]) => FormControlValidators.requiredNotEmpty(controls)
const NOOP = () => {
// do nothing
}

export interface ModalOptions {
payloadObject?: boolean,
validator?: (controls: FormControl[]) => boolean,
payloadObject?: boolean
validator?: (controls: FormControl[]) => boolean
afterSave?: () => void
}

export class ModalDefinition {
id: string
title: string
dispatch: string
controls: FormControl[]
validator: (controls: FormControl[]) => boolean
afterSave: () => void
payloadObject?: boolean
controls: FormControl[]

constructor(
id: string, title: string, dispatch: string, controls: FormControl[],
Expand All @@ -24,9 +29,10 @@ export class ModalDefinition {
this.id = id
this.title = title
this.dispatch = dispatch
this.controls = controls
this.validator = options?.validator ?? DEFAULT_VALIDATOR
this.afterSave = options?.afterSave ?? NOOP
this.payloadObject = options?.payloadObject ?? false
this.controls = controls
}

validate(): boolean {
Expand All @@ -38,6 +44,8 @@ export class ModalDefinition {

await store.dispatch(this.dispatch, payload)
store.commit('modals/close', this.id)

this.afterSave()
}

private getPayload() {
Expand All @@ -57,5 +65,6 @@ export class ModalDefinition {
return acc
}, {} as { [key: string]: string })
}

}

3 changes: 3 additions & 0 deletions samples/ui/src/components/modal/ModalDefinitionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export class ModalDefinitionFactory {
},
],
{
afterSave: () => {
window.location.reload()
},
payloadObject: true,
},
),
Expand Down

0 comments on commit 0293f8e

Please sign in to comment.