@mohasinac/appkit 2.7.8 → 2.7.10
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/_internal/shared/config/index.d.ts +1 -1
- package/dist/_internal/shared/config/schema.d.ts +95 -1
- package/dist/client-entry.d.ts +1 -1
- package/dist/client.d.ts +3 -0
- package/dist/client.js +5 -0
- package/dist/configs/next.js +28 -76
- package/dist/features/account/components/UserOffersPanel.js +17 -5
- package/dist/features/auctions/components/AuctionDetailPageView.js +17 -1
- package/dist/features/auctions/components/PlaceBidFormClient.js +10 -5
- package/dist/features/categories/components/BundleBuyNowCta.js +13 -6
- package/dist/features/events/components/EventPollWidget.js +7 -1
- package/dist/features/events/components/SpinWheelView.js +12 -5
- package/dist/features/pre-orders/components/PreOrderActionsClient.js +10 -3
- package/dist/features/products/components/MakeOfferButton.js +16 -8
- package/dist/features/products/components/PrizeRevealModal.js +18 -5
- package/dist/features/products/components/ProductDetailPageView.js +23 -1
- package/dist/features/seller/components/SellerOffersPanel.js +17 -5
- package/dist/features/wishlist/components/WishlistToggleButton.js +26 -12
- package/dist/http/api-handler.js +7 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +2 -0
- package/dist/tailwind-utilities.css +1 -1
- package/dist/ui/components/BaseListingCard.js +8 -6
- package/dist/ui/components/Button.style.css +8 -5
- package/dist/ui/components/ListingLayout.style.css +19 -9
- package/dist/ui/components/LoginRequiredModal.d.ts +9 -0
- package/dist/ui/components/LoginRequiredModal.js +11 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.js +1 -0
- package/dist/utils/auth-error.d.ts +8 -0
- package/dist/utils/auth-error.js +20 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { AppkitConfig, AppkitSmokeRoute, AppkitThemeProbeRoute, AppkitAuthFixture } from "./schema";
|
|
1
|
+
export type { AppkitConfig, AppkitSmokeRoute, AppkitThemeProbeRoute, AppkitAuthFixture, AppkitFirebaseConfig, AppkitFirebaseExtensions, AppkitVercelConfig, AppkitBrandConfig, AppkitSeoConfig, AppkitI18nConfig, AppkitImagePattern, FirestoreIndex, FirestoreIndexField, FirestoreFieldOverride, } from "./schema";
|
|
@@ -39,15 +39,99 @@ export interface AppkitAuthFixture {
|
|
|
39
39
|
/** Cookie header value, e.g. "session=FIXTURE_TOKEN" */
|
|
40
40
|
cookie: string;
|
|
41
41
|
}
|
|
42
|
+
export interface FirestoreIndexField {
|
|
43
|
+
fieldPath: string;
|
|
44
|
+
order?: "ASCENDING" | "DESCENDING";
|
|
45
|
+
arrayConfig?: "CONTAINS";
|
|
46
|
+
}
|
|
47
|
+
export interface FirestoreIndex {
|
|
48
|
+
collectionGroup: string;
|
|
49
|
+
queryScope: "COLLECTION" | "COLLECTION_GROUP";
|
|
50
|
+
fields: FirestoreIndexField[];
|
|
51
|
+
}
|
|
52
|
+
export interface FirestoreFieldOverride {
|
|
53
|
+
collectionGroup: string;
|
|
54
|
+
fieldPath: string;
|
|
55
|
+
indexes: Array<{
|
|
56
|
+
order?: "ASCENDING" | "DESCENDING";
|
|
57
|
+
arrayConfig?: "CONTAINS";
|
|
58
|
+
queryScope: "COLLECTION" | "COLLECTION_GROUP";
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
/** Consumer-specific Firebase extensions merged on top of the appkit base by firebase-merge.mjs. */
|
|
62
|
+
export interface AppkitFirebaseExtensions {
|
|
63
|
+
/** Additional Firestore composite indexes merged on top of the appkit base (deduplicated). */
|
|
64
|
+
indexes?: FirestoreIndex[];
|
|
65
|
+
/** Additional Firestore field overrides appended to the base list. */
|
|
66
|
+
fieldOverrides?: FirestoreFieldOverride[];
|
|
67
|
+
/** Additional RTDB rule paths deep-merged into the base rules object. */
|
|
68
|
+
database?: Record<string, unknown>;
|
|
69
|
+
/** Raw Firestore security rules block injected inside the top-level match block. */
|
|
70
|
+
firestoreRules?: string;
|
|
71
|
+
/** Raw Storage security rules block injected inside the bucket match block. */
|
|
72
|
+
storageRules?: string;
|
|
73
|
+
}
|
|
42
74
|
export interface AppkitFirebaseConfig {
|
|
43
75
|
/** Firebase project ID */
|
|
44
76
|
projectId: string;
|
|
45
|
-
/** Path to firestore.indexes.json base file */
|
|
77
|
+
/** Path to firestore.indexes.json base file (default: appkit/firebase/base/firestore.indexes.json) */
|
|
46
78
|
indexesPath?: string;
|
|
47
79
|
/** Collections to include in reset (undefined = all) */
|
|
48
80
|
resetCollections?: string[];
|
|
49
81
|
/** Firebase Functions region */
|
|
50
82
|
functionsRegion?: string;
|
|
83
|
+
/** Consumer-specific extensions merged on top of the appkit base by `npm run firebase:generate`. */
|
|
84
|
+
extensions?: AppkitFirebaseExtensions;
|
|
85
|
+
}
|
|
86
|
+
export interface AppkitBrandConfig {
|
|
87
|
+
/** Display name of the brand, e.g. "LetItRip" */
|
|
88
|
+
name: string;
|
|
89
|
+
/** Short / abbreviated name, e.g. "LT" */
|
|
90
|
+
shortName?: string;
|
|
91
|
+
/** One-line brand description used in meta tags and footers */
|
|
92
|
+
description?: string;
|
|
93
|
+
/** Tagline shown in footer / about sections */
|
|
94
|
+
madeInText?: string;
|
|
95
|
+
socialUrls?: {
|
|
96
|
+
instagram?: string;
|
|
97
|
+
twitter?: string;
|
|
98
|
+
whatsapp?: string;
|
|
99
|
+
youtube?: string;
|
|
100
|
+
facebook?: string;
|
|
101
|
+
linkedin?: string;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export interface AppkitSeoConfig {
|
|
105
|
+
/** Canonical site URL, e.g. "https://letitrip.in" */
|
|
106
|
+
siteUrl: string;
|
|
107
|
+
/** Default page <title> */
|
|
108
|
+
defaultTitle?: string;
|
|
109
|
+
/** Default meta description */
|
|
110
|
+
defaultDescription?: string;
|
|
111
|
+
/** Default OG image path (relative to public/) */
|
|
112
|
+
defaultImage?: string;
|
|
113
|
+
/** OG site name */
|
|
114
|
+
siteName?: string;
|
|
115
|
+
/** Twitter/X handle including @, e.g. "@letitrip" */
|
|
116
|
+
twitterHandle?: string;
|
|
117
|
+
/** BCP 47 locale tag for OG/schema.org, e.g. "en-IN" */
|
|
118
|
+
locale?: string;
|
|
119
|
+
}
|
|
120
|
+
export interface AppkitI18nConfig {
|
|
121
|
+
/** next-intl localePrefix strategy (default: "never") */
|
|
122
|
+
localePrefix?: "never" | "always" | "as-needed";
|
|
123
|
+
/**
|
|
124
|
+
* Set false to suppress the Set-Cookie: Next-Locale header, which forces
|
|
125
|
+
* cache-control: private and breaks Vercel ISR. Disable when running a single
|
|
126
|
+
* locale (default: false).
|
|
127
|
+
*/
|
|
128
|
+
enableLocaleCookie?: boolean;
|
|
129
|
+
}
|
|
130
|
+
export interface AppkitImagePattern {
|
|
131
|
+
protocol?: "http" | "https";
|
|
132
|
+
hostname: string;
|
|
133
|
+
port?: string;
|
|
134
|
+
pathname?: string;
|
|
51
135
|
}
|
|
52
136
|
export interface AppkitVercelConfig {
|
|
53
137
|
/** Vercel project ID */
|
|
@@ -56,12 +140,22 @@ export interface AppkitVercelConfig {
|
|
|
56
140
|
team?: string;
|
|
57
141
|
/** Path to .env file to sync */
|
|
58
142
|
envFile?: string;
|
|
143
|
+
/** Deployment regions, e.g. ["bom1"] */
|
|
144
|
+
regions?: string[];
|
|
59
145
|
}
|
|
60
146
|
export interface AppkitConfig {
|
|
61
147
|
/** Base URL for smoke tests and theme probes (default: http://localhost:3000) */
|
|
62
148
|
baseUrl?: string;
|
|
63
149
|
/** Supported locales (default: ["en"]) */
|
|
64
150
|
locales?: string[];
|
|
151
|
+
/** Brand identity — name, social URLs, taglines */
|
|
152
|
+
brand?: AppkitBrandConfig;
|
|
153
|
+
/** SEO defaults — siteUrl, defaultTitle, OG image, Twitter handle */
|
|
154
|
+
seo?: AppkitSeoConfig;
|
|
155
|
+
/** i18n / next-intl routing options */
|
|
156
|
+
i18n?: AppkitI18nConfig;
|
|
157
|
+
/** next/image remotePatterns for external image hosts (demo / seed data) */
|
|
158
|
+
externalImagePatterns?: AppkitImagePattern[];
|
|
65
159
|
/** Route configuration for smoke tests and theme probing */
|
|
66
160
|
routes?: {
|
|
67
161
|
/** Routes to SSR-verify: must return 200 + expected strings in initial HTML */
|
package/dist/client-entry.d.ts
CHANGED
|
@@ -18,6 +18,6 @@ export type { AppkitLabelSet } from "./_internal/client/i18n/LabelsProvider";
|
|
|
18
18
|
export { AppShell, DashboardScaffold } from "./_internal/client/scaffolds/index";
|
|
19
19
|
export type { AppShellProps, AppShellRenderContext, DashboardScaffoldProps, DashboardScaffoldRenderContext, } from "./_internal/client/scaffolds/index";
|
|
20
20
|
export { toClient, clientInitial } from "./_internal/shared/serialization/index";
|
|
21
|
-
export type { AppkitConfig } from "./_internal/shared/config/schema";
|
|
21
|
+
export type { AppkitConfig, AppkitFirebaseConfig, AppkitFirebaseExtensions, AppkitVercelConfig, AppkitBrandConfig, AppkitSeoConfig, AppkitI18nConfig, AppkitImagePattern, FirestoreIndex, FirestoreIndexField, FirestoreFieldOverride, } from "./_internal/shared/config/schema";
|
|
22
22
|
export { SEMANTIC_COLORS, SEMANTIC_COLORS_DARK, SEMANTIC_RADIUS, SEMANTIC_SHADOWS, SEMANTIC_Z_INDEX, MOTION_TOKENS, BREAKPOINTS, PLATFORM_LIMITS, } from "./_internal/shared/tokens/index";
|
|
23
23
|
export type { Responsive, Breakpoint, SemanticColor } from "./_internal/shared/tokens/index";
|
package/dist/client.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ export { Modal } from "./ui/components/Modal";
|
|
|
8
8
|
export { SideDrawer } from "./ui/components/SideDrawer";
|
|
9
9
|
export { SideModal } from "./ui/components/SideModal";
|
|
10
10
|
export { UnsavedChangesModal } from "./ui/components/UnsavedChangesModal";
|
|
11
|
+
export { LoginRequiredModal } from "./ui/components/LoginRequiredModal";
|
|
12
|
+
export type { LoginRequiredModalProps } from "./ui/components/LoginRequiredModal";
|
|
13
|
+
export { isAuthError } from "./utils/auth-error";
|
|
11
14
|
export { useToast } from "./ui/components/Toast";
|
|
12
15
|
export { useAuth } from "./react/contexts/SessionContext";
|
|
13
16
|
export { useCamera } from "./react/hooks/useCamera";
|
package/dist/client.js
CHANGED
|
@@ -27,6 +27,11 @@ export { SideModal } from "./ui/components/SideModal";
|
|
|
27
27
|
// [CLIENT-ONLY]-Cannot run in SSR mode â€" uses browser-only APIs (window, navigator, localStorage, matchMedia, DOM events) that do not exist in Node.js.
|
|
28
28
|
// UnsavedChangesModal - Component for unsaved changes modal.
|
|
29
29
|
export { UnsavedChangesModal } from "./ui/components/UnsavedChangesModal";
|
|
30
|
+
// [CLIENT-ONLY]-Cannot run in SSR mode — uses browser-only APIs (window.location).
|
|
31
|
+
// LoginRequiredModal - Modal prompting unauthenticated users to log in.
|
|
32
|
+
export { LoginRequiredModal } from "./ui/components/LoginRequiredModal";
|
|
33
|
+
// isAuthError - Detects auth/authorization errors from server actions or fetch responses.
|
|
34
|
+
export { isAuthError } from "./utils/auth-error";
|
|
30
35
|
// [CLIENT-ONLY]-Cannot run in SSR mode â€" uses browser-only APIs (window, navigator, localStorage, matchMedia, DOM events) that do not exist in Node.js.
|
|
31
36
|
// useToast - React hook for use toast.
|
|
32
37
|
export { useToast } from "./ui/components/Toast";
|
package/dist/configs/next.js
CHANGED
|
@@ -82,6 +82,10 @@ export function defineNextConfig(override = {}) {
|
|
|
82
82
|
// build/esm/, and any future subpackages are always included — no more
|
|
83
83
|
// per-subdirectory entries that silently miss e.g. build/protos/admin_v1.json.
|
|
84
84
|
// Consumer additions for the same route key are MERGED (array union), not replaced.
|
|
85
|
+
// List derived from full dynamic runtime trace (scripts/trace-firebase-full.mjs) plus
|
|
86
|
+
// known lazy-loaded packages (proxy agents, debug, stream utilities).
|
|
87
|
+
// Do NOT use broad @scope/** globs — the full firebase client SDK is hundreds of MB
|
|
88
|
+
// and causes Vercel's "Deploying outputs..." step to time out / fail.
|
|
85
89
|
const defaultOutputFileTracingIncludes = {
|
|
86
90
|
"/api/**": [
|
|
87
91
|
// Firebase Admin — entire package (lib/ + esm/, all sub-SDKs)
|
|
@@ -108,100 +112,48 @@ export function defineNextConfig(override = {}) {
|
|
|
108
112
|
"./node_modules/duplexify/**",
|
|
109
113
|
"./node_modules/uuid/**",
|
|
110
114
|
"./node_modules/lodash.camelcase/**",
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
"./node_modules/@firebase/database/**",
|
|
114
|
-
"./node_modules/@firebase/database-compat/**",
|
|
115
|
-
"./node_modules/@firebase/database-types/**",
|
|
116
|
-
"./node_modules/@firebase/logger/**",
|
|
117
|
-
"./node_modules/@firebase/util/**",
|
|
118
|
-
"./node_modules/@firebase/component/**",
|
|
119
|
-
"./node_modules/@firebase/app-check-interop-types/**",
|
|
120
|
-
"./node_modules/@firebase/auth-interop-types/**",
|
|
121
|
-
"./node_modules/@firebase/app-types/**",
|
|
122
|
-
// OpenTelemetry API (used by google-gax for tracing — api package only, no deps)
|
|
115
|
+
// Packages confirmed by dynamic runtime trace (trace-firebase-full.mjs) as loaded
|
|
116
|
+
// at cold start but not followed by Vercel's static file tracer:
|
|
123
117
|
"./node_modules/@opentelemetry/api/**",
|
|
124
|
-
|
|
125
|
-
"./node_modules
|
|
126
|
-
|
|
127
|
-
"./node_modules
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
"./node_modules/extend/**",
|
|
133
|
-
"./node_modules/https-proxy-agent/**",
|
|
134
|
-
"./node_modules/agent-base/**",
|
|
118
|
+
"./node_modules/@js-sdsl/ordered-map/**",
|
|
119
|
+
"./node_modules/base64-js/**",
|
|
120
|
+
"./node_modules/bignumber.js/**",
|
|
121
|
+
"./node_modules/ecdsa-sig-formatter/**",
|
|
122
|
+
"./node_modules/event-target-shim/**",
|
|
123
|
+
"./node_modules/fast-deep-equal/**",
|
|
124
|
+
"./node_modules/jwa/**",
|
|
125
|
+
// Stream / encoding utilities (loaded by duplexify / readable-stream / gRPC chain):
|
|
135
126
|
"./node_modules/readable-stream/**",
|
|
136
127
|
"./node_modules/inherits/**",
|
|
137
|
-
"./node_modules/debug/**",
|
|
138
|
-
"./node_modules/ms/**",
|
|
139
128
|
"./node_modules/end-of-stream/**",
|
|
140
129
|
"./node_modules/once/**",
|
|
141
130
|
"./node_modules/wrappy/**",
|
|
142
131
|
"./node_modules/stream-shift/**",
|
|
143
|
-
"./node_modules/stream-events/**",
|
|
144
132
|
"./node_modules/safe-buffer/**",
|
|
145
|
-
"./node_modules/string_decoder/**",
|
|
146
133
|
"./node_modules/util-deprecate/**",
|
|
147
|
-
|
|
134
|
+
// Auth / HTTP utilities:
|
|
135
|
+
"./node_modules/is-stream/**",
|
|
136
|
+
"./node_modules/extend/**",
|
|
137
|
+
"./node_modules/https-proxy-agent/**",
|
|
138
|
+
"./node_modules/agent-base/**",
|
|
148
139
|
"./node_modules/http-proxy-agent/**",
|
|
140
|
+
"./node_modules/debug/**",
|
|
141
|
+
"./node_modules/ms/**",
|
|
142
|
+
// Google Cloud metadata / logging / misc:
|
|
149
143
|
"./node_modules/gcp-metadata/**",
|
|
150
144
|
"./node_modules/json-bigint/**",
|
|
151
|
-
"./node_modules/
|
|
145
|
+
"./node_modules/google-logging-utils/**",
|
|
146
|
+
// teeny-request (used by retry-request for HTTP retries):
|
|
147
|
+
"./node_modules/teeny-request/**",
|
|
152
148
|
"./node_modules/form-data/**",
|
|
153
149
|
"./node_modules/combined-stream/**",
|
|
154
150
|
"./node_modules/delayed-stream/**",
|
|
155
151
|
"./node_modules/asynckit/**",
|
|
156
152
|
"./node_modules/mime-types/**",
|
|
157
153
|
"./node_modules/mime-db/**",
|
|
158
|
-
"./node_modules/
|
|
159
|
-
"./node_modules/
|
|
160
|
-
"./node_modules/
|
|
161
|
-
"./node_modules/websocket-driver/**",
|
|
162
|
-
"./node_modules/websocket-extensions/**",
|
|
163
|
-
"./node_modules/http-parser-js/**",
|
|
164
|
-
"./node_modules/functional-red-black-tree/**",
|
|
165
|
-
"./node_modules/fast-xml-parser/**",
|
|
166
|
-
"./node_modules/fast-xml-builder/**",
|
|
167
|
-
"./node_modules/strnum/**",
|
|
168
|
-
"./node_modules/html-entities/**",
|
|
169
|
-
"./node_modules/jose/**",
|
|
170
|
-
"./node_modules/jsonwebtoken/**",
|
|
171
|
-
"./node_modules/jwa/**",
|
|
172
|
-
"./node_modules/jwks-rsa/**",
|
|
173
|
-
"./node_modules/lru-memoizer/**",
|
|
174
|
-
"./node_modules/limiter/**",
|
|
175
|
-
"./node_modules/node-forge/**",
|
|
176
|
-
"./node_modules/lru-cache/**",
|
|
177
|
-
"./node_modules/yallist/**",
|
|
178
|
-
"./node_modules/async-retry/**",
|
|
179
|
-
"./node_modules/retry/**",
|
|
180
|
-
"./node_modules/p-limit/**",
|
|
181
|
-
"./node_modules/yocto-queue/**",
|
|
182
|
-
"./node_modules/arrify/**",
|
|
183
|
-
"./node_modules/semver/**",
|
|
184
|
-
"./node_modules/fast-deep-equal/**",
|
|
185
|
-
"./node_modules/tslib/**",
|
|
186
|
-
"./node_modules/base64-js/**",
|
|
187
|
-
"./node_modules/bignumber.js/**",
|
|
188
|
-
"./node_modules/farmhash-modern/**",
|
|
189
|
-
"./node_modules/mime/**",
|
|
190
|
-
"./node_modules/punycode/**",
|
|
191
|
-
"./node_modules/whatwg-url/**",
|
|
192
|
-
"./node_modules/tr46/**",
|
|
193
|
-
"./node_modules/webidl-conversions/**",
|
|
194
|
-
"./node_modules/path-expression-matcher/**",
|
|
195
|
-
"./node_modules/ecdsa-sig-formatter/**",
|
|
196
|
-
"./node_modules/buffer-equal-constant-time/**",
|
|
197
|
-
"./node_modules/lodash.clonedeep/**",
|
|
198
|
-
"./node_modules/lodash.includes/**",
|
|
199
|
-
"./node_modules/lodash.isboolean/**",
|
|
200
|
-
"./node_modules/lodash.isinteger/**",
|
|
201
|
-
"./node_modules/lodash.isnumber/**",
|
|
202
|
-
"./node_modules/lodash.isplainobject/**",
|
|
203
|
-
"./node_modules/lodash.isstring/**",
|
|
204
|
-
"./node_modules/lodash.once/**",
|
|
154
|
+
"./node_modules/stream-events/**",
|
|
155
|
+
"./node_modules/stubs/**",
|
|
156
|
+
"./node_modules/string_decoder/**",
|
|
205
157
|
],
|
|
206
158
|
};
|
|
207
159
|
const mergedOutputFileTracingIncludes = {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useCallback, useEffect, useState, useTransition } from "react";
|
|
4
|
-
import { Alert, Badge, Button, Div, Heading, Spinner, Text } from "../../../ui";
|
|
4
|
+
import { Alert, Badge, Button, Div, Heading, LoginRequiredModal, Spinner, Text } from "../../../ui";
|
|
5
|
+
import { isAuthError } from "../../../utils/auth-error";
|
|
5
6
|
function formatRupees(amount) {
|
|
6
7
|
if (amount === undefined || amount === null)
|
|
7
8
|
return "—";
|
|
@@ -32,7 +33,7 @@ function statusVariant(status) {
|
|
|
32
33
|
default: return "default";
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
function BuyerOfferCard({ offer, onAcceptCounter, onWithdraw, onCheckout, onUpdate }) {
|
|
36
|
+
function BuyerOfferCard({ offer, onAcceptCounter, onWithdraw, onCheckout, onUpdate, onNeedsLogin }) {
|
|
36
37
|
const [error, setError] = useState("");
|
|
37
38
|
const [isPending, startTransition] = useTransition();
|
|
38
39
|
const [confirming, setConfirming] = useState(null);
|
|
@@ -45,7 +46,12 @@ function BuyerOfferCard({ offer, onAcceptCounter, onWithdraw, onCheckout, onUpda
|
|
|
45
46
|
setConfirming(null);
|
|
46
47
|
}
|
|
47
48
|
catch (err) {
|
|
48
|
-
|
|
49
|
+
if (isAuthError(err)) {
|
|
50
|
+
onNeedsLogin();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
setError(err instanceof Error ? err.message : "Something went wrong.");
|
|
54
|
+
}
|
|
49
55
|
}
|
|
50
56
|
});
|
|
51
57
|
}
|
|
@@ -55,13 +61,19 @@ export function UserOffersPanel({ fetchEndpoint = "/api/user/offers", onAcceptCo
|
|
|
55
61
|
const [offers, setOffers] = useState([]);
|
|
56
62
|
const [loading, setLoading] = useState(true);
|
|
57
63
|
const [fetchError, setFetchError] = useState("");
|
|
64
|
+
const [showLoginModal, setShowLoginModal] = useState(false);
|
|
58
65
|
const loadOffers = useCallback(async () => {
|
|
59
66
|
setLoading(true);
|
|
60
67
|
setFetchError("");
|
|
61
68
|
try {
|
|
62
69
|
const res = await fetch(fetchEndpoint);
|
|
63
|
-
if (!res.ok)
|
|
70
|
+
if (!res.ok) {
|
|
71
|
+
if (res.status === 401 || res.status === 403) {
|
|
72
|
+
setShowLoginModal(true);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
64
75
|
throw new Error(`Error ${res.status}`);
|
|
76
|
+
}
|
|
65
77
|
const json = (await res.json());
|
|
66
78
|
const items = Array.isArray(json) ? json : (json.items ?? []);
|
|
67
79
|
setOffers(items);
|
|
@@ -77,5 +89,5 @@ export function UserOffersPanel({ fetchEndpoint = "/api/user/offers", onAcceptCo
|
|
|
77
89
|
function handleUpdate(id, patch) {
|
|
78
90
|
setOffers((prev) => prev.map((o) => (o.id === id ? { ...o, ...patch } : o)));
|
|
79
91
|
}
|
|
80
|
-
return (_jsxs(Div, { className: `space-y-4 ${className}`, children: [_jsxs(Div, { className: "flex items-center justify-between", children: [_jsx(Heading, { level: 2, className: "text-lg font-semibold text-zinc-900 dark:text-zinc-100", children: "My Offers" }), _jsx(Button, { size: "sm", variant: "ghost", onClick: loadOffers, disabled: loading, className: "border border-zinc-300 dark:border-zinc-600 text-xs", children: loading ? "Refreshing…" : "Refresh" })] }), fetchError && _jsx(Alert, { variant: "error", children: _jsx(Text, { className: "text-sm", children: fetchError }) }), loading && (_jsx(Div, { className: "flex justify-center py-12", children: _jsx(Spinner, { size: "lg" }) })), !loading && offers.length === 0 && (_jsx(Div, { className: "text-center py-12", children: _jsx(Text, { className: "text-zinc-400 dark:text-zinc-500 text-sm", children: "No offers yet" }) })), !loading && offers.length > 0 && (_jsx(Div, { className: "space-y-3", children: offers.map((offer) => (_jsx(BuyerOfferCard, { offer: offer, onAcceptCounter: onAcceptCounter, onWithdraw: onWithdraw, onCheckout: onCheckout, onUpdate: handleUpdate }, offer.id))) }))] }));
|
|
92
|
+
return (_jsxs(Div, { className: `space-y-4 ${className}`, children: [_jsx(LoginRequiredModal, { isOpen: showLoginModal, onClose: () => setShowLoginModal(false), message: "You need to be signed in to manage your offers. Please log in or create an account to continue." }), _jsxs(Div, { className: "flex items-center justify-between", children: [_jsx(Heading, { level: 2, className: "text-lg font-semibold text-zinc-900 dark:text-zinc-100", children: "My Offers" }), _jsx(Button, { size: "sm", variant: "ghost", onClick: loadOffers, disabled: loading, className: "border border-zinc-300 dark:border-zinc-600 text-xs", children: loading ? "Refreshing…" : "Refresh" })] }), fetchError && _jsx(Alert, { variant: "error", children: _jsx(Text, { className: "text-sm", children: fetchError }) }), loading && (_jsx(Div, { className: "flex justify-center py-12", children: _jsx(Spinner, { size: "lg" }) })), !loading && offers.length === 0 && (_jsx(Div, { className: "text-center py-12", children: _jsx(Text, { className: "text-zinc-400 dark:text-zinc-500 text-sm", children: "No offers yet" }) })), !loading && offers.length > 0 && (_jsx(Div, { className: "space-y-3", children: offers.map((offer) => (_jsx(BuyerOfferCard, { offer: offer, onAcceptCounter: onAcceptCounter, onWithdraw: onWithdraw, onCheckout: onCheckout, onUpdate: handleUpdate, onNeedsLogin: () => setShowLoginModal(true) }, offer.id))) }))] }));
|
|
81
93
|
}
|
|
@@ -137,8 +137,24 @@ export async function AuctionDetailPageView({ id, initialAuction, onPlaceBid, pr
|
|
|
137
137
|
}));
|
|
138
138
|
return _jsx(CollapsibleBidHistory, { bids: bids, currency: currency });
|
|
139
139
|
}, renderRelated: () => {
|
|
140
|
+
const now = new Date();
|
|
140
141
|
const related = relatedDocs
|
|
141
|
-
.filter((r) =>
|
|
142
|
+
.filter((r) => {
|
|
143
|
+
if (r.id === product.id || r.listingType !== "auction")
|
|
144
|
+
return false;
|
|
145
|
+
const s = r.status;
|
|
146
|
+
if (s && ["sold", "out_of_stock", "archived", "discontinued", "draft"].includes(s))
|
|
147
|
+
return false;
|
|
148
|
+
if (r.isSold === true)
|
|
149
|
+
return false;
|
|
150
|
+
const end = r.auctionEndDate;
|
|
151
|
+
if (!end)
|
|
152
|
+
return true;
|
|
153
|
+
const endDate = typeof end.toDate === "function"
|
|
154
|
+
? end.toDate()
|
|
155
|
+
: end instanceof Date ? end : new Date(String(end));
|
|
156
|
+
return endDate > now;
|
|
157
|
+
})
|
|
142
158
|
.slice(0, 4)
|
|
143
159
|
.map((r) => ({
|
|
144
160
|
id: String(r.id ?? ""),
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useTransition } from "react";
|
|
4
4
|
import { formatCurrency } from "../../../utils/number.formatter";
|
|
5
|
-
import {
|
|
5
|
+
import { isAuthError } from "../../../utils/auth-error";
|
|
6
|
+
import { Button, Div, Input, LoginRequiredModal, Row, Span, Stack, Text } from "../../../ui";
|
|
6
7
|
export function PlaceBidFormClient({ productId, currentBid, startingBid, minBidIncrement, currency, isEnded, buyNowPrice, bidCount, tags = [], onPlaceBid, }) {
|
|
7
8
|
const minBid = currentBid + minBidIncrement;
|
|
8
9
|
const [bidAmount, setBidAmount] = useState(String(minBid));
|
|
9
10
|
const [isPending, startTransition] = useTransition();
|
|
10
11
|
const [error, setError] = useState(null);
|
|
11
12
|
const [success, setSuccess] = useState(false);
|
|
13
|
+
const [showLoginModal, setShowLoginModal] = useState(false);
|
|
12
14
|
function handleSubmit(e) {
|
|
13
15
|
e.preventDefault();
|
|
14
16
|
const amount = Number(bidAmount);
|
|
@@ -33,11 +35,14 @@ export function PlaceBidFormClient({ productId, currentBid, startingBid, minBidI
|
|
|
33
35
|
setBidAmount(String(amount + minBidIncrement));
|
|
34
36
|
}
|
|
35
37
|
catch (err) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
if (isAuthError(err)) {
|
|
39
|
+
setShowLoginModal(true);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
setError(err instanceof Error ? err.message : "Failed to place bid. Please try again.");
|
|
43
|
+
}
|
|
39
44
|
}
|
|
40
45
|
});
|
|
41
46
|
}
|
|
42
|
-
return (_jsxs(Div, { className: "rounded-xl border border-zinc-100 dark:border-zinc-800 bg-zinc-50 dark:bg-zinc-900/60 p-5 space-y-4", children: [_jsxs(Div, { className: "space-y-1", children: [_jsxs(Row, { justify: "between", align: "center", children: [_jsx(Text, { className: "text-xs text-zinc-500", children: "Current bid" }), _jsx(Text, { className: "text-xs text-zinc-500", children: "Starting bid" })] }), _jsxs(Row, { justify: "between", align: "baseline", children: [_jsx(Span, { className: "text-xl font-bold text-primary-600 dark:text-primary-400", children: formatCurrency(currentBid, currency) }), _jsx(Span, { className: "text-sm text-zinc-500", children: formatCurrency(startingBid, currency) })] }), _jsxs(Text, { className: "text-xs text-zinc-400 dark:text-zinc-500", children: [bidCount, " ", bidCount === 1 ? "bid" : "bids", " \u00B7 min increment", " ", formatCurrency(minBidIncrement, currency)] })] }), _jsx("form", { onSubmit: handleSubmit, children: _jsxs(Stack, { gap: "sm", children: [_jsx(Input, { type: "number", value: bidAmount, onChange: (e) => setBidAmount(e.target.value), placeholder: `At least ${formatCurrency(minBid, currency)}`, min: minBid, step: minBidIncrement, "aria-label": "Your bid amount", disabled: isEnded || isPending }), error && (_jsx(Text, { className: "text-xs text-red-600 dark:text-red-400", children: error })), success && (_jsx(Text, { className: "text-xs text-emerald-600 dark:text-emerald-400", children: "\u2713 Bid placed successfully!" })), _jsx(Button, { variant: "primary", size: "md", className: "w-full", disabled: isEnded || isPending, type: "submit", children: isPending ? "Placing Bid…" : isEnded ? "Auction Ended" : "Place Bid" }), buyNowPrice !== null && !isEnded && (_jsxs(Button, { variant: "secondary", size: "md", className: "w-full", type: "button", children: ["Buy Now \u2014 ", formatCurrency(buyNowPrice, currency)] }))] }) }), tags.length > 0 && (_jsx(Div, { className: "border-t border-zinc-200 dark:border-zinc-700 pt-4", children: _jsx(Row, { wrap: true, gap: "xs", children: tags.map((tag) => (_jsx(Span, { className: "rounded-full bg-zinc-100 dark:bg-zinc-800 px-2.5 py-1 text-xs text-zinc-600 dark:text-zinc-300", children: tag }, tag))) }) }))] }));
|
|
47
|
+
return (_jsxs(Div, { className: "rounded-xl border border-zinc-100 dark:border-zinc-800 bg-zinc-50 dark:bg-zinc-900/60 p-5 space-y-4", children: [_jsxs(Div, { className: "space-y-1", children: [_jsxs(Row, { justify: "between", align: "center", children: [_jsx(Text, { className: "text-xs text-zinc-500", children: "Current bid" }), _jsx(Text, { className: "text-xs text-zinc-500", children: "Starting bid" })] }), _jsxs(Row, { justify: "between", align: "baseline", children: [_jsx(Span, { className: "text-xl font-bold text-primary-600 dark:text-primary-400", children: formatCurrency(currentBid, currency) }), _jsx(Span, { className: "text-sm text-zinc-500", children: formatCurrency(startingBid, currency) })] }), _jsxs(Text, { className: "text-xs text-zinc-400 dark:text-zinc-500", children: [bidCount, " ", bidCount === 1 ? "bid" : "bids", " \u00B7 min increment", " ", formatCurrency(minBidIncrement, currency)] })] }), _jsx(LoginRequiredModal, { isOpen: showLoginModal, onClose: () => setShowLoginModal(false), message: "You need to be signed in to place a bid. Please log in or create an account to continue." }), _jsx("form", { onSubmit: handleSubmit, children: _jsxs(Stack, { gap: "sm", children: [_jsx(Input, { type: "number", value: bidAmount, onChange: (e) => setBidAmount(e.target.value), placeholder: `At least ${formatCurrency(minBid, currency)}`, min: minBid, step: minBidIncrement, "aria-label": "Your bid amount", disabled: isEnded || isPending }), error && (_jsx(Text, { className: "text-xs text-red-600 dark:text-red-400", children: error })), success && (_jsx(Text, { className: "text-xs text-emerald-600 dark:text-emerald-400", children: "\u2713 Bid placed successfully!" })), _jsx(Button, { variant: "primary", size: "md", className: "w-full", disabled: isEnded || isPending, type: "submit", children: isPending ? "Placing Bid…" : isEnded ? "Auction Ended" : "Place Bid" }), buyNowPrice !== null && !isEnded && (_jsxs(Button, { variant: "secondary", size: "md", className: "w-full", type: "button", children: ["Buy Now \u2014 ", formatCurrency(buyNowPrice, currency)] }))] }) }), tags.length > 0 && (_jsx(Div, { className: "border-t border-zinc-200 dark:border-zinc-700 pt-4", children: _jsx(Row, { wrap: true, gap: "xs", children: tags.map((tag) => (_jsx(Span, { className: "rounded-full bg-zinc-100 dark:bg-zinc-800 px-2.5 py-1 text-xs text-zinc-600 dark:text-zinc-300", children: tag }, tag))) }) }))] }));
|
|
43
48
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
/**
|
|
4
4
|
* BundleBuyNowCta — direct-checkout CTA for bundle detail pages.
|
|
5
5
|
*
|
|
@@ -8,13 +8,15 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
8
8
|
* No qty input — bundles are always qty=1 per checkout.
|
|
9
9
|
*/
|
|
10
10
|
import { useState, useCallback } from "react";
|
|
11
|
-
import { Button, Stack, Text } from "../../../ui";
|
|
11
|
+
import { Button, LoginRequiredModal, Stack, Text } from "../../../ui";
|
|
12
12
|
import { useToast } from "../../../ui";
|
|
13
|
+
import { isAuthError } from "../../../utils/auth-error";
|
|
13
14
|
import { BUNDLE_COPY } from "../../../_internal/shared/features/categories/bundle-copy";
|
|
14
15
|
export function BundleBuyNowCta({ bundleSlug, outOfStock = false, onBuyNow, }) {
|
|
15
16
|
const { showToast } = useToast();
|
|
16
17
|
const [submitting, setSubmitting] = useState(false);
|
|
17
18
|
const [error, setError] = useState(null);
|
|
19
|
+
const [showLoginModal, setShowLoginModal] = useState(false);
|
|
18
20
|
const handleClick = useCallback(async () => {
|
|
19
21
|
setError(null);
|
|
20
22
|
setSubmitting(true);
|
|
@@ -22,9 +24,14 @@ export function BundleBuyNowCta({ bundleSlug, outOfStock = false, onBuyNow, }) {
|
|
|
22
24
|
await onBuyNow({ bundleSlug });
|
|
23
25
|
}
|
|
24
26
|
catch (err) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
if (isAuthError(err)) {
|
|
28
|
+
setShowLoginModal(true);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const message = err instanceof Error ? err.message : BUNDLE_COPY.detail.ctaErrorFallback;
|
|
32
|
+
setError(message);
|
|
33
|
+
showToast(message, "error");
|
|
34
|
+
}
|
|
28
35
|
}
|
|
29
36
|
finally {
|
|
30
37
|
setSubmitting(false);
|
|
@@ -33,5 +40,5 @@ export function BundleBuyNowCta({ bundleSlug, outOfStock = false, onBuyNow, }) {
|
|
|
33
40
|
if (outOfStock) {
|
|
34
41
|
return (_jsxs(Stack, { gap: "xs", "aria-live": "polite", children: [_jsx(Button, { variant: "primary", disabled: true, "aria-disabled": true, children: BUNDLE_COPY.detail.ctaOutOfStock }), _jsx(Text, { size: "xs", color: "muted", children: BUNDLE_COPY.detail.ctaHint })] }));
|
|
35
42
|
}
|
|
36
|
-
return (_jsxs(Stack, { gap: "sm", children: [_jsx(Button, { variant: "primary", onClick: handleClick, disabled: submitting, "aria-busy": submitting, children: submitting ? BUNDLE_COPY.detail.ctaAdding : BUNDLE_COPY.detail.ctaBuyNow }), error && (_jsx(Text, { size: "sm", color: "danger", role: "alert", children: error }))] }));
|
|
43
|
+
return (_jsxs(_Fragment, { children: [_jsx(LoginRequiredModal, { isOpen: showLoginModal, onClose: () => setShowLoginModal(false), message: "You need to be signed in to purchase this bundle. Please log in or create an account to continue." }), _jsxs(Stack, { gap: "sm", children: [_jsx(Button, { variant: "primary", onClick: handleClick, disabled: submitting, "aria-busy": submitting, children: submitting ? BUNDLE_COPY.detail.ctaAdding : BUNDLE_COPY.detail.ctaBuyNow }), error && (_jsx(Text, { size: "sm", color: "danger", role: "alert", children: error }))] })] }));
|
|
37
44
|
}
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { useAuth } from "../../../react/contexts/SessionContext";
|
|
5
5
|
import { ROUTES } from "../../../next";
|
|
6
|
+
import { LoginRequiredModal } from "../../../ui";
|
|
6
7
|
export function EventPollWidget({ eventId, pollConfig, eventStatus, totalEntries, entriesEndpoint, className = "", }) {
|
|
7
8
|
const { user } = useAuth();
|
|
8
9
|
const endpoint = entriesEndpoint ?? `/api/events/${eventId}/entries`;
|
|
@@ -13,6 +14,7 @@ export function EventPollWidget({ eventId, pollConfig, eventStatus, totalEntries
|
|
|
13
14
|
const [isLoading, setIsLoading] = useState(false);
|
|
14
15
|
const [isSubmitted, setIsSubmitted] = useState(false);
|
|
15
16
|
const [error, setError] = useState(null);
|
|
17
|
+
const [showLoginModal, setShowLoginModal] = useState(false);
|
|
16
18
|
const toggleVote = (id) => {
|
|
17
19
|
if (isMulti) {
|
|
18
20
|
setSelectedVotes((prev) => prev.includes(id) ? prev.filter((v) => v !== id) : [...prev, id]);
|
|
@@ -37,6 +39,10 @@ export function EventPollWidget({ eventId, pollConfig, eventStatus, totalEntries
|
|
|
37
39
|
credentials: "include",
|
|
38
40
|
});
|
|
39
41
|
if (!res.ok) {
|
|
42
|
+
if (res.status === 401 || res.status === 403) {
|
|
43
|
+
setShowLoginModal(true);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
40
46
|
const data = (await res.json().catch(() => ({})));
|
|
41
47
|
throw new Error(data.error ?? "Failed to submit vote");
|
|
42
48
|
}
|
|
@@ -58,5 +64,5 @@ export function EventPollWidget({ eventId, pollConfig, eventStatus, totalEntries
|
|
|
58
64
|
if (isSubmitted) {
|
|
59
65
|
return (_jsxs("div", { className: `rounded-xl border border-green-200 dark:border-green-800 bg-green-50 dark:bg-green-900/20 px-6 py-8 text-center space-y-2 ${className}`, "data-section": "eventpollwidget-div-5", children: [_jsx("p", { className: "font-semibold text-green-700 dark:text-green-300", children: "Vote recorded!" }), _jsx("p", { className: "text-sm text-zinc-500 dark:text-zinc-400", children: "Thanks for participating." })] }));
|
|
60
66
|
}
|
|
61
|
-
return (_jsxs("div", { className: `space-y-4 ${className}`, "data-section": "eventpollwidget-div-6", children: [_jsx("p", { className: "text-sm font-medium text-zinc-700 dark:text-zinc-200", children: isMulti ? "Select all that apply:" : "Choose one:" }), _jsx("div", { className: "space-y-2", "data-section": "eventpollwidget-div-7", children: pollConfig.options.map((opt) => (_jsxs("label", { className: "flex items-center gap-3 cursor-pointer rounded-lg border border-zinc-200 dark:border-zinc-700 px-4 py-3 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors", children: [_jsx("input", { type: isMulti ? "checkbox" : "radio", name: `poll-${eventId}`, value: opt.id, checked: selectedVotes.includes(opt.id), onChange: () => toggleVote(opt.id), className: "accent-primary" }), _jsx("span", { className: "text-sm text-zinc-700 dark:text-zinc-300", children: opt.label })] }, opt.id))) }), pollConfig.allowComment && (_jsx("textarea", { value: comment, onChange: (e) => setComment(e.target.value), placeholder: "Add a comment (optional)", rows: 3, className: "w-full rounded-lg border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-800 px-3 py-2 text-sm text-zinc-800 dark:text-zinc-200 placeholder:text-zinc-400 focus:outline-none focus:ring-2 focus:ring-primary" })), error && _jsx("p", { className: "text-sm text-red-500", children: error }), _jsx("button", { type: "button", onClick: handleSubmit, disabled: isLoading || selectedVotes.length === 0, className: "w-full rounded-xl bg-primary px-6 py-3 text-sm font-semibold text-white hover:bg-primary-600 disabled:opacity-60", children: isLoading ? "Submitting…" : "Submit Vote" })] }));
|
|
67
|
+
return (_jsxs("div", { className: `space-y-4 ${className}`, "data-section": "eventpollwidget-div-6", children: [_jsx(LoginRequiredModal, { isOpen: showLoginModal, onClose: () => setShowLoginModal(false), message: "You need to be signed in to vote in this poll. Please log in or create an account to continue." }), _jsx("p", { className: "text-sm font-medium text-zinc-700 dark:text-zinc-200", children: isMulti ? "Select all that apply:" : "Choose one:" }), _jsx("div", { className: "space-y-2", "data-section": "eventpollwidget-div-7", children: pollConfig.options.map((opt) => (_jsxs("label", { className: "flex items-center gap-3 cursor-pointer rounded-lg border border-zinc-200 dark:border-zinc-700 px-4 py-3 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors", children: [_jsx("input", { type: isMulti ? "checkbox" : "radio", name: `poll-${eventId}`, value: opt.id, checked: selectedVotes.includes(opt.id), onChange: () => toggleVote(opt.id), className: "accent-primary" }), _jsx("span", { className: "text-sm text-zinc-700 dark:text-zinc-300", children: opt.label })] }, opt.id))) }), pollConfig.allowComment && (_jsx("textarea", { value: comment, onChange: (e) => setComment(e.target.value), placeholder: "Add a comment (optional)", rows: 3, className: "w-full rounded-lg border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-800 px-3 py-2 text-sm text-zinc-800 dark:text-zinc-200 placeholder:text-zinc-400 focus:outline-none focus:ring-2 focus:ring-primary" })), error && _jsx("p", { className: "text-sm text-red-500", children: error }), _jsx("button", { type: "button", onClick: handleSubmit, disabled: isLoading || selectedVotes.length === 0, className: "w-full rounded-xl bg-primary px-6 py-3 text-sm font-semibold text-white hover:bg-primary-600 disabled:opacity-60", children: isLoading ? "Submitting…" : "Submit Vote" })] }));
|
|
62
68
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useCallback, useMemo, useState } from "react";
|
|
4
|
-
import { Button, Div, Heading, Span, Text } from "../../../ui";
|
|
4
|
+
import { Button, Div, Heading, LoginRequiredModal, Span, Text } from "../../../ui";
|
|
5
|
+
import { isAuthError } from "../../../utils/auth-error";
|
|
5
6
|
const DEFAULT_LABELS = {
|
|
6
7
|
heading: "Spin the Wheel",
|
|
7
8
|
spinButton: "Spin",
|
|
@@ -20,6 +21,7 @@ export function SpinWheelView({ eventId, prizes, alreadyUsed, initialPrizeId, in
|
|
|
20
21
|
const [resultPrizeId, setResultPrizeId] = useState(initialPrizeId);
|
|
21
22
|
const [resultCoupon, setResultCoupon] = useState(initialCouponCode);
|
|
22
23
|
const [error, setError] = useState(null);
|
|
24
|
+
const [showLoginModal, setShowLoginModal] = useState(false);
|
|
23
25
|
const now = Date.now();
|
|
24
26
|
const startMs = windowStart ? new Date(windowStart).getTime() : null;
|
|
25
27
|
const endMs = windowEnd ? new Date(windowEnd).getTime() : null;
|
|
@@ -43,15 +45,20 @@ export function SpinWheelView({ eventId, prizes, alreadyUsed, initialPrizeId, in
|
|
|
43
45
|
}
|
|
44
46
|
}, ANIMATION_MS);
|
|
45
47
|
}
|
|
46
|
-
catch {
|
|
48
|
+
catch (err) {
|
|
47
49
|
setSpinning(false);
|
|
48
|
-
|
|
50
|
+
if (isAuthError(err)) {
|
|
51
|
+
setShowLoginModal(true);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
setError(l.errorFallback);
|
|
55
|
+
}
|
|
49
56
|
}
|
|
50
57
|
}, [disabled, eventId, l.errorFallback, onSpin]);
|
|
51
58
|
const wonPrize = resultPrizeId
|
|
52
59
|
? activePrizes.find((p) => p.id === resultPrizeId)
|
|
53
60
|
: undefined;
|
|
54
|
-
return (_jsxs(Div, { className: "space-y-4", children: [_jsxs(Heading, { level: 2, className: "text-xl font-semibold text-zinc-900 dark:text-zinc-100", children: ["\uD83C\uDFA1 ", l.heading] }), _jsxs(Div, { className: "relative mx-auto aspect-square w-64 overflow-hidden rounded-full border-4 border-amber-400 bg-gradient-to-br from-amber-100 via-rose-100 to-violet-100 dark:from-amber-900/40 dark:via-rose-900/40 dark:to-violet-900/40", "aria-label": "Spin wheel", children: [_jsx(Div, { className: "absolute inset-0 flex items-center justify-center", style: {
|
|
61
|
+
return (_jsxs(Div, { className: "space-y-4", children: [_jsx(LoginRequiredModal, { isOpen: showLoginModal, onClose: () => setShowLoginModal(false), message: "You need to be signed in to spin the wheel. Please log in or create an account to continue." }), _jsxs(Heading, { level: 2, className: "text-xl font-semibold text-zinc-900 dark:text-zinc-100", children: ["\uD83C\uDFA1 ", l.heading] }), _jsxs(Div, { className: "relative mx-auto aspect-square w-64 overflow-hidden rounded-full border-4 border-amber-400 bg-gradient-to-br from-amber-100 via-rose-100 to-violet-100 dark:from-amber-900/40 dark:via-rose-900/40 dark:to-violet-900/40", "aria-label": "Spin wheel", children: [_jsx(Div, { className: "absolute inset-0 flex items-center justify-center", style: {
|
|
55
62
|
animation: spinning
|
|
56
63
|
? `lir-spin ${ANIMATION_MS}ms cubic-bezier(0.2, 0.8, 0.2, 1)`
|
|
57
64
|
: undefined,
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useTransition } from "react";
|
|
4
|
-
import { Button, Div, Stack, Text } from "../../../ui";
|
|
4
|
+
import { Button, Div, LoginRequiredModal, Stack, Text } from "../../../ui";
|
|
5
|
+
import { isAuthError } from "../../../utils/auth-error";
|
|
5
6
|
import { formatCurrency } from "../../../utils/number.formatter";
|
|
6
7
|
export function PreOrderActionsClient({ productId, price, currency, depositAmount, depositPercent, isCancellable, tags = [], onReserveNow, }) {
|
|
7
8
|
const [isPending, startTransition] = useTransition();
|
|
8
9
|
const [error, setError] = useState(null);
|
|
9
10
|
const [success, setSuccess] = useState(false);
|
|
11
|
+
const [showLoginModal, setShowLoginModal] = useState(false);
|
|
10
12
|
function handleReserve() {
|
|
11
13
|
setError(null);
|
|
12
14
|
setSuccess(false);
|
|
@@ -16,11 +18,16 @@ export function PreOrderActionsClient({ productId, price, currency, depositAmoun
|
|
|
16
18
|
setSuccess(true);
|
|
17
19
|
}
|
|
18
20
|
catch (err) {
|
|
19
|
-
|
|
21
|
+
if (isAuthError(err)) {
|
|
22
|
+
setShowLoginModal(true);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
setError(err instanceof Error ? err.message : "Failed to reserve. Please try again.");
|
|
26
|
+
}
|
|
20
27
|
}
|
|
21
28
|
});
|
|
22
29
|
}
|
|
23
|
-
return (_jsxs(Div, { className: "space-y-4", children: [price !== null && (_jsxs(Div, { children: [_jsx(Text, { className: "text-2xl font-bold text-zinc-900 dark:text-zinc-50", children: formatCurrency(price, currency) }), depositAmount !== null && (_jsxs(Text, { className: "mt-0.5 text-xs text-zinc-500", children: ["Reserve with ", formatCurrency(depositAmount, currency), depositPercent !== null ? ` (${depositPercent}% deposit)` : ""] }))] })), error && (_jsx(Text, { className: "text-xs text-red-600 dark:text-red-400", children: error })), success && (_jsx(Text, { className: "text-xs text-emerald-600 dark:text-emerald-400", children: "\u2713 Reserved! Redirecting to checkout\u2026" })), _jsxs(Stack, { gap: "sm", children: [_jsx(Button, { variant: "primary", size: "md", className: "w-full", disabled: isPending, onClick: handleReserve, children: isPending ? "Processing…" : "Reserve Now" }), isCancellable && (_jsx(Text, { className: "text-center text-xs text-zinc-500 dark:text-zinc-400", children: "\u2713 Free cancellation before production" }))] }), tags.length > 0 && (_jsx(Div, { className: "border-t border-zinc-200 dark:border-zinc-700 pt-4", children: _jsx("div", { className: "flex flex-wrap gap-1.5", children: tags.map((tag) => (_jsx("span", { className: "rounded-full bg-zinc-100 dark:bg-zinc-800 px-2.5 py-1 text-xs text-zinc-600 dark:text-zinc-300", children: tag }, tag))) }) })), _jsx(Div, { className: "border-t border-zinc-200 dark:border-zinc-700 pt-4", children: _jsx("div", { className: "flex flex-wrap gap-4 justify-center text-center", children: [
|
|
30
|
+
return (_jsxs(Div, { className: "space-y-4", children: [price !== null && (_jsxs(Div, { children: [_jsx(Text, { className: "text-2xl font-bold text-zinc-900 dark:text-zinc-50", children: formatCurrency(price, currency) }), depositAmount !== null && (_jsxs(Text, { className: "mt-0.5 text-xs text-zinc-500", children: ["Reserve with ", formatCurrency(depositAmount, currency), depositPercent !== null ? ` (${depositPercent}% deposit)` : ""] }))] })), error && (_jsx(Text, { className: "text-xs text-red-600 dark:text-red-400", children: error })), success && (_jsx(Text, { className: "text-xs text-emerald-600 dark:text-emerald-400", children: "\u2713 Reserved! Redirecting to checkout\u2026" })), _jsx(LoginRequiredModal, { isOpen: showLoginModal, onClose: () => setShowLoginModal(false), message: "You need to be signed in to reserve this pre-order. Please log in or create an account to continue." }), _jsxs(Stack, { gap: "sm", children: [_jsx(Button, { variant: "primary", size: "md", className: "w-full", disabled: isPending, onClick: handleReserve, children: isPending ? "Processing…" : "Reserve Now" }), isCancellable && (_jsx(Text, { className: "text-center text-xs text-zinc-500 dark:text-zinc-400", children: "\u2713 Free cancellation before production" }))] }), tags.length > 0 && (_jsx(Div, { className: "border-t border-zinc-200 dark:border-zinc-700 pt-4", children: _jsx("div", { className: "flex flex-wrap gap-1.5", children: tags.map((tag) => (_jsx("span", { className: "rounded-full bg-zinc-100 dark:bg-zinc-800 px-2.5 py-1 text-xs text-zinc-600 dark:text-zinc-300", children: tag }, tag))) }) })), _jsx(Div, { className: "border-t border-zinc-200 dark:border-zinc-700 pt-4", children: _jsx("div", { className: "flex flex-wrap gap-4 justify-center text-center", children: [
|
|
24
31
|
{ icon: "🔒", label: "Secure\nPayment" },
|
|
25
32
|
{ icon: "📅", label: "Guaranteed\nDelivery" },
|
|
26
33
|
{ icon: "↩", label: "Free\nCancellation" },
|