2018-06-25 14:40:43 +00:00
|
|
|
/* @flow */
|
|
|
|
|
|
|
|
import { combineReducers } from 'redux'
|
2018-07-12 08:09:41 +00:00
|
|
|
import type {
|
2018-08-23 14:42:02 +00:00
|
|
|
Action as CompanyStatusAction,
|
2018-07-12 08:09:41 +00:00
|
|
|
CompanyLegalStatus,
|
|
|
|
State
|
|
|
|
} from 'Types/companyStatusTypes'
|
2018-09-18 13:48:09 +00:00
|
|
|
import type {
|
|
|
|
Action as CreationChecklistAction,
|
|
|
|
} from 'Types/companyCreationChecklistTypes'
|
|
|
|
import type {
|
|
|
|
Action as HiringChecklist,
|
|
|
|
} from 'Types/hiringChecklistTypes'
|
2018-08-23 14:42:02 +00:00
|
|
|
type Action = CompanyStatusAction | CreationChecklistAction | HiringChecklist
|
2018-08-22 18:24:13 +00:00
|
|
|
|
2018-06-27 14:22:42 +00:00
|
|
|
function companyLegalStatus(
|
|
|
|
state: CompanyLegalStatus = {},
|
2018-06-26 15:57:50 +00:00
|
|
|
action: Action
|
2018-06-27 14:22:42 +00:00
|
|
|
): CompanyLegalStatus {
|
|
|
|
switch (action.type) {
|
|
|
|
case 'CHOOSE_COMPANY_LEGAL_SETUP':
|
2018-07-18 08:57:56 +00:00
|
|
|
return { ...state, liability: action.setup }
|
2018-06-26 15:57:50 +00:00
|
|
|
|
2018-06-27 14:22:42 +00:00
|
|
|
case 'DEFINE_DIRECTOR_STATUS':
|
|
|
|
return { ...state, directorStatus: action.status }
|
2018-09-10 09:10:41 +00:00
|
|
|
case 'COMPANY_HAS_MULTIPLE_ASSOCIATES':
|
2018-07-23 13:21:00 +00:00
|
|
|
return { ...state, multipleAssociates: action.multipleAssociates }
|
|
|
|
case 'COMPANY_IS_MICROENTERPRISE':
|
|
|
|
return { ...state, microenterprise: action.microenterprise }
|
2018-08-23 14:42:02 +00:00
|
|
|
case 'SPECIFY_DIRECTORS_SHARE':
|
|
|
|
return { ...state, minorityDirector: action.minorityDirector }
|
|
|
|
case 'RESET_COMPANY_STATUS_CHOICE':
|
|
|
|
return {}
|
2018-06-26 15:57:50 +00:00
|
|
|
}
|
2018-06-27 14:22:42 +00:00
|
|
|
return state
|
2018-06-26 15:57:50 +00:00
|
|
|
}
|
|
|
|
|
2018-09-18 13:48:09 +00:00
|
|
|
function hiringChecklist(
|
|
|
|
state: { [string]: boolean } = {},
|
|
|
|
action: Action
|
|
|
|
) {
|
2018-08-22 18:24:13 +00:00
|
|
|
switch (action.type) {
|
2018-08-23 14:42:02 +00:00
|
|
|
case 'CHECK_HIRING_ITEM':
|
2018-08-22 18:24:13 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2018-08-23 14:42:02 +00:00
|
|
|
[action.name]: action.checked
|
2018-08-22 18:24:13 +00:00
|
|
|
}
|
2018-08-23 14:42:02 +00:00
|
|
|
case 'INITIALIZE_HIRING_CHECKLIST':
|
2018-09-18 13:48:09 +00:00
|
|
|
return Object.keys(state).length ? state : action.checklistItems.reduce(
|
|
|
|
(checklist, item) => ({...checklist, [item]: false })
|
|
|
|
, {});
|
2018-08-22 18:24:13 +00:00
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 13:48:09 +00:00
|
|
|
|
2018-08-23 14:42:02 +00:00
|
|
|
function companyCreationChecklist(
|
2018-09-18 13:48:09 +00:00
|
|
|
state: { [string]: boolean } = {},
|
2018-07-06 12:31:30 +00:00
|
|
|
action: Action
|
2018-08-23 14:42:02 +00:00
|
|
|
) {
|
2018-07-06 12:31:30 +00:00
|
|
|
switch (action.type) {
|
2018-08-23 14:42:02 +00:00
|
|
|
case 'CHECK_COMPANY_CREATION_ITEM':
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
[action.name]: action.checked
|
|
|
|
}
|
|
|
|
case 'INITIALIZE_COMPANY_CREATION_CHECKLIST':
|
2018-09-18 13:48:09 +00:00
|
|
|
return Object.keys(state).length ? state : action.checklistItems.reduce(
|
|
|
|
(checklist, item) => ({...checklist, [item]: false })
|
|
|
|
, {})
|
|
|
|
;
|
|
|
|
case 'RESET_COMPANY_STATUS_CHOICE':
|
|
|
|
return {};
|
2018-07-06 12:31:30 +00:00
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|
2018-08-22 18:24:13 +00:00
|
|
|
|
2018-09-18 13:48:09 +00:00
|
|
|
function companyStatusChoice(
|
|
|
|
state: ?string = null,
|
|
|
|
action: Action
|
|
|
|
) {
|
2018-08-23 14:42:02 +00:00
|
|
|
if (action.type === 'RESET_COMPANY_STATUS_CHOICE') {
|
|
|
|
return null
|
2018-08-23 12:00:49 +00:00
|
|
|
}
|
2018-08-23 14:42:02 +00:00
|
|
|
if (action.type !== 'INITIALIZE_COMPANY_CREATION_CHECKLIST') {
|
2018-09-18 13:48:09 +00:00
|
|
|
return state;
|
|
|
|
}
|
2018-08-23 14:42:02 +00:00
|
|
|
return action.statusName
|
2018-08-20 17:02:56 +00:00
|
|
|
}
|
2018-07-06 12:31:30 +00:00
|
|
|
|
2018-08-23 14:42:02 +00:00
|
|
|
function existingCompanyDetails(
|
|
|
|
state: ?{ [string]: string } = null,
|
|
|
|
action: Action
|
|
|
|
): ?{ [string]: string } {
|
|
|
|
switch (action.type) {
|
|
|
|
case 'SAVE_EXISTING_COMPANY_DETAILS':
|
|
|
|
return action.details
|
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|
2018-07-12 08:09:41 +00:00
|
|
|
// $FlowFixMe
|
2018-07-06 13:48:41 +00:00
|
|
|
export default (combineReducers({
|
2018-07-06 12:31:30 +00:00
|
|
|
companyLegalStatus,
|
2018-08-23 14:42:02 +00:00
|
|
|
companyStatusChoice,
|
|
|
|
companyCreationChecklist,
|
|
|
|
existingCompanyDetails,
|
|
|
|
hiringChecklist
|
2018-07-06 13:48:41 +00:00
|
|
|
}): (State, Action) => State)
|