summit-registration-lite 7.0.3 → 7.0.4

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.
Files changed (28) hide show
  1. package/.claude/rules/summit-registration-lite-component-props.md +95 -0
  2. package/.claude/rules/summit-registration-lite-i18n.md +62 -0
  3. package/.claude/rules/summit-registration-lite-payment-providers.md +69 -0
  4. package/.claude/rules/summit-registration-lite-project.md +80 -0
  5. package/.claude/rules/summit-registration-lite-redux-actions.md +65 -0
  6. package/.claude/rules/summit-registration-lite-step-flow.md +77 -0
  7. package/.claude/rules/summit-registration-lite-testing.md +97 -0
  8. package/.claude/rules/summit-registration-lite-utils.md +71 -0
  9. package/.claude/skills/summit-registration-lite-add-provider/SKILL.md +155 -0
  10. package/.claude/skills/summit-registration-lite-dev-setup/SKILL.md +67 -0
  11. package/.claude/skills/summit-registration-lite-publish/SKILL.md +64 -0
  12. package/.claude/skills/summit-registration-lite-scaffold-component/SKILL.md +152 -0
  13. package/.codegraph/config.json +141 -0
  14. package/.codegraph/daemon.pid +6 -0
  15. package/dist/components/index.css +1 -2
  16. package/dist/components/index.js +24 -52
  17. package/dist/components/index.js.map +1 -1
  18. package/dist/components/registration-form.css +1 -2
  19. package/dist/components/registration-form.js +20 -47
  20. package/dist/components/registration-form.js.map +1 -1
  21. package/dist/components/registration-modal.css +1 -2
  22. package/dist/components/registration-modal.js +23 -51
  23. package/dist/components/registration-modal.js.map +1 -1
  24. package/dist/index.css +1 -2
  25. package/dist/index.js +23 -51
  26. package/dist/index.js.map +1 -1
  27. package/e2e/promo-code-discovery.spec.js +4 -2
  28. package/package.json +1 -1
