@pradip1995/segment-animation-login 0.1.4 → 0.1.5

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-animation-login",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Motion/Lumière OTP login and account shell",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -16,6 +16,10 @@
16
16
  ".": "./src/index.ts",
17
17
  "./manifest": "./src/manifest.ts"
18
18
  },
19
+ "scripts": {
20
+ "typecheck": "tsc --noEmit",
21
+ "lint": "tsc --noEmit"
22
+ },
19
23
  "peerDependencies": {
20
24
  "@pradip1995/commerce-auth": "^4.0.0",
21
25
  "@pradip1995/commerce-core": "^4.0.0",
@@ -27,8 +31,8 @@
27
31
  "dependencies": {
28
32
  "@medusajs/types": "^2.8.0",
29
33
  "@pradip1995/commerce-core": "^4.0.0",
30
- "@pradip1995/segment-login-template": "^0.5.14",
31
- "@pradip1995/segment-primitives": "^0.4.11",
34
+ "@pradip1995/segment-login-template": "^0.5.28",
35
+ "@pradip1995/segment-primitives": "^0.4.20",
32
36
  "framer-motion": "^11.0.0"
33
37
  },
34
38
  "devDependencies": {
@@ -37,9 +41,5 @@
37
41
  "next": ">=15",
38
42
  "react": "19.0.3",
39
43
  "typescript": "^5.7.2"
40
- },
41
- "scripts": {
42
- "typecheck": "tsc --noEmit",
43
- "lint": "tsc --noEmit"
44
44
  }
45
- }
45
+ }
@@ -6,9 +6,16 @@ import type { HttpTypes } from "@medusajs/types"
6
6
  import {
7
7
  addCustomerAddress,
8
8
  deleteCustomerAddress,
9
- setDefaultAddress,
10
9
  updateCustomerAddress,
11
10
  } from "@pradip1995/commerce-core/data/customer"
11
+ import {
12
+ ensureExclusiveDefaultAddress,
13
+ setExclusiveDefaultAddress,
14
+ } from "@pradip1995/segment-login-template/address-actions"
15
+ import {
16
+ isExclusiveDefaultAddress,
17
+ resolveDefaultAddressId,
18
+ } from "@pradip1995/segment-login-template/default-address"
12
19
 
13
20
  export default function AnimationAccountAddresses({
14
21
  customer,
@@ -20,7 +27,8 @@ export default function AnimationAccountAddresses({
20
27
  const addresses = customer.addresses ?? []
21
28
  const [editingId, setEditingId] = useState<string | null>(null)
22
29
  const [showAdd, setShowAdd] = useState(false)
23
- const hasDefault = addresses.some((a) => a.is_default_shipping || a.is_default_billing)
30
+ const defaultAddressId = resolveDefaultAddressId(addresses)
31
+ const hasDefault = Boolean(defaultAddressId)
24
32
  const editingAddress = addresses.find((address) => address.id === editingId)
25
33
 
26
34
  return (
@@ -57,7 +65,7 @@ export default function AnimationAccountAddresses({
57
65
  ) : (
58
66
  <ul className="anim-acct__address-list">
59
67
  {addresses.map((address) => {
60
- const isDefault = address.is_default_shipping || address.is_default_billing
68
+ const isDefault = isExclusiveDefaultAddress(address, defaultAddressId)
61
69
  const name = [address.first_name, address.last_name].filter(Boolean).join(" ")
62
70
  return (
63
71
  <li key={address.id} className="anim-acct__address-card">
@@ -120,9 +128,7 @@ export default function AnimationAccountAddresses({
120
128
  countryCode={countryCode}
121
129
  address={editingAddress}
122
130
  addressId={editingAddress.id}
123
- defaultChecked={
124
- !!(editingAddress.is_default_shipping || editingAddress.is_default_billing)
125
- }
131
+ defaultChecked={isExclusiveDefaultAddress(editingAddress, defaultAddressId)}
126
132
  onDone={() => setEditingId(null)}
127
133
  onCancel={() => setEditingId(null)}
128
134
  />
@@ -207,8 +213,13 @@ function AddressForm({
207
213
  formData
208
214
  )
209
215
  if (result?.success) {
210
- if (addressId && makeDefault && !address?.is_default_shipping) {
211
- const defaultResult = await setDefaultAddress(addressId)
216
+ if (makeDefault) {
217
+ const defaultResult = await ensureExclusiveDefaultAddress({
218
+ addressId,
219
+ address_1: String(formData.get("address_1") || ""),
220
+ postal_code: String(formData.get("postal_code") || ""),
221
+ phone: String(formData.get("phone") || ""),
222
+ })
212
223
  if (!defaultResult?.success) {
213
224
  return {
214
225
  success: false,
@@ -289,7 +300,7 @@ function MakeDefaultButton({ addressId }: { addressId: string }) {
289
300
  setPending(true)
290
301
  setError(null)
291
302
  try {
292
- const result = await setDefaultAddress(addressId)
303
+ const result = await setExclusiveDefaultAddress(addressId)
293
304
  if (!result?.success) {
294
305
  setError(result?.error || "Failed to set default address")
295
306
  setPending(false)