Add Site to Application.tsx (untested)

This commit is contained in:
Jerko Steiner 2019-04-03 19:01:33 +08:00
parent 831001a9c5
commit b5c5ea81a9
4 changed files with 13 additions and 10 deletions

View File

@ -311,10 +311,10 @@ describe('CRUD', () => {
describe('create', () => {
it('resets form.create state', () => {
store.dispatch(actions.create())
store.dispatch(actions.create({name: 'a'}))
expect(store.getState().Crud.form.create).toEqual({
item: {
name: '',
name: 'a',
},
errors: {},
})

View File

@ -156,9 +156,9 @@ export class FindManyActionCreator<
export class FormActionCreator<T, ActionType extends string> {
constructor(readonly actionType: ActionType) {}
create = (): TCRUDCreateAction<ActionType> => {
create = (item: Partial<T>): TCRUDCreateAction<T, ActionType> => {
return {
payload: undefined,
payload: item,
type: this.actionType,
method: 'create',
}

View File

@ -183,13 +183,16 @@ export class CRUDReducer<
}
}
handleCreate = (state: ICRUDState<T>): ICRUDState<T> => {
handleCreate = (state: ICRUDState<T>, payload: Partial<T>): ICRUDState<T> => {
return {
...state,
form: {
...state.form,
create: {
item: this.newItem,
item: {
...this.newItem,
...payload,
},
errors: {},
},
},
@ -271,7 +274,7 @@ export class CRUDReducer<
case 'edit':
return this.handleEdit(state, action.payload.id)
case 'create':
return this.handleCreate(state)
return this.handleCreate(state, action.payload)
default:
return state
}

View File

@ -20,8 +20,8 @@ export type TCRUDFindManyAction<T, ActionType extends string> =
// Synchronous actions
export type TCRUDCreateAction<ActionType extends string> =
IAction<undefined, ActionType> & {method: Extract<TCRUDMethod, 'create'>}
export type TCRUDCreateAction<T, ActionType extends string> =
IAction<Partial<T>, ActionType> & {method: Extract<TCRUDMethod, 'create'>}
export type TCRUDEditAction<ActionType extends string> =
IAction<{id: number}, ActionType> & {method: Extract<TCRUDMethod, 'edit'>}
@ -36,6 +36,6 @@ export type TCRUDAction<T, ActionType extends string> =
| TCRUDRemoveAction<T, ActionType>
| TCRUDFindOneAction<T, ActionType>
| TCRUDFindManyAction<T, ActionType>
| TCRUDCreateAction<ActionType>
| TCRUDCreateAction<T, ActionType>
| TCRUDEditAction<ActionType>
| TCRUDChangeAction<T, ActionType>