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