-const projectsReducer = (state: ProjectState = [], action: ProjectAction) => {
- return actions.match(action, {
- CREATE_PROJECT: project => [...state, project],
+const updateCreator = (state: ProjectState, creator: Partial<ProjectCreator>) => ({
+ ...state,
+ creator: {
+ ...state.creator,
+ ...creator
+ }
+});
+
+const initialState: ProjectState = {
+ items: [],
+ currentItemId: "",
+ creator: {
+ opened: false,
+ ownerUuid: ""
+ }
+};
+
+
+export const projectsReducer = (state: ProjectState = initialState, action: ProjectAction) => {
+ return projectActions.match(action, {
+ OPEN_PROJECT_CREATOR: ({ ownerUuid }) => updateCreator(state, { ownerUuid, opened: true }),
+ CLOSE_PROJECT_CREATOR: () => updateCreator(state, { opened: false }),
+ CREATE_PROJECT: () => updateCreator(state, { error: undefined }),
+ CREATE_PROJECT_SUCCESS: () => updateCreator(state, { opened: false, ownerUuid: "" }),