Add Site to Application.tsx (untested)
This commit is contained in:
parent
831001a9c5
commit
b5c5ea81a9
@ -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: {},
|
||||
})
|
||||
|
||||
@ -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',
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user