amp-workflow-ui 0.1.1 → 0.1.2
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/README.md +79 -14
- package/dist/index.js +1236 -513
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1238 -515
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# amp-workflow-ui
|
|
2
2
|
|
|
3
|
-
Reusable Approval Workflow UI components for Ampersand portals.
|
|
3
|
+
Reusable Approval Workflow UI components (DialogOpener, ApprovalWorkflow) for Ampersand portals. Components are decoupled from app internals and accept an injected API client and optional URL builder.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install
|
|
8
|
+
npm install amp-workflow-ui
|
|
9
9
|
# or
|
|
10
|
-
yarn add
|
|
10
|
+
yarn add amp-workflow-ui
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Peer dependencies required in host:
|
|
14
14
|
|
|
15
15
|
- react, react-dom (18.x)
|
|
16
|
-
- @mui/material, @mui/system
|
|
16
|
+
- @mui/material, @mui/system, @mui/icons-material
|
|
17
17
|
- @emotion/react, @emotion/styled
|
|
18
|
+
- react-hot-toast
|
|
18
19
|
|
|
19
20
|
## Usage
|
|
20
21
|
|
|
22
|
+
### 1) Basic React usage
|
|
23
|
+
|
|
21
24
|
```tsx
|
|
22
|
-
import { DialogOpener } from '
|
|
25
|
+
import { DialogOpener } from 'amp-workflow-ui'
|
|
23
26
|
import axios from 'axios'
|
|
24
27
|
|
|
25
28
|
const api = {
|
|
26
|
-
get: (p: any) => axios.
|
|
27
|
-
post: (p: any) => axios.
|
|
29
|
+
get: (p: any) => axios({ method: 'GET', baseURL: 'https://api.example.com', url: p.url }),
|
|
30
|
+
post: (p: any) => axios({ method: 'POST', baseURL: 'https://api.example.com', url: p.url, data: p.data })
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
<DialogOpener
|
|
@@ -32,32 +35,94 @@ const api = {
|
|
|
32
35
|
handleClose={() => setOpen(false)}
|
|
33
36
|
userInfoData={userInfo}
|
|
34
37
|
api={api}
|
|
38
|
+
// optional
|
|
39
|
+
urlBuilder={(moduleName, moduleId, ctx, referenceId) => `/${moduleName}/${moduleId}${referenceId ? `?ref=${referenceId}` : ''}`}
|
|
35
40
|
/>
|
|
36
41
|
```
|
|
37
42
|
|
|
38
43
|
Or render inline:
|
|
39
44
|
|
|
40
45
|
```tsx
|
|
41
|
-
import { ApprovalWorkflow } from '
|
|
46
|
+
import { ApprovalWorkflow } from 'amp-workflow-ui'
|
|
42
47
|
|
|
43
48
|
<ApprovalWorkflow userInfo={userInfo} api={api} />
|
|
44
49
|
```
|
|
45
50
|
|
|
46
|
-
|
|
51
|
+
Props overview:
|
|
52
|
+
- DialogOpener
|
|
53
|
+
- required: openDialog, userInfoData, api
|
|
54
|
+
- optional: handleClose, selectedWorkflowsList, urlBuilder, loadingComponent
|
|
55
|
+
- ApprovalWorkflow
|
|
56
|
+
- required: userInfo, api
|
|
57
|
+
- optional: selectedWorkflowsList, urlBuilder, loadingComponent
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
- `loadingComponent`: custom loader
|
|
59
|
+
### 2) Next.js usage (recommended)
|
|
50
60
|
|
|
51
|
-
|
|
61
|
+
Next.js may SSR your imports by default. To ensure client-only execution and avoid Node ESM resolver issues, dynamically import the package in a client component:
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
// app or pages client component
|
|
65
|
+
import React from 'react'
|
|
66
|
+
import dynamic from 'next/dynamic'
|
|
67
|
+
|
|
68
|
+
export const WorkflowDialog = dynamic(
|
|
69
|
+
async () => {
|
|
70
|
+
// Prefer the package root; if your environment errors on ESM resolution,
|
|
71
|
+
// fall back to the CJS build at /dist/index.cjs.js.
|
|
72
|
+
try {
|
|
73
|
+
const mod = await import('amp-workflow-ui')
|
|
74
|
+
return mod.DialogOpener
|
|
75
|
+
} catch {
|
|
76
|
+
const mod = await import('amp-workflow-ui/dist/index.cjs.js')
|
|
77
|
+
return mod.DialogOpener
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{ ssr: false, loading: () => <div>Loading Approval Management...</div> }
|
|
81
|
+
)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
If you still see “Directory import '@mui/material/Button' is not supported” during SSR, force the CJS build:
|
|
85
|
+
```tsx
|
|
86
|
+
const WorkflowDialog = dynamic(() => import('amp-workflow-ui/dist/index.cjs.js').then(m => m.DialogOpener), { ssr: false })
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Build (package maintainers)
|
|
52
90
|
|
|
53
91
|
```bash
|
|
54
92
|
npm run build
|
|
55
93
|
```
|
|
56
94
|
|
|
57
|
-
## Publish
|
|
95
|
+
## Publish (package maintainers)
|
|
58
96
|
|
|
59
97
|
```bash
|
|
98
|
+
# 1) Ensure you are logged in and have publish rights
|
|
99
|
+
npm whoami || npm login
|
|
100
|
+
|
|
101
|
+
# 2) Bump version (semver)
|
|
102
|
+
npm version patch # or minor | major
|
|
103
|
+
|
|
104
|
+
# 3) Build
|
|
105
|
+
npm run build
|
|
106
|
+
|
|
107
|
+
# 4) Publish (public)
|
|
60
108
|
npm publish --access public
|
|
61
109
|
```
|
|
62
110
|
|
|
111
|
+
Notes:
|
|
112
|
+
- Do not publish pre-releases unless explicitly needed; otherwise npm requires --tag.
|
|
113
|
+
- If your org enforces 2FA for publish, complete the OTP step in your terminal.
|
|
114
|
+
- Keep peerDependencies in sync to avoid duplicate React/MUI bundles in hosts.
|
|
115
|
+
|
|
116
|
+
## Troubleshooting
|
|
117
|
+
|
|
118
|
+
- Error: Element type is invalid … got: object
|
|
119
|
+
- Ensure you are importing the React component (named export) and not the module object. When using dynamic(), return the component (e.g., m.DialogOpener).
|
|
120
|
+
|
|
121
|
+
- Error: Directory import '@mui/material/Button' is not supported resolving ES modules
|
|
122
|
+
- This comes from Node’s ESM resolver during SSR. Use dynamic import with ssr: false or import the CJS build: `amp-workflow-ui/dist/index.cjs.js`.
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
|
127
|
+
|
|
63
128
|
|