@commercetools-frontend-extensions/operations 0.0.0-canary-20251209161906

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.
Files changed (180) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +178 -0
  3. package/babel.config.js +6 -0
  4. package/dist/commercetools-frontend-extensions-operations.cjs.d.ts +2 -0
  5. package/dist/commercetools-frontend-extensions-operations.cjs.dev.js +3273 -0
  6. package/dist/commercetools-frontend-extensions-operations.cjs.js +7 -0
  7. package/dist/commercetools-frontend-extensions-operations.cjs.prod.js +3265 -0
  8. package/dist/commercetools-frontend-extensions-operations.esm.js +3074 -0
  9. package/dist/declarations/src/@api/export-operations.d.ts +5 -0
  10. package/dist/declarations/src/@api/fetcher.d.ts +17 -0
  11. package/dist/declarations/src/@api/file-import-jobs.d.ts +7 -0
  12. package/dist/declarations/src/@api/file-upload.d.ts +3 -0
  13. package/dist/declarations/src/@api/import-containers.d.ts +35 -0
  14. package/dist/declarations/src/@api/import-operations.d.ts +6 -0
  15. package/dist/declarations/src/@api/index.d.ts +9 -0
  16. package/dist/declarations/src/@api/process-file.d.ts +3 -0
  17. package/dist/declarations/src/@api/test-fixtures.d.ts +279 -0
  18. package/dist/declarations/src/@api/urls.d.ts +74 -0
  19. package/dist/declarations/src/@components/file-drop-area/active-drag-drop-area.d.ts +10 -0
  20. package/dist/declarations/src/@components/file-drop-area/disabled-drop-area.d.ts +5 -0
  21. package/dist/declarations/src/@components/file-drop-area/drop-area-wrapper.d.ts +11 -0
  22. package/dist/declarations/src/@components/file-drop-area/enabled-drop-area.d.ts +7 -0
  23. package/dist/declarations/src/@components/file-drop-area/file-drop-area.d.ts +14 -0
  24. package/dist/declarations/src/@components/file-drop-area/file-dropped-area.d.ts +6 -0
  25. package/dist/declarations/src/@components/file-drop-area/index.d.ts +7 -0
  26. package/dist/declarations/src/@components/file-drop-area/styles.d.ts +9 -0
  27. package/dist/declarations/src/@components/icons/file-icon.d.ts +2 -0
  28. package/dist/declarations/src/@components/icons/index.d.ts +2 -0
  29. package/dist/declarations/src/@components/icons/lock-icon.d.ts +2 -0
  30. package/dist/declarations/src/@components/index.d.ts +6 -0
  31. package/dist/declarations/src/@components/info-box/index.d.ts +1 -0
  32. package/dist/declarations/src/@components/info-box/info-box.d.ts +7 -0
  33. package/dist/declarations/src/@components/upload-separator/index.d.ts +1 -0
  34. package/dist/declarations/src/@components/upload-separator/upload-separator.d.ts +12 -0
  35. package/dist/declarations/src/@components/upload-settings/index.d.ts +1 -0
  36. package/dist/declarations/src/@components/upload-settings/upload-settings.d.ts +11 -0
  37. package/dist/declarations/src/@components/uploading-modal/index.d.ts +1 -0
  38. package/dist/declarations/src/@components/uploading-modal/uploading-modal.d.ts +13 -0
  39. package/dist/declarations/src/@constants/delimiters.d.ts +8 -0
  40. package/dist/declarations/src/@constants/file-import-job.d.ts +1 -0
  41. package/dist/declarations/src/@constants/import-limits.d.ts +6 -0
  42. package/dist/declarations/src/@constants/import-tags.d.ts +7 -0
  43. package/dist/declarations/src/@constants/index.d.ts +5 -0
  44. package/dist/declarations/src/@constants/resource-links.d.ts +10 -0
  45. package/dist/declarations/src/@errors/http-error.d.ts +6 -0
  46. package/dist/declarations/src/@errors/index.d.ts +9 -0
  47. package/dist/declarations/src/@errors/invalid-response-error.d.ts +3 -0
  48. package/dist/declarations/src/@errors/no-resources-to-export-error.d.ts +3 -0
  49. package/dist/declarations/src/@errors/polling-aborted-error.d.ts +3 -0
  50. package/dist/declarations/src/@errors/project-key-not-available-error.d.ts +3 -0
  51. package/dist/declarations/src/@errors/query-predicate-error.d.ts +4 -0
  52. package/dist/declarations/src/@errors/unexpected-column-error.d.ts +3 -0
  53. package/dist/declarations/src/@errors/unexpected-operation-state-error.d.ts +4 -0
  54. package/dist/declarations/src/@errors/unexpected-resource-type-error.d.ts +3 -0
  55. package/dist/declarations/src/@hooks/index.d.ts +8 -0
  56. package/dist/declarations/src/@hooks/use-fetch-export-operations.d.ts +15 -0
  57. package/dist/declarations/src/@hooks/use-fetch-file-import-job.d.ts +17 -0
  58. package/dist/declarations/src/@hooks/use-fetch-import-container-details.d.ts +15 -0
  59. package/dist/declarations/src/@hooks/use-fetch-import-operations.d.ts +16 -0
  60. package/dist/declarations/src/@hooks/use-fetch-import-summaries.d.ts +20 -0
  61. package/dist/declarations/src/@hooks/use-file-import-job-upload.d.ts +18 -0
  62. package/dist/declarations/src/@hooks/use-file-upload.d.ts +28 -0
  63. package/dist/declarations/src/@hooks/use-import-container-upload.d.ts +19 -0
  64. package/dist/declarations/src/@types/api.d.ts +13 -0
  65. package/dist/declarations/src/@types/basic-error-data-type.d.ts +5 -0
  66. package/dist/declarations/src/@types/export-operation.d.ts +97 -0
  67. package/dist/declarations/src/@types/file-import-job.d.ts +99 -0
  68. package/dist/declarations/src/@types/file-upload-result.d.ts +21 -0
  69. package/dist/declarations/src/@types/file-upload.d.ts +63 -0
  70. package/dist/declarations/src/@types/import-container.d.ts +53 -0
  71. package/dist/declarations/src/@types/import-operation.d.ts +13 -0
  72. package/dist/declarations/src/@types/import-states.d.ts +9 -0
  73. package/dist/declarations/src/@types/import-summary.d.ts +15 -0
  74. package/dist/declarations/src/@types/index.d.ts +11 -0
  75. package/dist/declarations/src/@types/shared.d.ts +7 -0
  76. package/dist/declarations/src/@utils/error-mapping.d.ts +19 -0
  77. package/dist/declarations/src/@utils/file-import-job-helpers.d.ts +12 -0
  78. package/dist/declarations/src/@utils/file-upload.d.ts +54 -0
  79. package/dist/declarations/src/@utils/form.d.ts +1 -0
  80. package/dist/declarations/src/@utils/format.d.ts +5 -0
  81. package/dist/declarations/src/@utils/import-container.d.ts +8 -0
  82. package/dist/declarations/src/@utils/index.d.ts +8 -0
  83. package/dist/declarations/src/@utils/poll-job-until-validated.d.ts +11 -0
  84. package/dist/declarations/src/@utils/url.d.ts +6 -0
  85. package/dist/declarations/src/index.d.ts +26 -0
  86. package/index.js +1 -0
  87. package/jest.test.config.js +11 -0
  88. package/package.json +62 -0
  89. package/src/@api/export-operations.ts +26 -0
  90. package/src/@api/fetcher.spec.ts +51 -0
  91. package/src/@api/fetcher.ts +137 -0
  92. package/src/@api/file-import-jobs.ts +217 -0
  93. package/src/@api/file-upload.spec.ts +85 -0
  94. package/src/@api/file-upload.ts +46 -0
  95. package/src/@api/import-containers.ts +256 -0
  96. package/src/@api/import-operations.ts +33 -0
  97. package/src/@api/index.ts +9 -0
  98. package/src/@api/process-file.spec.ts +74 -0
  99. package/src/@api/process-file.ts +53 -0
  100. package/src/@api/test-fixtures.ts +894 -0
  101. package/src/@api/urls.ts +194 -0
  102. package/src/@components/file-drop-area/active-drag-drop-area.tsx +33 -0
  103. package/src/@components/file-drop-area/disabled-drop-area.tsx +17 -0
  104. package/src/@components/file-drop-area/drop-area-wrapper.tsx +38 -0
  105. package/src/@components/file-drop-area/enabled-drop-area.tsx +27 -0
  106. package/src/@components/file-drop-area/file-drop-area.tsx +74 -0
  107. package/src/@components/file-drop-area/file-dropped-area.tsx +29 -0
  108. package/src/@components/file-drop-area/index.ts +7 -0
  109. package/src/@components/file-drop-area/styles.ts +67 -0
  110. package/src/@components/icons/file-icon.tsx +30 -0
  111. package/src/@components/icons/index.ts +2 -0
  112. package/src/@components/icons/lock-icon.tsx +34 -0
  113. package/src/@components/index.ts +6 -0
  114. package/src/@components/info-box/index.ts +1 -0
  115. package/src/@components/info-box/info-box.tsx +23 -0
  116. package/src/@components/upload-separator/index.ts +1 -0
  117. package/src/@components/upload-separator/upload-separator.tsx +61 -0
  118. package/src/@components/upload-settings/index.ts +1 -0
  119. package/src/@components/upload-settings/upload-settings.tsx +36 -0
  120. package/src/@components/uploading-modal/index.ts +1 -0
  121. package/src/@components/uploading-modal/uploading-modal.tsx +66 -0
  122. package/src/@constants/delimiters.ts +14 -0
  123. package/src/@constants/file-import-job.ts +1 -0
  124. package/src/@constants/import-limits.ts +13 -0
  125. package/src/@constants/import-tags.ts +9 -0
  126. package/src/@constants/index.ts +5 -0
  127. package/src/@constants/resource-links.ts +61 -0
  128. package/src/@errors/http-error.ts +17 -0
  129. package/src/@errors/index.ts +9 -0
  130. package/src/@errors/invalid-response-error.ts +6 -0
  131. package/src/@errors/no-resources-to-export-error.ts +6 -0
  132. package/src/@errors/polling-aborted-error.ts +6 -0
  133. package/src/@errors/project-key-not-available-error.ts +6 -0
  134. package/src/@errors/query-predicate-error.ts +10 -0
  135. package/src/@errors/unexpected-column-error.ts +6 -0
  136. package/src/@errors/unexpected-operation-state-error.ts +8 -0
  137. package/src/@errors/unexpected-resource-type-error.ts +6 -0
  138. package/src/@hooks/index.ts +8 -0
  139. package/src/@hooks/use-fetch-export-operations.ts +34 -0
  140. package/src/@hooks/use-fetch-file-import-job.spec.ts +131 -0
  141. package/src/@hooks/use-fetch-file-import-job.ts +38 -0
  142. package/src/@hooks/use-fetch-import-container-details.ts +31 -0
  143. package/src/@hooks/use-fetch-import-operations.ts +42 -0
  144. package/src/@hooks/use-fetch-import-summaries.ts +47 -0
  145. package/src/@hooks/use-fetch.spec.ts +68 -0
  146. package/src/@hooks/use-fetch.ts +76 -0
  147. package/src/@hooks/use-file-import-job-upload.spec.ts +273 -0
  148. package/src/@hooks/use-file-import-job-upload.ts +101 -0
  149. package/src/@hooks/use-file-upload.ts +223 -0
  150. package/src/@hooks/use-import-container-upload.spec.ts +297 -0
  151. package/src/@hooks/use-import-container-upload.ts +130 -0
  152. package/src/@types/api.ts +14 -0
  153. package/src/@types/basic-error-data-type.ts +5 -0
  154. package/src/@types/export-operation.ts +147 -0
  155. package/src/@types/file-import-job.ts +165 -0
  156. package/src/@types/file-upload-result.ts +23 -0
  157. package/src/@types/file-upload.ts +81 -0
  158. package/src/@types/import-container.ts +104 -0
  159. package/src/@types/import-operation.ts +31 -0
  160. package/src/@types/import-states.ts +9 -0
  161. package/src/@types/import-summary.ts +22 -0
  162. package/src/@types/index.ts +11 -0
  163. package/src/@types/shared.ts +52 -0
  164. package/src/@utils/error-mapping.spec.ts +126 -0
  165. package/src/@utils/error-mapping.ts +40 -0
  166. package/src/@utils/file-import-job-helpers.spec.ts +147 -0
  167. package/src/@utils/file-import-job-helpers.ts +47 -0
  168. package/src/@utils/file-upload.spec.ts +151 -0
  169. package/src/@utils/file-upload.ts +189 -0
  170. package/src/@utils/form.ts +20 -0
  171. package/src/@utils/format.spec.ts +62 -0
  172. package/src/@utils/format.ts +53 -0
  173. package/src/@utils/import-container.spec.ts +26 -0
  174. package/src/@utils/import-container.ts +34 -0
  175. package/src/@utils/index.ts +8 -0
  176. package/src/@utils/poll-job-until-validated.ts +76 -0
  177. package/src/@utils/url.spec.ts +75 -0
  178. package/src/@utils/url.ts +18 -0
  179. package/src/index.ts +27 -0
  180. package/tsconfig.json +9 -0
