Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 0985bf0

Browse files
committed
feat(sharedata): add validation for step 3
1 parent 0786d88 commit 0985bf0

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/ui/page/share/dataset/shareDataset.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const ShareDataset: FC = () => {
2121
hasStoredFiles: store.hasStoredFiles
2222
}))
2323

24+
const { hasTextFieldValue } = useAppStore(state => ({
25+
hasTextFieldValue: state.shareData.hasTextFieldValue
26+
}))
27+
2428
const storageServiceSelection: StepElement = {
2529
id: 'step1',
2630
content: <ServiceStorageSelection />,
@@ -31,7 +35,11 @@ export const ShareDataset: FC = () => {
3135
content: <DataSelection />,
3236
validate: () => hasStoredFiles()()
3337
}
34-
const metadataFilling: StepElement = { id: 'step3', content: <MetadataFilling /> }
38+
const metadataFilling: StepElement = {
39+
id: 'step3',
40+
content: <MetadataFilling />,
41+
validate: hasTextFieldValue('input-field-1')
42+
}
3543
const summary: StepElement = { id: 'step4', content: <Summary /> }
3644
const completeTransaction: StepElement = { id: 'step5', content: <CompleteTransaction /> }
3745

src/ui/store/slice/shareData/shareData.slice.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { IOEither } from 'fp-ts/IOEither'
88
import type { IOOption } from 'fp-ts/IOOption'
99
import type { Eq } from 'fp-ts/lib/Eq'
1010
import type { Show } from 'fp-ts/lib/Show'
11-
import type IO from 'fp-ts/IO'
11+
import * as IO from 'fp-ts/IO'
1212
import * as A from 'fp-ts/Array'
1313
import * as IOE from 'fp-ts/IOEither'
1414
import * as IOO from 'fp-ts/IOOption'
@@ -137,6 +137,7 @@ export type ShareDataSlice = {
137137
id: string,
138138
value: FormItemValue
139139
) => IOEither<ResourceNotFoundError | PayloadIsEmptyError | FormItemWrongTypeError, void>
140+
hasTextFieldValue: (id: FormItemId) => IO.IO<boolean>
140141
}
141142
}
142143
const eqFormItemId: Eq<FormItemId> = S.Eq
@@ -286,6 +287,8 @@ export const isDateStringRange = (formItemValue: FormItemValue): formItemValue i
286287
'from' in formItemValue &&
287288
'to' in formItemValue
288289

290+
export const isTextField = (item: FormItem): item is TextField => item.type === 'text'
291+
289292
const updateFormItem =
290293
(updatedValue: FormItemValue) =>
291294
(formItem: FormItem): E.Either<FormItemWrongTypeError, FormItem> => {
@@ -433,6 +436,23 @@ export const createShareDataSlice: ShareDataStateCreator =
433436
IOO.fromIO(() => get().shareData.form),
434437
IOO.chainOptionK(flow(A.findFirst(formItem => eqFormItem.equals(formItem, { id }))))
435438
),
439+
hasTextFieldValue: (id: FormItemId) =>
440+
pipe(
441+
IOO.fromIO(() => get().shareData.form),
442+
IOO.chainOptionK(flow(A.findFirst(formItem => eqFormItem.equals(formItem, { id })))),
443+
IOO.flatMap(formItem =>
444+
IOO.fromOption(
445+
pipe(
446+
formItem,
447+
O.fromPredicate(isTextField),
448+
O.flatMap(({ value }) => value),
449+
O.map(S.trim),
450+
O.map(isNotEmpty)
451+
)
452+
)
453+
),
454+
IOO.getOrElse(constant(IO.of(false)))
455+
),
436456
setFormItemValue: (id: string, value: FormItemValue) =>
437457
pipe(
438458
id,

0 commit comments

Comments
 (0)