@dev-crew-berlin/enter-js-utils 0.95.0 → 0.95.2

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.
@@ -221,6 +221,7 @@ export type components = {
221
221
  };
222
222
  companions?: components["schemas"]["RootModel_Union_Companion__MainGuest__-Input"];
223
223
  payment?: components["schemas"]["Payment"] | null;
224
+ partialPayment?: components["schemas"]["PartialPayment"];
224
225
  /** Branches */
225
226
  branches?: string[];
226
227
  /** Deletedbranches */
@@ -767,6 +768,16 @@ export type components = {
767
768
  */
768
769
  items: components["schemas"]["ItemOption"][];
769
770
  };
771
+ /**
772
+ * DynamicTag
773
+ * @description A tag with color and optional filter
774
+ */
775
+ DynamicTag: {
776
+ /** Color */
777
+ color: string;
778
+ /** @default {} */
779
+ filter?: components["schemas"]["Filter"];
780
+ };
770
781
  /** EmailField */
771
782
  EmailField: {
772
783
  /**
@@ -1006,6 +1017,11 @@ export type components = {
1006
1017
  /** Ext */
1007
1018
  ext: string[] | null;
1008
1019
  };
1020
+ /** Filter */
1021
+ Filter: {
1022
+ /** Query */
1023
+ query: string | null;
1024
+ };
1009
1025
  /** FrontendConfigJSON */
