@pradip1995/segment-login-template 0.5.6 → 0.5.8
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pradip1995/segment-login-template",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -20,10 +20,6 @@
|
|
|
20
20
|
"./google-auth-section": "./src/google-auth-section.tsx",
|
|
21
21
|
"./otp-input": "./src/otp-input.tsx"
|
|
22
22
|
},
|
|
23
|
-
"scripts": {
|
|
24
|
-
"typecheck": "tsc --noEmit",
|
|
25
|
-
"lint": "tsc --noEmit"
|
|
26
|
-
},
|
|
27
23
|
"peerDependencies": {
|
|
28
24
|
"@pradip1995/commerce-auth": "^4.0.0",
|
|
29
25
|
"@pradip1995/commerce-core": "^4.0.0",
|
|
@@ -43,5 +39,9 @@
|
|
|
43
39
|
"@types/react": "^19",
|
|
44
40
|
"react": "19.0.3",
|
|
45
41
|
"typescript": "^5.7.2"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"lint": "tsc --noEmit"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|
|
@@ -5,6 +5,7 @@ import type { HttpTypes } from "@medusajs/types"
|
|
|
5
5
|
import {
|
|
6
6
|
addCustomerAddress,
|
|
7
7
|
deleteCustomerAddress,
|
|
8
|
+
setDefaultAddress,
|
|
8
9
|
updateCustomerAddress,
|
|
9
10
|
} from "@pradip1995/commerce-core/data/customer"
|
|
10
11
|
import { acct } from "./account-theme"
|
|
@@ -19,6 +20,7 @@ export default function AccountAddresses({
|
|
|
19
20
|
const addresses = customer.addresses ?? []
|
|
20
21
|
const [editingId, setEditingId] = useState<string | null>(null)
|
|
21
22
|
const [showAdd, setShowAdd] = useState(false)
|
|
23
|
+
const hasDefault = addresses.some((a) => a.is_default_shipping || a.is_default_billing)
|
|
22
24
|
|
|
23
25
|
return (
|
|
24
26
|
<div className="space-y-8">
|
|
@@ -46,6 +48,7 @@ export default function AccountAddresses({
|
|
|
46
48
|
countryCode={countryCode}
|
|
47
49
|
address={address}
|
|
48
50
|
addressId={address.id}
|
|
51
|
+
defaultChecked={!!(address.is_default_shipping || address.is_default_billing)}
|
|
49
52
|
onDone={() => setEditingId(null)}
|
|
50
53
|
onCancel={() => setEditingId(null)}
|
|
51
54
|
/>
|
|
@@ -72,7 +75,10 @@ export default function AccountAddresses({
|
|
|
72
75
|
</p>
|
|
73
76
|
)}
|
|
74
77
|
</div>
|
|
75
|
-
<div className="flex gap-2 shrink-0">
|
|
78
|
+
<div className="flex flex-col sm:flex-row gap-2 shrink-0 items-end sm:items-center">
|
|
79
|
+
{!address.is_default_shipping && (
|
|
80
|
+
<MakeDefaultButton addressId={address.id!} />
|
|
81
|
+
)}
|
|
76
82
|
<button
|
|
77
83
|
type="button"
|
|
78
84
|
onClick={() => setEditingId(address.id!)}
|
|
@@ -93,6 +99,7 @@ export default function AccountAddresses({
|
|
|
93
99
|
<h3 className="text-sm font-semibold text-heading mb-4">New address</h3>
|
|
94
100
|
<AddressForm
|
|
95
101
|
countryCode={countryCode}
|
|
102
|
+
defaultChecked={addresses.length === 0 || !hasDefault}
|
|
96
103
|
onDone={() => setShowAdd(false)}
|
|
97
104
|
onCancel={() => setShowAdd(false)}
|
|
98
105
|
/>
|
|
@@ -106,23 +113,41 @@ function AddressForm({
|
|
|
106
113
|
countryCode,
|
|
107
114
|
address,
|
|
108
115
|
addressId,
|
|
116
|
+
defaultChecked = false,
|
|
109
117
|
onDone,
|
|
110
118
|
onCancel,
|
|
111
119
|
}: {
|
|
112
120
|
countryCode: string
|
|
113
121
|
address?: HttpTypes.StoreCustomerAddress
|
|
114
122
|
addressId?: string
|
|
123
|
+
defaultChecked?: boolean
|
|
115
124
|
onDone: () => void
|
|
116
125
|
onCancel: () => void
|
|
117
126
|
}) {
|
|
118
127
|
const action = addressId ? updateCustomerAddress : addCustomerAddress
|
|
119
128
|
const [state, formAction, pending] = useActionState(
|
|
120
129
|
async (prev: Record<string, unknown>, formData: FormData) => {
|
|
130
|
+
const makeDefault = formData.get("is_default") === "on"
|
|
121
131
|
const result = await action(
|
|
122
|
-
addressId
|
|
132
|
+
addressId
|
|
133
|
+
? { ...prev, addressId }
|
|
134
|
+
: {
|
|
135
|
+
...prev,
|
|
136
|
+
isDefaultShipping: makeDefault,
|
|
137
|
+
isDefaultBilling: makeDefault,
|
|
138
|
+
},
|
|
123
139
|
formData
|
|
124
140
|
)
|
|
125
141
|
if (result?.success) {
|
|
142
|
+
if (addressId && makeDefault && !address?.is_default_shipping) {
|
|
143
|
+
const defaultResult = await setDefaultAddress(addressId)
|
|
144
|
+
if (!defaultResult?.success) {
|
|
145
|
+
return {
|
|
146
|
+
success: false,
|
|
147
|
+
error: defaultResult?.error || "Failed to set default address",
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
126
151
|
onDone()
|
|
127
152
|
window.location.reload()
|
|
128
153
|
}
|
|
@@ -146,6 +171,15 @@ function AddressForm({
|
|
|
146
171
|
defaultValue={address?.country_code || countryCode}
|
|
147
172
|
/>
|
|
148
173
|
<Field label="Phone" name="phone" type="tel" defaultValue={address?.phone || ""} />
|
|
174
|
+
<label className="sm:col-span-2 flex items-center gap-2 text-sm text-body cursor-pointer">
|
|
175
|
+
<input
|
|
176
|
+
type="checkbox"
|
|
177
|
+
name="is_default"
|
|
178
|
+
defaultChecked={defaultChecked}
|
|
179
|
+
className="size-4 accent-[var(--color-brand-accent,#7c3aed)]"
|
|
180
|
+
/>
|
|
181
|
+
<span>Set as default shipping address</span>
|
|
182
|
+
</label>
|
|
149
183
|
{state?.error && (
|
|
150
184
|
<p className="sm:col-span-2 text-sm text-red-600">{String(state.error)}</p>
|
|
151
185
|
)}
|
|
@@ -161,6 +195,42 @@ function AddressForm({
|
|
|
161
195
|
)
|
|
162
196
|
}
|
|
163
197
|
|
|
198
|
+
function MakeDefaultButton({ addressId }: { addressId: string }) {
|
|
199
|
+
const [pending, setPending] = useState(false)
|
|
200
|
+
const [error, setError] = useState<string | null>(null)
|
|
201
|
+
|
|
202
|
+
async function handleDefault() {
|
|
203
|
+
setPending(true)
|
|
204
|
+
setError(null)
|
|
205
|
+
try {
|
|
206
|
+
const result = await setDefaultAddress(addressId)
|
|
207
|
+
if (!result?.success) {
|
|
208
|
+
setError(result?.error || "Failed to set default address")
|
|
209
|
+
setPending(false)
|
|
210
|
+
return
|
|
211
|
+
}
|
|
212
|
+
window.location.reload()
|
|
213
|
+
} catch (err) {
|
|
214
|
+
setError(err instanceof Error ? err.message : "Failed to set default address")
|
|
215
|
+
setPending(false)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<div className="flex flex-col items-end gap-1">
|
|
221
|
+
<button
|
|
222
|
+
type="button"
|
|
223
|
+
onClick={handleDefault}
|
|
224
|
+
disabled={pending}
|
|
225
|
+
className="text-xs text-brand-accent hover:underline disabled:opacity-60"
|
|
226
|
+
>
|
|
227
|
+
{pending ? "Setting…" : "Make default"}
|
|
228
|
+
</button>
|
|
229
|
+
{error && <p className="text-xs text-red-600 max-w-[12rem] text-right">{error}</p>}
|
|
230
|
+
</div>
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
|
|
164
234
|
function DeleteAddressButton({ addressId }: { addressId: string }) {
|
|
165
235
|
const [pending, setPending] = useState(false)
|
|
166
236
|
|
|
@@ -4,7 +4,7 @@ import type { HttpTypes } from "@medusajs/types"
|
|
|
4
4
|
import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
|
|
5
5
|
import { formatPrice } from "@pradip1995/segment-primitives/format-price"
|
|
6
6
|
import { logoutGuest } from "@pradip1995/commerce-core/data/guest"
|
|
7
|
-
import {
|
|
7
|
+
import { acct } from "./account-theme"
|
|
8
8
|
|
|
9
9
|
export default function AccountGuestOrders({
|
|
10
10
|
orders,
|
|
@@ -62,8 +62,8 @@ export default function AccountGuestOrders({
|
|
|
62
62
|
{safeOrders.length === 0 ? (
|
|
63
63
|
<div className="border border-cart-border bg-surface p-8 text-center">
|
|
64
64
|
<p className="text-sm text-muted mb-4">No guest orders found for this session.</p>
|
|
65
|
-
<LocalizedLink href="/store" className={
|
|
66
|
-
|
|
65
|
+
<LocalizedLink href="/store" className={acct.btnPrimary}>
|
|
66
|
+
Continue shopping
|
|
67
67
|
</LocalizedLink>
|
|
68
68
|
</div>
|
|
69
69
|
) : (
|
package/src/account-theme.ts
CHANGED
|
@@ -51,7 +51,7 @@ export const auth = {
|
|
|
51
51
|
input:
|
|
52
52
|
"w-full px-0 py-3 text-sm text-heading bg-transparent border-0 border-b-2 border-cart-border rounded-none placeholder:text-muted/50 focus:outline-none focus:border-brand-primary focus:ring-0 transition-colors duration-200",
|
|
53
53
|
btnPrimary:
|
|
54
|
-
"group relative w-full py-3.5 bg-brand-primary text-inverse text-[11px] font-bold uppercase tracking-[0.28em] shadow-[0_8px_28px_-6px_rgba(0,0,0,0.25)] hover:bg-brand-accent hover:shadow-[0_12px_32px_-6px_rgba(0,0,0,0.3)] transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed overflow-hidden active:scale-[0.98]",
|
|
54
|
+
"group relative w-full inline-flex items-center justify-center py-3.5 bg-brand-primary text-inverse text-[11px] font-bold uppercase tracking-[0.28em] shadow-[0_8px_28px_-6px_rgba(0,0,0,0.25)] hover:bg-brand-accent hover:shadow-[0_12px_32px_-6px_rgba(0,0,0,0.3)] transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed overflow-hidden active:scale-[0.98]",
|
|
55
55
|
btnShine:
|
|
56
56
|
"before:absolute before:inset-0 before:bg-gradient-to-r before:from-transparent before:via-white/15 before:to-transparent before:-translate-x-full hover:before:translate-x-full before:transition-transform before:duration-700",
|
|
57
57
|
btnOutline:
|