@pradip1995/segment-animation-login 0.1.1
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 +45 -0
- package/src/account-addresses.tsx +436 -0
- package/src/account-orders.tsx +261 -0
- package/src/account-overview.tsx +117 -0
- package/src/account-pages.tsx +81 -0
- package/src/animation-account.css +878 -0
- package/src/animation-login.css +427 -0
- package/src/guest-order-modal.tsx +216 -0
- package/src/index.ts +2 -0
- package/src/login-form.tsx +358 -0
- package/src/manifest.ts +11 -0
- package/src/segment.tsx +147 -0
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pradip1995/segment-animation-login",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Motion/Lumière OTP login and account shell",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"sideEffects": [
|
|
10
|
+
"./src/animation-login.css"
|
|
11
|
+
],
|
|
12
|
+
"files": [
|
|
13
|
+
"src"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./src/index.ts",
|
|
17
|
+
"./manifest": "./src/manifest.ts"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@pradip1995/commerce-auth": "^4.0.0",
|
|
21
|
+
"@pradip1995/commerce-core": "^4.0.0",
|
|
22
|
+
"@pradip1995/plugin-sdk": "^0.2.0",
|
|
23
|
+
"next": ">=15",
|
|
24
|
+
"react": ">=19",
|
|
25
|
+
"react-dom": ">=19"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@medusajs/types": "^2.8.0",
|
|
29
|
+
"@pradip1995/commerce-core": "^4.0.0",
|
|
30
|
+
"@pradip1995/segment-login-template": "^0.5.7",
|
|
31
|
+
"@pradip1995/segment-primitives": "^0.4.3",
|
|
32
|
+
"framer-motion": "^11.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@pradip1995/plugin-sdk": "^0.2.0",
|
|
36
|
+
"@types/react": "^19",
|
|
37
|
+
"next": ">=15",
|
|
38
|
+
"react": "19.0.3",
|
|
39
|
+
"typescript": "^5.7.2"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"lint": "tsc --noEmit"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useActionState, useEffect, useState, type ReactNode } from "react"
|
|
4
|
+
import type { HttpTypes } from "@medusajs/types"
|
|
5
|
+
import {
|
|
6
|
+
addCustomerAddress,
|
|
7
|
+
deleteCustomerAddress,
|
|
8
|
+
setDefaultAddress,
|
|
9
|
+
updateCustomerAddress,
|
|
10
|
+
} from "@pradip1995/commerce-core/data/customer"
|
|
11
|
+
|
|
12
|
+
export default function AnimationAccountAddresses({
|
|
13
|
+
customer,
|
|
14
|
+
countryCode,
|
|
15
|
+
}: {
|
|
16
|
+
customer: HttpTypes.StoreCustomer
|
|
17
|
+
countryCode: string
|
|
18
|
+
}) {
|
|
19
|
+
const addresses = customer.addresses ?? []
|
|
20
|
+
const [editingId, setEditingId] = useState<string | null>(null)
|
|
21
|
+
const [showAdd, setShowAdd] = useState(false)
|
|
22
|
+
const hasDefault = addresses.some((a) => a.is_default_shipping || a.is_default_billing)
|
|
23
|
+
const editingAddress = addresses.find((address) => address.id === editingId)
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div className="anim-acct anim-acct--addresses">
|
|
27
|
+
<header className="anim-acct__welcome">
|
|
28
|
+
<div>
|
|
29
|
+
<p className="anim-acct__kicker">Delivery</p>
|
|
30
|
+
<h2 className="anim-acct__hello">Saved addresses</h2>
|
|
31
|
+
<p className="anim-acct__signed-in">Manage shipping and billing addresses.</p>
|
|
32
|
+
</div>
|
|
33
|
+
<button
|
|
34
|
+
type="button"
|
|
35
|
+
className="anim-acct__btn anim-acct__btn--primary"
|
|
36
|
+
onClick={() => {
|
|
37
|
+
setEditingId(null)
|
|
38
|
+
setShowAdd(true)
|
|
39
|
+
}}
|
|
40
|
+
>
|
|
41
|
+
Add address
|
|
42
|
+
</button>
|
|
43
|
+
</header>
|
|
44
|
+
|
|
45
|
+
{addresses.length === 0 ? (
|
|
46
|
+
<div className="anim-acct__empty">
|
|
47
|
+
<p>No saved addresses yet.</p>
|
|
48
|
+
<button
|
|
49
|
+
type="button"
|
|
50
|
+
className="anim-acct__btn anim-acct__btn--outline"
|
|
51
|
+
onClick={() => setShowAdd(true)}
|
|
52
|
+
>
|
|
53
|
+
Add your first address
|
|
54
|
+
</button>
|
|
55
|
+
</div>
|
|
56
|
+
) : (
|
|
57
|
+
<ul className="anim-acct__address-list">
|
|
58
|
+
{addresses.map((address) => {
|
|
59
|
+
const isDefault = address.is_default_shipping || address.is_default_billing
|
|
60
|
+
const name = [address.first_name, address.last_name].filter(Boolean).join(" ")
|
|
61
|
+
return (
|
|
62
|
+
<li key={address.id} className="anim-acct__address-card">
|
|
63
|
+
<div className="anim-acct__address-top">
|
|
64
|
+
<div className="anim-acct__address-heading">
|
|
65
|
+
<h3>{name || "Customer"}</h3>
|
|
66
|
+
{isDefault ? <span className="anim-acct__badge">Default</span> : null}
|
|
67
|
+
</div>
|
|
68
|
+
<div className="anim-acct__address-icons">
|
|
69
|
+
<button
|
|
70
|
+
type="button"
|
|
71
|
+
className="anim-acct__icon-btn"
|
|
72
|
+
aria-label="Edit address"
|
|
73
|
+
title="Edit"
|
|
74
|
+
onClick={() => {
|
|
75
|
+
setShowAdd(false)
|
|
76
|
+
setEditingId(address.id!)
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
79
|
+
<EditIcon />
|
|
80
|
+
</button>
|
|
81
|
+
<DeleteAddressButton addressId={address.id!} iconOnly />
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
<div className="anim-acct__address-body">
|
|
85
|
+
<p>{address.address_1}</p>
|
|
86
|
+
{address.address_2 ? <p>{address.address_2}</p> : null}
|
|
87
|
+
<p>
|
|
88
|
+
{[address.city, address.province, address.postal_code]
|
|
89
|
+
.filter(Boolean)
|
|
90
|
+
.join(", ")}
|
|
91
|
+
</p>
|
|
92
|
+
{address.phone ? <p className="anim-acct__address-phone">{address.phone}</p> : null}
|
|
93
|
+
</div>
|
|
94
|
+
{!isDefault ? (
|
|
95
|
+
<div className="anim-acct__address-actions">
|
|
96
|
+
<MakeDefaultButton addressId={address.id!} />
|
|
97
|
+
</div>
|
|
98
|
+
) : null}
|
|
99
|
+
</li>
|
|
100
|
+
)
|
|
101
|
+
})}
|
|
102
|
+
</ul>
|
|
103
|
+
)}
|
|
104
|
+
|
|
105
|
+
{showAdd ? (
|
|
106
|
+
<AddressModal title="New address" onClose={() => setShowAdd(false)}>
|
|
107
|
+
<AddressForm
|
|
108
|
+
countryCode={countryCode}
|
|
109
|
+
defaultChecked={addresses.length === 0 || !hasDefault}
|
|
110
|
+
onDone={() => setShowAdd(false)}
|
|
111
|
+
onCancel={() => setShowAdd(false)}
|
|
112
|
+
/>
|
|
113
|
+
</AddressModal>
|
|
114
|
+
) : null}
|
|
115
|
+
|
|
116
|
+
{editingAddress ? (
|
|
117
|
+
<AddressModal title="Edit address" onClose={() => setEditingId(null)}>
|
|
118
|
+
<AddressForm
|
|
119
|
+
countryCode={countryCode}
|
|
120
|
+
address={editingAddress}
|
|
121
|
+
addressId={editingAddress.id}
|
|
122
|
+
defaultChecked={
|
|
123
|
+
!!(editingAddress.is_default_shipping || editingAddress.is_default_billing)
|
|
124
|
+
}
|
|
125
|
+
onDone={() => setEditingId(null)}
|
|
126
|
+
onCancel={() => setEditingId(null)}
|
|
127
|
+
/>
|
|
128
|
+
</AddressModal>
|
|
129
|
+
) : null}
|
|
130
|
+
</div>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function AddressModal({
|
|
135
|
+
title,
|
|
136
|
+
onClose,
|
|
137
|
+
children,
|
|
138
|
+
}: {
|
|
139
|
+
title: string
|
|
140
|
+
onClose: () => void
|
|
141
|
+
children: ReactNode
|
|
142
|
+
}) {
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
const previous = document.body.style.overflow
|
|
145
|
+
document.body.style.overflow = "hidden"
|
|
146
|
+
|
|
147
|
+
function onKey(event: KeyboardEvent) {
|
|
148
|
+
if (event.key === "Escape") onClose()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
window.addEventListener("keydown", onKey)
|
|
152
|
+
return () => {
|
|
153
|
+
document.body.style.overflow = previous
|
|
154
|
+
window.removeEventListener("keydown", onKey)
|
|
155
|
+
}
|
|
156
|
+
}, [onClose])
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<div className="anim-acct-modal" role="dialog" aria-modal="true" aria-label={title}>
|
|
160
|
+
<button
|
|
161
|
+
type="button"
|
|
162
|
+
className="anim-acct-modal__backdrop"
|
|
163
|
+
aria-label="Close dialog"
|
|
164
|
+
onClick={onClose}
|
|
165
|
+
/>
|
|
166
|
+
<div className="anim-acct-modal__panel">
|
|
167
|
+
<div className="anim-acct-modal__head">
|
|
168
|
+
<h3>{title}</h3>
|
|
169
|
+
<button type="button" className="anim-acct-modal__close" onClick={onClose} aria-label="Close">
|
|
170
|
+
×
|
|
171
|
+
</button>
|
|
172
|
+
</div>
|
|
173
|
+
<div className="anim-acct-modal__body">{children}</div>
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function AddressForm({
|
|
180
|
+
countryCode,
|
|
181
|
+
address,
|
|
182
|
+
addressId,
|
|
183
|
+
defaultChecked = false,
|
|
184
|
+
onDone,
|
|
185
|
+
onCancel,
|
|
186
|
+
}: {
|
|
187
|
+
countryCode: string
|
|
188
|
+
address?: HttpTypes.StoreCustomerAddress
|
|
189
|
+
addressId?: string
|
|
190
|
+
defaultChecked?: boolean
|
|
191
|
+
onDone: () => void
|
|
192
|
+
onCancel: () => void
|
|
193
|
+
}) {
|
|
194
|
+
const action = addressId ? updateCustomerAddress : addCustomerAddress
|
|
195
|
+
const [state, formAction, pending] = useActionState(
|
|
196
|
+
async (prev: Record<string, unknown>, formData: FormData) => {
|
|
197
|
+
const makeDefault = formData.get("is_default") === "on"
|
|
198
|
+
const result = await action(
|
|
199
|
+
addressId
|
|
200
|
+
? { ...prev, addressId }
|
|
201
|
+
: {
|
|
202
|
+
...prev,
|
|
203
|
+
isDefaultShipping: makeDefault,
|
|
204
|
+
isDefaultBilling: makeDefault,
|
|
205
|
+
},
|
|
206
|
+
formData
|
|
207
|
+
)
|
|
208
|
+
if (result?.success) {
|
|
209
|
+
if (addressId && makeDefault && !address?.is_default_shipping) {
|
|
210
|
+
const defaultResult = await setDefaultAddress(addressId)
|
|
211
|
+
if (!defaultResult?.success) {
|
|
212
|
+
return {
|
|
213
|
+
success: false,
|
|
214
|
+
error: defaultResult?.error || "Failed to set default address",
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
onDone()
|
|
219
|
+
window.location.reload()
|
|
220
|
+
}
|
|
221
|
+
return result
|
|
222
|
+
},
|
|
223
|
+
{ success: false, error: null as string | null }
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
return (
|
|
227
|
+
<form action={formAction} className="anim-acct-form">
|
|
228
|
+
<Field label="First name" name="first_name" defaultValue={address?.first_name || ""} />
|
|
229
|
+
<Field label="Last name" name="last_name" defaultValue={address?.last_name || ""} />
|
|
230
|
+
<Field
|
|
231
|
+
label="Address line 1"
|
|
232
|
+
name="address_1"
|
|
233
|
+
className="anim-acct-form__full"
|
|
234
|
+
defaultValue={address?.address_1 || ""}
|
|
235
|
+
/>
|
|
236
|
+
<Field
|
|
237
|
+
label="Address line 2"
|
|
238
|
+
name="address_2"
|
|
239
|
+
className="anim-acct-form__full"
|
|
240
|
+
defaultValue={address?.address_2 || ""}
|
|
241
|
+
required={false}
|
|
242
|
+
/>
|
|
243
|
+
<Field label="City" name="city" defaultValue={address?.city || ""} />
|
|
244
|
+
<Field label="State / Province" name="province" defaultValue={address?.province || ""} />
|
|
245
|
+
<Field label="Postal code" name="postal_code" defaultValue={address?.postal_code || ""} />
|
|
246
|
+
<Field
|
|
247
|
+
label="Country code"
|
|
248
|
+
name="country_code"
|
|
249
|
+
defaultValue={address?.country_code || countryCode}
|
|
250
|
+
/>
|
|
251
|
+
<Field
|
|
252
|
+
label="Phone"
|
|
253
|
+
name="phone"
|
|
254
|
+
type="tel"
|
|
255
|
+
className="anim-acct-form__full"
|
|
256
|
+
defaultValue={address?.phone || ""}
|
|
257
|
+
required={false}
|
|
258
|
+
/>
|
|
259
|
+
<label className="anim-acct-form__check anim-acct-form__full">
|
|
260
|
+
<input type="checkbox" name="is_default" defaultChecked={defaultChecked} />
|
|
261
|
+
<span>Set as default shipping address</span>
|
|
262
|
+
</label>
|
|
263
|
+
{state?.error ? (
|
|
264
|
+
<p className="anim-acct-form__error anim-acct-form__full">{String(state.error)}</p>
|
|
265
|
+
) : null}
|
|
266
|
+
<div className="anim-acct-form__actions anim-acct-form__full">
|
|
267
|
+
<button type="submit" disabled={pending} className="anim-acct__btn anim-acct__btn--primary">
|
|
268
|
+
{pending ? "Saving…" : "Save address"}
|
|
269
|
+
</button>
|
|
270
|
+
<button
|
|
271
|
+
type="button"
|
|
272
|
+
onClick={onCancel}
|
|
273
|
+
className="anim-acct__btn anim-acct__btn--outline"
|
|
274
|
+
disabled={pending}
|
|
275
|
+
>
|
|
276
|
+
Cancel
|
|
277
|
+
</button>
|
|
278
|
+
</div>
|
|
279
|
+
</form>
|
|
280
|
+
)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function MakeDefaultButton({ addressId }: { addressId: string }) {
|
|
284
|
+
const [pending, setPending] = useState(false)
|
|
285
|
+
const [error, setError] = useState<string | null>(null)
|
|
286
|
+
|
|
287
|
+
async function handleDefault() {
|
|
288
|
+
setPending(true)
|
|
289
|
+
setError(null)
|
|
290
|
+
try {
|
|
291
|
+
const result = await setDefaultAddress(addressId)
|
|
292
|
+
if (!result?.success) {
|
|
293
|
+
setError(result?.error || "Failed to set default address")
|
|
294
|
+
setPending(false)
|
|
295
|
+
return
|
|
296
|
+
}
|
|
297
|
+
window.location.reload()
|
|
298
|
+
} catch (err) {
|
|
299
|
+
setError(err instanceof Error ? err.message : "Failed to set default address")
|
|
300
|
+
setPending(false)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return (
|
|
305
|
+
<div className="anim-acct__text-action-wrap">
|
|
306
|
+
<button
|
|
307
|
+
type="button"
|
|
308
|
+
onClick={handleDefault}
|
|
309
|
+
disabled={pending}
|
|
310
|
+
className="anim-acct__text-action"
|
|
311
|
+
>
|
|
312
|
+
{pending ? "Setting…" : "Make default"}
|
|
313
|
+
</button>
|
|
314
|
+
{error ? <p className="anim-acct-form__error">{error}</p> : null}
|
|
315
|
+
</div>
|
|
316
|
+
)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function DeleteAddressButton({
|
|
320
|
+
addressId,
|
|
321
|
+
iconOnly = false,
|
|
322
|
+
}: {
|
|
323
|
+
addressId: string
|
|
324
|
+
iconOnly?: boolean
|
|
325
|
+
}) {
|
|
326
|
+
const [pending, setPending] = useState(false)
|
|
327
|
+
|
|
328
|
+
async function handleDelete() {
|
|
329
|
+
if (!confirm("Delete this address?")) return
|
|
330
|
+
setPending(true)
|
|
331
|
+
try {
|
|
332
|
+
await deleteCustomerAddress(addressId)
|
|
333
|
+
window.location.reload()
|
|
334
|
+
} finally {
|
|
335
|
+
setPending(false)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (iconOnly) {
|
|
340
|
+
return (
|
|
341
|
+
<button
|
|
342
|
+
type="button"
|
|
343
|
+
onClick={handleDelete}
|
|
344
|
+
disabled={pending}
|
|
345
|
+
className="anim-acct__icon-btn anim-acct__icon-btn--danger"
|
|
346
|
+
aria-label={pending ? "Deleting address" : "Delete address"}
|
|
347
|
+
title="Delete"
|
|
348
|
+
>
|
|
349
|
+
<DeleteIcon />
|
|
350
|
+
</button>
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return (
|
|
355
|
+
<button
|
|
356
|
+
type="button"
|
|
357
|
+
onClick={handleDelete}
|
|
358
|
+
disabled={pending}
|
|
359
|
+
className="anim-acct__text-action anim-acct__text-action--danger"
|
|
360
|
+
>
|
|
361
|
+
{pending ? "Deleting…" : "Delete"}
|
|
362
|
+
</button>
|
|
363
|
+
)
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function EditIcon() {
|
|
367
|
+
return (
|
|
368
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden>
|
|
369
|
+
<path
|
|
370
|
+
d="M12 20h9"
|
|
371
|
+
stroke="currentColor"
|
|
372
|
+
strokeWidth="1.75"
|
|
373
|
+
strokeLinecap="round"
|
|
374
|
+
strokeLinejoin="round"
|
|
375
|
+
/>
|
|
376
|
+
<path
|
|
377
|
+
d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"
|
|
378
|
+
stroke="currentColor"
|
|
379
|
+
strokeWidth="1.75"
|
|
380
|
+
strokeLinecap="round"
|
|
381
|
+
strokeLinejoin="round"
|
|
382
|
+
/>
|
|
383
|
+
</svg>
|
|
384
|
+
)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function DeleteIcon() {
|
|
388
|
+
return (
|
|
389
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden>
|
|
390
|
+
<path
|
|
391
|
+
d="M3 6h18"
|
|
392
|
+
stroke="currentColor"
|
|
393
|
+
strokeWidth="1.75"
|
|
394
|
+
strokeLinecap="round"
|
|
395
|
+
/>
|
|
396
|
+
<path
|
|
397
|
+
d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"
|
|
398
|
+
stroke="currentColor"
|
|
399
|
+
strokeWidth="1.75"
|
|
400
|
+
strokeLinecap="round"
|
|
401
|
+
strokeLinejoin="round"
|
|
402
|
+
/>
|
|
403
|
+
<path
|
|
404
|
+
d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"
|
|
405
|
+
stroke="currentColor"
|
|
406
|
+
strokeWidth="1.75"
|
|
407
|
+
strokeLinecap="round"
|
|
408
|
+
strokeLinejoin="round"
|
|
409
|
+
/>
|
|
410
|
+
<path d="M10 11v6M14 11v6" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" />
|
|
411
|
+
</svg>
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function Field({
|
|
416
|
+
label,
|
|
417
|
+
name,
|
|
418
|
+
type = "text",
|
|
419
|
+
defaultValue,
|
|
420
|
+
className = "",
|
|
421
|
+
required = true,
|
|
422
|
+
}: {
|
|
423
|
+
label: string
|
|
424
|
+
name: string
|
|
425
|
+
type?: string
|
|
426
|
+
defaultValue?: string
|
|
427
|
+
className?: string
|
|
428
|
+
required?: boolean
|
|
429
|
+
}) {
|
|
430
|
+
return (
|
|
431
|
+
<label className={`anim-acct-form__field ${className}`}>
|
|
432
|
+
<span>{label}</span>
|
|
433
|
+
<input name={name} type={type} defaultValue={defaultValue} required={required} />
|
|
434
|
+
</label>
|
|
435
|
+
)
|
|
436
|
+
}
|