@@ -0,0 +1,194 @@
1
+ import type { ResourceTypeId } from '@commercetools/importapi-sdk'
2
+ import { plural } from 'pluralize'
3
+ import { formatQueryString, toImportApiResourceType } from '../@utils'
4
+ import type {
5
+ ImportContainerQueryParams,
6
+ ExportOperationQueryParams,
7
+ } from '../@types'
8
+
9
+ export function getImportContainersURL({
10
+ projectKey,
11
+ queryParams,
12
+ }: {
13
+ projectKey: string
14
+ queryParams: ImportContainerQueryParams
15
+ }): string {
16
+ const queryString = formatQueryString(queryParams)
17
+ return `/${projectKey}/import-containers${queryString}`
18
+ }
19
+
20
+ export function getImportOperationsURL({
21
+ projectKey,
22
+ importContainerKey,
23
+ queryParams,
24
+ }: {
25
+ projectKey: string
26
+ importContainerKey: string
27
+ queryParams?: ImportContainerQueryParams
28
+ }): string {
29
+ const queryString = formatQueryString(queryParams)
30
+ return `/${projectKey}/import-containers/${importContainerKey}/import-operations${queryString}&debug=true`
31
+ }
32
+
33
+ export function getImportContainerByKeyURL({
34
+ projectKey,
35
+ importContainerKey,
36
+ }: {
37
+ projectKey: string
38
+ importContainerKey: string
39
+ }): string {
40
+ return `/${projectKey}/import-containers/${importContainerKey}`
41
+ }
42
+
43
+ export function getCreateImportContainerURL({
44
+ projectKey,
45
+ }: {
46
+ projectKey: string
47
+ }): string {
48
+ return `/${projectKey}/import-containers`
49
+ }
50
+
51
+ export function getImportContainerTasksURL({
52
+ projectKey,
53
+ importContainerKey,
54
+ }: {
55
+ projectKey: string
56
+ importContainerKey: string
57
+ }): string {
58
+ return `/${projectKey}/import-containers/${importContainerKey}/tasks`
59
+ }
60
+
61
+ export function getDeleteImportContainerURL({
62
+ projectKey,
63
+ importContainerKey,
64
+ }: {
65
+ projectKey: string
66
+ importContainerKey: string
67
+ }): string {
68
+ return `/${projectKey}/import-containers/${importContainerKey}`
69
+ }
70
+
71
+ export function getImportSummaryURL({
72
+ projectKey,
73
+ importContainerKey,
74
+ }: {
75
+ projectKey: string
76
+ importContainerKey: string
77
+ }): string {
78
+ return `/${projectKey}/import-containers/${importContainerKey}/import-summaries`
79
+ }
80
+
81
+ export function getFileUploadURL({
82
+ projectKey,
83
+ resourceType,
84
+ importContainerKey,
85
+ }: {
86
+ projectKey: string
87
+ resourceType: ResourceTypeId
88
+ importContainerKey: string
89
+ }): string {
90
+ return `/${projectKey}/${plural(
91
+ resourceType
92
+ )}/import-containers/${importContainerKey}/file-upload`
93
+ }
94
+
95
+ export function getProccessFileURL({
96
+ projectKey,
97
+ resourceType,
98
+ importContainerKey,
99
+ }: {
100
+ projectKey: string
101
+ resourceType: ResourceTypeId
102
+ importContainerKey: string
103
+ }): string {
104
+ return `/${projectKey}/${plural(
105
+ resourceType
106
+ )}/import-containers/${importContainerKey}/process-file`
107
+ }
108
+
109
+ export function getExportOperationsURL({
110
+ projectKey,
111
+ queryParams,
112
+ }: {
113
+ projectKey: string
114
+ queryParams: ExportOperationQueryParams
115
+ }): string {
116
+ const queryString = formatQueryString(queryParams)
117
+ return `/${projectKey}/export-operations${queryString}`
118
+ }
119
+
120
+ export function getFileImportJobsURL({
121
+ projectKey,
122
+ resourceType,
123
+ importContainerKey,
124
+ }: {
125
+ projectKey: string
126
+ resourceType: string
127
+ importContainerKey: string
128
+ }): string {
129
+ return `/${projectKey}/${plural(
130
+ toImportApiResourceType(resourceType)
131
+ )}/import-containers/${importContainerKey}/file-import-jobs`
132
+ }
133
+
134
+ export function getFileImportJobByIdURL({
135
+ projectKey,
136
+ importContainerKey,
137
+ jobId,
138
+ }: {
139
+ projectKey: string
140
+ importContainerKey: string
141
+ jobId: string
142
+ }): string {
143
+ return `/${projectKey}/import-containers/${importContainerKey}/file-import-jobs/${jobId}`
144
+ }
145
+
146
+ export function getFileImportJobRecordsURL({
147
+ projectKey,
148
+ importContainerKey,
149
+ jobId,
150
+ }: {
151
+ projectKey: string
152
+ importContainerKey: string
153
+ jobId: string
154
+ }): string {
155
+ return `/${projectKey}/import-containers/${importContainerKey}/file-import-jobs/${jobId}/records`
156
+ }
157
+
158
+ export function getFileImportJobProcessURL({
159
+ projectKey,
160
+ resourceType,
161
+ importContainerKey,
162
+ jobId,
163
+ }: {
164
+ projectKey: string
165
+ resourceType: string
166
+ importContainerKey: string
167
+ jobId: string
168
+ }): string {
169
+ return `/${projectKey}/${plural(
170
+ toImportApiResourceType(resourceType)
171
+ )}/import-containers/${importContainerKey}/file-import-jobs/${jobId}/process`
172
+ }
173
+
174
+ export function getFileImportJobDeleteURL({
175
+ projectKey,
176
+ importContainerKey,
177
+ jobId,
178
+ }: {
179
+ projectKey: string
180
+ importContainerKey: string
181
+ jobId: string
182
+ }): string {
183
+ return `/${projectKey}/import-containers/${importContainerKey}/file-import-jobs/${jobId}`
184
+ }
185
+
186
+ export function getFileImportJobsListURL({
187
+ projectKey,
188
+ importContainerKey,
189
+ }: {
190
+ projectKey: string
191
+ importContainerKey: string
192
+ }): string {
193
+ return `/${projectKey}/import-containers/${importContainerKey}/file-import-jobs`
194
+ }
@@ -0,0 +1,33 @@
1
+ import { EnabledDropArea } from './enabled-drop-area'
2
+ import { FileDroppedArea } from './file-dropped-area'
3
+
4
+ interface ActiveDragDropAreaProps {
5
+ isFileDropped: boolean
6
+ fileName?: string
7
+ chooseFileLabel: string
8
+ dragAndDropText: string
9
+ orText: string
10
+ browseFileText: string
11
+ }
12
+
13
+ export const ActiveDragDropArea = ({
14
+ isFileDropped,
15
+ fileName,
16
+ chooseFileLabel,
17
+ dragAndDropText,
18
+ orText,
19
+ browseFileText,
20
+ }: ActiveDragDropAreaProps) => {
21
+ if (isFileDropped) {
22
+ return (
23
+ <FileDroppedArea fileName={fileName} chooseFileLabel={chooseFileLabel} />
24
+ )
25
+ }
26
+ return (
27
+ <EnabledDropArea
28
+ dragAndDropText={dragAndDropText}
29
+ orText={orText}
30
+ browseFileText={browseFileText}
31
+ />
32
+ )
33
+ }
@@ -0,0 +1,17 @@
1
+ import { Spacings, Text } from '@commercetools-frontend/ui-kit'
2
+ import { LockIcon } from '../icons/lock-icon'
3
+
4
+ type DisabledDropAreaProps = {
5
+ disabledMessage?: string
6
+ }
7
+
8
+ export const DisabledDropArea = ({
9
+ disabledMessage,
10
+ }: DisabledDropAreaProps) => {
11
+ return (
12
+ <Spacings.Stack alignItems="center">
13
+ <LockIcon />
14
+ {disabledMessage && <Text.Body>{disabledMessage}</Text.Body>}
15
+ </Spacings.Stack>
16
+ )
17
+ }
@@ -0,0 +1,38 @@
1
+ import type { DropzoneRootProps } from 'react-dropzone'
2
+ import { css } from '@emotion/react'
3
+ import styled from '@emotion/styled'
4
+ import { dropAreaStyles } from './styles'
5
+ import type { DropAreaState } from '../../@types'
6
+
7
+ interface DropWrapperProps extends DropzoneRootProps {
8
+ dropAreaState: DropAreaState
9
+ }
10
+
11
+ export const DropAreaWrapper = styled.div<DropWrapperProps>`
12
+ ${dropAreaStyles.base}
13
+ ${(props) => {
14
+ if (props.dropAreaState === 'disabled') {
15
+ return dropAreaStyles.disabled
16
+ }
17
+ if (props.dropAreaState === 'ready-for-drop') {
18
+ return dropAreaStyles.readyForDrop
19
+ }
20
+ if (props.dropAreaState === 'active-drag') {
21
+ return dropAreaStyles.activeDrag
22
+ }
23
+ if (props.dropAreaState === 'invalid') {
24
+ return dropAreaStyles.invalid
25
+ }
26
+ if (props.dropAreaState === 'is-parsing') {
27
+ return dropAreaStyles.parsing
28
+ }
29
+ if (props.dropAreaState === 'file-dropped') {
30
+ return dropAreaStyles.fileDropped
31
+ }
32
+ return getDefaultDropWrapperStyles(props.dropAreaState)
33
+ }}
34
+ `
35
+
36
+ function getDefaultDropWrapperStyles(_dropAreaState: DropAreaState) {
37
+ return css``
38
+ }
@@ -0,0 +1,27 @@
1
+ import { Link, Spacings, Text } from '@commercetools-frontend/ui-kit'
2
+ import { FileIcon } from '../icons/file-icon'
3
+
4
+ type EnabledDropAreaProps = {
5
+ dragAndDropText: string
6
+ orText: string
7
+ browseFileText: string
8
+ }
9
+
10
+ export const EnabledDropArea = ({
11
+ dragAndDropText,
12
+ orText,
13
+ browseFileText,
14
+ }: EnabledDropAreaProps) => {
15
+ return (
16
+ <Spacings.Inline alignItems="center" justifyContent="center" scale="s">
17
+ <FileIcon />
18
+ <Spacings.Inline alignItems="center" scale="s">
19
+ <Text.Subheadline as="h4">{dragAndDropText}</Text.Subheadline>
20
+ <Text.Body>{orText}</Text.Body>
21
+ <Link tone="secondary" to="" onClick={(ev) => ev.preventDefault()}>
22
+ {browseFileText}
23
+ </Link>
24
+ </Spacings.Inline>
25
+ </Spacings.Inline>
26
+ )
27
+ }
@@ -0,0 +1,74 @@
1
+ import React from 'react'
2
+ import type { Accept, DropEvent, FileRejection } from 'react-dropzone'
3
+ import { useDropzone } from 'react-dropzone'
4
+ import { Constraints } from '@commercetools-frontend/ui-kit'
5
+ import { DropAreaWrapper } from './drop-area-wrapper'
6
+ import type { DropAreaState } from '../../@types'
7
+
8
+ type OnDrop = <T extends File>(
9
+ acceptedFiles: T[],
10
+ fileRejections: FileRejection[],
11
+ event: DropEvent
12
+ ) => void
13
+
14
+ type FileDropAreaProps = {
15
+ onDrop: OnDrop
16
+ disabled?: boolean
17
+ accept: Accept
18
+ getDropAreaState: (isDragActive: boolean) => DropAreaState
19
+ children: (dropAreaState: DropAreaState) => React.ReactNode
20
+ onDropRejected?: (
21
+ errorType: 'too-many-files' | 'invalid-type' | 'generic'
22
+ ) => void
23
+ }
24
+
25
+ export const FileDropArea = ({
26
+ onDrop,
27
+ disabled,
28
+ accept,
29
+ getDropAreaState,
30
+ children,
31
+ onDropRejected: handleDropRejected,
32
+ }: FileDropAreaProps) => {
33
+ const { getRootProps, getInputProps, isDragActive } = useDropzone({
34
+ onDrop,
35
+ multiple: false,
36
+ disabled,
37
+ accept,
38
+ onDropRejected: ([rejectedFile]: FileRejection[]) => {
39
+ if (!handleDropRejected) return
40
+
41
+ if (
42
+ rejectedFile?.errors.some(
43
+ (error: { code: string }) => error.code === 'too-many-files'
44
+ )
45
+ ) {
46
+ handleDropRejected('too-many-files')
47
+ return
48
+ }
49
+
50
+ if (
51
+ rejectedFile?.errors.some(
52
+ (error: { code: string }) => error.code === 'file-invalid-type'
53
+ )
54
+ ) {
55
+ handleDropRejected('invalid-type')
56
+ } else {
57
+ handleDropRejected('generic')
58
+ }
59
+ },
60
+ })
61
+
62
+ const dropAreaState = getDropAreaState(isDragActive)
63
+
64
+ return (
65
+ <DropAreaWrapper
66
+ role="presentation"
67
+ {...getRootProps()}
68
+ dropAreaState={dropAreaState}
69
+ >
70
+ <input data-testid="file-input" {...getInputProps()} />
71
+ <Constraints.Horizontal>{children(dropAreaState)}</Constraints.Horizontal>
72
+ </DropAreaWrapper>
73
+ )
74
+ }
@@ -0,0 +1,29 @@
1
+ import {
2
+ Constraints,
3
+ PaperclipIcon,
4
+ SecondaryButton,
5
+ Spacings,
6
+ Text,
7
+ } from '@commercetools-frontend/ui-kit'
8
+
9
+ type FileDroppedAreaProps = {
10
+ fileName?: string
11
+ chooseFileLabel: string
12
+ }
13
+
14
+ export const FileDroppedArea = ({
15
+ fileName,
16
+ chooseFileLabel,
17
+ }: FileDroppedAreaProps) => {
18
+ return (
19
+ <Spacings.Stack alignItems="center" scale="s">
20
+ <Spacings.Inline alignItems="flex-start" scale="xs">
21
+ <PaperclipIcon color="neutral60" />
22
+ <Constraints.Horizontal max={13}>
23
+ <Text.Body>{fileName}</Text.Body>
24
+ </Constraints.Horizontal>
25
+ </Spacings.Inline>
26
+ <SecondaryButton tone="secondary" size="medium" label={chooseFileLabel} />
27
+ </Spacings.Stack>
28
+ )
29
+ }
@@ -0,0 +1,7 @@
1
+ export * from './active-drag-drop-area'
2
+ export * from './disabled-drop-area'
3
+ export * from './drop-area-wrapper'
4
+ export * from './enabled-drop-area'
5
+ export * from './file-drop-area'
6
+ export * from './file-dropped-area'
7
+ export * from './styles'
@@ -0,0 +1,67 @@
1
+ import { customProperties } from '@commercetools-frontend/ui-kit'
2
+ import { css } from '@emotion/react'
3
+
4
+ type DropAreaState = 'default' | 'error' | 'active'
5
+
6
+ const getBorderColor = (state: DropAreaState) => {
7
+ const borderColors = {
8
+ default: '#909dbc',
9
+ error: '#e60050',
10
+ active: customProperties.colorPrimary,
11
+ }
12
+
13
+ return borderColors[state] || borderColors.default
14
+ }
15
+
16
+ const getDashedBorder = (state: DropAreaState = 'default') => {
17
+ const color = getBorderColor(state)
18
+ const svgContent = `
19
+ <svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
20
+ <rect width="100%" height="100%" fill="none" stroke="${color}" stroke-width="2px" stroke-dasharray="6,6" stroke-dashoffset="0" stroke-linecap="square"/>
21
+ </svg>
22
+ `
23
+ return `data:image/svg+xml,${encodeURIComponent(svgContent)}`
24
+ }
25
+
26
+ const base = css`
27
+ border-radius: ${customProperties.borderRadius6};
28
+ min-height: 136px;
29
+ display: flex;
30
+ justify-content: center;
31
+ align-items: center;
32
+ `
33
+ const disabled = css``
34
+ const readyForDrop = css`
35
+ background-image: url('${getDashedBorder()}');
36
+ background-color: ${customProperties.colorSurface};
37
+ `
38
+ const activeDrag = css`
39
+ background-image: url('${getDashedBorder('active')}');
40
+ background-color: ${customProperties.colorPrimary95};
41
+ padding: ${customProperties.spacing50} 100px;
42
+ `
43
+ const fileDropped = css`
44
+ background-image: url('${getDashedBorder()}');
45
+ background-color: ${customProperties.colorSurface};
46
+ padding: ${customProperties.spacing50} 100px;
47
+ `
48
+ const invalid = css`
49
+ background-image: url('${getDashedBorder('default')}');
50
+ background-color: ${customProperties.colorSurface};
51
+ padding: ${customProperties.spacing70} 100px;
52
+ `
53
+ const parsing = css`
54
+ background-image: url('${getDashedBorder()}');
55
+ background-color: ${customProperties.colorSurface};
56
+ padding: ${customProperties.spacing50} 100px;
57
+ `
58
+
59
+ export const dropAreaStyles = {
60
+ base,
61
+ readyForDrop,
62
+ fileDropped,
63
+ disabled,
64
+ activeDrag,
65
+ invalid,
66
+ parsing,
67
+ }
@@ -0,0 +1,30 @@
1
+ import React from 'react'
2
+
3
+ export const FileIcon: React.FC<React.SVGProps<SVGSVGElement>> = (props) => (
4
+ <svg
5
+ width="32"
6
+ height="32"
7
+ viewBox="0 0 32 32"
8
+ fill="none"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ {...props}
11
+ >
12
+ <mask
13
+ id="mask0_17_6643"
14
+ style={{ maskType: 'alpha' }}
15
+ maskUnits="userSpaceOnUse"
16
+ x="0"
17
+ y="0"
18
+ width="32"
19
+ height="32"
20
+ >
21
+ <rect width="32" height="32" fill="#D9D9D9" />
22
+ </mask>
23
+ <g mask="url(#mask0_17_6643)">
24
+ <path
25
+ d="M14.6667 25.3333H17.3333V19.7667L19.4667 21.9L21.3333 20L16 14.6667L10.6667 20L12.5667 21.8667L14.6667 19.7667V25.3333ZM8 29.3333C7.26667 29.3333 6.63889 29.0722 6.11667 28.55C5.59444 28.0278 5.33333 27.4 5.33333 26.6667V5.33332C5.33333 4.59999 5.59444 3.97221 6.11667 3.44999C6.63889 2.92777 7.26667 2.66666 8 2.66666H18.6667L26.6667 10.6667V26.6667C26.6667 27.4 26.4056 28.0278 25.8833 28.55C25.3611 29.0722 24.7333 29.3333 24 29.3333H8ZM17.3333 12H24L17.3333 5.33332V12Z"
26
+ fill="#B1ACFF"
27
+ />
28
+ </g>
29
+ </svg>
30
+ )
@@ -0,0 +1,2 @@
1
+ export * from './file-icon'
2
+ export * from './lock-icon'
@@ -0,0 +1,34 @@
1
+ import React from 'react'
2
+
3
+ export const LockIcon: React.FC<React.SVGProps<SVGSVGElement>> = (props) => (
4
+ <svg
5
+ width="87px"
6
+ height="118px"
7
+ viewBox="0 0 87 118"
8
+ version="1.1"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ xmlnsXlink="http://www.w3.org/1999/xlink"
11
+ {...props}
12
+ >
13
+ <title>Shape</title>
14
+ <g
15
+ id="Final-ImportBoard"
16
+ stroke="none"
17
+ strokeWidth="1"
18
+ fill="none"
19
+ fillRule="evenodd"
20
+ >
21
+ <g
22
+ id="2-Upload-files---Locked"
23
+ transform="translate(-697.000000, -285.000000)"
24
+ fill="#999999"
25
+ fillRule="nonzero"
26
+ >
27
+ <path
28
+ d="M781.167075,334.924997 L774.342717,334.924997 L774.342717,319.039771 C774.342717,300.267972 759.042508,285 740.22093,285 C721.403902,285 706.099143,300.267972 706.099143,319.039771 L706.099143,334.924997 L699.274786,334.924997 C698.019104,334.924997 697,335.941652 697,337.194315 L697,389.184392 C697,389.974114 697.414011,390.709373 698.087348,391.122389 C710.839797,398.892534 725.407525,403 740.22093,403 C755.034335,403 769.602064,398.892534 782.359062,391.122389 C783.027849,390.709373 783.44186,389.974114 783.44186,389.184392 L783.44186,337.194315 C783.44186,335.941652 782.418207,334.924997 781.167075,334.924997 Z M745.590495,368.913821 L745.590495,384.782392 C745.590495,386.353821 744.382343,387.639535 742.905713,387.639535 L737.536148,387.639535 C736.054148,387.639535 734.851365,386.353821 734.851365,384.782392 L734.851365,368.913821 C731.651104,366.930963 729.4818,363.296678 729.4818,359.068106 C729.4818,352.759535 734.29293,347.639535 740.22093,347.639535 C746.14893,347.639535 750.960061,352.759535 750.960061,359.068106 C750.960061,363.285249 748.790756,366.930963 745.590495,368.913821 Z M760.116279,334.395349 L718.953488,334.395349 L718.953488,318.787791 C718.953488,307.724262 728.187674,298.72093 739.534884,298.72093 C750.877519,298.72093 760.116279,307.724262 760.116279,318.787791 L760.116279,334.395349 Z"
29
+ id="Shape"
30
+ ></path>
31
+ </g>
32
+ </g>
33
+ </svg>
34
+ )
@@ -0,0 +1,6 @@
1
+ export * from './file-drop-area'
2
+ export * from './icons'
3
+ export * from './info-box'
4
+ export * from './upload-separator'
5
+ export * from './upload-settings'
6
+ export * from './uploading-modal'
@@ -0,0 +1 @@
1
+ export * from './info-box'
@@ -0,0 +1,23 @@
1
+ import {
2
+ ContentNotification,
3
+ Spacings,
4
+ Text,
5
+ } from '@commercetools-frontend/ui-kit'
6
+
7
+ type InfoBoxProps = {
8
+ title: string
9
+ description: React.ReactNode
10
+ }
11
+
12
+ export const InfoBox = ({ title, description }: InfoBoxProps) => {
13
+ return (
14
+ <ContentNotification type="info">
15
+ <Spacings.Inset scale="xs">
16
+ <Spacings.Stack scale="xs">
17
+ <Text.Subheadline as="h4">{title}</Text.Subheadline>
18
+ <Text.Body>{description}</Text.Body>
19
+ </Spacings.Stack>
20
+ </Spacings.Inset>
21
+ </ContentNotification>
22
+ )
23
+ }
@@ -0,0 +1 @@
1
+ export * from './upload-separator'
@@ -0,0 +1,61 @@
1
+ import { SelectField, Spacings, Text } from '@commercetools-frontend/ui-kit'
2
+ import { css } from '@emotion/react'
3
+ import { DELIMITERS } from '../../@constants'
4
+ import type { DecimalSeparator } from '../../@types'
5
+
6
+ type UploadSeparatorProps = {
7
+ value?: DecimalSeparator
8
+ onChange: (decimalSeparator: DecimalSeparator) => void
9
+ separatorTitle: string
10
+ decimalsSeparatorDescription: string
11
+ decimalSeparatorPointLabel: string
12
+ decimalSeparatorCommaLabel: string
13
+ decimalsLabel: string
14
+ }
15
+
16
+ export const UploadSeparator = ({
17
+ value,
18
+ onChange,
19
+ separatorTitle,
20
+ decimalsSeparatorDescription,
21
+ decimalSeparatorPointLabel,
22
+ decimalSeparatorCommaLabel,
23
+ decimalsLabel,
24
+ }: UploadSeparatorProps) => {
25
+ const decimalSeparatorOptions = [
26
+ {
27
+ label: decimalSeparatorPointLabel,
28
+ value: DELIMITERS.POINT,
29
+ },
30
+ {
31
+ label: decimalSeparatorCommaLabel,
32
+ value: DELIMITERS.COMMA,
33
+ },
34
+ ]
35
+
36
+ return (
37
+ <Spacings.Stack scale="m">
38
+ <div>
39
+ <Text.Subheadline as="h4">{separatorTitle}</Text.Subheadline>
40
+ <Text.Caption tone="tertiary">
41
+ {decimalsSeparatorDescription}
42
+ </Text.Caption>
43
+ </div>
44
+ <div
45
+ css={css`
46
+ width: calc(50% - 16px);
47
+ `}
48
+ >
49
+ <SelectField
50
+ title={decimalsLabel}
51
+ isSearchable={false}
52
+ options={decimalSeparatorOptions}
53
+ value={value}
54
+ onChange={(e) => {
55
+ onChange(e.target.value as DecimalSeparator)
56
+ }}
57
+ />
58
+ </div>
59
+ </Spacings.Stack>
60
+ )
61
+ }
@@ -0,0 +1 @@
1
+ export * from './upload-settings'