@contember/react-client-tenant 2.1.0-alpha.21 → 2.1.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/src/components/forms/PasswordlessSignInForm.cjs +2 -2
- package/dist/development/src/components/forms/PasswordlessSignInForm.cjs.map +1 -1
- package/dist/development/src/components/forms/PasswordlessSignInForm.js +2 -2
- package/dist/development/src/components/forms/PasswordlessSignInForm.js.map +1 -1
- package/dist/development/src/components/forms/PasswordlessSignInInitForm.cjs +6 -1
- package/dist/development/src/components/forms/PasswordlessSignInInitForm.cjs.map +1 -1
- package/dist/development/src/components/forms/PasswordlessSignInInitForm.js +6 -1
- package/dist/development/src/components/forms/PasswordlessSignInInitForm.js.map +1 -1
- package/dist/development/src/internal/hooks/useRedirectToBacklink.cjs +9 -4
- package/dist/development/src/internal/hooks/useRedirectToBacklink.cjs.map +1 -1
- package/dist/development/src/internal/hooks/useRedirectToBacklink.js +9 -4
- package/dist/development/src/internal/hooks/useRedirectToBacklink.js.map +1 -1
- package/dist/production/src/components/forms/PasswordlessSignInForm.cjs +2 -2
- package/dist/production/src/components/forms/PasswordlessSignInForm.cjs.map +1 -1
- package/dist/production/src/components/forms/PasswordlessSignInForm.js +2 -2
- package/dist/production/src/components/forms/PasswordlessSignInForm.js.map +1 -1
- package/dist/production/src/components/forms/PasswordlessSignInInitForm.cjs +5 -0
- package/dist/production/src/components/forms/PasswordlessSignInInitForm.cjs.map +1 -1
- package/dist/production/src/components/forms/PasswordlessSignInInitForm.js +5 -0
- package/dist/production/src/components/forms/PasswordlessSignInInitForm.js.map +1 -1
- package/dist/production/src/internal/hooks/useRedirectToBacklink.cjs +9 -4
- package/dist/production/src/internal/hooks/useRedirectToBacklink.cjs.map +1 -1
- package/dist/production/src/internal/hooks/useRedirectToBacklink.js +9 -4
- package/dist/production/src/internal/hooks/useRedirectToBacklink.js.map +1 -1
- package/dist/types/components/forms/PasswordlessSignInForm.d.ts +1 -1
- package/dist/types/components/forms/PasswordlessSignInForm.d.ts.map +1 -1
- package/dist/types/components/forms/PasswordlessSignInInitForm.d.ts.map +1 -1
- package/dist/types/internal/hooks/useRedirectToBacklink.d.ts +3 -1
- package/dist/types/internal/hooks/useRedirectToBacklink.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/forms/PasswordlessSignInForm.tsx +4 -4
- package/src/components/forms/PasswordlessSignInInitForm.tsx +6 -0
- package/src/internal/hooks/useRedirectToBacklink.ts +11 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/react-client-tenant",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.1.0-alpha.
|
|
4
|
+
"version": "2.1.0-alpha.22",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/production/index.js",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"directory": "packages/react-client-tenant"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@contember/graphql-client-tenant": "2.1.0-alpha.
|
|
38
|
-
"@contember/react-client": "2.1.0-alpha.
|
|
39
|
-
"@contember/react-utils": "2.1.0-alpha.
|
|
37
|
+
"@contember/graphql-client-tenant": "2.1.0-alpha.22",
|
|
38
|
+
"@contember/react-client": "2.1.0-alpha.22",
|
|
39
|
+
"@contember/react-utils": "2.1.0-alpha.22",
|
|
40
40
|
"@radix-ui/primitive": "^1.1.0",
|
|
41
41
|
"@radix-ui/react-slot": "^1.1.0",
|
|
42
42
|
"graphql-ts-client-api": "^3.1.17"
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ReactElement, useCallback, useMemo } from 'react'
|
|
2
1
|
import * as TenantApi from '@contember/graphql-client-tenant'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { useSetSessionToken } from '@contember/react-client'
|
|
3
|
+
import { ReactElement, useCallback, useMemo } from 'react'
|
|
5
4
|
import { useForm } from '../../contexts'
|
|
6
5
|
import { SignInPasswordlessMutationResult, useSignInPasswordlessMutation } from '../../hooks'
|
|
7
6
|
import { useRedirectToBacklinkCallback } from '../../internal/hooks/useRedirectToBacklink'
|
|
8
|
-
import {
|
|
7
|
+
import { FormContextValue, FormError, FormState } from '../../types/forms'
|
|
8
|
+
import { TenantForm } from './TenantForm'
|
|
9
9
|
|
|
10
10
|
export type PasswordlessSignInFormValues = {
|
|
11
11
|
token: string
|
|
@@ -5,6 +5,7 @@ import { FormContextValue, FormError, FormState } from '../../types/forms'
|
|
|
5
5
|
import { useForm } from '../../contexts'
|
|
6
6
|
import { InitSignInPasswordlessMutationResult, useInitSignInPasswordlessMutation } from '../../hooks'
|
|
7
7
|
import { PASSWORDLESS_REQUEST_STORAGE_KEY } from '../../consts'
|
|
8
|
+
import { useSaveBacklink } from '../../internal/hooks/useRedirectToBacklink'
|
|
8
9
|
|
|
9
10
|
export type PasswordlessSignInInitFormValues = {
|
|
10
11
|
email: string
|
|
@@ -33,10 +34,15 @@ export const usePasswordlessSignInInitForm = useForm as () => PasswordlessSignIn
|
|
|
33
34
|
export const PasswordlessSignInInitForm = ({ children, onSuccess }: PasswordlessSignInInitFormProps) => {
|
|
34
35
|
|
|
35
36
|
const initSignIn = useInitSignInPasswordlessMutation()
|
|
37
|
+
const saveBacklink = useSaveBacklink({
|
|
38
|
+
storage: 'local',
|
|
39
|
+
})
|
|
40
|
+
|
|
36
41
|
return (
|
|
37
42
|
<TenantForm<PasswordlessSignInInitFormContextValue, InitSignInPasswordlessMutationResult>
|
|
38
43
|
onSuccess={res => {
|
|
39
44
|
localStorage.setItem(PASSWORDLESS_REQUEST_STORAGE_KEY, res.result.requestId)
|
|
45
|
+
saveBacklink()
|
|
40
46
|
onSuccess?.(res)
|
|
41
47
|
}}
|
|
42
48
|
errorMapping={errorToField}
|
|
@@ -5,23 +5,30 @@ const getBacklinkFromUrl = () => {
|
|
|
5
5
|
return new URLSearchParams(window.location.search).get('backlink')
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export const useSaveBacklink = (
|
|
8
|
+
export const useSaveBacklink = ({ storage = 'session' }: {
|
|
9
|
+
storage?: 'session' | 'local'
|
|
10
|
+
} = {}) => {
|
|
9
11
|
return useCallback(() => {
|
|
10
12
|
const backlink = getBacklinkFromUrl()
|
|
11
13
|
if (!backlink) {
|
|
12
14
|
return
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
if (storage === 'local') {
|
|
17
|
+
localStorage.setItem('backlink', backlink)
|
|
18
|
+
} else {
|
|
19
|
+
sessionStorage.setItem('backlink', backlink)
|
|
20
|
+
}
|
|
21
|
+
}, [storage])
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
export const useRedirectToBacklinkCallback = () => {
|
|
19
25
|
return useCallback(() => {
|
|
20
|
-
const backlink = getBacklinkFromUrl() ?? sessionStorage.getItem('backlink')
|
|
26
|
+
const backlink = getBacklinkFromUrl() ?? sessionStorage.getItem('backlink') ?? localStorage.getItem('backlink')
|
|
21
27
|
if (!backlink) {
|
|
22
28
|
return
|
|
23
29
|
}
|
|
24
30
|
sessionStorage.removeItem('backlink')
|
|
31
|
+
localStorage.removeItem('backlink')
|
|
25
32
|
const resolvedBacklink = new URL(backlink, window.location.href)
|
|
26
33
|
if (resolvedBacklink.origin === window.location.origin) {
|
|
27
34
|
window.location.href = resolvedBacklink.toString()
|