@pradip1995/segment-login-template 0.5.26 → 0.5.28

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.
Files changed (43) hide show
  1. package/package.json +58 -54
  2. package/src/account-addresses.tsx +307 -287
  3. package/src/account-guest-orders.tsx +98 -98
  4. package/src/account-orders.tsx +260 -260
  5. package/src/account-overview.tsx +133 -133
  6. package/src/account-payment-methods.tsx +328 -328
  7. package/src/account-profile-logic.ts +282 -282
  8. package/src/account-profile.tsx +111 -111
  9. package/src/account-theme.ts +91 -91
  10. package/src/account-utils.ts +20 -20
  11. package/src/address-actions.ts +74 -0
  12. package/src/auth-server.ts +442 -442
  13. package/src/card-expiry.test.ts +71 -0
  14. package/src/card-expiry.ts +29 -0
  15. package/src/commerce-auth-otp-modal.css +125 -125
  16. package/src/commerce-auth-otp-modal.tsx +121 -121
  17. package/src/default-address.test.ts +143 -0
  18. package/src/default-address.ts +51 -0
  19. package/src/forgot-password-form.tsx +109 -109
  20. package/src/google-auth-section.tsx +22 -22
  21. package/src/google-sign-in-section.tsx +67 -67
  22. package/src/guest-order-modal.tsx +215 -215
  23. package/src/index.ts +7 -7
  24. package/src/is-next-redirect.ts +60 -60
  25. package/src/login-brand-panel.tsx +159 -158
  26. package/src/login-form.tsx +469 -469
  27. package/src/manifest.ts +11 -11
  28. package/src/order-history-status.test.ts +224 -224
  29. package/src/order-history-status.ts +244 -244
  30. package/src/otp-component.ts +14 -14
  31. package/src/otp-input.tsx +46 -46
  32. package/src/otp-unified-form.tsx +333 -333
  33. package/src/otp-verification-modal.tsx +112 -112
  34. package/src/payment-methods-actions.ts +243 -243
  35. package/src/profile-email-field.tsx +116 -116
  36. package/src/profile-email.test.ts +182 -182
  37. package/src/profile-email.ts +54 -54
  38. package/src/profile-phone-field.tsx +119 -119
  39. package/src/register-form.tsx +339 -339
  40. package/src/reorder-checkout-address.ts +103 -101
  41. package/src/reset-password-form.tsx +103 -103
  42. package/src/reset-password-page.tsx +12 -12
  43. package/src/segment.tsx +272 -272
