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