@blaze-cms/react-page-builder 0.125.0-alpha.15 → 0.125.0-alpha.18
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/CHANGELOG.md +12 -0
- package/README.md +2 -1
- package/lib/components/Banner/index.js +1 -1
- package/lib/components/Banner/index.js.map +1 -1
- package/lib/components/Card/Card.js +31 -22
- package/lib/components/Card/Card.js.map +1 -1
- package/lib/components/Card/CardContainer.js +2 -1
- package/lib/components/Card/CardContainer.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryTypes/index.js +5 -5
- package/lib/components/DataSummary/DataSummaryTypes/index.js.map +1 -1
- package/lib/components/Image/GlobalLightbox/index.js +1 -1
- package/lib/components/Image/GlobalLightbox/index.js.map +1 -1
- package/lib/components/LazyImage/index.js +1 -1
- package/lib/components/LazyImage/index.js.map +1 -1
- package/lib/components/List/components/Cards/CardsRender.js.map +1 -1
- package/lib/components/List/components/Cards/CardsRenderItem.js +2 -1
- package/lib/components/List/components/Cards/CardsRenderItem.js.map +1 -1
- package/lib/components/Video/providers/JWPlayer/JWPlayerController.js +2 -1
- package/lib/components/Video/providers/JWPlayer/JWPlayerController.js.map +1 -1
- package/lib/components/Video/providers/get-provider.js +4 -4
- package/lib/components/Video/providers/get-provider.js.map +1 -1
- package/lib/components/index.js +28 -43
- package/lib/components/index.js.map +1 -1
- package/lib/constants/index.js +2 -14
- package/lib/constants/index.js.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib-es/components/Card/Card.js +15 -5
- package/lib-es/components/Card/Card.js.map +1 -1
- package/lib-es/components/Card/CardContainer.js +2 -1
- package/lib-es/components/Card/CardContainer.js.map +1 -1
- package/lib-es/components/List/components/Cards/CardsRender.js.map +1 -1
- package/lib-es/components/List/components/Cards/CardsRenderItem.js +2 -1
- package/lib-es/components/List/components/Cards/CardsRenderItem.js.map +1 -1
- package/lib-es/components/index.js +0 -3
- package/lib-es/components/index.js.map +1 -1
- package/lib-es/constants/index.js +1 -7
- package/lib-es/constants/index.js.map +1 -1
- package/lib-es/index.js +1 -1
- package/lib-es/index.js.map +1 -1
- package/package.json +7 -7
- package/src/components/Card/Card.js +13 -3
- package/src/components/Card/CardContainer.js +2 -1
- package/src/components/List/components/Cards/CardsRender.js +1 -0
- package/src/components/List/components/Cards/CardsRenderItem.js +2 -1
- package/src/components/index.js +1 -7
- package/src/constants/index.js +0 -13
- package/src/index.js +1 -1
- package/tests/unit/src/components/Card/Card.test.js +18 -7
- package/tests/unit/src/components/Card/__snapshots__/Card.test.js.snap +5 -0
- package/tests/unit/src/components/__snapshots__/index.test.js.snap +0 -12
- package/lib/components/Login/LoggedInMessage.js +0 -28
- package/lib/components/Login/LoggedInMessage.js.map +0 -1
- package/lib/components/Login/Login.js +0 -135
- package/lib/components/Login/Login.js.map +0 -1
- package/lib/components/Login/LoginForm.js +0 -112
- package/lib/components/Login/LoginForm.js.map +0 -1
- package/lib/components/Login/helpers/check-gtm-children.js +0 -42
- package/lib/components/Login/helpers/check-gtm-children.js.map +0 -1
- package/lib/components/Login/helpers/get-url-to-use.js +0 -18
- package/lib/components/Login/helpers/get-url-to-use.js.map +0 -1
- package/lib/components/Login/helpers/index.js +0 -22
- package/lib/components/Login/helpers/index.js.map +0 -1
- package/lib/components/Login/index.js +0 -12
- package/lib/components/Login/index.js.map +0 -1
- package/lib/components/PasswordReset/PasswordReset.js +0 -172
- package/lib/components/PasswordReset/PasswordReset.js.map +0 -1
- package/lib/components/PasswordReset/helpers/index.js +0 -15
- package/lib/components/PasswordReset/helpers/index.js.map +0 -1
- package/lib/components/PasswordReset/helpers/validatePassword.js +0 -16
- package/lib/components/PasswordReset/helpers/validatePassword.js.map +0 -1
- package/lib/components/PasswordReset/index.js +0 -12
- package/lib/components/PasswordReset/index.js.map +0 -1
- package/lib/components/PasswordResetRequest/PasswordResetRequest.js +0 -114
- package/lib/components/PasswordResetRequest/PasswordResetRequest.js.map +0 -1
- package/lib/components/PasswordResetRequest/index.js +0 -12
- package/lib/components/PasswordResetRequest/index.js.map +0 -1
- package/lib-es/components/Login/LoggedInMessage.js +0 -18
- package/lib-es/components/Login/LoggedInMessage.js.map +0 -1
- package/lib-es/components/Login/Login.js +0 -83
- package/lib-es/components/Login/Login.js.map +0 -1
- package/lib-es/components/Login/LoginForm.js +0 -89
- package/lib-es/components/Login/LoginForm.js.map +0 -1
- package/lib-es/components/Login/helpers/check-gtm-children.js +0 -35
- package/lib-es/components/Login/helpers/check-gtm-children.js.map +0 -1
- package/lib-es/components/Login/helpers/get-url-to-use.js +0 -10
- package/lib-es/components/Login/helpers/get-url-to-use.js.map +0 -1
- package/lib-es/components/Login/helpers/index.js +0 -4
- package/lib-es/components/Login/helpers/index.js.map +0 -1
- package/lib-es/components/Login/index.js +0 -3
- package/lib-es/components/Login/index.js.map +0 -1
- package/lib-es/components/PasswordReset/PasswordReset.js +0 -144
- package/lib-es/components/PasswordReset/PasswordReset.js.map +0 -1
- package/lib-es/components/PasswordReset/helpers/index.js +0 -3
- package/lib-es/components/PasswordReset/helpers/index.js.map +0 -1
- package/lib-es/components/PasswordReset/helpers/validatePassword.js +0 -7
- package/lib-es/components/PasswordReset/helpers/validatePassword.js.map +0 -1
- package/lib-es/components/PasswordReset/index.js +0 -3
- package/lib-es/components/PasswordReset/index.js.map +0 -1
- package/lib-es/components/PasswordResetRequest/PasswordResetRequest.js +0 -92
- package/lib-es/components/PasswordResetRequest/PasswordResetRequest.js.map +0 -1
- package/lib-es/components/PasswordResetRequest/index.js +0 -3
- package/lib-es/components/PasswordResetRequest/index.js.map +0 -1
- package/src/components/Login/LoggedInMessage.js +0 -24
- package/src/components/Login/Login.js +0 -74
- package/src/components/Login/LoginForm.js +0 -81
- package/src/components/Login/helpers/check-gtm-children.js +0 -30
- package/src/components/Login/helpers/get-url-to-use.js +0 -6
- package/src/components/Login/helpers/index.js +0 -4
- package/src/components/Login/index.js +0 -3
- package/src/components/PasswordReset/PasswordReset.js +0 -120
- package/src/components/PasswordReset/helpers/index.js +0 -3
- package/src/components/PasswordReset/helpers/validatePassword.js +0 -8
- package/src/components/PasswordReset/index.js +0 -3
- package/src/components/PasswordResetRequest/PasswordResetRequest.js +0 -82
- package/src/components/PasswordResetRequest/index.js +0 -3
- package/tests/unit/src/components/Login/Login.test.js +0 -36
- package/tests/unit/src/components/Login/__snapshots__/Login.test.js.snap +0 -103
- package/tests/unit/src/components/Login/helpers/check-gtm-children.test.js +0 -60
- package/tests/unit/src/components/Login/helpers/get-url-to-use.test.js +0 -15
- package/tests/unit/src/components/PasswordReset/PasswordReset.test.js +0 -85
- package/tests/unit/src/components/PasswordReset/__snapshots__/PasswordReset.test.js.snap +0 -83
- package/tests/unit/src/components/PasswordReset/helpers/validatePassword.test.js +0 -21
- package/tests/unit/src/components/PasswordResetRequest/PasswordResetRequest.test.js +0 -79
- package/tests/unit/src/components/PasswordResetRequest/__snapshots__/PasswordResetRequest.test.js.snap +0 -39
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PasswordReset.js","names":["React","useState","PropTypes","Input","Button","useMutation","useRouter","parseUrl","RESET_USER_PASSWORD_MUTATION","validatePassword","withTitle","GRAPH_QL_ERROR","PASSWORD_CONFIRM_MESSAGE","PASSWORD_VALIDATION_MESSAGE","hasChildren","PasswordReset","children","modifier","router","asPath","query","token","displayChildren","setShouldDisplayChildren","formValues","setFormValues","password","passwordConfirm","validationErrors","setValidationErrors","errorMessageToDisplay","setErrorMessage","passwordResetMutation","onCompleted","resetUserPasswordResult","result","extras","redirectUrl","push","shallow","onError","message","parsedMessage","replace","handleChange","event","target","name","iName","value","iValue","handleSubmit","e","preventDefault","isPasswordValid","variables","input","isDisabled","shouldDisplayChildren","propTypes","string","oneOfType","arrayOf","node","defaultProps"],"sources":["../../../src/components/PasswordReset/PasswordReset.js"],"sourcesContent":["import React, { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport Input from '@blaze-react/input';\nimport Button from '@blaze-react/button';\nimport { useMutation } from '@apollo/client';\nimport { useRouter } from 'next/router';\nimport { parseUrl } from 'query-string';\nimport { RESET_USER_PASSWORD_MUTATION } from '@blaze-cms/core-auth-ui';\nimport { validatePassword } from './helpers';\nimport { withTitle } from '../../HOC';\nimport {\n GRAPH_QL_ERROR,\n PASSWORD_CONFIRM_MESSAGE,\n PASSWORD_VALIDATION_MESSAGE\n} from '../../constants';\nimport { hasChildren } from '../../helpers';\n\nconst PasswordReset = ({ children, modifier }) => {\n const router = useRouter();\n const { asPath } = router;\n const { query: { token } = {} } = parseUrl(asPath);\n const [displayChildren, setShouldDisplayChildren] = useState(false);\n const [formValues, setFormValues] = useState({ password: '', passwordConfirm: '' });\n const [validationErrors, setValidationErrors] = useState([]);\n const [errorMessageToDisplay, setErrorMessage] = useState(null);\n const { password, passwordConfirm } = formValues;\n\n const [passwordResetMutation] = useMutation(RESET_USER_PASSWORD_MUTATION, {\n onCompleted: ({ resetUserPasswordResult }) => {\n const {\n result: { extras }\n } =\n resetUserPasswordResult || {};\n const { redirectUrl } = extras || {};\n setShouldDisplayChildren(true);\n setErrorMessage(null);\n setValidationErrors([false, false]);\n if (redirectUrl) {\n router.push(`/Resolver`, `${asPath}&redirectUrl=${redirectUrl}`, { shallow: true });\n }\n },\n onError: ({ message }) => {\n const parsedMessage = message.replace(GRAPH_QL_ERROR, '');\n setErrorMessage(parsedMessage);\n }\n });\n\n const handleChange = ({ event }) => {\n const {\n target: { name: iName, value: iValue }\n } = event;\n\n if (iName === 'password') setFormValues({ ...formValues, password: iValue });\n if (iName === 'passwordConfirm') setFormValues({ ...formValues, passwordConfirm: iValue });\n };\n\n const handleSubmit = e => {\n e.preventDefault();\n const isPasswordValid = validatePassword(password);\n if (!isPasswordValid) return setValidationErrors([true, false]);\n if (password !== passwordConfirm) return setValidationErrors([false, true]);\n passwordResetMutation({\n variables: { input: { token, password } }\n });\n };\n\n const isDisabled = !passwordConfirm || !password;\n const shouldDisplayChildren = displayChildren && hasChildren(children);\n if (!token) return null;\n\n return (\n <div className={modifier}>\n {!displayChildren && (\n <form id=\"passwordReset\" onSubmit={handleSubmit}>\n <Input\n id=\"password\"\n type=\"password\"\n name=\"password\"\n label=\"Password\"\n required\n error={validationErrors[0]}\n validationMessage={PASSWORD_VALIDATION_MESSAGE}\n onChange={handleChange}\n value={password}\n />\n <Input\n id=\"passwordConfirm\"\n type=\"password\"\n name=\"passwordConfirm\"\n label=\"Confirm New Password\"\n required\n error={validationErrors[1]}\n validationMessage={PASSWORD_CONFIRM_MESSAGE}\n onChange={handleChange}\n value={passwordConfirm}\n />\n </form>\n )}\n {!displayChildren && (\n <Button type=\"submit\" name=\"button\" form=\"passwordReset\" disabled={isDisabled}>\n Reset Password\n </Button>\n )}\n {!!errorMessageToDisplay && <div className=\"error_message\">{errorMessageToDisplay}</div>}\n {shouldDisplayChildren && <div>{children}</div>}\n </div>\n );\n};\n\nPasswordReset.propTypes = {\n modifier: PropTypes.string,\n children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])\n};\n\nPasswordReset.defaultProps = {\n modifier: '',\n children: null\n};\n\nexport default withTitle(PasswordReset);\n"],"mappings":";;;AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,KAAK,MAAM,oBAAoB;AACtC,OAAOC,MAAM,MAAM,qBAAqB;AACxC,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,QAAQ,QAAQ,cAAc;AACvC,SAASC,4BAA4B,QAAQ,yBAAyB;AACtE,SAASC,gBAAgB,QAAQ,WAAW;AAC5C,SAASC,SAAS,QAAQ,WAAW;AACrC,SACEC,cAAc,EACdC,wBAAwB,EACxBC,2BAA2B,QACtB,iBAAiB;AACxB,SAASC,WAAW,QAAQ,eAAe;AAE3C,MAAMC,aAAa,GAAG,CAAC;EAAEC,QAAQ;EAAEC;AAAS,CAAC,KAAK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1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["validatePassword"],"sources":["../../../../src/components/PasswordReset/helpers/index.js"],"sourcesContent":["import validatePassword from './validatePassword';\n\nexport { validatePassword };\n"],"mappings":"AAAA,OAAOA,gBAAgB,MAAM,oBAAoB;AAEjD,SAASA,gBAAgB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validatePassword.js","names":["PASSWORD_REGEX","validatePassword","password","test"],"sources":["../../../../src/components/PasswordReset/helpers/validatePassword.js"],"sourcesContent":["import { PASSWORD_REGEX } from '../../../constants';\n\nconst validatePassword = password => {\n if (!password) return false;\n return PASSWORD_REGEX.test(password);\n};\n\nexport default validatePassword;\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,oBAAoB;AAEnD,MAAMC,gBAAgB,GAAGC,QAAQ,IAAI;EACnC,IAAI,CAACA,QAAQ,EAAE,OAAO,KAAK;EAC3B,OAAOF,cAAc,CAACG,IAAI,CAACD,QAAQ,CAAC;AACtC,CAAC;AAED,eAAeD,gBAAgB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["PasswordReset"],"sources":["../../../src/components/PasswordReset/index.js"],"sourcesContent":["import PasswordReset from './PasswordReset';\n\nexport default PasswordReset;\n"],"mappings":"AAAA,OAAOA,aAAa,MAAM,iBAAiB;AAE3C,eAAeA,aAAa"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import Input from '@blaze-react/input';
|
|
4
|
-
import Button from '@blaze-react/button';
|
|
5
|
-
import { useMutation } from '@apollo/client';
|
|
6
|
-
import { useRouter } from 'next/router';
|
|
7
|
-
import { checkIfLoggedIn, REQUEST_USER_PASSWORD_RESET_MUTATION } from '@blaze-cms/core-auth-ui';
|
|
8
|
-
import { GRAPH_QL_ERROR } from '../../constants';
|
|
9
|
-
import { hasChildren } from '../../helpers';
|
|
10
|
-
const PasswordResetRequest = ({
|
|
11
|
-
children,
|
|
12
|
-
modifier
|
|
13
|
-
}) => {
|
|
14
|
-
const {
|
|
15
|
-
id: userId
|
|
16
|
-
} = checkIfLoggedIn();
|
|
17
|
-
const router = useRouter();
|
|
18
|
-
const {
|
|
19
|
-
asPath
|
|
20
|
-
} = router;
|
|
21
|
-
const [displayChildren, setShouldDisplayChildren] = useState(false);
|
|
22
|
-
const [errorMessageToDisplay, setErrorMessage] = useState(null);
|
|
23
|
-
const [email, setEmail] = useState('');
|
|
24
|
-
const [requestUserPasswordResetMutation] = useMutation(REQUEST_USER_PASSWORD_RESET_MUTATION, {
|
|
25
|
-
onCompleted: () => {
|
|
26
|
-
setShouldDisplayChildren(true);
|
|
27
|
-
setErrorMessage(null);
|
|
28
|
-
},
|
|
29
|
-
onError: ({
|
|
30
|
-
message
|
|
31
|
-
}) => {
|
|
32
|
-
const parsedMessage = message.replace(GRAPH_QL_ERROR, '');
|
|
33
|
-
setErrorMessage(parsedMessage);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
const isDisabled = !email;
|
|
37
|
-
const displayValidChildren = displayChildren && hasChildren(children);
|
|
38
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
39
|
-
className: modifier
|
|
40
|
-
}, !displayChildren && /*#__PURE__*/React.createElement("form", {
|
|
41
|
-
id: "passwordResetRequest",
|
|
42
|
-
onSubmit: e => {
|
|
43
|
-
e.preventDefault();
|
|
44
|
-
if (isDisabled) return;
|
|
45
|
-
requestUserPasswordResetMutation({
|
|
46
|
-
variables: {
|
|
47
|
-
input: {
|
|
48
|
-
email,
|
|
49
|
-
userId,
|
|
50
|
-
extras: {
|
|
51
|
-
redirectUrl: asPath
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}, /*#__PURE__*/React.createElement(Input, {
|
|
58
|
-
key: "email",
|
|
59
|
-
type: "email",
|
|
60
|
-
name: "email",
|
|
61
|
-
label: "Email",
|
|
62
|
-
required: true,
|
|
63
|
-
onChange: ({
|
|
64
|
-
event
|
|
65
|
-
}) => {
|
|
66
|
-
const {
|
|
67
|
-
target: {
|
|
68
|
-
value
|
|
69
|
-
}
|
|
70
|
-
} = event;
|
|
71
|
-
setEmail(value);
|
|
72
|
-
},
|
|
73
|
-
value: email
|
|
74
|
-
})), !displayChildren && /*#__PURE__*/React.createElement(Button, {
|
|
75
|
-
type: "submit",
|
|
76
|
-
name: "button",
|
|
77
|
-
form: "passwordResetRequest",
|
|
78
|
-
disabled: isDisabled
|
|
79
|
-
}, "Request Password Reset"), !!errorMessageToDisplay && /*#__PURE__*/React.createElement("div", {
|
|
80
|
-
className: "error_message"
|
|
81
|
-
}, errorMessageToDisplay), displayValidChildren && /*#__PURE__*/React.createElement("div", null, children));
|
|
82
|
-
};
|
|
83
|
-
PasswordResetRequest.propTypes = {
|
|
84
|
-
modifier: PropTypes.string,
|
|
85
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
|
|
86
|
-
};
|
|
87
|
-
PasswordResetRequest.defaultProps = {
|
|
88
|
-
modifier: '',
|
|
89
|
-
children: null
|
|
90
|
-
};
|
|
91
|
-
export default PasswordResetRequest;
|
|
92
|
-
//# sourceMappingURL=PasswordResetRequest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PasswordResetRequest.js","names":["React","useState","PropTypes","Input","Button","useMutation","useRouter","checkIfLoggedIn","REQUEST_USER_PASSWORD_RESET_MUTATION","GRAPH_QL_ERROR","hasChildren","PasswordResetRequest","children","modifier","id","userId","router","asPath","displayChildren","setShouldDisplayChildren","errorMessageToDisplay","setErrorMessage","email","setEmail","requestUserPasswordResetMutation","onCompleted","onError","message","parsedMessage","replace","isDisabled","displayValidChildren","e","preventDefault","variables","input","extras","redirectUrl","event","target","value","propTypes","string","oneOfType","arrayOf","node","defaultProps"],"sources":["../../../src/components/PasswordResetRequest/PasswordResetRequest.js"],"sourcesContent":["import React, { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport Input from '@blaze-react/input';\nimport Button from '@blaze-react/button';\nimport { useMutation } from '@apollo/client';\nimport { useRouter } from 'next/router';\nimport { checkIfLoggedIn, REQUEST_USER_PASSWORD_RESET_MUTATION } from '@blaze-cms/core-auth-ui';\nimport { GRAPH_QL_ERROR } from '../../constants';\nimport { hasChildren } from '../../helpers';\n\nconst PasswordResetRequest = ({ children, modifier }) => {\n const { id: userId } = checkIfLoggedIn();\n const router = useRouter();\n const { asPath } = router;\n const [displayChildren, setShouldDisplayChildren] = useState(false);\n const [errorMessageToDisplay, setErrorMessage] = useState(null);\n const [email, setEmail] = useState('');\n\n const [requestUserPasswordResetMutation] = useMutation(REQUEST_USER_PASSWORD_RESET_MUTATION, {\n onCompleted: () => {\n setShouldDisplayChildren(true);\n setErrorMessage(null);\n },\n onError: ({ message }) => {\n const parsedMessage = message.replace(GRAPH_QL_ERROR, '');\n setErrorMessage(parsedMessage);\n }\n });\n\n const isDisabled = !email;\n const displayValidChildren = displayChildren && hasChildren(children);\n\n return (\n <div className={modifier}>\n {!displayChildren && (\n <form\n id=\"passwordResetRequest\"\n onSubmit={e => {\n e.preventDefault();\n if (isDisabled) return;\n requestUserPasswordResetMutation({\n variables: { input: { email, userId, extras: { redirectUrl: asPath } } }\n });\n }}>\n <Input\n key=\"email\"\n type=\"email\"\n name=\"email\"\n label=\"Email\"\n required\n onChange={({ event }) => {\n const {\n target: { value }\n } = event;\n setEmail(value);\n }}\n value={email}\n />\n </form>\n )}\n {!displayChildren && (\n <Button type=\"submit\" name=\"button\" form=\"passwordResetRequest\" disabled={isDisabled}>\n Request Password Reset\n </Button>\n )}\n {!!errorMessageToDisplay && <div className=\"error_message\">{errorMessageToDisplay}</div>}\n {displayValidChildren && <div>{children}</div>}\n </div>\n );\n};\n\nPasswordResetRequest.propTypes = {\n modifier: PropTypes.string,\n children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])\n};\n\nPasswordResetRequest.defaultProps = {\n modifier: '',\n children: null\n};\n\nexport default PasswordResetRequest;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,KAAK,MAAM,oBAAoB;AACtC,OAAOC,MAAM,MAAM,qBAAqB;AACxC,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,eAAe,EAAEC,oCAAoC,QAAQ,yBAAyB;AAC/F,SAASC,cAAc,QAAQ,iBAAiB;AAChD,SAASC,WAAW,QAAQ,eAAe;AAE3C,MAAMC,oBAAoB,GAAG,CAAC;EAAEC,QAAQ;EAAEC;AAAS,CAAC,KAAK;EACvD,MAAM;IAAEC,EAAE,EAAEC;EAAO,CAAC,GAAGR,eAAe,EAAE;EACxC,MAAMS,MAAM,GAAGV,SAAS,EAAE;EAC1B,MAAM;IAAEW;EAAO,CAAC,GAAGD,MAAM;EACzB,MAAM,CAACE,eAAe,EAAEC,wBAAwB,CAAC,GAAGlB,QAAQ,CAAC,KAAK,CAAC;EACnE,MAAM,CAACmB,qBAAqB,EAAEC,eAAe,CAAC,GAAGpB,QAAQ,CAAC,IAAI,CAAC;EAC/D,MAAM,CAACqB,KAAK,EAAEC,QAAQ,CAAC,GAAGtB,QAAQ,CAAC,EAAE,CAAC;EAEtC,MAAM,CAACuB,gCAAgC,CAAC,GAAGnB,WAAW,CAACG,oCAAoC,EAAE;IAC3FiB,WAAW,EAAE,MAAM;MACjBN,wBAAwB,CAAC,IAAI,CAAC;MAC9BE,eAAe,CAAC,IAAI,CAAC;IACvB,CAAC;IACDK,OAAO,EAAE,CAAC;MAAEC;IAAQ,CAAC,KAAK;MACxB,MAAMC,aAAa,GAAGD,OAAO,CAACE,OAAO,CAACpB,cAAc,EAAE,EAAE,CAAC;MACzDY,eAAe,CAACO,aAAa,CA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zC,SAAS,CAAC0C,OAAO,CAAC1C,SAAS,CAAC2C,IAAI,CAAC,EAAE3C,SAAS,CAAC2C,IAAI,CAAC;AACnF,CAAC;AAEDlC,oBAAoB,CAACmC,YAAY,GAAG;EAClCjC,QAAQ,EAAE,EAAE;EACZD,QAAQ,EAAE;AACZ,CAAC;AAED,eAAeD,oBAAoB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["PasswordResetRequest"],"sources":["../../../src/components/PasswordResetRequest/index.js"],"sourcesContent":["import PasswordResetRequest from './PasswordResetRequest';\n\nexport default PasswordResetRequest;\n"],"mappings":"AAAA,OAAOA,oBAAoB,MAAM,wBAAwB;AAEzD,eAAeA,oBAAoB"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
|
|
4
|
-
const LoggedInMessage = ({ goToUrl, urlToUse }) => (
|
|
5
|
-
<span>
|
|
6
|
-
You are already logged in please{' '}
|
|
7
|
-
<a
|
|
8
|
-
onClick={e => {
|
|
9
|
-
e.preventDefault();
|
|
10
|
-
goToUrl(true);
|
|
11
|
-
}}
|
|
12
|
-
href={urlToUse}>
|
|
13
|
-
click here
|
|
14
|
-
</a>{' '}
|
|
15
|
-
to reload your content access
|
|
16
|
-
</span>
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
LoggedInMessage.propTypes = {
|
|
20
|
-
goToUrl: PropTypes.func.isRequired,
|
|
21
|
-
urlToUse: PropTypes.string.isRequired
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default LoggedInMessage;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { handleLogin, checkIfLoggedIn, LOGIN_MUTATION } from '@blaze-cms/core-auth-ui';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import { useMutation } from '@apollo/client';
|
|
5
|
-
import { useRouter } from 'next/router';
|
|
6
|
-
import { parseUrl } from 'query-string';
|
|
7
|
-
import LoggedInMessage from './LoggedInMessage';
|
|
8
|
-
import LoginForm from './LoginForm';
|
|
9
|
-
import { checkGtmChildren, getUrlToUse } from './helpers';
|
|
10
|
-
import { GRAPH_QL_ERROR } from '../../constants';
|
|
11
|
-
|
|
12
|
-
function shouldShowAlreadyLoggedInMessage(called) {
|
|
13
|
-
const { isLoggedIn } = checkIfLoggedIn();
|
|
14
|
-
return !called && isLoggedIn;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const Login = ({ modifier, url, children }) => {
|
|
18
|
-
const router = useRouter();
|
|
19
|
-
const { asPath } = router;
|
|
20
|
-
const { query: { redirectUrl } = {} } = parseUrl(asPath);
|
|
21
|
-
|
|
22
|
-
const [isLoginDone, setIsLoginDone] = useState(false);
|
|
23
|
-
const [errorMessageToDisplay, setErrorMessage] = useState(null);
|
|
24
|
-
const urlToUse = getUrlToUse({ redirectUrl, url, asPath });
|
|
25
|
-
const goToUrl = reload => {
|
|
26
|
-
urlToUse === asPath && reload ? router.reload() : router.push('/Resolver', urlToUse);
|
|
27
|
-
};
|
|
28
|
-
const [hasOnSuccessChildren, updatedChildren] = checkGtmChildren(children, goToUrl);
|
|
29
|
-
|
|
30
|
-
const [loginMutation, { client, called }] = useMutation(LOGIN_MUTATION, {
|
|
31
|
-
update: (cache, { data }) => afterLogin(data),
|
|
32
|
-
onError: ({ message }) => {
|
|
33
|
-
const parsedMessage = message.replace(GRAPH_QL_ERROR, '');
|
|
34
|
-
setErrorMessage(parsedMessage);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const afterLogin = async data => {
|
|
39
|
-
if (!(await handleLogin(data, client))) return;
|
|
40
|
-
if (!hasOnSuccessChildren) goToUrl();
|
|
41
|
-
setIsLoginDone(true);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const showAlreadyLoggedInMessage = shouldShowAlreadyLoggedInMessage(called);
|
|
45
|
-
const shouldRenderForm = !showAlreadyLoggedInMessage && !isLoginDone;
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<>
|
|
49
|
-
{showAlreadyLoggedInMessage && <LoggedInMessage goToUrl={goToUrl} urlToUse={urlToUse} />}
|
|
50
|
-
{shouldRenderForm && (
|
|
51
|
-
<LoginForm
|
|
52
|
-
errorMessageToDisplay={errorMessageToDisplay}
|
|
53
|
-
loginMutation={loginMutation}
|
|
54
|
-
modifier={modifier}
|
|
55
|
-
/>
|
|
56
|
-
)}
|
|
57
|
-
{isLoginDone && updatedChildren}
|
|
58
|
-
</>
|
|
59
|
-
);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
Login.propTypes = {
|
|
63
|
-
modifier: PropTypes.string,
|
|
64
|
-
url: PropTypes.string,
|
|
65
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
Login.defaultProps = {
|
|
69
|
-
modifier: '',
|
|
70
|
-
url: '',
|
|
71
|
-
children: null
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export default Login;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import Input from '@blaze-react/input';
|
|
4
|
-
import Button from '@blaze-react/button';
|
|
5
|
-
import { Checkbox } from '@blaze-react/checkboxes';
|
|
6
|
-
import { EMAIL, PASSWORD, LOGIN_FORM } from '../../constants';
|
|
7
|
-
|
|
8
|
-
const LoginForm = ({ errorMessageToDisplay, loginMutation, modifier }) => {
|
|
9
|
-
const [email, setEmail] = useState('');
|
|
10
|
-
const [password, setPassword] = useState('');
|
|
11
|
-
const [rememberMe, setRememberMe] = useState(false);
|
|
12
|
-
|
|
13
|
-
const handleChange = ({ event }) => {
|
|
14
|
-
const {
|
|
15
|
-
target: { name: iName, value: iValue }
|
|
16
|
-
} = event;
|
|
17
|
-
|
|
18
|
-
if (iName === EMAIL) setEmail(iValue);
|
|
19
|
-
if (iName === PASSWORD) setPassword(iValue);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const isDisabled = !email || !password;
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<>
|
|
26
|
-
<form
|
|
27
|
-
id={LOGIN_FORM}
|
|
28
|
-
className={modifier}
|
|
29
|
-
onSubmit={e => {
|
|
30
|
-
e.preventDefault();
|
|
31
|
-
if (isDisabled) return;
|
|
32
|
-
loginMutation({
|
|
33
|
-
variables: { input: { identity: email, password, rememberMe } }
|
|
34
|
-
});
|
|
35
|
-
}}>
|
|
36
|
-
<Input
|
|
37
|
-
key="email"
|
|
38
|
-
type="email"
|
|
39
|
-
name="email"
|
|
40
|
-
placeholder="example@email.com"
|
|
41
|
-
label="Email"
|
|
42
|
-
required
|
|
43
|
-
onChange={handleChange}
|
|
44
|
-
value={email}
|
|
45
|
-
/>
|
|
46
|
-
<Input
|
|
47
|
-
key="password"
|
|
48
|
-
type="password"
|
|
49
|
-
name="password"
|
|
50
|
-
label="Password"
|
|
51
|
-
required
|
|
52
|
-
onChange={handleChange}
|
|
53
|
-
value={password}
|
|
54
|
-
/>
|
|
55
|
-
<Checkbox
|
|
56
|
-
checked={rememberMe}
|
|
57
|
-
label="Remember Me"
|
|
58
|
-
name="rememberme"
|
|
59
|
-
id="remember-me"
|
|
60
|
-
onChange={({ value: { checked } }) => setRememberMe(checked)}
|
|
61
|
-
/>
|
|
62
|
-
{!!errorMessageToDisplay && <div className="error_message">{errorMessageToDisplay}</div>}
|
|
63
|
-
</form>
|
|
64
|
-
<Button type="submit" name="button" form={LOGIN_FORM} disabled={isDisabled}>
|
|
65
|
-
Login
|
|
66
|
-
</Button>
|
|
67
|
-
</>
|
|
68
|
-
);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
LoginForm.propTypes = {
|
|
72
|
-
errorMessageToDisplay: PropTypes.string,
|
|
73
|
-
modifier: PropTypes.string.isRequired,
|
|
74
|
-
loginMutation: PropTypes.func.isRequired
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
LoginForm.defaultProps = {
|
|
78
|
-
errorMessageToDisplay: PropTypes.string.isRequired
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export default LoginForm;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const checkGtmChildren = (children, handleOnSuccess) => {
|
|
2
|
-
let hasOnSuccessChildren = false;
|
|
3
|
-
if (!children || Array.isArray(children)) return [hasOnSuccessChildren, children];
|
|
4
|
-
const {
|
|
5
|
-
props: {
|
|
6
|
-
children: [, allChildren]
|
|
7
|
-
}
|
|
8
|
-
} = children;
|
|
9
|
-
|
|
10
|
-
if (allChildren && allChildren.length) {
|
|
11
|
-
allChildren.forEach(({ props }) => {
|
|
12
|
-
let { component: { settings: { gtmEvents } } = {} } = props;
|
|
13
|
-
if (gtmEvents) {
|
|
14
|
-
gtmEvents = gtmEvents.map(gtmEvent => {
|
|
15
|
-
const updatedEvent = gtmEvent;
|
|
16
|
-
if (gtmEvent.eventTrigger === 'onSuccess') {
|
|
17
|
-
updatedEvent.handleOnSuccess = handleOnSuccess;
|
|
18
|
-
hasOnSuccessChildren = true;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return updatedEvent;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return [hasOnSuccessChildren, children];
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export default checkGtmChildren;
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import Input from '@blaze-react/input';
|
|
4
|
-
import Button from '@blaze-react/button';
|
|
5
|
-
import { useMutation } from '@apollo/client';
|
|
6
|
-
import { useRouter } from 'next/router';
|
|
7
|
-
import { parseUrl } from 'query-string';
|
|
8
|
-
import { RESET_USER_PASSWORD_MUTATION } from '@blaze-cms/core-auth-ui';
|
|
9
|
-
import { validatePassword } from './helpers';
|
|
10
|
-
import { withTitle } from '../../HOC';
|
|
11
|
-
import {
|
|
12
|
-
GRAPH_QL_ERROR,
|
|
13
|
-
PASSWORD_CONFIRM_MESSAGE,
|
|
14
|
-
PASSWORD_VALIDATION_MESSAGE
|
|
15
|
-
} from '../../constants';
|
|
16
|
-
import { hasChildren } from '../../helpers';
|
|
17
|
-
|
|
18
|
-
const PasswordReset = ({ children, modifier }) => {
|
|
19
|
-
const router = useRouter();
|
|
20
|
-
const { asPath } = router;
|
|
21
|
-
const { query: { token } = {} } = parseUrl(asPath);
|
|
22
|
-
const [displayChildren, setShouldDisplayChildren] = useState(false);
|
|
23
|
-
const [formValues, setFormValues] = useState({ password: '', passwordConfirm: '' });
|
|
24
|
-
const [validationErrors, setValidationErrors] = useState([]);
|
|
25
|
-
const [errorMessageToDisplay, setErrorMessage] = useState(null);
|
|
26
|
-
const { password, passwordConfirm } = formValues;
|
|
27
|
-
|
|
28
|
-
const [passwordResetMutation] = useMutation(RESET_USER_PASSWORD_MUTATION, {
|
|
29
|
-
onCompleted: ({ resetUserPasswordResult }) => {
|
|
30
|
-
const {
|
|
31
|
-
result: { extras }
|
|
32
|
-
} =
|
|
33
|
-
resetUserPasswordResult || {};
|
|
34
|
-
const { redirectUrl } = extras || {};
|
|
35
|
-
setShouldDisplayChildren(true);
|
|
36
|
-
setErrorMessage(null);
|
|
37
|
-
setValidationErrors([false, false]);
|
|
38
|
-
if (redirectUrl) {
|
|
39
|
-
router.push(`/Resolver`, `${asPath}&redirectUrl=${redirectUrl}`, { shallow: true });
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
onError: ({ message }) => {
|
|
43
|
-
const parsedMessage = message.replace(GRAPH_QL_ERROR, '');
|
|
44
|
-
setErrorMessage(parsedMessage);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const handleChange = ({ event }) => {
|
|
49
|
-
const {
|
|
50
|
-
target: { name: iName, value: iValue }
|
|
51
|
-
} = event;
|
|
52
|
-
|
|
53
|
-
if (iName === 'password') setFormValues({ ...formValues, password: iValue });
|
|
54
|
-
if (iName === 'passwordConfirm') setFormValues({ ...formValues, passwordConfirm: iValue });
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const handleSubmit = e => {
|
|
58
|
-
e.preventDefault();
|
|
59
|
-
const isPasswordValid = validatePassword(password);
|
|
60
|
-
if (!isPasswordValid) return setValidationErrors([true, false]);
|
|
61
|
-
if (password !== passwordConfirm) return setValidationErrors([false, true]);
|
|
62
|
-
passwordResetMutation({
|
|
63
|
-
variables: { input: { token, password } }
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const isDisabled = !passwordConfirm || !password;
|
|
68
|
-
const shouldDisplayChildren = displayChildren && hasChildren(children);
|
|
69
|
-
if (!token) return null;
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<div className={modifier}>
|
|
73
|
-
{!displayChildren && (
|
|
74
|
-
<form id="passwordReset" onSubmit={handleSubmit}>
|
|
75
|
-
<Input
|
|
76
|
-
id="password"
|
|
77
|
-
type="password"
|
|
78
|
-
name="password"
|
|
79
|
-
label="Password"
|
|
80
|
-
required
|
|
81
|
-
error={validationErrors[0]}
|
|
82
|
-
validationMessage={PASSWORD_VALIDATION_MESSAGE}
|
|
83
|
-
onChange={handleChange}
|
|
84
|
-
value={password}
|
|
85
|
-
/>
|
|
86
|
-
<Input
|
|
87
|
-
id="passwordConfirm"
|
|
88
|
-
type="password"
|
|
89
|
-
name="passwordConfirm"
|
|
90
|
-
label="Confirm New Password"
|
|
91
|
-
required
|
|
92
|
-
error={validationErrors[1]}
|
|
93
|
-
validationMessage={PASSWORD_CONFIRM_MESSAGE}
|
|
94
|
-
onChange={handleChange}
|
|
95
|
-
value={passwordConfirm}
|
|
96
|
-
/>
|
|
97
|
-
</form>
|
|
98
|
-
)}
|
|
99
|
-
{!displayChildren && (
|
|
100
|
-
<Button type="submit" name="button" form="passwordReset" disabled={isDisabled}>
|
|
101
|
-
Reset Password
|
|
102
|
-
</Button>
|
|
103
|
-
)}
|
|
104
|
-
{!!errorMessageToDisplay && <div className="error_message">{errorMessageToDisplay}</div>}
|
|
105
|
-
{shouldDisplayChildren && <div>{children}</div>}
|
|
106
|
-
</div>
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
PasswordReset.propTypes = {
|
|
111
|
-
modifier: PropTypes.string,
|
|
112
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
PasswordReset.defaultProps = {
|
|
116
|
-
modifier: '',
|
|
117
|
-
children: null
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export default withTitle(PasswordReset);
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import Input from '@blaze-react/input';
|
|
4
|
-
import Button from '@blaze-react/button';
|
|
5
|
-
import { useMutation } from '@apollo/client';
|
|
6
|
-
import { useRouter } from 'next/router';
|
|
7
|
-
import { checkIfLoggedIn, REQUEST_USER_PASSWORD_RESET_MUTATION } from '@blaze-cms/core-auth-ui';
|
|
8
|
-
import { GRAPH_QL_ERROR } from '../../constants';
|
|
9
|
-
import { hasChildren } from '../../helpers';
|
|
10
|
-
|
|
11
|
-
const PasswordResetRequest = ({ children, modifier }) => {
|
|
12
|
-
const { id: userId } = checkIfLoggedIn();
|
|
13
|
-
const router = useRouter();
|
|
14
|
-
const { asPath } = router;
|
|
15
|
-
const [displayChildren, setShouldDisplayChildren] = useState(false);
|
|
16
|
-
const [errorMessageToDisplay, setErrorMessage] = useState(null);
|
|
17
|
-
const [email, setEmail] = useState('');
|
|
18
|
-
|
|
19
|
-
const [requestUserPasswordResetMutation] = useMutation(REQUEST_USER_PASSWORD_RESET_MUTATION, {
|
|
20
|
-
onCompleted: () => {
|
|
21
|
-
setShouldDisplayChildren(true);
|
|
22
|
-
setErrorMessage(null);
|
|
23
|
-
},
|
|
24
|
-
onError: ({ message }) => {
|
|
25
|
-
const parsedMessage = message.replace(GRAPH_QL_ERROR, '');
|
|
26
|
-
setErrorMessage(parsedMessage);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const isDisabled = !email;
|
|
31
|
-
const displayValidChildren = displayChildren && hasChildren(children);
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<div className={modifier}>
|
|
35
|
-
{!displayChildren && (
|
|
36
|
-
<form
|
|
37
|
-
id="passwordResetRequest"
|
|
38
|
-
onSubmit={e => {
|
|
39
|
-
e.preventDefault();
|
|
40
|
-
if (isDisabled) return;
|
|
41
|
-
requestUserPasswordResetMutation({
|
|
42
|
-
variables: { input: { email, userId, extras: { redirectUrl: asPath } } }
|
|
43
|
-
});
|
|
44
|
-
}}>
|
|
45
|
-
<Input
|
|
46
|
-
key="email"
|
|
47
|
-
type="email"
|
|
48
|
-
name="email"
|
|
49
|
-
label="Email"
|
|
50
|
-
required
|
|
51
|
-
onChange={({ event }) => {
|
|
52
|
-
const {
|
|
53
|
-
target: { value }
|
|
54
|
-
} = event;
|
|
55
|
-
setEmail(value);
|
|
56
|
-
}}
|
|
57
|
-
value={email}
|
|
58
|
-
/>
|
|
59
|
-
</form>
|
|
60
|
-
)}
|
|
61
|
-
{!displayChildren && (
|
|
62
|
-
<Button type="submit" name="button" form="passwordResetRequest" disabled={isDisabled}>
|
|
63
|
-
Request Password Reset
|
|
64
|
-
</Button>
|
|
65
|
-
)}
|
|
66
|
-
{!!errorMessageToDisplay && <div className="error_message">{errorMessageToDisplay}</div>}
|
|
67
|
-
{displayValidChildren && <div>{children}</div>}
|
|
68
|
-
</div>
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
PasswordResetRequest.propTypes = {
|
|
73
|
-
modifier: PropTypes.string,
|
|
74
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
PasswordResetRequest.defaultProps = {
|
|
78
|
-
modifier: '',
|
|
79
|
-
children: null
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export default PasswordResetRequest;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { render } from '@blaze-cms/tools/test-helpers/test-functions';
|
|
2
|
-
import '@testing-library/jest-dom/extend-expect';
|
|
3
|
-
import Login from '../../../../../src/components/Login';
|
|
4
|
-
|
|
5
|
-
jest.mock('@blaze-cms/core-auth-ui', () => ({
|
|
6
|
-
checkIfLoggedIn: jest
|
|
7
|
-
.fn()
|
|
8
|
-
.mockImplementationOnce(() => ({ isLoggedIn: false }))
|
|
9
|
-
.mockImplementationOnce(() => ({ isLoggedIn: true }))
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
jest.mock('@apollo/client', () => ({
|
|
13
|
-
...jest.requireActual('@apollo/client'),
|
|
14
|
-
useMutation: jest.fn(() => [variables => variables, { client: { resetStore: null } }])
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
jest.mock('next/router', () => ({
|
|
18
|
-
useRouter: jest.fn().mockImplementation(() => ({
|
|
19
|
-
asPath: ''
|
|
20
|
-
}))
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
const props = {};
|
|
24
|
-
|
|
25
|
-
describe('Login component', () => {
|
|
26
|
-
it('should render without throwing an error and match snapshot', () => {
|
|
27
|
-
const { asFragment } = render(Login, props);
|
|
28
|
-
expect(asFragment()).toMatchSnapshot();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should render rederict link if logged in', () => {
|
|
32
|
-
const { asFragment, container } = render(Login, props);
|
|
33
|
-
expect(asFragment()).toMatchSnapshot();
|
|
34
|
-
expect(container.firstChild).toContainHTML('span');
|
|
35
|
-
});
|
|
36
|
-
});
|