/
queueStore.js
96 lines (90 loc) · 2.69 KB
/
queueStore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { omit } from 'lodash';
import React from 'react';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import { MemoryRouter, Route } from 'react-router-dom';
import reducer from '../../../app/queue/reducers';
import { defaultHearing, hearingDateOptions } from '../../data/hearings';
import { amaAppeal, openHearingAppeal, defaultAssignHearing, legacyAppeal } from '../../data/appeals';
import { roLocations, roList } from '../../data/regional-offices';
export const appealsData = {
[legacyAppeal.externalId]: legacyAppeal,
[amaAppeal.externalId]: amaAppeal,
[openHearingAppeal.externalId]: openHearingAppeal,
};
export const initialState = {
components: {
scheduledHearing: {
taskId: null,
disposition: null,
externalId: null,
polling: false,
},
dropdowns: {
regionalOffices: { options: roList },
[`hearingLocationsFor${amaAppeal.externalId}At${defaultHearing.regionalOfficeKey}`]: { options: roLocations },
[`hearingDatesFor${defaultHearing.regionalOfficeKey}`]: { options: hearingDateOptions }
},
forms: {
assignHearing: defaultAssignHearing
}
},
queue: {
appeals: appealsData,
appealDetails: appealsData,
stagedChanges: {
appeals: {}
}
},
ui: {
messages: {},
saveState: {},
modals: {},
featureToggles: {}
}
};
export const queueWrapper = ({ children, ...props }) => {
// Providing `route` allows tests that depend on a route match to work (in
// other words, if your component relies on `prop.match`).
const initialRoute = props.route;
return (
<Provider store={createStore(reducer, {
...initialState,
...omit(props, ['route']),
components: {
...initialState.components,
...props?.components,
dropdowns: {
...initialState.components.dropdowns,
...props?.components?.dropdowns,
},
forms: {
...initialState.components.forms,
...props?.components?.forms,
},
scheduledHearing: {
...initialState.components.scheduledHearing,
...props?.components?.scheduledHearing,
}
},
queue: {
...initialState.queue,
...props?.queue
},
ui: {
...initialState.ui,
...props?.ui
},
})}>
<MemoryRouter
initialEntries={initialRoute ? [initialRoute] : ['/']}
keyLength={0}
>
{/* Create a dummy route for the supplied route. */}
{initialRoute && <Route path={initialRoute}>{children}</Route>}
{/* No route supplied. */}
{!initialRoute && <React.Fragment>{children}</React.Fragment>}
</MemoryRouter>
</Provider>
);
};