ba-js-common-header 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,216 @@
1
+ # Bookassist Shared Header
2
+
3
+ A React-based common Bookassist header component
4
+
5
+ ## Installation
6
+
7
+ ```javascript
8
+ yarn add ba-js-common-header
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```javascript
14
+ // React
15
+
16
+ import { Header } from 'ba-js-common-header'
17
+
18
+ function App(props) {
19
+ return <Header {...props} />
20
+ }
21
+ ```
22
+
23
+ ```javascript
24
+ // website
25
+
26
+ <div id="header"></div>
27
+
28
+ // es5
29
+ <script src="https://unpkg.com/ba-js-common-header/dist/ba-js-common-header.umd.js"></script>
30
+ // baJsHeader global now available
31
+ <script>
32
+ const { renderHeader } = baJsHeader
33
+ renderHeader(document.querySelector('#header'), {
34
+ // props
35
+ })
36
+ </script>
37
+
38
+ // ES Modules
39
+ <script type="module">
40
+ import { renderHeader } from 'https://unpkg.com/ba-js-common-header/dist/ba-js-common-header.es.js'
41
+ renderHeader(document.querySelector('#header'), {
42
+ // props
43
+ })
44
+ </script>
45
+ ```
46
+
47
+ ## Redux State
48
+
49
+ The header uses redux to manage shared application state. The redux state shape is as follows:
50
+
51
+ ```javascript
52
+ {
53
+ hotelInfo: {
54
+ name: '',
55
+ hotelId: 0,
56
+ guideId: 0,
57
+ hotelGroupId: 0,
58
+ },
59
+ userInfo: {
60
+ username: '',
61
+ userid: 0,
62
+ hotelId: 0,
63
+ guideId: 0,
64
+ hotelGroupId: 0,
65
+ },
66
+ userLanguage: 'en',
67
+ menuItems: [
68
+ {
69
+ id: 1453141030,
70
+ label: 'Hotel Info',
71
+ path: '/hotel_admin/hotelinfo.jsp',
72
+ },
73
+ {
74
+ id: 555613737,
75
+ parentId: 1453141030,
76
+ label: 'Create Vouchers',
77
+ path: '/hotel_admin/new_voucher_package.jsp',
78
+ },
79
+ ],
80
+ selectedMenuItem: 555613737,
81
+ notifications,
82
+ }
83
+ ```
84
+
85
+ ## Header Props
86
+
87
+ | Prop | Type | Description |
88
+ | :--------------------- | :------- | :--------------------------------------------------------------- |
89
+ | `fetchUserInfo` | `obj/fn` | userInfo object (or function that resolves to same) |
90
+ | `fetchHotelInfo` | `obj/fn` | hotelInfo object (or function that resolves to same) |
91
+ | `fetchHotels` | `arr/fn` | array of hotels for selector (or function that resolves to same) |
92
+ | `handleHotelChange` | `fn` | hotel selector callback |
93
+ | `languages` | `arr` | array of language codes |
94
+ | `handleLanguageChange` | `fn` | language selector callback |
95
+ | `brand` | `str` | brand name |
96
+ | `product` | `str` | product name |
97
+ | `logout` | `str/fn` | href or logout function |
98
+ | `handleLogout` | `fn` | logout callback |
99
+ | `fetchMenu` | `obj/fn` | menu configuration object (or function that resolves to same) |
100
+
101
+ #### fetchUserInfo
102
+
103
+ This provides the initial userInfo state to the header. It can be one of three things:
104
+
105
+ 1. a userInfo object
106
+ 2. a promise resolving to a userInfo object
107
+ 3. a function returning a promise that resolves to a userInfo object
108
+
109
+ ```javascript
110
+ // userInfo
111
+ {
112
+ userId: 0,
113
+ username: '',
114
+ hotelId: 0,
115
+ guideId: 0,
116
+ hotelGroupId: 0,
117
+ }
118
+ ```
119
+
120
+ #### fetchHotelInfo
121
+
122
+ This provides the initial hotelInfo state to the header. It can be one of three things:
123
+
124
+ 1. a hotelInfo object
125
+ 2. a promise resolving to a hotelInfo object
126
+ 3. a function returning a promise that resolves to a hotelInfo object
127
+
128
+ ```javascript
129
+ // hotelInfo
130
+ {
131
+ hotelId: 0,
132
+ guideId: 0,
133
+ name: '',
134
+ hotelGroupId: 0,
135
+ }
136
+ ```
137
+
138
+ #### handleHotelChange
139
+
140
+ This is a callback that fires when the hotelInfo state changes. The callback is passed the new hotelInfo state
141
+
142
+ #### fetchHotels
143
+
144
+ This is an array of hotels for the hotel selector combo box (format TBD). It can be one of three things:
145
+
146
+ 1. an array of hotel objects
147
+ 2. a promise resolving to an array of hotel objects
148
+ 3. a function returning a promise that resolves to an array of hotel objects
149
+
150
+ ```javascript
151
+ // current Hotel Admin format
152
+ hotels = [
153
+ ['ADLER HOTEL', '3724_802'],
154
+ ['Adria Hotel Prague', '1465_802'],
155
+ ['Agroturismo Can Toni Xumeu', '3033_102'],
156
+ // ...
157
+ ]
158
+ ```
159
+
160
+ Selecting a hotel updates the hotelInfo state
161
+
162
+ #### languages
163
+
164
+ This is an array of ISO language codes. The header handles language naming needs using the [Intl.DisplayNames](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames) object.
165
+
166
+ #### handleLanguageChange
167
+
168
+ This is a callback that fires when the user selects a language. The callback is passed the new language code
169
+
170
+ #### brand
171
+
172
+ This is the product brand
173
+
174
+ #### product
175
+
176
+ This is the product
177
+
178
+ #### logout
179
+
180
+ This is a string (logout link) or function that logs a user out
181
+
182
+ #### handleLogout
183
+
184
+ When `logout` is a function this is a callback that fires after successful logout. It is passed the return value of the `logout` call
185
+
186
+ #### fetchMenu
187
+
188
+ TBD
189
+
190
+ ## Data Structures
191
+
192
+ #### Menu
193
+
194
+ The menu items are modelled as a flat array of objects.
195
+
196
+ ```javascript
197
+ var menuItems = [
198
+ {
199
+ id, // required
200
+ parentId, // required for nested menu items
201
+ label, // required
202
+ host, // origin for external links
203
+ path, // link path
204
+ },
205
+ // ...
206
+ ]
207
+ ```
208
+
209
+ #### TODO
210
+
211
+ - feed structure
212
+ - how breadcrumb works
213
+ - notifications
214
+ - icons
215
+ - bootstrap dependencies
216
+ - i18n