@ouroboros/mouth-mui 2.1.1 → 2.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 +80 -10
- package/lib/components/pages/Locales.d.ts +2 -2
- package/lib/components/pages/Locales.js +11 -5
- package/lib/components/pages/Templates/Create.d.ts +2 -2
- package/lib/components/pages/Templates/Create.js +1 -1
- package/lib/components/pages/Templates/Template/Content/Create/index.d.ts +1 -1
- package/lib/components/pages/Templates/Template/Content/Create/index.js +11 -2
- package/lib/components/pages/Templates/Template/Content/Preview/index.d.ts +2 -2
- package/lib/components/pages/Templates/Template/Content/Preview/index.js +9 -2
- package/lib/components/pages/Templates/Template/Content/Update/index.d.ts +1 -1
- package/lib/components/pages/Templates/Template/Content/Update/index.js +8 -2
- package/lib/components/pages/Templates/Template/Content/View/index.d.ts +2 -2
- package/lib/components/pages/Templates/Template/Content/View/index.js +1 -1
- package/lib/components/pages/Templates/Template/index.d.ts +2 -2
- package/lib/components/pages/Templates/Template/index.js +1 -1
- package/lib/components/pages/Templates/index.d.ts +4 -4
- package/lib/components/pages/Templates/index.js +13 -5
- package/package.json +3 -3
- package/releases.md +18 -0
- package/src/components/pages/Locales.tsx +11 -5
- package/src/components/pages/Templates/Create.tsx +2 -2
- package/src/components/pages/Templates/Template/Content/Create/index.tsx +9 -3
- package/src/components/pages/Templates/Template/Content/Preview/index.tsx +10 -4
- package/src/components/pages/Templates/Template/Content/Update/index.tsx +7 -3
- package/src/components/pages/Templates/Template/Content/View/index.tsx +2 -2
- package/src/components/pages/Templates/Template/index.tsx +2 -2
- package/src/components/pages/Templates/index.tsx +15 -7
package/README.md
CHANGED
|
@@ -1,15 +1,85 @@
|
|
|
1
1
|
# @ouroboros/mouth-mui
|
|
2
|
+
[](https://www.npmjs.com/package/@ouroboros/mouth-mui) 
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
Material-UI Components for interacting with the
|
|
5
|
+
[mouth2_oc](https://pypi.org/project/mouth2_oc/) service. It uses
|
|
6
|
+
[@ouroboros/mouth](https://npmjs.com/package/@ouroboros/mouth) to handle the
|
|
7
|
+
actual connections.
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
This code comes without documentation as it's not meant to be used by anyone
|
|
9
|
-
outside of Ouroboros Coding Inc. Please see LICENSE for further information.
|
|
9
|
+
See [Releases](https://github.com/ouroboroscoding/mouth-mui/blob/main/releases.md)
|
|
10
|
+
for changes from release to release.
|
|
10
11
|
|
|
11
12
|
## Installation
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
```console
|
|
14
|
+
foo@bar:~$ npm install @ouroboros/mouth-mui
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Using mouth-mui
|
|
18
|
+
If you're using react with material-ui, this library provides components for
|
|
19
|
+
creating and editing locales and templates.
|
|
20
|
+
|
|
21
|
+
### Components
|
|
22
|
+
- [Locales](#locales)
|
|
23
|
+
- [Templates](#templates)
|
|
24
|
+
|
|
25
|
+
### Locales
|
|
26
|
+
`Locales` is used to setup allowable locales on the system, as well as to make
|
|
27
|
+
it easier to look up what locales can be chosen. It handles all C.R.U.D.
|
|
28
|
+
operations.
|
|
29
|
+
|
|
30
|
+
```jsx
|
|
31
|
+
import { Locales } from '@ouroboros/mouth-mui';
|
|
32
|
+
import React from 'react';
|
|
33
|
+
import { addError, addMessage } from 'your_module';
|
|
34
|
+
function MyLocalesPage(props) {
|
|
35
|
+
return <Locales
|
|
36
|
+
onError={addError}
|
|
37
|
+
onSuccess={(type) => {
|
|
38
|
+
/* type includes [
|
|
39
|
+
'create', 'delete', 'update',
|
|
40
|
+
] */
|
|
41
|
+
addMessage(`${type} successful!`)
|
|
42
|
+
}}
|
|
43
|
+
/>
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
| Prop | Type | Optional | Description |
|
|
48
|
+
| ---- | ---- | -------- | ----------- |
|
|
49
|
+
| onError | <nobr>`error => void`</nobr> | yes | Callback for when an error occurs. `error` is a `responseErrorStruct` from [@ouroboros/body](https://www.npmjs.com/package/@ouroboros/body). |
|
|
50
|
+
| onSuccess | <nobr>`type => void`</nobr> | yes | Callback for when any of the following `type`s happen: 'create', 'delete', and 'update'. |
|
|
51
|
+
|
|
52
|
+
[ [top](#ouroborosmouth-mui) / [components](#components) ]
|
|
53
|
+
|
|
54
|
+
### Templates
|
|
55
|
+
`Templates` is used to setup named templates with individual versions per locale
|
|
56
|
+
and method (content). For example, you could make a template with both email
|
|
57
|
+
content and sms content so that depending on the user's preference you have
|
|
58
|
+
both. Or you could have an email with both English and Spanish content. Or you
|
|
59
|
+
could have all instances and have multiple locales setup for both email and sms.
|
|
60
|
+
The component handles creating and updating for all these variations.
|
|
61
|
+
|
|
62
|
+
```jsx
|
|
63
|
+
import { Templates } from '@ouroboros/mouth-mui';
|
|
64
|
+
import React from 'react';
|
|
65
|
+
import { addError, addMessage } from 'your_module';
|
|
66
|
+
function MyTemplatesPage(props) {
|
|
67
|
+
return <Templates
|
|
68
|
+
onError={addError}
|
|
69
|
+
onSuccess={(type) => {
|
|
70
|
+
/* type includes [
|
|
71
|
+
'template_create', 'template_update',
|
|
72
|
+
'content_create', 'content_update'
|
|
73
|
+
] */
|
|
74
|
+
addMessage(`${type} successful!`)
|
|
75
|
+
}}
|
|
76
|
+
/>
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
| Prop | Type | Optional | Description |
|
|
81
|
+
| ---- | ---- | -------- | ----------- |
|
|
82
|
+
| onError | <nobr>`error => void`</nobr> | yes | Callback for when an error occurs. `error` is a `responseErrorStruct` from [@ouroboros/body](https://www.npmjs.com/package/@ouroboros/body). |
|
|
83
|
+
| onSuccess | <nobr>`type => void`</nobr> | yes | Callback for when any of the following `type`s happen: 'template_create', 'template_update', 'content_create','content_update'. |
|
|
84
|
+
|
|
85
|
+
[ [top](#ouroborosmouth-mui) / [components](#components) ]
|
|
@@ -26,8 +26,8 @@ export type LocalesProps = {
|
|
|
26
26
|
declare function Locales({ onError, onSuccess }: LocalesProps): React.JSX.Element;
|
|
27
27
|
declare namespace Locales {
|
|
28
28
|
var propTypes: {
|
|
29
|
-
onError: PropTypes.
|
|
30
|
-
onSuccess: PropTypes.
|
|
29
|
+
onError: PropTypes.Requireable<(...args: any[]) => any>;
|
|
30
|
+
onSuccess: PropTypes.Requireable<(...args: any[]) => any>;
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
export default Locales;
|
|
@@ -73,7 +73,9 @@ export default function Locales({ onError, onSuccess }) {
|
|
|
73
73
|
// If we were successful
|
|
74
74
|
if (data) {
|
|
75
75
|
// Notify the parent
|
|
76
|
-
onSuccess
|
|
76
|
+
if (onSuccess) {
|
|
77
|
+
onSuccess('create');
|
|
78
|
+
}
|
|
77
79
|
// Close the create form
|
|
78
80
|
createSet(false);
|
|
79
81
|
// Clone the records, add the new one to the start, and set
|
|
@@ -110,7 +112,9 @@ export default function Locales({ onError, onSuccess }) {
|
|
|
110
112
|
// If it was successful
|
|
111
113
|
if (data) {
|
|
112
114
|
// Notify the parent
|
|
113
|
-
onSuccess
|
|
115
|
+
if (onSuccess) {
|
|
116
|
+
onSuccess('delete');
|
|
117
|
+
}
|
|
114
118
|
// Look for the record
|
|
115
119
|
const i = afindi(records, '_id', key);
|
|
116
120
|
// If it exists
|
|
@@ -144,7 +148,9 @@ export default function Locales({ onError, onSuccess }) {
|
|
|
144
148
|
// If we were successful
|
|
145
149
|
if (data) {
|
|
146
150
|
// Notify the parent
|
|
147
|
-
onSuccess
|
|
151
|
+
if (onSuccess) {
|
|
152
|
+
onSuccess('update');
|
|
153
|
+
}
|
|
148
154
|
// Look for the record
|
|
149
155
|
const i = afindi(records, '_id', key);
|
|
150
156
|
// If it exists
|
|
@@ -192,6 +198,6 @@ export default function Locales({ onError, onSuccess }) {
|
|
|
192
198
|
}
|
|
193
199
|
// Valid props
|
|
194
200
|
Locales.propTypes = {
|
|
195
|
-
onError: PropTypes.func
|
|
196
|
-
onSuccess: PropTypes.func
|
|
201
|
+
onError: PropTypes.func,
|
|
202
|
+
onSuccess: PropTypes.func
|
|
197
203
|
};
|
|
@@ -13,7 +13,7 @@ import { templateStruct } from './Template';
|
|
|
13
13
|
export interface CreateProps {
|
|
14
14
|
onCancel?: () => void;
|
|
15
15
|
onCreated: (template: templateStruct) => void;
|
|
16
|
-
onError
|
|
16
|
+
onError?: (error: responseErrorStruct) => void;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Create
|
|
@@ -30,7 +30,7 @@ declare namespace Create {
|
|
|
30
30
|
var propTypes: {
|
|
31
31
|
onCancel: PropTypes.Requireable<(...args: any[]) => any>;
|
|
32
32
|
onCreated: PropTypes.Validator<(...args: any[]) => any>;
|
|
33
|
-
onError: PropTypes.
|
|
33
|
+
onError: PropTypes.Requireable<(...args: any[]) => any>;
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
export default Create;
|
|
@@ -13,7 +13,7 @@ import { responseErrorStruct } from '@ouroboros/body';
|
|
|
13
13
|
export type TemplateContentCreateProps = {
|
|
14
14
|
locales: Record<string, string>;
|
|
15
15
|
onCreated: (content: contentStruct) => void;
|
|
16
|
-
onError
|
|
16
|
+
onError?: (error: responseErrorStruct) => void;
|
|
17
17
|
template: string;
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
@@ -83,10 +83,16 @@ export default function Create({ locales, onCreated, onError, template }) {
|
|
|
83
83
|
if (onError) {
|
|
84
84
|
onError({ code: 0, msg: lLines.join('\n') });
|
|
85
85
|
}
|
|
86
|
+
else {
|
|
87
|
+
throw new Error(JSON.stringify(error));
|
|
88
|
+
}
|
|
86
89
|
}
|
|
87
|
-
else {
|
|
90
|
+
else if (onError) {
|
|
88
91
|
onError(error);
|
|
89
92
|
}
|
|
93
|
+
else {
|
|
94
|
+
throw new Error(JSON.stringify(error));
|
|
95
|
+
}
|
|
90
96
|
});
|
|
91
97
|
}
|
|
92
98
|
// Called when any fields in the record are changed
|
|
@@ -156,9 +162,12 @@ export default function Create({ locales, onCreated, onError, template }) {
|
|
|
156
162
|
if (error.code === errors.body.DATA_FIELDS) {
|
|
157
163
|
fieldErrorsSet(errorTree(error.msg));
|
|
158
164
|
}
|
|
159
|
-
else {
|
|
165
|
+
else if (onError) {
|
|
160
166
|
onError(error);
|
|
161
167
|
}
|
|
168
|
+
else {
|
|
169
|
+
throw new Error(JSON.stringify(error));
|
|
170
|
+
}
|
|
162
171
|
previewSet(false);
|
|
163
172
|
}, value: { ...record, type } }))));
|
|
164
173
|
}
|
|
@@ -12,7 +12,7 @@ import { contentStruct } from '../..';
|
|
|
12
12
|
import { responseErrorStruct } from '@ouroboros/body';
|
|
13
13
|
export type PreviewProps = {
|
|
14
14
|
onClose: () => void;
|
|
15
|
-
onError
|
|
15
|
+
onError?: (error: responseErrorStruct) => void;
|
|
16
16
|
value: contentStruct;
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
@@ -29,7 +29,7 @@ declare function Preview({ onClose, onError, value }: PreviewProps): React.JSX.E
|
|
|
29
29
|
declare namespace Preview {
|
|
30
30
|
var propTypes: {
|
|
31
31
|
onClose: PropTypes.Validator<(...args: any[]) => any>;
|
|
32
|
-
onError: PropTypes.
|
|
32
|
+
onError: PropTypes.Requireable<(...args: any[]) => any>;
|
|
33
33
|
value: PropTypes.Requireable<PropTypes.InferProps<{
|
|
34
34
|
locale: PropTypes.Validator<string>;
|
|
35
35
|
template: PropTypes.Requireable<string>;
|
|
@@ -33,7 +33,14 @@ export default function Preview({ onClose, onError, value }) {
|
|
|
33
33
|
const [preview, previewSet] = useState(false);
|
|
34
34
|
// Value effect
|
|
35
35
|
useEffect(() => {
|
|
36
|
-
mouth.create(`template/${value.type}/generate`, value).then(previewSet,
|
|
36
|
+
mouth.create(`template/${value.type}/generate`, value).then(previewSet, error => {
|
|
37
|
+
if (onError) {
|
|
38
|
+
onError(error);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error(JSON.stringify(error));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
37
44
|
}, [value, onError]);
|
|
38
45
|
// Render
|
|
39
46
|
return (React.createElement(Dialog, { fullWidth: true, maxWidth: "lg", onClose: onClose, open: true, "aria-labelledby": "template-content-preview-title" },
|
|
@@ -51,7 +58,7 @@ export default function Preview({ onClose, onError, value }) {
|
|
|
51
58
|
// Valid props
|
|
52
59
|
Preview.propTypes = {
|
|
53
60
|
onClose: PropTypes.func.isRequired,
|
|
54
|
-
onError: PropTypes.func
|
|
61
|
+
onError: PropTypes.func,
|
|
55
62
|
value: PropTypes.shape({
|
|
56
63
|
locale: PropTypes.string.isRequired,
|
|
57
64
|
template: PropTypes.string,
|
|
@@ -12,7 +12,7 @@ import { responseErrorStruct } from '@ouroboros/body';
|
|
|
12
12
|
import { contentStruct } from '../..';
|
|
13
13
|
export type updateStruct = Omit<contentStruct, 'type'>;
|
|
14
14
|
export type UpdateProps = {
|
|
15
|
-
onError
|
|
15
|
+
onError?: (error: responseErrorStruct) => void;
|
|
16
16
|
onUpdated: (content: contentStruct) => void;
|
|
17
17
|
value: contentStruct;
|
|
18
18
|
};
|
|
@@ -66,9 +66,12 @@ export default function Update({ onError, onUpdated, value }) {
|
|
|
66
66
|
onError({ code: 0, msg: lLines.join('\n') });
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
else {
|
|
69
|
+
else if (onError) {
|
|
70
70
|
onError(error);
|
|
71
71
|
}
|
|
72
|
+
else {
|
|
73
|
+
throw new Error(JSON.stringify(error));
|
|
74
|
+
}
|
|
72
75
|
});
|
|
73
76
|
}
|
|
74
77
|
// Called when any fields in the record are changed
|
|
@@ -94,9 +97,12 @@ export default function Update({ onError, onUpdated, value }) {
|
|
|
94
97
|
if (error.code === errors.body.DATA_FIELDS) {
|
|
95
98
|
fieldErrorsSet(errorTree(error.msg));
|
|
96
99
|
}
|
|
97
|
-
else {
|
|
100
|
+
else if (onError) {
|
|
98
101
|
onError(error);
|
|
99
102
|
}
|
|
103
|
+
else {
|
|
104
|
+
throw new Error(JSON.stringify(error));
|
|
105
|
+
}
|
|
100
106
|
previewSet(false);
|
|
101
107
|
}, value: { ...record, type: value.type } }))));
|
|
102
108
|
}
|
|
@@ -11,7 +11,7 @@ import React from 'react';
|
|
|
11
11
|
import { responseErrorStruct } from '@ouroboros/body';
|
|
12
12
|
import { contentStruct } from '../..';
|
|
13
13
|
export type ViewProps = {
|
|
14
|
-
onError
|
|
14
|
+
onError?: (error: responseErrorStruct) => void;
|
|
15
15
|
value: contentStruct;
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
@@ -27,7 +27,7 @@ export type ViewProps = {
|
|
|
27
27
|
declare function View({ onError, value }: ViewProps): React.JSX.Element;
|
|
28
28
|
declare namespace View {
|
|
29
29
|
var propTypes: {
|
|
30
|
-
onError: PropTypes.
|
|
30
|
+
onError: PropTypes.Requireable<(...args: any[]) => any>;
|
|
31
31
|
value: PropTypes.Requireable<PropTypes.InferProps<{
|
|
32
32
|
_id: PropTypes.Validator<string>;
|
|
33
33
|
type: PropTypes.Validator<string>;
|
|
@@ -41,7 +41,7 @@ export default function View({ onError, value }) {
|
|
|
41
41
|
}
|
|
42
42
|
// Valid props
|
|
43
43
|
View.propTypes = {
|
|
44
|
-
onError: PropTypes.func
|
|
44
|
+
onError: PropTypes.func,
|
|
45
45
|
value: PropTypes.shape({
|
|
46
46
|
_id: PropTypes.string.isRequired,
|
|
47
47
|
type: PropTypes.oneOf(['email', 'sms']).isRequired
|
|
@@ -33,7 +33,7 @@ export type typeOption = 'email' | 'sms';
|
|
|
33
33
|
export type TemplateProps = {
|
|
34
34
|
locales: Record<string, string>;
|
|
35
35
|
onChange: (template: templateStruct) => void;
|
|
36
|
-
onError
|
|
36
|
+
onError?: (error: responseErrorStruct) => void;
|
|
37
37
|
onContent: (type: string) => void;
|
|
38
38
|
rights: {
|
|
39
39
|
template: idStruct;
|
|
@@ -58,7 +58,7 @@ declare namespace Template {
|
|
|
58
58
|
[x: string]: string | null | undefined;
|
|
59
59
|
}>;
|
|
60
60
|
onChange: PropTypes.Validator<(...args: any[]) => any>;
|
|
61
|
-
onError: PropTypes.
|
|
61
|
+
onError: PropTypes.Requireable<(...args: any[]) => any>;
|
|
62
62
|
onContent: PropTypes.Validator<(...args: any[]) => any>;
|
|
63
63
|
rights: PropTypes.Requireable<Required<PropTypes.InferProps<{
|
|
64
64
|
template: PropTypes.Validator<Required<PropTypes.InferProps<{
|
|
@@ -163,7 +163,7 @@ export default function Template({ locales, onChange, onError, onContent, rights
|
|
|
163
163
|
Template.propTypes = {
|
|
164
164
|
locales: PropTypes.objectOf(PropTypes.string).isRequired,
|
|
165
165
|
onChange: PropTypes.func.isRequired,
|
|
166
|
-
onError: PropTypes.func
|
|
166
|
+
onError: PropTypes.func,
|
|
167
167
|
onContent: PropTypes.func.isRequired,
|
|
168
168
|
rights: PropTypes.exact({
|
|
169
169
|
template: PropTypes.exact({
|
|
@@ -10,8 +10,8 @@ import PropTypes from 'prop-types';
|
|
|
10
10
|
import React from 'react';
|
|
11
11
|
import { responseErrorStruct } from '@ouroboros/body';
|
|
12
12
|
export type TemplatesProps = {
|
|
13
|
-
onError
|
|
14
|
-
onSuccess
|
|
13
|
+
onError?: (error: responseErrorStruct) => void;
|
|
14
|
+
onSuccess?: (type: string) => void;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Templates
|
|
@@ -26,8 +26,8 @@ export type TemplatesProps = {
|
|
|
26
26
|
declare function Templates({ onError, onSuccess }: TemplatesProps): React.JSX.Element;
|
|
27
27
|
declare namespace Templates {
|
|
28
28
|
var propTypes: {
|
|
29
|
-
onError: PropTypes.
|
|
30
|
-
onSuccess: PropTypes.
|
|
29
|
+
onError: PropTypes.Requireable<(...args: any[]) => any>;
|
|
30
|
+
onSuccess: PropTypes.Requireable<(...args: any[]) => any>;
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
export default Templates;
|
|
@@ -63,7 +63,9 @@ export default function Templates({ onError, onSuccess }) {
|
|
|
63
63
|
// Called when a template has been created
|
|
64
64
|
function templateCreated(template) {
|
|
65
65
|
// Notify parent
|
|
66
|
-
onSuccess
|
|
66
|
+
if (onSuccess) {
|
|
67
|
+
onSuccess('template_create');
|
|
68
|
+
}
|
|
67
69
|
// Hide the create form
|
|
68
70
|
createSet(false);
|
|
69
71
|
// Clone the current templates, add the new one to the front, and set
|
|
@@ -73,7 +75,9 @@ export default function Templates({ onError, onSuccess }) {
|
|
|
73
75
|
// Called when a template has been updated
|
|
74
76
|
function templateUpdated(template) {
|
|
75
77
|
// Notify parent
|
|
76
|
-
onSuccess
|
|
78
|
+
if (onSuccess) {
|
|
79
|
+
onSuccess('template_update');
|
|
80
|
+
}
|
|
77
81
|
// Work on latest
|
|
78
82
|
templatesSet(l => arrayFindOverwrite(l, '_id', template._id, template, true));
|
|
79
83
|
}
|
|
@@ -88,13 +92,17 @@ export default function Templates({ onError, onSuccess }) {
|
|
|
88
92
|
React.createElement("i", { className: 'fa-solid fa-plus' + (create ? ' open' : '') }))))),
|
|
89
93
|
create &&
|
|
90
94
|
React.createElement(Create, { onCancel: () => createSet(false), onCreated: templateCreated, onError: onError }),
|
|
91
|
-
templates.map((o) => React.createElement(Template, { key: o._id, locales: locales, onChange: templateUpdated, onContent: type =>
|
|
95
|
+
templates.map((o) => React.createElement(Template, { key: o._id, locales: locales, onChange: templateUpdated, onContent: type => {
|
|
96
|
+
if (onSuccess) {
|
|
97
|
+
onSuccess(`content_${type}`);
|
|
98
|
+
}
|
|
99
|
+
}, onError: onError, rights: {
|
|
92
100
|
content: rightsContent,
|
|
93
101
|
template: rightsTemplate
|
|
94
102
|
}, value: o }))));
|
|
95
103
|
}
|
|
96
104
|
// Valid props
|
|
97
105
|
Templates.propTypes = {
|
|
98
|
-
onError: PropTypes.func
|
|
99
|
-
onSuccess: PropTypes.func
|
|
106
|
+
onError: PropTypes.func,
|
|
107
|
+
onSuccess: PropTypes.func
|
|
100
108
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouroboros/mouth-mui",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Components for use with the Mouth service",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@ouroboros/define": "^1.1.3",
|
|
38
38
|
"@ouroboros/define-mui": "^1.5.6",
|
|
39
|
-
"@ouroboros/mouth": "^2.1.
|
|
39
|
+
"@ouroboros/mouth": "^2.1.2",
|
|
40
40
|
"@ouroboros/react-radiobuttons-mui": "^1.1.0",
|
|
41
41
|
"@ouroboros/subscribe": "^1.3.2",
|
|
42
|
-
"@ouroboros/tools": "^0.7.
|
|
42
|
+
"@ouroboros/tools": "^0.7.1",
|
|
43
43
|
"prop-types": "^15.8.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
package/releases.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @ouroboros/mouth-mui releases
|
|
2
|
+
|
|
3
|
+
## 2.1.2
|
|
4
|
+
- Completed documentation.
|
|
5
|
+
|
|
6
|
+
## 2.1.1
|
|
7
|
+
- Updated @ouroboros/mouth to 2.1.1.
|
|
8
|
+
- Updated @ouroboros/body to 1.2.0.
|
|
9
|
+
- Updated @ouroboros/brain-react to 2.3.1.
|
|
10
|
+
|
|
11
|
+
## 2.1.0
|
|
12
|
+
- Updated @ouroboros/brain-react to 2.3.0.
|
|
13
|
+
- Updated @ouroboros/define to 1.1.3.
|
|
14
|
+
- Updated @ouroboros/define-mui to 1.5.6.
|
|
15
|
+
- Updated @ouroboros/mouth to 2.1.0.
|
|
16
|
+
- Removed the `mobile` prop from all components as it wasn't used.
|
|
17
|
+
- Removed all uses of clone from the project.
|
|
18
|
+
- Added a shared file for holding onto common types / defines.
|
|
@@ -97,7 +97,9 @@ export default function Locales({ onError, onSuccess }: LocalesProps) {
|
|
|
97
97
|
if(data) {
|
|
98
98
|
|
|
99
99
|
// Notify the parent
|
|
100
|
-
onSuccess
|
|
100
|
+
if(onSuccess) {
|
|
101
|
+
onSuccess('create');
|
|
102
|
+
}
|
|
101
103
|
|
|
102
104
|
// Close the create form
|
|
103
105
|
createSet(false);
|
|
@@ -140,7 +142,9 @@ export default function Locales({ onError, onSuccess }: LocalesProps) {
|
|
|
140
142
|
if(data) {
|
|
141
143
|
|
|
142
144
|
// Notify the parent
|
|
143
|
-
onSuccess
|
|
145
|
+
if(onSuccess) {
|
|
146
|
+
onSuccess('delete');
|
|
147
|
+
}
|
|
144
148
|
|
|
145
149
|
// Look for the record
|
|
146
150
|
const i = afindi(records, '_id', key);
|
|
@@ -183,7 +187,9 @@ export default function Locales({ onError, onSuccess }: LocalesProps) {
|
|
|
183
187
|
if(data) {
|
|
184
188
|
|
|
185
189
|
// Notify the parent
|
|
186
|
-
onSuccess
|
|
190
|
+
if(onSuccess) {
|
|
191
|
+
onSuccess('update');
|
|
192
|
+
}
|
|
187
193
|
|
|
188
194
|
// Look for the record
|
|
189
195
|
const i = afindi(records, '_id', key);
|
|
@@ -262,6 +268,6 @@ export default function Locales({ onError, onSuccess }: LocalesProps) {
|
|
|
262
268
|
|
|
263
269
|
// Valid props
|
|
264
270
|
Locales.propTypes = {
|
|
265
|
-
onError: PropTypes.func
|
|
266
|
-
onSuccess: PropTypes.func
|
|
271
|
+
onError: PropTypes.func,
|
|
272
|
+
onSuccess: PropTypes.func
|
|
267
273
|
}
|
|
@@ -35,7 +35,7 @@ import { templateStruct } from './Template';
|
|
|
35
35
|
export interface CreateProps {
|
|
36
36
|
onCancel?: () => void,
|
|
37
37
|
onCreated: (template: templateStruct) => void,
|
|
38
|
-
onError
|
|
38
|
+
onError?: (error: responseErrorStruct) => void
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -132,5 +132,5 @@ export default function Create({ onCancel, onCreated, onError }: CreateProps) {
|
|
|
132
132
|
Create.propTypes = {
|
|
133
133
|
onCancel: PropTypes.func,
|
|
134
134
|
onCreated: PropTypes.func.isRequired,
|
|
135
|
-
onError: PropTypes.func
|
|
135
|
+
onError: PropTypes.func,
|
|
136
136
|
}
|
|
@@ -36,7 +36,7 @@ import { responseErrorStruct } from '@ouroboros/body';
|
|
|
36
36
|
export type TemplateContentCreateProps = {
|
|
37
37
|
locales: Record<string, string>,
|
|
38
38
|
onCreated: (content: contentStruct) => void,
|
|
39
|
-
onError
|
|
39
|
+
onError?: (error: responseErrorStruct) => void,
|
|
40
40
|
template: string
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -103,9 +103,13 @@ export default function Create(
|
|
|
103
103
|
// Show the errors
|
|
104
104
|
if(onError) {
|
|
105
105
|
onError({ code: 0, msg: lLines.join('\n') });
|
|
106
|
+
} else {
|
|
107
|
+
throw new Error(JSON.stringify(error));
|
|
106
108
|
}
|
|
107
|
-
} else {
|
|
109
|
+
} else if(onError) {
|
|
108
110
|
onError(error);
|
|
111
|
+
} else {
|
|
112
|
+
throw new Error(JSON.stringify(error));
|
|
109
113
|
}
|
|
110
114
|
});
|
|
111
115
|
}
|
|
@@ -227,8 +231,10 @@ export default function Create(
|
|
|
227
231
|
onError={(error: responseErrorStruct) => {
|
|
228
232
|
if(error.code === errors.body.DATA_FIELDS) {
|
|
229
233
|
fieldErrorsSet(errorTree(error.msg));
|
|
230
|
-
} else {
|
|
234
|
+
} else if(onError) {
|
|
231
235
|
onError(error);
|
|
236
|
+
} else {
|
|
237
|
+
throw new Error(JSON.stringify(error));
|
|
232
238
|
}
|
|
233
239
|
previewSet(false);
|
|
234
240
|
}}
|
|
@@ -30,7 +30,7 @@ import { contentStruct } from '../..';
|
|
|
30
30
|
import { responseErrorStruct } from '@ouroboros/body';
|
|
31
31
|
export type PreviewProps = {
|
|
32
32
|
onClose: () => void,
|
|
33
|
-
onError
|
|
33
|
+
onError?: (error: responseErrorStruct) => void,
|
|
34
34
|
value: contentStruct
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -54,8 +54,14 @@ export default function Preview({ onClose, onError, value }: PreviewProps) {
|
|
|
54
54
|
mouth.create(
|
|
55
55
|
`template/${value.type}/generate`,
|
|
56
56
|
value
|
|
57
|
-
).then(previewSet,
|
|
58
|
-
|
|
57
|
+
).then(previewSet, error => {
|
|
58
|
+
if(onError) {
|
|
59
|
+
onError(error);
|
|
60
|
+
} else {
|
|
61
|
+
throw new Error(JSON.stringify(error));
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
}, [ value, onError ]);
|
|
59
65
|
|
|
60
66
|
// Render
|
|
61
67
|
return (
|
|
@@ -91,7 +97,7 @@ export default function Preview({ onClose, onError, value }: PreviewProps) {
|
|
|
91
97
|
// Valid props
|
|
92
98
|
Preview.propTypes = {
|
|
93
99
|
onClose: PropTypes.func.isRequired,
|
|
94
|
-
onError: PropTypes.func
|
|
100
|
+
onError: PropTypes.func,
|
|
95
101
|
value: PropTypes.shape({
|
|
96
102
|
locale: PropTypes.string.isRequired,
|
|
97
103
|
template: PropTypes.string,
|
|
@@ -30,7 +30,7 @@ import { responseErrorStruct } from '@ouroboros/body';
|
|
|
30
30
|
import { contentStruct } from '../..';
|
|
31
31
|
export type updateStruct = Omit<contentStruct, 'type'>;
|
|
32
32
|
export type UpdateProps = {
|
|
33
|
-
onError
|
|
33
|
+
onError?: (error: responseErrorStruct) => void,
|
|
34
34
|
onUpdated: (content: contentStruct) => void,
|
|
35
35
|
value: contentStruct
|
|
36
36
|
}
|
|
@@ -82,8 +82,10 @@ export default function Update({ onError, onUpdated, value }: UpdateProps) {
|
|
|
82
82
|
if(onError) {
|
|
83
83
|
onError({ code: 0, msg: lLines.join('\n') });
|
|
84
84
|
}
|
|
85
|
-
} else {
|
|
85
|
+
} else if(onError) {
|
|
86
86
|
onError(error);
|
|
87
|
+
} else {
|
|
88
|
+
throw new Error(JSON.stringify(error));
|
|
87
89
|
}
|
|
88
90
|
});
|
|
89
91
|
}
|
|
@@ -128,8 +130,10 @@ export default function Update({ onError, onUpdated, value }: UpdateProps) {
|
|
|
128
130
|
onError={(error: responseErrorStruct) => {
|
|
129
131
|
if(error.code === errors.body.DATA_FIELDS) {
|
|
130
132
|
fieldErrorsSet(errorTree(error.msg));
|
|
131
|
-
} else {
|
|
133
|
+
} else if(onError) {
|
|
132
134
|
onError(error);
|
|
135
|
+
} else {
|
|
136
|
+
throw new Error(JSON.stringify(error));
|
|
133
137
|
}
|
|
134
138
|
previewSet(false);
|
|
135
139
|
}}
|
|
@@ -24,7 +24,7 @@ import SMS from './SMS';
|
|
|
24
24
|
import { responseErrorStruct } from '@ouroboros/body';
|
|
25
25
|
import { contentStruct } from '../..';
|
|
26
26
|
export type ViewProps = {
|
|
27
|
-
onError
|
|
27
|
+
onError?: (error: responseErrorStruct) => void,
|
|
28
28
|
value: contentStruct
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -67,7 +67,7 @@ export default function View({ onError, value }: ViewProps) {
|
|
|
67
67
|
|
|
68
68
|
// Valid props
|
|
69
69
|
View.propTypes = {
|
|
70
|
-
onError: PropTypes.func
|
|
70
|
+
onError: PropTypes.func,
|
|
71
71
|
value: PropTypes.shape({
|
|
72
72
|
_id: PropTypes.string.isRequired,
|
|
73
73
|
type: PropTypes.oneOf([ 'email', 'sms' ]).isRequired
|
|
@@ -61,7 +61,7 @@ export type typeOption = 'email' | 'sms';
|
|
|
61
61
|
export type TemplateProps = {
|
|
62
62
|
locales: Record<string, string>,
|
|
63
63
|
onChange: (template: templateStruct) => void,
|
|
64
|
-
onError
|
|
64
|
+
onError?: (error: responseErrorStruct) => void,
|
|
65
65
|
onContent: (type: string) => void,
|
|
66
66
|
rights: {
|
|
67
67
|
template: idStruct,
|
|
@@ -289,7 +289,7 @@ export default function Template(
|
|
|
289
289
|
Template.propTypes = {
|
|
290
290
|
locales: PropTypes.objectOf(PropTypes.string).isRequired,
|
|
291
291
|
onChange: PropTypes.func.isRequired,
|
|
292
|
-
onError: PropTypes.func
|
|
292
|
+
onError: PropTypes.func,
|
|
293
293
|
onContent: PropTypes.func.isRequired,
|
|
294
294
|
rights: PropTypes.exact({
|
|
295
295
|
template: PropTypes.exact({
|
|
@@ -28,8 +28,8 @@ import Template, { templateStruct } from './Template';
|
|
|
28
28
|
// Types
|
|
29
29
|
import { responseErrorStruct } from '@ouroboros/body';
|
|
30
30
|
export type TemplatesProps = {
|
|
31
|
-
onError
|
|
32
|
-
onSuccess
|
|
31
|
+
onError?: (error: responseErrorStruct) => void,
|
|
32
|
+
onSuccess?: (type: string) => void
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -82,7 +82,9 @@ export default function Templates({ onError, onSuccess }: TemplatesProps) {
|
|
|
82
82
|
function templateCreated(template: templateStruct) {
|
|
83
83
|
|
|
84
84
|
// Notify parent
|
|
85
|
-
onSuccess
|
|
85
|
+
if(onSuccess) {
|
|
86
|
+
onSuccess('template_create');
|
|
87
|
+
}
|
|
86
88
|
|
|
87
89
|
// Hide the create form
|
|
88
90
|
createSet(false);
|
|
@@ -96,7 +98,9 @@ export default function Templates({ onError, onSuccess }: TemplatesProps) {
|
|
|
96
98
|
function templateUpdated(template: templateStruct) {
|
|
97
99
|
|
|
98
100
|
// Notify parent
|
|
99
|
-
onSuccess
|
|
101
|
+
if(onSuccess) {
|
|
102
|
+
onSuccess('template_update');
|
|
103
|
+
}
|
|
100
104
|
|
|
101
105
|
// Work on latest
|
|
102
106
|
templatesSet(l =>
|
|
@@ -133,7 +137,11 @@ export default function Templates({ onError, onSuccess }: TemplatesProps) {
|
|
|
133
137
|
key={o._id}
|
|
134
138
|
locales={locales}
|
|
135
139
|
onChange={templateUpdated}
|
|
136
|
-
onContent={type =>
|
|
140
|
+
onContent={type => {
|
|
141
|
+
if(onSuccess) {
|
|
142
|
+
onSuccess(`content_${type}`)
|
|
143
|
+
}
|
|
144
|
+
}}
|
|
137
145
|
onError={onError}
|
|
138
146
|
rights={{
|
|
139
147
|
content: rightsContent,
|
|
@@ -148,6 +156,6 @@ export default function Templates({ onError, onSuccess }: TemplatesProps) {
|
|
|
148
156
|
|
|
149
157
|
// Valid props
|
|
150
158
|
Templates.propTypes = {
|
|
151
|
-
onError: PropTypes.func
|
|
152
|
-
onSuccess: PropTypes.func
|
|
159
|
+
onError: PropTypes.func,
|
|
160
|
+
onSuccess: PropTypes.func
|
|
153
161
|
}
|