@contember/create 2.1.0-alpha.16 → 2.1.0-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/create",
3
- "version": "2.1.0-alpha.16",
3
+ "version": "2.1.0-alpha.17",
4
4
  "license": "Apache-2.0",
5
5
  "bin": "dist/production/run.js",
6
6
  "dependencies": {
@@ -3,7 +3,7 @@ import { InviteErrorCodes } from './tenant/hooks/useInvite'
3
3
  import { UploaderErrorType } from '@contember/react-uploader'
4
4
  import { ChangeMyPasswordFormErrorCode, CreateApiKeyFormErrorCode } from '@contember/interface'
5
5
  import { InviteFormErrorCode, LoginFormErrorCode, OtpPrepareFormErrorCode, OtpConfirmFormErrorCode, PasswordResetFormErrorCode, PasswordResetRequestFormErrorCode, UpdateProjectMemberFormErrorCode, PasswordlessSignInInitFormErrorCode, PasswordlessSignInFormErrorCode } from '@contember/react-identity'
6
- import { ActivatePasswordlessOtpErrorCode } from '@contember/graphql-client-tenant'
6
+ import { ActivatePasswordlessOtpErrorCode, WeakPasswordReason } from '@contember/graphql-client-tenant'
7
7
 
8
8
  export const dict = {
9
9
  deleteEntityDialog: {
@@ -209,6 +209,8 @@ export const dict = {
209
209
  'NO_PASSWORD_SET': 'No password set',
210
210
  'PERSON_DISABLED': 'Person disabled',
211
211
  'UNKNOWN_EMAIL': 'Unknown email',
212
+ 'INVALID_CREDENTIALS': 'Invalid credentials',
213
+ 'RATE_LIMIT_EXCEEDED': 'Too many failed attempts, please try again later',
212
214
  'OTP_REQUIRED': undefined,
213
215
  } satisfies Record<LoginFormErrorCode, string | undefined>,
214
216
  idpInitError: 'Failed to initialize IdP login:',
@@ -6,18 +6,20 @@ import {
6
6
  createImageFileType,
7
7
  createVideoFileType,
8
8
  FileType,
9
+ FileWithMeta,
9
10
  ImageFileTypeProps,
10
11
  MultiUploader,
11
12
  UploaderBaseFieldProps,
12
13
  UploaderHasFile,
14
+ useMultiUploaderFileState,
13
15
  useS3Client,
14
16
  VideoFileTypeProps,
15
17
  } from '@contember/react-uploader'
16
18
  import * as React from 'react'
17
- import { ReactNode, useId, useMemo, useState } from 'react'
19
+ import { ReactNode, useMemo, useState } from 'react'
18
20
  import { FormContainer, FormContainerProps } from './container'
19
- import { Component } from '@contember/interface'
20
- import { FormErrorContext, FormFieldIdContext, FormFieldStateProvider } from '@contember/react-form'
21
+ import { Component, useEntity } from '@contember/interface'
22
+ import { FormFieldStateProvider } from '@contember/react-form'
21
23
  import {
22
24
  UploadedAnyView,
23
25
  UploadedAudioView,
@@ -39,6 +41,7 @@ import {
39
41
  RepeaterSortableItemNode,
40
42
  } from '@contember/react-repeater-dnd-kit'
41
43
  import { UploaderRepeaterDropIndicator } from '../upload/repeater'
44
+ import { Loader } from '../ui/loader'
42
45
 
43
46
 
44
47
  export type BaseFileRepeaterFieldProps =
@@ -57,7 +60,11 @@ export type ImageRepeaterFieldProps =
57
60
  & ImageFileTypeProps
58
61
 
59
62
  export const ImageRepeaterField = Component<ImageRepeaterFieldProps>(props => <>
60
- <FileRepeaterFieldInner {...props} fileType={createImageFileType(props)}>
63
+ <FileRepeaterFieldInner {...props} fileType={createImageFileType(props)} renderPreview={file => {
64
+ return <div className="flex items-center justify-center h-40 rounded-md group relative">
65
+ <img src={file.file.previewUrl} className="max-w-full max-h-full" />
66
+ </div>
67
+ }}>
61
68
  {props.children ?? (
62
69
  <UploadedImageView {...props} DestroyAction={RepeaterRemoveItemTrigger} />
63
70
  )}
@@ -104,11 +111,16 @@ export const FileRepeaterField = Component<FileRepeaterFieldProps>(props => <>
104
111
  </>)
105
112
 
106
113
 
114
+ type PreviewRenderer = (props: {
115
+ file: FileWithMeta
116
+ }) => ReactNode
117
+
107
118
  type FileRepeaterFieldInnerProps =
108
119
  & BaseFileRepeaterFieldProps
109
120
  & {
110
121
  fileType: FileType
111
122
  children: ReactNode
123
+ renderPreview?: PreviewRenderer
112
124
  }
113
125
 
114
126
  const FileRepeaterFieldInner = Component<FileRepeaterFieldInnerProps>(({
@@ -118,6 +130,7 @@ const FileRepeaterFieldInner = Component<FileRepeaterFieldInnerProps>(({
118
130
  children,
119
131
  fileType,
120
132
  dropzonePlaceholder,
133
+ renderPreview,
121
134
  ...props
122
135
  }) => {
123
136
 
@@ -145,34 +158,37 @@ const FileRepeaterFieldInner = Component<FileRepeaterFieldInnerProps>(({
145
158
  <UploaderProgress />
146
159
  </UploaderHasFile>
147
160
  <UploaderDropzone dropzonePlaceholder={dropzonePlaceholder} />
148
- </MultiUploader>
149
161
 
150
- <RepeaterSortable>
162
+ <RepeaterSortable>
163
+
164
+ <RepeaterSortableEachItem>
165
+ <div className="flex">
166
+ <UploaderRepeaterDropIndicator position={'before'} />
167
+ <RepeaterSortableItemNode>
168
+ <UploaderRepeaterItemUI>
169
+ <RepeaterSortableItemActivator>
170
+ <UploaderRepeaterHandleUI />
171
+ </RepeaterSortableItemActivator>
151
172
 
152
- <RepeaterSortableEachItem>
153
- <div className="flex">
154
- <UploaderRepeaterDropIndicator position={'before'} />
155
- <RepeaterSortableItemNode>
156
- <UploaderRepeaterItemUI>
157
- <RepeaterSortableItemActivator>
158
- <UploaderRepeaterHandleUI />
159
- </RepeaterSortableItemActivator>
160
- {children}
161
- </UploaderRepeaterItemUI>
162
- </RepeaterSortableItemNode>
163
- <UploaderRepeaterDropIndicator position={'after'} />
164
- </div>
173
+ <FileRepeaterItemPreview renderPreview={renderPreview} >
174
+ {children}
175
+ </FileRepeaterItemPreview>
176
+ </UploaderRepeaterItemUI>
177
+ </RepeaterSortableItemNode>
178
+ <UploaderRepeaterDropIndicator position={'after'} />
179
+ </div>
165
180
 
166
181
 
167
- </RepeaterSortableEachItem>
182
+ </RepeaterSortableEachItem>
168
183
 
169
- <RepeaterSortableDragOverlay>
170
- <UploaderRepeaterDragOverlayUI>
171
- {children}
172
- </UploaderRepeaterDragOverlayUI>
173
- </RepeaterSortableDragOverlay>
184
+ <RepeaterSortableDragOverlay>
185
+ <UploaderRepeaterDragOverlayUI>
186
+ {children}
187
+ </UploaderRepeaterDragOverlayUI>
188
+ </RepeaterSortableDragOverlay>
174
189
 
175
- </RepeaterSortable>
190
+ </RepeaterSortable>
191
+ </MultiUploader>
176
192
  </UploaderRepeaterItemsWrapperUI>
177
193
  </Repeater>
178
194
  </FormContainer>
@@ -186,3 +202,16 @@ const FileRepeaterFieldInner = Component<FileRepeaterFieldInnerProps>(({
186
202
  </Repeater>
187
203
  </>
188
204
  }, 'FileRepeaterFieldInner')
205
+
206
+ const FileRepeaterItemPreview = ({ renderPreview, children }: { renderPreview?: PreviewRenderer; children: ReactNode }) => {
207
+ const entity = useEntity()
208
+ const fileState = useMultiUploaderFileState(entity)
209
+ if (!fileState || fileState.state === 'success' || fileState.state === 'error') {
210
+ return <>{children}</>
211
+ }
212
+
213
+ return <>
214
+ {renderPreview?.({ file: fileState.file })}
215
+ <Loader position="absolute" className="bg-transparent" />
216
+ </>
217
+ }