@dev-crew-berlin/enter-js-utils 0.88.0 → 0.89.0

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 CHANGED
@@ -12,7 +12,7 @@ npm install @dev-crew-berlin/enter-js-utils
12
12
 
13
13
  React ui components for enter and dcb apps.
14
14
 
15
- > docs: https://js-utils.enter.events/storybook
15
+ > docs: https://js-utils.enter.events/storybook/
16
16
 
17
17
  ### lib
18
18
 
@@ -20,12 +20,13 @@ export declare class Attendee {
20
20
  checkin: Map<string, Checkins>;
21
21
  companions: {
22
22
  isCompanion: false;
23
- comanionNames?: {
23
+ companionNames?: {
24
24
  [attendeeId: string]: string;
25
25
  };
26
26
  } | {
27
27
  isCompanion: true;
28
28
  mainGuestId: string;
29
+ mainGuestName: string;
29
30
  };
30
31
  payment: Payment | null;
31
32
  deleted: boolean;
@@ -39,6 +40,7 @@ export declare class Attendee {
39
40
  */
40
41
  static generateID(prefix: string): string;
41
42
  toJSON(): AttendeeJSON;
43
+ hash(): string;
42
44
  getRsvpCountForBranch(branchName: string): number;
43
45
  getRsvpCount(branchName: string, counterName: string): number;
44
46
  getResponseForBranch(branchName: string): 'no-response' | 'negative-response' | 'positive-response';
@@ -1,4 +1,5 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
+ import hash from 'stable-hash';
2
3
  import { Checkins } from './checkins';
3
4
  import { Rsvp } from './rsvp';
4
5
  export class Attendee {
@@ -10,7 +11,7 @@ export class Attendee {
10
11
  checkin = new Map();
11
12
  companions = {
12
13
  isCompanion: false,
13
- comanionNames: {}
14
+ companionNames: {}
14
15
  };
15
16
  payment = null;
16
17
  deleted = false;
@@ -30,11 +31,12 @@ export class Attendee {
30
31
  this.rsvp = new Map(Object.entries(json.rsvp ?? {}).map(([checkinTag, rsvp]) => [checkinTag, rsvp ? new Rsvp(rsvp) : null]));
31
32
  this.checkin = new Map(Object.entries(json.checkin ?? {}).map(([checkinTag, checkin]) => [checkinTag, new Checkins(checkin)]));
32
33
  this.companions = json.companions?.isCompanion ? {
34
+ ...json.companions,
33
35
  isCompanion: true,
34
- ...json.companions
36
+ mainGuestName: json.companions.mainGuestName ?? json.companions.mainGuestId
35
37
  } : {
36
- isCompanion: false,
37
- ...json.companions
38
+ ...json.companions,
39
+ isCompanion: false
38
40
  };
39
41
  this.payment = json.payment ?? null;
40
42
  this.deleted = json.deleted ?? false;
@@ -73,6 +75,9 @@ export class Attendee {
73
75
  rsvp
74
76
  };
75
77
  }
78
+ hash() {
79
+ return hash([this.id, Array.from(this.userdata), Array.from(this.tags), this.language, this.time, Array.from(this.branches), Array.from(this.rsvp).map(([counterName, rsvp]) => [counterName, rsvp?.hash()]), Array.from(this.checkin).map(([counterName, checkin]) => [counterName, checkin?.hash()]), this.companions, this.payment, this.deleted]);
80
+ }
76
81
  getRsvpCountForBranch(branchName) {
77
82
  const rsvp = this.rsvp.get(branchName);
78
83
  if (!rsvp) return 0;
@@ -7,6 +7,7 @@ export declare class Checkins {
7
7
  deleted: Set<string>;
8
8
  constructor(json?: CheckinsJSONInput);
9
9
  toJSON(): CheckinsJSON;
10
+ hash(): string;
10
11
  getActiveCheckins(counterName?: string): Checkin[];
11
12
  merge(otherCheckin: Checkins): Checkins;
12
13
  }
@@ -1,3 +1,4 @@
1
+ import hash from 'stable-hash';
1
2
  import { Checkin } from './checkin';
2
3
  export class Checkins {
3
4
  checkins = [];
@@ -14,6 +15,9 @@ export class Checkins {
14
15
  deleted: Array.from(this.deleted)
15
16
  };
16
17
  }
18
+ hash() {
19
+ return hash([this.checkins.map(checkin => checkin.id), Array.from(this.deleted)]);
20
+ }
17
21
  getActiveCheckins(counterName = 'main') {
18
22
  return this.checkins.filter(checkin => checkin.counterName === counterName && !this.deleted.has(checkin.id));
19
23
  }
@@ -11,4 +11,5 @@ export declare class Rsvp {
11
11
  static declining(): Rsvp;
12
12
  get confirmed(): boolean;
13
13
  toJSON(): RsvpJSON;
14
+ hash(): string;
14
15
  }
@@ -1,4 +1,5 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
+ import hash from 'stable-hash';
2
3
  export class Rsvp {
3
4
  constructor(args) {
4
5
  if (typeof args == 'number') {
@@ -34,4 +35,7 @@ export class Rsvp {
34
35
  checkinCounters: Array.from(this.checkinCounters)
35
36
  };
36
37
  }
38
+ hash() {
39
+ return hash([this.tieBreaker, this.time, this.personCount, Array.from(this.checkinCounters)]);
40
+ }
37
41
  }
@@ -1,15 +1,13 @@
1
1
  import { FunctionComponent } from 'react';
2
2
  import 'styled-jsx';
3
- import { Attendee } from '../models';
4
3
  type Props = {
5
4
  companionStatus: {
6
5
  isCompanion: false;
7
6
  } | {
8
7
  isCompanion: true;
9
8
  mainGuestId: string;
9
+ mainGuestName: string;
10
10
  };
11
- formatName: (attendee: Attendee) => string;
12
- findMainGuest?: (attendeeId: string) => Attendee | undefined;
13
11
  };
14
12
  export declare const CompanionInfo: FunctionComponent<Props>;
15
13
  export {};
@@ -4,13 +4,11 @@ import 'styled-jsx';
4
4
  import { colors, fonts } from '../lib/theme';
5
5
  export const CompanionInfo = props => {
6
6
  if (!props.companionStatus.isCompanion) return null;
7
- const mainGuest = props.findMainGuest ? props.findMainGuest(props.companionStatus.mainGuestId) : undefined;
8
- const mainGuestName = mainGuest ? props.formatName(mainGuest) : undefined;
9
7
  return /*#__PURE__*/React.createElement("p", {
10
8
  className: _JSXStyle.dynamic([["21346984", [colors.enterMediumGrey, fonts.primary, colors.enterDarkGrey]]]) + " " + 'companion-info'
11
- }, mainGuestName ? /*#__PURE__*/React.createElement(React.Fragment, null, "companion of ", /*#__PURE__*/React.createElement("span", {
9
+ }, "companion of", ' ', /*#__PURE__*/React.createElement("span", {
12
10
  className: _JSXStyle.dynamic([["21346984", [colors.enterMediumGrey, fonts.primary, colors.enterDarkGrey]]]) + " " + 'companion-name'
13
- }, mainGuestName)) : /*#__PURE__*/React.createElement(React.Fragment, null, "companion"), /*#__PURE__*/React.createElement(_JSXStyle, {
11
+ }, props.companionStatus.mainGuestName), /*#__PURE__*/React.createElement(_JSXStyle, {
14
12
  id: "21346984",
15
13
  dynamic: [colors.enterMediumGrey, fonts.primary, colors.enterDarkGrey]
16
14
  }, `.companion-info.__jsx-style-dynamic-selector{margin:-0.5em 0 0.4em;color:${colors.enterMediumGrey};font-family:${fonts.primary};}.companion-name.__jsx-style-dynamic-selector{color:${colors.enterDarkGrey};}`));
@@ -3,6 +3,5 @@ import { CompanionInfo } from './companion-info';
3
3
  declare const meta: Meta<typeof CompanionInfo>;
4
4
  export default meta;
5
5
  type Story = StoryObj<typeof CompanionInfo>;
6
- export declare const WithMainGuestFound: Story;
7
- export declare const WithoutMainGuest: Story;
6
+ export declare const WithMainGuest: Story;
8
7
  export declare const NotACompanion: Story;
@@ -1,57 +1,15 @@
1
1
  import { CompanionInfo } from './companion-info';
2
- import { Attendee } from '../models';
3
2
  const meta = {
4
3
  title: 'Companion Info',
5
- component: CompanionInfo,
6
- argTypes: {
7
- formatName: {
8
- type: 'function'
9
- }
10
- }
4
+ component: CompanionInfo
11
5
  };
12
6
  export default meta;
13
- const mainGuest = new Attendee({
14
- id: 'my-attendee',
15
- language: 'de',
16
- tags: ['VIP', 'Import-200-02-10'],
17
- time: new Date('2022-01-01').toISOString(),
18
- rsvp: {
19
- default: {
20
- personCount: 1,
21
- time: new Date('2022-01-01').toISOString(),
22
- tieBreaker: '1'
23
- }
24
- },
25
- checkin: {},
26
- companions: {
27
- isCompanion: false
28
- },
29
- userdata: {
30
- name: 'Max Mustermann'
31
- },
32
- deleted: false,
33
- payment: null
34
- });
35
- export const WithMainGuestFound = {
36
- args: {
37
- companionStatus: {
38
- isCompanion: true,
39
- mainGuestId: 'my-attendee'
40
- },
41
- findMainGuest: () => mainGuest,
42
- formatName(attendee) {
43
- return attendee.getFieldValueString('name');
44
- }
45
- }
46
- };
47
- export const WithoutMainGuest = {
7
+ export const WithMainGuest = {
48
8
  args: {
49
9
  companionStatus: {
50
10
  isCompanion: true,
51
- mainGuestId: 'my-attendee'
52
- },
53
- formatName(attendee) {
54
- return attendee.getFieldValueString('name');
11
+ mainGuestId: 'my-attendee',
12
+ mainGuestName: 'Max Mustermann'
55
13
  }
56
14
  }
57
15
  };
@@ -59,9 +17,6 @@ export const NotACompanion = {
59
17
  args: {
60
18
  companionStatus: {
61
19
  isCompanion: false
62
- },
63
- formatName(attendee) {
64
- return attendee.getFieldValueString('name');
65
20
  }
66
21
  }
67
22
  };
@@ -11,7 +11,6 @@ type Props = {
11
11
  formatName: (attendee: Attendee) => string;
12
12
  filterTags?: (tag: string) => boolean;
13
13
  getTagColor?: (tag: string) => string | undefined;
14
- findMainGuest?: (attendeeId: string) => Attendee | undefined;
15
14
  onClick?: (attendeeId: string) => void;
16
15
  };
17
16
  export declare const GuestCard: FunctionComponent<Props>;
@@ -37,9 +37,7 @@ export const GuestCard = props => {
37
37
  }, /*#__PURE__*/React.createElement("h2", {
38
38
  className: _JSXStyle.dynamic([["1739379681", [colors.enterGrey, colors.enterBackground, fonts.primary, props.dense ? '0.5em 0' : '1.5em 0']]]) + " " + 'name'
39
39
  }, props.formatName(props.attendee)), /*#__PURE__*/React.createElement(CompanionInfo, {
40
- companionStatus: props.attendee.companions,
41
- findMainGuest: props.findMainGuest,
42
- formatName: props.formatName
40
+ companionStatus: props.attendee.companions
43
41
  }), /*#__PURE__*/React.createElement(CheckinCountIndicator, {
44
42
  checkins: props.attendee.getCheckinsForBranch(props.branchName).getActiveCheckins(props.counterName),
45
43
  response: props.attendee.getResponse(props.branchName, props.counterName),
@@ -70,7 +70,8 @@ const companion = new Attendee({
70
70
  checkin: {},
71
71
  companions: {
72
72
  isCompanion: true,
73
- mainGuestId: 'my-attendee'
73
+ mainGuestId: 'my-attendee',
74
+ mainGuestName: 'Max Mustermann'
74
75
  },
75
76
  userdata: {
76
77
  name: 'John Doe'
@@ -88,7 +89,7 @@ export const WithBackground = {
88
89
  branchName: 'default',
89
90
  counterName: 'main',
90
91
  formatName(attendee) {
91
- return attendee.getFieldValueString('name');
92
+ return attendee.getFieldString('name');
92
93
  }
93
94
  }
94
95
  };
@@ -99,7 +100,7 @@ export const Plain = {
99
100
  branchName: 'default',
100
101
  counterName: 'main',
101
102
  formatName(attendee) {
102
- return attendee.getFieldValueString('name');
103
+ return attendee.getFieldString('name');
103
104
  }
104
105
  }
105
106
  };
@@ -110,7 +111,7 @@ export const Dense = {
110
111
  branchName: 'default',
111
112
  counterName: 'main',
112
113
  formatName(attendee) {
113
- return attendee.getFieldValueString('name');
114
+ return attendee.getFieldString('name');
114
115
  }
115
116
  }
116
117
  };
@@ -124,7 +125,7 @@ export const FilteredTags = {
124
125
  return allowedTags.includes(tag);
125
126
  },
126
127
  formatName(attendee) {
127
- return attendee.getFieldValueString('name');
128
+ return attendee.getFieldString('name');
128
129
  }
129
130
  }
130
131
  };
@@ -134,7 +135,7 @@ export const WithColorLabel = {
134
135
  branchName: 'default',
135
136
  counterName: 'main',
136
137
  formatName(attendee) {
137
- return attendee.getFieldValueString('name');
138
+ return attendee.getFieldString('name');
138
139
  },
139
140
  getTagColor(tag) {
140
141
  return tagColors[tag] ?? undefined;
@@ -147,7 +148,7 @@ export const WithMultipleColorLabels = {
147
148
  branchName: 'default',
148
149
  counterName: 'main',
149
150
  formatName(attendee) {
150
- return attendee.getFieldValueString('name');
151
+ return attendee.getFieldString('name');
151
152
  },
152
153
  getTagColor(tag) {
153
154
  return tagColors[tag] ?? undefined;
@@ -161,7 +162,7 @@ export const WithInfoText = {
161
162
  counterName: 'main',
162
163
  infoText: '🥦 Vegetarian',
163
164
  formatName(attendee) {
164
- return attendee.getFieldValueString('name');
165
+ return attendee.getFieldString('name');
165
166
  }
166
167
  }
167
168
  };
@@ -170,11 +171,8 @@ export const WithCompanion = {
170
171
  attendee: companion,
171
172
  branchName: 'default',
172
173
  counterName: 'main',
173
- findMainGuest: () => {
174
- return attendee;
175
- },
176
174
  formatName(attendee) {
177
- return attendee.getFieldValueString('name');
175
+ return attendee.getFieldString('name');
178
176
  }
179
177
  }
180
178
  };
@@ -184,7 +182,7 @@ export const WithCompanionButNoMainGuestInfo = {
184
182
  branchName: 'default',
185
183
  counterName: 'main',
186
184
  formatName(attendee) {
187
- return attendee.getFieldValueString('name');
185
+ return attendee.getFieldString('name');
188
186
  }
189
187
  }
190
188
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-crew-berlin/enter-js-utils",
3
- "version": "0.88.0",
3
+ "version": "0.89.0",
4
4
  "description": "utils such as vaildation and other helpers to work with data from the enter app",
5
5
  "files": [
6
6
  "dist",
@@ -79,6 +79,7 @@
79
79
  "dependencies": {
80
80
  "cookie": "^1.0.1",
81
81
  "jws": "^4.0.0",
82
+ "stable-hash": "^0.0.5",
82
83
  "styled-jsx": "^5.1.6",
83
84
  "uuid": "^9.0.0"
84
85
  }