@pradip1995/segment-login-template 0.5.24 → 0.5.26
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 +54 -54
- package/src/account-addresses.tsx +287 -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/auth-server.ts +442 -442
- package/src/commerce-auth-otp-modal.css +125 -125
- package/src/commerce-auth-otp-modal.tsx +121 -121
- package/src/forgot-password-form.tsx +109 -109
- package/src/google-auth-section.tsx +22 -22
- package/src/google-sign-in-section.tsx +67 -142
- 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 +158 -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 +101 -101
- package/src/reset-password-form.tsx +103 -103
- package/src/reset-password-page.tsx +12 -12
- package/src/segment.tsx +272 -272
package/src/profile-email.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
export const EMAIL_REGEX = /^\S+@\S+\.\S+$/
|
|
2
|
-
|
|
3
|
-
export const EMAIL_OTP_ERRORS = {
|
|
4
|
-
empty: "Please enter an email address before verifying.",
|
|
5
|
-
invalid: "Please enter a valid email address.",
|
|
6
|
-
} as const
|
|
7
|
-
|
|
8
|
-
export function normalizeEmail(value: string | null | undefined): string {
|
|
9
|
-
return (value || "").trim().toLowerCase()
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function isValidEmail(value: string | null | undefined): boolean {
|
|
13
|
-
return EMAIL_REGEX.test(normalizeEmail(value))
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type EmailOtpFlow = "verify_existing" | "change_contact"
|
|
17
|
-
|
|
18
|
-
export type ResolveEmailOtpFlowResult =
|
|
19
|
-
| { ok: true; flow: EmailOtpFlow; email: string }
|
|
20
|
-
| { ok: false; reason: "empty" | "invalid" }
|
|
21
|
-
|
|
22
|
-
export function resolveEmailOtpFlow(input: {
|
|
23
|
-
currentEmail: string | null | undefined
|
|
24
|
-
draftEmail: string | null | undefined
|
|
25
|
-
}): ResolveEmailOtpFlowResult {
|
|
26
|
-
const email = normalizeEmail(input.draftEmail)
|
|
27
|
-
if (!email) return { ok: false, reason: "empty" }
|
|
28
|
-
if (!isValidEmail(email)) return { ok: false, reason: "invalid" }
|
|
29
|
-
const current = normalizeEmail(input.currentEmail)
|
|
30
|
-
if (current && email === current) {
|
|
31
|
-
return { ok: true, flow: "verify_existing", email }
|
|
32
|
-
}
|
|
33
|
-
return { ok: true, flow: "change_contact", email }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function isEmailFieldLocked(input: {
|
|
37
|
-
emailVerified: boolean
|
|
38
|
-
editing: boolean
|
|
39
|
-
}): boolean {
|
|
40
|
-
return input.emailVerified && !input.editing
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type ProfileEmailAction = "verify" | "edit" | "verified" | "none"
|
|
44
|
-
|
|
45
|
-
export function profileEmailAction(input: {
|
|
46
|
-
emailVerified: boolean
|
|
47
|
-
editing: boolean
|
|
48
|
-
emailReady: boolean
|
|
49
|
-
}): ProfileEmailAction {
|
|
50
|
-
if (isEmailFieldLocked(input)) return "edit"
|
|
51
|
-
if (input.emailVerified) return "verified"
|
|
52
|
-
if (input.emailReady) return "verify"
|
|
53
|
-
return "none"
|
|
54
|
-
}
|
|
1
|
+
export const EMAIL_REGEX = /^\S+@\S+\.\S+$/
|
|
2
|
+
|
|
3
|
+
export const EMAIL_OTP_ERRORS = {
|
|
4
|
+
empty: "Please enter an email address before verifying.",
|
|
5
|
+
invalid: "Please enter a valid email address.",
|
|
6
|
+
} as const
|
|
7
|
+
|
|
8
|
+
export function normalizeEmail(value: string | null | undefined): string {
|
|
9
|
+
return (value || "").trim().toLowerCase()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function isValidEmail(value: string | null | undefined): boolean {
|
|
13
|
+
return EMAIL_REGEX.test(normalizeEmail(value))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type EmailOtpFlow = "verify_existing" | "change_contact"
|
|
17
|
+
|
|
18
|
+
export type ResolveEmailOtpFlowResult =
|
|
19
|
+
| { ok: true; flow: EmailOtpFlow; email: string }
|
|
20
|
+
| { ok: false; reason: "empty" | "invalid" }
|
|
21
|
+
|
|
22
|
+
export function resolveEmailOtpFlow(input: {
|
|
23
|
+
currentEmail: string | null | undefined
|
|
24
|
+
draftEmail: string | null | undefined
|
|
25
|
+
}): ResolveEmailOtpFlowResult {
|
|
26
|
+
const email = normalizeEmail(input.draftEmail)
|
|
27
|
+
if (!email) return { ok: false, reason: "empty" }
|
|
28
|
+
if (!isValidEmail(email)) return { ok: false, reason: "invalid" }
|
|
29
|
+
const current = normalizeEmail(input.currentEmail)
|
|
30
|
+
if (current && email === current) {
|
|
31
|
+
return { ok: true, flow: "verify_existing", email }
|
|
32
|
+
}
|
|
33
|
+
return { ok: true, flow: "change_contact", email }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isEmailFieldLocked(input: {
|
|
37
|
+
emailVerified: boolean
|
|
38
|
+
editing: boolean
|
|
39
|
+
}): boolean {
|
|
40
|
+
return input.emailVerified && !input.editing
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ProfileEmailAction = "verify" | "edit" | "verified" | "none"
|
|
44
|
+
|
|
45
|
+
export function profileEmailAction(input: {
|
|
46
|
+
emailVerified: boolean
|
|
47
|
+
editing: boolean
|
|
48
|
+
emailReady: boolean
|
|
49
|
+
}): ProfileEmailAction {
|
|
50
|
+
if (isEmailFieldLocked(input)) return "edit"
|
|
51
|
+
if (input.emailVerified) return "verified"
|
|
52
|
+
if (input.emailReady) return "verify"
|
|
53
|
+
return "none"
|
|
54
|
+
}
|
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { useEffect, useState } from "react"
|
|
4
|
-
import { SplitPhoneInput } from "@pradip1995/commerce-core/components/split-phone-input"
|
|
5
|
-
|
|
6
|
-
export type ProfilePhoneFieldProps = {
|
|
7
|
-
phone: string
|
|
8
|
-
onPhoneChange: (value: string) => void
|
|
9
|
-
phoneVerified: boolean
|
|
10
|
-
phoneReady: boolean
|
|
11
|
-
phoneError: string | null
|
|
12
|
-
verifyPending: boolean
|
|
13
|
-
onVerify: () => void
|
|
14
|
-
label?: string
|
|
15
|
-
wrapperClassName?: string
|
|
16
|
-
labelClassName?: string
|
|
17
|
-
rowClassName?: string
|
|
18
|
-
verifyButtonClassName?: string
|
|
19
|
-
editButtonClassName?: string
|
|
20
|
-
verifiedClassName?: string
|
|
21
|
-
errorClassName?: string
|
|
22
|
-
hintClassName?: string
|
|
23
|
-
phoneInputClassName?: string
|
|
24
|
-
numberInputId?: string
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default function ProfilePhoneField({
|
|
28
|
-
phone,
|
|
29
|
-
onPhoneChange,
|
|
30
|
-
phoneVerified,
|
|
31
|
-
phoneReady,
|
|
32
|
-
phoneError,
|
|
33
|
-
verifyPending,
|
|
34
|
-
onVerify,
|
|
35
|
-
label = "Phone",
|
|
36
|
-
wrapperClassName = "",
|
|
37
|
-
labelClassName = "text-xs font-semibold uppercase tracking-wider text-muted mb-1.5 block",
|
|
38
|
-
rowClassName = "flex flex-wrap items-center gap-3",
|
|
39
|
-
verifyButtonClassName = "",
|
|
40
|
-
editButtonClassName = "",
|
|
41
|
-
verifiedClassName = "text-xs text-green-600 font-medium",
|
|
42
|
-
errorClassName = "text-sm text-red-600 mt-1.5",
|
|
43
|
-
hintClassName = "text-xs text-muted mt-1.5",
|
|
44
|
-
phoneInputClassName = "",
|
|
45
|
-
numberInputId = "account-profile-phone",
|
|
46
|
-
}: ProfilePhoneFieldProps) {
|
|
47
|
-
const [editing, setEditing] = useState(false)
|
|
48
|
-
const locked = phoneVerified && !editing
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
if (phoneVerified) setEditing(false)
|
|
52
|
-
}, [phoneVerified])
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<div className={wrapperClassName}>
|
|
56
|
-
<span className={labelClassName}>{label}</span>
|
|
57
|
-
<div className={rowClassName}>
|
|
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
|
-
>
|
|
65
|
-
<SplitPhoneInput
|
|
66
|
-
value={phone}
|
|
67
|
-
onChange={onPhoneChange}
|
|
68
|
-
label="Mobile number"
|
|
69
|
-
numberInputId={numberInputId}
|
|
70
|
-
data-testid="account-profile-phone"
|
|
71
|
-
/>
|
|
72
|
-
</div>
|
|
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 ? (
|
|
86
|
-
<span className={verifiedClassName}>Verified</span>
|
|
87
|
-
) : phoneReady ? (
|
|
88
|
-
<button
|
|
89
|
-
type="button"
|
|
90
|
-
onClick={onVerify}
|
|
91
|
-
disabled={verifyPending}
|
|
92
|
-
className={verifyButtonClassName}
|
|
93
|
-
data-testid="account-profile-verify-phone"
|
|
94
|
-
>
|
|
95
|
-
{verifyPending ? "Sending…" : "Verify phone"}
|
|
96
|
-
</button>
|
|
97
|
-
) : null}
|
|
98
|
-
</div>
|
|
99
|
-
{phoneError ? (
|
|
100
|
-
<p className={errorClassName} role="alert">
|
|
101
|
-
{phoneError}
|
|
102
|
-
</p>
|
|
103
|
-
) : null}
|
|
104
|
-
{locked ? (
|
|
105
|
-
<p className={hintClassName}>
|
|
106
|
-
Tap <strong>Edit</strong> to change this number.
|
|
107
|
-
</p>
|
|
108
|
-
) : !phoneVerified && phoneReady ? (
|
|
109
|
-
<p className={hintClassName}>
|
|
110
|
-
Tap <strong>Verify phone</strong> to receive an OTP on this number.
|
|
111
|
-
</p>
|
|
112
|
-
) : editing ? (
|
|
113
|
-
<p className={hintClassName}>
|
|
114
|
-
Update the number, then save and verify it again.
|
|
115
|
-
</p>
|
|
116
|
-
) : null}
|
|
117
|
-
</div>
|
|
118
|
-
)
|
|
119
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react"
|
|
4
|
+
import { SplitPhoneInput } from "@pradip1995/commerce-core/components/split-phone-input"
|
|
5
|
+
|
|
6
|
+
export type ProfilePhoneFieldProps = {
|
|
7
|
+
phone: string
|
|
8
|
+
onPhoneChange: (value: string) => void
|
|
9
|
+
phoneVerified: boolean
|
|
10
|
+
phoneReady: boolean
|
|
11
|
+
phoneError: string | null
|
|
12
|
+
verifyPending: boolean
|
|
13
|
+
onVerify: () => void
|
|
14
|
+
label?: string
|
|
15
|
+
wrapperClassName?: string
|
|
16
|
+
labelClassName?: string
|
|
17
|
+
rowClassName?: string
|
|
18
|
+
verifyButtonClassName?: string
|
|
19
|
+
editButtonClassName?: string
|
|
20
|
+
verifiedClassName?: string
|
|
21
|
+
errorClassName?: string
|
|
22
|
+
hintClassName?: string
|
|
23
|
+
phoneInputClassName?: string
|
|
24
|
+
numberInputId?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default function ProfilePhoneField({
|
|
28
|
+
phone,
|
|
29
|
+
onPhoneChange,
|
|
30
|
+
phoneVerified,
|
|
31
|
+
phoneReady,
|
|
32
|
+
phoneError,
|
|
33
|
+
verifyPending,
|
|
34
|
+
onVerify,
|
|
35
|
+
label = "Phone",
|
|
36
|
+
wrapperClassName = "",
|
|
37
|
+
labelClassName = "text-xs font-semibold uppercase tracking-wider text-muted mb-1.5 block",
|
|
38
|
+
rowClassName = "flex flex-wrap items-center gap-3",
|
|
39
|
+
verifyButtonClassName = "",
|
|
40
|
+
editButtonClassName = "",
|
|
41
|
+
verifiedClassName = "text-xs text-green-600 font-medium",
|
|
42
|
+
errorClassName = "text-sm text-red-600 mt-1.5",
|
|
43
|
+
hintClassName = "text-xs text-muted mt-1.5",
|
|
44
|
+
phoneInputClassName = "",
|
|
45
|
+
numberInputId = "account-profile-phone",
|
|
46
|
+
}: ProfilePhoneFieldProps) {
|
|
47
|
+
const [editing, setEditing] = useState(false)
|
|
48
|
+
const locked = phoneVerified && !editing
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (phoneVerified) setEditing(false)
|
|
52
|
+
}, [phoneVerified])
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div className={wrapperClassName}>
|
|
56
|
+
<span className={labelClassName}>{label}</span>
|
|
57
|
+
<div className={rowClassName}>
|
|
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
|
+
>
|
|
65
|
+
<SplitPhoneInput
|
|
66
|
+
value={phone}
|
|
67
|
+
onChange={onPhoneChange}
|
|
68
|
+
label="Mobile number"
|
|
69
|
+
numberInputId={numberInputId}
|
|
70
|
+
data-testid="account-profile-phone"
|
|
71
|
+
/>
|
|
72
|
+
</div>
|
|
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 ? (
|
|
86
|
+
<span className={verifiedClassName}>Verified</span>
|
|
87
|
+
) : phoneReady ? (
|
|
88
|
+
<button
|
|
89
|
+
type="button"
|
|
90
|
+
onClick={onVerify}
|
|
91
|
+
disabled={verifyPending}
|
|
92
|
+
className={verifyButtonClassName}
|
|
93
|
+
data-testid="account-profile-verify-phone"
|
|
94
|
+
>
|
|
95
|
+
{verifyPending ? "Sending…" : "Verify phone"}
|
|
96
|
+
</button>
|
|
97
|
+
) : null}
|
|
98
|
+
</div>
|
|
99
|
+
{phoneError ? (
|
|
100
|
+
<p className={errorClassName} role="alert">
|
|
101
|
+
{phoneError}
|
|
102
|
+
</p>
|
|
103
|
+
) : null}
|
|
104
|
+
{locked ? (
|
|
105
|
+
<p className={hintClassName}>
|
|
106
|
+
Tap <strong>Edit</strong> to change this number.
|
|
107
|
+
</p>
|
|
108
|
+
) : !phoneVerified && phoneReady ? (
|
|
109
|
+
<p className={hintClassName}>
|
|
110
|
+
Tap <strong>Verify phone</strong> to receive an OTP on this number.
|
|
111
|
+
</p>
|
|
112
|
+
) : editing ? (
|
|
113
|
+
<p className={hintClassName}>
|
|
114
|
+
Update the number, then save and verify it again.
|
|
115
|
+
</p>
|
|
116
|
+
) : null}
|
|
117
|
+
</div>
|
|
118
|
+
)
|
|
119
|
+
}
|