ywana-core8 0.1.29 → 0.1.30

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -29,7 +29,8 @@
29
29
  "jest": "^29.7.0",
30
30
  "microbundle": "^0.14.2",
31
31
  "react": "^17.0.2",
32
- "react-dom": "^17.0.2"
32
+ "react-dom": "^17.0.2",
33
+ "react-scripts": "^5.0.1"
33
34
  },
34
35
  "dependencies": {
35
36
  "axios": "^1.3.4",
@@ -2,8 +2,7 @@
2
2
  * Session store
3
3
  * implements securityCtx methods
4
4
  */
5
-
6
- const SESSION_NAME = process.env.REACT_APP_SESSION || window && window.SESSION ? window.SESSION : 'YWANA-CORE6-SESSION';
5
+ const SESSION_NAME = typeof process !== 'undefined' ? process.env.REACT_APP_SESSION : window && window.SESSION ? window.SESSION : 'YWANA-CORE8-SESSION';
7
6
 
8
7
  export const Session = {
9
8
 
@@ -1,13 +1,14 @@
1
1
  export * from './login/LoginBox'
2
2
  export * from './login/ResetPasswordBox'
3
- export * from './login/login_commons'
3
+ export * from './login/validations'
4
4
  export * from './login/actions'
5
5
  export * from './login/dialogs'
6
6
  export * from './login/dictionary'
7
+ export * from './login/context'
7
8
 
8
9
  export * from './viewer/Viewer'
9
10
  export * from './kanban/Kanban'
10
- export * from './avatar/avatar'
11
+ export * from './avatar/Avatar'
11
12
  export * from './waiter'
12
13
  export * from './calendar/Calendar'
13
14
  export * from './planner/Planner'
@@ -1,33 +1,8 @@
1
1
  .login-box {
2
2
  background-color: var(--paper-color);
3
- display: grid;
4
- grid-template-areas:
5
- "header header"
6
- "main main"
7
- "footer footer";
8
- }
9
-
10
- .login-box > header {
11
- grid-area: header;
12
- display: flex;
13
- flex: 1;
14
- flex-direction: column;
15
- justify-content: space-around;
16
- align-items: center;
17
- padding: 1rem;
18
- }
19
-
20
- .login-box > header > img {
21
- max-width: 90%;
22
- }
23
-
24
- .login-box > header > .title {
25
- font-size: 2rem;
26
- font-weight: 600;
27
3
  }
28
4
 
29
5
  .login-box > main {
30
- grid-area: main;
31
6
  padding: 1rem 1rem 0 1rem;
32
7
  display: flex;
33
8
  flex-direction: column;
@@ -6,15 +6,11 @@ import './LoginBox.css'
6
6
  * Login Box
7
7
  */
8
8
  export const LoginBox = ({
9
- logo, title,
10
- userLabel = "User",
11
- userValue = "",
12
- passwordLabel = "Password",
13
- passwordValue = '',
14
- loginLabel = "Log In", onOK,
15
- forgotLabel = "Forgot Password?", onForgot,
16
- message,
17
- loading
9
+ userLabel = "User", userValue = "",
10
+ passwordLabel = "Password", passwordValue = '',
11
+ loginLabel = "Log In",
12
+ onOK, message, loading,
13
+ children
18
14
  }) => {
19
15
 
20
16
  const [user, setUser] = useState(userValue)
@@ -28,14 +24,6 @@ export const LoginBox = ({
28
24
  if (onOK && canOK()) onOK(user, forcedPwd || password)
29
25
  }
30
26
 
31
- function canForgot() {
32
- return user && user.length > 0
33
- }
34
-
35
- function forgot() {
36
- if (onForgot) onForgot(user)
37
- }
38
-
39
27
  function tx(txt) {
40
28
  return <Text>{txt}</Text>
41
29
  }
@@ -50,17 +38,14 @@ export const LoginBox = ({
50
38
 
51
39
  return (
52
40
  <div className="login-box">
53
- <header>
54
- {logo ? <img src={logo} /> : ''}
55
- <div className="title"><Text>{title}</Text></div>
56
- </header>
57
41
  <main>
58
42
  <TextField label={tx(userLabel)} value={user} onChange={changeUser} onEnter={ok} outlined autoComplete="on" />
59
43
  <TextField id="loginbox-password" label={tx(passwordLabel)} value={password} onChange={changePassword} onEnter={ok} type="password" outlined autoComplete="on" />
60
44
  </main>
61
45
  <footer>
62
- { loading ? <div className="load-box"><Icon icon="refresh" /></div> : <Button label={tx(loginLabel)} action={ok} disabled={!canOK()} raised className="login-button" /> }
63
- { onForgot ? <Button label={tx(forgotLabel)} action={forgot} disabled={!canForgot()} className="forgot-button"/> : null }
46
+ { loading ? <div className="load-box"><Icon icon="refresh" /></div> : null }
47
+ { !loading ? <Button label={tx(loginLabel)} action={ok} disabled={!canOK()} raised className="login-button" /> : null }
48
+ { children }
64
49
  { message ? <div className="message"><Text>{message}</Text></div> : null}
65
50
  </footer>
66
51
  </div>
@@ -1,11 +1,12 @@
1
1
  import React from 'react'
2
2
  import { LoginBox } from './LoginBox'
3
+ import { ForgetUserPasswordAction } from './actions'
3
4
 
4
5
  const LoginBoxTest = (prop) => {
5
6
 
6
7
  return (
7
-
8
- <LoginBox onForgot />
9
-
8
+ <LoginBox>
9
+ <ForgetUserPasswordAction icon={false} />
10
+ </LoginBox>
10
11
  )
11
12
  }
@@ -1,20 +1,10 @@
1
1
  .reset-password-box {
2
2
  background-color: var(--paper-color);
3
- display: grid;
4
- grid-template-areas: "header header" "main main" "footer footer";
5
3
  animation: fadeIn 2s;
6
4
  padding: .5rem;
7
5
  }
8
6
 
9
- .reset-password-box>header {
10
- grid-area: header;
11
- display: flex;
12
- flex-direction: column;
13
- justify-content: space-around;
14
- }
15
-
16
7
  .reset-password-box>main {
17
- grid-area: main;
18
8
  display: flex;
19
9
  flex-direction: column;
20
10
  }
@@ -30,7 +20,6 @@
30
20
  }
31
21
 
32
22
  .reset-password-box>footer {
33
- grid-area: footer;
34
23
  margin-top: .5rem;
35
24
  display: flex;
36
25
  }
@@ -1,12 +1,12 @@
1
1
  import React, { useState } from 'react'
2
2
  import { TextField, Text, Button } from '../../html'
3
- import { validatePassword } from './login_commons'
3
+ import { validatePassword } from './validations'
4
4
  import './ResetPasswordBox.css'
5
5
 
6
6
  /**
7
7
  * Reset Password
8
8
  */
9
- export const ResetPasswordBox = ({ title, userRequired = true, oldPwdRequired = false, validator, children, onOK }) => {
9
+ export const ResetPasswordBox = ({ userRequired = true, oldPwdRequired = false, validator, children, onOK }) => {
10
10
 
11
11
  const [form, setForm] = useState({
12
12
  user: "",
@@ -110,10 +110,7 @@ export const ResetPasswordBox = ({ title, userRequired = true, oldPwdRequired =
110
110
 
111
111
  return (
112
112
  <div className="reset-password-box">
113
- <header>
114
- {title ? <div className="title"><Text>{title}</Text></div> : null}
115
- </header>
116
- <main className={`reset-password-form`}>
113
+ <main className="reset-password-form">
117
114
 
118
115
  {userRequired ? <TextField id="user" className={userStyle} outlined icon="person" label={userLabel} lapse={100} onChange={changeField} onEnter={ok} /> : null}
119
116
  {userRequired ? errors.user ? <div className="error-message"><Text>{errors.user}</Text></div> : null : null}
@@ -7,7 +7,6 @@ import { ResetPasswordBox } from './ResetPasswordBox'
7
7
  export const ResetPasswordBoxTest = (prop) => {
8
8
 
9
9
  const config = {
10
- title: 'Reset Password',
11
10
  userRequired: true,
12
11
  oldPwdRequired: true,
13
12
  lang: 'EN',
@@ -9,7 +9,7 @@ import { ChangeUserPasswordDialog } from './dialogs'
9
9
  export const ForgetUserPasswordAction = (props) => {
10
10
 
11
11
  const site = useContext(SiteContext)
12
- const { user, icon = true, onOK, onSuccess } = props
12
+ const { user, icon = false, onOK, onSuccess } = props
13
13
 
14
14
  async function execute() {
15
15
  try {
@@ -35,7 +35,7 @@ export const ForgetUserPasswordAction = (props) => {
35
35
  return icon ? (
36
36
  <Icon icon="mail_lock" clickable action={execute} size="small" tooltip={{ text: label, top: "-.5rem", left: "-14rem" }} />
37
37
  ) : (
38
- <Button label={label} action={execute} outlined className="" />
38
+ <Button label={label} action={execute} className="" />
39
39
  )
40
40
  }
41
41
 
@@ -0,0 +1,125 @@
1
+ import { HTTPClient, Session } from "../../http"
2
+ const API_URL = typeof process !== 'undefined' ? process.env.REACT_APP_API : window.API
3
+ const http = HTTPClient(window.API || API_URL, Session)
4
+
5
+ /**
6
+ * LOGIN_API
7
+ */
8
+ export const LOGIN_API = {
9
+
10
+ /**
11
+ * Change Password
12
+ * Request API to change user password
13
+ *
14
+ * @param {*} id
15
+ * @param {*} form
16
+ * @returns
17
+ *
18
+ * PATCH /users/:id
19
+ * payload: { old_Password, new_Password }
20
+ *
21
+ */
22
+ changePassword(id, form) {
23
+ const body = JSON.stringify(form)
24
+ return http.PATCH(`/users/${id}`, body)
25
+ },
26
+
27
+ /**
28
+ * Forget user password
29
+ * Request API to send a message to user email with a link to reset password
30
+ *
31
+ * @param {*} email
32
+ * @returns
33
+ *
34
+ * POST /users/forget
35
+ * payload: { email }
36
+ */
37
+ forgetUserPassword(email) {
38
+ const body = JSON.stringify({ email })
39
+ return http.POST(`/users/forget`, body)
40
+ },
41
+
42
+ /**
43
+ * Reset user password
44
+ * Request API to reset user password
45
+ *
46
+ * @param {*} token
47
+ * @param {*} password
48
+ * @returns
49
+ *
50
+ * POST /users/assign
51
+ * payload: { token, password }
52
+ */
53
+ resetUserPassword(token, password) {
54
+ const body = JSON.stringify({ token, password })
55
+ return http.POST(`/users/assign`, body)
56
+ }
57
+ }
58
+
59
+ /**
60
+ * LOGIN_CONTEXT
61
+ */
62
+ export const LOGIN_CONTEXT = {
63
+
64
+ /**
65
+ * Change user password
66
+ *
67
+ * @param {*} user
68
+ * @param {*} old_Password
69
+ * @param {*} new_Password
70
+ */
71
+ async changeUserPassword(user, old_Password, new_Password) {
72
+ try {
73
+ const response = await LOGIN_API.changePassword(user, { old_Password, new_Password });
74
+ console.log("changeUserPassword", response);
75
+ } catch (error) {
76
+ console.log("changeUserPassword error", error);
77
+ throw error;
78
+ }
79
+ },
80
+
81
+ /**
82
+ * Unlock user
83
+ *
84
+ * @param {*} id
85
+ */
86
+ async unlockUser(id) {
87
+ try {
88
+ await API.changePassword(id, { unlock: true });
89
+ } catch (error) {
90
+ console.log("unblockUser error", error);
91
+ throw error;
92
+ }
93
+ },
94
+
95
+ /**
96
+ * Forget user password
97
+ *
98
+ * @param {*} email
99
+ */
100
+ async forgetUserPassword(email) {
101
+ try {
102
+ await API.forgetUserPassword(email);
103
+ } catch (error) {
104
+ console.log("forgetUserPassword error", error);
105
+ throw error;
106
+ }
107
+ },
108
+
109
+ /**
110
+ * Reset Password
111
+ *
112
+ * @param {*} token
113
+ * @param {*} password
114
+ * @param {*} onError
115
+ * @param {*} onSuccess
116
+ */
117
+ async resetUserPassword(token, password, onError, onSuccess) {
118
+ try {
119
+ await API.resetUserPassword(token, password);
120
+ onSuccess();
121
+ } catch (error) {
122
+ onError(error);
123
+ }
124
+ }
125
+ }
@@ -31,7 +31,7 @@ export const ChangeUserPasswordDialog = (props) => {
31
31
  )
32
32
  }
33
33
 
34
- const title = <div className="dialog-title"><Text>Change Password</Text>></div>
34
+ const title = <div className="dialog-title"><Text>Change Password</Text></div>
35
35
  return (
36
36
  <Dialog title={title} className="change-password-dialog" toolbar={<Toolbar />} >
37
37
  { error && (<div className="dialog-error-message"><Icon icon="warning" />{error}</div>) }
@@ -1,5 +1,5 @@
1
- const login_commons = require('./login_commons');
2
- const { validatePassword } = login_commons;
1
+ const validations = require('./validations');
2
+ const { validatePassword } = validations;
3
3
 
4
4
  describe('validatePassword', () => {
5
5
  test('debería devolver un error si la longitud es menor a 15 caracteres', () => {