@pradip1995/segment-login-template 0.5.11 → 0.5.12

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.11",
3
+ "version": "0.5.12",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -62,6 +62,7 @@ export default function AccountProfile({
62
62
  verifyPending={profile.otpPending}
63
63
  onVerify={() => profile.sendVerifyOtp("phone_verification")}
64
64
  verifyButtonClassName={`${acct.btnOutline} !py-2 !px-3`}
65
+ editButtonClassName={`${acct.btnOutline} !py-2 !px-3`}
65
66
  />
66
67
 
67
68
  {(profile.state.error || profile.message) && (
@@ -1,5 +1,6 @@
1
1
  "use client"
2
2
 
3
+ import { useEffect, useState } from "react"
3
4
  import { SplitPhoneInput } from "@pradip1995/commerce-core/components/split-phone-input"
4
5
 
5
6
  export type ProfilePhoneFieldProps = {
@@ -15,6 +16,7 @@ export type ProfilePhoneFieldProps = {
15
16
  labelClassName?: string
16
17
  rowClassName?: string
17
18
  verifyButtonClassName?: string
19
+ editButtonClassName?: string
18
20
  verifiedClassName?: string
19
21
  errorClassName?: string
20
22
  hintClassName?: string
@@ -35,17 +37,31 @@ export default function ProfilePhoneField({
35
37
  labelClassName = "text-xs font-semibold uppercase tracking-wider text-muted mb-1.5 block",
36
38
  rowClassName = "flex flex-wrap items-center gap-3",
37
39
  verifyButtonClassName = "",
40
+ editButtonClassName = "",
38
41
  verifiedClassName = "text-xs text-green-600 font-medium",
39
42
  errorClassName = "text-sm text-red-600 mt-1.5",
40
43
  hintClassName = "text-xs text-muted mt-1.5",
41
44
  phoneInputClassName = "",
42
45
  numberInputId = "account-profile-phone",
43
46
  }: ProfilePhoneFieldProps) {
47
+ const [editing, setEditing] = useState(false)
48
+ const locked = phoneVerified && !editing
49
+
50
+ useEffect(() => {
51
+ if (phoneVerified) setEditing(false)
52
+ }, [phoneVerified])
53
+
44
54
  return (
45
55
  <div className={wrapperClassName}>
46
56
  <span className={labelClassName}>{label}</span>
47
57
  <div className={rowClassName}>
48
- <div className={`flex-1 min-w-[200px] ${phoneInputClassName}`}>
58
+ <div
59
+ className={`flex-1 min-w-[200px] ${phoneInputClassName}${
60
+ locked ? " pointer-events-none opacity-80" : ""
61
+ }`}
62
+ aria-disabled={locked || undefined}
63
+ {...(locked ? { inert: true } : {})}
64
+ >
49
65
  <SplitPhoneInput
50
66
  value={phone}
51
67
  onChange={onPhoneChange}
@@ -54,7 +70,19 @@ export default function ProfilePhoneField({
54
70
  data-testid="account-profile-phone"
55
71
  />
56
72
  </div>
57
- {phoneVerified ? (
73
+ {locked ? (
74
+ <>
75
+ <span className={verifiedClassName}>Verified</span>
76
+ <button
77
+ type="button"
78
+ onClick={() => setEditing(true)}
79
+ className={editButtonClassName || verifyButtonClassName}
80
+ data-testid="account-profile-edit-phone"
81
+ >
82
+ Edit
83
+ </button>
84
+ </>
85
+ ) : phoneVerified ? (
58
86
  <span className={verifiedClassName}>Verified</span>
59
87
  ) : phoneReady ? (
60
88
  <button
@@ -73,10 +101,18 @@ export default function ProfilePhoneField({
73
101
  {phoneError}
74
102
  </p>
75
103
  ) : null}
76
- {!phoneVerified && phoneReady ? (
104
+ {locked ? (
105
+ <p className={hintClassName}>
106
+ Tap <strong>Edit</strong> to change this number.
107
+ </p>
108
+ ) : !phoneVerified && phoneReady ? (
77
109
  <p className={hintClassName}>
78
110
  Tap <strong>Verify phone</strong> to receive an OTP on this number.
79
111
  </p>
112
+ ) : editing ? (
113
+ <p className={hintClassName}>
114
+ Update the number, then save and verify it again.
115
+ </p>
80
116
  ) : null}
81
117
  </div>
82
118
  )