@sikka/hawa 0.1.0 → 0.1.1
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/styles.css +9 -12
- package/es/blocks/AuthForms/SignInForm.d.ts +1 -1
- package/es/elements/Button.d.ts +1 -0
- package/es/elements/Card.d.ts +3 -1
- package/es/index.es.js +3 -3
- package/lib/blocks/AuthForms/SignInForm.d.ts +1 -1
- package/lib/elements/Button.d.ts +1 -0
- package/lib/elements/Card.d.ts +3 -1
- package/lib/index.js +3 -3
- package/package.json +1 -1
- package/src/blocks/AuthForms/ResetPasswordForm.tsx +59 -49
- package/src/blocks/AuthForms/SignInForm.tsx +137 -147
- package/src/blocks/AuthForms/SignUpForm.tsx +237 -225
- package/src/elements/Button.tsx +22 -2
- package/src/elements/Card.tsx +11 -2
- package/src/elements/HawaLoading.tsx +4 -4
- package/src/elements/HawaTextField.tsx +9 -7
- package/src/elements/Icons.tsx +4 -1
- package/src/styles.css +9 -12
- package/src/tailwind.css +2 -6
- package/src/translations/ar.json +1 -0
- package/src/translations/en.json +1 -0
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import React, { FC } from "react"
|
|
2
2
|
import { Controller, useForm } from "react-hook-form"
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { HawaTextField } from "../../elements"
|
|
4
|
+
import {
|
|
5
|
+
Card,
|
|
6
|
+
CardContent,
|
|
7
|
+
CardDescription,
|
|
8
|
+
CardHeader,
|
|
9
|
+
CardTitle,
|
|
10
|
+
} from "../../elements/Card"
|
|
11
|
+
import { Button } from "../../elements/Button"
|
|
5
12
|
|
|
6
13
|
type ResetPasswordType = {
|
|
7
14
|
handleResetPassword: () => void
|
|
@@ -28,52 +35,55 @@ export const ResetPasswordForm: FC<ResetPasswordType> = (props) => {
|
|
|
28
35
|
control,
|
|
29
36
|
} = methods
|
|
30
37
|
return (
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
38
|
+
<Card>
|
|
39
|
+
<CardHeader>
|
|
40
|
+
<CardTitle>Reset Password</CardTitle>
|
|
41
|
+
<CardDescription>
|
|
42
|
+
Enter your email to reset your account password
|
|
43
|
+
</CardDescription>
|
|
44
|
+
</CardHeader>
|
|
45
|
+
<CardContent>
|
|
46
|
+
{!props.sent ? (
|
|
47
|
+
<form onSubmit={handleSubmit(props.handleResetPassword)}>
|
|
48
|
+
<Controller
|
|
49
|
+
control={control}
|
|
50
|
+
name="email"
|
|
51
|
+
render={({ field }) => (
|
|
52
|
+
<HawaTextField
|
|
53
|
+
width="full"
|
|
54
|
+
type="text"
|
|
55
|
+
label={props.texts.emailLabel}
|
|
56
|
+
helpertext={errors.email?.message}
|
|
57
|
+
placeholder={props.texts.emailPlaceholder}
|
|
58
|
+
{...field}
|
|
59
|
+
value={field.value ?? ""}
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
62
|
+
rules={{
|
|
63
|
+
required: props.texts.emailRequiredText,
|
|
64
|
+
pattern: {
|
|
65
|
+
value:
|
|
66
|
+
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
|
67
|
+
message: props.texts.emailInvalidText,
|
|
68
|
+
},
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
<div className=" pb-2 text-left text-sm dark:text-gray-300">
|
|
72
|
+
{props.texts.dontHaveAccount ?? "Don't have an account? "}
|
|
73
|
+
<span
|
|
74
|
+
onClick={props.handleRouteToSignUp}
|
|
75
|
+
className="cursor-pointer text-blue-600 dark:text-blue-400"
|
|
76
|
+
>
|
|
77
|
+
{props.texts.signUpText ?? "Sign Up"}
|
|
78
|
+
</span>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<Button className="w-full">{props.texts.resetPassword}</Button>
|
|
82
|
+
</form>
|
|
83
|
+
) : (
|
|
84
|
+
<div className="text-center">{props.texts.emailSentText}</div>
|
|
85
|
+
)}
|
|
86
|
+
</CardContent>
|
|
87
|
+
</Card>
|
|
78
88
|
)
|
|
79
89
|
}
|
|
@@ -10,6 +10,9 @@ import { Controller, useForm } from "react-hook-form"
|
|
|
10
10
|
import { HawaContainer } from "../../layout"
|
|
11
11
|
import { Button } from "../../elements/Button"
|
|
12
12
|
import { FaGithub, FaGoogle } from "react-icons/fa"
|
|
13
|
+
import { Card, CardContent, CardFooter, CardHeader } from "../../elements/Card"
|
|
14
|
+
import { Icons } from "../../elements/Icons"
|
|
15
|
+
import clsx from "clsx"
|
|
13
16
|
|
|
14
17
|
export const SignInForm: FC<SignInFormTypes> = (props) => {
|
|
15
18
|
const {
|
|
@@ -19,174 +22,161 @@ export const SignInForm: FC<SignInFormTypes> = (props) => {
|
|
|
19
22
|
} = useForm()
|
|
20
23
|
|
|
21
24
|
return (
|
|
22
|
-
<
|
|
23
|
-
<
|
|
24
|
-
{props.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
control={control}
|
|
34
|
-
name="email"
|
|
35
|
-
render={({ field }) => (
|
|
36
|
-
<HawaTextField
|
|
37
|
-
width="full"
|
|
38
|
-
type="text"
|
|
39
|
-
autoComplete="email"
|
|
40
|
-
label={props.texts.emailLabel}
|
|
41
|
-
helpertext={errors.email?.message}
|
|
42
|
-
placeholder={props.texts.emailPlaceholder}
|
|
43
|
-
value={field.value ?? ""}
|
|
44
|
-
onChange={field.onChange}
|
|
45
|
-
/>
|
|
46
|
-
)}
|
|
47
|
-
rules={{
|
|
48
|
-
required: props.texts.emailRequiredText,
|
|
49
|
-
pattern: {
|
|
50
|
-
value:
|
|
51
|
-
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
|
52
|
-
message: props.texts.emailInvalidText,
|
|
53
|
-
},
|
|
54
|
-
}}
|
|
55
|
-
/>
|
|
56
|
-
) : props.signInType === "username" ? (
|
|
57
|
-
<Controller
|
|
58
|
-
control={control}
|
|
59
|
-
name="username"
|
|
60
|
-
render={({ field }) => {
|
|
61
|
-
return (
|
|
62
|
-
<HawaTextField
|
|
63
|
-
width="full"
|
|
64
|
-
type="text"
|
|
65
|
-
autoComplete="username"
|
|
66
|
-
label={props.texts.usernameLabel}
|
|
67
|
-
helpertext={errors.username?.message}
|
|
68
|
-
placeholder={props.texts.usernamePlaceholder}
|
|
69
|
-
onChange={field.onChange}
|
|
70
|
-
value={field.value ?? ""}
|
|
71
|
-
/>
|
|
72
|
-
)
|
|
73
|
-
}}
|
|
74
|
-
rules={{
|
|
75
|
-
required: props.texts.usernameRequired,
|
|
76
|
-
}}
|
|
77
|
-
/>
|
|
78
|
-
) : (
|
|
79
|
-
<Controller
|
|
80
|
-
control={control}
|
|
81
|
-
name="phone"
|
|
82
|
-
render={({ field }) => <HawaPhoneInput label="Phone number" />}
|
|
83
|
-
rules={{ required: props.texts.phoneRequiredText }}
|
|
84
|
-
/>
|
|
85
|
-
)}
|
|
86
|
-
{props.signInType !== "phone" && (
|
|
87
|
-
<>
|
|
25
|
+
<Card dir={props.direction}>
|
|
26
|
+
<CardContent headless>
|
|
27
|
+
<form onSubmit={handleSubmit((e) => props.handleSignIn(e))}>
|
|
28
|
+
{props.showError && (
|
|
29
|
+
<HawaAlert
|
|
30
|
+
title={props.errorTitle}
|
|
31
|
+
text={props.errorText}
|
|
32
|
+
severity="error"
|
|
33
|
+
/>
|
|
34
|
+
)}
|
|
35
|
+
{props.signInType === "email" ? (
|
|
88
36
|
<Controller
|
|
89
37
|
control={control}
|
|
90
|
-
name="
|
|
38
|
+
name="email"
|
|
91
39
|
render={({ field }) => (
|
|
92
40
|
<HawaTextField
|
|
93
41
|
width="full"
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
label={props.texts.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
onChange={field.onChange}
|
|
42
|
+
type="text"
|
|
43
|
+
autoComplete="email"
|
|
44
|
+
label={props.texts.emailLabel}
|
|
45
|
+
helpertext={errors.email?.message}
|
|
46
|
+
placeholder={props.texts.emailPlaceholder}
|
|
100
47
|
value={field.value ?? ""}
|
|
48
|
+
onChange={field.onChange}
|
|
101
49
|
/>
|
|
102
50
|
)}
|
|
103
51
|
rules={{
|
|
104
|
-
required: props.texts.
|
|
105
|
-
|
|
52
|
+
required: props.texts.emailRequiredText,
|
|
53
|
+
pattern: {
|
|
54
|
+
value:
|
|
55
|
+
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
|
56
|
+
message: props.texts.emailInvalidText,
|
|
57
|
+
},
|
|
106
58
|
}}
|
|
107
59
|
/>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
60
|
+
) : props.signInType === "username" ? (
|
|
61
|
+
<Controller
|
|
62
|
+
control={control}
|
|
63
|
+
name="username"
|
|
64
|
+
render={({ field }) => {
|
|
65
|
+
return (
|
|
66
|
+
<HawaTextField
|
|
67
|
+
width="full"
|
|
68
|
+
type="text"
|
|
69
|
+
autoComplete="username"
|
|
70
|
+
label={props.texts.usernameLabel}
|
|
71
|
+
helpertext={errors.username?.message}
|
|
72
|
+
placeholder={props.texts.usernamePlaceholder}
|
|
73
|
+
onChange={field.onChange}
|
|
74
|
+
value={field.value ?? ""}
|
|
75
|
+
/>
|
|
76
|
+
)
|
|
77
|
+
}}
|
|
78
|
+
rules={{
|
|
79
|
+
required: props.texts.usernameRequired,
|
|
80
|
+
}}
|
|
81
|
+
/>
|
|
82
|
+
) : (
|
|
83
|
+
<Controller
|
|
84
|
+
control={control}
|
|
85
|
+
name="phone"
|
|
86
|
+
render={({ field }) => <HawaPhoneInput label="Phone number" />}
|
|
87
|
+
rules={{ required: props.texts.phoneRequiredText }}
|
|
88
|
+
/>
|
|
89
|
+
)}
|
|
90
|
+
{props.signInType !== "phone" && (
|
|
91
|
+
<>
|
|
92
|
+
<Controller
|
|
93
|
+
control={control}
|
|
94
|
+
name="password"
|
|
95
|
+
render={({ field }) => (
|
|
96
|
+
<HawaTextField
|
|
97
|
+
width="full"
|
|
98
|
+
autoComplete="current-password"
|
|
99
|
+
type="password"
|
|
100
|
+
label={props.texts.passwordLabel}
|
|
101
|
+
placeholder={props.texts.passwordPlaceholder}
|
|
102
|
+
helpertext={errors.password?.message}
|
|
103
|
+
onChange={field.onChange}
|
|
104
|
+
value={field.value ?? ""}
|
|
105
|
+
/>
|
|
106
|
+
)}
|
|
107
|
+
rules={{
|
|
108
|
+
required: props.texts.passwordRequiredText,
|
|
109
|
+
minLength: 5,
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
{!props.withoutResetPassword && (
|
|
113
|
+
<div
|
|
114
|
+
onClick={props.handleForgotPassword}
|
|
115
|
+
className="mb-3 w-fit cursor-pointer text-xs dark:text-gray-300"
|
|
116
|
+
>
|
|
117
|
+
{props.texts.forgotPasswordText}
|
|
118
|
+
</div>
|
|
119
|
+
)}
|
|
120
|
+
</>
|
|
121
|
+
)}
|
|
118
122
|
|
|
119
|
-
{/* <HawaButton
|
|
120
|
-
isLoading={props.isLoading}
|
|
121
|
-
variant="contained"
|
|
122
|
-
color="primary"
|
|
123
|
-
size="medium"
|
|
124
|
-
width="full"
|
|
125
|
-
>
|
|
126
|
-
{props.texts.signInText}
|
|
127
|
-
</HawaButton> */}
|
|
128
|
-
<Button className="w-full">{props.texts.signInText}</Button>
|
|
129
|
-
{!props.withoutSignUp && (
|
|
130
|
-
<div className="p-3 text-center text-sm font-semibold dark:text-gray-300">
|
|
131
|
-
{props.texts.newUserText}{" "}
|
|
132
|
-
<span
|
|
133
|
-
onClick={props.handleRouteToSignUp}
|
|
134
|
-
className="cursor-pointer text-blue-600 dark:text-blue-400"
|
|
135
|
-
>
|
|
136
|
-
{props.texts.signUpText}
|
|
137
|
-
</span>
|
|
138
|
-
</div>
|
|
139
|
-
)}
|
|
140
|
-
</form>
|
|
141
123
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
</div> */}
|
|
124
|
+
<Button className="w-full" isLoading={props.isLoading}>
|
|
125
|
+
{props.texts.signInText}
|
|
126
|
+
</Button>
|
|
127
|
+
{!props.withoutSignUp && (
|
|
128
|
+
<div className="p-3 text-center text-sm font-semibold dark:text-gray-300">
|
|
129
|
+
{props.texts.newUserText}{" "}
|
|
130
|
+
<span
|
|
131
|
+
onClick={props.handleRouteToSignUp}
|
|
132
|
+
className="cursor-pointer text-blue-600 dark:text-blue-400"
|
|
133
|
+
>
|
|
134
|
+
{props.texts.createAccount}
|
|
135
|
+
</span>
|
|
136
|
+
</div>
|
|
137
|
+
)}
|
|
138
|
+
</form>
|
|
139
|
+
</CardContent>
|
|
140
|
+
|
|
160
141
|
{/* 3rd Party Sign Auth Buttons */}
|
|
161
142
|
{props.viaGithub || props.viaGoogle || props.viaTwitter ? (
|
|
162
|
-
<
|
|
143
|
+
<CardFooter className="grid grid-cols-1 gap-2 ">
|
|
163
144
|
{props.viaGoogle && (
|
|
164
|
-
<
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
145
|
+
<Button variant="outline" onClick={props.handleGoogleSignIn}>
|
|
146
|
+
<Icons.google
|
|
147
|
+
className={clsx(
|
|
148
|
+
"h-4 w-4",
|
|
149
|
+
props.direction === "rtl" ? "ml-2" : "mr-2"
|
|
150
|
+
)}
|
|
151
|
+
/>
|
|
152
|
+
{props.texts.signInViaGoogleLabel}
|
|
153
|
+
</Button>
|
|
170
154
|
)}
|
|
171
155
|
{props.viaGithub && (
|
|
172
|
-
<
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
156
|
+
<Button variant="outline" onClick={props.handleGithubSignIn}>
|
|
157
|
+
<Icons.gitHub
|
|
158
|
+
className={clsx(
|
|
159
|
+
"h-4 w-4",
|
|
160
|
+
props.direction === "rtl" ? "ml-2" : "mr-2"
|
|
161
|
+
)}
|
|
162
|
+
/>
|
|
163
|
+
{props.texts.signInViaGithubLabel}
|
|
164
|
+
</Button>
|
|
178
165
|
)}
|
|
179
166
|
{props.viaTwitter && (
|
|
180
|
-
<
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
167
|
+
<Button variant="outline" onClick={props.handleTwitterSignIn}>
|
|
168
|
+
<Icons.twitter
|
|
169
|
+
className={clsx(
|
|
170
|
+
"h-4 w-4",
|
|
171
|
+
props.direction === "rtl" ? "ml-2" : "mr-2"
|
|
172
|
+
)}
|
|
173
|
+
/>
|
|
174
|
+
{props.texts.signInViaTwitterLabel}
|
|
175
|
+
</Button>
|
|
186
176
|
)}
|
|
187
|
-
</
|
|
177
|
+
</CardFooter>
|
|
188
178
|
) : null}
|
|
189
|
-
</
|
|
179
|
+
</Card>
|
|
190
180
|
)
|
|
191
181
|
}
|
|
192
182
|
|
|
@@ -210,7 +200,7 @@ type SignInFormTypes = {
|
|
|
210
200
|
passwordRequiredText?: string
|
|
211
201
|
forgotPasswordText?: string
|
|
212
202
|
newUserText?: string
|
|
213
|
-
|
|
203
|
+
createAccount?: string
|
|
214
204
|
signInText?: string
|
|
215
205
|
signInViaGoogleLabel?: string
|
|
216
206
|
signInViaGithubLabel?: string
|