1010
1026
  FrontendConfigJSON: {
1011
1027
  /** Domain */
@@ -1246,13 +1262,34 @@ export type components = {
1246
1262
  */
1247
1263
  max: number;
1248
1264
  };
1265
+ /** PartialPayment */
1266
+ PartialPayment: {
1267
+ /** Paid */
1268
+ paid?: boolean;
1269
+ /** Amount */
1270
+ amount?: number;
1271
+ /**
1272
+ * Provider
1273
+ * @enum {string}
1274
+ */
1275
+ provider?: "manual" | "sepa" | "credit" | "bank_transfer" | "paypal" | "stripe";
1276
+ /**
1277
+ * Currency
1278
+ * @enum {string}
1279
+ */
1280
+ currency?: "USD" | "EUR" | "CHF";
1281
+ };
1249
1282
  /** Payment */
1250
1283
  Payment: {
1251
1284
  /** Paid */
1252
1285
  paid: boolean;
1253
1286
  /** Title */
1254
1287
  title?: string | null;
1255
- provider: components["schemas"]["PaymentProvider"];
1288
+ /**
1289
+ * Provider
1290
+ * @enum {string}
1291
+ */
1292
+ provider: "manual" | "sepa" | "credit" | "bank_transfer" | "paypal" | "stripe";
1256
1293
  /** Reference */
1257
1294
  reference?: string | null;
1258
1295
  /** Amount */
@@ -1288,10 +1325,9 @@ export type components = {
1288
1325
  attendeeId: string;
1289
1326
  /** Instancename */
1290
1327
  instanceName: string;
1291
- provider?: components["schemas"]["PaymentProvider"] | null;
1328
+ /** Provider */
1329
+ provider?: ("manual" | "sepa" | "credit" | "bank_transfer" | "paypal" | "stripe") | null;
1292
1330
  };
1293
- /** @enum {string} */
1294
- PaymentProvider: "manual" | "sepa" | "credit" | "bank_transfer" | "paypal" | "stripe";
1295
1331
  /** PublicAttendee */
1296
1332
  "PublicAttendee-Input": {
1297
1333
  /** Id */
@@ -1391,6 +1427,8 @@ export type components = {
1391
1427
  * @default false
1392
1428
  */
1393
1429
  deleted: boolean;
1430
+ /** Name */
1431
+ name: string;
1394
1432
  };
1395
1433
  /** PublicEmail */
1396
1434
  PublicEmail: {
@@ -1415,10 +1453,17 @@ export type components = {
1415
1453
  registration: components["schemas"]["PublicRegistrationInfo"];
1416
1454
  /** Guestnamefields */
1417
1455
  guestNameFields: string[];
1418
- /** Tagcolors */
1456
+ /**
1457
+ * Tagcolors
1458
+ * @deprecated
1459
+ */
1419
1460
  tagColors: {
1420
1461
  [key: string]: string;
1421
1462
  };
1463
+ /** Dynamictags */
1464
+ dynamicTags: {
1465
+ [key: string]: components["schemas"]["DynamicTag"];
1466
+ };
1422
1467
  /** Branches */
1423
1468
  branches: {
1424
1469
  [key: string]: components["schemas"]["Branch"];
@@ -11,6 +11,7 @@ export type AttendeeJSON = Omit<components['schemas']['PublicAttendee-Output'],
11
11
  };
12
12
  export declare class Attendee {
13
13
  id: string;
14
+ readonly name: string | undefined;
14
15
  userdata: Map<string, FieldValue>;
15
16
  tags: Set<string>;
16
17
  language: string | null;
@@ -20,17 +21,17 @@ export declare class Attendee {
20
21
  checkin: Map<string, Checkins>;
21
22
  companions: {
22
23
  isCompanion: false;
23
- companionNames?: {
24
+ readonly companionNames?: {
24
25
  [attendeeId: string]: string;
25
26
  };
26
27
  } | {
27
28
  isCompanion: true;
28
29
  mainGuestId: string;
29
- mainGuestName: string;
30
+ readonly mainGuestName: string;
30
31
  };
31
32
  payment: Payment | null;
32
33
  deleted: boolean;
33
- constructor(args: AttendeeJSONInput | string);
34
+ constructor(args: AttendeeJSONInput | AttendeeJSON | string);
34
35
  /**
35
36
  * creates a bse36 encoded uuid
36
37
  * we use base36 encoding because it is more human readable and also shorter
@@ -23,6 +23,7 @@ export class Attendee {
23
23
  }
24
24
  const json = args;
25
25
  this.id = json.id;
26
+ this.name = 'name' in json ? json.name : undefined;
26
27
  this.userdata = new Map(Object.entries(json.userdata ?? {}));
27
28
  this.tags = new Set(json.tags);
28
29
  this.language = json.language;
@@ -67,6 +68,7 @@ export class Attendee {
67
68
  const rsvp = Object.fromEntries(Array.from(this.rsvp).map(([checkinTag, rsvp]) => [checkinTag, rsvp ? rsvp.toJSON() : null]));
68
69
  return {
69
70
  ...this,
71
+ name: this.name ?? '',
70
72
  time: this.time?.toISOString(),
71
73
  branches: Array.from(this.branches),
72
74
  tags: Array.from(this.tags),
@@ -97,7 +99,7 @@ export class Attendee {
97
99
  getResponse(branchName, counterName) {
98
100
  const rsvp = this.rsvp.get(branchName) ?? null;
99
101
  if (rsvp === null) return 'no-response';
100
- if (!rsvp.checkinCounters.has(counterName)) 'no-response';
102
+ if (!rsvp.checkinCounters.has(counterName)) return 'no-response';
101
103
  return rsvp.confirmed ? 'positive-response' : 'negative-response';
102
104
  }
103
105
  getCheckinsForBranch(branchName) {
@@ -0,0 +1,2 @@
1
+ import { components } from '../generated/api-schema';
2
+ export type DynamicTag = components['schemas']['DynamicTag'];
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,7 @@
1
1
  import { components } from '../generated/api-schema';
2
2
  import { Attendee } from './attendee';
3
3
  import { Branch } from './branch';
4
+ import { DynamicTag } from './dynamic-tag';
4
5
  export type InstanceJSON = components['schemas']['PublicInstance'];
5
6
  export declare class Instance {
6
7
  name: string;
@@ -20,7 +21,7 @@ export declare class Instance {
20
21
  allowRegistrationWithAuthCode: boolean;
21
22
  };
22
23
  guestNameFields: string[];
23
- tagColors: Record<string, string>;
24
+ dynamicTags: Map<string, DynamicTag>;
24
25
  constructor(json: InstanceJSON);
25
26
  toJSON(): InstanceJSON;
26
27
  isRegistrationClosed(): boolean;
@@ -16,11 +16,13 @@ export class Instance {
16
16
  allowRegistrationWithAuthCode: json.registration.allowRegistrationWithAuthCode
17
17
  };
18
18
  this.guestNameFields = json.guestNameFields;
19
- this.tagColors = json.tagColors;
19
+ this.dynamicTags = new Map(Object.entries(json.dynamicTags));
20
20
  }
21
21
  toJSON() {
22
22
  // convert each branch to its json representation
23
23
  const branches = Object.fromEntries(Array.from(this.branches).map(([branchName, branch]) => [branchName, branch.toJSON()]));
24
+ const dynamicTags = Object.fromEntries(this.dynamicTags);
25
+ const tagColors = Object.fromEntries(Array.from(this.dynamicTags).map(([tag, dynamicTag]) => [tag, dynamicTag.color]));
24
26
  return {
25
27
  name: this.name,
26
28
  title: this.title,
@@ -37,7 +39,8 @@ export class Instance {
37
39
  allowRegistrationWithAuthCode: this.registration.allowRegistrationWithAuthCode
38
40
  },
39
41
  guestNameFields: this.guestNameFields,
40
- tagColors: this.tagColors
42
+ tagColors: tagColors,
43
+ dynamicTags: dynamicTags
41
44
  };
42
45
  }
43
46
  isRegistrationClosed() {
@@ -70,6 +73,6 @@ export class Instance {
70
73
  return this.guestNameFields.map(fieldKey => guest.userdata.get(fieldKey) ?? '').join(' ');
71
74
  }
72
75
  getTagColor(tag) {
73
- return this.tagColors[tag] ?? undefined;
76
+ return this.dynamicTags.get(tag)?.color;
74
77
  }
75
78
  }
@@ -45,7 +45,8 @@ export const GuestCard = props => {
45
45
  })), /*#__PURE__*/React.createElement("div", {
46
46
  className: _JSXStyle.dynamic([["1739379681", [colors.enterGrey, colors.enterBackground, fonts.primary, props.dense ? '0.5em 0' : '1.5em 0']]]) + " " + 'tag-list'
47
47
  }, tags.map(tag => /*#__PURE__*/React.createElement(Tag, {
48
- key: tag
48
+ key: tag,
49
+ color: getTagColor(tag)
49
50
  }, tag)), props.infoText && /*#__PURE__*/React.createElement("div", {
50
51
  className: _JSXStyle.dynamic([["1739379681", [colors.enterGrey, colors.enterBackground, fonts.primary, props.dense ? '0.5em 0' : '1.5em 0']]]) + " " + 'info'
51
52
  }, " ", props.infoText))), /*#__PURE__*/React.createElement(_JSXStyle, {
package/dist/ui/tag.d.ts CHANGED
@@ -2,6 +2,8 @@ import { FunctionComponent, ReactNode } from 'react';
2
2
  import 'styled-jsx';
3
3
  type Props = {
4
4
  children: ReactNode;
5
+ color?: string | null;
6
+ big?: boolean;
5
7
  };
6
8
  export declare const Tag: FunctionComponent<Props>;
7
9
  export {};
package/dist/ui/tag.js CHANGED
@@ -2,11 +2,21 @@ import _JSXStyle from "styled-jsx/style";
2
2
  import React from 'react';
3
3
  import 'styled-jsx';
4
4
  import { colors, fonts } from '../lib/theme';
5
+
6
+ // Decide on text color based on contrast to background color
7
+ function getContrastYIQ(hexcolor) {
8
+ const r = parseInt(hexcolor.substring(1, 3), 16);
9
+ const g = parseInt(hexcolor.substring(3, 5), 16);
10
+ const b = parseInt(hexcolor.substring(5, 7), 16);
11
+ const yiq = (r * 299 + g * 587 + b * 114) / 1000;
12
+ return yiq >= 128 ? 'black' : 'white';
13
+ }
5
14
  export const Tag = props => {
15
+ const textColor = getContrastYIQ(props.color ?? '#ffffff');
6
16
  return /*#__PURE__*/React.createElement("div", {
7
- className: _JSXStyle.dynamic([["3070421237", [fonts.primary, colors.enterDarkGrey, colors.enterGrey]]]) + " " + 'tag'
17
+ className: _JSXStyle.dynamic([["2799826206", [fonts.primary, props.big ? '14px' : '0.8em', textColor === 'black' ? colors.enterDarkGrey : 'white', props.color ? props.color : 'transparent', colors.enterGrey, props.big ? '7px 10px 5px 0' : '0 0 0.5em 0.5em']]]) + " " + 'tag'
8
18
  }, props.children, /*#__PURE__*/React.createElement(_JSXStyle, {
9
- id: "3070421237",
10
- dynamic: [fonts.primary, colors.enterDarkGrey, colors.enterGrey]
11
- }, `.tag.__jsx-style-dynamic-selector{font-family:${fonts.primary};font-size:0.8em;color:${colors.enterDarkGrey};text-transform:uppercase;display:inline-block;background-color:transparent;border-radius:2px;border:1px solid ${colors.enterGrey};padding:2px 8px;margin:0 0 0.5em 0.5em;word-wrap:anywhere;}`));
19
+ id: "2799826206",
20
+ dynamic: [fonts.primary, props.big ? '14px' : '0.8em', textColor === 'black' ? colors.enterDarkGrey : 'white', props.color ? props.color : 'transparent', colors.enterGrey, props.big ? '7px 10px 5px 0' : '0 0 0.5em 0.5em']
21
+ }, `.tag.__jsx-style-dynamic-selector{font-family:${fonts.primary};font-size:${props.big ? '14px' : '0.8em'};color:${textColor === 'black' ? colors.enterDarkGrey : 'white'};text-transform:uppercase;display:inline-block;background-color:${props.color ? props.color : 'transparent'};border-radius:2px;border:1px solid ${colors.enterGrey};padding:2px 8px;margin:${props.big ? '7px 10px 5px 0' : '0 0 0.5em 0.5em'};word-wrap:anywhere;}`));
12
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-crew-berlin/enter-js-utils",
3
- "version": "0.95.0",
3
+ "version": "0.95.2",
4
4
  "description": "utils such as vaildation and other helpers to work with data from the enter app",
5
5
  "files": [
6
6
  "dist",