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', () => { describe('create', () => {
it('resets form.create state', () => { it('resets form.create state', () => {
store.dispatch(actions.create()) store.dispatch(actions.create({name: 'a'}))
expect(store.getState().Crud.form.create).toEqual({ expect(store.getState().Crud.form.create).toEqual({
item: { item: {
name: '', name: 'a',
}, },
errors: {}, errors: {},
}) })

View File

@ -156,9 +156,9 @@ export class FindManyActionCreator<
export class FormActionCreator<T, ActionType extends string> { export class FormActionCreator<T, ActionType extends string> {
constructor(readonly actionType: ActionType) {} constructor(readonly actionType: ActionType) {}
create = (): TCRUDCreateAction<ActionType> => { create = (item: Partial<T>): TCRUDCreateAction<T, ActionType> => {
return { return {
payload: undefined, payload: item,
type: this.actionType, type: this.actionType,
method: 'create', 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 { return {
...state, ...state,
form: { form: {
...state.form, ...state.form,
create: { create: {
item: this.newItem, item: {
...this.newItem,
...payload,
},
errors: {}, errors: {},
}, },
}, },
@ -271,7 +274,7 @@ export class CRUDReducer<
case 'edit': case 'edit':
return this.handleEdit(state, action.payload.id) return this.handleEdit(state, action.payload.id)
case 'create': case 'create':
return this.handleCreate(state) return this.handleCreate(state, action.payload)
default: default:
return state return state
} }

View File

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