@pradip1995/segment-login-template 0.5.24 → 0.5.26
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/package.json +54 -54
- package/src/account-addresses.tsx +287 -287
- package/src/account-guest-orders.tsx +98 -98
- package/src/account-orders.tsx +260 -260
- package/src/account-overview.tsx +133 -133
- package/src/account-payment-methods.tsx +328 -328
- package/src/account-profile-logic.ts +282 -282
- package/src/account-profile.tsx +111 -111
- package/src/account-theme.ts +91 -91
- package/src/account-utils.ts +20 -20
- package/src/auth-server.ts +442 -442
- package/src/commerce-auth-otp-modal.css +125 -125
- package/src/commerce-auth-otp-modal.tsx +121 -121
- package/src/forgot-password-form.tsx +109 -109
- package/src/google-auth-section.tsx +22 -22
- package/src/google-sign-in-section.tsx +67 -142
- package/src/guest-order-modal.tsx +215 -215
- package/src/index.ts +7 -7
- package/src/is-next-redirect.ts +60 -60
- package/src/login-brand-panel.tsx +158 -158
- package/src/login-form.tsx +469 -469
- package/src/manifest.ts +11 -11
- package/src/order-history-status.test.ts +224 -224
- package/src/order-history-status.ts +244 -244
- package/src/otp-component.ts +14 -14
- package/src/otp-input.tsx +46 -46
- package/src/otp-unified-form.tsx +333 -333
- package/src/otp-verification-modal.tsx +112 -112
- package/src/payment-methods-actions.ts +243 -243
- package/src/profile-email-field.tsx +116 -116
- package/src/profile-email.test.ts +182 -182
- package/src/profile-email.ts +54 -54
- package/src/profile-phone-field.tsx +119 -119
- package/src/register-form.tsx +339 -339
- package/src/reorder-checkout-address.ts +101 -101
- package/src/reset-password-form.tsx +103 -103
- package/src/reset-password-page.tsx +12 -12
- package/src/segment.tsx +272 -272
|
@@ -1,244 +1,244 @@
|
|
|
1
|
-
export type OrderHistoryStatusTone =
|
|
2
|
-
| "cancel"
|
|
3
|
-
| "shipped"
|
|
4
|
-
| "done"
|
|
5
|
-
| "return"
|
|
6
|
-
| "processing"
|
|
7
|
-
|
|
8
|
-
export type OrderHistoryStatus = {
|
|
9
|
-
label: string
|
|
10
|
-
tone: OrderHistoryStatusTone
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type OrderHistoryReturnLike = {
|
|
14
|
-
status?: string | null
|
|
15
|
-
exchange_id?: string | null
|
|
16
|
-
claim_id?: string | null
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type OrderHistoryStatusInput = {
|
|
20
|
-
status?: string | null
|
|
21
|
-
fulfillment_status?: string | null
|
|
22
|
-
payment_status?: string | null
|
|
23
|
-
returns?: OrderHistoryReturnLike[] | null
|
|
24
|
-
exchanges?: Array<{
|
|
25
|
-
id?: string | null
|
|
26
|
-
canceled_at?: string | Date | null
|
|
27
|
-
}> | null
|
|
28
|
-
items?: Array<{
|
|
29
|
-
product_id?: string | null
|
|
30
|
-
created_at?: string | Date | null
|
|
31
|
-
detail?: {
|
|
32
|
-
return_requested_quantity?: number | null
|
|
33
|
-
return_received_quantity?: number | null
|
|
34
|
-
} | null
|
|
35
|
-
}> | null
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
type ReturnLifecycle =
|
|
39
|
-
| "requested"
|
|
40
|
-
| "approved"
|
|
41
|
-
| "in_progress"
|
|
42
|
-
| "returned"
|
|
43
|
-
| "refunded"
|
|
44
|
-
|
|
45
|
-
const CLOSED_RETURN = new Set(["canceled", "cancelled", "rejected"])
|
|
46
|
-
|
|
47
|
-
const RETURN_RANK: Record<ReturnLifecycle, number> = {
|
|
48
|
-
requested: 1,
|
|
49
|
-
approved: 2,
|
|
50
|
-
in_progress: 3,
|
|
51
|
-
returned: 4,
|
|
52
|
-
refunded: 5,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const RETURN_LABEL: Record<ReturnLifecycle, string> = {
|
|
56
|
-
requested: "Return Requested",
|
|
57
|
-
approved: "Return Approved",
|
|
58
|
-
in_progress: "Return In Progress",
|
|
59
|
-
returned: "Returned",
|
|
60
|
-
refunded: "Refunded",
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const EXCHANGE_LABEL: Record<ReturnLifecycle, string> = {
|
|
64
|
-
requested: "Exchange Requested",
|
|
65
|
-
approved: "Exchange Approved",
|
|
66
|
-
in_progress: "Exchange In Progress",
|
|
67
|
-
returned: "Exchanged",
|
|
68
|
-
refunded: "Refunded",
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function normalize(value?: string | null) {
|
|
72
|
-
return (value || "").toLowerCase().trim()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function isStandaloneReturn(ret: OrderHistoryReturnLike) {
|
|
76
|
-
return !ret.exchange_id && !ret.claim_id
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function isOpenExchangeReturn(ret: OrderHistoryReturnLike) {
|
|
80
|
-
return Boolean(ret.exchange_id) && !CLOSED_RETURN.has(normalize(ret.status))
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function itemCreatedAt(item: { created_at?: string | Date | null }): number {
|
|
84
|
-
if (!item.created_at) return 0
|
|
85
|
-
const t = new Date(item.created_at).getTime()
|
|
86
|
-
return Number.isFinite(t) ? t : 0
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function orderHasActiveExchange(order: OrderHistoryStatusInput): boolean {
|
|
90
|
-
if ((order.exchanges || []).some((row) => row?.id && !row.canceled_at)) {
|
|
91
|
-
return true
|
|
92
|
-
}
|
|
93
|
-
if ((order.returns || []).some(isOpenExchangeReturn)) return true
|
|
94
|
-
|
|
95
|
-
const items = order.items || []
|
|
96
|
-
const byProduct = new Map<string, number>()
|
|
97
|
-
for (const item of items) {
|
|
98
|
-
if (!item.product_id) continue
|
|
99
|
-
byProduct.set(item.product_id, (byProduct.get(item.product_id) || 0) + 1)
|
|
100
|
-
}
|
|
101
|
-
if ([...byProduct.values()].some((count) => count >= 2)) return true
|
|
102
|
-
|
|
103
|
-
for (const item of items) {
|
|
104
|
-
const createdAt = itemCreatedAt(item)
|
|
105
|
-
if (!createdAt) continue
|
|
106
|
-
const hasEarlierItem = items.some((other) => {
|
|
107
|
-
if (other === item) return false
|
|
108
|
-
const otherAt = itemCreatedAt(other)
|
|
109
|
-
return otherAt > 0 && createdAt > otherAt + 1000
|
|
110
|
-
})
|
|
111
|
-
if (hasEarlierItem) return true
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return false
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function lifecycleFromReturnStatus(status: string): ReturnLifecycle | null {
|
|
118
|
-
switch (status) {
|
|
119
|
-
case "requested":
|
|
120
|
-
return "requested"
|
|
121
|
-
case "open":
|
|
122
|
-
case "approved":
|
|
123
|
-
return "approved"
|
|
124
|
-
case "partially_received":
|
|
125
|
-
case "in_progress":
|
|
126
|
-
return "in_progress"
|
|
127
|
-
case "received":
|
|
128
|
-
case "returned":
|
|
129
|
-
case "complete":
|
|
130
|
-
case "completed":
|
|
131
|
-
return "returned"
|
|
132
|
-
default:
|
|
133
|
-
return null
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function pickHigher(
|
|
138
|
-
current: ReturnLifecycle | null,
|
|
139
|
-
next: ReturnLifecycle
|
|
140
|
-
): ReturnLifecycle {
|
|
141
|
-
if (!current) return next
|
|
142
|
-
return RETURN_RANK[next] > RETURN_RANK[current] ? next : current
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function requestLifecycle(
|
|
146
|
-
order: OrderHistoryStatusInput,
|
|
147
|
-
mode: "return" | "exchange"
|
|
148
|
-
): ReturnLifecycle | null {
|
|
149
|
-
const payment = normalize(order.payment_status)
|
|
150
|
-
let best: ReturnLifecycle | null = null
|
|
151
|
-
const exchange = orderHasActiveExchange(order)
|
|
152
|
-
|
|
153
|
-
if (mode === "return" && (payment === "refunded" || payment === "partially_refunded")) {
|
|
154
|
-
best = "refunded"
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
for (const ret of order.returns || []) {
|
|
158
|
-
const status = normalize(ret.status)
|
|
159
|
-
if (CLOSED_RETURN.has(status)) continue
|
|
160
|
-
if (mode === "exchange" && !isOpenExchangeReturn(ret)) continue
|
|
161
|
-
if (mode === "return" && !isStandaloneReturn(ret)) continue
|
|
162
|
-
const life = status
|
|
163
|
-
? lifecycleFromReturnStatus(status) ?? "requested"
|
|
164
|
-
: "requested"
|
|
165
|
-
best = pickHigher(best, life)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
let requestedQty = 0
|
|
169
|
-
let receivedQty = 0
|
|
170
|
-
for (const item of order.items || []) {
|
|
171
|
-
requestedQty += Number(item.detail?.return_requested_quantity) || 0
|
|
172
|
-
receivedQty += Number(item.detail?.return_received_quantity) || 0
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const qtyApplies =
|
|
176
|
-
(mode === "exchange" && exchange) || (mode === "return" && !exchange)
|
|
177
|
-
|
|
178
|
-
if (qtyApplies) {
|
|
179
|
-
if (receivedQty > 0 && requestedQty > receivedQty) {
|
|
180
|
-
best = pickHigher(best, "in_progress")
|
|
181
|
-
} else if (receivedQty > 0) {
|
|
182
|
-
best = pickHigher(best, "returned")
|
|
183
|
-
} else if (requestedQty > 0) {
|
|
184
|
-
best = pickHigher(best, "requested")
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (mode === "return") {
|
|
189
|
-
const fulfillment = normalize(order.fulfillment_status)
|
|
190
|
-
if (fulfillment === "returned") {
|
|
191
|
-
best = pickHigher(best, "returned")
|
|
192
|
-
} else if (fulfillment === "partially_returned") {
|
|
193
|
-
best = pickHigher(best, "in_progress")
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (mode === "exchange" && exchange) {
|
|
198
|
-
return best || "requested"
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return best
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export function resolveOrderHistoryStatus(
|
|
205
|
-
order: OrderHistoryStatusInput
|
|
206
|
-
): OrderHistoryStatus {
|
|
207
|
-
const orderStatus = normalize(order.status)
|
|
208
|
-
if (orderStatus === "canceled" || orderStatus === "cancelled") {
|
|
209
|
-
return { label: "Cancelled", tone: "cancel" }
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const exchangeLife = requestLifecycle(order, "exchange")
|
|
213
|
-
if (exchangeLife) {
|
|
214
|
-
return { label: EXCHANGE_LABEL[exchangeLife], tone: "return" }
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const returnLife = requestLifecycle(order, "return")
|
|
218
|
-
if (returnLife) {
|
|
219
|
-
return { label: RETURN_LABEL[returnLife], tone: "return" }
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const fulfillment = normalize(order.fulfillment_status)
|
|
223
|
-
const combined = fulfillment || orderStatus
|
|
224
|
-
|
|
225
|
-
if (combined.includes("cancel")) {
|
|
226
|
-
return { label: "Cancelled", tone: "cancel" }
|
|
227
|
-
}
|
|
228
|
-
if (combined.includes("ship")) {
|
|
229
|
-
return { label: "Shipped", tone: "shipped" }
|
|
230
|
-
}
|
|
231
|
-
if (
|
|
232
|
-
combined === "delivered" ||
|
|
233
|
-
combined === "complete" ||
|
|
234
|
-
combined === "completed" ||
|
|
235
|
-
combined.includes("fulfill")
|
|
236
|
-
) {
|
|
237
|
-
return {
|
|
238
|
-
label: combined === "delivered" ? "Delivered" : "Order Confirmed",
|
|
239
|
-
tone: "done",
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return { label: "Processing", tone: "processing" }
|
|
244
|
-
}
|
|
1
|
+
export type OrderHistoryStatusTone =
|
|
2
|
+
| "cancel"
|
|
3
|
+
| "shipped"
|
|
4
|
+
| "done"
|
|
5
|
+
| "return"
|
|
6
|
+
| "processing"
|
|
7
|
+
|
|
8
|
+
export type OrderHistoryStatus = {
|
|
9
|
+
label: string
|
|
10
|
+
tone: OrderHistoryStatusTone
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type OrderHistoryReturnLike = {
|
|
14
|
+
status?: string | null
|
|
15
|
+
exchange_id?: string | null
|
|
16
|
+
claim_id?: string | null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type OrderHistoryStatusInput = {
|
|
20
|
+
status?: string | null
|
|
21
|
+
fulfillment_status?: string | null
|
|
22
|
+
payment_status?: string | null
|
|
23
|
+
returns?: OrderHistoryReturnLike[] | null
|
|
24
|
+
exchanges?: Array<{
|
|
25
|
+
id?: string | null
|
|
26
|
+
canceled_at?: string | Date | null
|
|
27
|
+
}> | null
|
|
28
|
+
items?: Array<{
|
|
29
|
+
product_id?: string | null
|
|
30
|
+
created_at?: string | Date | null
|
|
31
|
+
detail?: {
|
|
32
|
+
return_requested_quantity?: number | null
|
|
33
|
+
return_received_quantity?: number | null
|
|
34
|
+
} | null
|
|
35
|
+
}> | null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type ReturnLifecycle =
|
|
39
|
+
| "requested"
|
|
40
|
+
| "approved"
|
|
41
|
+
| "in_progress"
|
|
42
|
+
| "returned"
|
|
43
|
+
| "refunded"
|
|
44
|
+
|
|
45
|
+
const CLOSED_RETURN = new Set(["canceled", "cancelled", "rejected"])
|
|
46
|
+
|
|
47
|
+
const RETURN_RANK: Record<ReturnLifecycle, number> = {
|
|
48
|
+
requested: 1,
|
|
49
|
+
approved: 2,
|
|
50
|
+
in_progress: 3,
|
|
51
|
+
returned: 4,
|
|
52
|
+
refunded: 5,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const RETURN_LABEL: Record<ReturnLifecycle, string> = {
|
|
56
|
+
requested: "Return Requested",
|
|
57
|
+
approved: "Return Approved",
|
|
58
|
+
in_progress: "Return In Progress",
|
|
59
|
+
returned: "Returned",
|
|
60
|
+
refunded: "Refunded",
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const EXCHANGE_LABEL: Record<ReturnLifecycle, string> = {
|
|
64
|
+
requested: "Exchange Requested",
|
|
65
|
+
approved: "Exchange Approved",
|
|
66
|
+
in_progress: "Exchange In Progress",
|
|
67
|
+
returned: "Exchanged",
|
|
68
|
+
refunded: "Refunded",
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function normalize(value?: string | null) {
|
|
72
|
+
return (value || "").toLowerCase().trim()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isStandaloneReturn(ret: OrderHistoryReturnLike) {
|
|
76
|
+
return !ret.exchange_id && !ret.claim_id
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function isOpenExchangeReturn(ret: OrderHistoryReturnLike) {
|
|
80
|
+
return Boolean(ret.exchange_id) && !CLOSED_RETURN.has(normalize(ret.status))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function itemCreatedAt(item: { created_at?: string | Date | null }): number {
|
|
84
|
+
if (!item.created_at) return 0
|
|
85
|
+
const t = new Date(item.created_at).getTime()
|
|
86
|
+
return Number.isFinite(t) ? t : 0
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function orderHasActiveExchange(order: OrderHistoryStatusInput): boolean {
|
|
90
|
+
if ((order.exchanges || []).some((row) => row?.id && !row.canceled_at)) {
|
|
91
|
+
return true
|
|
92
|
+
}
|
|
93
|
+
if ((order.returns || []).some(isOpenExchangeReturn)) return true
|
|
94
|
+
|
|
95
|
+
const items = order.items || []
|
|
96
|
+
const byProduct = new Map<string, number>()
|
|
97
|
+
for (const item of items) {
|
|
98
|
+
if (!item.product_id) continue
|
|
99
|
+
byProduct.set(item.product_id, (byProduct.get(item.product_id) || 0) + 1)
|
|
100
|
+
}
|
|
101
|
+
if ([...byProduct.values()].some((count) => count >= 2)) return true
|
|
102
|
+
|
|
103
|
+
for (const item of items) {
|
|
104
|
+
const createdAt = itemCreatedAt(item)
|
|
105
|
+
if (!createdAt) continue
|
|
106
|
+
const hasEarlierItem = items.some((other) => {
|
|
107
|
+
if (other === item) return false
|
|
108
|
+
const otherAt = itemCreatedAt(other)
|
|
109
|
+
return otherAt > 0 && createdAt > otherAt + 1000
|
|
110
|
+
})
|
|
111
|
+
if (hasEarlierItem) return true
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return false
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function lifecycleFromReturnStatus(status: string): ReturnLifecycle | null {
|
|
118
|
+
switch (status) {
|
|
119
|
+
case "requested":
|
|
120
|
+
return "requested"
|
|
121
|
+
case "open":
|
|
122
|
+
case "approved":
|
|
123
|
+
return "approved"
|
|
124
|
+
case "partially_received":
|
|
125
|
+
case "in_progress":
|
|
126
|
+
return "in_progress"
|
|
127
|
+
case "received":
|
|
128
|
+
case "returned":
|
|
129
|
+
case "complete":
|
|
130
|
+
case "completed":
|
|
131
|
+
return "returned"
|
|
132
|
+
default:
|
|
133
|
+
return null
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function pickHigher(
|
|
138
|
+
current: ReturnLifecycle | null,
|
|
139
|
+
next: ReturnLifecycle
|
|
140
|
+
): ReturnLifecycle {
|
|
141
|
+
if (!current) return next
|
|
142
|
+
return RETURN_RANK[next] > RETURN_RANK[current] ? next : current
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function requestLifecycle(
|
|
146
|
+
order: OrderHistoryStatusInput,
|
|
147
|
+
mode: "return" | "exchange"
|
|
148
|
+
): ReturnLifecycle | null {
|
|
149
|
+
const payment = normalize(order.payment_status)
|
|
150
|
+
let best: ReturnLifecycle | null = null
|
|
151
|
+
const exchange = orderHasActiveExchange(order)
|
|
152
|
+
|
|
153
|
+
if (mode === "return" && (payment === "refunded" || payment === "partially_refunded")) {
|
|
154
|
+
best = "refunded"
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
for (const ret of order.returns || []) {
|
|
158
|
+
const status = normalize(ret.status)
|
|
159
|
+
if (CLOSED_RETURN.has(status)) continue
|
|
160
|
+
if (mode === "exchange" && !isOpenExchangeReturn(ret)) continue
|
|
161
|
+
if (mode === "return" && !isStandaloneReturn(ret)) continue
|
|
162
|
+
const life = status
|
|
163
|
+
? lifecycleFromReturnStatus(status) ?? "requested"
|
|
164
|
+
: "requested"
|
|
165
|
+
best = pickHigher(best, life)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let requestedQty = 0
|
|
169
|
+
let receivedQty = 0
|
|
170
|
+
for (const item of order.items || []) {
|
|
171
|
+
requestedQty += Number(item.detail?.return_requested_quantity) || 0
|
|
172
|
+
receivedQty += Number(item.detail?.return_received_quantity) || 0
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const qtyApplies =
|
|
176
|
+
(mode === "exchange" && exchange) || (mode === "return" && !exchange)
|
|
177
|
+
|
|
178
|
+
if (qtyApplies) {
|
|
179
|
+
if (receivedQty > 0 && requestedQty > receivedQty) {
|
|
180
|
+
best = pickHigher(best, "in_progress")
|
|
181
|
+
} else if (receivedQty > 0) {
|
|
182
|
+
best = pickHigher(best, "returned")
|
|
183
|
+
} else if (requestedQty > 0) {
|
|
184
|
+
best = pickHigher(best, "requested")
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (mode === "return") {
|
|
189
|
+
const fulfillment = normalize(order.fulfillment_status)
|
|
190
|
+
if (fulfillment === "returned") {
|
|
191
|
+
best = pickHigher(best, "returned")
|
|
192
|
+
} else if (fulfillment === "partially_returned") {
|
|
193
|
+
best = pickHigher(best, "in_progress")
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (mode === "exchange" && exchange) {
|
|
198
|
+
return best || "requested"
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return best
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function resolveOrderHistoryStatus(
|
|
205
|
+
order: OrderHistoryStatusInput
|
|
206
|
+
): OrderHistoryStatus {
|
|
207
|
+
const orderStatus = normalize(order.status)
|
|
208
|
+
if (orderStatus === "canceled" || orderStatus === "cancelled") {
|
|
209
|
+
return { label: "Cancelled", tone: "cancel" }
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const exchangeLife = requestLifecycle(order, "exchange")
|
|
213
|
+
if (exchangeLife) {
|
|
214
|
+
return { label: EXCHANGE_LABEL[exchangeLife], tone: "return" }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const returnLife = requestLifecycle(order, "return")
|
|
218
|
+
if (returnLife) {
|
|
219
|
+
return { label: RETURN_LABEL[returnLife], tone: "return" }
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const fulfillment = normalize(order.fulfillment_status)
|
|
223
|
+
const combined = fulfillment || orderStatus
|
|
224
|
+
|
|
225
|
+
if (combined.includes("cancel")) {
|
|
226
|
+
return { label: "Cancelled", tone: "cancel" }
|
|
227
|
+
}
|
|
228
|
+
if (combined.includes("ship")) {
|
|
229
|
+
return { label: "Shipped", tone: "shipped" }
|
|
230
|
+
}
|
|
231
|
+
if (
|
|
232
|
+
combined === "delivered" ||
|
|
233
|
+
combined === "complete" ||
|
|
234
|
+
combined === "completed" ||
|
|
235
|
+
combined.includes("fulfill")
|
|
236
|
+
) {
|
|
237
|
+
return {
|
|
238
|
+
label: combined === "delivered" ? "Delivered" : "Order Confirmed",
|
|
239
|
+
tone: "done",
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return { label: "Processing", tone: "processing" }
|
|
244
|
+
}
|
package/src/otp-component.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { ComponentType } from "react"
|
|
2
|
-
import type { OtpVerificationModalProps } from "./otp-verification-modal"
|
|
3
|
-
import DefaultOtpVerificationModal from "./otp-verification-modal"
|
|
4
|
-
|
|
5
|
-
export type OtpVerificationComponent = ComponentType<OtpVerificationModalProps>
|
|
6
|
-
|
|
7
|
-
export function resolveOtpComponent(
|
|
8
|
-
component?: OtpVerificationComponent | string
|
|
9
|
-
): OtpVerificationComponent {
|
|
10
|
-
if (!component || typeof component === "string") {
|
|
11
|
-
return DefaultOtpVerificationModal
|
|
12
|
-
}
|
|
13
|
-
return component
|
|
14
|
-
}
|
|
1
|
+
import type { ComponentType } from "react"
|
|
2
|
+
import type { OtpVerificationModalProps } from "./otp-verification-modal"
|
|
3
|
+
import DefaultOtpVerificationModal from "./otp-verification-modal"
|
|
4
|
+
|
|
5
|
+
export type OtpVerificationComponent = ComponentType<OtpVerificationModalProps>
|
|
6
|
+
|
|
7
|
+
export function resolveOtpComponent(
|
|
8
|
+
component?: OtpVerificationComponent | string
|
|
9
|
+
): OtpVerificationComponent {
|
|
10
|
+
if (!component || typeof component === "string") {
|
|
11
|
+
return DefaultOtpVerificationModal
|
|
12
|
+
}
|
|
13
|
+
return component
|
|
14
|
+
}
|
package/src/otp-input.tsx
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
type OtpInputProps = {
|
|
4
|
-
value: string
|
|
5
|
-
onChange: (value: string) => void
|
|
6
|
-
length?: number
|
|
7
|
-
autoFocus?: boolean
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default function OtpInput({
|
|
11
|
-
value,
|
|
12
|
-
onChange,
|
|
13
|
-
length = 6,
|
|
14
|
-
autoFocus = false,
|
|
15
|
-
}: OtpInputProps) {
|
|
16
|
-
return (
|
|
17
|
-
<div className="relative flex justify-center gap-x-2.5">
|
|
18
|
-
{Array.from({ length }, (_, index) => (
|
|
19
|
-
<div
|
|
20
|
-
key={index}
|
|
21
|
-
className={`w-10 h-12 flex items-center justify-center border-2 rounded-lg text-xl font-bold transition-all duration-200 ${
|
|
22
|
-
value.length === index
|
|
23
|
-
? "border-brand-accent ring-2 ring-brand-accent/10 bg-page-bg"
|
|
24
|
-
: value.length > index
|
|
25
|
-
? "border-cart-border bg-page-bg shadow-sm"
|
|
26
|
-
: "border-cart-border bg-surface-muted/50"
|
|
27
|
-
}`}
|
|
28
|
-
>
|
|
29
|
-
{value[index] || ""}
|
|
30
|
-
</div>
|
|
31
|
-
))}
|
|
32
|
-
<input
|
|
33
|
-
type="text"
|
|
34
|
-
inputMode="numeric"
|
|
35
|
-
maxLength={length}
|
|
36
|
-
className="absolute inset-0 opacity-0 cursor-pointer"
|
|
37
|
-
value={value}
|
|
38
|
-
onChange={(event) =>
|
|
39
|
-
onChange(event.target.value.replace(/\D/g, "").slice(0, length))
|
|
40
|
-
}
|
|
41
|
-
autoFocus={autoFocus}
|
|
42
|
-
aria-label="One-time password"
|
|
43
|
-
/>
|
|
44
|
-
</div>
|
|
45
|
-
)
|
|
46
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
type OtpInputProps = {
|
|
4
|
+
value: string
|
|
5
|
+
onChange: (value: string) => void
|
|
6
|
+
length?: number
|
|
7
|
+
autoFocus?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function OtpInput({
|
|
11
|
+
value,
|
|
12
|
+
onChange,
|
|
13
|
+
length = 6,
|
|
14
|
+
autoFocus = false,
|
|
15
|
+
}: OtpInputProps) {
|
|
16
|
+
return (
|
|
17
|
+
<div className="relative flex justify-center gap-x-2.5">
|
|
18
|
+
{Array.from({ length }, (_, index) => (
|
|
19
|
+
<div
|
|
20
|
+
key={index}
|
|
21
|
+
className={`w-10 h-12 flex items-center justify-center border-2 rounded-lg text-xl font-bold transition-all duration-200 ${
|
|
22
|
+
value.length === index
|
|
23
|
+
? "border-brand-accent ring-2 ring-brand-accent/10 bg-page-bg"
|
|
24
|
+
: value.length > index
|
|
25
|
+
? "border-cart-border bg-page-bg shadow-sm"
|
|
26
|
+
: "border-cart-border bg-surface-muted/50"
|
|
27
|
+
}`}
|
|
28
|
+
>
|
|
29
|
+
{value[index] || ""}
|
|
30
|
+
</div>
|
|
31
|
+
))}
|
|
32
|
+
<input
|
|
33
|
+
type="text"
|
|
34
|
+
inputMode="numeric"
|
|
35
|
+
maxLength={length}
|
|
36
|
+
className="absolute inset-0 opacity-0 cursor-pointer"
|
|
37
|
+
value={value}
|
|
38
|
+
onChange={(event) =>
|
|
39
|
+
onChange(event.target.value.replace(/\D/g, "").slice(0, length))
|
|
40
|
+
}
|
|
41
|
+
autoFocus={autoFocus}
|
|
42
|
+
aria-label="One-time password"
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
45
|
+
)
|
|
46
|
+
}
|