@@ -0,0 +1,95 @@
1
+ # Component Prop Conventions
2
+
3
+ ## When to Apply
4
+
5
+ Defining props for new components or understanding prop flow from widget to child components.
6
+
7
+ ## Pattern
8
+
9
+ **Widget Root (RegistrationLiteWidget):**
10
+
11
+ Parent app passes all props to widget, which wraps `<RegistrationLite>` in Redux Provider.
12
+
13
+ **Main Component (RegistrationLite):**
14
+
15
+ ```javascript
16
+ const RegistrationLite = ({
17
+ // Lifecycle callbacks (parent app control)
18
+ authUser, // (provider) => void - handle SSO login
19
+ goToExtraQuestions, // (attendeeId) => void - redirect to extra questions
20
+ goToEvent, // () => void - redirect to event page
21
+ goToMyOrders, // () => void - redirect to my orders
22
+ onPurchaseComplete, // (order) => void - handle successful purchase
23
+ closeWidget, // () => void - close/minimize widget
24
+
25
+ // Auth callbacks
26
+ getPasswordlessCode, // (email) => void - request OTP code
27
+ loginWithCode, // (email, code) => void - verify OTP
28
+ authErrorCallback, // (error) => void - handle auth errors
29
+
30
+ // Error handling
31
+ onError, // ({type, msg, exception}) => void
32
+ handleCompanyError, // (error) => void - company dropdown errors
33
+
34
+ // Data
35
+ summitData, // { id, name, time_zone, registration_disclaimer, ... }
36
+ profileData, // { email, first_name, last_name, company, ... }
37
+
38
+ // Config
39
+ apiBaseUrl, // Base URL for API calls
40
+ supportEmail, // Support email for help text
41
+ allowPromoCodes, // boolean - show/hide promo code field (default: true)
42
+ showCompanyInput, // boolean - show/hide company field (default: true)
43
+ allowsNativeAuth, // boolean - show email/password login
44
+ allowsOtpAuth, // boolean - show passwordless OTP login
45
+ loginOptions, // [{ button_color, provider_label, provider_param }]
46
+
47
+ // UI customization
48
+ loading, // boolean - external loading state
49
+ showMultipleTicketTexts, // boolean - show multi-ticket messaging
50
+ hidePostalCode, // boolean - hide postal code in payment (default: false)
51
+ idpLogoDark, // string - custom logo src (dark theme)
52
+ idpLogoLight, // string - custom logo src (light theme)
53
+
54
+ // Messages (optional overrides)
55
+ noAllowedTicketsMessage,
56
+ ticketTaxesErrorMessage,
57
+
58
+ // Provider options
59
+ providerOptions, // { stripe: {...}, lawpay: {...} }
60
+ successfulPaymentReturnUrl, // Stripe return URL after payment
61
+
62
+ // Redux state (from connect)
63
+ step, reservation, ticketTypes, taxTypes, ...
64
+
65
+ // Redux actions (from connect)
66
+ loadSession, changeStep, reserveTicket, payTicketWithProvider, ...
67
+ }) => { /* ... */ }
68
+ ```
69
+
70
+ ## Key Points
71
+
72
+ - **Callback pattern:** Parent app controls navigation (`goToExtraQuestions`, `goToEvent`, etc.) - widget doesn't redirect directly
73
+ - **Error handling delegation:** Widget calls `onError` / `authErrorCallback` / `handleCompanyError`, parent decides what to do
74
+ - **Data vs. Config:** `summitData` is event info, `profileData` is user info, others are config/behavior flags
75
+ - **Optional overrides:** Most text/messages have defaults but can be overridden via props
76
+ - **Redux separation:** Connected props (`step`, `reservation`) vs. passed props (callbacks, config)
77
+
78
+ ## Prop Flow Example
79
+
80
+ ```
81
+ Parent App
82
+ └─> RegistrationLiteWidget (wraps Provider)
83
+ └─> RegistrationLite (receives props + Redux state)
84
+ ├─> LoginComponent (loginOptions, allowsNativeAuth, allowsOtpAuth)
85
+ ├─> TicketTypeComponent (ticketTypes, summitData)
86
+ ├─> PersonalInfoComponent (profileData, showCompanyInput)
87
+ └─> PaymentComponent (reservation, providerOptions)
88
+ ```
89
+
90
+ ## Common Mistakes
91
+
92
+ - Hardcoding navigation instead of calling prop callbacks (breaks widget embedding)
93
+ - Not providing `apiBaseUrl` (causes API calls to fail)
94
+ - Forgetting `onError` handler (errors go to console only, user sees nothing)
95
+ - Passing incomplete `summitData` (missing `time_zone` breaks clock, missing `id` breaks API calls)
@@ -0,0 +1,62 @@
1
+ # i18n / Translation Pattern
2
+
3
+ ## When to Apply
4
+
5
+ Adding user-facing text to components or modifying existing strings.
6
+
7
+ ## Pattern
8
+
9
+ **Library:** `i18n-react` — imported as `T`.
10
+
11
+ **Setup (in `registration-lite.js`):**
12
+
13
+ ```javascript
14
+ import T from 'i18n-react';
15
+
16
+ // Loaded once at component init, falls back to English
17
+ try {
18
+ T.setTexts(require(`../i18n/${language}.json`));
19
+ } catch {
20
+ T.setTexts(require(`../i18n/en.json`));
21
+ }
22
+ ```
23
+
24
+ **Usage in components:**
25
+
26
+ ```javascript
27
+ import T from 'i18n-react';
28
+
29
+ // Simple key
30
+ T.translate("bar_button.next") // → "Next"
31
+
32
+ // With interpolation
33
+ T.translate("purchase_complete_step.footer_assistance_text", { supportEmail: "help@example.com" })
34
+ // Template: "For further assistance, please email <a href=\"mailto:{supportEmail}\">{supportEmail}</a>"
35
+ ```
36
+
37
+ ## Translation File Structure
38
+
39
+ `src/i18n/en.json` — flat namespaced by UI section:
40
+
41
+ ```json
42
+ {
43
+ "purchase_complete_step": { "title": "...", "initial_order_complete_button": "..." },
44
+ "ticket_type": { "ticket_quantity_tooltip": "..." },
45
+ "promo_code": { "promo_code_tooltip": "..." },
46
+ "bar_button": { "back": "Back", "next": "Next", "get_ticket": "Get Ticket", "pay_now": "Pay Now", "loading": "Loading" }
47
+ }
48
+ ```
49
+
50
+ ## Key Points
51
+
52
+ - Namespace keys by component/step: `"section_name.key_name"`
53
+ - Interpolation uses `{variableName}` syntax (not `${}` or `%s`)
54
+ - HTML is allowed in translation values (rendered as-is)
55
+ - Only English (`en.json`) exists — add new languages as `{lang}.json` in `src/i18n/`
56
+ - Components using text must `import T from 'i18n-react'`
57
+
58
+ ## Common Mistakes
59
+
60
+ - Hardcoding user-facing strings instead of using `T.translate()`
61
+ - Adding keys without updating `en.json` (renders the key path as literal text)
62
+ - Using wrong namespace (check `en.json` for existing sections before creating new ones)
@@ -0,0 +1,69 @@
1
+ # Payment Provider Integration
2
+
3
+ ## When to Apply
4
+
5
+ Adding or modifying payment providers (Stripe, LawPay, or new providers).
6
+
7
+ ## Pattern
8
+
9
+ **Factory Pattern:** `PaymentProviderFactory.build(provider, params)` returns provider instance.
10
+
11
+ **Provider Structure:**
12
+
13
+ ```javascript
14
+ export class NewProvider {
15
+ constructor({ reservation, summitId, userProfile, access_token, apiBaseUrl, dispatch }) {
16
+ // Store params as instance properties
17
+ this.reservation = reservation;
18
+ this.summitId = summitId;
19
+ // ... etc
20
+ }
21
+
22
+ payTicket = ({ /* provider-specific params */, onError = () => {} }) => async (dispatch) => {
23
+ // 1. Custom error handler for HTTP status codes
24
+ const errorHandler = (err, res) => (dispatch, state) => {
25
+ switch (err.status) {
26
+ case 404: onError({type: ERROR_TYPE_VALIDATION, msg: res.body.message, exception: null}); break;
27
+ case 500: onError({type: ERROR_TYPE_ERROR, msg: res.body.message, exception: null}); break;
28
+ default: authErrorHandler(err, res)(dispatch, state); break;
29
+ }
30
+ };
31
+
32
+ // 2. Free/prepaid orders skip payment gateway
33
+ if (isFreeOrder(this.reservation) || isPrePaidOrder(this.reservation)) {
34
+ return putRequest(/* ... checkout endpoint ... */)(params)(this.dispatch);
35
+ }
36
+
37
+ // 3. Payment gateway flow (provider-specific)
38
+ // Call gateway API, handle result, then checkout
39
+ }
40
+ }
41
+ ```
42
+
43
+ **Factory Registration:**
44
+
45
+ ```javascript
46
+ // src/utils/payment-providers/payment-provider-factory.js
47
+ import { NEW_PROVIDER } from '../constants';
48
+ import { NewProvider } from './new-provider';
49
+
50
+ case NEW_PROVIDER: {
51
+ currentProvider = new NewProvider({...params});
52
+ break;
53
+ }
54
+ ```
55
+
56
+ ## Key Points
57
+
58
+ - Free/prepaid orders always skip gateway, go straight to `/checkout` endpoint
59
+ - Error types: `ERROR_TYPE_VALIDATION` (404), `ERROR_TYPE_ERROR` (500), `ERROR_TYPE_PAYMENT` (gateway errors)
60
+ - Always dispatch `startWidgetLoading()` before async ops, `stopWidgetLoading()` after
61
+ - Success flow: checkout API → `CLEAR_RESERVATION` → `changeStep(STEP_COMPLETE)`
62
+ - Failure flow: `removeReservedTicket()` → `changeStep(STEP_PERSONAL_INFO)`
63
+ - Checkout endpoint requires billing address fields from `userProfile`
64
+
65
+ ## Common Mistakes
66
+
67
+ - Forgetting to handle free/prepaid orders (they don't have `payment_gateway_client_token`)
68
+ - Not calling `removeReservedTicket()` on payment failure (leaves stale reservation)
69
+ - Missing `stopWidgetLoading()` in catch blocks (spinner never stops)
@@ -0,0 +1,80 @@
1
+ # Project: Summit Registration Lite
2
+
3
+ **Last Updated:** 2026-03-05
4
+
5
+ ## Overview
6
+
7
+ React widget for summit registration supporting authentication, ticket selection, payment processing, and order completion. Published as NPM package, designed to be embedded in parent applications.
8
+
9
+ ## Technology Stack
10
+
11
+ - **Language:** JavaScript (ES6+)
12
+ - **Framework:** React 16+ with Redux for state management
13
+ - **Build Tool:** Webpack 5 (dev/prod configs)
14
+ - **Testing:** Jest with @testing-library/react
15
+ - **Package Manager:** Yarn
16
+ - **Key Libraries:**
17
+ - openstack-uicore-foundation (HTTP utils, actions)
18
+ - redux-persist (state persistence)
19
+ - Stripe.js and custom payment providers
20
+ - Material-UI (@mui/material)
21
+
22
+ ## Directory Structure
23
+
24
+ ```
25
+ summit-registration-lite/
26
+ ├── src/
27
+ │ ├── components/ # React components (login, payment, tickets, etc.)
28
+ │ ├── utils/
29
+ │ │ ├── payment-providers/ # Stripe, LawPay provider implementations
30
+ │ │ ├── hooks/ # Custom React hooks
31
+ │ │ └── constants.js # Step constants, error types
32
+ │ ├── helpers/ # Formatting utilities
33
+ │ ├── actions.js # Redux action creators (API calls)
34
+ │ ├── reducer.js # Redux reducer
35
+ │ ├── store.js # Redux store configuration
36
+ │ └── summit-registration-lite.js # Main widget export
37
+ ├── webpack.common.js
38
+ ├── webpack.dev.js
39
+ ├── webpack.prod.js
40
+ └── babel.config.js
41
+ ```
42
+
43
+ ## Key Files
44
+
45
+ - **Entry:** `src/summit-registration-lite.js` - Provider wrapper, exports widget and standalone login components
46
+ - **Main Component:** `src/components/registration-lite.js` - Multi-step registration flow
47
+ - **Actions:** `src/actions.js` - API integration (ticket types, reservations, payments)
48
+ - **Payment:** `src/utils/payment-providers/` - Factory pattern for payment provider abstraction
49
+ - **Config:** `webpack.common.js` - Shared webpack configuration
50
+
51
+ ## Development Commands
52
+
53
+ | Task | Command |
54
+ |------|---------|
55
+ | Install | `yarn` |
56
+ | Dev Server | `yarn serve` |
57
+ | Build Dev | `yarn build-dev` |
58
+ | Build Prod | `yarn build` |
59
+ | Test (watch) | `yarn test` |
60
+ | Clean | `yarn clean` |
61
+ | Publish | `yarn publish-package` |
62
+
63
+ ## Architecture Notes
64
+
65
+ - **State:** Redux with redux-persist for cross-session state
66
+ - **API Base:** Configurable via props (`apiBaseUrl`), uses openstack-uicore-foundation HTTP utils
67
+ - **Payment Providers:** Factory pattern (`PaymentProviderFactory`) supports Stripe and LawPay
68
+ - **Steps:** Multi-step flow defined in `utils/constants.js` (login, personal info, payment, complete)
69
+ - **Auth:** Supports native auth, OTP (passwordless), and configurable SSO providers via `loginOptions` prop
70
+ - **Integration:** Widget receives callbacks (`authUser`, `goToExtraQuestions`, `onPurchaseComplete`, etc.) for parent app control
71
+
72
+ ## Testing
73
+
74
+ - Jest configuration in `package.json`
75
+ - Component tests in `__tests__` directories alongside components
76
+ - Mock files for static assets (`src/__mocks__/fileMock.js`)
77
+
78
+ ## Debug Mode
79
+
80
+ URL hash override for testing time-based logic: `#now=2020-06-03,10:59:50` (summit timezone)
@@ -0,0 +1,65 @@
1
+ # Redux API Action Patterns
2
+
3
+ ## When to Apply
4
+
5
+ Creating new API actions or modifying existing ones in `src/actions.js`.
6
+
7
+ ## Pattern
8
+
9
+ **Action Structure (openstack-uicore-foundation):**
10
+
11
+ ```javascript
12
+ export const GET_DATA = 'GET_DATA';
13
+
14
+ export const getData = (summitId) => async (dispatch, getState) => {
15
+ const { apiBaseUrl } = getState().registration;
16
+
17
+ const params = {
18
+ access_token: await accessTokenSelector()(dispatch, getState),
19
+ expand: 'relations,nested.relations'
20
+ };
21
+
22
+ return getRequest(
23
+ null,
24
+ createAction(GET_DATA),
25
+ `${apiBaseUrl}/api/v1/summits/${summitId}/resource`,
26
+ customErrorHandler // optional
27
+ )(params)(dispatch);
28
+ };
29
+ ```
30
+
31
+ **Error Handling:**
32
+
33
+ ```javascript
34
+ const customErrorHandler = (err, res) => (dispatch, state) => {
35
+ if (err.timeout) return err;
36
+ if (res?.statusCode === 404) return err; // Handle specific codes
37
+ if (res?.statusCode === 500) return err;
38
+ return authErrorHandler(err, res)(dispatch, state); // Default auth handling
39
+ };
40
+ ```
41
+
42
+ **Reducer Convention:**
43
+
44
+ ```javascript
45
+ case GET_DATA: {
46
+ return {...state, data: payload.response};
47
+ }
48
+ ```
49
+
50
+ ## Key Points
51
+
52
+ - Actions exported as constants (`export const ACTION_NAME`) AND action creators (`export const actionName`)
53
+ - Use `createAction()` from openstack-uicore-foundation for action creators
54
+ - HTTP methods: `getRequest`, `postRequest`, `putRequest`, `deleteRequest`
55
+ - Always pass `params` object with `access_token` (use `accessTokenSelector()` or widget prop)
56
+ - Use `expand` param for nested relations (dot notation: `tickets.owner.extra_questions`)
57
+ - Custom error handlers must return `authErrorHandler` as default case
58
+ - Thunk signature: `(dispatch, getState) => { ... }`
59
+
60
+ ## Common Mistakes
61
+
62
+ - Forgetting to await `accessTokenSelector()` (results in Promise instead of token)
63
+ - Not handling 404/500 in custom error handlers (triggers unwanted auth errors)
64
+ - Hardcoding API base URL (always use `state.registration.apiBaseUrl` or prop)
65
+ - Missing `expand` params (causes N+1 queries or missing data in components)
@@ -0,0 +1,77 @@
1
+ # Multi-Step Registration Flow
2
+
3
+ ## When to Apply
4
+
5
+ Adding step-specific logic, modifying step transitions, or rendering step-dependent UI.
6
+
7
+ ## Step Constants
8
+
9
+ Defined in `src/utils/constants.js`:
10
+
11
+ ```javascript
12
+ export const STEP_SELECT_TICKET_TYPE = 0; // Ticket selection + promo code
13
+ export const STEP_PERSONAL_INFO = 1; // Attendee details + ticket assignment
14
+ export const STEP_PAYMENT = 2; // Payment form (Stripe/LawPay)
15
+ export const STEP_COMPLETE = 3; // Order confirmation
16
+ ```
17
+
18
+ ## Step Transitions
19
+
20
+ **Forward flow (happy path):**
21
+
22
+ ```
23
+ STEP_SELECT_TICKET_TYPE → (Next/validate promo) → STEP_PERSONAL_INFO
24
+ STEP_PERSONAL_INFO → (submit form) → reserveTicket → STEP_PAYMENT
25
+ STEP_PAYMENT → (pay) → payTicketWithProvider → STEP_COMPLETE
26
+ ```
27
+
28
+ **Special cases:**
29
+
30
+ | Scenario | Transition |
31
+ |----------|------------|
32
+ | Free ticket (cost === 0) | `STEP_PERSONAL_INFO` → skip payment → `STEP_COMPLETE` |
33
+ | Pre-paid ticket | `STEP_PERSONAL_INFO` → skip payment → `STEP_COMPLETE` |
34
+ | Payment failure | `STEP_PAYMENT` → `removeReservedTicket()` → `STEP_PERSONAL_INFO` |
35
+ | No ticket selected + back | Any step → `STEP_SELECT_TICKET_TYPE` |
36
+
37
+ **Back navigation:**
38
+
39
+ - From `STEP_PERSONAL_INFO`: `changeStep(step - 1)`
40
+ - From `STEP_PAYMENT`: `removeReservedTicket()` (clears reservation, reducer resets to `STEP_PERSONAL_INFO`)
41
+
42
+ ## Redux Integration
43
+
44
+ ```javascript
45
+ // Action
46
+ export const changeStep = (step) => (dispatch, getState) => {
47
+ dispatch(createAction(CHANGE_STEP)(step));
48
+ };
49
+
50
+ // Reducer
51
+ case CHANGE_STEP: {
52
+ return { ...state, step: payload };
53
+ }
54
+ ```
55
+
56
+ Default state: `step: STEP_SELECT_TICKET_TYPE`
57
+
58
+ ## Rendering Pattern
59
+
60
+ In `registration-lite.js`, each step renders conditionally:
61
+
62
+ ```javascript
63
+ <StepComponent isActive={step === STEP_SELECT_TICKET_TYPE} ... />
64
+ <StepComponent isActive={step === STEP_PERSONAL_INFO} ... />
65
+ <StepComponent isActive={step === STEP_PAYMENT} ... />
66
+ {step === STEP_COMPLETE && <PurchaseCompleteComponent ... />}
67
+ ```
68
+
69
+ - Steps 0-2 share layout with `ButtonBarComponent`
70
+ - Step 3 (complete) has its own layout, no button bar
71
+ - Button bar renders step-specific buttons based on current `step` value
72
+
73
+ ## Common Mistakes
74
+
75
+ - Skipping `removeReservedTicket()` when going back from payment (leaves stale reservation)
76
+ - Not checking `reservation` existence before allowing forward navigation
77
+ - Adding steps without updating `ButtonBarComponent` (buttons won't render for new step)
@@ -0,0 +1,97 @@
1
+ # Testing Patterns
2
+
3
+ ## When to Apply
4
+
5
+ Writing new component tests or maintaining existing tests.
6
+
7
+ ## Pattern
8
+
9
+ **Test Structure:**
10
+
11
+ ```javascript
12
+ import React from 'react';
13
+ import { render, fireEvent, waitFor, screen } from '@testing-library/react';
14
+ import '@testing-library/jest-dom';
15
+ import ComponentName from '..';
16
+
17
+ const mockCallback = jest.fn();
18
+
19
+ afterEach(() => {
20
+ jest.clearAllMocks(); // Reset mocks between tests
21
+ });
22
+
23
+ it('describes expected behavior', () => {
24
+ const { getByTestId, getAllByTestId, queryByText } = render(
25
+ <ComponentName prop1={value1} callback={mockCallback} />
26
+ );
27
+
28
+ // Arrange: find elements
29
+ const button = getByTestId('button-id');
30
+
31
+ // Act: interact
32
+ fireEvent.click(button);
33
+
34
+ // Assert: verify outcome
35
+ expect(mockCallback).toHaveBeenCalledWith(expectedArg);
36
+ });
37
+ ```
38
+
39
+ **Common Queries:**
40
+
41
+ ```javascript
42
+ // Single element (throws if not found)
43
+ getByTestId('id') // data-testid attribute
44
+ getByText('text') // visible text content
45
+ getByRole('button') // ARIA role
46
+
47
+ // Multiple elements
48
+ getAllByTestId('id') // returns array
49
+
50
+ // Nullable queries (returns null if not found)
51
+ queryByText('text') // useful for "expect().toBeFalsy()"
52
+
53
+ // From screen utility
54
+ screen.queryByText('text')
55
+ ```
56
+
57
+ **Async Testing:**
58
+
59
+ ```javascript
60
+ it('handles async behavior', async () => {
61
+ const { getByTestId } = render(<Component />);
62
+
63
+ fireEvent.click(getByTestId('async-button'));
64
+
65
+ await waitFor(() => {
66
+ expect(getByTestId('result')).toBeInTheDocument();
67
+ });
68
+ });
69
+ ```
70
+
71
+ ## Key Points
72
+
73
+ - Tests live in `__tests__/` directories alongside components
74
+ - Use `data-testid` attributes for reliable element selection
75
+ - Mock callbacks with `jest.fn()`, verify with `.toHaveBeenCalled()` or `.toHaveBeenCalledWith()`
76
+ - Use `queryBy*` for negative assertions (`expect().toBeFalsy()`)
77
+ - Use `getBy*` for positive assertions (throws if element missing)
78
+ - `@testing-library/react` auto-cleanup enabled (no manual unmount needed)
79
+ - CSS/SCSS mocked via `identity-obj-proxy` (className checks work)
80
+ - Static assets (images) mocked via `src/__mocks__/fileMock.js`
81
+
82
+ ## Test Organization
83
+
84
+ ```
85
+ src/components/my-component/
86
+ ├── index.js
87
+ ├── my-component.module.scss
88
+ └── __tests__/
89
+ └── my-component.test.js
90
+ ```
91
+
92
+ ## Common Mistakes
93
+
94
+ - Using brittle selectors (text content that changes) instead of `data-testid`
95
+ - Forgetting `@testing-library/jest-dom` import (causes `.toBeInTheDocument()` to fail)
96
+ - Not awaiting async operations (tests pass locally, fail in CI due to timing)
97
+ - Testing implementation details instead of user behavior (prefer user interactions over internal state checks)
@@ -0,0 +1,71 @@
1
+ # Utility Functions
2
+
3
+ ## When to Apply
4
+
5
+ Working with ticket pricing, order status checks, payment provider resolution, or UI color logic.
6
+
7
+ ## Key Functions (`src/utils/utils.js`)
8
+
9
+ ### Order/Ticket Status Checks
10
+
11
+ ```javascript
12
+ isFreeOrder(reservation) // reservation.amount === 0
13
+ isPrePaidOrder(reservation) // status === 'Paid' && payment_method === 'Offline'
14
+ isPrePaidTicketType(ticketType) // ticketType.sub_type === 'PrePaid'
15
+ hasDiscountApplied(ticketType) // has cost_with_applied_discount !== cost
16
+ ```
17
+
18
+ Used in payment providers to decide whether to skip the payment gateway.
19
+
20
+ ### Pricing Display
21
+
22
+ ```javascript
23
+ getTicketCost(ticket, quantity) // Returns JSX: strikethrough original + discounted price, or just price
24
+ getTicketTaxes(ticket, taxes) // Returns tax label string: " plus Tax A & Tax B"
25
+ formatCurrency(amount, { currency }) // From helpers/ — locale-aware currency formatting
26
+ ```
27
+
28
+ ### Payment Provider Resolution
29
+
30
+ ```javascript
31
+ getCurrentProvider(summit)
32
+ // Iterates summit.payment_profiles for application_type === 'Registration'
33
+ // Returns { publicKey, provider } — uses test vs live key based on test_mode_enabled
34
+ ```
35
+
36
+ ### UI Helpers
37
+
38
+ ```javascript
39
+ getContrastingTextColor(bgColor, lightColor, darkColor) // WCAG luminance contrast
40
+ parseColor(input, element) // Resolves CSS variables to RGB
41
+ removeWhiteSpaces(value) // Strip all whitespace
42
+ isEmptyString(val) // Trim-aware empty check
43
+ ```
44
+
45
+ ### Error Tracking
46
+
47
+ ```javascript
48
+ handleSentryException(err) // Sends to Sentry if window.SENTRY_DSN is set, else console.log
49
+ ```
50
+
51
+ ### Analytics
52
+
53
+ ```javascript
54
+ buildTrackEvent(data, ticketQuantity, promoCode)
55
+ // Builds GA4-style event data with currency, items_array, discount
56
+ ```
57
+
58
+ ## Helper Exports (`src/helpers/`)
59
+
60
+ Barrel export from `src/helpers/index.js`:
61
+
62
+ - `capitalizeFirstLetter` — text formatting
63
+ - `formatCurrency` — locale-aware currency display
64
+ - `formatErrorMessage` — error message normalization
65
+ - `getTicketMaxQuantity` — ticket quantity constraints
66
+
67
+ ## Common Mistakes
68
+
69
+ - Using `reservation.amount === 0` directly instead of `isFreeOrder()` (misses edge cases)
70
+ - Forgetting `isPrePaidOrder()` check alongside `isFreeOrder()` in payment flows
71
+ - Not handling `getCurrentProvider()` returning `{ publicKey: null, provider: '' }` when no payment profile exists