@pradip1995/segment-login-template 0.5.26 → 0.5.28
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 +58 -54
- package/src/account-addresses.tsx +307 -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/address-actions.ts +74 -0
- package/src/auth-server.ts +442 -442
- package/src/card-expiry.test.ts +71 -0
- package/src/card-expiry.ts +29 -0
- package/src/commerce-auth-otp-modal.css +125 -125
- package/src/commerce-auth-otp-modal.tsx +121 -121
- package/src/default-address.test.ts +143 -0
- package/src/default-address.ts +51 -0
- package/src/forgot-password-form.tsx +109 -109
- package/src/google-auth-section.tsx +22 -22
- package/src/google-sign-in-section.tsx +67 -67
- 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 +159 -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 +103 -101
- package/src/reset-password-form.tsx +103 -103
- package/src/reset-password-page.tsx +12 -12
- package/src/segment.tsx +272 -272
|
@@ -1,328 +1,328 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { useState } from "react"
|
|
4
|
-
import {
|
|
5
|
-
addPaymentMethodAction,
|
|
6
|
-
deletePaymentMethodAction,
|
|
7
|
-
makeDefaultPaymentMethodAction,
|
|
8
|
-
} from "./payment-methods-actions"
|
|
9
|
-
import { acct } from "./account-theme"
|
|
10
|
-
|
|
11
|
-
type PaymentDetail = {
|
|
12
|
-
id: string
|
|
13
|
-
type: "upi" | "bank" | "card"
|
|
14
|
-
detail_json?: Record<string, string>
|
|
15
|
-
is_default?: boolean
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const emptyForm = {
|
|
19
|
-
upi_id: "",
|
|
20
|
-
account_holder_name: "",
|
|
21
|
-
bank_name: "",
|
|
22
|
-
account_number: "",
|
|
23
|
-
ifsc: "",
|
|
24
|
-
branch_name: "",
|
|
25
|
-
card_holder_name: "",
|
|
26
|
-
card_number: "",
|
|
27
|
-
expiry_date: "",
|
|
28
|
-
cvv: "",
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export default function AccountPaymentMethods({
|
|
32
|
-
paymentDetails,
|
|
33
|
-
}: {
|
|
34
|
-
paymentDetails: PaymentDetail[]
|
|
35
|
-
}) {
|
|
36
|
-
const [showForm, setShowForm] = useState(false)
|
|
37
|
-
const [type, setType] = useState<"upi" | "bank" | "card">("upi")
|
|
38
|
-
const [pending, setPending] = useState(false)
|
|
39
|
-
const [error, setError] = useState<string | null>(null)
|
|
40
|
-
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({})
|
|
41
|
-
const [form, setForm] = useState(emptyForm)
|
|
42
|
-
|
|
43
|
-
async function handleAdd(e: React.FormEvent) {
|
|
44
|
-
e.preventDefault()
|
|
45
|
-
setPending(true)
|
|
46
|
-
setError(null)
|
|
47
|
-
setFieldErrors({})
|
|
48
|
-
|
|
49
|
-
let detail_json: Record<string, string> = {}
|
|
50
|
-
if (type === "upi") {
|
|
51
|
-
detail_json = { upi_id: form.upi_id.trim() }
|
|
52
|
-
} else if (type === "bank") {
|
|
53
|
-
detail_json = {
|
|
54
|
-
account_holder_name: form.account_holder_name.trim(),
|
|
55
|
-
bank_name: form.bank_name.trim(),
|
|
56
|
-
account_number: form.account_number.trim(),
|
|
57
|
-
ifsc: form.ifsc.trim(),
|
|
58
|
-
}
|
|
59
|
-
if (form.branch_name.trim()) {
|
|
60
|
-
detail_json.branch_name = form.branch_name.trim()
|
|
61
|
-
}
|
|
62
|
-
} else {
|
|
63
|
-
detail_json = {
|
|
64
|
-
card_holder_name: form.card_holder_name.trim(),
|
|
65
|
-
card_number: form.card_number.trim(),
|
|
66
|
-
expiry_date: form.expiry_date.trim(),
|
|
67
|
-
cvv: form.cvv.trim(),
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const result = await addPaymentMethodAction(type, detail_json)
|
|
72
|
-
if (!result.success) {
|
|
73
|
-
setError(result.error)
|
|
74
|
-
setFieldErrors(result.field_errors || {})
|
|
75
|
-
setPending(false)
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
window.location.reload()
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async function handleDefault(id: string) {
|
|
82
|
-
setPending(true)
|
|
83
|
-
setError(null)
|
|
84
|
-
setFieldErrors({})
|
|
85
|
-
const result = await makeDefaultPaymentMethodAction(id)
|
|
86
|
-
if (!result.success) {
|
|
87
|
-
setError(result.error)
|
|
88
|
-
setPending(false)
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
window.location.reload()
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async function handleDelete(id: string) {
|
|
95
|
-
const target = paymentDetails.find((d) => d.id === id)
|
|
96
|
-
if (target?.is_default && paymentDetails.length === 1) {
|
|
97
|
-
setError(
|
|
98
|
-
"The default payment method cannot be removed. Please add another payment method and set it as default before removing this one."
|
|
99
|
-
)
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
if (!confirm("Remove this payment method?")) return
|
|
103
|
-
setPending(true)
|
|
104
|
-
setError(null)
|
|
105
|
-
setFieldErrors({})
|
|
106
|
-
const result = await deletePaymentMethodAction(id)
|
|
107
|
-
if (!result.success) {
|
|
108
|
-
setError(result.error)
|
|
109
|
-
setPending(false)
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
window.location.reload()
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function labelFor(detail: PaymentDetail) {
|
|
116
|
-
const json = detail.detail_json ?? {}
|
|
117
|
-
if (detail.type === "upi") return `UPI · ${json.upi_id || "—"}`
|
|
118
|
-
if (detail.type === "bank") {
|
|
119
|
-
const holder = json.account_holder_name || json.account_holder || "—"
|
|
120
|
-
const last4 = json.account_number?.slice(-4) || "****"
|
|
121
|
-
const bank = json.bank_name ? ` · ${json.bank_name}` : ""
|
|
122
|
-
return `Bank · ${holder}${bank} (····${last4})`
|
|
123
|
-
}
|
|
124
|
-
const holder = json.card_holder_name || "—"
|
|
125
|
-
const last4 =
|
|
126
|
-
json.card_number?.replace(/\s+/g, "").slice(-4) ||
|
|
127
|
-
json.card_last4 ||
|
|
128
|
-
"****"
|
|
129
|
-
return `Card · ${holder} (····${last4})`
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return (
|
|
133
|
-
<div className="space-y-6">
|
|
134
|
-
<div className="flex flex-wrap items-end justify-between gap-4">
|
|
135
|
-
<div>
|
|
136
|
-
<h2 className={acct.title}>Payment methods</h2>
|
|
137
|
-
<p className={`text-sm ${acct.muted}`}>Refund destinations for returns and exchanges.</p>
|
|
138
|
-
</div>
|
|
139
|
-
<button type="button" onClick={() => setShowForm((v) => !v)} className={acct.btnPrimary}>
|
|
140
|
-
{showForm ? "Cancel" : "Add method"}
|
|
141
|
-
</button>
|
|
142
|
-
</div>
|
|
143
|
-
|
|
144
|
-
{showForm && (
|
|
145
|
-
<form onSubmit={handleAdd} className={`${acct.card} p-6 space-y-4`}>
|
|
146
|
-
<div className="flex flex-wrap gap-2">
|
|
147
|
-
{(["upi", "bank", "card"] as const).map((t) => (
|
|
148
|
-
<button
|
|
149
|
-
key={t}
|
|
150
|
-
type="button"
|
|
151
|
-
onClick={() => {
|
|
152
|
-
setType(t)
|
|
153
|
-
setError(null)
|
|
154
|
-
setFieldErrors({})
|
|
155
|
-
}}
|
|
156
|
-
className={`px-3 py-1.5 text-xs font-medium rounded-none border ${
|
|
157
|
-
type === t
|
|
158
|
-
? "border-brand-accent text-brand-accent bg-brand-accent-muted"
|
|
159
|
-
: "border-cart-border text-muted"
|
|
160
|
-
}`}
|
|
161
|
-
>
|
|
162
|
-
{t.toUpperCase()}
|
|
163
|
-
</button>
|
|
164
|
-
))}
|
|
165
|
-
</div>
|
|
166
|
-
|
|
167
|
-
{type === "upi" && (
|
|
168
|
-
<Field
|
|
169
|
-
label="UPI ID"
|
|
170
|
-
value={form.upi_id}
|
|
171
|
-
error={fieldErrors.upi_id}
|
|
172
|
-
onChange={(v) => setForm((f) => ({ ...f, upi_id: v }))}
|
|
173
|
-
/>
|
|
174
|
-
)}
|
|
175
|
-
|
|
176
|
-
{type === "bank" && (
|
|
177
|
-
<>
|
|
178
|
-
<Field
|
|
179
|
-
label="Account holder name"
|
|
180
|
-
value={form.account_holder_name}
|
|
181
|
-
error={fieldErrors.account_holder_name}
|
|
182
|
-
onChange={(v) => setForm((f) => ({ ...f, account_holder_name: v }))}
|
|
183
|
-
/>
|
|
184
|
-
<Field
|
|
185
|
-
label="Bank name"
|
|
186
|
-
value={form.bank_name}
|
|
187
|
-
error={fieldErrors.bank_name}
|
|
188
|
-
onChange={(v) => setForm((f) => ({ ...f, bank_name: v }))}
|
|
189
|
-
/>
|
|
190
|
-
<Field
|
|
191
|
-
label="Account number"
|
|
192
|
-
value={form.account_number}
|
|
193
|
-
error={fieldErrors.account_number}
|
|
194
|
-
onChange={(v) => setForm((f) => ({ ...f, account_number: v }))}
|
|
195
|
-
/>
|
|
196
|
-
<Field
|
|
197
|
-
label="IFSC"
|
|
198
|
-
value={form.ifsc}
|
|
199
|
-
error={fieldErrors.ifsc}
|
|
200
|
-
onChange={(v) => setForm((f) => ({ ...f, ifsc: v }))}
|
|
201
|
-
/>
|
|
202
|
-
<Field
|
|
203
|
-
label="Branch name (optional)"
|
|
204
|
-
value={form.branch_name}
|
|
205
|
-
required={false}
|
|
206
|
-
error={fieldErrors.branch_name}
|
|
207
|
-
onChange={(v) => setForm((f) => ({ ...f, branch_name: v }))}
|
|
208
|
-
/>
|
|
209
|
-
</>
|
|
210
|
-
)}
|
|
211
|
-
|
|
212
|
-
{type === "card" && (
|
|
213
|
-
<>
|
|
214
|
-
<Field
|
|
215
|
-
label="Card holder name"
|
|
216
|
-
value={form.card_holder_name}
|
|
217
|
-
error={fieldErrors.card_holder_name}
|
|
218
|
-
onChange={(v) => setForm((f) => ({ ...f, card_holder_name: v }))}
|
|
219
|
-
/>
|
|
220
|
-
<Field
|
|
221
|
-
label="Card number"
|
|
222
|
-
value={form.card_number}
|
|
223
|
-
error={fieldErrors.card_number}
|
|
224
|
-
onChange={(v) => setForm((f) => ({ ...f, card_number: v }))}
|
|
225
|
-
/>
|
|
226
|
-
<Field
|
|
227
|
-
label="Expiry (MM/YY)"
|
|
228
|
-
value={form.expiry_date}
|
|
229
|
-
error={fieldErrors.expiry_date}
|
|
230
|
-
placeholder="08/28"
|
|
231
|
-
onChange={(v) => setForm((f) => ({ ...f, expiry_date: v }))}
|
|
232
|
-
/>
|
|
233
|
-
<Field
|
|
234
|
-
label="CVV"
|
|
235
|
-
value={form.cvv}
|
|
236
|
-
error={fieldErrors.cvv}
|
|
237
|
-
onChange={(v) => setForm((f) => ({ ...f, cvv: v }))}
|
|
238
|
-
/>
|
|
239
|
-
</>
|
|
240
|
-
)}
|
|
241
|
-
|
|
242
|
-
<button type="submit" disabled={pending} className={acct.btnPrimary}>
|
|
243
|
-
{pending ? "Saving…" : "Save payment method"}
|
|
244
|
-
</button>
|
|
245
|
-
</form>
|
|
246
|
-
)}
|
|
247
|
-
|
|
248
|
-
{error && <p className="text-sm text-red-600">{error}</p>}
|
|
249
|
-
|
|
250
|
-
{paymentDetails.length === 0 ? (
|
|
251
|
-
<div className={`${acct.cardMuted} p-8 text-center text-sm ${acct.muted}`}>
|
|
252
|
-
No refund payment methods saved.
|
|
253
|
-
</div>
|
|
254
|
-
) : (
|
|
255
|
-
<ul className="space-y-3">
|
|
256
|
-
{paymentDetails.map((detail) => (
|
|
257
|
-
<li
|
|
258
|
-
key={detail.id}
|
|
259
|
-
className={`${acct.card} p-5 flex flex-wrap justify-between gap-4 items-center`}
|
|
260
|
-
>
|
|
261
|
-
<div>
|
|
262
|
-
<p className="font-medium text-heading text-sm">{labelFor(detail)}</p>
|
|
263
|
-
{detail.is_default && (
|
|
264
|
-
<p className="text-xs text-brand-accent font-medium mt-1">Default</p>
|
|
265
|
-
)}
|
|
266
|
-
</div>
|
|
267
|
-
<div className="flex gap-3 text-xs">
|
|
268
|
-
{!detail.is_default && (
|
|
269
|
-
<button
|
|
270
|
-
type="button"
|
|
271
|
-
onClick={() => handleDefault(detail.id)}
|
|
272
|
-
disabled={pending}
|
|
273
|
-
className="text-brand-accent hover:underline disabled:opacity-60"
|
|
274
|
-
>
|
|
275
|
-
Make default
|
|
276
|
-
</button>
|
|
277
|
-
)}
|
|
278
|
-
<button
|
|
279
|
-
type="button"
|
|
280
|
-
onClick={() => handleDelete(detail.id)}
|
|
281
|
-
disabled={pending}
|
|
282
|
-
className="text-red-600 hover:underline disabled:opacity-60"
|
|
283
|
-
>
|
|
284
|
-
Remove
|
|
285
|
-
</button>
|
|
286
|
-
</div>
|
|
287
|
-
</li>
|
|
288
|
-
))}
|
|
289
|
-
</ul>
|
|
290
|
-
)}
|
|
291
|
-
</div>
|
|
292
|
-
)
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function Field({
|
|
296
|
-
label,
|
|
297
|
-
value,
|
|
298
|
-
onChange,
|
|
299
|
-
error,
|
|
300
|
-
required = true,
|
|
301
|
-
placeholder,
|
|
302
|
-
}: {
|
|
303
|
-
label: string
|
|
304
|
-
value: string
|
|
305
|
-
onChange: (value: string) => void
|
|
306
|
-
error?: string
|
|
307
|
-
required?: boolean
|
|
308
|
-
placeholder?: string
|
|
309
|
-
}) {
|
|
310
|
-
return (
|
|
311
|
-
<label className="block">
|
|
312
|
-
<span className="text-xs font-semibold uppercase tracking-wider text-muted mb-1.5 block">
|
|
313
|
-
{label}
|
|
314
|
-
</span>
|
|
315
|
-
<input
|
|
316
|
-
value={value}
|
|
317
|
-
onChange={(e) => onChange(e.target.value)}
|
|
318
|
-
required={required}
|
|
319
|
-
placeholder={placeholder}
|
|
320
|
-
aria-invalid={Boolean(error)}
|
|
321
|
-
className={`w-full border rounded-none px-3 py-2.5 text-sm bg-surface text-heading focus:outline-none focus:border-brand-accent ${
|
|
322
|
-
error ? "border-red-500" : "border-cart-border"
|
|
323
|
-
}`}
|
|
324
|
-
/>
|
|
325
|
-
{error && <span className="mt-1 block text-xs text-red-600">{error}</span>}
|
|
326
|
-
</label>
|
|
327
|
-
)
|
|
328
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useState } from "react"
|
|
4
|
+
import {
|
|
5
|
+
addPaymentMethodAction,
|
|
6
|
+
deletePaymentMethodAction,
|
|
7
|
+
makeDefaultPaymentMethodAction,
|
|
8
|
+
} from "./payment-methods-actions"
|
|
9
|
+
import { acct } from "./account-theme"
|
|
10
|
+
|
|
11
|
+
type PaymentDetail = {
|
|
12
|
+
id: string
|
|
13
|
+
type: "upi" | "bank" | "card"
|
|
14
|
+
detail_json?: Record<string, string>
|
|
15
|
+
is_default?: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const emptyForm = {
|
|
19
|
+
upi_id: "",
|
|
20
|
+
account_holder_name: "",
|
|
21
|
+
bank_name: "",
|
|
22
|
+
account_number: "",
|
|
23
|
+
ifsc: "",
|
|
24
|
+
branch_name: "",
|
|
25
|
+
card_holder_name: "",
|
|
26
|
+
card_number: "",
|
|
27
|
+
expiry_date: "",
|
|
28
|
+
cvv: "",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default function AccountPaymentMethods({
|
|
32
|
+
paymentDetails,
|
|
33
|
+
}: {
|
|
34
|
+
paymentDetails: PaymentDetail[]
|
|
35
|
+
}) {
|
|
36
|
+
const [showForm, setShowForm] = useState(false)
|
|
37
|
+
const [type, setType] = useState<"upi" | "bank" | "card">("upi")
|
|
38
|
+
const [pending, setPending] = useState(false)
|
|
39
|
+
const [error, setError] = useState<string | null>(null)
|
|
40
|
+
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({})
|
|
41
|
+
const [form, setForm] = useState(emptyForm)
|
|
42
|
+
|
|
43
|
+
async function handleAdd(e: React.FormEvent) {
|
|
44
|
+
e.preventDefault()
|
|
45
|
+
setPending(true)
|
|
46
|
+
setError(null)
|
|
47
|
+
setFieldErrors({})
|
|
48
|
+
|
|
49
|
+
let detail_json: Record<string, string> = {}
|
|
50
|
+
if (type === "upi") {
|
|
51
|
+
detail_json = { upi_id: form.upi_id.trim() }
|
|
52
|
+
} else if (type === "bank") {
|
|
53
|
+
detail_json = {
|
|
54
|
+
account_holder_name: form.account_holder_name.trim(),
|
|
55
|
+
bank_name: form.bank_name.trim(),
|
|
56
|
+
account_number: form.account_number.trim(),
|
|
57
|
+
ifsc: form.ifsc.trim(),
|
|
58
|
+
}
|
|
59
|
+
if (form.branch_name.trim()) {
|
|
60
|
+
detail_json.branch_name = form.branch_name.trim()
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
detail_json = {
|
|
64
|
+
card_holder_name: form.card_holder_name.trim(),
|
|
65
|
+
card_number: form.card_number.trim(),
|
|
66
|
+
expiry_date: form.expiry_date.trim(),
|
|
67
|
+
cvv: form.cvv.trim(),
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const result = await addPaymentMethodAction(type, detail_json)
|
|
72
|
+
if (!result.success) {
|
|
73
|
+
setError(result.error)
|
|
74
|
+
setFieldErrors(result.field_errors || {})
|
|
75
|
+
setPending(false)
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
window.location.reload()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function handleDefault(id: string) {
|
|
82
|
+
setPending(true)
|
|
83
|
+
setError(null)
|
|
84
|
+
setFieldErrors({})
|
|
85
|
+
const result = await makeDefaultPaymentMethodAction(id)
|
|
86
|
+
if (!result.success) {
|
|
87
|
+
setError(result.error)
|
|
88
|
+
setPending(false)
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
window.location.reload()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function handleDelete(id: string) {
|
|
95
|
+
const target = paymentDetails.find((d) => d.id === id)
|
|
96
|
+
if (target?.is_default && paymentDetails.length === 1) {
|
|
97
|
+
setError(
|
|
98
|
+
"The default payment method cannot be removed. Please add another payment method and set it as default before removing this one."
|
|
99
|
+
)
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
if (!confirm("Remove this payment method?")) return
|
|
103
|
+
setPending(true)
|
|
104
|
+
setError(null)
|
|
105
|
+
setFieldErrors({})
|
|
106
|
+
const result = await deletePaymentMethodAction(id)
|
|
107
|
+
if (!result.success) {
|
|
108
|
+
setError(result.error)
|
|
109
|
+
setPending(false)
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
window.location.reload()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function labelFor(detail: PaymentDetail) {
|
|
116
|
+
const json = detail.detail_json ?? {}
|
|
117
|
+
if (detail.type === "upi") return `UPI · ${json.upi_id || "—"}`
|
|
118
|
+
if (detail.type === "bank") {
|
|
119
|
+
const holder = json.account_holder_name || json.account_holder || "—"
|
|
120
|
+
const last4 = json.account_number?.slice(-4) || "****"
|
|
121
|
+
const bank = json.bank_name ? ` · ${json.bank_name}` : ""
|
|
122
|
+
return `Bank · ${holder}${bank} (····${last4})`
|
|
123
|
+
}
|
|
124
|
+
const holder = json.card_holder_name || "—"
|
|
125
|
+
const last4 =
|
|
126
|
+
json.card_number?.replace(/\s+/g, "").slice(-4) ||
|
|
127
|
+
json.card_last4 ||
|
|
128
|
+
"****"
|
|
129
|
+
return `Card · ${holder} (····${last4})`
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<div className="space-y-6">
|
|
134
|
+
<div className="flex flex-wrap items-end justify-between gap-4">
|
|
135
|
+
<div>
|
|
136
|
+
<h2 className={acct.title}>Payment methods</h2>
|
|
137
|
+
<p className={`text-sm ${acct.muted}`}>Refund destinations for returns and exchanges.</p>
|
|
138
|
+
</div>
|
|
139
|
+
<button type="button" onClick={() => setShowForm((v) => !v)} className={acct.btnPrimary}>
|
|
140
|
+
{showForm ? "Cancel" : "Add method"}
|
|
141
|
+
</button>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
{showForm && (
|
|
145
|
+
<form onSubmit={handleAdd} className={`${acct.card} p-6 space-y-4`}>
|
|
146
|
+
<div className="flex flex-wrap gap-2">
|
|
147
|
+
{(["upi", "bank", "card"] as const).map((t) => (
|
|
148
|
+
<button
|
|
149
|
+
key={t}
|
|
150
|
+
type="button"
|
|
151
|
+
onClick={() => {
|
|
152
|
+
setType(t)
|
|
153
|
+
setError(null)
|
|
154
|
+
setFieldErrors({})
|
|
155
|
+
}}
|
|
156
|
+
className={`px-3 py-1.5 text-xs font-medium rounded-none border ${
|
|
157
|
+
type === t
|
|
158
|
+
? "border-brand-accent text-brand-accent bg-brand-accent-muted"
|
|
159
|
+
: "border-cart-border text-muted"
|
|
160
|
+
}`}
|
|
161
|
+
>
|
|
162
|
+
{t.toUpperCase()}
|
|
163
|
+
</button>
|
|
164
|
+
))}
|
|
165
|
+
</div>
|
|
166
|
+
|
|
167
|
+
{type === "upi" && (
|
|
168
|
+
<Field
|
|
169
|
+
label="UPI ID"
|
|
170
|
+
value={form.upi_id}
|
|
171
|
+
error={fieldErrors.upi_id}
|
|
172
|
+
onChange={(v) => setForm((f) => ({ ...f, upi_id: v }))}
|
|
173
|
+
/>
|
|
174
|
+
)}
|
|
175
|
+
|
|
176
|
+
{type === "bank" && (
|
|
177
|
+
<>
|
|
178
|
+
<Field
|
|
179
|
+
label="Account holder name"
|
|
180
|
+
value={form.account_holder_name}
|
|
181
|
+
error={fieldErrors.account_holder_name}
|
|
182
|
+
onChange={(v) => setForm((f) => ({ ...f, account_holder_name: v }))}
|
|
183
|
+
/>
|
|
184
|
+
<Field
|
|
185
|
+
label="Bank name"
|
|
186
|
+
value={form.bank_name}
|
|
187
|
+
error={fieldErrors.bank_name}
|
|
188
|
+
onChange={(v) => setForm((f) => ({ ...f, bank_name: v }))}
|
|
189
|
+
/>
|
|
190
|
+
<Field
|
|
191
|
+
label="Account number"
|
|
192
|
+
value={form.account_number}
|
|
193
|
+
error={fieldErrors.account_number}
|
|
194
|
+
onChange={(v) => setForm((f) => ({ ...f, account_number: v }))}
|
|
195
|
+
/>
|
|
196
|
+
<Field
|
|
197
|
+
label="IFSC"
|
|
198
|
+
value={form.ifsc}
|
|
199
|
+
error={fieldErrors.ifsc}
|
|
200
|
+
onChange={(v) => setForm((f) => ({ ...f, ifsc: v }))}
|
|
201
|
+
/>
|
|
202
|
+
<Field
|
|
203
|
+
label="Branch name (optional)"
|
|
204
|
+
value={form.branch_name}
|
|
205
|
+
required={false}
|
|
206
|
+
error={fieldErrors.branch_name}
|
|
207
|
+
onChange={(v) => setForm((f) => ({ ...f, branch_name: v }))}
|
|
208
|
+
/>
|
|
209
|
+
</>
|
|
210
|
+
)}
|
|
211
|
+
|
|
212
|
+
{type === "card" && (
|
|
213
|
+
<>
|
|
214
|
+
<Field
|
|
215
|
+
label="Card holder name"
|
|
216
|
+
value={form.card_holder_name}
|
|
217
|
+
error={fieldErrors.card_holder_name}
|
|
218
|
+
onChange={(v) => setForm((f) => ({ ...f, card_holder_name: v }))}
|
|
219
|
+
/>
|
|
220
|
+
<Field
|
|
221
|
+
label="Card number"
|
|
222
|
+
value={form.card_number}
|
|
223
|
+
error={fieldErrors.card_number}
|
|
224
|
+
onChange={(v) => setForm((f) => ({ ...f, card_number: v }))}
|
|
225
|
+
/>
|
|
226
|
+
<Field
|
|
227
|
+
label="Expiry (MM/YY)"
|
|
228
|
+
value={form.expiry_date}
|
|
229
|
+
error={fieldErrors.expiry_date}
|
|
230
|
+
placeholder="08/28"
|
|
231
|
+
onChange={(v) => setForm((f) => ({ ...f, expiry_date: v }))}
|
|
232
|
+
/>
|
|
233
|
+
<Field
|
|
234
|
+
label="CVV"
|
|
235
|
+
value={form.cvv}
|
|
236
|
+
error={fieldErrors.cvv}
|
|
237
|
+
onChange={(v) => setForm((f) => ({ ...f, cvv: v }))}
|
|
238
|
+
/>
|
|
239
|
+
</>
|
|
240
|
+
)}
|
|
241
|
+
|
|
242
|
+
<button type="submit" disabled={pending} className={acct.btnPrimary}>
|
|
243
|
+
{pending ? "Saving…" : "Save payment method"}
|
|
244
|
+
</button>
|
|
245
|
+
</form>
|
|
246
|
+
)}
|
|
247
|
+
|
|
248
|
+
{error && <p className="text-sm text-red-600">{error}</p>}
|
|
249
|
+
|
|
250
|
+
{paymentDetails.length === 0 ? (
|
|
251
|
+
<div className={`${acct.cardMuted} p-8 text-center text-sm ${acct.muted}`}>
|
|
252
|
+
No refund payment methods saved.
|
|
253
|
+
</div>
|
|
254
|
+
) : (
|
|
255
|
+
<ul className="space-y-3">
|
|
256
|
+
{paymentDetails.map((detail) => (
|
|
257
|
+
<li
|
|
258
|
+
key={detail.id}
|
|
259
|
+
className={`${acct.card} p-5 flex flex-wrap justify-between gap-4 items-center`}
|
|
260
|
+
>
|
|
261
|
+
<div>
|
|
262
|
+
<p className="font-medium text-heading text-sm">{labelFor(detail)}</p>
|
|
263
|
+
{detail.is_default && (
|
|
264
|
+
<p className="text-xs text-brand-accent font-medium mt-1">Default</p>
|
|
265
|
+
)}
|
|
266
|
+
</div>
|
|
267
|
+
<div className="flex gap-3 text-xs">
|
|
268
|
+
{!detail.is_default && (
|
|
269
|
+
<button
|
|
270
|
+
type="button"
|
|
271
|
+
onClick={() => handleDefault(detail.id)}
|
|
272
|
+
disabled={pending}
|
|
273
|
+
className="text-brand-accent hover:underline disabled:opacity-60"
|
|
274
|
+
>
|
|
275
|
+
Make default
|
|
276
|
+
</button>
|
|
277
|
+
)}
|
|
278
|
+
<button
|
|
279
|
+
type="button"
|
|
280
|
+
onClick={() => handleDelete(detail.id)}
|
|
281
|
+
disabled={pending}
|
|
282
|
+
className="text-red-600 hover:underline disabled:opacity-60"
|
|
283
|
+
>
|
|
284
|
+
Remove
|
|
285
|
+
</button>
|
|
286
|
+
</div>
|
|
287
|
+
</li>
|
|
288
|
+
))}
|
|
289
|
+
</ul>
|
|
290
|
+
)}
|
|
291
|
+
</div>
|
|
292
|
+
)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function Field({
|
|
296
|
+
label,
|
|
297
|
+
value,
|
|
298
|
+
onChange,
|
|
299
|
+
error,
|
|
300
|
+
required = true,
|
|
301
|
+
placeholder,
|
|
302
|
+
}: {
|
|
303
|
+
label: string
|
|
304
|
+
value: string
|
|
305
|
+
onChange: (value: string) => void
|
|
306
|
+
error?: string
|
|
307
|
+
required?: boolean
|
|
308
|
+
placeholder?: string
|
|
309
|
+
}) {
|
|
310
|
+
return (
|
|
311
|
+
<label className="block">
|
|
312
|
+
<span className="text-xs font-semibold uppercase tracking-wider text-muted mb-1.5 block">
|
|
313
|
+
{label}
|
|
314
|
+
</span>
|
|
315
|
+
<input
|
|
316
|
+
value={value}
|
|
317
|
+
onChange={(e) => onChange(e.target.value)}
|
|
318
|
+
required={required}
|
|
319
|
+
placeholder={placeholder}
|
|
320
|
+
aria-invalid={Boolean(error)}
|
|
321
|
+
className={`w-full border rounded-none px-3 py-2.5 text-sm bg-surface text-heading focus:outline-none focus:border-brand-accent ${
|
|
322
|
+
error ? "border-red-500" : "border-cart-border"
|
|
323
|
+
}`}
|
|
324
|
+
/>
|
|
325
|
+
{error && <span className="mt-1 block text-xs text-red-600">{error}</span>}
|
|
326
|
+
</label>
|
|
327
|
+
)
|
|
328
|
+
}
|