@contember/create 2.0.0-alpha.14 → 2.0.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@contember/create",
3
- "version": "2.0.0-alpha.14",
3
+ "version": "2.0.0-alpha.15",
4
4
  "license": "Apache-2.0",
5
5
  "bin": "dist/production/run.js",
6
6
  "dependencies": {
7
- "@contember/cli-common": "2.0.0-alpha.14",
7
+ "@contember/cli-common": "2.0.0-alpha.15",
8
8
  "chalk": "^4.1.2",
9
9
  "download-tarball": "^2.0.0",
10
10
  "fs-extra": "^11.1.1",
@@ -1,12 +1,14 @@
1
1
  import { ReactNode, useEffect } from 'react'
2
2
  import { AccessorTreeState, DataBindingProvider } from '@contember/interface'
3
3
  import { Loader } from '../ui/loader'
4
+ import { NavigationGuardDialog } from './navigation-guard-dialog'
4
5
 
5
6
  export const Binding = ({ children }: {
6
7
  children: ReactNode
7
8
  }) => {
8
9
  return (
9
10
  <DataBindingProvider stateComponent={BindingStateRenderer}>
11
+ <NavigationGuardDialog />
10
12
  {children}
11
13
  </DataBindingProvider>
12
14
  )
@@ -1,7 +1,7 @@
1
- import { ReactNode, useCallback } from 'react'
1
+ import { useCallback } from 'react'
2
2
  import { dict } from '../dict'
3
3
  import { ToastContent, useShowToast } from '../toast'
4
- import { ErrorAccessor, ErrorPersistResult, SuccessfulPersistResult, usePersist } from '@contember/interface'
4
+ import { ErrorPersistResult, SuccessfulPersistResult, usePersist } from '@contember/interface'
5
5
  import { useErrorFormatter } from '../errors'
6
6
 
7
7
  export const usePersistWithFeedback = () => {
@@ -0,0 +1,39 @@
1
+ import { useCallback, useState } from 'react'
2
+ import { AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogTitle } from '../ui/alert-dialog'
3
+ import { BlockNavigationOnDirtyStateResult, useBlockNavigationOnDirtyState } from '@contember/interface'
4
+ import { usePersistFeedbackHandlers } from './hooks'
5
+ import { Button } from '../ui/button'
6
+ import { SaveIcon } from 'lucide-react'
7
+
8
+ export const NavigationGuardDialog = () => {
9
+ const [resolver, setResolver] = useState<((value: BlockNavigationOnDirtyStateResult) => void) | null>(null)
10
+
11
+ const handler = useCallback(() => new Promise<BlockNavigationOnDirtyStateResult>(resolve => {
12
+ setResolver(() => (value: BlockNavigationOnDirtyStateResult) => {
13
+ setResolver(null)
14
+ resolve(value)
15
+ })
16
+ }), [])
17
+
18
+ useBlockNavigationOnDirtyState(handler, usePersistFeedbackHandlers())
19
+
20
+ return (
21
+ <AlertDialog open={resolver !== null} onOpenChange={it => it ? null : resolver?.('cancel')}>
22
+ <AlertDialogContent>
23
+ <AlertDialogTitle>Unsaved changes</AlertDialogTitle>
24
+ Do you want to save your changes before leaving?
25
+ <div className="flex gap-2 justify-end">
26
+ <Button onClick={() => resolver?.('save')}>
27
+ <SaveIcon className="w-4 h-4 mr-2" />
28
+ Save
29
+ </Button>
30
+ <Button onClick={() => resolver?.('discard')} variant="outline"
31
+ className="border-destructive/50 text-destructive hover:bg-red-100 hover:text-destructive">
32
+ Don&apos;t save
33
+ </Button>
34
+ <AlertDialogCancel onClick={() => resolver?.('cancel')} className="border-gray-500">Cancel</AlertDialogCancel>
35
+ </div>
36
+ </AlertDialogContent>
37
+ </AlertDialog>
38
+ )
39
+ }
@@ -2,7 +2,8 @@ import { TextFilterArtifactsMatchMode } from '@contember/react-dataview'
2
2
  import { InviteErrorCodes } from './tenant/hooks/useInvite'
3
3
  import { UploaderErrorType } from '@contember/react-uploader'
4
4
  import { ChangeMyPasswordFormErrorCode, CreateApiKeyFormErrorCode } from '@contember/interface'
5
- import { InviteFormErrorCode, LoginFormErrorCode, OtpPrepareFormErrorCode, OtpConfirmFormErrorCode, PasswordResetFormErrorCode, PasswordResetRequestFormErrorCode, UpdateProjectMemberFormErrorCode } from '@contember/react-identity'
5
+ import { InviteFormErrorCode, LoginFormErrorCode, OtpPrepareFormErrorCode, OtpConfirmFormErrorCode, PasswordResetFormErrorCode, PasswordResetRequestFormErrorCode, UpdateProjectMemberFormErrorCode, PasswordlessSignInInitFormErrorCode, PasswordlessSignInFormErrorCode } from '@contember/react-identity'
6
+ import { ActivatePasswordlessOtpErrorCode } from '@contember/graphql-client-tenant'
6
7
 
7
8
  export const dict = {
8
9
  deleteEntityDialog: {
@@ -194,7 +195,7 @@ export const dict = {
194
195
  login: {
195
196
  email: 'Email',
196
197
  password: 'Password',
197
- otpToken: 'OTP token',
198
+ otpToken: '2FA OTP token',
198
199
  forgotPassword: 'Forgot password?',
199
200
  login: 'Login',
200
201
  errorMessages: {
@@ -275,13 +276,14 @@ export const dict = {
275
276
  'TOKEN_EXPIRED': 'Token expired',
276
277
  'TOKEN_NOT_FOUND': 'Token not found',
277
278
  'TOKEN_USED': 'Token already used',
279
+ 'TOKEN_INVALID': 'Invalid token',
278
280
  } satisfies Record<PasswordResetFormErrorCode, string>,
279
281
  title: 'Reset password',
280
282
  description: 'Enter new password below',
281
283
  success: 'Password has been reset',
282
284
  },
283
285
  passwordResetRequest: {
284
- email: 'Email',
286
+ email: 'E-mail',
285
287
  submit: 'Request reset code',
286
288
  errorMessages: {
287
289
  'FIELD_REQUIRED': 'This field is required',
@@ -295,6 +297,50 @@ export const dict = {
295
297
  checkMail: 'Please check your mailbox for instructions on how to reset your password.',
296
298
  entryCode: 'Or enter the reset code directly.',
297
299
  },
300
+ passwordlessSignInInit: {
301
+ email: 'E-mail',
302
+ submit: 'Send magic link',
303
+ errorMessages: {
304
+ 'FIELD_REQUIRED': 'This field is required',
305
+ 'INVALID_VALUE': 'Invalid value',
306
+ 'UNKNOWN_ERROR': 'Something went wrong. Please try again later',
307
+ 'PERSON_NOT_FOUND': 'Unknown email',
308
+ 'PASSWORDLESS_DISABLED': 'Passwordless sign-in is not available',
309
+ } satisfies Record<PasswordlessSignInInitFormErrorCode, string>,
310
+ title: 'Sign in',
311
+ description: 'Enter your email below to sign in to your account',
312
+ success: 'Magic link has been sent',
313
+ checkMail: 'Please check your mailbox for instructions on how to sign in.',
314
+ entryCode: 'Or enter the reset code directly.',
315
+ },
316
+ passwordlessSignIn: {
317
+ token: 'Verification code',
318
+ otpToken: '2FA OTP token',
319
+ submit: 'Sign in',
320
+ errorMessages: {
321
+ 'FIELD_REQUIRED': 'This field is required',
322
+ 'INVALID_VALUE': 'Invalid value',
323
+ 'UNKNOWN_ERROR': 'Something went wrong. Please try again later',
324
+ 'INVALID_OTP_TOKEN': 'Invalid OTP token',
325
+ 'OTP_REQUIRED': undefined,
326
+ 'PERSON_DISABLED': 'Person disabled',
327
+ 'TOKEN_EXPIRED': 'Token expired',
328
+ 'TOKEN_NOT_FOUND': 'Token not found',
329
+ 'TOKEN_USED': 'Token already used',
330
+ 'TOKEN_INVALID': 'Invalid token',
331
+ } satisfies Record<PasswordlessSignInFormErrorCode, string | undefined>,
332
+ title: 'Sign in',
333
+ },
334
+ otpActivation: {
335
+ errorMessages: {
336
+ 'TOKEN_INVALID': 'This token is not valid. Please try again.',
337
+ 'TOKEN_USED': 'Token already used',
338
+ 'TOKEN_NOT_FOUND': 'Token not found',
339
+ 'TOKEN_EXPIRED': 'Token expired',
340
+ 'UNKNOWN_ERROR': 'Something went wrong. Please try again later',
341
+ } satisfies Record<ActivatePasswordlessOtpErrorCode | 'UNKNOWN_ERROR', string>,
342
+ },
343
+
298
344
  updateProjectMember: {
299
345
  updateSuccess: 'Roles updated',
300
346
  roles: 'Roles',
@@ -7,6 +7,7 @@ import { dict } from '../../dict'
7
7
 
8
8
  export const PasswordResetFormFields = ({ hasToken }: { hasToken?: boolean }) => {
9
9
  const form = usePasswordResetForm()
10
+ const fieldErrors = form.errors.map(it => it.field)
10
11
  return (
11
12
  <div className="relative flex flex-col gap-2">
12
13
  {form.state === 'success' || form.state === 'submitting' ? <Loader position="absolute" /> : null}
@@ -15,7 +16,7 @@ export const PasswordResetFormFields = ({ hasToken }: { hasToken?: boolean }) =>
15
16
  form={form} messages={dict.tenant.passwordReset.errorMessages}
16
17
  />
17
18
 
18
- {hasToken ? null : (
19
+ {(!hasToken || fieldErrors.includes('token')) && (
19
20
  <TenantFormField
20
21
  form={form} messages={dict.tenant.passwordReset.errorMessages} field="token"
21
22
  type="text" required autoComplete="off"
@@ -0,0 +1,31 @@
1
+ import { usePasswordlessSignInInitForm } from '@contember/react-identity'
2
+ import { Button } from '../../ui/button'
3
+ import { Loader } from '../../ui/loader'
4
+ import { TenantFormError, TenantFormField } from './common'
5
+ import { dict } from '../../dict'
6
+
7
+
8
+ export const PasswordlessSignInInitFormFields = () => {
9
+ const form = usePasswordlessSignInInitForm()
10
+ return (
11
+ <div className="relative flex flex-col gap-2">
12
+ {form.state === 'success' || form.state === 'submitting' ? <Loader position="absolute" /> : null}
13
+
14
+ <TenantFormError
15
+ form={form} messages={dict.tenant.passwordlessSignInInit.errorMessages}
16
+ />
17
+
18
+ <TenantFormField
19
+ form={form} messages={dict.tenant.passwordlessSignInInit.errorMessages} field="email"
20
+ type="email" required autoFocus autoComplete="email"
21
+ >
22
+ {dict.tenant.passwordlessSignInInit.email}
23
+ </TenantFormField>
24
+
25
+ <Button type="submit" className="w-full" disabled={form.state === 'submitting'}>
26
+ {dict.tenant.passwordlessSignInInit.submit}
27
+ </Button>
28
+ </div>
29
+ )
30
+ }
31
+
@@ -0,0 +1,59 @@
1
+ import { usePasswordlessSignInForm } from '@contember/react-identity'
2
+ import { Button } from '../../ui/button'
3
+ import { Loader } from '../../ui/loader'
4
+ import { TenantFormError, TenantFormField } from './common'
5
+ import { dict } from '../../dict'
6
+ import { useEffect, useRef, useState } from 'react'
7
+
8
+
9
+ export const PasswordlessSignInFormFields = ({ type, email }: { type: 'token' | 'otp'; email?: string }) => {
10
+ const form = usePasswordlessSignInForm()
11
+ const fieldErrors = form.errors.map(it => it.field)
12
+ const buttonRef = useRef<HTMLButtonElement | null>(null)
13
+ const [initialTokenValue] = useState(form.values.token)
14
+ const hasToken = type === 'token' && initialTokenValue
15
+ useEffect(() => {
16
+ if (hasToken) {
17
+ buttonRef.current?.click()
18
+ }
19
+ }, [hasToken])
20
+ const setValues = form.setValues
21
+
22
+ useEffect(() => {
23
+ if (type === 'otp') {
24
+ setValues(it => ({ ...it, token: it.token.toUpperCase() }))
25
+ }
26
+ }, [setValues, type, form.values.token])
27
+
28
+ return (
29
+ <div className="relative flex flex-col gap-2">
30
+ {form.state === 'success' || form.state === 'submitting' ? <Loader position="absolute" /> : null}
31
+
32
+ <TenantFormError
33
+ form={form} messages={dict.tenant.passwordlessSignIn.errorMessages}
34
+ />
35
+
36
+ {(!hasToken || fieldErrors.includes('token')) && <TenantFormField
37
+ form={form} messages={dict.tenant.passwordlessSignIn.errorMessages} field="token"
38
+ type="text" required autoComplete="off" autoFocus
39
+ className={type === 'otp' ? 'text-2xl font-bold font-mono' : ''}
40
+ >
41
+ {dict.tenant.passwordlessSignIn.token}
42
+ </TenantFormField>}
43
+
44
+ {(form.state === 'otp-required' || fieldErrors.includes('otpToken')) && (
45
+ <TenantFormField
46
+ form={form} messages={dict.tenant.passwordlessSignIn.errorMessages} field="otpToken" autoComplete="one-time-code"
47
+ type="text" required autoFocus maxLength={6}
48
+ >
49
+ {dict.tenant.passwordlessSignIn.otpToken}
50
+ </TenantFormField>
51
+ )}
52
+
53
+ <Button type="submit" className="w-full" disabled={form.state === 'submitting'} ref={buttonRef}>
54
+ {dict.tenant.passwordlessSignIn.submit}
55
+ </Button>
56
+ </div>
57
+ )
58
+ }
59
+