@@ -1,116 +1,116 @@
1
- "use client"
2
-
3
- import { useEffect, useState } from "react"
4
- import { isEmailFieldLocked, isValidEmail, profileEmailAction } from "./profile-email"
5
-
6
- export type ProfileEmailFieldProps = {
7
- email: string
8
- onEmailChange: (value: string) => void
9
- emailVerified: boolean
10
- emailError: string | null
11
- verifyPending: boolean
12
- onVerify: () => void
13
- label?: string
14
- wrapperClassName?: string
15
- labelClassName?: string
16
- rowClassName?: string
17
- inputClassName?: string
18
- verifyButtonClassName?: string
19
- editButtonClassName?: string
20
- verifiedClassName?: string
21
- errorClassName?: string
22
- hintClassName?: string
23
- }
24
-
25
- export default function ProfileEmailField({
26
- email,
27
- onEmailChange,
28
- emailVerified,
29
- emailError,
30
- verifyPending,
31
- onVerify,
32
- label = "Email",
33
- wrapperClassName = "",
34
- labelClassName = "block text-xs font-semibold uppercase tracking-wider text-muted mb-1.5",
35
- rowClassName = "flex flex-wrap items-center gap-3",
36
- inputClassName = "flex-1 min-w-[200px] border border-cart-border rounded-none px-3 py-2.5 text-sm bg-surface text-heading focus:outline-none focus:border-brand-accent",
37
- verifyButtonClassName = "",
38
- editButtonClassName = "",
39
- verifiedClassName = "text-xs text-green-600 font-medium",
40
- errorClassName = "text-sm text-red-600 mt-1.5",
41
- hintClassName = "text-xs text-muted mt-1.5",
42
- }: ProfileEmailFieldProps) {
43
- const [editing, setEditing] = useState(false)
44
- const locked = isEmailFieldLocked({ emailVerified, editing })
45
- const emailReady = isValidEmail(email)
46
- const action = profileEmailAction({ emailVerified, editing, emailReady })
47
-
48
- useEffect(() => {
49
- if (emailVerified) setEditing(false)
50
- }, [emailVerified])
51
-
52
- return (
53
- <div className={wrapperClassName}>
54
- <label className={labelClassName} htmlFor="account-profile-email">
55
- {label}
56
- </label>
57
- <div className={rowClassName}>
58
- <input
59
- id="account-profile-email"
60
- name="email"
61
- type="email"
62
- value={email}
63
- onChange={(event) => onEmailChange(event.target.value)}
64
- readOnly={locked}
65
- placeholder="Enter your email"
66
- autoComplete="email"
67
- className={`${inputClassName}${locked ? " bg-surface-muted text-muted" : ""}`}
68
- data-testid="account-profile-email"
69
- />
70
- {action === "edit" ? (
71
- <>
72
- <span className={verifiedClassName}>Verified</span>
73
- <button
74
- type="button"
75
- onClick={() => setEditing(true)}
76
- className={editButtonClassName || verifyButtonClassName}
77
- data-testid="account-profile-edit-email"
78
- >
79
- Edit
80
- </button>
81
- </>
82
- ) : null}
83
- {action === "verified" ? <span className={verifiedClassName}>Verified</span> : null}
84
- {action === "verify" ? (
85
- <button
86
- type="button"
87
- onClick={onVerify}
88
- disabled={verifyPending}
89
- className={verifyButtonClassName}
90
- data-testid="account-profile-verify-email"
91
- >
92
- {verifyPending ? "Sending…" : "Verify email"}
93
- </button>
94
- ) : null}
95
- </div>
96
- {emailError ? (
97
- <p className={errorClassName} role="alert">
98
- {emailError}
99
- </p>
100
- ) : null}
101
- {action === "edit" ? (
102
- <p className={hintClassName}>
103
- Tap <strong>Edit</strong> to change this email.
104
- </p>
105
- ) : action === "verify" ? (
106
- <p className={hintClassName}>
107
- Tap <strong>Verify email</strong> to receive an OTP at this address.
108
- </p>
109
- ) : editing ? (
110
- <p className={hintClassName}>
111
- Update the email, then verify it again.
112
- </p>
113
- ) : null}
114
- </div>
115
- )
116
- }
1
+ "use client"
2
+
3
+ import { useEffect, useState } from "react"
4
+ import { isEmailFieldLocked, isValidEmail, profileEmailAction } from "./profile-email"
5
+
6
+ export type ProfileEmailFieldProps = {
7
+ email: string
8
+ onEmailChange: (value: string) => void
9
+ emailVerified: boolean
10
+ emailError: string | null
11
+ verifyPending: boolean
12
+ onVerify: () => void
13
+ label?: string
14
+ wrapperClassName?: string
15
+ labelClassName?: string
16
+ rowClassName?: string
17
+ inputClassName?: string
18
+ verifyButtonClassName?: string
19
+ editButtonClassName?: string
20
+ verifiedClassName?: string
21
+ errorClassName?: string
22
+ hintClassName?: string
23
+ }
24
+
25
+ export default function ProfileEmailField({
26
+ email,
27
+ onEmailChange,
28
+ emailVerified,
29
+ emailError,
30
+ verifyPending,
31
+ onVerify,
32
+ label = "Email",
33
+ wrapperClassName = "",
34
+ labelClassName = "block text-xs font-semibold uppercase tracking-wider text-muted mb-1.5",
35
+ rowClassName = "flex flex-wrap items-center gap-3",
36
+ inputClassName = "flex-1 min-w-[200px] border border-cart-border rounded-none px-3 py-2.5 text-sm bg-surface text-heading focus:outline-none focus:border-brand-accent",
37
+ verifyButtonClassName = "",
38
+ editButtonClassName = "",
39
+ verifiedClassName = "text-xs text-green-600 font-medium",
40
+ errorClassName = "text-sm text-red-600 mt-1.5",
41
+ hintClassName = "text-xs text-muted mt-1.5",
42
+ }: ProfileEmailFieldProps) {
43
+ const [editing, setEditing] = useState(false)
44
+ const locked = isEmailFieldLocked({ emailVerified, editing })
45
+ const emailReady = isValidEmail(email)
46
+ const action = profileEmailAction({ emailVerified, editing, emailReady })
47
+
48
+ useEffect(() => {
49
+ if (emailVerified) setEditing(false)
50
+ }, [emailVerified])
51
+
52
+ return (
53
+ <div className={wrapperClassName}>
54
+ <label className={labelClassName} htmlFor="account-profile-email">
55
+ {label}
56
+ </label>
57
+ <div className={rowClassName}>
58
+ <input
59
+ id="account-profile-email"
60
+ name="email"
61
+ type="email"
62
+ value={email}
63
+ onChange={(event) => onEmailChange(event.target.value)}
64
+ readOnly={locked}
65
+ placeholder="Enter your email"
66
+ autoComplete="email"
67
+ className={`${inputClassName}${locked ? " bg-surface-muted text-muted" : ""}`}
68
+ data-testid="account-profile-email"
69
+ />
70
+ {action === "edit" ? (
71
+ <>
72
+ <span className={verifiedClassName}>Verified</span>
73
+ <button
74
+ type="button"
75
+ onClick={() => setEditing(true)}
76
+ className={editButtonClassName || verifyButtonClassName}
77
+ data-testid="account-profile-edit-email"
78
+ >
79
+ Edit
80
+ </button>
81
+ </>
82
+ ) : null}
83
+ {action === "verified" ? <span className={verifiedClassName}>Verified</span> : null}
84
+ {action === "verify" ? (
85
+ <button
86
+ type="button"
87
+ onClick={onVerify}
88
+ disabled={verifyPending}
89
+ className={verifyButtonClassName}
90
+ data-testid="account-profile-verify-email"
91
+ >
92
+ {verifyPending ? "Sending…" : "Verify email"}
93
+ </button>
94
+ ) : null}
95
+ </div>
96
+ {emailError ? (
97
+ <p className={errorClassName} role="alert">
98
+ {emailError}
99
+ </p>
100
+ ) : null}
101
+ {action === "edit" ? (
102
+ <p className={hintClassName}>
103
+ Tap <strong>Edit</strong> to change this email.
104
+ </p>
105
+ ) : action === "verify" ? (
106
+ <p className={hintClassName}>
107
+ Tap <strong>Verify email</strong> to receive an OTP at this address.
108
+ </p>
109
+ ) : editing ? (
110
+ <p className={hintClassName}>
111
+ Update the email, then verify it again.
112
+ </p>
113
+ ) : null}
114
+ </div>
115
+ )
116
+ }
@@ -1,182 +1,182 @@
1
- import { describe, it } from "node:test"
2
- import assert from "node:assert/strict"
3
- import {
4
- EMAIL_OTP_ERRORS,
5
- isEmailFieldLocked,
6
- isValidEmail,
7
- normalizeEmail,
8
- profileEmailAction,
9
- resolveEmailOtpFlow,
10
- type ProfileEmailAction,
11
- type ResolveEmailOtpFlowResult,
12
- } from "./profile-email.ts"
13
-
14
- const NORMALIZE_CASES: { name: string; value: string | null | undefined; want: string }[] = [
15
- { name: "trims and lowercases a typed email", value: " Jay@Empire.COM ", want: "jay@empire.com" },
16
- { name: "empty string stays empty", value: "", want: "" },
17
- { name: "whitespace-only becomes empty", value: " ", want: "" },
18
- { name: "null becomes empty", value: null, want: "" },
19
- { name: "undefined becomes empty", value: undefined, want: "" },
20
- ]
21
-
22
- const VALID_CASES: { name: string; value: string | null | undefined; want: boolean }[] = [
23
- { name: "accepts a normal email", value: "jay@empire.com", want: true },
24
- { name: "accepts mixed-case with spaces", value: " Jay@Empire.COM ", want: true },
25
- { name: "rejects empty", value: "", want: false },
26
- { name: "rejects missing at-sign", value: "jayempire.com", want: false },
27
- { name: "rejects missing domain", value: "jay@", want: false },
28
- { name: "rejects phone-only customer empty email", value: null, want: false },
29
- ]
30
-
31
- const FLOW_CASES: {
32
- name: string
33
- currentEmail: string | null | undefined
34
- draftEmail: string
35
- want: ResolveEmailOtpFlowResult
36
- }[] = [
37
- {
38
- name: "phone-only user adding an email uses contact change",
39
- currentEmail: "",
40
- draftEmail: "jay@empire.com",
41
- want: { ok: true, flow: "change_contact", email: "jay@empire.com" },
42
- },
43
- {
44
- name: "missing current email uses contact change",
45
- currentEmail: null,
46
- draftEmail: "jay@empire.com",
47
- want: { ok: true, flow: "change_contact", email: "jay@empire.com" },
48
- },
49
- {
50
- name: "same unverified email verifies the existing address",
51
- currentEmail: "jay@empire.com",
52
- draftEmail: "Jay@Empire.com",
53
- want: { ok: true, flow: "verify_existing", email: "jay@empire.com" },
54
- },
55
- {
56
- name: "changing to a different email uses contact change",
57
- currentEmail: "old@empire.com",
58
- draftEmail: "new@empire.com",
59
- want: { ok: true, flow: "change_contact", email: "new@empire.com" },
60
- },
61
- {
62
- name: "empty draft is empty",
63
- currentEmail: "",
64
- draftEmail: " ",
65
- want: { ok: false, reason: "empty" },
66
- },
67
- {
68
- name: "malformed draft is invalid",
69
- currentEmail: "",
70
- draftEmail: "not-an-email",
71
- want: { ok: false, reason: "invalid" },
72
- },
73
- ]
74
-
75
- const LOCK_CASES: { name: string; emailVerified: boolean; editing: boolean; want: boolean }[] = [
76
- { name: "verified and not editing is locked", emailVerified: true, editing: false, want: true },
77
- { name: "verified while editing is unlocked so the user can type", emailVerified: true, editing: true, want: false },
78
- { name: "unverified empty email is never locked", emailVerified: false, editing: false, want: false },
79
- { name: "unverified stays unlocked even if editing flag is set", emailVerified: false, editing: true, want: false },
80
- ]
81
-
82
- const ACTION_CASES: {
83
- name: string
84
- emailVerified: boolean
85
- editing: boolean
86
- emailReady: boolean
87
- want: ProfileEmailAction
88
- }[] = [
89
- {
90
- name: "phone-only empty field shows no verify button yet",
91
- emailVerified: false,
92
- editing: false,
93
- emailReady: false,
94
- want: "none",
95
- },
96
- {
97
- name: "typed valid unverified email shows verify",
98
- emailVerified: false,
99
- editing: false,
100
- emailReady: true,
101
- want: "verify",
102
- },
103
- {
104
- name: "verified email shows edit",
105
- emailVerified: true,
106
- editing: false,
107
- emailReady: true,
108
- want: "edit",
109
- },
110
- {
111
- name: "editing a verified email keeps the verified label until the value changes",
112
- emailVerified: true,
113
- editing: true,
114
- emailReady: true,
115
- want: "verified",
116
- },
117
- ]
118
-
119
- describe("normalizeEmail", () => {
120
- for (const tc of NORMALIZE_CASES) {
121
- it(tc.name, () => {
122
- assert.equal(normalizeEmail(tc.value), tc.want)
123
- })
124
- }
125
- })
126
-
127
- describe("isValidEmail", () => {
128
- for (const tc of VALID_CASES) {
129
- it(tc.name, () => {
130
- assert.equal(isValidEmail(tc.value), tc.want)
131
- })
132
- }
133
- })
134
-
135
- describe("resolveEmailOtpFlow", () => {
136
- for (const tc of FLOW_CASES) {
137
- it(tc.name, () => {
138
- assert.deepEqual(
139
- resolveEmailOtpFlow({ currentEmail: tc.currentEmail, draftEmail: tc.draftEmail }),
140
- tc.want
141
- )
142
- })
143
- }
144
- })
145
-
146
- describe("isEmailFieldLocked", () => {
147
- for (const tc of LOCK_CASES) {
148
- it(tc.name, () => {
149
- assert.equal(
150
- isEmailFieldLocked({ emailVerified: tc.emailVerified, editing: tc.editing }),
151
- tc.want
152
- )
153
- })
154
- }
155
- })
156
-
157
- describe("profileEmailAction", () => {
158
- for (const tc of ACTION_CASES) {
159
- it(tc.name, () => {
160
- assert.equal(
161
- profileEmailAction({
162
- emailVerified: tc.emailVerified,
163
- editing: tc.editing,
164
- emailReady: tc.emailReady,
165
- }),
166
- tc.want
167
- )
168
- })
169
- }
170
- })
171
-
172
- describe("EMAIL_OTP_ERRORS", () => {
173
- const CASES = [
174
- { name: "empty copy", reason: "empty" as const, want: "Please enter an email address before verifying." },
175
- { name: "invalid copy", reason: "invalid" as const, want: "Please enter a valid email address." },
176
- ]
177
- for (const tc of CASES) {
178
- it(tc.name, () => {
179
- assert.equal(EMAIL_OTP_ERRORS[tc.reason], tc.want)
180
- })
181
- }
182
- })
1
+ import { describe, it } from "node:test"
2
+ import assert from "node:assert/strict"
3
+ import {
4
+ EMAIL_OTP_ERRORS,
5
+ isEmailFieldLocked,
6
+ isValidEmail,
7
+ normalizeEmail,
8
+ profileEmailAction,
9
+ resolveEmailOtpFlow,
10
+ type ProfileEmailAction,
11
+ type ResolveEmailOtpFlowResult,
12
+ } from "./profile-email.ts"
13
+
14
+ const NORMALIZE_CASES: { name: string; value: string | null | undefined; want: string }[] = [
15
+ { name: "trims and lowercases a typed email", value: " Jay@Empire.COM ", want: "jay@empire.com" },
16
+ { name: "empty string stays empty", value: "", want: "" },
17
+ { name: "whitespace-only becomes empty", value: " ", want: "" },
18
+ { name: "null becomes empty", value: null, want: "" },
19
+ { name: "undefined becomes empty", value: undefined, want: "" },
20
+ ]
21
+
22
+ const VALID_CASES: { name: string; value: string | null | undefined; want: boolean }[] = [
23
+ { name: "accepts a normal email", value: "jay@empire.com", want: true },
24
+ { name: "accepts mixed-case with spaces", value: " Jay@Empire.COM ", want: true },
25
+ { name: "rejects empty", value: "", want: false },
26
+ { name: "rejects missing at-sign", value: "jayempire.com", want: false },
27
+ { name: "rejects missing domain", value: "jay@", want: false },
28
+ { name: "rejects phone-only customer empty email", value: null, want: false },
29
+ ]
30
+
31
+ const FLOW_CASES: {
32
+ name: string
33
+ currentEmail: string | null | undefined
34
+ draftEmail: string
35
+ want: ResolveEmailOtpFlowResult
36
+ }[] = [
37
+ {
38
+ name: "phone-only user adding an email uses contact change",
39
+ currentEmail: "",
40
+ draftEmail: "jay@empire.com",
41
+ want: { ok: true, flow: "change_contact", email: "jay@empire.com" },
42
+ },
43
+ {
44
+ name: "missing current email uses contact change",
45
+ currentEmail: null,
46
+ draftEmail: "jay@empire.com",
47
+ want: { ok: true, flow: "change_contact", email: "jay@empire.com" },
48
+ },
49
+ {
50
+ name: "same unverified email verifies the existing address",
51
+ currentEmail: "jay@empire.com",
52
+ draftEmail: "Jay@Empire.com",
53
+ want: { ok: true, flow: "verify_existing", email: "jay@empire.com" },
54
+ },
55
+ {
56
+ name: "changing to a different email uses contact change",
57
+ currentEmail: "old@empire.com",
58
+ draftEmail: "new@empire.com",
59
+ want: { ok: true, flow: "change_contact", email: "new@empire.com" },
60
+ },
61
+ {
62
+ name: "empty draft is empty",
63
+ currentEmail: "",
64
+ draftEmail: " ",
65
+ want: { ok: false, reason: "empty" },
66
+ },
67
+ {
68
+ name: "malformed draft is invalid",
69
+ currentEmail: "",
70
+ draftEmail: "not-an-email",
71
+ want: { ok: false, reason: "invalid" },
72
+ },
73
+ ]
74
+
75
+ const LOCK_CASES: { name: string; emailVerified: boolean; editing: boolean; want: boolean }[] = [
76
+ { name: "verified and not editing is locked", emailVerified: true, editing: false, want: true },
77
+ { name: "verified while editing is unlocked so the user can type", emailVerified: true, editing: true, want: false },
78
+ { name: "unverified empty email is never locked", emailVerified: false, editing: false, want: false },
79
+ { name: "unverified stays unlocked even if editing flag is set", emailVerified: false, editing: true, want: false },
80
+ ]
81
+
82
+ const ACTION_CASES: {
83
+ name: string
84
+ emailVerified: boolean
85
+ editing: boolean
86
+ emailReady: boolean
87
+ want: ProfileEmailAction
88
+ }[] = [
89
+ {
90
+ name: "phone-only empty field shows no verify button yet",
91
+ emailVerified: false,
92
+ editing: false,
93
+ emailReady: false,
94
+ want: "none",
95
+ },
96
+ {
97
+ name: "typed valid unverified email shows verify",
98
+ emailVerified: false,
99
+ editing: false,
100
+ emailReady: true,
101
+ want: "verify",
102
+ },
103
+ {
104
+ name: "verified email shows edit",
105
+ emailVerified: true,
106
+ editing: false,
107
+ emailReady: true,
108
+ want: "edit",
109
+ },
110
+ {
111
+ name: "editing a verified email keeps the verified label until the value changes",
112
+ emailVerified: true,
113
+ editing: true,
114
+ emailReady: true,
115
+ want: "verified",
116
+ },
117
+ ]
118
+
119
+ describe("normalizeEmail", () => {
120
+ for (const tc of NORMALIZE_CASES) {
121
+ it(tc.name, () => {
122
+ assert.equal(normalizeEmail(tc.value), tc.want)
123
+ })
124
+ }
125
+ })
126
+
127
+ describe("isValidEmail", () => {
128
+ for (const tc of VALID_CASES) {
129
+ it(tc.name, () => {
130
+ assert.equal(isValidEmail(tc.value), tc.want)
131
+ })
132
+ }
133
+ })
134
+
135
+ describe("resolveEmailOtpFlow", () => {
136
+ for (const tc of FLOW_CASES) {
137
+ it(tc.name, () => {
138
+ assert.deepEqual(
139
+ resolveEmailOtpFlow({ currentEmail: tc.currentEmail, draftEmail: tc.draftEmail }),
140
+ tc.want
141
+ )
142
+ })
143
+ }
144
+ })
145
+
146
+ describe("isEmailFieldLocked", () => {
147
+ for (const tc of LOCK_CASES) {
148
+ it(tc.name, () => {
149
+ assert.equal(
150
+ isEmailFieldLocked({ emailVerified: tc.emailVerified, editing: tc.editing }),
151
+ tc.want
152
+ )
153
+ })
154
+ }
155
+ })
156
+
157
+ describe("profileEmailAction", () => {
158
+ for (const tc of ACTION_CASES) {
159
+ it(tc.name, () => {
160
+ assert.equal(
161
+ profileEmailAction({
162
+ emailVerified: tc.emailVerified,
163
+ editing: tc.editing,
164
+ emailReady: tc.emailReady,
165
+ }),
166
+ tc.want
167
+ )
168
+ })
169
+ }
170
+ })
171
+
172
+ describe("EMAIL_OTP_ERRORS", () => {
173
+ const CASES = [
174
+ { name: "empty copy", reason: "empty" as const, want: "Please enter an email address before verifying." },
175
+ { name: "invalid copy", reason: "invalid" as const, want: "Please enter a valid email address." },
176
+ ]
177
+ for (const tc of CASES) {
178
+ it(tc.name, () => {
179
+ assert.equal(EMAIL_OTP_ERRORS[tc.reason], tc.want)
180
+ })
181
+ }
182
+ })