@ttoss/react-auth 1.5.0 → 1.6.0
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/LICENSE +674 -0
- package/dist/esm/index.js +147 -88
- package/dist/index.js +146 -87
- package/i18n/lang/en.json +16 -16
- package/package.json +20 -21
- package/src/AuthCard.tsx +51 -39
- package/src/AuthConfirmSignUp.tsx +1 -0
- package/src/AuthSignIn.tsx +61 -32
- package/src/AuthSignUp.tsx +9 -7
- package/src/useHidePassInput.ts +26 -0
package/src/AuthSignIn.tsx
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { AuthCard } from './AuthCard';
|
|
2
|
+
import { Button, Flex, Link, Text } from '@ttoss/ui';
|
|
2
3
|
import { Form, FormFieldInput, useForm, yup, yupResolver } from '@ttoss/forms';
|
|
3
4
|
import { PASSWORD_MINIMUM_LENGTH } from '@ttoss/cloud-auth';
|
|
5
|
+
import { useHidePassInput } from './useHidePassInput';
|
|
4
6
|
import { useI18n } from '@ttoss/react-i18n';
|
|
5
7
|
import type { OnSignIn, OnSignInInput } from './types';
|
|
6
8
|
|
|
7
9
|
export type AuthSignInProps = {
|
|
8
10
|
onSignIn: OnSignIn;
|
|
9
11
|
onSignUp: () => void;
|
|
12
|
+
onForgotPassword?: () => void;
|
|
10
13
|
defaultValues?: Partial<OnSignInInput>;
|
|
11
14
|
urlLogo?: string;
|
|
12
15
|
};
|
|
@@ -15,9 +18,12 @@ export const AuthSignIn = ({
|
|
|
15
18
|
onSignIn,
|
|
16
19
|
onSignUp,
|
|
17
20
|
defaultValues,
|
|
21
|
+
onForgotPassword,
|
|
18
22
|
}: AuthSignInProps) => {
|
|
19
23
|
const { intl } = useI18n();
|
|
20
24
|
|
|
25
|
+
const { handleClick, icon, inputType } = useHidePassInput();
|
|
26
|
+
|
|
21
27
|
const schema = yup.object().shape({
|
|
22
28
|
email: yup
|
|
23
29
|
.string()
|
|
@@ -52,6 +58,7 @@ export const AuthSignIn = ({
|
|
|
52
58
|
)
|
|
53
59
|
)
|
|
54
60
|
.trim(),
|
|
61
|
+
// remember: yup.boolean(),
|
|
55
62
|
});
|
|
56
63
|
|
|
57
64
|
const formMethods = useForm<OnSignInInput>({
|
|
@@ -68,43 +75,65 @@ export const AuthSignIn = ({
|
|
|
68
75
|
<AuthCard
|
|
69
76
|
title={intl.formatMessage({
|
|
70
77
|
description: 'Sign in title.',
|
|
71
|
-
defaultMessage: '
|
|
78
|
+
defaultMessage: 'Log in',
|
|
72
79
|
})}
|
|
73
80
|
buttonLabel={intl.formatMessage({
|
|
74
81
|
description: 'Button label.',
|
|
75
|
-
defaultMessage: '
|
|
82
|
+
defaultMessage: 'Log in',
|
|
76
83
|
})}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
]}
|
|
84
|
+
isValidForm={formMethods.formState.isValid}
|
|
85
|
+
extraButton={
|
|
86
|
+
<Button
|
|
87
|
+
type="button"
|
|
88
|
+
variant="secondary"
|
|
89
|
+
sx={{ textAlign: 'center', display: 'initial' }}
|
|
90
|
+
onClick={onSignUp}
|
|
91
|
+
aria-label="sign-up"
|
|
92
|
+
>
|
|
93
|
+
{intl.formatMessage({
|
|
94
|
+
description: 'Sign up',
|
|
95
|
+
defaultMessage: 'Sign up',
|
|
96
|
+
})}
|
|
97
|
+
</Button>
|
|
98
|
+
}
|
|
93
99
|
>
|
|
94
|
-
<
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
100
|
+
<Flex sx={{ flexDirection: 'column', gap: 'xl' }}>
|
|
101
|
+
<FormFieldInput
|
|
102
|
+
name="email"
|
|
103
|
+
label={intl.formatMessage({
|
|
104
|
+
description: 'Email label.',
|
|
105
|
+
defaultMessage: 'Email',
|
|
106
|
+
})}
|
|
107
|
+
/>
|
|
108
|
+
<FormFieldInput
|
|
109
|
+
name="password"
|
|
110
|
+
trailingIcon={icon}
|
|
111
|
+
onTrailingIconClick={handleClick}
|
|
112
|
+
type={inputType}
|
|
113
|
+
label={intl.formatMessage({
|
|
114
|
+
description: 'Password label.',
|
|
115
|
+
defaultMessage: 'Password',
|
|
116
|
+
})}
|
|
117
|
+
/>
|
|
118
|
+
</Flex>
|
|
119
|
+
|
|
120
|
+
<Flex sx={{ justifyContent: 'space-between', marginTop: 'lg' }}>
|
|
121
|
+
{/* TODO: temporally commented */}
|
|
122
|
+
{/* <FormFieldCheckbox
|
|
123
|
+
name="remember"
|
|
124
|
+
label={intl.formatMessage({
|
|
125
|
+
description: 'Remember',
|
|
126
|
+
defaultMessage: 'Remember',
|
|
127
|
+
})}
|
|
128
|
+
/> */}
|
|
129
|
+
|
|
130
|
+
<Text as={Link} onClick={onForgotPassword}>
|
|
131
|
+
{intl.formatMessage({
|
|
132
|
+
description: 'Forgot password?',
|
|
133
|
+
defaultMessage: 'Forgot password?',
|
|
134
|
+
})}
|
|
135
|
+
</Text>
|
|
136
|
+
</Flex>
|
|
108
137
|
</AuthCard>
|
|
109
138
|
</Form>
|
|
110
139
|
);
|
package/src/AuthSignUp.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AuthCard } from './AuthCard';
|
|
2
2
|
import { Form, FormFieldInput, useForm, yup, yupResolver } from '@ttoss/forms';
|
|
3
|
+
import { Link, Text } from '@ttoss/ui';
|
|
3
4
|
import { PASSWORD_MINIMUM_LENGTH } from '@ttoss/cloud-auth';
|
|
4
5
|
import { useI18n } from '@ttoss/react-i18n';
|
|
5
6
|
import type { OnSignUp, OnSignUpInput } from './types';
|
|
@@ -67,15 +68,15 @@ export const AuthSignUp = ({ onSignUp, onReturnToSignIn }: AuthSignUpProps) => {
|
|
|
67
68
|
description: 'Title on sign up.',
|
|
68
69
|
defaultMessage: 'Register',
|
|
69
70
|
})}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
isValidForm={formMethods.formState.isValid}
|
|
72
|
+
extraButton={
|
|
73
|
+
<Text onClick={onReturnToSignIn} as={Link}>
|
|
74
|
+
{intl.formatMessage({
|
|
73
75
|
description: 'Link to sign in on sign up.',
|
|
74
76
|
defaultMessage: 'Do you already have an account? Sign in',
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
]}
|
|
77
|
+
})}
|
|
78
|
+
</Text>
|
|
79
|
+
}
|
|
79
80
|
>
|
|
80
81
|
<FormFieldInput
|
|
81
82
|
name="email"
|
|
@@ -86,6 +87,7 @@ export const AuthSignUp = ({ onSignUp, onReturnToSignIn }: AuthSignUpProps) => {
|
|
|
86
87
|
/>
|
|
87
88
|
<FormFieldInput
|
|
88
89
|
name="password"
|
|
90
|
+
type="password"
|
|
89
91
|
label={intl.formatMessage({
|
|
90
92
|
description: 'Password label.',
|
|
91
93
|
defaultMessage: 'Password',
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
export const useHidePassInput = (defaultValue = true) => {
|
|
4
|
+
const [hidePass, setHidePass] = React.useState<boolean>(
|
|
5
|
+
Boolean(defaultValue)
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
const { icon, inputType } = React.useMemo(() => {
|
|
9
|
+
return {
|
|
10
|
+
icon: hidePass ? 'view-off' : 'view-on',
|
|
11
|
+
inputType: hidePass ? 'password' : 'text',
|
|
12
|
+
};
|
|
13
|
+
}, [hidePass]);
|
|
14
|
+
|
|
15
|
+
const handleClick = () => {
|
|
16
|
+
setHidePass((prev) => {
|
|
17
|
+
return !prev;
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
handleClick,
|
|
23
|
+
icon,
|
|
24
|
+
inputType,
|
|
25
|
+
};
|
|
26
|
+
};
|