@scalemule/nextjs 0.0.42 → 0.1.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/dist/index.d.mts +102 -2
- package/dist/index.d.ts +102 -2
- package/dist/index.js +337 -0
- package/dist/index.mjs +337 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import { ReactNode, ReactElement } from 'react';
|
|
3
3
|
import { MoneyClient } from '@scalemule/money';
|
|
4
4
|
export { MoneyClient, MoneyClientConfig, createMoneyClient } from '@scalemule/money';
|
|
5
5
|
import { RealtimeService } from '@scalemule/sdk';
|
|
@@ -346,6 +346,106 @@ interface UseShareReturn {
|
|
|
346
346
|
}
|
|
347
347
|
declare function useShare(options?: UseShareOptions): UseShareReturn;
|
|
348
348
|
|
|
349
|
+
/**
|
|
350
|
+
* Public types for the feedback hook + widget.
|
|
351
|
+
*
|
|
352
|
+
* Mirrors the JSON shape returned by `scalemule-feedback`'s public endpoints
|
|
353
|
+
* (`/v1/feedback/submit`, `/v1/feedback/items`). Dashboard/admin shapes live
|
|
354
|
+
* server-side and are not exported here — customer apps interact with the
|
|
355
|
+
* SDK only through the end-user surface.
|
|
356
|
+
*/
|
|
357
|
+
type FeedbackType = 'bug_report' | 'feature_request' | 'improvement' | 'other';
|
|
358
|
+
type FeedbackStatus = 'new' | 'reviewed' | 'planned' | 'in_progress' | 'completed' | 'declined';
|
|
359
|
+
type FeedbackPriority = 'low' | 'medium' | 'high' | 'urgent';
|
|
360
|
+
/**
|
|
361
|
+
* The end-user-visible shape of a feedback item. Excludes staff-only fields
|
|
362
|
+
* (assigned_to, internal_notes, email of OTHER users, etc.) that the service
|
|
363
|
+
* never returns through `/items`.
|
|
364
|
+
*/
|
|
365
|
+
interface FeedbackItem {
|
|
366
|
+
id: string;
|
|
367
|
+
type: FeedbackType;
|
|
368
|
+
title: string;
|
|
369
|
+
description: string;
|
|
370
|
+
status: FeedbackStatus;
|
|
371
|
+
priority: FeedbackPriority;
|
|
372
|
+
tags: string[] | null;
|
|
373
|
+
created_at: string;
|
|
374
|
+
updated_at: string;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Body for `POST /v1/feedback/submit`.
|
|
378
|
+
*
|
|
379
|
+
* `email` is required when no end-user session is present — the gateway omits
|
|
380
|
+
* `x-user-id` in that case and the service rejects with 400 unless email is
|
|
381
|
+
* given. When a session exists, email is optional.
|
|
382
|
+
*/
|
|
383
|
+
interface FeedbackItemInput {
|
|
384
|
+
type: FeedbackType;
|
|
385
|
+
title: string;
|
|
386
|
+
description: string;
|
|
387
|
+
email?: string;
|
|
388
|
+
tags?: string[];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
interface UseFeedbackOptions {
|
|
392
|
+
/** Optional status filter applied to the list call. */
|
|
393
|
+
status?: FeedbackStatus;
|
|
394
|
+
/** Optional type filter. */
|
|
395
|
+
type?: FeedbackType;
|
|
396
|
+
/** When false, suppress the initial list fetch (the widget submits without listing). */
|
|
397
|
+
enabled?: boolean;
|
|
398
|
+
}
|
|
399
|
+
interface UseFeedbackResult {
|
|
400
|
+
/** End-user's own feedback items for the current tenant. Empty when not signed in. */
|
|
401
|
+
items: FeedbackItem[];
|
|
402
|
+
loading: boolean;
|
|
403
|
+
error: ApiError | null;
|
|
404
|
+
/** Submit a new feedback item. Returns the persisted item on success. */
|
|
405
|
+
submit: (input: FeedbackItemInput) => Promise<FeedbackItem>;
|
|
406
|
+
/** Re-fetch the list. */
|
|
407
|
+
refresh: () => Promise<void>;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Hook for end-user feedback submission and read-own.
|
|
411
|
+
*
|
|
412
|
+
* Calls go through `client` from `ScaleMuleProvider`, which attaches the
|
|
413
|
+
* configured API key and (when present) the user session token. Tenancy
|
|
414
|
+
* (`x-app-id`) is derived by the gateway from the API key — never set
|
|
415
|
+
* client-side.
|
|
416
|
+
*/
|
|
417
|
+
declare function useFeedback(options?: UseFeedbackOptions): UseFeedbackResult;
|
|
418
|
+
|
|
419
|
+
interface FeedbackWidgetProps {
|
|
420
|
+
/** Floating-button corner. Default `bottom-right`. */
|
|
421
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
422
|
+
/** Default selected type when the modal opens. Default `feature_request`. */
|
|
423
|
+
defaultType?: FeedbackType;
|
|
424
|
+
/** Restrict the type select to this subset. Default: all four types. */
|
|
425
|
+
allowedTypes?: FeedbackType[];
|
|
426
|
+
/** Trigger button label. Default `Feedback`. */
|
|
427
|
+
triggerLabel?: string;
|
|
428
|
+
/** `light`/`dark`/`auto` (matches OS). Default `auto`. */
|
|
429
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
430
|
+
/** Optional class for the trigger button (use to override styling). */
|
|
431
|
+
className?: string;
|
|
432
|
+
/** Called after a successful submit. */
|
|
433
|
+
onSubmitted?: (item: FeedbackItem) => void;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Floating feedback widget. Renders nothing until the trigger is clicked,
|
|
437
|
+
* then opens a small modal with type / title / description fields. Submits
|
|
438
|
+
* via `useFeedback().submit()` — inherits identity from `ScaleMuleProvider`.
|
|
439
|
+
*
|
|
440
|
+
* If the end-user is not signed in, the widget shows an additional `email`
|
|
441
|
+
* field (required by the service for anonymous submissions).
|
|
442
|
+
*
|
|
443
|
+
* Tenant must have `feedback_app_config.enabled = TRUE` for `/submit` to
|
|
444
|
+
* accept submissions; otherwise the service responds with 404
|
|
445
|
+
* `FEEDBACK_DISABLED` and the widget surfaces the error message.
|
|
446
|
+
*/
|
|
447
|
+
declare function FeedbackWidget(props: FeedbackWidgetProps): ReactElement | null;
|
|
448
|
+
|
|
349
449
|
/**
|
|
350
450
|
* Client-side validation helpers
|
|
351
451
|
*
|
|
@@ -504,4 +604,4 @@ declare function createSafeLogger(prefix: string): {
|
|
|
504
604
|
error: (message: string, data?: unknown) => void;
|
|
505
605
|
};
|
|
506
606
|
|
|
507
|
-
export { ApiError, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, ListFilesParams, LoginResponse, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAuth, useBilling, useContent, useFeatureFlags, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useUser, validateForm, validators };
|
|
607
|
+
export { ApiError, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useUser, validateForm, validators };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import { ReactNode, ReactElement } from 'react';
|
|
3
3
|
import { MoneyClient } from '@scalemule/money';
|
|
4
4
|
export { MoneyClient, MoneyClientConfig, createMoneyClient } from '@scalemule/money';
|
|
5
5
|
import { RealtimeService } from '@scalemule/sdk';
|
|
@@ -346,6 +346,106 @@ interface UseShareReturn {
|
|
|
346
346
|
}
|
|
347
347
|
declare function useShare(options?: UseShareOptions): UseShareReturn;
|
|
348
348
|
|
|
349
|
+
/**
|
|
350
|
+
* Public types for the feedback hook + widget.
|
|
351
|
+
*
|
|
352
|
+
* Mirrors the JSON shape returned by `scalemule-feedback`'s public endpoints
|
|
353
|
+
* (`/v1/feedback/submit`, `/v1/feedback/items`). Dashboard/admin shapes live
|
|
354
|
+
* server-side and are not exported here — customer apps interact with the
|
|
355
|
+
* SDK only through the end-user surface.
|
|
356
|
+
*/
|
|
357
|
+
type FeedbackType = 'bug_report' | 'feature_request' | 'improvement' | 'other';
|
|
358
|
+
type FeedbackStatus = 'new' | 'reviewed' | 'planned' | 'in_progress' | 'completed' | 'declined';
|
|
359
|
+
type FeedbackPriority = 'low' | 'medium' | 'high' | 'urgent';
|
|
360
|
+
/**
|
|
361
|
+
* The end-user-visible shape of a feedback item. Excludes staff-only fields
|
|
362
|
+
* (assigned_to, internal_notes, email of OTHER users, etc.) that the service
|
|
363
|
+
* never returns through `/items`.
|
|
364
|
+
*/
|
|
365
|
+
interface FeedbackItem {
|
|
366
|
+
id: string;
|
|
367
|
+
type: FeedbackType;
|
|
368
|
+
title: string;
|
|
369
|
+
description: string;
|
|
370
|
+
status: FeedbackStatus;
|
|
371
|
+
priority: FeedbackPriority;
|
|
372
|
+
tags: string[] | null;
|
|
373
|
+
created_at: string;
|
|
374
|
+
updated_at: string;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Body for `POST /v1/feedback/submit`.
|
|
378
|
+
*
|
|
379
|
+
* `email` is required when no end-user session is present — the gateway omits
|
|
380
|
+
* `x-user-id` in that case and the service rejects with 400 unless email is
|
|
381
|
+
* given. When a session exists, email is optional.
|
|
382
|
+
*/
|
|
383
|
+
interface FeedbackItemInput {
|
|
384
|
+
type: FeedbackType;
|
|
385
|
+
title: string;
|
|
386
|
+
description: string;
|
|
387
|
+
email?: string;
|
|
388
|
+
tags?: string[];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
interface UseFeedbackOptions {
|
|
392
|
+
/** Optional status filter applied to the list call. */
|
|
393
|
+
status?: FeedbackStatus;
|
|
394
|
+
/** Optional type filter. */
|
|
395
|
+
type?: FeedbackType;
|
|
396
|
+
/** When false, suppress the initial list fetch (the widget submits without listing). */
|
|
397
|
+
enabled?: boolean;
|
|
398
|
+
}
|
|
399
|
+
interface UseFeedbackResult {
|
|
400
|
+
/** End-user's own feedback items for the current tenant. Empty when not signed in. */
|
|
401
|
+
items: FeedbackItem[];
|
|
402
|
+
loading: boolean;
|
|
403
|
+
error: ApiError | null;
|
|
404
|
+
/** Submit a new feedback item. Returns the persisted item on success. */
|
|
405
|
+
submit: (input: FeedbackItemInput) => Promise<FeedbackItem>;
|
|
406
|
+
/** Re-fetch the list. */
|
|
407
|
+
refresh: () => Promise<void>;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Hook for end-user feedback submission and read-own.
|
|
411
|
+
*
|
|
412
|
+
* Calls go through `client` from `ScaleMuleProvider`, which attaches the
|
|
413
|
+
* configured API key and (when present) the user session token. Tenancy
|
|
414
|
+
* (`x-app-id`) is derived by the gateway from the API key — never set
|
|
415
|
+
* client-side.
|
|
416
|
+
*/
|
|
417
|
+
declare function useFeedback(options?: UseFeedbackOptions): UseFeedbackResult;
|
|
418
|
+
|
|
419
|
+
interface FeedbackWidgetProps {
|
|
420
|
+
/** Floating-button corner. Default `bottom-right`. */
|
|
421
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
422
|
+
/** Default selected type when the modal opens. Default `feature_request`. */
|
|
423
|
+
defaultType?: FeedbackType;
|
|
424
|
+
/** Restrict the type select to this subset. Default: all four types. */
|
|
425
|
+
allowedTypes?: FeedbackType[];
|
|
426
|
+
/** Trigger button label. Default `Feedback`. */
|
|
427
|
+
triggerLabel?: string;
|
|
428
|
+
/** `light`/`dark`/`auto` (matches OS). Default `auto`. */
|
|
429
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
430
|
+
/** Optional class for the trigger button (use to override styling). */
|
|
431
|
+
className?: string;
|
|
432
|
+
/** Called after a successful submit. */
|
|
433
|
+
onSubmitted?: (item: FeedbackItem) => void;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Floating feedback widget. Renders nothing until the trigger is clicked,
|
|
437
|
+
* then opens a small modal with type / title / description fields. Submits
|
|
438
|
+
* via `useFeedback().submit()` — inherits identity from `ScaleMuleProvider`.
|
|
439
|
+
*
|
|
440
|
+
* If the end-user is not signed in, the widget shows an additional `email`
|
|
441
|
+
* field (required by the service for anonymous submissions).
|
|
442
|
+
*
|
|
443
|
+
* Tenant must have `feedback_app_config.enabled = TRUE` for `/submit` to
|
|
444
|
+
* accept submissions; otherwise the service responds with 404
|
|
445
|
+
* `FEEDBACK_DISABLED` and the widget surfaces the error message.
|
|
446
|
+
*/
|
|
447
|
+
declare function FeedbackWidget(props: FeedbackWidgetProps): ReactElement | null;
|
|
448
|
+
|
|
349
449
|
/**
|
|
350
450
|
* Client-side validation helpers
|
|
351
451
|
*
|
|
@@ -504,4 +604,4 @@ declare function createSafeLogger(prefix: string): {
|
|
|
504
604
|
error: (message: string, data?: unknown) => void;
|
|
505
605
|
};
|
|
506
606
|
|
|
507
|
-
export { ApiError, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, ListFilesParams, LoginResponse, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAuth, useBilling, useContent, useFeatureFlags, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useUser, validateForm, validators };
|
|
607
|
+
export { ApiError, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useUser, validateForm, validators };
|
package/dist/index.js
CHANGED
|
@@ -9602,6 +9602,341 @@ function useShare(options) {
|
|
|
9602
9602
|
}, [shareUrl]);
|
|
9603
9603
|
return { shareUrl, referralCode, copyLink, copied, loading };
|
|
9604
9604
|
}
|
|
9605
|
+
function toApiError2(error) {
|
|
9606
|
+
if (error instanceof ScaleMuleApiError) {
|
|
9607
|
+
return {
|
|
9608
|
+
code: error.code,
|
|
9609
|
+
message: error.message,
|
|
9610
|
+
field: error.field
|
|
9611
|
+
};
|
|
9612
|
+
}
|
|
9613
|
+
return {
|
|
9614
|
+
code: "UNKNOWN",
|
|
9615
|
+
message: error instanceof Error ? error.message : "Feedback request failed"
|
|
9616
|
+
};
|
|
9617
|
+
}
|
|
9618
|
+
function useFeedback(options = {}) {
|
|
9619
|
+
const { client } = useScaleMule();
|
|
9620
|
+
const { status, type, enabled = true } = options;
|
|
9621
|
+
const [items, setItems] = react.useState([]);
|
|
9622
|
+
const [loading, setLoading] = react.useState(enabled);
|
|
9623
|
+
const [error, setError] = react.useState(null);
|
|
9624
|
+
const refresh = react.useCallback(async () => {
|
|
9625
|
+
if (!enabled) {
|
|
9626
|
+
setLoading(false);
|
|
9627
|
+
return;
|
|
9628
|
+
}
|
|
9629
|
+
setLoading(true);
|
|
9630
|
+
try {
|
|
9631
|
+
const params = new URLSearchParams();
|
|
9632
|
+
if (status) params.append("status", status);
|
|
9633
|
+
if (type) params.append("type", type);
|
|
9634
|
+
const qs = params.toString();
|
|
9635
|
+
const path = `/v1/feedback/items${qs ? "?" + qs : ""}`;
|
|
9636
|
+
const result = await client.get(path);
|
|
9637
|
+
setItems(Array.isArray(result) ? result : []);
|
|
9638
|
+
setError(null);
|
|
9639
|
+
} catch (err) {
|
|
9640
|
+
setError(toApiError2(err));
|
|
9641
|
+
} finally {
|
|
9642
|
+
setLoading(false);
|
|
9643
|
+
}
|
|
9644
|
+
}, [client, enabled, status, type]);
|
|
9645
|
+
react.useEffect(() => {
|
|
9646
|
+
refresh();
|
|
9647
|
+
}, [refresh]);
|
|
9648
|
+
const submit = react.useCallback(
|
|
9649
|
+
async (input) => {
|
|
9650
|
+
try {
|
|
9651
|
+
const created = await client.post("/v1/feedback/submit", input);
|
|
9652
|
+
setItems((prev) => [created, ...prev]);
|
|
9653
|
+
setError(null);
|
|
9654
|
+
return created;
|
|
9655
|
+
} catch (err) {
|
|
9656
|
+
const apiErr = toApiError2(err);
|
|
9657
|
+
setError(apiErr);
|
|
9658
|
+
throw err;
|
|
9659
|
+
}
|
|
9660
|
+
},
|
|
9661
|
+
[client]
|
|
9662
|
+
);
|
|
9663
|
+
return { items, loading, error, submit, refresh };
|
|
9664
|
+
}
|
|
9665
|
+
var TYPE_LABELS = {
|
|
9666
|
+
bug_report: "Bug",
|
|
9667
|
+
feature_request: "Feature request",
|
|
9668
|
+
improvement: "Improvement",
|
|
9669
|
+
other: "Other"
|
|
9670
|
+
};
|
|
9671
|
+
var POSITION_STYLES = {
|
|
9672
|
+
"bottom-right": { bottom: 24, right: 24 },
|
|
9673
|
+
"bottom-left": { bottom: 24, left: 24 },
|
|
9674
|
+
"top-right": { top: 24, right: 24 },
|
|
9675
|
+
"top-left": { top: 24, left: 24 }
|
|
9676
|
+
};
|
|
9677
|
+
var STYLES = {
|
|
9678
|
+
trigger: {
|
|
9679
|
+
position: "fixed",
|
|
9680
|
+
zIndex: 999998,
|
|
9681
|
+
padding: "10px 16px",
|
|
9682
|
+
fontSize: 14,
|
|
9683
|
+
fontWeight: 600,
|
|
9684
|
+
border: "none",
|
|
9685
|
+
borderRadius: 999,
|
|
9686
|
+
cursor: "pointer",
|
|
9687
|
+
boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
|
|
9688
|
+
background: "#1f2937",
|
|
9689
|
+
color: "#fff"
|
|
9690
|
+
},
|
|
9691
|
+
overlay: {
|
|
9692
|
+
position: "fixed",
|
|
9693
|
+
inset: 0,
|
|
9694
|
+
background: "rgba(15, 23, 42, 0.5)",
|
|
9695
|
+
zIndex: 999999,
|
|
9696
|
+
display: "flex",
|
|
9697
|
+
alignItems: "center",
|
|
9698
|
+
justifyContent: "center",
|
|
9699
|
+
padding: 16
|
|
9700
|
+
},
|
|
9701
|
+
modal: {
|
|
9702
|
+
width: "min(440px, 100%)",
|
|
9703
|
+
background: "#fff",
|
|
9704
|
+
color: "#0f172a",
|
|
9705
|
+
borderRadius: 12,
|
|
9706
|
+
boxShadow: "0 20px 60px rgba(0,0,0,0.2)",
|
|
9707
|
+
padding: 20,
|
|
9708
|
+
display: "flex",
|
|
9709
|
+
flexDirection: "column",
|
|
9710
|
+
gap: 12
|
|
9711
|
+
},
|
|
9712
|
+
modalDark: {
|
|
9713
|
+
background: "#0f172a",
|
|
9714
|
+
color: "#f8fafc"
|
|
9715
|
+
},
|
|
9716
|
+
label: {
|
|
9717
|
+
fontSize: 12,
|
|
9718
|
+
fontWeight: 600,
|
|
9719
|
+
textTransform: "uppercase",
|
|
9720
|
+
letterSpacing: 0.5,
|
|
9721
|
+
opacity: 0.7
|
|
9722
|
+
},
|
|
9723
|
+
field: {
|
|
9724
|
+
width: "100%",
|
|
9725
|
+
padding: "8px 10px",
|
|
9726
|
+
fontSize: 14,
|
|
9727
|
+
border: "1px solid #e2e8f0",
|
|
9728
|
+
borderRadius: 6,
|
|
9729
|
+
boxSizing: "border-box",
|
|
9730
|
+
background: "transparent",
|
|
9731
|
+
color: "inherit"
|
|
9732
|
+
},
|
|
9733
|
+
textarea: {
|
|
9734
|
+
minHeight: 96,
|
|
9735
|
+
resize: "vertical"
|
|
9736
|
+
},
|
|
9737
|
+
rowEnd: {
|
|
9738
|
+
display: "flex",
|
|
9739
|
+
justifyContent: "flex-end",
|
|
9740
|
+
gap: 8
|
|
9741
|
+
},
|
|
9742
|
+
primaryBtn: {
|
|
9743
|
+
padding: "8px 14px",
|
|
9744
|
+
fontSize: 14,
|
|
9745
|
+
fontWeight: 600,
|
|
9746
|
+
border: "none",
|
|
9747
|
+
borderRadius: 6,
|
|
9748
|
+
background: "#2563eb",
|
|
9749
|
+
color: "#fff",
|
|
9750
|
+
cursor: "pointer"
|
|
9751
|
+
},
|
|
9752
|
+
secondaryBtn: {
|
|
9753
|
+
padding: "8px 14px",
|
|
9754
|
+
fontSize: 14,
|
|
9755
|
+
border: "1px solid #cbd5e1",
|
|
9756
|
+
borderRadius: 6,
|
|
9757
|
+
background: "transparent",
|
|
9758
|
+
color: "inherit",
|
|
9759
|
+
cursor: "pointer"
|
|
9760
|
+
},
|
|
9761
|
+
error: {
|
|
9762
|
+
fontSize: 13,
|
|
9763
|
+
color: "#dc2626"
|
|
9764
|
+
},
|
|
9765
|
+
success: {
|
|
9766
|
+
fontSize: 14,
|
|
9767
|
+
fontWeight: 500,
|
|
9768
|
+
textAlign: "center",
|
|
9769
|
+
padding: "24px 8px"
|
|
9770
|
+
}
|
|
9771
|
+
};
|
|
9772
|
+
var ALL_TYPES = ["bug_report", "feature_request", "improvement", "other"];
|
|
9773
|
+
function FeedbackWidget(props) {
|
|
9774
|
+
const {
|
|
9775
|
+
position = "bottom-right",
|
|
9776
|
+
defaultType = "feature_request",
|
|
9777
|
+
allowedTypes = ALL_TYPES,
|
|
9778
|
+
triggerLabel = "Feedback",
|
|
9779
|
+
theme = "auto",
|
|
9780
|
+
className,
|
|
9781
|
+
onSubmitted
|
|
9782
|
+
} = props;
|
|
9783
|
+
const sm = useScaleMule();
|
|
9784
|
+
const { submit } = useFeedback({ enabled: false });
|
|
9785
|
+
const [open, setOpen] = react.useState(false);
|
|
9786
|
+
const [type, setType] = react.useState(defaultType);
|
|
9787
|
+
const [title, setTitle] = react.useState("");
|
|
9788
|
+
const [description, setDescription] = react.useState("");
|
|
9789
|
+
const [email, setEmail] = react.useState("");
|
|
9790
|
+
const [submitting, setSubmitting] = react.useState(false);
|
|
9791
|
+
const [errMsg, setErrMsg] = react.useState(null);
|
|
9792
|
+
const [done, setDone] = react.useState(false);
|
|
9793
|
+
Boolean(sm.user || sm.user === void 0 ? false : false);
|
|
9794
|
+
const signedIn = Boolean(sm.user);
|
|
9795
|
+
function reset() {
|
|
9796
|
+
setType(defaultType);
|
|
9797
|
+
setTitle("");
|
|
9798
|
+
setDescription("");
|
|
9799
|
+
setEmail("");
|
|
9800
|
+
setErrMsg(null);
|
|
9801
|
+
setDone(false);
|
|
9802
|
+
}
|
|
9803
|
+
async function handleSubmit(e) {
|
|
9804
|
+
e.preventDefault();
|
|
9805
|
+
if (!title.trim() || !description.trim()) return;
|
|
9806
|
+
if (!signedIn && !email.trim()) {
|
|
9807
|
+
setErrMsg("email is required when not signed in");
|
|
9808
|
+
return;
|
|
9809
|
+
}
|
|
9810
|
+
setSubmitting(true);
|
|
9811
|
+
setErrMsg(null);
|
|
9812
|
+
try {
|
|
9813
|
+
const item = await submit({
|
|
9814
|
+
type,
|
|
9815
|
+
title: title.trim(),
|
|
9816
|
+
description: description.trim(),
|
|
9817
|
+
email: signedIn ? void 0 : email.trim() || void 0
|
|
9818
|
+
});
|
|
9819
|
+
setDone(true);
|
|
9820
|
+
onSubmitted?.(item);
|
|
9821
|
+
} catch (err) {
|
|
9822
|
+
const message = err && typeof err === "object" && "message" in err ? String(err.message) : "Submit failed";
|
|
9823
|
+
setErrMsg(message);
|
|
9824
|
+
} finally {
|
|
9825
|
+
setSubmitting(false);
|
|
9826
|
+
}
|
|
9827
|
+
}
|
|
9828
|
+
function handleClose() {
|
|
9829
|
+
setOpen(false);
|
|
9830
|
+
setTimeout(reset, 200);
|
|
9831
|
+
}
|
|
9832
|
+
const dark = theme === "dark" || theme === "auto" && typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
9833
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
9834
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9835
|
+
"button",
|
|
9836
|
+
{
|
|
9837
|
+
type: "button",
|
|
9838
|
+
onClick: () => setOpen(true),
|
|
9839
|
+
className,
|
|
9840
|
+
style: { ...STYLES.trigger, ...POSITION_STYLES[position] },
|
|
9841
|
+
children: triggerLabel
|
|
9842
|
+
}
|
|
9843
|
+
),
|
|
9844
|
+
open && /* @__PURE__ */ jsxRuntime.jsx("div", { role: "dialog", "aria-modal": "true", style: STYLES.overlay, onClick: handleClose, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
9845
|
+
"form",
|
|
9846
|
+
{
|
|
9847
|
+
onSubmit: handleSubmit,
|
|
9848
|
+
onClick: (e) => e.stopPropagation(),
|
|
9849
|
+
style: { ...STYLES.modal, ...dark ? STYLES.modalDark : null },
|
|
9850
|
+
children: done ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
9851
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: STYLES.success, children: [
|
|
9852
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 32, marginBottom: 8 }, children: "\u{1F389}" }),
|
|
9853
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: "Thanks \u2014 we got it." })
|
|
9854
|
+
] }),
|
|
9855
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: STYLES.rowEnd, children: /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: STYLES.primaryBtn, onClick: handleClose, children: "Close" }) })
|
|
9856
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
9857
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", justifyContent: "space-between" }, children: [
|
|
9858
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { style: { fontSize: 16 }, children: "Send feedback" }),
|
|
9859
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9860
|
+
"button",
|
|
9861
|
+
{
|
|
9862
|
+
type: "button",
|
|
9863
|
+
onClick: handleClose,
|
|
9864
|
+
"aria-label": "Close",
|
|
9865
|
+
style: {
|
|
9866
|
+
background: "transparent",
|
|
9867
|
+
border: "none",
|
|
9868
|
+
fontSize: 18,
|
|
9869
|
+
cursor: "pointer",
|
|
9870
|
+
color: "inherit"
|
|
9871
|
+
},
|
|
9872
|
+
children: "\xD7"
|
|
9873
|
+
}
|
|
9874
|
+
)
|
|
9875
|
+
] }),
|
|
9876
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
9877
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: STYLES.label, children: "Type" }),
|
|
9878
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9879
|
+
"select",
|
|
9880
|
+
{
|
|
9881
|
+
style: STYLES.field,
|
|
9882
|
+
value: type,
|
|
9883
|
+
onChange: (e) => setType(e.target.value),
|
|
9884
|
+
children: allowedTypes.map((t) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: t, children: TYPE_LABELS[t] }, t))
|
|
9885
|
+
}
|
|
9886
|
+
)
|
|
9887
|
+
] }),
|
|
9888
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
9889
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: STYLES.label, children: "Title" }),
|
|
9890
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9891
|
+
"input",
|
|
9892
|
+
{
|
|
9893
|
+
style: STYLES.field,
|
|
9894
|
+
type: "text",
|
|
9895
|
+
value: title,
|
|
9896
|
+
onChange: (e) => setTitle(e.target.value),
|
|
9897
|
+
placeholder: "One-line summary",
|
|
9898
|
+
maxLength: 255,
|
|
9899
|
+
required: true
|
|
9900
|
+
}
|
|
9901
|
+
)
|
|
9902
|
+
] }),
|
|
9903
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
9904
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: STYLES.label, children: "Details" }),
|
|
9905
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9906
|
+
"textarea",
|
|
9907
|
+
{
|
|
9908
|
+
style: { ...STYLES.field, ...STYLES.textarea },
|
|
9909
|
+
value: description,
|
|
9910
|
+
onChange: (e) => setDescription(e.target.value),
|
|
9911
|
+
placeholder: "What happened, what you expected, anything else helpful\u2026",
|
|
9912
|
+
required: true
|
|
9913
|
+
}
|
|
9914
|
+
)
|
|
9915
|
+
] }),
|
|
9916
|
+
!signedIn && /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
9917
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: STYLES.label, children: "Email" }),
|
|
9918
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
9919
|
+
"input",
|
|
9920
|
+
{
|
|
9921
|
+
style: STYLES.field,
|
|
9922
|
+
type: "email",
|
|
9923
|
+
value: email,
|
|
9924
|
+
onChange: (e) => setEmail(e.target.value),
|
|
9925
|
+
placeholder: "you@example.com",
|
|
9926
|
+
required: true
|
|
9927
|
+
}
|
|
9928
|
+
)
|
|
9929
|
+
] }),
|
|
9930
|
+
errMsg && /* @__PURE__ */ jsxRuntime.jsx("div", { style: STYLES.error, children: errMsg }),
|
|
9931
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: STYLES.rowEnd, children: [
|
|
9932
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: STYLES.secondaryBtn, onClick: handleClose, children: "Cancel" }),
|
|
9933
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", style: STYLES.primaryBtn, disabled: submitting, children: submitting ? "Sending\u2026" : "Send" })
|
|
9934
|
+
] })
|
|
9935
|
+
] })
|
|
9936
|
+
}
|
|
9937
|
+
) })
|
|
9938
|
+
] });
|
|
9939
|
+
}
|
|
9605
9940
|
|
|
9606
9941
|
// src/validation.ts
|
|
9607
9942
|
var phoneCountries = [
|
|
@@ -9902,6 +10237,7 @@ Object.defineProperty(exports, "createMoneyClient", {
|
|
|
9902
10237
|
enumerable: true,
|
|
9903
10238
|
get: function () { return money.createMoneyClient; }
|
|
9904
10239
|
});
|
|
10240
|
+
exports.FeedbackWidget = FeedbackWidget;
|
|
9905
10241
|
exports.ScaleMuleApiError = ScaleMuleApiError;
|
|
9906
10242
|
exports.ScaleMuleClient = ScaleMuleClient2;
|
|
9907
10243
|
exports.ScaleMuleProvider = ScaleMuleProvider;
|
|
@@ -9916,6 +10252,7 @@ exports.useAuth = useAuth;
|
|
|
9916
10252
|
exports.useBilling = useBilling;
|
|
9917
10253
|
exports.useContent = useContent;
|
|
9918
10254
|
exports.useFeatureFlags = useFeatureFlags;
|
|
10255
|
+
exports.useFeedback = useFeedback;
|
|
9919
10256
|
exports.useMoney = useMoney;
|
|
9920
10257
|
exports.useMoneyClient = useMoneyClient;
|
|
9921
10258
|
exports.usePushNotifications = usePushNotifications;
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createContext, useState, useMemo, useEffect, useCallback, useContext, useRef } from 'react';
|
|
2
2
|
import { createMoneyClient } from '@scalemule/money';
|
|
3
3
|
export { MoneyClient, createMoneyClient } from '@scalemule/money';
|
|
4
|
-
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
7
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -9601,6 +9601,341 @@ function useShare(options) {
|
|
|
9601
9601
|
}, [shareUrl]);
|
|
9602
9602
|
return { shareUrl, referralCode, copyLink, copied, loading };
|
|
9603
9603
|
}
|
|
9604
|
+
function toApiError2(error) {
|
|
9605
|
+
if (error instanceof ScaleMuleApiError) {
|
|
9606
|
+
return {
|
|
9607
|
+
code: error.code,
|
|
9608
|
+
message: error.message,
|
|
9609
|
+
field: error.field
|
|
9610
|
+
};
|
|
9611
|
+
}
|
|
9612
|
+
return {
|
|
9613
|
+
code: "UNKNOWN",
|
|
9614
|
+
message: error instanceof Error ? error.message : "Feedback request failed"
|
|
9615
|
+
};
|
|
9616
|
+
}
|
|
9617
|
+
function useFeedback(options = {}) {
|
|
9618
|
+
const { client } = useScaleMule();
|
|
9619
|
+
const { status, type, enabled = true } = options;
|
|
9620
|
+
const [items, setItems] = useState([]);
|
|
9621
|
+
const [loading, setLoading] = useState(enabled);
|
|
9622
|
+
const [error, setError] = useState(null);
|
|
9623
|
+
const refresh = useCallback(async () => {
|
|
9624
|
+
if (!enabled) {
|
|
9625
|
+
setLoading(false);
|
|
9626
|
+
return;
|
|
9627
|
+
}
|
|
9628
|
+
setLoading(true);
|
|
9629
|
+
try {
|
|
9630
|
+
const params = new URLSearchParams();
|
|
9631
|
+
if (status) params.append("status", status);
|
|
9632
|
+
if (type) params.append("type", type);
|
|
9633
|
+
const qs = params.toString();
|
|
9634
|
+
const path = `/v1/feedback/items${qs ? "?" + qs : ""}`;
|
|
9635
|
+
const result = await client.get(path);
|
|
9636
|
+
setItems(Array.isArray(result) ? result : []);
|
|
9637
|
+
setError(null);
|
|
9638
|
+
} catch (err) {
|
|
9639
|
+
setError(toApiError2(err));
|
|
9640
|
+
} finally {
|
|
9641
|
+
setLoading(false);
|
|
9642
|
+
}
|
|
9643
|
+
}, [client, enabled, status, type]);
|
|
9644
|
+
useEffect(() => {
|
|
9645
|
+
refresh();
|
|
9646
|
+
}, [refresh]);
|
|
9647
|
+
const submit = useCallback(
|
|
9648
|
+
async (input) => {
|
|
9649
|
+
try {
|
|
9650
|
+
const created = await client.post("/v1/feedback/submit", input);
|
|
9651
|
+
setItems((prev) => [created, ...prev]);
|
|
9652
|
+
setError(null);
|
|
9653
|
+
return created;
|
|
9654
|
+
} catch (err) {
|
|
9655
|
+
const apiErr = toApiError2(err);
|
|
9656
|
+
setError(apiErr);
|
|
9657
|
+
throw err;
|
|
9658
|
+
}
|
|
9659
|
+
},
|
|
9660
|
+
[client]
|
|
9661
|
+
);
|
|
9662
|
+
return { items, loading, error, submit, refresh };
|
|
9663
|
+
}
|
|
9664
|
+
var TYPE_LABELS = {
|
|
9665
|
+
bug_report: "Bug",
|
|
9666
|
+
feature_request: "Feature request",
|
|
9667
|
+
improvement: "Improvement",
|
|
9668
|
+
other: "Other"
|
|
9669
|
+
};
|
|
9670
|
+
var POSITION_STYLES = {
|
|
9671
|
+
"bottom-right": { bottom: 24, right: 24 },
|
|
9672
|
+
"bottom-left": { bottom: 24, left: 24 },
|
|
9673
|
+
"top-right": { top: 24, right: 24 },
|
|
9674
|
+
"top-left": { top: 24, left: 24 }
|
|
9675
|
+
};
|
|
9676
|
+
var STYLES = {
|
|
9677
|
+
trigger: {
|
|
9678
|
+
position: "fixed",
|
|
9679
|
+
zIndex: 999998,
|
|
9680
|
+
padding: "10px 16px",
|
|
9681
|
+
fontSize: 14,
|
|
9682
|
+
fontWeight: 600,
|
|
9683
|
+
border: "none",
|
|
9684
|
+
borderRadius: 999,
|
|
9685
|
+
cursor: "pointer",
|
|
9686
|
+
boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
|
|
9687
|
+
background: "#1f2937",
|
|
9688
|
+
color: "#fff"
|
|
9689
|
+
},
|
|
9690
|
+
overlay: {
|
|
9691
|
+
position: "fixed",
|
|
9692
|
+
inset: 0,
|
|
9693
|
+
background: "rgba(15, 23, 42, 0.5)",
|
|
9694
|
+
zIndex: 999999,
|
|
9695
|
+
display: "flex",
|
|
9696
|
+
alignItems: "center",
|
|
9697
|
+
justifyContent: "center",
|
|
9698
|
+
padding: 16
|
|
9699
|
+
},
|
|
9700
|
+
modal: {
|
|
9701
|
+
width: "min(440px, 100%)",
|
|
9702
|
+
background: "#fff",
|
|
9703
|
+
color: "#0f172a",
|
|
9704
|
+
borderRadius: 12,
|
|
9705
|
+
boxShadow: "0 20px 60px rgba(0,0,0,0.2)",
|
|
9706
|
+
padding: 20,
|
|
9707
|
+
display: "flex",
|
|
9708
|
+
flexDirection: "column",
|
|
9709
|
+
gap: 12
|
|
9710
|
+
},
|
|
9711
|
+
modalDark: {
|
|
9712
|
+
background: "#0f172a",
|
|
9713
|
+
color: "#f8fafc"
|
|
9714
|
+
},
|
|
9715
|
+
label: {
|
|
9716
|
+
fontSize: 12,
|
|
9717
|
+
fontWeight: 600,
|
|
9718
|
+
textTransform: "uppercase",
|
|
9719
|
+
letterSpacing: 0.5,
|
|
9720
|
+
opacity: 0.7
|
|
9721
|
+
},
|
|
9722
|
+
field: {
|
|
9723
|
+
width: "100%",
|
|
9724
|
+
padding: "8px 10px",
|
|
9725
|
+
fontSize: 14,
|
|
9726
|
+
border: "1px solid #e2e8f0",
|
|
9727
|
+
borderRadius: 6,
|
|
9728
|
+
boxSizing: "border-box",
|
|
9729
|
+
background: "transparent",
|
|
9730
|
+
color: "inherit"
|
|
9731
|
+
},
|
|
9732
|
+
textarea: {
|
|
9733
|
+
minHeight: 96,
|
|
9734
|
+
resize: "vertical"
|
|
9735
|
+
},
|
|
9736
|
+
rowEnd: {
|
|
9737
|
+
display: "flex",
|
|
9738
|
+
justifyContent: "flex-end",
|
|
9739
|
+
gap: 8
|
|
9740
|
+
},
|
|
9741
|
+
primaryBtn: {
|
|
9742
|
+
padding: "8px 14px",
|
|
9743
|
+
fontSize: 14,
|
|
9744
|
+
fontWeight: 600,
|
|
9745
|
+
border: "none",
|
|
9746
|
+
borderRadius: 6,
|
|
9747
|
+
background: "#2563eb",
|
|
9748
|
+
color: "#fff",
|
|
9749
|
+
cursor: "pointer"
|
|
9750
|
+
},
|
|
9751
|
+
secondaryBtn: {
|
|
9752
|
+
padding: "8px 14px",
|
|
9753
|
+
fontSize: 14,
|
|
9754
|
+
border: "1px solid #cbd5e1",
|
|
9755
|
+
borderRadius: 6,
|
|
9756
|
+
background: "transparent",
|
|
9757
|
+
color: "inherit",
|
|
9758
|
+
cursor: "pointer"
|
|
9759
|
+
},
|
|
9760
|
+
error: {
|
|
9761
|
+
fontSize: 13,
|
|
9762
|
+
color: "#dc2626"
|
|
9763
|
+
},
|
|
9764
|
+
success: {
|
|
9765
|
+
fontSize: 14,
|
|
9766
|
+
fontWeight: 500,
|
|
9767
|
+
textAlign: "center",
|
|
9768
|
+
padding: "24px 8px"
|
|
9769
|
+
}
|
|
9770
|
+
};
|
|
9771
|
+
var ALL_TYPES = ["bug_report", "feature_request", "improvement", "other"];
|
|
9772
|
+
function FeedbackWidget(props) {
|
|
9773
|
+
const {
|
|
9774
|
+
position = "bottom-right",
|
|
9775
|
+
defaultType = "feature_request",
|
|
9776
|
+
allowedTypes = ALL_TYPES,
|
|
9777
|
+
triggerLabel = "Feedback",
|
|
9778
|
+
theme = "auto",
|
|
9779
|
+
className,
|
|
9780
|
+
onSubmitted
|
|
9781
|
+
} = props;
|
|
9782
|
+
const sm = useScaleMule();
|
|
9783
|
+
const { submit } = useFeedback({ enabled: false });
|
|
9784
|
+
const [open, setOpen] = useState(false);
|
|
9785
|
+
const [type, setType] = useState(defaultType);
|
|
9786
|
+
const [title, setTitle] = useState("");
|
|
9787
|
+
const [description, setDescription] = useState("");
|
|
9788
|
+
const [email, setEmail] = useState("");
|
|
9789
|
+
const [submitting, setSubmitting] = useState(false);
|
|
9790
|
+
const [errMsg, setErrMsg] = useState(null);
|
|
9791
|
+
const [done, setDone] = useState(false);
|
|
9792
|
+
Boolean(sm.user || sm.user === void 0 ? false : false);
|
|
9793
|
+
const signedIn = Boolean(sm.user);
|
|
9794
|
+
function reset() {
|
|
9795
|
+
setType(defaultType);
|
|
9796
|
+
setTitle("");
|
|
9797
|
+
setDescription("");
|
|
9798
|
+
setEmail("");
|
|
9799
|
+
setErrMsg(null);
|
|
9800
|
+
setDone(false);
|
|
9801
|
+
}
|
|
9802
|
+
async function handleSubmit(e) {
|
|
9803
|
+
e.preventDefault();
|
|
9804
|
+
if (!title.trim() || !description.trim()) return;
|
|
9805
|
+
if (!signedIn && !email.trim()) {
|
|
9806
|
+
setErrMsg("email is required when not signed in");
|
|
9807
|
+
return;
|
|
9808
|
+
}
|
|
9809
|
+
setSubmitting(true);
|
|
9810
|
+
setErrMsg(null);
|
|
9811
|
+
try {
|
|
9812
|
+
const item = await submit({
|
|
9813
|
+
type,
|
|
9814
|
+
title: title.trim(),
|
|
9815
|
+
description: description.trim(),
|
|
9816
|
+
email: signedIn ? void 0 : email.trim() || void 0
|
|
9817
|
+
});
|
|
9818
|
+
setDone(true);
|
|
9819
|
+
onSubmitted?.(item);
|
|
9820
|
+
} catch (err) {
|
|
9821
|
+
const message = err && typeof err === "object" && "message" in err ? String(err.message) : "Submit failed";
|
|
9822
|
+
setErrMsg(message);
|
|
9823
|
+
} finally {
|
|
9824
|
+
setSubmitting(false);
|
|
9825
|
+
}
|
|
9826
|
+
}
|
|
9827
|
+
function handleClose() {
|
|
9828
|
+
setOpen(false);
|
|
9829
|
+
setTimeout(reset, 200);
|
|
9830
|
+
}
|
|
9831
|
+
const dark = theme === "dark" || theme === "auto" && typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
9832
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
9833
|
+
/* @__PURE__ */ jsx(
|
|
9834
|
+
"button",
|
|
9835
|
+
{
|
|
9836
|
+
type: "button",
|
|
9837
|
+
onClick: () => setOpen(true),
|
|
9838
|
+
className,
|
|
9839
|
+
style: { ...STYLES.trigger, ...POSITION_STYLES[position] },
|
|
9840
|
+
children: triggerLabel
|
|
9841
|
+
}
|
|
9842
|
+
),
|
|
9843
|
+
open && /* @__PURE__ */ jsx("div", { role: "dialog", "aria-modal": "true", style: STYLES.overlay, onClick: handleClose, children: /* @__PURE__ */ jsx(
|
|
9844
|
+
"form",
|
|
9845
|
+
{
|
|
9846
|
+
onSubmit: handleSubmit,
|
|
9847
|
+
onClick: (e) => e.stopPropagation(),
|
|
9848
|
+
style: { ...STYLES.modal, ...dark ? STYLES.modalDark : null },
|
|
9849
|
+
children: done ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
9850
|
+
/* @__PURE__ */ jsxs("div", { style: STYLES.success, children: [
|
|
9851
|
+
/* @__PURE__ */ jsx("div", { style: { fontSize: 32, marginBottom: 8 }, children: "\u{1F389}" }),
|
|
9852
|
+
/* @__PURE__ */ jsx("div", { children: "Thanks \u2014 we got it." })
|
|
9853
|
+
] }),
|
|
9854
|
+
/* @__PURE__ */ jsx("div", { style: STYLES.rowEnd, children: /* @__PURE__ */ jsx("button", { type: "button", style: STYLES.primaryBtn, onClick: handleClose, children: "Close" }) })
|
|
9855
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
9856
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between" }, children: [
|
|
9857
|
+
/* @__PURE__ */ jsx("strong", { style: { fontSize: 16 }, children: "Send feedback" }),
|
|
9858
|
+
/* @__PURE__ */ jsx(
|
|
9859
|
+
"button",
|
|
9860
|
+
{
|
|
9861
|
+
type: "button",
|
|
9862
|
+
onClick: handleClose,
|
|
9863
|
+
"aria-label": "Close",
|
|
9864
|
+
style: {
|
|
9865
|
+
background: "transparent",
|
|
9866
|
+
border: "none",
|
|
9867
|
+
fontSize: 18,
|
|
9868
|
+
cursor: "pointer",
|
|
9869
|
+
color: "inherit"
|
|
9870
|
+
},
|
|
9871
|
+
children: "\xD7"
|
|
9872
|
+
}
|
|
9873
|
+
)
|
|
9874
|
+
] }),
|
|
9875
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
9876
|
+
/* @__PURE__ */ jsx("div", { style: STYLES.label, children: "Type" }),
|
|
9877
|
+
/* @__PURE__ */ jsx(
|
|
9878
|
+
"select",
|
|
9879
|
+
{
|
|
9880
|
+
style: STYLES.field,
|
|
9881
|
+
value: type,
|
|
9882
|
+
onChange: (e) => setType(e.target.value),
|
|
9883
|
+
children: allowedTypes.map((t) => /* @__PURE__ */ jsx("option", { value: t, children: TYPE_LABELS[t] }, t))
|
|
9884
|
+
}
|
|
9885
|
+
)
|
|
9886
|
+
] }),
|
|
9887
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
9888
|
+
/* @__PURE__ */ jsx("div", { style: STYLES.label, children: "Title" }),
|
|
9889
|
+
/* @__PURE__ */ jsx(
|
|
9890
|
+
"input",
|
|
9891
|
+
{
|
|
9892
|
+
style: STYLES.field,
|
|
9893
|
+
type: "text",
|
|
9894
|
+
value: title,
|
|
9895
|
+
onChange: (e) => setTitle(e.target.value),
|
|
9896
|
+
placeholder: "One-line summary",
|
|
9897
|
+
maxLength: 255,
|
|
9898
|
+
required: true
|
|
9899
|
+
}
|
|
9900
|
+
)
|
|
9901
|
+
] }),
|
|
9902
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
9903
|
+
/* @__PURE__ */ jsx("div", { style: STYLES.label, children: "Details" }),
|
|
9904
|
+
/* @__PURE__ */ jsx(
|
|
9905
|
+
"textarea",
|
|
9906
|
+
{
|
|
9907
|
+
style: { ...STYLES.field, ...STYLES.textarea },
|
|
9908
|
+
value: description,
|
|
9909
|
+
onChange: (e) => setDescription(e.target.value),
|
|
9910
|
+
placeholder: "What happened, what you expected, anything else helpful\u2026",
|
|
9911
|
+
required: true
|
|
9912
|
+
}
|
|
9913
|
+
)
|
|
9914
|
+
] }),
|
|
9915
|
+
!signedIn && /* @__PURE__ */ jsxs("label", { children: [
|
|
9916
|
+
/* @__PURE__ */ jsx("div", { style: STYLES.label, children: "Email" }),
|
|
9917
|
+
/* @__PURE__ */ jsx(
|
|
9918
|
+
"input",
|
|
9919
|
+
{
|
|
9920
|
+
style: STYLES.field,
|
|
9921
|
+
type: "email",
|
|
9922
|
+
value: email,
|
|
9923
|
+
onChange: (e) => setEmail(e.target.value),
|
|
9924
|
+
placeholder: "you@example.com",
|
|
9925
|
+
required: true
|
|
9926
|
+
}
|
|
9927
|
+
)
|
|
9928
|
+
] }),
|
|
9929
|
+
errMsg && /* @__PURE__ */ jsx("div", { style: STYLES.error, children: errMsg }),
|
|
9930
|
+
/* @__PURE__ */ jsxs("div", { style: STYLES.rowEnd, children: [
|
|
9931
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: STYLES.secondaryBtn, onClick: handleClose, children: "Cancel" }),
|
|
9932
|
+
/* @__PURE__ */ jsx("button", { type: "submit", style: STYLES.primaryBtn, disabled: submitting, children: submitting ? "Sending\u2026" : "Send" })
|
|
9933
|
+
] })
|
|
9934
|
+
] })
|
|
9935
|
+
}
|
|
9936
|
+
) })
|
|
9937
|
+
] });
|
|
9938
|
+
}
|
|
9604
9939
|
|
|
9605
9940
|
// src/validation.ts
|
|
9606
9941
|
var phoneCountries = [
|
|
@@ -9893,4 +10228,4 @@ function createSafeLogger(prefix) {
|
|
|
9893
10228
|
};
|
|
9894
10229
|
}
|
|
9895
10230
|
|
|
9896
|
-
export { ScaleMuleApiError, ScaleMuleClient2 as ScaleMuleClient, ScaleMuleProvider, composePhone, createClient, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAuth, useBilling, useContent, useFeatureFlags, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useUser, validateForm, validators };
|
|
10231
|
+
export { FeedbackWidget, ScaleMuleApiError, ScaleMuleClient2 as ScaleMuleClient, ScaleMuleProvider, composePhone, createClient, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useUser, validateForm, validators };
|
package/package.json
CHANGED