@sikka/hawa 0.27.12-next → 0.27.14-next
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/dist/blocks/auth/index.d.mts +2 -2
- package/dist/blocks/auth/index.d.ts +2 -2
- package/dist/blocks/auth/index.js +64 -36
- package/dist/blocks/auth/index.mjs +57 -31
- package/dist/blocks/index.d.mts +2 -2
- package/dist/blocks/index.d.ts +2 -2
- package/dist/blocks/index.js +64 -36
- package/dist/blocks/index.mjs +57 -31
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +57 -31
- package/dist/index.mjs +57 -31
- package/package.json +11 -11
@@ -18,7 +18,7 @@ type LoginFormTypes = {
|
|
18
18
|
/** Login identifier type user will use to log in. */
|
19
19
|
loginType?: "email" | "username" | "phone" | "link";
|
20
20
|
/** If true, the reset password option is hidden. */
|
21
|
-
|
21
|
+
withResetPassword?: boolean;
|
22
22
|
/** If true, the register option is hidden. */
|
23
23
|
allowRegister?: boolean;
|
24
24
|
/** If true, a loading spinner is displayed within the main form submit button. */
|
@@ -36,7 +36,7 @@ type LoginFormTypes = {
|
|
36
36
|
/** If true, Twitter login option is displayed. */
|
37
37
|
viaTwitter?: boolean;
|
38
38
|
/** Function to handle form submission. */
|
39
|
-
onLogin
|
39
|
+
onLogin: (e: any) => void;
|
40
40
|
/** Function to route user to the register page. */
|
41
41
|
onRouteToRegister?: () => void;
|
42
42
|
/** Function to handle forgotten password case. */
|
@@ -18,7 +18,7 @@ type LoginFormTypes = {
|
|
18
18
|
/** Login identifier type user will use to log in. */
|
19
19
|
loginType?: "email" | "username" | "phone" | "link";
|
20
20
|
/** If true, the reset password option is hidden. */
|
21
|
-
|
21
|
+
withResetPassword?: boolean;
|
22
22
|
/** If true, the register option is hidden. */
|
23
23
|
allowRegister?: boolean;
|
24
24
|
/** If true, a loading spinner is displayed within the main form submit button. */
|
@@ -36,7 +36,7 @@ type LoginFormTypes = {
|
|
36
36
|
/** If true, Twitter login option is displayed. */
|
37
37
|
viaTwitter?: boolean;
|
38
38
|
/** Function to handle form submission. */
|
39
|
-
onLogin
|
39
|
+
onLogin: (e: any) => void;
|
40
40
|
/** Function to route user to the register page. */
|
41
41
|
onRouteToRegister?: () => void;
|
42
42
|
/** Function to handle forgotten password case. */
|
@@ -45,11 +45,6 @@ module.exports = __toCommonJS(auth_exports);
|
|
45
45
|
var import_react13 = __toESM(require("react"));
|
46
46
|
var import_react_hook_form = require("react-hook-form");
|
47
47
|
var import_zod = require("@hookform/resolvers/zod");
|
48
|
-
var import_libphonenumber_js = require("libphonenumber-js");
|
49
|
-
var z = __toESM(require("zod"));
|
50
|
-
|
51
|
-
// elements/alert/Alert.tsx
|
52
|
-
var import_react2 = __toESM(require("react"));
|
53
48
|
|
54
49
|
// util/index.ts
|
55
50
|
var import_clsx = require("clsx");
|
@@ -58,6 +53,13 @@ function cn(...inputs) {
|
|
58
53
|
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
59
54
|
}
|
60
55
|
|
56
|
+
// blocks/auth/LoginForm.tsx
|
57
|
+
var import_libphonenumber_js = require("libphonenumber-js");
|
58
|
+
var z = __toESM(require("zod"));
|
59
|
+
|
60
|
+
// elements/alert/Alert.tsx
|
61
|
+
var import_react2 = __toESM(require("react"));
|
62
|
+
|
61
63
|
// elements/button/Button.tsx
|
62
64
|
var React2 = __toESM(require("react"));
|
63
65
|
var import_class_variance_authority = require("class-variance-authority");
|
@@ -3082,7 +3084,7 @@ var AuthButtons = (props) => {
|
|
3082
3084
|
|
3083
3085
|
// blocks/auth/LoginForm.tsx
|
3084
3086
|
var LoginForm = ({
|
3085
|
-
loginType,
|
3087
|
+
loginType = "email",
|
3086
3088
|
texts,
|
3087
3089
|
passwordLength = 8,
|
3088
3090
|
...props
|
@@ -3101,33 +3103,45 @@ var LoginForm = ({
|
|
3101
3103
|
let formSchema;
|
3102
3104
|
if (loginType === "email") {
|
3103
3105
|
formSchema = z.object({
|
3104
|
-
email: z.string({ required_error: (_a = texts == null ? void 0 : texts.email) == null ? void 0 : _a.required }).min(1, { message: (_b = texts == null ? void 0 : texts.email) == null ? void 0 : _b.required }).email({ message: (_c = texts == null ? void 0 : texts.email) == null ? void 0 : _c.invalid }),
|
3105
|
-
password: z.string({
|
3106
|
+
email: z.string({ required_error: ((_a = texts == null ? void 0 : texts.email) == null ? void 0 : _a.required) || "Email Required" }).min(1, { message: ((_b = texts == null ? void 0 : texts.email) == null ? void 0 : _b.required) || "Email Required" }).email({ message: ((_c = texts == null ? void 0 : texts.email) == null ? void 0 : _c.invalid) || "Email Invalid" }),
|
3107
|
+
password: z.string({
|
3108
|
+
required_error: ((_d = texts == null ? void 0 : texts.password) == null ? void 0 : _d.required) || "Password Required"
|
3109
|
+
}).min(1, { message: ((_e = texts == null ? void 0 : texts.password) == null ? void 0 : _e.required) || "Password Required" }).min(passwordLength, {
|
3110
|
+
message: ((_f = texts == null ? void 0 : texts.password) == null ? void 0 : _f.tooShort) || "Password too short"
|
3111
|
+
})
|
3106
3112
|
});
|
3107
3113
|
} else if (loginType === "username") {
|
3108
3114
|
formSchema = z.object({
|
3109
|
-
username: z.string({
|
3115
|
+
username: z.string({
|
3116
|
+
required_error: ((_g = texts == null ? void 0 : texts.username) == null ? void 0 : _g.required) || "Username Required"
|
3117
|
+
}).min(2, { message: ((_h = texts == null ? void 0 : texts.username) == null ? void 0 : _h.tooShort) || "Username too short" }).refine(
|
3110
3118
|
(value) => {
|
3111
3119
|
const isValid = /^[a-zA-Z][a-zA-Z0-9_-]{2,14}$/.test(value);
|
3112
3120
|
return isValid;
|
3113
3121
|
},
|
3114
|
-
{ message: (_i = texts == null ? void 0 : texts.username) == null ? void 0 : _i.invalid }
|
3122
|
+
{ message: ((_i = texts == null ? void 0 : texts.username) == null ? void 0 : _i.invalid) || "Username Invalid" }
|
3115
3123
|
),
|
3116
|
-
password: z.string({
|
3124
|
+
password: z.string({
|
3125
|
+
required_error: ((_j = texts == null ? void 0 : texts.password) == null ? void 0 : _j.required) || "Password Required"
|
3126
|
+
}).min(1, { message: ((_k = texts == null ? void 0 : texts.password) == null ? void 0 : _k.required) || "Password Required" }).min(passwordLength, {
|
3127
|
+
message: ((_l = texts == null ? void 0 : texts.password) == null ? void 0 : _l.tooShort) || "Password too short"
|
3128
|
+
})
|
3117
3129
|
});
|
3118
3130
|
} else if (loginType === "phone") {
|
3119
3131
|
formSchema = z.object({
|
3120
|
-
phone: z.string({
|
3132
|
+
phone: z.string({
|
3133
|
+
required_error: ((_m = texts == null ? void 0 : texts.phone) == null ? void 0 : _m.required) || "Phone Number Required"
|
3134
|
+
}).refine(
|
3121
3135
|
(value) => {
|
3122
3136
|
let phoneNumber = (0, import_libphonenumber_js.parsePhoneNumber)(value);
|
3123
3137
|
return phoneNumber.isValid();
|
3124
3138
|
},
|
3125
|
-
{ message: (_n = texts == null ? void 0 : texts.phone) == null ? void 0 : _n.invalid }
|
3139
|
+
{ message: ((_n = texts == null ? void 0 : texts.phone) == null ? void 0 : _n.invalid) || "Phone Number Invalid" }
|
3126
3140
|
)
|
3127
3141
|
});
|
3128
3142
|
} else if (loginType === "link") {
|
3129
3143
|
formSchema = z.object({
|
3130
|
-
email: z.string({ required_error: (_o = texts == null ? void 0 : texts.email) == null ? void 0 : _o.required }).min(1, { message: (_p = texts == null ? void 0 : texts.email) == null ? void 0 : _p.required }).email({ message: (_q = texts == null ? void 0 : texts.email) == null ? void 0 : _q.invalid })
|
3144
|
+
email: z.string({ required_error: ((_o = texts == null ? void 0 : texts.email) == null ? void 0 : _o.required) || "Email Required" }).min(1, { message: ((_p = texts == null ? void 0 : texts.email) == null ? void 0 : _p.required) || "Email Required" }).email({ message: ((_q = texts == null ? void 0 : texts.email) == null ? void 0 : _q.invalid) || "Email Invalid" })
|
3131
3145
|
});
|
3132
3146
|
} else {
|
3133
3147
|
formSchema = z.object({});
|
@@ -3154,7 +3168,7 @@ var LoginForm = ({
|
|
3154
3168
|
dir: "ltr",
|
3155
3169
|
width: "full",
|
3156
3170
|
autoComplete: "email",
|
3157
|
-
label: (_a2 = texts == null ? void 0 : texts.email) == null ? void 0 : _a2.label,
|
3171
|
+
label: ((_a2 = texts == null ? void 0 : texts.email) == null ? void 0 : _a2.label) || "Email",
|
3158
3172
|
helperText: (_b2 = formState.errors.email) == null ? void 0 : _b2.message,
|
3159
3173
|
placeholder: ((_c2 = texts == null ? void 0 : texts.email) == null ? void 0 : _c2.placeholder) || "contact@sikka.io",
|
3160
3174
|
...field
|
@@ -3191,7 +3205,7 @@ var LoginForm = ({
|
|
3191
3205
|
);
|
3192
3206
|
}
|
3193
3207
|
}
|
3194
|
-
),
|
3208
|
+
), props.withResetPassword && /* @__PURE__ */ import_react13.default.createElement(
|
3195
3209
|
"div",
|
3196
3210
|
{
|
3197
3211
|
onClick: props.onForgotPassword,
|
@@ -3233,7 +3247,7 @@ var LoginForm = ({
|
|
3233
3247
|
width: "full",
|
3234
3248
|
autoComplete: "current-password",
|
3235
3249
|
type: passwordVisible ? "text" : "password",
|
3236
|
-
label: (_a2 = texts == null ? void 0 : texts.password) == null ? void 0 : _a2.label,
|
3250
|
+
label: ((_a2 = texts == null ? void 0 : texts.password) == null ? void 0 : _a2.label) || "Password",
|
3237
3251
|
endIcon: /* @__PURE__ */ import_react13.default.createElement(
|
3238
3252
|
"div",
|
3239
3253
|
{
|
@@ -3249,7 +3263,7 @@ var LoginForm = ({
|
|
3249
3263
|
);
|
3250
3264
|
}
|
3251
3265
|
}
|
3252
|
-
),
|
3266
|
+
), props.withResetPassword && /* @__PURE__ */ import_react13.default.createElement(
|
3253
3267
|
"div",
|
3254
3268
|
{
|
3255
3269
|
onClick: props.onForgotPassword,
|
@@ -3268,7 +3282,7 @@ var LoginForm = ({
|
|
3268
3282
|
return /* @__PURE__ */ import_react13.default.createElement(
|
3269
3283
|
PhoneInput,
|
3270
3284
|
{
|
3271
|
-
label: (_a2 = texts == null ? void 0 : texts.phone) == null ? void 0 : _a2.label,
|
3285
|
+
label: ((_a2 = texts == null ? void 0 : texts.phone) == null ? void 0 : _a2.label) || "Phone Number",
|
3272
3286
|
helperText: (_b2 = formState.errors.phone) == null ? void 0 : _b2.message,
|
3273
3287
|
preferredCountry: { label: "+966" },
|
3274
3288
|
handleChange: (e) => field.onChange((0, import_libphonenumber_js.parsePhoneNumber)(e).number)
|
@@ -3524,6 +3538,8 @@ var StopPropagationWrapper = (props) => {
|
|
3524
3538
|
var RegisterForm = ({
|
3525
3539
|
texts,
|
3526
3540
|
registerFields = ["email"],
|
3541
|
+
showTermsOption = false,
|
3542
|
+
showNewsletterOption = false,
|
3527
3543
|
...props
|
3528
3544
|
}) => {
|
3529
3545
|
var _a, _b, _c, _d, _e, _f;
|
@@ -3546,26 +3562,38 @@ var RegisterForm = ({
|
|
3546
3562
|
fieldSchemas["fullName"] = z2.string().optional();
|
3547
3563
|
break;
|
3548
3564
|
case "email":
|
3549
|
-
fieldSchemas["email"] = z2.string({
|
3565
|
+
fieldSchemas["email"] = z2.string({
|
3566
|
+
required_error: ((_a2 = texts == null ? void 0 : texts.email) == null ? void 0 : _a2.required) || "Email is required"
|
3567
|
+
}).email({ message: ((_b2 = texts == null ? void 0 : texts.email) == null ? void 0 : _b2.invalid) || "Invalid email" }).min(1, { message: ((_c2 = texts == null ? void 0 : texts.email) == null ? void 0 : _c2.required) || "Email is required" });
|
3550
3568
|
break;
|
3551
3569
|
case "username":
|
3552
|
-
fieldSchemas["username"] = z2.string({
|
3570
|
+
fieldSchemas["username"] = z2.string({
|
3571
|
+
required_error: ((_d2 = texts == null ? void 0 : texts.username) == null ? void 0 : _d2.required) || "Username is required"
|
3572
|
+
}).min(1, {
|
3573
|
+
message: ((_e2 = texts == null ? void 0 : texts.username) == null ? void 0 : _e2.required) || "Username is required"
|
3574
|
+
}).refine(
|
3553
3575
|
(value) => {
|
3554
3576
|
const isValid = /^[a-zA-Z][a-zA-Z0-9_-]{2,14}$/.test(value);
|
3555
3577
|
return isValid;
|
3556
3578
|
},
|
3557
|
-
{ message: (_f2 = texts == null ? void 0 : texts.username) == null ? void 0 : _f2.invalid }
|
3579
|
+
{ message: ((_f2 = texts == null ? void 0 : texts.username) == null ? void 0 : _f2.invalid) || "Invalid username" }
|
3558
3580
|
);
|
3559
3581
|
break;
|
3560
3582
|
}
|
3561
3583
|
});
|
3562
3584
|
const formSchema = z2.object({
|
3563
3585
|
...fieldSchemas,
|
3564
|
-
password: z2.string({
|
3565
|
-
|
3586
|
+
password: z2.string({
|
3587
|
+
required_error: ((_a = texts == null ? void 0 : texts.password) == null ? void 0 : _a.required) || "Password is required"
|
3588
|
+
}).min(5, {
|
3589
|
+
message: ((_b = texts == null ? void 0 : texts.password) == null ? void 0 : _b.tooShort) || "Password is too short"
|
3590
|
+
}).refine((value) => value !== "", {
|
3591
|
+
message: ((_c = texts == null ? void 0 : texts.password) == null ? void 0 : _c.required) || "Password is required"
|
3566
3592
|
}),
|
3567
|
-
confirm_password: z2.string({
|
3568
|
-
|
3593
|
+
confirm_password: z2.string({
|
3594
|
+
required_error: ((_d = texts == null ? void 0 : texts.confirm) == null ? void 0 : _d.required) || "Confirm password required"
|
3595
|
+
}).refine((value) => value !== "", {
|
3596
|
+
message: ((_e = texts == null ? void 0 : texts.password) == null ? void 0 : _e.required) || "Confirm password is required"
|
3569
3597
|
}),
|
3570
3598
|
refCode: z2.string().optional(),
|
3571
3599
|
reference: z2.string().optional(),
|
@@ -3614,7 +3642,7 @@ var RegisterForm = ({
|
|
3614
3642
|
Input,
|
3615
3643
|
{
|
3616
3644
|
width: "full",
|
3617
|
-
label: (_a2 = texts == null ? void 0 : texts.fullName) == null ? void 0 : _a2.label,
|
3645
|
+
label: ((_a2 = texts == null ? void 0 : texts.fullName) == null ? void 0 : _a2.label) || "Full Name",
|
3618
3646
|
placeholder: (_b2 = texts == null ? void 0 : texts.fullName) == null ? void 0 : _b2.placeholder,
|
3619
3647
|
helperText: (_c2 = formState.errors.fullName) == null ? void 0 : _c2.message,
|
3620
3648
|
...field
|
@@ -3642,7 +3670,7 @@ var RegisterForm = ({
|
|
3642
3670
|
},
|
3643
3671
|
width: "full",
|
3644
3672
|
autoComplete: "email",
|
3645
|
-
label: (_a2 = texts == null ? void 0 : texts.email) == null ? void 0 : _a2.label,
|
3673
|
+
label: ((_a2 = texts == null ? void 0 : texts.email) == null ? void 0 : _a2.label) || "Email",
|
3646
3674
|
helperText: (_b2 = formState.errors.email) == null ? void 0 : _b2.message,
|
3647
3675
|
placeholder: ((_c2 = texts == null ? void 0 : texts.email) == null ? void 0 : _c2.placeholder) || "Enter your email",
|
3648
3676
|
...field
|
@@ -3666,7 +3694,7 @@ var RegisterForm = ({
|
|
3666
3694
|
{
|
3667
3695
|
width: "full",
|
3668
3696
|
autoComplete: "username",
|
3669
|
-
label: (_a2 = texts == null ? void 0 : texts.username) == null ? void 0 : _a2.label,
|
3697
|
+
label: ((_a2 = texts == null ? void 0 : texts.username) == null ? void 0 : _a2.label) || "Username",
|
3670
3698
|
labelProps: {
|
3671
3699
|
...(_b2 = props.usernameOptions) == null ? void 0 : _b2.label
|
3672
3700
|
},
|
@@ -3702,7 +3730,7 @@ var RegisterForm = ({
|
|
3702
3730
|
" "
|
3703
3731
|
),
|
3704
3732
|
autoComplete: "new-password",
|
3705
|
-
label: (_a2 = texts == null ? void 0 : texts.password) == null ? void 0 : _a2.label,
|
3733
|
+
label: ((_a2 = texts == null ? void 0 : texts.password) == null ? void 0 : _a2.label) || "Password",
|
3706
3734
|
placeholder: (_b2 = texts == null ? void 0 : texts.password) == null ? void 0 : _b2.placeholder,
|
3707
3735
|
helperText: (_c2 = formState.errors.password) == null ? void 0 : _c2.message,
|
3708
3736
|
...field
|
@@ -3724,7 +3752,7 @@ var RegisterForm = ({
|
|
3724
3752
|
width: "full",
|
3725
3753
|
type: "password",
|
3726
3754
|
autoComplete: "new-password",
|
3727
|
-
label: (_a2 = texts == null ? void 0 : texts.confirm) == null ? void 0 : _a2.label,
|
3755
|
+
label: ((_a2 = texts == null ? void 0 : texts.confirm) == null ? void 0 : _a2.label) || "Confirm Password",
|
3728
3756
|
placeholder: (_b2 = texts == null ? void 0 : texts.confirm) == null ? void 0 : _b2.placeholder,
|
3729
3757
|
helperText: (_c2 = formState.errors.confirm_password) == null ? void 0 : _c2.message,
|
3730
3758
|
...field
|
@@ -3779,7 +3807,7 @@ var RegisterForm = ({
|
|
3779
3807
|
}
|
3780
3808
|
}
|
3781
3809
|
),
|
3782
|
-
/* @__PURE__ */ import_react15.default.createElement("div", { className: "hawa-flex hawa-flex-col hawa-gap-3" },
|
3810
|
+
/* @__PURE__ */ import_react15.default.createElement("div", { className: "hawa-flex hawa-flex-col hawa-gap-3" }, showTermsOption && /* @__PURE__ */ import_react15.default.createElement(
|
3783
3811
|
import_react_hook_form2.Controller,
|
3784
3812
|
{
|
3785
3813
|
control,
|
@@ -3792,19 +3820,19 @@ var RegisterForm = ({
|
|
3792
3820
|
id: "terms_accepted",
|
3793
3821
|
helperText: (_b2 = (_a2 = formState.errors.terms_accepted) == null ? void 0 : _a2.message) == null ? void 0 : _b2.toString(),
|
3794
3822
|
onCheckedChange: (e) => field.onChange(e),
|
3795
|
-
label: /* @__PURE__ */ import_react15.default.createElement("div", { className: "hawa-flex hawa-flex-row hawa-gap-0.5" }, /* @__PURE__ */ import_react15.default.createElement("span", null, texts == null ? void 0 : texts.iAcceptText), " ", /* @__PURE__ */ import_react15.default.createElement(StopPropagationWrapper, null, /* @__PURE__ */ import_react15.default.createElement(
|
3823
|
+
label: /* @__PURE__ */ import_react15.default.createElement("div", { className: "hawa-flex hawa-flex-row hawa-gap-0.5" }, /* @__PURE__ */ import_react15.default.createElement("span", null, (texts == null ? void 0 : texts.iAcceptText) || "I accept the "), " ", /* @__PURE__ */ import_react15.default.createElement(StopPropagationWrapper, null, /* @__PURE__ */ import_react15.default.createElement(
|
3796
3824
|
"a",
|
3797
3825
|
{
|
3798
3826
|
onClick: props.onRouteToTOS,
|
3799
3827
|
className: "clickable-link"
|
3800
3828
|
},
|
3801
|
-
texts == null ? void 0 : texts.termsText
|
3829
|
+
(texts == null ? void 0 : texts.termsText) || "Terms of Service"
|
3802
3830
|
)))
|
3803
3831
|
}
|
3804
3832
|
);
|
3805
3833
|
}
|
3806
3834
|
}
|
3807
|
-
),
|
3835
|
+
), showNewsletterOption && /* @__PURE__ */ import_react15.default.createElement(
|
3808
3836
|
import_react_hook_form2.Controller,
|
3809
3837
|
{
|
3810
3838
|
control,
|
@@ -3830,7 +3858,7 @@ var RegisterForm = ({
|
|
3830
3858
|
(texts == null ? void 0 : texts.registerText) || "Register"
|
3831
3859
|
),
|
3832
3860
|
props.additionalButtons
|
3833
|
-
)), /* @__PURE__ */ import_react15.default.createElement("div", { className: "hawa-flex hawa-flex-row hawa-items-center hawa-justify-center hawa-gap-1 hawa-p-3 hawa-text-center hawa-text-sm hawa-font-normal dark:hawa-text-white" }, /* @__PURE__ */ import_react15.default.createElement("span", null, texts == null ? void 0 : texts.existingUserText), /* @__PURE__ */ import_react15.default.createElement("span", { onClick: props.onRouteToLogin, className: "clickable-link" }, (texts == null ? void 0 : texts.loginText) || "Login")))), props.viaGithub || props.viaGoogle || props.viaTwitter ? /* @__PURE__ */ import_react15.default.createElement(
|
3861
|
+
)), /* @__PURE__ */ import_react15.default.createElement("div", { className: "hawa-flex hawa-flex-row hawa-items-center hawa-justify-center hawa-gap-1 hawa-p-3 hawa-text-center hawa-text-sm hawa-font-normal dark:hawa-text-white" }, /* @__PURE__ */ import_react15.default.createElement("span", null, (texts == null ? void 0 : texts.existingUserText) || "Already have an account?"), /* @__PURE__ */ import_react15.default.createElement("span", { onClick: props.onRouteToLogin, className: "clickable-link" }, (texts == null ? void 0 : texts.loginText) || "Login")))), props.viaGithub || props.viaGoogle || props.viaTwitter ? /* @__PURE__ */ import_react15.default.createElement(
|
3834
3862
|
CardFooter,
|
3835
3863
|
{
|
3836
3864
|
className: cn(
|
@@ -2219,7 +2219,7 @@ var AuthButtons = (props) => {
|
|
2219
2219
|
|
2220
2220
|
// blocks/auth/LoginForm.tsx
|
2221
2221
|
var LoginForm = ({
|
2222
|
-
loginType,
|
2222
|
+
loginType = "email",
|
2223
2223
|
texts,
|
2224
2224
|
passwordLength = 8,
|
2225
2225
|
...props
|
@@ -2238,33 +2238,45 @@ var LoginForm = ({
|
|
2238
2238
|
let formSchema;
|
2239
2239
|
if (loginType === "email") {
|
2240
2240
|
formSchema = z.object({
|
2241
|
-
email: z.string({ required_error: (_a = texts == null ? void 0 : texts.email) == null ? void 0 : _a.required }).min(1, { message: (_b = texts == null ? void 0 : texts.email) == null ? void 0 : _b.required }).email({ message: (_c = texts == null ? void 0 : texts.email) == null ? void 0 : _c.invalid }),
|
2242
|
-
password: z.string({
|
2241
|
+
email: z.string({ required_error: ((_a = texts == null ? void 0 : texts.email) == null ? void 0 : _a.required) || "Email Required" }).min(1, { message: ((_b = texts == null ? void 0 : texts.email) == null ? void 0 : _b.required) || "Email Required" }).email({ message: ((_c = texts == null ? void 0 : texts.email) == null ? void 0 : _c.invalid) || "Email Invalid" }),
|
2242
|
+
password: z.string({
|
2243
|
+
required_error: ((_d = texts == null ? void 0 : texts.password) == null ? void 0 : _d.required) || "Password Required"
|
2244
|
+
}).min(1, { message: ((_e = texts == null ? void 0 : texts.password) == null ? void 0 : _e.required) || "Password Required" }).min(passwordLength, {
|
2245
|
+
message: ((_f = texts == null ? void 0 : texts.password) == null ? void 0 : _f.tooShort) || "Password too short"
|
2246
|
+
})
|
2243
2247
|
});
|
2244
2248
|
} else if (loginType === "username") {
|
2245
2249
|
formSchema = z.object({
|
2246
|
-
username: z.string({
|
2250
|
+
username: z.string({
|
2251
|
+
required_error: ((_g = texts == null ? void 0 : texts.username) == null ? void 0 : _g.required) || "Username Required"
|
2252
|
+
}).min(2, { message: ((_h = texts == null ? void 0 : texts.username) == null ? void 0 : _h.tooShort) || "Username too short" }).refine(
|
2247
2253
|
(value) => {
|
2248
2254
|
const isValid = /^[a-zA-Z][a-zA-Z0-9_-]{2,14}$/.test(value);
|
2249
2255
|
return isValid;
|
2250
2256
|
},
|
2251
|
-
{ message: (_i = texts == null ? void 0 : texts.username) == null ? void 0 : _i.invalid }
|
2257
|
+
{ message: ((_i = texts == null ? void 0 : texts.username) == null ? void 0 : _i.invalid) || "Username Invalid" }
|
2252
2258
|
),
|
2253
|
-
password: z.string({
|
2259
|
+
password: z.string({
|
2260
|
+
required_error: ((_j = texts == null ? void 0 : texts.password) == null ? void 0 : _j.required) || "Password Required"
|
2261
|
+
}).min(1, { message: ((_k = texts == null ? void 0 : texts.password) == null ? void 0 : _k.required) || "Password Required" }).min(passwordLength, {
|
2262
|
+
message: ((_l = texts == null ? void 0 : texts.password) == null ? void 0 : _l.tooShort) || "Password too short"
|
2263
|
+
})
|
2254
2264
|
});
|
2255
2265
|
} else if (loginType === "phone") {
|
2256
2266
|
formSchema = z.object({
|
2257
|
-
phone: z.string({
|
2267
|
+
phone: z.string({
|
2268
|
+
required_error: ((_m = texts == null ? void 0 : texts.phone) == null ? void 0 : _m.required) || "Phone Number Required"
|
2269
|
+
}).refine(
|
2258
2270
|
(value) => {
|
2259
2271
|
let phoneNumber = parsePhoneNumber(value);
|
2260
2272
|
return phoneNumber.isValid();
|
2261
2273
|
},
|
2262
|
-
{ message: (_n = texts == null ? void 0 : texts.phone) == null ? void 0 : _n.invalid }
|
2274
|
+
{ message: ((_n = texts == null ? void 0 : texts.phone) == null ? void 0 : _n.invalid) || "Phone Number Invalid" }
|
2263
2275
|
)
|
2264
2276
|
});
|
2265
2277
|
} else if (loginType === "link") {
|
2266
2278
|
formSchema = z.object({
|
2267
|
-
email: z.string({ required_error: (_o = texts == null ? void 0 : texts.email) == null ? void 0 : _o.required }).min(1, { message: (_p = texts == null ? void 0 : texts.email) == null ? void 0 : _p.required }).email({ message: (_q = texts == null ? void 0 : texts.email) == null ? void 0 : _q.invalid })
|
2279
|
+
email: z.string({ required_error: ((_o = texts == null ? void 0 : texts.email) == null ? void 0 : _o.required) || "Email Required" }).min(1, { message: ((_p = texts == null ? void 0 : texts.email) == null ? void 0 : _p.required) || "Email Required" }).email({ message: ((_q = texts == null ? void 0 : texts.email) == null ? void 0 : _q.invalid) || "Email Invalid" })
|
2268
2280
|
});
|
2269
2281
|
} else {
|
2270
2282
|
formSchema = z.object({});
|
@@ -2291,7 +2303,7 @@ var LoginForm = ({
|
|
2291
2303
|
dir: "ltr",
|
2292
2304
|
width: "full",
|
2293
2305
|
autoComplete: "email",
|
2294
|
-
label: (_a2 = texts == null ? void 0 : texts.email) == null ? void 0 : _a2.label,
|
2306
|
+
label: ((_a2 = texts == null ? void 0 : texts.email) == null ? void 0 : _a2.label) || "Email",
|
2295
2307
|
helperText: (_b2 = formState.errors.email) == null ? void 0 : _b2.message,
|
2296
2308
|
placeholder: ((_c2 = texts == null ? void 0 : texts.email) == null ? void 0 : _c2.placeholder) || "contact@sikka.io",
|
2297
2309
|
...field
|
@@ -2328,7 +2340,7 @@ var LoginForm = ({
|
|
2328
2340
|
);
|
2329
2341
|
}
|
2330
2342
|
}
|
2331
|
-
),
|
2343
|
+
), props.withResetPassword && /* @__PURE__ */ React5.createElement(
|
2332
2344
|
"div",
|
2333
2345
|
{
|
2334
2346
|
onClick: props.onForgotPassword,
|
@@ -2370,7 +2382,7 @@ var LoginForm = ({
|
|
2370
2382
|
width: "full",
|
2371
2383
|
autoComplete: "current-password",
|
2372
2384
|
type: passwordVisible ? "text" : "password",
|
2373
|
-
label: (_a2 = texts == null ? void 0 : texts.password) == null ? void 0 : _a2.label,
|
2385
|
+
label: ((_a2 = texts == null ? void 0 : texts.password) == null ? void 0 : _a2.label) || "Password",
|
2374
2386
|
endIcon: /* @__PURE__ */ React5.createElement(
|
2375
2387
|
"div",
|
2376
2388
|
{
|
@@ -2386,7 +2398,7 @@ var LoginForm = ({
|
|
2386
2398
|
);
|
2387
2399
|
}
|
2388
2400
|
}
|
2389
|
-
),
|
2401
|
+
), props.withResetPassword && /* @__PURE__ */ React5.createElement(
|
2390
2402
|
"div",
|
2391
2403
|
{
|
2392
2404
|
onClick: props.onForgotPassword,
|
@@ -2405,7 +2417,7 @@ var LoginForm = ({
|
|
2405
2417
|
return /* @__PURE__ */ React5.createElement(
|
2406
2418
|
PhoneInput,
|
2407
2419
|
{
|
2408
|
-
label: (_a2 = texts == null ? void 0 : texts.phone) == null ? void 0 : _a2.label,
|
2420
|
+
label: ((_a2 = texts == null ? void 0 : texts.phone) == null ? void 0 : _a2.label) || "Phone Number",
|
2409
2421
|
helperText: (_b2 = formState.errors.phone) == null ? void 0 : _b2.message,
|
2410
2422
|
preferredCountry: { label: "+966" },
|
2411
2423
|
handleChange: (e) => field.onChange(parsePhoneNumber(e).number)
|
@@ -2652,6 +2664,8 @@ CheckboxElement.displayName = CheckboxPrimitive.Root.displayName;
|
|
2652
2664
|
var RegisterForm = ({
|
2653
2665
|
texts,
|
2654
2666
|
registerFields = ["email"],
|
2667
|
+
showTermsOption = false,
|
2668
|
+
showNewsletterOption = false,
|
2655
2669
|
...props
|
2656
2670
|
}) => {
|
2657
2671
|
var _a, _b, _c, _d, _e, _f;
|
@@ -2674,26 +2688,38 @@ var RegisterForm = ({
|
|
2674
2688
|
fieldSchemas["fullName"] = z2.string().optional();
|
2675
2689
|
break;
|
2676
2690
|
case "email":
|
2677
|
-
fieldSchemas["email"] = z2.string({
|
2691
|
+
fieldSchemas["email"] = z2.string({
|
2692
|
+
required_error: ((_a2 = texts == null ? void 0 : texts.email) == null ? void 0 : _a2.required) || "Email is required"
|
2693
|
+
}).email({ message: ((_b2 = texts == null ? void 0 : texts.email) == null ? void 0 : _b2.invalid) || "Invalid email" }).min(1, { message: ((_c2 = texts == null ? void 0 : texts.email) == null ? void 0 : _c2.required) || "Email is required" });
|
2678
2694
|
break;
|
2679
2695
|
case "username":
|
2680
|
-
fieldSchemas["username"] = z2.string({
|
2696
|
+
fieldSchemas["username"] = z2.string({
|
2697
|
+
required_error: ((_d2 = texts == null ? void 0 : texts.username) == null ? void 0 : _d2.required) || "Username is required"
|
2698
|
+
}).min(1, {
|
2699
|
+
message: ((_e2 = texts == null ? void 0 : texts.username) == null ? void 0 : _e2.required) || "Username is required"
|
2700
|
+
}).refine(
|
2681
2701
|
(value) => {
|
2682
2702
|
const isValid = /^[a-zA-Z][a-zA-Z0-9_-]{2,14}$/.test(value);
|
2683
2703
|
return isValid;
|
2684
2704
|
},
|
2685
|
-
{ message: (_f2 = texts == null ? void 0 : texts.username) == null ? void 0 : _f2.invalid }
|
2705
|
+
{ message: ((_f2 = texts == null ? void 0 : texts.username) == null ? void 0 : _f2.invalid) || "Invalid username" }
|
2686
2706
|
);
|
2687
2707
|
break;
|
2688
2708
|
}
|
2689
2709
|
});
|
2690
2710
|
const formSchema = z2.object({
|
2691
2711
|
...fieldSchemas,
|
2692
|
-
password: z2.string({
|
2693
|
-
|
2712
|
+
password: z2.string({
|
2713
|
+
required_error: ((_a = texts == null ? void 0 : texts.password) == null ? void 0 : _a.required) || "Password is required"
|
2714
|
+
}).min(5, {
|
2715
|
+
message: ((_b = texts == null ? void 0 : texts.password) == null ? void 0 : _b.tooShort) || "Password is too short"
|
2716
|
+
}).refine((value) => value !== "", {
|
2717
|
+
message: ((_c = texts == null ? void 0 : texts.password) == null ? void 0 : _c.required) || "Password is required"
|
2694
2718
|
}),
|
2695
|
-
confirm_password: z2.string({
|
2696
|
-
|
2719
|
+
confirm_password: z2.string({
|
2720
|
+
required_error: ((_d = texts == null ? void 0 : texts.confirm) == null ? void 0 : _d.required) || "Confirm password required"
|
2721
|
+
}).refine((value) => value !== "", {
|
2722
|
+
message: ((_e = texts == null ? void 0 : texts.password) == null ? void 0 : _e.required) || "Confirm password is required"
|
2697
2723
|
}),
|
2698
2724
|
refCode: z2.string().optional(),
|
2699
2725
|
reference: z2.string().optional(),
|
@@ -2742,7 +2768,7 @@ var RegisterForm = ({
|
|
2742
2768
|
Input,
|
2743
2769
|
{
|
2744
2770
|
width: "full",
|
2745
|
-
label: (_a2 = texts == null ? void 0 : texts.fullName) == null ? void 0 : _a2.label,
|
2771
|
+
label: ((_a2 = texts == null ? void 0 : texts.fullName) == null ? void 0 : _a2.label) || "Full Name",
|
2746
2772
|
placeholder: (_b2 = texts == null ? void 0 : texts.fullName) == null ? void 0 : _b2.placeholder,
|
2747
2773
|
helperText: (_c2 = formState.errors.fullName) == null ? void 0 : _c2.message,
|
2748
2774
|
...field
|
@@ -2770,7 +2796,7 @@ var RegisterForm = ({
|
|
2770
2796
|
},
|
2771
2797
|
width: "full",
|
2772
2798
|
autoComplete: "email",
|
2773
|
-
label: (_a2 = texts == null ? void 0 : texts.email) == null ? void 0 : _a2.label,
|
2799
|
+
label: ((_a2 = texts == null ? void 0 : texts.email) == null ? void 0 : _a2.label) || "Email",
|
2774
2800
|
helperText: (_b2 = formState.errors.email) == null ? void 0 : _b2.message,
|
2775
2801
|
placeholder: ((_c2 = texts == null ? void 0 : texts.email) == null ? void 0 : _c2.placeholder) || "Enter your email",
|
2776
2802
|
...field
|
@@ -2794,7 +2820,7 @@ var RegisterForm = ({
|
|
2794
2820
|
{
|
2795
2821
|
width: "full",
|
2796
2822
|
autoComplete: "username",
|
2797
|
-
label: (_a2 = texts == null ? void 0 : texts.username) == null ? void 0 : _a2.label,
|
2823
|
+
label: ((_a2 = texts == null ? void 0 : texts.username) == null ? void 0 : _a2.label) || "Username",
|
2798
2824
|
labelProps: {
|
2799
2825
|
...(_b2 = props.usernameOptions) == null ? void 0 : _b2.label
|
2800
2826
|
},
|
@@ -2830,7 +2856,7 @@ var RegisterForm = ({
|
|
2830
2856
|
" "
|
2831
2857
|
),
|
2832
2858
|
autoComplete: "new-password",
|
2833
|
-
label: (_a2 = texts == null ? void 0 : texts.password) == null ? void 0 : _a2.label,
|
2859
|
+
label: ((_a2 = texts == null ? void 0 : texts.password) == null ? void 0 : _a2.label) || "Password",
|
2834
2860
|
placeholder: (_b2 = texts == null ? void 0 : texts.password) == null ? void 0 : _b2.placeholder,
|
2835
2861
|
helperText: (_c2 = formState.errors.password) == null ? void 0 : _c2.message,
|
2836
2862
|
...field
|
@@ -2852,7 +2878,7 @@ var RegisterForm = ({
|
|
2852
2878
|
width: "full",
|
2853
2879
|
type: "password",
|
2854
2880
|
autoComplete: "new-password",
|
2855
|
-
label: (_a2 = texts == null ? void 0 : texts.confirm) == null ? void 0 : _a2.label,
|
2881
|
+
label: ((_a2 = texts == null ? void 0 : texts.confirm) == null ? void 0 : _a2.label) || "Confirm Password",
|
2856
2882
|
placeholder: (_b2 = texts == null ? void 0 : texts.confirm) == null ? void 0 : _b2.placeholder,
|
2857
2883
|
helperText: (_c2 = formState.errors.confirm_password) == null ? void 0 : _c2.message,
|
2858
2884
|
...field
|
@@ -2907,7 +2933,7 @@ var RegisterForm = ({
|
|
2907
2933
|
}
|
2908
2934
|
}
|
2909
2935
|
),
|
2910
|
-
/* @__PURE__ */ React7.createElement("div", { className: "hawa-flex hawa-flex-col hawa-gap-3" },
|
2936
|
+
/* @__PURE__ */ React7.createElement("div", { className: "hawa-flex hawa-flex-col hawa-gap-3" }, showTermsOption && /* @__PURE__ */ React7.createElement(
|
2911
2937
|
Controller2,
|
2912
2938
|
{
|
2913
2939
|
control,
|
@@ -2920,19 +2946,19 @@ var RegisterForm = ({
|
|
2920
2946
|
id: "terms_accepted",
|
2921
2947
|
helperText: (_b2 = (_a2 = formState.errors.terms_accepted) == null ? void 0 : _a2.message) == null ? void 0 : _b2.toString(),
|
2922
2948
|
onCheckedChange: (e) => field.onChange(e),
|
2923
|
-
label: /* @__PURE__ */ React7.createElement("div", { className: "hawa-flex hawa-flex-row hawa-gap-0.5" }, /* @__PURE__ */ React7.createElement("span", null, texts == null ? void 0 : texts.iAcceptText), " ", /* @__PURE__ */ React7.createElement(StopPropagationWrapper, null, /* @__PURE__ */ React7.createElement(
|
2949
|
+
label: /* @__PURE__ */ React7.createElement("div", { className: "hawa-flex hawa-flex-row hawa-gap-0.5" }, /* @__PURE__ */ React7.createElement("span", null, (texts == null ? void 0 : texts.iAcceptText) || "I accept the "), " ", /* @__PURE__ */ React7.createElement(StopPropagationWrapper, null, /* @__PURE__ */ React7.createElement(
|
2924
2950
|
"a",
|
2925
2951
|
{
|
2926
2952
|
onClick: props.onRouteToTOS,
|
2927
2953
|
className: "clickable-link"
|
2928
2954
|
},
|
2929
|
-
texts == null ? void 0 : texts.termsText
|
2955
|
+
(texts == null ? void 0 : texts.termsText) || "Terms of Service"
|
2930
2956
|
)))
|
2931
2957
|
}
|
2932
2958
|
);
|
2933
2959
|
}
|
2934
2960
|
}
|
2935
|
-
),
|
2961
|
+
), showNewsletterOption && /* @__PURE__ */ React7.createElement(
|
2936
2962
|
Controller2,
|
2937
2963
|
{
|
2938
2964
|
control,
|
@@ -2958,7 +2984,7 @@ var RegisterForm = ({
|
|
2958
2984
|
(texts == null ? void 0 : texts.registerText) || "Register"
|
2959
2985
|
),
|
2960
2986
|
props.additionalButtons
|
2961
|
-
)), /* @__PURE__ */ React7.createElement("div", { className: "hawa-flex hawa-flex-row hawa-items-center hawa-justify-center hawa-gap-1 hawa-p-3 hawa-text-center hawa-text-sm hawa-font-normal dark:hawa-text-white" }, /* @__PURE__ */ React7.createElement("span", null, texts == null ? void 0 : texts.existingUserText), /* @__PURE__ */ React7.createElement("span", { onClick: props.onRouteToLogin, className: "clickable-link" }, (texts == null ? void 0 : texts.loginText) || "Login")))), props.viaGithub || props.viaGoogle || props.viaTwitter ? /* @__PURE__ */ React7.createElement(
|
2987
|
+
)), /* @__PURE__ */ React7.createElement("div", { className: "hawa-flex hawa-flex-row hawa-items-center hawa-justify-center hawa-gap-1 hawa-p-3 hawa-text-center hawa-text-sm hawa-font-normal dark:hawa-text-white" }, /* @__PURE__ */ React7.createElement("span", null, (texts == null ? void 0 : texts.existingUserText) || "Already have an account?"), /* @__PURE__ */ React7.createElement("span", { onClick: props.onRouteToLogin, className: "clickable-link" }, (texts == null ? void 0 : texts.loginText) || "Login")))), props.viaGithub || props.viaGoogle || props.viaTwitter ? /* @__PURE__ */ React7.createElement(
|
2962
2988
|
CardFooter,
|
2963
2989
|
{
|
2964
2990
|
className: cn(
|
package/dist/blocks/index.d.mts
CHANGED
@@ -21,7 +21,7 @@ type LoginFormTypes = {
|
|
21
21
|
/** Login identifier type user will use to log in. */
|
22
22
|
loginType?: "email" | "username" | "phone" | "link";
|
23
23
|
/** If true, the reset password option is hidden. */
|
24
|
-
|
24
|
+
withResetPassword?: boolean;
|
25
25
|
/** If true, the register option is hidden. */
|
26
26
|
allowRegister?: boolean;
|
27
27
|
/** If true, a loading spinner is displayed within the main form submit button. */
|
@@ -39,7 +39,7 @@ type LoginFormTypes = {
|
|
39
39
|
/** If true, Twitter login option is displayed. */
|
40
40
|
viaTwitter?: boolean;
|
41
41
|
/** Function to handle form submission. */
|
42
|
-
onLogin
|
42
|
+
onLogin: (e: any) => void;
|
43
43
|
/** Function to route user to the register page. */
|
44
44
|
onRouteToRegister?: () => void;
|
45
45
|
/** Function to handle forgotten password case. */
|
package/dist/blocks/index.d.ts
CHANGED
@@ -21,7 +21,7 @@ type LoginFormTypes = {
|
|
21
21
|
/** Login identifier type user will use to log in. */
|
22
22
|
loginType?: "email" | "username" | "phone" | "link";
|
23
23
|
/** If true, the reset password option is hidden. */
|
24
|
-
|
24
|
+
withResetPassword?: boolean;
|
25
25
|
/** If true, the register option is hidden. */
|
26
26
|
allowRegister?: boolean;
|
27
27
|
/** If true, a loading spinner is displayed within the main form submit button. */
|
@@ -39,7 +39,7 @@ type LoginFormTypes = {
|
|
39
39
|
/** If true, Twitter login option is displayed. */
|
40
40
|
viaTwitter?: boolean;
|
41
41
|
/** Function to handle form submission. */
|
42
|
-
onLogin
|
42
|
+
onLogin: (e: any) => void;
|
43
43
|
/** Function to route user to the register page. */
|
44
44
|
onRouteToRegister?: () => void;
|
45
45
|
/** Function to handle forgotten password case. */
|