@ouroboros/mouth-mui 2.1.1 → 2.1.3
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 +62 -48
- package/lib/components/pages/Templates/Create.d.ts +2 -2
- package/lib/components/pages/Templates/Create.js +17 -14
- package/lib/components/pages/Templates/Template/Content/Create/index.d.ts +1 -1
- package/lib/components/pages/Templates/Template/Content/Create/index.js +44 -32
- package/lib/components/pages/Templates/Template/Content/Preview/index.d.ts +2 -2
- package/lib/components/pages/Templates/Template/Content/Preview/index.js +15 -2
- package/lib/components/pages/Templates/Template/Content/Update/index.d.ts +1 -1
- package/lib/components/pages/Templates/Template/Content/Update/index.js +36 -26
- 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 +18 -10
- package/lib/components/pages/Templates/index.d.ts +4 -4
- package/lib/components/pages/Templates/index.js +16 -8
- package/lib/locales.js +18 -15
- package/package.json +9 -10
- package/releases.md +21 -0
- package/src/components/pages/Locales.tsx +61 -46
- package/src/components/pages/Templates/Create.tsx +21 -17
- package/src/components/pages/Templates/Template/Content/Create/index.tsx +48 -38
- package/src/components/pages/Templates/Template/Content/Preview/index.tsx +20 -5
- package/src/components/pages/Templates/Template/Content/Update/index.tsx +38 -28
- package/src/components/pages/Templates/Template/Content/View/index.tsx +2 -2
- package/src/components/pages/Templates/Template/index.tsx +20 -13
- package/src/components/pages/Templates/index.tsx +20 -12
- package/src/locales.ts +25 -22
|
@@ -26,11 +26,11 @@ import Preview from '../Preview';
|
|
|
26
26
|
import SMS from './SMS';
|
|
27
27
|
|
|
28
28
|
// Types
|
|
29
|
-
import { responseErrorStruct } from '@ouroboros/body';
|
|
29
|
+
import { responseErrorStruct, responseStruct } 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
|
}
|
|
@@ -56,35 +56,43 @@ export default function Update({ onError, onUpdated, value }: UpdateProps) {
|
|
|
56
56
|
function update() {
|
|
57
57
|
|
|
58
58
|
// Send the record data to the server
|
|
59
|
-
mouth.update(`template/${value.type}`, record).then(() => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if(error
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
mouth.update(`template/${value.type}`, record).then((res: responseStruct) => {
|
|
60
|
+
|
|
61
|
+
// If we failed
|
|
62
|
+
if(res.error) {
|
|
63
|
+
if(res.error.code === errors.body.DATA_FIELDS) {
|
|
64
|
+
fieldErrorsSet(errorTree(res.error.msg));
|
|
65
|
+
} else if(res.error.code === errors.TEMPLATE_CONTENT_ERROR) {
|
|
66
|
+
const oLines: { templates: string[], variables: string[] } = { templates: [], variables: [] };
|
|
67
|
+
for(const l of res.error.msg) {
|
|
68
|
+
if(l[0] === 'template') {
|
|
69
|
+
oLines.templates.push(l[1]);
|
|
70
|
+
} else if(l[0] === 'variable') {
|
|
71
|
+
oLines.variables.push(l[1]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const lLines = [];
|
|
75
|
+
if(oLines.templates.length) {
|
|
76
|
+
lLines.push('The following templates are invalid: ' + oLines.templates.join(', '));
|
|
77
|
+
}
|
|
78
|
+
if(oLines.variables.length) {
|
|
79
|
+
lLines.push('The following variables are invalid: ' + oLines.variables.join(', '));
|
|
71
80
|
}
|
|
72
|
-
}
|
|
73
|
-
const lLines = [];
|
|
74
|
-
if(oLines.templates.length) {
|
|
75
|
-
lLines.push('The following templates are invalid: ' + oLines.templates.join(', '));
|
|
76
|
-
}
|
|
77
|
-
if(oLines.variables.length) {
|
|
78
|
-
lLines.push('The following variables are invalid: ' + oLines.variables.join(', '));
|
|
79
|
-
}
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
// Show the errors
|
|
83
|
+
if(onError) {
|
|
84
|
+
onError({ code: 0, msg: lLines.join('\n') });
|
|
85
|
+
}
|
|
86
|
+
} else if(onError) {
|
|
87
|
+
onError(res.error);
|
|
88
|
+
} else {
|
|
89
|
+
throw new Error(JSON.stringify(res.error));
|
|
84
90
|
}
|
|
85
|
-
|
|
86
|
-
onError(error);
|
|
91
|
+
return;
|
|
87
92
|
}
|
|
93
|
+
|
|
94
|
+
// Let the parent know it was updated
|
|
95
|
+
onUpdated({type: value.type, ...record});
|
|
88
96
|
});
|
|
89
97
|
}
|
|
90
98
|
|
|
@@ -128,8 +136,10 @@ export default function Update({ onError, onUpdated, value }: UpdateProps) {
|
|
|
128
136
|
onError={(error: responseErrorStruct) => {
|
|
129
137
|
if(error.code === errors.body.DATA_FIELDS) {
|
|
130
138
|
fieldErrorsSet(errorTree(error.msg));
|
|
131
|
-
} else {
|
|
139
|
+
} else if(onError) {
|
|
132
140
|
onError(error);
|
|
141
|
+
} else {
|
|
142
|
+
throw new Error(JSON.stringify(error));
|
|
133
143
|
}
|
|
134
144
|
previewSet(false);
|
|
135
145
|
}}
|
|
@@ -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
|
|
@@ -36,7 +36,7 @@ import ContentView from './Content/View';
|
|
|
36
36
|
import Variables from './Variables';
|
|
37
37
|
|
|
38
38
|
// Types
|
|
39
|
-
import { responseErrorStruct } from '@ouroboros/body';
|
|
39
|
+
import { responseErrorStruct, responseStruct } from '@ouroboros/body';
|
|
40
40
|
import { idStruct } from '@ouroboros/brain-react';
|
|
41
41
|
export type contentStruct = {
|
|
42
42
|
_id?: string,
|
|
@@ -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,
|
|
@@ -134,21 +134,28 @@ export default function Template(
|
|
|
134
134
|
function update() {
|
|
135
135
|
|
|
136
136
|
// Create the data in the system
|
|
137
|
-
mouth.update('template', edit).then((
|
|
137
|
+
mouth.update('template', edit).then((res: responseStruct) => {
|
|
138
|
+
|
|
139
|
+
// If we failed
|
|
140
|
+
if(res.error) {
|
|
141
|
+
if(res.error.code === errors.body.DB_DUPLICATE) {
|
|
142
|
+
refName.current?.error('Duplicate');
|
|
143
|
+
} else {
|
|
144
|
+
if(onError) {
|
|
145
|
+
onError(res.error);
|
|
146
|
+
} else {
|
|
147
|
+
throw new Error(JSON.stringify(res.error));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
138
152
|
|
|
139
153
|
// Hide the form
|
|
140
154
|
editSet(false);
|
|
141
155
|
|
|
142
156
|
// Let the parent know
|
|
143
157
|
onChange(edit as templateStruct);
|
|
144
|
-
|
|
145
|
-
}, (error: responseErrorStruct) => {
|
|
146
|
-
if(error.code === errors.body.DB_DUPLICATE) {
|
|
147
|
-
refName.current?.error('Duplicate');
|
|
148
|
-
} else {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
})
|
|
158
|
+
});
|
|
152
159
|
}
|
|
153
160
|
|
|
154
161
|
// View toggle
|
|
@@ -159,7 +166,7 @@ export default function Template(
|
|
|
159
166
|
if(contents === false) {
|
|
160
167
|
mouth.read('template/contents', {
|
|
161
168
|
template: value._id
|
|
162
|
-
}).then(contentsSet);
|
|
169
|
+
}).then((res: responseStruct) => contentsSet(res.data));
|
|
163
170
|
}
|
|
164
171
|
viewSet(true);
|
|
165
172
|
}
|
|
@@ -289,7 +296,7 @@ export default function Template(
|
|
|
289
296
|
Template.propTypes = {
|
|
290
297
|
locales: PropTypes.objectOf(PropTypes.string).isRequired,
|
|
291
298
|
onChange: PropTypes.func.isRequired,
|
|
292
|
-
onError: PropTypes.func
|
|
299
|
+
onError: PropTypes.func,
|
|
293
300
|
onContent: PropTypes.func.isRequired,
|
|
294
301
|
rights: PropTypes.exact({
|
|
295
302
|
template: PropTypes.exact({
|
|
@@ -26,10 +26,10 @@ import Create from './Create'
|
|
|
26
26
|
import Template, { templateStruct } from './Template';
|
|
27
27
|
|
|
28
28
|
// Types
|
|
29
|
-
import { responseErrorStruct } from '@ouroboros/body';
|
|
29
|
+
import { responseErrorStruct, responseStruct } 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
|
/**
|
|
@@ -58,14 +58,14 @@ export default function Templates({ onError, onSuccess }: TemplatesProps) {
|
|
|
58
58
|
|
|
59
59
|
// If we have template read permissions
|
|
60
60
|
if(rightsTemplate.read) {
|
|
61
|
-
mouth.read('locales').then((
|
|
62
|
-
const oLocales: Record<string, string> = {};
|
|
63
|
-
for(const o of data) {
|
|
61
|
+
mouth.read('locales').then((res: responseStruct) => {
|
|
62
|
+
const oLocales: Record<string, string> = { };
|
|
63
|
+
for(const o of res.data) {
|
|
64
64
|
oLocales[o._id] = o.name;
|
|
65
65
|
}
|
|
66
66
|
localesSet(oLocales);
|
|
67
67
|
});
|
|
68
|
-
mouth.read('templates').then(templatesSet);
|
|
68
|
+
mouth.read('templates').then((res: responseStruct) => templatesSet(res.data));
|
|
69
69
|
} else {
|
|
70
70
|
localesSet({});
|
|
71
71
|
templatesSet([]);
|
|
@@ -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
|
}
|
package/src/locales.ts
CHANGED
|
@@ -16,6 +16,7 @@ import Subscribe, { SubscribeCallback, SubscribeReturn } from '@ouroboros/subscr
|
|
|
16
16
|
import mouth from '@ouroboros/mouth';
|
|
17
17
|
|
|
18
18
|
// Types
|
|
19
|
+
import { responseStruct } from '@ouroboros/body';
|
|
19
20
|
export type Option = {
|
|
20
21
|
id: string,
|
|
21
22
|
text: string
|
|
@@ -171,13 +172,33 @@ class Locales extends Subscribe {
|
|
|
171
172
|
this.fetching = true;
|
|
172
173
|
|
|
173
174
|
// Fetch the data from the server
|
|
174
|
-
mouth.read('locales').then((
|
|
175
|
+
mouth.read('locales').then((res: responseStruct) => {
|
|
176
|
+
|
|
177
|
+
// If we failed
|
|
178
|
+
if(res.error) {
|
|
179
|
+
|
|
180
|
+
// If we haven't hit the limit
|
|
181
|
+
if(this.failed < 3) {
|
|
182
|
+
|
|
183
|
+
// Increase the failed count
|
|
184
|
+
++this.failed;
|
|
185
|
+
|
|
186
|
+
// Fetch again
|
|
187
|
+
this.fetch();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Else, we can't keep trying, notify the user
|
|
191
|
+
else {
|
|
192
|
+
events.get('error').trigger(res.error);
|
|
193
|
+
}
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
175
196
|
|
|
176
197
|
// If there's data
|
|
177
|
-
if(
|
|
198
|
+
if(res.data) {
|
|
178
199
|
|
|
179
200
|
// Trigger all callbacks
|
|
180
|
-
this.set(
|
|
201
|
+
this.set(res.data);
|
|
181
202
|
}
|
|
182
203
|
|
|
183
204
|
// Finish running
|
|
@@ -185,29 +206,11 @@ class Locales extends Subscribe {
|
|
|
185
206
|
|
|
186
207
|
// Reset the count
|
|
187
208
|
this.failed = 0;
|
|
188
|
-
|
|
189
|
-
}, error => {
|
|
190
|
-
|
|
191
|
-
// If we haven't hit the limit
|
|
192
|
-
if(this.failed < 3) {
|
|
193
|
-
|
|
194
|
-
// Increase the failed count
|
|
195
|
-
++this.failed;
|
|
196
|
-
|
|
197
|
-
// Fetch again
|
|
198
|
-
this.fetch();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Else, we can't keep trying, notify the user
|
|
202
|
-
else {
|
|
203
|
-
events.get('error').trigger(error);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
209
|
}).finally(() => {
|
|
207
210
|
|
|
208
211
|
// Regardless of the outcome, we're done fetching
|
|
209
212
|
this.fetching = false;
|
|
210
|
-
})
|
|
213
|
+
});
|
|
211
214
|
}
|
|
212
215
|
|
|
213
216
|
/**
|