/
PackageCreateDialog.tsx
55 lines (48 loc) · 1.4 KB
/
PackageCreateDialog.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as R from 'ramda'
import * as React from 'react'
import * as AWS from 'utils/AWS'
import AsyncResult from 'utils/AsyncResult'
import * as BucketPreferences from 'utils/BucketPreferences'
import * as Data from 'utils/Data'
import type * as workflows from 'utils/workflows'
import * as PD from './PackageDialog'
import * as requests from './requests'
interface UsePackageCreateDialogProps {
bucket: string
onExited: (result: {
pushed: PD.PackageCreationSuccess | false
}) => boolean | undefined | void
}
export function usePackageCreateDialog({
bucket,
onExited,
}: UsePackageCreateDialogProps) {
const s3 = AWS.S3.use()
const workflowsData = Data.use(requests.workflowsConfig, { s3, bucket })
// XXX: use AsyncResult
const preferences = BucketPreferences.use()
const data = workflowsData.case({
Ok: (workflowsConfig: workflows.WorkflowsConfig) =>
preferences
? AsyncResult.Ok({
workflowsConfig,
sourceBuckets: preferences.ui.sourceBuckets,
})
: AsyncResult.Pending(),
_: R.identity,
})
return PD.usePackageCreationDialog({
bucket,
data,
delayHashing: true,
disableStateDisplay: true,
onExited,
ui: {
successTitle: 'Package created',
successRenderMessage: ({ packageLink }) => (
<>Package {packageLink} successfully created</>
),
title: 'Create package',
},
})
}