@oneblink/apps-react 4.0.0-beta.5 → 4.0.0-beta.7
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/README.md +2 -8
- package/dist/OneBlinkAutoSaveForm.d.ts +25 -5
- package/dist/OneBlinkAutoSaveForm.js +12 -0
- package/dist/OneBlinkAutoSaveForm.js.map +1 -1
- package/dist/OneBlinkForm.d.ts +558 -8
- package/dist/OneBlinkForm.js +546 -0
- package/dist/OneBlinkForm.js.map +1 -1
- package/dist/OneBlinkFormBase.d.ts +51 -6
- package/dist/OneBlinkFormBase.js.map +1 -1
- package/dist/OneBlinkReadOnlyForm.d.ts +83 -6
- package/dist/OneBlinkReadOnlyForm.js +79 -0
- package/dist/OneBlinkReadOnlyForm.js.map +1 -1
- package/dist/PaymentReceipt.d.ts +59 -0
- package/dist/PaymentReceipt.js +49 -0
- package/dist/PaymentReceipt.js.map +1 -1
- package/dist/components/formStore/FormStoreTableProvider.js +23 -1
- package/dist/components/formStore/FormStoreTableProvider.js.map +1 -1
- package/dist/components/formStore/OneBlinkFormStoreClearFiltersButton.d.ts +5 -0
- package/dist/components/formStore/OneBlinkFormStoreClearFiltersButton.js +5 -0
- package/dist/components/formStore/OneBlinkFormStoreClearFiltersButton.js.map +1 -1
- package/dist/components/formStore/OneBlinkFormStoreColumnsButton.d.ts +5 -0
- package/dist/components/formStore/OneBlinkFormStoreColumnsButton.js +5 -0
- package/dist/components/formStore/OneBlinkFormStoreColumnsButton.js.map +1 -1
- package/dist/components/formStore/OneBlinkFormStoreDownloadButton.d.ts +5 -0
- package/dist/components/formStore/OneBlinkFormStoreDownloadButton.js +5 -0
- package/dist/components/formStore/OneBlinkFormStoreDownloadButton.js.map +1 -1
- package/dist/components/formStore/OneBlinkFormStoreProvider.d.ts +5 -0
- package/dist/components/formStore/OneBlinkFormStoreProvider.js +5 -0
- package/dist/components/formStore/OneBlinkFormStoreProvider.js.map +1 -1
- package/dist/components/formStore/OneBlinkFormStoreRefreshButton.d.ts +5 -0
- package/dist/components/formStore/OneBlinkFormStoreRefreshButton.js +5 -0
- package/dist/components/formStore/OneBlinkFormStoreRefreshButton.js.map +1 -1
- package/dist/components/formStore/OneBlinkFormStoreTable.d.ts +4 -0
- package/dist/components/formStore/OneBlinkFormStoreTable.js +4 -0
- package/dist/components/formStore/OneBlinkFormStoreTable.js.map +1 -1
- package/dist/components/pickers/V4CompatibleDatePicker.d.ts +5 -0
- package/dist/components/pickers/V4CompatibleDatePicker.js +5 -0
- package/dist/components/pickers/V4CompatibleDatePicker.js.map +1 -1
- package/dist/components/pickers/V4CompatibleDateTimePicker.d.ts +5 -0
- package/dist/components/pickers/V4CompatibleDateTimePicker.js +5 -0
- package/dist/components/pickers/V4CompatibleDateTimePicker.js.map +1 -1
- package/dist/components/pickers/V4CompatibleTimePicker.d.ts +5 -0
- package/dist/components/pickers/V4CompatibleTimePicker.js +5 -0
- package/dist/components/pickers/V4CompatibleTimePicker.js.map +1 -1
- package/dist/components/renderer/LookupNotification.js +11 -2
- package/dist/components/renderer/LookupNotification.js.map +1 -1
- package/dist/components/renderer/OneBlinkFormElements.d.ts +3 -3
- package/dist/components/renderer/OneBlinkFormElements.js.map +1 -1
- package/dist/components/renderer/PageFormElements.d.ts +3 -3
- package/dist/components/renderer/PageFormElements.js.map +1 -1
- package/dist/components/renderer/ProgressBar.d.ts +7 -3
- package/dist/components/renderer/ProgressBar.js +5 -0
- package/dist/components/renderer/ProgressBar.js.map +1 -1
- package/dist/form-elements/FormElementCalculation.js.map +1 -1
- package/dist/form-elements/FormElementForm.d.ts +4 -4
- package/dist/form-elements/FormElementForm.js.map +1 -1
- package/dist/form-elements/FormElementRepeatableSet.d.ts +4 -4
- package/dist/form-elements/FormElementRepeatableSet.js.map +1 -1
- package/dist/form-elements/FormElementSummary.js.map +1 -1
- package/dist/hooks/useAuth.d.ts +81 -6
- package/dist/hooks/useAuth.js +54 -0
- package/dist/hooks/useAuth.js.map +1 -1
- package/dist/hooks/useBooleanState.d.ts +42 -5
- package/dist/hooks/useBooleanState.js +36 -0
- package/dist/hooks/useBooleanState.js.map +1 -1
- package/dist/hooks/useClickOutsideElement.d.ts +40 -0
- package/dist/hooks/useClickOutsideElement.js +40 -0
- package/dist/hooks/useClickOutsideElement.js.map +1 -1
- package/dist/hooks/useConditionalLogic.d.ts +2 -3
- package/dist/hooks/useConditionalLogic.js.map +1 -1
- package/dist/hooks/useDrafts.d.ts +63 -1
- package/dist/hooks/useDrafts.js +58 -11
- package/dist/hooks/useDrafts.js.map +1 -1
- package/dist/hooks/useFormSubmissionAutoSaveState.d.ts +18 -5
- package/dist/hooks/useFormSubmissionAutoSaveState.js +10 -0
- package/dist/hooks/useFormSubmissionAutoSaveState.js.map +1 -1
- package/dist/hooks/useFormSubmissionModelContext.d.ts +4 -4
- package/dist/hooks/useFormSubmissionModelContext.js.map +1 -1
- package/dist/hooks/useFormSubmissionState.d.ts +45 -5
- package/dist/hooks/useFormSubmissionState.js +37 -0
- package/dist/hooks/useFormSubmissionState.js.map +1 -1
- package/dist/hooks/useFormValidation.d.ts +3 -3
- package/dist/hooks/useFormValidation.js.map +1 -1
- package/dist/hooks/useInjectPages.d.ts +2 -3
- package/dist/hooks/useInjectPages.js.map +1 -1
- package/dist/hooks/useIsMounted.d.ts +20 -0
- package/dist/hooks/useIsMounted.js +19 -0
- package/dist/hooks/useIsMounted.js.map +1 -1
- package/dist/hooks/useIsOffline.d.ts +54 -0
- package/dist/hooks/useIsOffline.js +54 -0
- package/dist/hooks/useIsOffline.js.map +1 -1
- package/dist/hooks/useLoadDataState.d.ts +46 -3
- package/dist/hooks/useLoadDataState.js +41 -0
- package/dist/hooks/useLoadDataState.js.map +1 -1
- package/dist/hooks/useLogin.d.ts +400 -13
- package/dist/hooks/useLogin.js +300 -0
- package/dist/hooks/useLogin.js.map +1 -1
- package/dist/hooks/useLookups.d.ts +3 -3
- package/dist/hooks/useLookups.js.map +1 -1
- package/dist/hooks/useNullableState.d.ts +46 -1
- package/dist/hooks/useNullableState.js +42 -1
- package/dist/hooks/useNullableState.js.map +1 -1
- package/dist/hooks/usePendingSubmissions.d.ts +103 -0
- package/dist/hooks/usePendingSubmissions.js +195 -0
- package/dist/hooks/usePendingSubmissions.js.map +1 -0
- package/dist/hooks/useSignUp.d.ts +5 -0
- package/dist/hooks/useSignUp.js +5 -0
- package/dist/hooks/useSignUp.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/services/checkBsbsAreInvalid.d.ts +2 -3
- package/dist/services/checkBsbsAreInvalid.js.map +1 -1
- package/dist/services/checkIfAttachmentsExist.d.ts +2 -3
- package/dist/services/checkIfAttachmentsExist.js.map +1 -1
- package/dist/services/checkIfBsbsAreValidating.d.ts +2 -3
- package/dist/services/checkIfBsbsAreValidating.js.map +1 -1
- package/dist/services/cleanFormSubmissionModel.d.ts +4 -4
- package/dist/services/cleanFormSubmissionModel.js +2 -1
- package/dist/services/cleanFormSubmissionModel.js.map +1 -1
- package/dist/services/form-validation.d.ts +3 -3
- package/dist/services/form-validation.js.map +1 -1
- package/dist/services/generate-default-data.d.ts +2 -3
- package/dist/services/generate-default-data.js +3 -1
- package/dist/services/generate-default-data.js.map +1 -1
- package/dist/services/generateFreshdeskDependentFieldElements.js.map +1 -1
- package/dist/services/getDateRangeConfiguration.d.ts +2 -3
- package/dist/services/getDateRangeConfiguration.js.map +1 -1
- package/dist/services/getRepeatableSetEntriesConfiguration.d.ts +2 -3
- package/dist/services/getRepeatableSetEntriesConfiguration.js.map +1 -1
- package/dist/styles/receipt.scss +1 -1
- package/dist/styles/repeatable-set.scss +2 -2
- package/dist/typedoc.d.ts +2 -0
- package/dist/typedoc.js +3 -0
- package/dist/typedoc.js.map +1 -0
- package/dist/types/form.d.ts +5 -6
- package/dist/types/form.js.map +1 -1
- package/package.json +9 -3
package/dist/hooks/useLogin.js
CHANGED
@@ -2,6 +2,305 @@ import * as React from 'react';
|
|
2
2
|
import { authService, Sentry } from '@oneblink/apps';
|
3
3
|
import useIsMounted from './useIsMounted';
|
4
4
|
import useBooleanState from './useBooleanState';
|
5
|
+
/**
|
6
|
+
* This function is a react hook to help writing your own login screen.
|
7
|
+
*
|
8
|
+
* ## Example
|
9
|
+
*
|
10
|
+
* ```jsx
|
11
|
+
* import * as React from 'react'
|
12
|
+
* import { useHistory } from 'react-router-dom'
|
13
|
+
* import { useLogin } from '@oneblink/apps-react'
|
14
|
+
*
|
15
|
+
* function App() {
|
16
|
+
* const history = useHistory()
|
17
|
+
*
|
18
|
+
* const [username, setUsername] = React.useState('')
|
19
|
+
* const [password, setPassword] = React.useState('')
|
20
|
+
* const [newPasswordConfirmed, setNewPasswordConfirmed] = React.useState('')
|
21
|
+
* const [newPassword, setNewPassword] = React.useState('')
|
22
|
+
* const [code, setCode] = React.useState('')
|
23
|
+
*
|
24
|
+
* const onLogin = React.useCallback(() => {
|
25
|
+
* history.push('/')
|
26
|
+
* }, [history])
|
27
|
+
*
|
28
|
+
* const {
|
29
|
+
* // Login
|
30
|
+
* loginWithGoogle,
|
31
|
+
* loginWithUsernamePassword,
|
32
|
+
* isLoggingIn,
|
33
|
+
* // Reset Temp Password
|
34
|
+
* isPasswordTemporary,
|
35
|
+
* isResettingTemporaryPassword,
|
36
|
+
* resetTemporaryPassword,
|
37
|
+
* // MFA Password
|
38
|
+
* isMfaCodeRequired,
|
39
|
+
* isSubmittingMfaCode,
|
40
|
+
* submitMfaCode,
|
41
|
+
* // Login Errors
|
42
|
+
* loginError,
|
43
|
+
* clearLoginError,
|
44
|
+
* // Showing Forgot Password
|
45
|
+
* isShowingForgotPassword,
|
46
|
+
* showForgotPassword,
|
47
|
+
* hideForgotPassword,
|
48
|
+
* // Sending Forgot Password Code
|
49
|
+
* isSendingForgotPasswordCode,
|
50
|
+
* sendForgotPasswordCode,
|
51
|
+
* // Resetting Forgotten Password
|
52
|
+
* hasSentForgotPasswordCode,
|
53
|
+
* isResettingForgottenPassword,
|
54
|
+
* resetForgottenPassword,
|
55
|
+
* // Forgot Password Errors
|
56
|
+
* forgotPasswordError,
|
57
|
+
* clearForgotPasswordError,
|
58
|
+
* // Validation
|
59
|
+
* usernameValidation,
|
60
|
+
* passwordValidation,
|
61
|
+
* codeValidation,
|
62
|
+
* newPasswordValidation,
|
63
|
+
* newPasswordConfirmedValidation,
|
64
|
+
* } = useLogin({
|
65
|
+
* username,
|
66
|
+
* password,
|
67
|
+
* newPassword,
|
68
|
+
* newPasswordConfirmed,
|
69
|
+
* code,
|
70
|
+
* onLogin,
|
71
|
+
* })
|
72
|
+
*
|
73
|
+
* if (hasSentForgotPasswordCode) {
|
74
|
+
* return (
|
75
|
+
* <form
|
76
|
+
* onSubmit={(e) => {
|
77
|
+
* e.preventDefault()
|
78
|
+
* resetForgottenPassword()
|
79
|
+
* }}
|
80
|
+
* >
|
81
|
+
* <p>We have sent you a password reset code via email. Enter it below to reset your password.</p>
|
82
|
+
*
|
83
|
+
* <input
|
84
|
+
* type="password"
|
85
|
+
* placeholder="Code"
|
86
|
+
* value={code}
|
87
|
+
* onChange={(e) => setCode(e.target.value)}
|
88
|
+
* />
|
89
|
+
*
|
90
|
+
* <input
|
91
|
+
* type="password"
|
92
|
+
* placeholder="New Password"
|
93
|
+
* value={newPassword}
|
94
|
+
* onChange={(e) => setNewPassword(e.target.value)}
|
95
|
+
* />
|
96
|
+
*
|
97
|
+
* <input
|
98
|
+
* type="password"
|
99
|
+
* placeholder="Confirm Password"
|
100
|
+
* value={newPassword}
|
101
|
+
* onChange={(e) => setNewPasswordConfirmed(e.target.value)}
|
102
|
+
* />
|
103
|
+
*
|
104
|
+
* <button
|
105
|
+
* type="submit"
|
106
|
+
* disabled={isResettingForgottenPassword || codeValidation.isInvalid || newPasswordValidation.isInvalid || newPasswordConfirmedValidation.isInvalid}
|
107
|
+
* >
|
108
|
+
* Change Password
|
109
|
+
* </button>
|
110
|
+
*
|
111
|
+
* <p>Password Requirements</p>
|
112
|
+
* <p>Contains a lowercase letter: {validation.hasLowercaseLetter ? 'Yes' : 'No'}</p>
|
113
|
+
* <p>Contains an upper case letter: {validation.hasUpperCaseLetter ? 'Yes' : 'No'}</p>
|
114
|
+
* <p>Contains a number: {validation.hasNumber ? 'Yes' : 'No'}</p>
|
115
|
+
* <p>Contains a special character: {validation.hasSpecialCharacter ? 'Yes' : 'No'}</p>
|
116
|
+
* <p>Contains at least 8 characters: {validation.hasMinLength ? 'Yes' : 'No'}</p>
|
117
|
+
*
|
118
|
+
* {forgotPasswordError && (
|
119
|
+
* <p>{forgotPasswordError.message}</p>
|
120
|
+
* <button type="button" onClick={clearForgotPasswordError}>Clear Error</button>
|
121
|
+
* )}
|
122
|
+
* </form>
|
123
|
+
* )
|
124
|
+
* }
|
125
|
+
*
|
126
|
+
* if (isShowingForgotPassword) {
|
127
|
+
* return (
|
128
|
+
* <form
|
129
|
+
* onSubmit={(e) => {
|
130
|
+
* e.preventDefault()
|
131
|
+
* sendForgotPasswordCode()
|
132
|
+
* }}
|
133
|
+
* >
|
134
|
+
* <p>Enter your email address and we will send you a code to reset your password.</p>
|
135
|
+
*
|
136
|
+
* <input
|
137
|
+
* type="email"
|
138
|
+
* placeholder="Email Address"
|
139
|
+
* value={username}
|
140
|
+
* onChange={(e) => setUsername(e.target.value)}
|
141
|
+
* />
|
142
|
+
*
|
143
|
+
* <p>
|
144
|
+
* <a onClick={hideForgotPassword}>Remembered your password?</a>
|
145
|
+
* </p>
|
146
|
+
*
|
147
|
+
* <button
|
148
|
+
* type="submit"
|
149
|
+
* disabled={isSendingForgotPasswordCode || usernameValidation.isInvalid}
|
150
|
+
* >
|
151
|
+
* Reset Password
|
152
|
+
* </button>
|
153
|
+
*
|
154
|
+
* {forgotPasswordError && (
|
155
|
+
* <p>{forgotPasswordError.message}</p>
|
156
|
+
* <button type="button" onClick={clearForgotPasswordError}>Clear Error</button>
|
157
|
+
* )}
|
158
|
+
* </form>
|
159
|
+
* )
|
160
|
+
* }
|
161
|
+
*
|
162
|
+
* if (isPasswordTemporary) {
|
163
|
+
* return (
|
164
|
+
* <form
|
165
|
+
* onSubmit={(e) => {
|
166
|
+
* e.preventDefault()
|
167
|
+
* resetTemporaryPassword()
|
168
|
+
* }}
|
169
|
+
* >
|
170
|
+
* <p>The password you entered was only temporary and must be reset for security purposes. Please enter your new password below to continue.</p>
|
171
|
+
*
|
172
|
+
* <input
|
173
|
+
* type="password"
|
174
|
+
* placeholder="New Password"
|
175
|
+
* value={newPassword}
|
176
|
+
* onChange={(e) => setNewPassword(e.target.value)}
|
177
|
+
* />
|
178
|
+
*
|
179
|
+
* <input
|
180
|
+
* type="password"
|
181
|
+
* placeholder="Confirm Password"
|
182
|
+
* value={newPassword}
|
183
|
+
* onChange={(e) => setNewPasswordConfirmed(e.target.value)}
|
184
|
+
* />
|
185
|
+
*
|
186
|
+
* <button
|
187
|
+
* type="submit"
|
188
|
+
* disabled={isResettingTemporaryPassword || newPasswordValidation.isInvalid || newPasswordConfirmedValidation.isInvalid}
|
189
|
+
* >
|
190
|
+
* Change Password & Sign In
|
191
|
+
* </button>
|
192
|
+
*
|
193
|
+
* <p>Password Requirements</p>
|
194
|
+
* <p>Contains a lowercase letter: {validation.hasLowercaseLetter ? 'Yes' : 'No'}</p>
|
195
|
+
* <p>Contains an upper case letter: {validation.hasUpperCaseLetter ? 'Yes' : 'No'}</p>
|
196
|
+
* <p>Contains a number: {validation.hasNumber ? 'Yes' : 'No'}</p>
|
197
|
+
* <p>Contains a special character: {validation.hasSpecialCharacter ? 'Yes' : 'No'}</p>
|
198
|
+
* <p>Contains at least 8 characters: {validation.hasMinLength ? 'Yes' : 'No'}</p>
|
199
|
+
*
|
200
|
+
* {loginError && (
|
201
|
+
* <p>{loginError.message}</p>
|
202
|
+
* <button type="button" onClick={clearLoginError}>Clear Error</button>
|
203
|
+
* )}
|
204
|
+
* </form>
|
205
|
+
* )
|
206
|
+
* }
|
207
|
+
*
|
208
|
+
* if (isMfaCodeRequired) {
|
209
|
+
* return (
|
210
|
+
* <form
|
211
|
+
* onSubmit={(e) => {
|
212
|
+
* e.preventDefault()
|
213
|
+
* submitMfaCode()
|
214
|
+
* }}
|
215
|
+
* >
|
216
|
+
* <p>Enter the 6-digit code found in your authenticator app.</p>
|
217
|
+
*
|
218
|
+
* <input
|
219
|
+
* type="password"
|
220
|
+
* placeholder="Code"
|
221
|
+
* value={code}
|
222
|
+
* onChange={(e) => setCode(e.target.value)}
|
223
|
+
* />
|
224
|
+
*
|
225
|
+
* <button
|
226
|
+
* type="submit"
|
227
|
+
* disabled={isSubmittingMfaCode || codeValidation.isInvalid}
|
228
|
+
* >
|
229
|
+
* Sign In
|
230
|
+
* </button>
|
231
|
+
*
|
232
|
+
* {loginError && (
|
233
|
+
* <p>{loginError.message}</p>
|
234
|
+
* <button type="button" onClick={clearLoginError}>Clear Error</button>
|
235
|
+
* )}
|
236
|
+
* </form>
|
237
|
+
* )
|
238
|
+
* }
|
239
|
+
*
|
240
|
+
* return (
|
241
|
+
* <form
|
242
|
+
* onSubmit={(e) => {
|
243
|
+
* e.preventDefault()
|
244
|
+
* loginWithUsernamePassword()
|
245
|
+
* }}
|
246
|
+
* >
|
247
|
+
* <p>Sign in with your email address and password.</p>
|
248
|
+
* <input
|
249
|
+
* type="email"
|
250
|
+
* placeholder="Email Address"
|
251
|
+
* value={username}
|
252
|
+
* onChange={(e) => setUsername(e.target.value)}
|
253
|
+
* />
|
254
|
+
*
|
255
|
+
* <input
|
256
|
+
* type="password"
|
257
|
+
* placeholder="New Password"
|
258
|
+
* value={newPassword}
|
259
|
+
* onChange={(e) => setNewPassword(e.target.value)}
|
260
|
+
* />
|
261
|
+
*
|
262
|
+
* <p>
|
263
|
+
* <a onClick={showForgotPassword}>Forgot your password?</a>
|
264
|
+
* </p>
|
265
|
+
*
|
266
|
+
* <button
|
267
|
+
* type="submit"
|
268
|
+
* disabled={isLoggingIn || usernameValidation.isInvalid || passwordValidation.isInvalid}
|
269
|
+
* >
|
270
|
+
* {children}
|
271
|
+
* </button>
|
272
|
+
*
|
273
|
+
* <p>or</p>
|
274
|
+
*
|
275
|
+
* <button
|
276
|
+
* type="button"
|
277
|
+
* onClick={loginWithGoogle}
|
278
|
+
* >
|
279
|
+
* <img
|
280
|
+
* alt="Google"
|
281
|
+
* src="google-sign-in.png"
|
282
|
+
* />
|
283
|
+
* <span>Sign in with Google</span>
|
284
|
+
* </button>
|
285
|
+
*
|
286
|
+
* {loginError && (
|
287
|
+
* <p>{loginError.message}</p>
|
288
|
+
* <button type="button" onClick={clearLoginError}>Clear Error</button>
|
289
|
+
* )}
|
290
|
+
* </form>
|
291
|
+
* )
|
292
|
+
* }
|
293
|
+
*
|
294
|
+
* const root = document.getElementById('root')
|
295
|
+
* if (root) {
|
296
|
+
* ReactDOM.render(<App />, root)
|
297
|
+
* }
|
298
|
+
* ```
|
299
|
+
*
|
300
|
+
* @param options
|
301
|
+
* @returns
|
302
|
+
* @group Hooks
|
303
|
+
*/
|
5
304
|
export default function useLogin({ username, password, newPassword, newPasswordConfirmed, code, }) {
|
6
305
|
const isMounted = useIsMounted();
|
7
306
|
// Validation
|
@@ -298,6 +597,7 @@ export default function useLogin({ username, password, newPassword, newPasswordC
|
|
298
597
|
}, []);
|
299
598
|
return {
|
300
599
|
// Login
|
600
|
+
/** Open redirect user to the Google sign in */
|
301
601
|
loginWithGoogle,
|
302
602
|
loginWithUsernamePassword,
|
303
603
|
isLoggingIn,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useLogin.js","sourceRoot":"","sources":["../../src/hooks/useLogin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAE/C,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,QA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;QACd,qBAAqB;QACrB,8BAA8B;KAC/B,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { authService, Sentry } from '@oneblink/apps'\n\nimport useIsMounted from './useIsMounted'\nimport useBooleanState from './useBooleanState'\n\nexport default function useLogin({\n username,\n password,\n newPassword,\n newPasswordConfirmed,\n code,\n}: {\n username: string\n password: string\n newPassword: string\n newPasswordConfirmed: string\n code: string\n}) {\n const isMounted = useIsMounted()\n\n // Validation\n const usernameValidation = React.useMemo(() => {\n return {\n isInvalid: !username.trim(),\n }\n }, [username])\n\n const passwordValidation = React.useMemo(() => {\n return {\n isInvalid: !password.trim(),\n }\n }, [password])\n\n const codeValidation = React.useMemo(() => {\n return {\n isInvalid: !code.trim(),\n }\n }, [code])\n\n const newPasswordValidation = React.useMemo(() => {\n const validation = {\n hasLowercaseLetter: /[a-z]+/.test(newPassword),\n hasUpperCaseLetter: /[A-Z]+/.test(newPassword),\n hasNumber: /\\d+/.test(newPassword),\n hasSpecialCharacter: /[\\^$*.[\\]{}()?|\\-\"!@#%&/,><':;|_~`]+/.test(\n newPassword,\n ),\n hasMinLength: newPassword.length >= 8,\n isInvalid: true,\n }\n validation.isInvalid =\n !validation.hasLowercaseLetter ||\n !validation.hasUpperCaseLetter ||\n !validation.hasNumber ||\n !validation.hasSpecialCharacter ||\n !validation.hasMinLength\n return validation\n }, [newPassword])\n\n const newPasswordConfirmedValidation = React.useMemo(() => {\n return {\n isInvalid: newPassword !== newPasswordConfirmed,\n }\n }, [newPassword, newPasswordConfirmed])\n\n // Login, Reset Password, MFA\n const [\n {\n isResettingTemporaryPassword,\n isLoggingIn,\n loginError,\n loginAttemptResponse,\n isSubmittingMfaCode,\n },\n setLoginState,\n ] = React.useState<{\n isResettingTemporaryPassword: boolean\n isLoggingIn: boolean\n loginError: null | Error\n loginAttemptResponse: authService.LoginAttemptResponse | undefined\n isSubmittingMfaCode: boolean\n }>({\n isResettingTemporaryPassword: false,\n isLoggingIn: false,\n loginError: null,\n loginAttemptResponse: undefined,\n isSubmittingMfaCode: false,\n })\n const clearLoginError = React.useCallback(\n () =>\n setLoginState((current) => ({\n ...current,\n loginError: null,\n })),\n [],\n )\n const loginWithUsernamePassword = React.useCallback(async () => {\n if (usernameValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please enter a valid email address'),\n }))\n return\n }\n if (passwordValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please enter a valid password'),\n }))\n return\n }\n\n setLoginState((currentState) => ({\n ...currentState,\n isLoggingIn: true,\n loginError: null,\n }))\n\n try {\n const newLoginAttemptResponse = await authService.loginUsernamePassword(\n username,\n password,\n )\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isLoggingIn: false,\n loginAttemptResponse: newLoginAttemptResponse,\n }))\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isLoggingIn: false,\n loginError: error as Error,\n }))\n }\n }\n }, [\n isMounted,\n password,\n passwordValidation.isInvalid,\n username,\n usernameValidation.isInvalid,\n ])\n\n const resetTemporaryPassword = React.useCallback(async () => {\n const resetTemporaryPasswordCallback =\n loginAttemptResponse?.resetPasswordCallback\n if (!resetTemporaryPasswordCallback) {\n return\n }\n\n if (newPasswordValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please enter a valid password'),\n }))\n return\n }\n\n if (newPasswordConfirmedValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please confirm your new password'),\n }))\n return\n }\n\n setLoginState((current) => ({\n ...current,\n isResettingPassword: true,\n loginError: null,\n }))\n\n try {\n const resetPasswordResponse = await resetTemporaryPasswordCallback(\n newPassword,\n )\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isResettingTemporaryPassword: false,\n loginAttemptResponse: resetPasswordResponse,\n }))\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setLoginState((current) => ({\n ...current,\n isResettingPassword: false,\n loginError: error as Error,\n }))\n }\n }\n }, [\n isMounted,\n loginAttemptResponse?.resetPasswordCallback,\n newPassword,\n newPasswordConfirmedValidation.isInvalid,\n newPasswordValidation.isInvalid,\n ])\n\n const submitMfaCode = React.useCallback(async () => {\n const mfaCodeCallback = loginAttemptResponse?.mfaCodeCallback\n if (!mfaCodeCallback) {\n return\n }\n\n setLoginState((current) => ({\n ...current,\n isSubmittingMfaCode: true,\n loginError: null,\n }))\n\n try {\n const mfaResponse = await mfaCodeCallback(code)\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isSubmittingMfaCode: false,\n loginAttemptResponse: mfaResponse,\n }))\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setLoginState((current) => ({\n ...current,\n isSubmittingMfaCode: false,\n loginError: error as Error,\n }))\n }\n }\n }, [code, isMounted, loginAttemptResponse?.mfaCodeCallback])\n\n // Forgot Password\n const [isShowingForgotPassword, showForgotPassword, hideForgotPassword] =\n useBooleanState(false)\n const [\n {\n resetForgottenPasswordCallback,\n isSendingForgotPasswordCode,\n isResettingForgottenPassword,\n forgotPasswordError,\n },\n setForgotPasswordState,\n ] = React.useState<{\n isSendingForgotPasswordCode: boolean\n forgotPasswordError: null | Error\n resetForgottenPasswordCallback:\n | null\n | ((code: string, newPassword: string) => void)\n isResettingForgottenPassword: boolean\n }>({\n isSendingForgotPasswordCode: false,\n forgotPasswordError: null,\n resetForgottenPasswordCallback: null,\n isResettingForgottenPassword: false,\n })\n const clearForgotPasswordError = React.useCallback(\n () =>\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: null,\n })),\n [],\n )\n const sendForgotPasswordCode = React.useCallback(async () => {\n if (usernameValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error('Please enter a valid email address'),\n }))\n return\n }\n\n setForgotPasswordState({\n isSendingForgotPasswordCode: true,\n resetForgottenPasswordCallback: null,\n forgotPasswordError: null,\n isResettingForgottenPassword: false,\n })\n\n try {\n const newResetForgottenPasswordCallback =\n await authService.forgotPassword(username)\n if (isMounted.current) {\n setForgotPasswordState({\n isSendingForgotPasswordCode: false,\n resetForgottenPasswordCallback: newResetForgottenPasswordCallback,\n forgotPasswordError: null,\n isResettingForgottenPassword: false,\n })\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setForgotPasswordState({\n isSendingForgotPasswordCode: false,\n resetForgottenPasswordCallback: null,\n forgotPasswordError: error as Error,\n isResettingForgottenPassword: false,\n })\n }\n }\n }, [isMounted, username, usernameValidation.isInvalid])\n\n const resetForgottenPassword = React.useCallback(async () => {\n if (!resetForgottenPasswordCallback) {\n return\n }\n\n if (codeValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error(\n 'Please enter the code that was sent to your email address',\n ),\n }))\n }\n if (newPasswordValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error('Please enter a valid password'),\n }))\n return\n }\n if (newPasswordConfirmedValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error('Please confirm your new password'),\n }))\n return\n }\n\n setForgotPasswordState((current) => ({\n ...current,\n isChangingPassword: true,\n forgotPasswordError: null,\n }))\n\n try {\n await resetForgottenPasswordCallback(code, newPassword)\n if (isMounted.current) {\n setForgotPasswordState({\n isSendingForgotPasswordCode: false,\n resetForgottenPasswordCallback: null,\n forgotPasswordError: null,\n isResettingForgottenPassword: false,\n })\n hideForgotPassword()\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setForgotPasswordState((current) => ({\n ...current,\n isChangingPassword: false,\n forgotPasswordError: error as Error,\n }))\n }\n }\n }, [\n resetForgottenPasswordCallback,\n codeValidation.isInvalid,\n newPasswordValidation.isInvalid,\n newPasswordConfirmedValidation.isInvalid,\n code,\n newPassword,\n isMounted,\n hideForgotPassword,\n ])\n\n const loginWithGoogle = React.useCallback(() => {\n authService.loginHostedUI('Google')\n }, [])\n\n return {\n // Login\n loginWithGoogle,\n loginWithUsernamePassword,\n isLoggingIn,\n loginError,\n clearLoginError,\n // Reset Temp Password\n isPasswordTemporary: !!loginAttemptResponse?.resetPasswordCallback,\n isResettingTemporaryPassword,\n resetTemporaryPassword,\n // MFA Code\n isMfaCodeRequired: !!loginAttemptResponse?.mfaCodeCallback,\n isSubmittingMfaCode,\n submitMfaCode,\n // Showing Forgot Password\n isShowingForgotPassword,\n showForgotPassword,\n hideForgotPassword,\n forgotPasswordError,\n clearForgotPasswordError,\n // Sending Forgot Password Code\n isSendingForgotPasswordCode,\n sendForgotPasswordCode,\n // Resetting Forgotten Password\n hasSentForgotPasswordCode: !!resetForgottenPasswordCallback,\n isResettingForgottenPassword,\n resetForgottenPassword,\n // Validation\n usernameValidation,\n passwordValidation,\n codeValidation,\n newPasswordValidation,\n newPasswordConfirmedValidation,\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"useLogin.js","sourceRoot":"","sources":["../../src/hooks/useLogin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0S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A4B;QAC5B,sBAAsB;QACtB,aAAa;QACb,kBAAkB;QAClB,kBAAkB;QAClB,cAAc;QACd,qBAAqB;QACrB,8BAA8B;KAC/B,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { authService, Sentry } from '@oneblink/apps'\n\nimport useIsMounted from './useIsMounted'\nimport useBooleanState from './useBooleanState'\n\n/**\n * This function is a react hook to help writing your own login screen.\n *\n * ## Example\n *\n * ```jsx\n * import * as React from 'react'\n * import { useHistory } from 'react-router-dom'\n * import { useLogin } from '@oneblink/apps-react'\n *\n * function App() {\n * const history = useHistory()\n *\n * const [username, setUsername] = React.useState('')\n * const [password, setPassword] = React.useState('')\n * const [newPasswordConfirmed, setNewPasswordConfirmed] = React.useState('')\n * const [newPassword, setNewPassword] = React.useState('')\n * const [code, setCode] = React.useState('')\n *\n * const onLogin = React.useCallback(() => {\n * history.push('/')\n * }, [history])\n *\n * const {\n * // Login\n * loginWithGoogle,\n * loginWithUsernamePassword,\n * isLoggingIn,\n * // Reset Temp Password\n * isPasswordTemporary,\n * isResettingTemporaryPassword,\n * resetTemporaryPassword,\n * // MFA Password\n * isMfaCodeRequired,\n * isSubmittingMfaCode,\n * submitMfaCode,\n * // Login Errors\n * loginError,\n * clearLoginError,\n * // Showing Forgot Password\n * isShowingForgotPassword,\n * showForgotPassword,\n * hideForgotPassword,\n * // Sending Forgot Password Code\n * isSendingForgotPasswordCode,\n * sendForgotPasswordCode,\n * // Resetting Forgotten Password\n * hasSentForgotPasswordCode,\n * isResettingForgottenPassword,\n * resetForgottenPassword,\n * // Forgot Password Errors\n * forgotPasswordError,\n * clearForgotPasswordError,\n * // Validation\n * usernameValidation,\n * passwordValidation,\n * codeValidation,\n * newPasswordValidation,\n * newPasswordConfirmedValidation,\n * } = useLogin({\n * username,\n * password,\n * newPassword,\n * newPasswordConfirmed,\n * code,\n * onLogin,\n * })\n *\n * if (hasSentForgotPasswordCode) {\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * resetForgottenPassword()\n * }}\n * >\n * <p>We have sent you a password reset code via email. Enter it below to reset your password.</p>\n *\n * <input\n * type=\"password\"\n * placeholder=\"Code\"\n * value={code}\n * onChange={(e) => setCode(e.target.value)}\n * />\n *\n * <input\n * type=\"password\"\n * placeholder=\"New Password\"\n * value={newPassword}\n * onChange={(e) => setNewPassword(e.target.value)}\n * />\n *\n * <input\n * type=\"password\"\n * placeholder=\"Confirm Password\"\n * value={newPassword}\n * onChange={(e) => setNewPasswordConfirmed(e.target.value)}\n * />\n *\n * <button\n * type=\"submit\"\n * disabled={isResettingForgottenPassword || codeValidation.isInvalid || newPasswordValidation.isInvalid || newPasswordConfirmedValidation.isInvalid}\n * >\n * Change Password\n * </button>\n *\n * <p>Password Requirements</p>\n * <p>Contains a lowercase letter: {validation.hasLowercaseLetter ? 'Yes' : 'No'}</p>\n * <p>Contains an upper case letter: {validation.hasUpperCaseLetter ? 'Yes' : 'No'}</p>\n * <p>Contains a number: {validation.hasNumber ? 'Yes' : 'No'}</p>\n * <p>Contains a special character: {validation.hasSpecialCharacter ? 'Yes' : 'No'}</p>\n * <p>Contains at least 8 characters: {validation.hasMinLength ? 'Yes' : 'No'}</p>\n *\n * {forgotPasswordError && (\n * <p>{forgotPasswordError.message}</p>\n * <button type=\"button\" onClick={clearForgotPasswordError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * if (isShowingForgotPassword) {\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * sendForgotPasswordCode()\n * }}\n * >\n * <p>Enter your email address and we will send you a code to reset your password.</p>\n *\n * <input\n * type=\"email\"\n * placeholder=\"Email Address\"\n * value={username}\n * onChange={(e) => setUsername(e.target.value)}\n * />\n *\n * <p>\n * <a onClick={hideForgotPassword}>Remembered your password?</a>\n * </p>\n *\n * <button\n * type=\"submit\"\n * disabled={isSendingForgotPasswordCode || usernameValidation.isInvalid}\n * >\n * Reset Password\n * </button>\n *\n * {forgotPasswordError && (\n * <p>{forgotPasswordError.message}</p>\n * <button type=\"button\" onClick={clearForgotPasswordError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * if (isPasswordTemporary) {\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * resetTemporaryPassword()\n * }}\n * >\n * <p>The password you entered was only temporary and must be reset for security purposes. Please enter your new password below to continue.</p>\n *\n * <input\n * type=\"password\"\n * placeholder=\"New Password\"\n * value={newPassword}\n * onChange={(e) => setNewPassword(e.target.value)}\n * />\n *\n * <input\n * type=\"password\"\n * placeholder=\"Confirm Password\"\n * value={newPassword}\n * onChange={(e) => setNewPasswordConfirmed(e.target.value)}\n * />\n *\n * <button\n * type=\"submit\"\n * disabled={isResettingTemporaryPassword || newPasswordValidation.isInvalid || newPasswordConfirmedValidation.isInvalid}\n * >\n * Change Password & Sign In\n * </button>\n *\n * <p>Password Requirements</p>\n * <p>Contains a lowercase letter: {validation.hasLowercaseLetter ? 'Yes' : 'No'}</p>\n * <p>Contains an upper case letter: {validation.hasUpperCaseLetter ? 'Yes' : 'No'}</p>\n * <p>Contains a number: {validation.hasNumber ? 'Yes' : 'No'}</p>\n * <p>Contains a special character: {validation.hasSpecialCharacter ? 'Yes' : 'No'}</p>\n * <p>Contains at least 8 characters: {validation.hasMinLength ? 'Yes' : 'No'}</p>\n *\n * {loginError && (\n * <p>{loginError.message}</p>\n * <button type=\"button\" onClick={clearLoginError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * if (isMfaCodeRequired) {\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * submitMfaCode()\n * }}\n * >\n * <p>Enter the 6-digit code found in your authenticator app.</p>\n *\n * <input\n * type=\"password\"\n * placeholder=\"Code\"\n * value={code}\n * onChange={(e) => setCode(e.target.value)}\n * />\n *\n * <button\n * type=\"submit\"\n * disabled={isSubmittingMfaCode || codeValidation.isInvalid}\n * >\n * Sign In\n * </button>\n *\n * {loginError && (\n * <p>{loginError.message}</p>\n * <button type=\"button\" onClick={clearLoginError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * loginWithUsernamePassword()\n * }}\n * >\n * <p>Sign in with your email address and password.</p>\n * <input\n * type=\"email\"\n * placeholder=\"Email Address\"\n * value={username}\n * onChange={(e) => setUsername(e.target.value)}\n * />\n *\n * <input\n * type=\"password\"\n * placeholder=\"New Password\"\n * value={newPassword}\n * onChange={(e) => setNewPassword(e.target.value)}\n * />\n *\n * <p>\n * <a onClick={showForgotPassword}>Forgot your password?</a>\n * </p>\n *\n * <button\n * type=\"submit\"\n * disabled={isLoggingIn || usernameValidation.isInvalid || passwordValidation.isInvalid}\n * >\n * {children}\n * </button>\n *\n * <p>or</p>\n *\n * <button\n * type=\"button\"\n * onClick={loginWithGoogle}\n * >\n * <img\n * alt=\"Google\"\n * src=\"google-sign-in.png\"\n * />\n * <span>Sign in with Google</span>\n * </button>\n *\n * {loginError && (\n * <p>{loginError.message}</p>\n * <button type=\"button\" onClick={clearLoginError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param options\n * @returns\n * @group Hooks\n */\nexport default function useLogin({\n username,\n password,\n newPassword,\n newPasswordConfirmed,\n code,\n}: {\n /** The email address entered by the user. */\n username: string\n /** The password entered by the user. */\n password: string\n /** The new password entered by the user if changing their password. */\n newPassword: string\n /**\n * The new password repeated by the user if changing their password to ensure\n * they do type it in wrong.\n */\n newPasswordConfirmed: string\n /**\n * The code sent to the user after requesting a password reset by starting the\n * \"forgot password\" process.\n */\n code: string\n}): UseLoginValue {\n const isMounted = useIsMounted()\n\n // Validation\n const usernameValidation = React.useMemo(() => {\n return {\n isInvalid: !username.trim(),\n }\n }, [username])\n\n const passwordValidation = React.useMemo(() => {\n return {\n isInvalid: !password.trim(),\n }\n }, [password])\n\n const codeValidation = React.useMemo(() => {\n return {\n isInvalid: !code.trim(),\n }\n }, [code])\n\n const newPasswordValidation = React.useMemo(() => {\n const validation = {\n hasLowercaseLetter: /[a-z]+/.test(newPassword),\n hasUpperCaseLetter: /[A-Z]+/.test(newPassword),\n hasNumber: /\\d+/.test(newPassword),\n hasSpecialCharacter: /[\\^$*.[\\]{}()?|\\-\"!@#%&/,><':;|_~`]+/.test(\n newPassword,\n ),\n hasMinLength: newPassword.length >= 8,\n isInvalid: true,\n }\n validation.isInvalid =\n !validation.hasLowercaseLetter ||\n !validation.hasUpperCaseLetter ||\n !validation.hasNumber ||\n !validation.hasSpecialCharacter ||\n !validation.hasMinLength\n return validation\n }, [newPassword])\n\n const newPasswordConfirmedValidation = React.useMemo(() => {\n return {\n isInvalid: newPassword !== newPasswordConfirmed,\n }\n }, [newPassword, newPasswordConfirmed])\n\n // Login, Reset Password, MFA\n const [\n {\n isResettingTemporaryPassword,\n isLoggingIn,\n loginError,\n loginAttemptResponse,\n isSubmittingMfaCode,\n },\n setLoginState,\n ] = React.useState<{\n isResettingTemporaryPassword: boolean\n isLoggingIn: boolean\n loginError: null | Error\n loginAttemptResponse: authService.LoginAttemptResponse | undefined\n isSubmittingMfaCode: boolean\n }>({\n isResettingTemporaryPassword: false,\n isLoggingIn: false,\n loginError: null,\n loginAttemptResponse: undefined,\n isSubmittingMfaCode: false,\n })\n const clearLoginError = React.useCallback(\n () =>\n setLoginState((current) => ({\n ...current,\n loginError: null,\n })),\n [],\n )\n const loginWithUsernamePassword = React.useCallback(async () => {\n if (usernameValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please enter a valid email address'),\n }))\n return\n }\n if (passwordValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please enter a valid password'),\n }))\n return\n }\n\n setLoginState((currentState) => ({\n ...currentState,\n isLoggingIn: true,\n loginError: null,\n }))\n\n try {\n const newLoginAttemptResponse = await authService.loginUsernamePassword(\n username,\n password,\n )\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isLoggingIn: false,\n loginAttemptResponse: newLoginAttemptResponse,\n }))\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isLoggingIn: false,\n loginError: error as Error,\n }))\n }\n }\n }, [\n isMounted,\n password,\n passwordValidation.isInvalid,\n username,\n usernameValidation.isInvalid,\n ])\n\n const resetTemporaryPassword = React.useCallback(async () => {\n const resetTemporaryPasswordCallback =\n loginAttemptResponse?.resetPasswordCallback\n if (!resetTemporaryPasswordCallback) {\n return\n }\n\n if (newPasswordValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please enter a valid password'),\n }))\n return\n }\n\n if (newPasswordConfirmedValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please confirm your new password'),\n }))\n return\n }\n\n setLoginState((current) => ({\n ...current,\n isResettingPassword: true,\n loginError: null,\n }))\n\n try {\n const resetPasswordResponse = await resetTemporaryPasswordCallback(\n newPassword,\n )\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isResettingTemporaryPassword: false,\n loginAttemptResponse: resetPasswordResponse,\n }))\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setLoginState((current) => ({\n ...current,\n isResettingPassword: false,\n loginError: error as Error,\n }))\n }\n }\n }, [\n isMounted,\n loginAttemptResponse?.resetPasswordCallback,\n newPassword,\n newPasswordConfirmedValidation.isInvalid,\n newPasswordValidation.isInvalid,\n ])\n\n const submitMfaCode = React.useCallback(async () => {\n const mfaCodeCallback = loginAttemptResponse?.mfaCodeCallback\n if (!mfaCodeCallback) {\n return\n }\n\n setLoginState((current) => ({\n ...current,\n isSubmittingMfaCode: true,\n loginError: null,\n }))\n\n try {\n const mfaResponse = await mfaCodeCallback(code)\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isSubmittingMfaCode: false,\n loginAttemptResponse: mfaResponse,\n }))\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setLoginState((current) => ({\n ...current,\n isSubmittingMfaCode: false,\n loginError: error as Error,\n }))\n }\n }\n }, [code, isMounted, loginAttemptResponse?.mfaCodeCallback])\n\n // Forgot Password\n const [isShowingForgotPassword, showForgotPassword, hideForgotPassword] =\n useBooleanState(false)\n const [\n {\n resetForgottenPasswordCallback,\n isSendingForgotPasswordCode,\n isResettingForgottenPassword,\n forgotPasswordError,\n },\n setForgotPasswordState,\n ] = React.useState<{\n isSendingForgotPasswordCode: boolean\n forgotPasswordError: null | Error\n resetForgottenPasswordCallback:\n | null\n | ((code: string, newPassword: string) => void)\n isResettingForgottenPassword: boolean\n }>({\n isSendingForgotPasswordCode: false,\n forgotPasswordError: null,\n resetForgottenPasswordCallback: null,\n isResettingForgottenPassword: false,\n })\n const clearForgotPasswordError = React.useCallback(\n () =>\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: null,\n })),\n [],\n )\n const sendForgotPasswordCode = React.useCallback(async () => {\n if (usernameValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error('Please enter a valid email address'),\n }))\n return\n }\n\n setForgotPasswordState({\n isSendingForgotPasswordCode: true,\n resetForgottenPasswordCallback: null,\n forgotPasswordError: null,\n isResettingForgottenPassword: false,\n })\n\n try {\n const newResetForgottenPasswordCallback =\n await authService.forgotPassword(username)\n if (isMounted.current) {\n setForgotPasswordState({\n isSendingForgotPasswordCode: false,\n resetForgottenPasswordCallback: newResetForgottenPasswordCallback,\n forgotPasswordError: null,\n isResettingForgottenPassword: false,\n })\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setForgotPasswordState({\n isSendingForgotPasswordCode: false,\n resetForgottenPasswordCallback: null,\n forgotPasswordError: error as Error,\n isResettingForgottenPassword: false,\n })\n }\n }\n }, [isMounted, username, usernameValidation.isInvalid])\n\n const resetForgottenPassword = React.useCallback(async () => {\n if (!resetForgottenPasswordCallback) {\n return\n }\n\n if (codeValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error(\n 'Please enter the code that was sent to your email address',\n ),\n }))\n }\n if (newPasswordValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error('Please enter a valid password'),\n }))\n return\n }\n if (newPasswordConfirmedValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error('Please confirm your new password'),\n }))\n return\n }\n\n setForgotPasswordState((current) => ({\n ...current,\n isChangingPassword: true,\n forgotPasswordError: null,\n }))\n\n try {\n await resetForgottenPasswordCallback(code, newPassword)\n if (isMounted.current) {\n setForgotPasswordState({\n isSendingForgotPasswordCode: false,\n resetForgottenPasswordCallback: null,\n forgotPasswordError: null,\n isResettingForgottenPassword: false,\n })\n hideForgotPassword()\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setForgotPasswordState((current) => ({\n ...current,\n isChangingPassword: false,\n forgotPasswordError: error as Error,\n }))\n }\n }\n }, [\n resetForgottenPasswordCallback,\n codeValidation.isInvalid,\n newPasswordValidation.isInvalid,\n newPasswordConfirmedValidation.isInvalid,\n code,\n newPassword,\n isMounted,\n hideForgotPassword,\n ])\n\n const loginWithGoogle = React.useCallback(() => {\n authService.loginHostedUI('Google')\n }, [])\n\n return {\n // Login\n /** Open redirect user to the Google sign in */\n loginWithGoogle,\n loginWithUsernamePassword,\n isLoggingIn,\n loginError,\n clearLoginError,\n // Reset Temp Password\n isPasswordTemporary: !!loginAttemptResponse?.resetPasswordCallback,\n isResettingTemporaryPassword,\n resetTemporaryPassword,\n // MFA Code\n isMfaCodeRequired: !!loginAttemptResponse?.mfaCodeCallback,\n isSubmittingMfaCode,\n submitMfaCode,\n // Showing Forgot Password\n isShowingForgotPassword,\n showForgotPassword,\n hideForgotPassword,\n forgotPasswordError,\n clearForgotPasswordError,\n // Sending Forgot Password Code\n isSendingForgotPasswordCode,\n sendForgotPasswordCode,\n // Resetting Forgotten Password\n hasSentForgotPasswordCode: !!resetForgottenPasswordCallback,\n isResettingForgottenPassword,\n resetForgottenPassword,\n // Validation\n usernameValidation,\n passwordValidation,\n codeValidation,\n newPasswordValidation,\n newPasswordConfirmedValidation,\n }\n}\n\nexport interface UseLoginValue {\n /** Open redirect user to the Google sign-in page. */\n loginWithGoogle: () => void\n /**\n * Attempt to use the `username` and `password` arguments to create a session.\n * Will call `onLogin()` if successful, otherwise will set `loginError`.\n */\n loginWithUsernamePassword: () => void\n /** `true` while processing `loginWithUsernamePassword()`. */\n isLoggingIn: boolean\n /**\n * `true` if the user logged in using a temporary password. Prompt the user\n * for a new password and call `resetTemporaryPassword()`.\n */\n isPasswordTemporary: boolean\n /**\n * Attempt to use `newPassword` and `newPasswordConfirmed` arguments to reset\n * the user's password and create a session. Will call `onLogin()` if\n * successful, otherwise will set `loginError`.\n */\n resetTemporaryPassword: () => void\n /**\n * Set if an error occurs while processing `loginWithUsernamePassword()` or\n * `resetTemporaryPassword()`.\n */\n loginError: Error | null\n /** Set `loginError` back to `null`. */\n clearLoginError: () => void\n /** `true` while processing `resetTemporaryPassword()`. */\n isResettingTemporaryPassword: boolean\n /** `true` when showing the forgot password flow. */\n isShowingForgotPassword: boolean\n /** Set `isShowingForgotPassword` to `true`. */\n showForgotPassword: () => void\n /** Set `isShowingForgotPassword` to `false`. */\n hideForgotPassword: () => void\n /**\n * Attempt to use the `username` argument to start the forgot password\n * process. This will send the user an email with a code to enter. A failed\n * request will set `forgotPasswordError`.\n */\n sendForgotPasswordCode: () => void\n /** `true` while processing `sendForgotPasswordCode()`. */\n isSendingForgotPasswordCode: boolean\n /** `true` if the forgot password code has been successfully sent to the user. */\n hasSentForgotPasswordCode: boolean\n /**\n * Attempt to use the `code`, `newPassword`, and `newPasswordConfirmed`\n * arguments to reset the user's password. A failed request will set\n * `forgotPasswordError`.\n */\n resetForgottenPassword: () => void\n /** `true` while processing `resetForgottenPassword()`. */\n isResettingForgottenPassword: boolean\n /**\n * Set if an error occurs while processing `sendForgotPasswordCode()` or\n * `resetForgottenPassword()`.\n */\n forgotPasswordError: Error | null\n /** Set `forgotPasswordError` back to `null`. */\n clearForgotPasswordError: () => void\n usernameValidation: {\n /** `true` if the `username` argument is invalid. */\n isInvalid: boolean\n }\n passwordValidation: {\n /** `true` if the `password` argument is invalid. */\n isInvalid: boolean\n }\n codeValidation: {\n /** `true` if the `code` argument is invalid. */\n isInvalid: boolean\n }\n newPasswordValidation: {\n /** `true` if the `newPassword` argument is invalid. */\n isInvalid: boolean\n /**\n * `true` if the `newPassword` argument has a lowercase letter (required to\n * be valid).\n */\n hasLowercaseLetter: boolean\n /**\n * `true` if the `newPassword` argument has an uppercase letter (required to\n * be valid).\n */\n hasUpperCaseLetter: boolean\n /** `true` if the `newPassword` argument has a number (required to be valid). */\n hasNumber: boolean\n /**\n * `true` if the `newPassword` argument has a special character (required to\n * be valid).\n */\n hasSpecialCharacter: boolean\n /**\n * `true` if the `newPassword` argument has at least the minimum number of\n * characters (required to be valid).\n */\n hasMinLength: boolean\n }\n newPasswordConfirmedValidation: {\n /**\n * `true` if the `newPasswordConfirmed` argument is invalid (must match the\n * `newPassword` argument).\n */\n isInvalid: boolean\n }\n /**\n * `true` if the user logged in using MFA and a code is required to finish the\n * login attempt. Prompt the user for a code and call `submitMfaCode()`.\n */\n isMfaCodeRequired: boolean\n /** `true` while processing `submitMfaCode()`. */\n isSubmittingMfaCode: boolean\n /**\n * Attempt to use `code` argument to submit the MFA code and create a session.\n * Will call `onLogin()` if successful, otherwise will set `loginError`.\n */\n submitMfaCode: () => void\n}\n"]}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { FormTypes } from '@oneblink/types';
|
2
|
-
import {
|
1
|
+
import { FormTypes, SubmissionTypes } from '@oneblink/types';
|
2
|
+
import { SetFormSubmission } from '../types/form';
|
3
3
|
export default function useLookups(formId: number, setFormSubmission: SetFormSubmission): {
|
4
|
-
handlePagesLookupResult: (element: FormTypes.LookupFormElement, elementLookupData: FormTypes.PageElement[], dataLookupResult?:
|
4
|
+
handlePagesLookupResult: (element: FormTypes.LookupFormElement, elementLookupData: FormTypes.PageElement[], dataLookupResult?: SubmissionTypes.S3SubmissionData['submission']) => void;
|
5
5
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useLookups.js","sourceRoot":"","sources":["../../src/hooks/useLookups.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,mBAAmB,MAAM,mCAAmC,CAAA;AAInE,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,MAAc,EACd,iBAAoC;IAEpC,MAAM,uBAAuB,GAAG,KAAK,CAAC,WAAW,CAC/C,CACE,OAAoC,EACpC,iBAA0C,EAC1C,
|
1
|
+
{"version":3,"file":"useLookups.js","sourceRoot":"","sources":["../../src/hooks/useLookups.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,mBAAmB,MAAM,mCAAmC,CAAA;AAInE,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,MAAc,EACd,iBAAoC;IAEpC,MAAM,uBAAuB,GAAG,KAAK,CAAC,WAAW,CAC/C,CACE,OAAoC,EACpC,iBAA0C,EAC1C,gBAAiE,EACjE,EAAE;QACF,MAAM,eAAe,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACpD,GAAG,CAAC;YACJ,mBAAmB,EAAE,OAAO,CAAC,EAAE;SAChC,CAAC,CAAC,CAAA;QACH,iBAAiB,CAAC,CAAC,qBAAqB,EAAE,EAAE;YAC1C,MAAM,UAAU,GAAmB;gBACjC,GAAG,qBAAqB,CAAC,UAAU;gBACnC,WAAW,EAA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,UAAU,GAAG,mBAAmB,CAAC,UAAU,CAAC,QAAQ,EAAE;gBAC1D,GAAG,qBAAqB,CAAC,UAAU;gBACnC,GAAG,gBAAgB;aACpB,CAAC,CAAA;YACF,OAAO;gBACL,UAAU;gBACV,UAAU;gBACV,kBAAkB,EAAE,qBAAqB,CAAC,kBAAkB;aAC7D,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,EACD,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAC5B,CAAA;IAED,OAAO;QACL,uBAAuB;KACxB,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { formElementsService } from '@oneblink/sdk-core'\n\nimport generateDefaultData from '../services/generate-default-data'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { SetFormSubmission } from '../types/form'\n\nexport default function useLookups(\n formId: number,\n setFormSubmission: SetFormSubmission,\n) {\n const handlePagesLookupResult = React.useCallback(\n (\n element: FormTypes.LookupFormElement,\n elementLookupData: FormTypes.PageElement[],\n dataLookupResult?: SubmissionTypes.S3SubmissionData['submission'],\n ) => {\n const newPageElements = elementLookupData.map((e) => ({\n ...e,\n injectedByElementId: element.id,\n }))\n setFormSubmission((currentFormSubmission) => {\n const definition: FormTypes.Form = {\n ...currentFormSubmission.definition,\n isMultiPage: true,\n }\n if (!currentFormSubmission.definition.isMultiPage) {\n definition.elements = [\n {\n id: formId.toString(),\n type: 'page',\n label: 'Page 1',\n elements: currentFormSubmission.definition.elements,\n conditionallyShow: false,\n requiresAllConditionallyShowPredicates: false,\n },\n ...newPageElements,\n ]\n } else {\n const indexOfPage =\n currentFormSubmission.definition.elements.findIndex(\n (pageElement: FormTypes.FormElement) => {\n if (pageElement.type === 'page') {\n return formElementsService.findFormElement(\n pageElement.elements,\n (el) => el.id === element.id,\n )\n }\n },\n )\n if (indexOfPage === -1) {\n return currentFormSubmission\n }\n definition.elements =\n currentFormSubmission.definition.elements.reduce(\n (\n partialPageElements: FormTypes.FormElement[],\n pageElement: FormTypes.FormElement,\n index: number,\n ) => {\n // @ts-expect-error Sorry typescript, we need to add a property you don't approve of :(\n if (pageElement.injectedByElementId !== element.id) {\n partialPageElements.push(pageElement)\n }\n if (index === indexOfPage) {\n partialPageElements.push(...newPageElements)\n }\n return partialPageElements\n },\n [],\n )\n }\n\n const submission = generateDefaultData(definition.elements, {\n ...currentFormSubmission.submission,\n ...dataLookupResult,\n })\n return {\n submission,\n definition,\n lastElementUpdated: currentFormSubmission.lastElementUpdated,\n }\n })\n },\n [formId, setFormSubmission],\n )\n\n return {\n handlePagesLookupResult,\n }\n}\n"]}
|
@@ -1,2 +1,47 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
|
2
|
+
/**
|
3
|
+
* This function is a react hook for state of type of your choosing. It comes
|
4
|
+
* with two memoized functions, one for setting state and one for clearing it.
|
5
|
+
*
|
6
|
+
* The items returned in the array can be destructured and named whatever you
|
7
|
+
* like:
|
8
|
+
*
|
9
|
+
* ```js
|
10
|
+
* import { useNullableState } from '@oneblink/apps-react'
|
11
|
+
*
|
12
|
+
* const startingProfile = {
|
13
|
+
* name: 'Forest Gump',
|
14
|
+
* profession: 'Military, Athlete, Other',
|
15
|
+
* }
|
16
|
+
*
|
17
|
+
* const [userProfile, setUserProfile, unsetUserProfile] =
|
18
|
+
* useBooleanState(startingProfile)
|
19
|
+
* ```
|
20
|
+
*
|
21
|
+
* `setUserProfile` can then be called with an object of type `T` like:
|
22
|
+
*
|
23
|
+
* ```js
|
24
|
+
* setUserProfile({
|
25
|
+
* name: 'Walter White',
|
26
|
+
* profession: 'Chemistry Teacher (Secondary School), Other',
|
27
|
+
* })
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* And `unsetUserProfile` can be called like:
|
31
|
+
*
|
32
|
+
* ```js
|
33
|
+
* unsetUserProfile()
|
34
|
+
* ```
|
35
|
+
*
|
36
|
+
* @typeParam T The type of the state
|
37
|
+
* @param defaultValue
|
38
|
+
* @returns
|
39
|
+
* @group Hooks
|
40
|
+
*/
|
41
|
+
export default function useNullableState<T>(
|
42
|
+
/** The starting state for the hook. */
|
43
|
+
defaultValue: T | null): [
|
44
|
+
state: T | null,
|
45
|
+
setState: React.Dispatch<React.SetStateAction<T | null>>,
|
46
|
+
clearState: () => void
|
47
|
+
];
|
@@ -1,5 +1,46 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
|
2
|
+
/**
|
3
|
+
* This function is a react hook for state of type of your choosing. It comes
|
4
|
+
* with two memoized functions, one for setting state and one for clearing it.
|
5
|
+
*
|
6
|
+
* The items returned in the array can be destructured and named whatever you
|
7
|
+
* like:
|
8
|
+
*
|
9
|
+
* ```js
|
10
|
+
* import { useNullableState } from '@oneblink/apps-react'
|
11
|
+
*
|
12
|
+
* const startingProfile = {
|
13
|
+
* name: 'Forest Gump',
|
14
|
+
* profession: 'Military, Athlete, Other',
|
15
|
+
* }
|
16
|
+
*
|
17
|
+
* const [userProfile, setUserProfile, unsetUserProfile] =
|
18
|
+
* useBooleanState(startingProfile)
|
19
|
+
* ```
|
20
|
+
*
|
21
|
+
* `setUserProfile` can then be called with an object of type `T` like:
|
22
|
+
*
|
23
|
+
* ```js
|
24
|
+
* setUserProfile({
|
25
|
+
* name: 'Walter White',
|
26
|
+
* profession: 'Chemistry Teacher (Secondary School), Other',
|
27
|
+
* })
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* And `unsetUserProfile` can be called like:
|
31
|
+
*
|
32
|
+
* ```js
|
33
|
+
* unsetUserProfile()
|
34
|
+
* ```
|
35
|
+
*
|
36
|
+
* @typeParam T The type of the state
|
37
|
+
* @param defaultValue
|
38
|
+
* @returns
|
39
|
+
* @group Hooks
|
40
|
+
*/
|
41
|
+
export default function useNullableState(
|
42
|
+
/** The starting state for the hook. */
|
43
|
+
defaultValue) {
|
3
44
|
const [state, setState] = React.useState(defaultValue);
|
4
45
|
const unsetState = React.useCallback(() => setState(null), []);
|
5
46
|
return [state, setState, unsetState];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useNullableState.js","sourceRoot":"","sources":["../../src/hooks/useNullableState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,MAAM,CAAC,OAAO,UAAU,gBAAgB,
|
1
|
+
{"version":3,"file":"useNullableState.js","sourceRoot":"","sources":["../../src/hooks/useNullableState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB;AACtC,uCAAuC;AACvC,YAAsB;IAMtB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;IACtD,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;IAC9D,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA;AACtC,CAAC","sourcesContent":["import * as React from 'react'\n\n/**\n * This function is a react hook for state of type of your choosing. It comes\n * with two memoized functions, one for setting state and one for clearing it.\n *\n * The items returned in the array can be destructured and named whatever you\n * like:\n *\n * ```js\n * import { useNullableState } from '@oneblink/apps-react'\n *\n * const startingProfile = {\n * name: 'Forest Gump',\n * profession: 'Military, Athlete, Other',\n * }\n *\n * const [userProfile, setUserProfile, unsetUserProfile] =\n * useBooleanState(startingProfile)\n * ```\n *\n * `setUserProfile` can then be called with an object of type `T` like:\n *\n * ```js\n * setUserProfile({\n * name: 'Walter White',\n * profession: 'Chemistry Teacher (Secondary School), Other',\n * })\n * ```\n *\n * And `unsetUserProfile` can be called like:\n *\n * ```js\n * unsetUserProfile()\n * ```\n *\n * @typeParam T The type of the state\n * @param defaultValue\n * @returns\n * @group Hooks\n */\nexport default function useNullableState<T>(\n /** The starting state for the hook. */\n defaultValue: T | null,\n): [\n state: T | null,\n setState: React.Dispatch<React.SetStateAction<T | null>>,\n clearState: () => void,\n] {\n const [state, setState] = React.useState(defaultValue)\n const unsetState = React.useCallback(() => setState(null), [])\n return [state, setState, unsetState]\n}\n"]}
|