Skip to content

Commit 0c8a0a3

Browse files
authored
Merge pull request #38 from workshopbutler/1.17.0
Add support for passing attendee properties over query string
2 parents 7b5ae2f + 6413863 commit 0c8a0a3

16 files changed

+638
-130
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ module.exports = {
164164
"no-undef-init": "error",
165165
"no-underscore-dangle": "error",
166166
"no-unsafe-finally": "error",
167-
"no-unused-expressions": "error",
167+
"no-unused-expressions": "warn",
168168
"no-unused-labels": "error",
169169
"no-var": "error",
170170
"object-shorthand": "error",

package-lock.json

Lines changed: 284 additions & 94 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "workshop_butler_widget",
3-
"version": "1.16.2",
3+
"version": "1.17.0",
44
"description": "Workshop Butler JS Widgets",
55
"author": "https://workshopbutler.com",
66
"license": "ISC",

site/pages/event-page.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
show: true,
2222
bio: true,
2323
},
24+
forwardSearchParams: true,
2425
trainerPageUrl: '/trainer-profile',
2526
registrationPageUrl: '/registration',
2627
expiredTickets: true,

site/pages/registration.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
trainers: {
2121
show: true,
2222
bio: true,
23-
}
23+
},
24+
forwardSearchParams: [{name: 'ref', to: 'first_name', hidden: true}, {
25+
name: 'name',
26+
to: '0421dc07',
27+
}]
2428
}
2529
];
2630
const config = {

src/models/Event.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export default class Event {
2525
const language = Language.fromJSON(json.language);
2626
const trainers = Event.getTrainers(json, options);
2727
const tickets = Event.getTickets(json.free, json.tickets);
28-
const registrationPage = new RegistrationPage(json.registration_page, options.registrationPageUrl, json.hashed_id);
28+
const registrationPage = new RegistrationPage(json.registration_page,
29+
options.registrationPageUrl, options.forwardSearchParams, json.hashed_id);
2930
const type = json.type ? (typeof json.type === 'number' ? json.type : new Type(json.type)) : undefined;
3031
const coverImage = CoverImage.fromJSON(json.cover_image);
3132
const category = json.category ? new Category(json.category) : undefined;

src/models/workshop/RegistrationPage.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
import IPlainObject from '../../interfaces/IPlainObject';
2+
import ForwardSearchParamsSetting, {
3+
ForwardSearchParamsSettingType,
4+
} from '../../widgets/config/ForwardSearchParamsSetting';
25

36
/**
47
* Contains the logic for the event registration
58
*/
69
export default class RegistrationPage {
710

8-
/**
9-
* Returns a correctly formed url for a registration page of the event
10-
* @param registrationPageUrl {string} Url of the page with RegistrationPage widget
11-
* @param eventId {string} Hashed event id
12-
*/
13-
protected static getInternalUrl(registrationPageUrl: string, eventId: string): string {
14-
return registrationPageUrl + `?id=${eventId}`;
15-
}
1611
readonly external: boolean;
1712
readonly url?: string;
13+
readonly passQueryParams: ForwardSearchParamsSetting;
1814

19-
constructor(attrs: IPlainObject, registrationUrl: string | null = null, eventId: string) {
15+
constructor(attrs: IPlainObject, registrationUrl: string | null = null,
16+
forwardSearchParams: ForwardSearchParamsSettingType,
17+
eventId: string) {
2018
if (attrs) {
2119
this.external = attrs.external;
2220
this.url = attrs.url;
2321
}
22+
this.passQueryParams = new ForwardSearchParamsSetting(forwardSearchParams);
2423
if (!this.external && registrationUrl) {
25-
this.url = RegistrationPage.getInternalUrl(registrationUrl, eventId);
24+
this.url = this.passQueryParams.createUrl(registrationUrl, {id: eventId});
2625
}
2726
}
2827

src/utils/validators.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export function isString(value: any): value is string {
2+
return typeof value === 'string';
3+
}
4+
export function isBoolean(value: any): value is boolean {
5+
return typeof value === 'boolean';
6+
}

src/widgets/RegistrationPage.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ export default class RegistrationPage extends Widget<RegistrationPageConfig> {
135135
this.getErrorMessages());
136136

137137
const paymentConfig = this.getPaymentConfig();
138-
const formConfig = new RegistrationFormConfig(this.event.id, this.config.successRedirectUrl);
138+
const formConfig = new RegistrationFormConfig(this.event.id,
139+
this.config.searchToFieldConfigs,
140+
this.config.successRedirectUrl);
139141
return new SharedRegistrationForm(this.$root.find('.wsb-body'), formHelper,
140142
formConfig, paymentConfig);
141143
}
@@ -144,7 +146,7 @@ export default class RegistrationPage extends Widget<RegistrationPageConfig> {
144146
const registerUrl = `attendees/register?api_key=${this.apiKey}&t=${this.getWidgetStats()}`;
145147
const preRegisterUrl = `attendees/pre-register?api_key=${this.apiKey}&t=${this.getWidgetStats()}`;
146148
const taxValidationUrl = `tax-validation/:number?api_key=${this.apiKey}&t=${this.getWidgetStats()}`
147-
+`&lang=${this.formatter.getLocale()}`;
149+
+ `&lang=${this.formatter.getLocale()}`;
148150

149151
return new PaymentConfig(this.event.cardPayment?.active || false, this.event.free,
150152
this.event.cardPayment?.testMode() || false, preRegisterUrl, registerUrl, taxValidationUrl,

src/widgets/config/EventPageConfig.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import {logError} from '../../common/Error';
22
import {absoluteURL, safeHref} from '../../common/helpers/UrlParser';
33
import IPlainObject from '../../interfaces/IPlainObject';
4-
import WidgetConfig from './WidgetConfig';
54
import CoverImageConfig from './CoverImageConfig';
65
import TrainersConfig from './TrainersConfig';
6+
import WidgetConfig from './WidgetConfig';
7+
import {ForwardSearchParamsSettingType, WithPassSearchParamsSetting} from './ForwardSearchParamsSetting';
78

89
/**
910
* Contains @EventPageConfig widget configuration options
1011
*/
11-
export default class EventPageConfig extends WidgetConfig {
12+
export default class EventPageConfig extends WidgetConfig implements WithPassSearchParamsSetting {
1213

1314
/**
1415
* Returns the config if the options are correct
@@ -86,6 +87,8 @@ export default class EventPageConfig extends WidgetConfig {
8687
*/
8788
readonly showAdditionalButton: boolean;
8889

90+
readonly forwardSearchParams: ForwardSearchParamsSettingType;
91+
8992
protected constructor(options: IPlainObject) {
9093
super(options);
9194
this.trainers = new TrainersConfig(options.trainers);
@@ -100,6 +103,7 @@ export default class EventPageConfig extends WidgetConfig {
100103
options.coverImage.width, options.coverImage.height) : new CoverImageConfig();
101104
this.eventPageUrl = safeHref();
102105
this.showAdditionalButton = options.showAdditionalButton !== undefined ? options.showAdditionalButton : false;
106+
this.forwardSearchParams = options.forwardSearchParams;
103107
}
104108

105109
}

0 commit comments

Comments
 (0)