@ouroboros/mouth-mui 2.1.2 → 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/lib/components/pages/Locales.js +51 -43
- package/lib/components/pages/Templates/Create.js +16 -13
- package/lib/components/pages/Templates/Template/Content/Create/index.js +39 -36
- package/lib/components/pages/Templates/Template/Content/Preview/index.js +12 -6
- package/lib/components/pages/Templates/Template/Content/Update/index.js +32 -28
- package/lib/components/pages/Templates/Template/index.js +17 -9
- package/lib/components/pages/Templates/index.js +3 -3
- package/lib/locales.js +18 -15
- package/package.json +9 -10
- package/releases.md +3 -0
- package/src/components/pages/Locales.tsx +50 -41
- package/src/components/pages/Templates/Create.tsx +19 -15
- package/src/components/pages/Templates/Template/Content/Create/index.tsx +44 -40
- package/src/components/pages/Templates/Template/Content/Preview/index.tsx +15 -6
- package/src/components/pages/Templates/Template/Content/Update/index.tsx +34 -28
- package/src/components/pages/Templates/Template/index.tsx +18 -11
- package/src/components/pages/Templates/index.tsx +5 -5
- package/src/locales.ts +25 -22
|
@@ -54,7 +54,7 @@ export default function Locales({ onError, onSuccess }) {
|
|
|
54
54
|
useEffect(() => {
|
|
55
55
|
// If we have read rights
|
|
56
56
|
if (rights.read) {
|
|
57
|
-
mouth.read('locales').then(recordsSet);
|
|
57
|
+
mouth.read('locales').then((res) => recordsSet(res.data));
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
60
|
recordsSet([]);
|
|
@@ -69,9 +69,27 @@ export default function Locales({ onError, onSuccess }) {
|
|
|
69
69
|
// Create a new Promise and return it
|
|
70
70
|
return new Promise((resolve, reject) => {
|
|
71
71
|
// Create the new locale
|
|
72
|
-
mouth.create('locale', locale).then((
|
|
72
|
+
mouth.create('locale', locale).then((res) => {
|
|
73
|
+
// If we failed
|
|
74
|
+
if (res.error) {
|
|
75
|
+
if (res.error.code === errors.body.DB_NO_RECORD) {
|
|
76
|
+
return reject([['_id', 'Already in use']]);
|
|
77
|
+
}
|
|
78
|
+
else if (res.error.code === errors.body.DATA_FIELDS) {
|
|
79
|
+
return reject(res.error.msg);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
if (onError) {
|
|
83
|
+
onError(res.error);
|
|
84
|
+
return reject([]);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
throw new Error(JSON.stringify(res.error));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
73
91
|
// If we were successful
|
|
74
|
-
if (data) {
|
|
92
|
+
if (res.data) {
|
|
75
93
|
// Notify the parent
|
|
76
94
|
if (onSuccess) {
|
|
77
95
|
onSuccess('create');
|
|
@@ -86,31 +104,25 @@ export default function Locales({ onError, onSuccess }) {
|
|
|
86
104
|
locales.set(lRecords);
|
|
87
105
|
}
|
|
88
106
|
// Resolve with the form
|
|
89
|
-
resolve(data ? true : false);
|
|
90
|
-
}, (error) => {
|
|
91
|
-
if (error.code === errors.body.DB_NO_RECORD) {
|
|
92
|
-
reject([['_id', 'Already in use']]);
|
|
93
|
-
}
|
|
94
|
-
else if (error.code === errors.body.DATA_FIELDS) {
|
|
95
|
-
reject(error.msg);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
if (onError) {
|
|
99
|
-
onError(error);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
throw new Error(JSON.stringify(error));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
107
|
+
resolve(res.data ? true : false);
|
|
105
108
|
});
|
|
106
109
|
});
|
|
107
110
|
}
|
|
108
111
|
// Called when the delete button on a locale was clicked
|
|
109
112
|
function deleteClick(key) {
|
|
110
113
|
// Delete the existing locale
|
|
111
|
-
mouth.delete('locale', { _id: key }).then((
|
|
114
|
+
mouth.delete('locale', { _id: key }).then((res) => {
|
|
115
|
+
// If we failed
|
|
116
|
+
if (res.error) {
|
|
117
|
+
if (onError) {
|
|
118
|
+
return onError(res.error);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
throw new Error(JSON.stringify(res.error));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
112
124
|
// If it was successful
|
|
113
|
-
if (data) {
|
|
125
|
+
if (res.data) {
|
|
114
126
|
// Notify the parent
|
|
115
127
|
if (onSuccess) {
|
|
116
128
|
onSuccess('delete');
|
|
@@ -128,13 +140,6 @@ export default function Locales({ onError, onSuccess }) {
|
|
|
128
140
|
locales.set(lRecords);
|
|
129
141
|
}
|
|
130
142
|
}
|
|
131
|
-
}, (error) => {
|
|
132
|
-
if (onError) {
|
|
133
|
-
onError(error);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
throw new Error(JSON.stringify(error));
|
|
137
|
-
}
|
|
138
143
|
});
|
|
139
144
|
}
|
|
140
145
|
// Called when an update form is submitted
|
|
@@ -144,9 +149,24 @@ export default function Locales({ onError, onSuccess }) {
|
|
|
144
149
|
// Create a new Promise and return it
|
|
145
150
|
return new Promise((resolve, reject) => {
|
|
146
151
|
// Update the locale on the server
|
|
147
|
-
mouth.update('locale', locale).then((
|
|
152
|
+
mouth.update('locale', locale).then((res) => {
|
|
153
|
+
// If we failed
|
|
154
|
+
if (res.error) {
|
|
155
|
+
if (res.error.code === errors.body.DATA_FIELDS) {
|
|
156
|
+
return reject(res.error.msg);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
if (onError) {
|
|
160
|
+
onError(res.error);
|
|
161
|
+
return reject([]);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
throw new Error(JSON.stringify(res.error));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
148
168
|
// If we were successful
|
|
149
|
-
if (data) {
|
|
169
|
+
if (res.data) {
|
|
150
170
|
// Notify the parent
|
|
151
171
|
if (onSuccess) {
|
|
152
172
|
onSuccess('update');
|
|
@@ -165,19 +185,7 @@ export default function Locales({ onError, onSuccess }) {
|
|
|
165
185
|
}
|
|
166
186
|
}
|
|
167
187
|
// Resolve with the Form
|
|
168
|
-
resolve(data);
|
|
169
|
-
}, (error) => {
|
|
170
|
-
if (error.code === errors.body.DATA_FIELDS) {
|
|
171
|
-
reject(error.msg);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
if (onError) {
|
|
175
|
-
onError(error);
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
throw new Error(JSON.stringify(error));
|
|
179
|
-
}
|
|
180
|
-
}
|
|
188
|
+
resolve(res.data);
|
|
181
189
|
});
|
|
182
190
|
});
|
|
183
191
|
}
|
|
@@ -51,23 +51,26 @@ export default function Create({ onCancel, onCreated, onError }) {
|
|
|
51
51
|
// Called to create the template
|
|
52
52
|
function create() {
|
|
53
53
|
// Create the data in the system
|
|
54
|
-
mouth.create('template', record).then((
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}, (error) => {
|
|
60
|
-
if (error.code === errors.body.DB_DUPLICATE) {
|
|
61
|
-
refName.current?.error('Duplicate');
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
if (onError) {
|
|
65
|
-
onError(error);
|
|
54
|
+
mouth.create('template', record).then((res) => {
|
|
55
|
+
// If we failed
|
|
56
|
+
if (res.error) {
|
|
57
|
+
if (res.error.code === errors.body.DB_DUPLICATE) {
|
|
58
|
+
refName.current?.error('Duplicate');
|
|
66
59
|
}
|
|
67
60
|
else {
|
|
68
|
-
|
|
61
|
+
if (onError) {
|
|
62
|
+
onError(res.error);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error(JSON.stringify(res.error));
|
|
67
|
+
}
|
|
69
68
|
}
|
|
70
69
|
}
|
|
70
|
+
// Add the ID to the record
|
|
71
|
+
record._id = res.data;
|
|
72
|
+
// Let the parent know
|
|
73
|
+
onCreated({ ...record });
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
76
|
// Render
|
|
@@ -50,49 +50,52 @@ export default function Create({ locales, onCreated, onError, template }) {
|
|
|
50
50
|
// Called to create the new content record
|
|
51
51
|
function create() {
|
|
52
52
|
// Send the record data to the server
|
|
53
|
-
mouth.create(`template/${type}`, record).then((
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}, (error) => {
|
|
59
|
-
if (error.code === errors.body.DATA_FIELDS) {
|
|
60
|
-
fieldErrorsSet(errorTree(error.msg));
|
|
61
|
-
}
|
|
62
|
-
else if (error.code === errors.body.DB_DUPLICATE) {
|
|
63
|
-
fieldErrorsSet({ locale: 'Already used' });
|
|
64
|
-
}
|
|
65
|
-
else if (error.code === errors.TEMPLATE_CONTENT_ERROR) {
|
|
66
|
-
const oLines = { templates: [], variables: [] };
|
|
67
|
-
for (const l of error.msg) {
|
|
68
|
-
if (l[0] === 'template') {
|
|
69
|
-
oLines.templates.push(l[1]);
|
|
70
|
-
}
|
|
71
|
-
else if (l[0] === 'variable') {
|
|
72
|
-
oLines.variables.push(l[1]);
|
|
73
|
-
}
|
|
53
|
+
mouth.create(`template/${type}`, record).then((res) => {
|
|
54
|
+
// If we failed
|
|
55
|
+
if (res.error) {
|
|
56
|
+
if (res.error.code === errors.body.DATA_FIELDS) {
|
|
57
|
+
fieldErrorsSet(errorTree(res.error.msg));
|
|
74
58
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
lLines.push('The following templates are invalid: ' + oLines.templates.join(', '));
|
|
59
|
+
else if (res.error.code === errors.body.DB_DUPLICATE) {
|
|
60
|
+
fieldErrorsSet({ locale: 'Already used' });
|
|
78
61
|
}
|
|
79
|
-
if (
|
|
80
|
-
|
|
62
|
+
else if (res.error.code === errors.TEMPLATE_CONTENT_ERROR) {
|
|
63
|
+
const oLines = { templates: [], variables: [] };
|
|
64
|
+
for (const l of res.error.msg) {
|
|
65
|
+
if (l[0] === 'template') {
|
|
66
|
+
oLines.templates.push(l[1]);
|
|
67
|
+
}
|
|
68
|
+
else if (l[0] === 'variable') {
|
|
69
|
+
oLines.variables.push(l[1]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const lLines = [];
|
|
73
|
+
if (oLines.templates.length) {
|
|
74
|
+
lLines.push('The following templates are invalid: ' + oLines.templates.join(', '));
|
|
75
|
+
}
|
|
76
|
+
if (oLines.variables.length) {
|
|
77
|
+
lLines.push('The following variables are invalid: ' + oLines.variables.join(', '));
|
|
78
|
+
}
|
|
79
|
+
// Show the errors
|
|
80
|
+
if (onError) {
|
|
81
|
+
onError({ code: 0, msg: lLines.join('\n') });
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new Error(JSON.stringify(res.error));
|
|
85
|
+
}
|
|
81
86
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
onError({ code: 0, msg: lLines.join('\n') });
|
|
87
|
+
else if (onError) {
|
|
88
|
+
onError(res.error);
|
|
85
89
|
}
|
|
86
90
|
else {
|
|
87
|
-
throw new Error(JSON.stringify(error));
|
|
91
|
+
throw new Error(JSON.stringify(res.error));
|
|
88
92
|
}
|
|
93
|
+
return;
|
|
89
94
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
throw new Error(JSON.stringify(error));
|
|
95
|
-
}
|
|
95
|
+
// Add the type and ID
|
|
96
|
+
const oRecord = { ...record, type, _id: res.data };
|
|
97
|
+
// Tell the parent about the new record
|
|
98
|
+
onCreated(oRecord);
|
|
96
99
|
});
|
|
97
100
|
}
|
|
98
101
|
// Called when any fields in the record are changed
|
|
@@ -33,13 +33,19 @@ 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(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
mouth.create(`template/${value.type}/generate`, value).then((res) => {
|
|
37
|
+
// If we failed
|
|
38
|
+
if (res.error) {
|
|
39
|
+
if (onError) {
|
|
40
|
+
onError(res.error);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw new Error(JSON.stringify(res.error));
|
|
45
|
+
}
|
|
42
46
|
}
|
|
47
|
+
// Set the preview
|
|
48
|
+
previewSet(res.data);
|
|
43
49
|
});
|
|
44
50
|
}, [value, onError]);
|
|
45
51
|
// Render
|
|
@@ -38,40 +38,44 @@ export default function Update({ onError, onUpdated, value }) {
|
|
|
38
38
|
// Called to create the new content record
|
|
39
39
|
function update() {
|
|
40
40
|
// Send the record data to the server
|
|
41
|
-
mouth.update(`template/${value.type}`, record).then(() => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
mouth.update(`template/${value.type}`, record).then((res) => {
|
|
42
|
+
// If we failed
|
|
43
|
+
if (res.error) {
|
|
44
|
+
if (res.error.code === errors.body.DATA_FIELDS) {
|
|
45
|
+
fieldErrorsSet(errorTree(res.error.msg));
|
|
46
|
+
}
|
|
47
|
+
else if (res.error.code === errors.TEMPLATE_CONTENT_ERROR) {
|
|
48
|
+
const oLines = { templates: [], variables: [] };
|
|
49
|
+
for (const l of res.error.msg) {
|
|
50
|
+
if (l[0] === 'template') {
|
|
51
|
+
oLines.templates.push(l[1]);
|
|
52
|
+
}
|
|
53
|
+
else if (l[0] === 'variable') {
|
|
54
|
+
oLines.variables.push(l[1]);
|
|
55
|
+
}
|
|
52
56
|
}
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
const lLines = [];
|
|
58
|
+
if (oLines.templates.length) {
|
|
59
|
+
lLines.push('The following templates are invalid: ' + oLines.templates.join(', '));
|
|
60
|
+
}
|
|
61
|
+
if (oLines.variables.length) {
|
|
62
|
+
lLines.push('The following variables are invalid: ' + oLines.variables.join(', '));
|
|
63
|
+
}
|
|
64
|
+
// Show the errors
|
|
65
|
+
if (onError) {
|
|
66
|
+
onError({ code: 0, msg: lLines.join('\n') });
|
|
55
67
|
}
|
|
56
68
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
lLines.push('The following templates are invalid: ' + oLines.templates.join(', '));
|
|
60
|
-
}
|
|
61
|
-
if (oLines.variables.length) {
|
|
62
|
-
lLines.push('The following variables are invalid: ' + oLines.variables.join(', '));
|
|
69
|
+
else if (onError) {
|
|
70
|
+
onError(res.error);
|
|
63
71
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
onError({ code: 0, msg: lLines.join('\n') });
|
|
72
|
+
else {
|
|
73
|
+
throw new Error(JSON.stringify(res.error));
|
|
67
74
|
}
|
|
75
|
+
return;
|
|
68
76
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
throw new Error(JSON.stringify(error));
|
|
74
|
-
}
|
|
77
|
+
// Let the parent know it was updated
|
|
78
|
+
onUpdated({ type: value.type, ...record });
|
|
75
79
|
});
|
|
76
80
|
}
|
|
77
81
|
// Called when any fields in the record are changed
|
|
@@ -76,18 +76,26 @@ export default function Template({ locales, onChange, onError, onContent, rights
|
|
|
76
76
|
// Called to update the template
|
|
77
77
|
function update() {
|
|
78
78
|
// Create the data in the system
|
|
79
|
-
mouth.update('template', edit).then((
|
|
79
|
+
mouth.update('template', edit).then((res) => {
|
|
80
|
+
// If we failed
|
|
81
|
+
if (res.error) {
|
|
82
|
+
if (res.error.code === errors.body.DB_DUPLICATE) {
|
|
83
|
+
refName.current?.error('Duplicate');
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
if (onError) {
|
|
87
|
+
onError(res.error);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
throw new Error(JSON.stringify(res.error));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
80
95
|
// Hide the form
|
|
81
96
|
editSet(false);
|
|
82
97
|
// Let the parent know
|
|
83
98
|
onChange(edit);
|
|
84
|
-
}, (error) => {
|
|
85
|
-
if (error.code === errors.body.DB_DUPLICATE) {
|
|
86
|
-
refName.current?.error('Duplicate');
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
99
|
});
|
|
92
100
|
}
|
|
93
101
|
// View toggle
|
|
@@ -99,7 +107,7 @@ export default function Template({ locales, onChange, onError, onContent, rights
|
|
|
99
107
|
if (contents === false) {
|
|
100
108
|
mouth.read('template/contents', {
|
|
101
109
|
template: value._id
|
|
102
|
-
}).then(contentsSet);
|
|
110
|
+
}).then((res) => contentsSet(res.data));
|
|
103
111
|
}
|
|
104
112
|
viewSet(true);
|
|
105
113
|
}
|
|
@@ -42,14 +42,14 @@ export default function Templates({ onError, onSuccess }) {
|
|
|
42
42
|
useEffect(() => {
|
|
43
43
|
// If we have template read permissions
|
|
44
44
|
if (rightsTemplate.read) {
|
|
45
|
-
mouth.read('locales').then((
|
|
45
|
+
mouth.read('locales').then((res) => {
|
|
46
46
|
const oLocales = {};
|
|
47
|
-
for (const o of data) {
|
|
47
|
+
for (const o of res.data) {
|
|
48
48
|
oLocales[o._id] = o.name;
|
|
49
49
|
}
|
|
50
50
|
localesSet(oLocales);
|
|
51
51
|
});
|
|
52
|
-
mouth.read('templates').then(templatesSet);
|
|
52
|
+
mouth.read('templates').then((res) => templatesSet(res.data));
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
55
|
localesSet({});
|
package/lib/locales.js
CHANGED
|
@@ -139,28 +139,31 @@ class Locales extends Subscribe {
|
|
|
139
139
|
// Mark us as running
|
|
140
140
|
this.fetching = true;
|
|
141
141
|
// Fetch the data from the server
|
|
142
|
-
mouth.read('locales').then((
|
|
142
|
+
mouth.read('locales').then((res) => {
|
|
143
|
+
// If we failed
|
|
144
|
+
if (res.error) {
|
|
145
|
+
// If we haven't hit the limit
|
|
146
|
+
if (this.failed < 3) {
|
|
147
|
+
// Increase the failed count
|
|
148
|
+
++this.failed;
|
|
149
|
+
// Fetch again
|
|
150
|
+
this.fetch();
|
|
151
|
+
}
|
|
152
|
+
// Else, we can't keep trying, notify the user
|
|
153
|
+
else {
|
|
154
|
+
events.get('error').trigger(res.error);
|
|
155
|
+
}
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
143
158
|
// If there's data
|
|
144
|
-
if (
|
|
159
|
+
if (res.data) {
|
|
145
160
|
// Trigger all callbacks
|
|
146
|
-
this.set(
|
|
161
|
+
this.set(res.data);
|
|
147
162
|
}
|
|
148
163
|
// Finish running
|
|
149
164
|
this.fetching = false;
|
|
150
165
|
// Reset the count
|
|
151
166
|
this.failed = 0;
|
|
152
|
-
}, error => {
|
|
153
|
-
// If we haven't hit the limit
|
|
154
|
-
if (this.failed < 3) {
|
|
155
|
-
// Increase the failed count
|
|
156
|
-
++this.failed;
|
|
157
|
-
// Fetch again
|
|
158
|
-
this.fetch();
|
|
159
|
-
}
|
|
160
|
-
// Else, we can't keep trying, notify the user
|
|
161
|
-
else {
|
|
162
|
-
events.get('error').trigger(error);
|
|
163
|
-
}
|
|
164
167
|
}).finally(() => {
|
|
165
168
|
// Regardless of the outcome, we're done fetching
|
|
166
169
|
this.fetching = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouroboros/mouth-mui",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Components for use with the Mouth service",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -28,27 +28,26 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^18.14.0",
|
|
30
30
|
"@types/react": "^18.0.28",
|
|
31
|
-
"@types/uuid": "^9.0.0",
|
|
32
31
|
"tslint": "^6.1.3",
|
|
33
32
|
"tslint-config-prettier": "^1.18.0",
|
|
34
|
-
"typescript": "^
|
|
33
|
+
"typescript": "^5.9.3"
|
|
35
34
|
},
|
|
36
35
|
"dependencies": {
|
|
37
36
|
"@ouroboros/define": "^1.1.3",
|
|
38
37
|
"@ouroboros/define-mui": "^1.5.6",
|
|
39
|
-
"@ouroboros/mouth": "^2.
|
|
38
|
+
"@ouroboros/mouth": "^2.2.0",
|
|
40
39
|
"@ouroboros/react-radiobuttons-mui": "^1.1.0",
|
|
41
40
|
"@ouroboros/subscribe": "^1.3.2",
|
|
42
|
-
"@ouroboros/tools": "^0.7.
|
|
41
|
+
"@ouroboros/tools": "^0.7.3",
|
|
43
42
|
"prop-types": "^15.8.1"
|
|
44
43
|
},
|
|
45
44
|
"peerDependencies": {
|
|
46
|
-
"@emotion/react": "^11.
|
|
47
|
-
"@emotion/styled": "^11.
|
|
45
|
+
"@emotion/react": "^11.14.0",
|
|
46
|
+
"@emotion/styled": "^11.14.1",
|
|
48
47
|
"@mui/material": "^5.5.1",
|
|
49
|
-
"@ouroboros/body": "^1.
|
|
50
|
-
"@ouroboros/brain-react": "^2.3.
|
|
51
|
-
"@ouroboros/events": "^1.1.
|
|
48
|
+
"@ouroboros/body": "^1.3.0",
|
|
49
|
+
"@ouroboros/brain-react": "^2.3.3",
|
|
50
|
+
"@ouroboros/events": "^1.1.3",
|
|
52
51
|
"react": "^17.0.2 || ^18.0.0",
|
|
53
52
|
"react-dom": "^17.0.2 || ^18.0.0"
|
|
54
53
|
}
|
package/releases.md
CHANGED
|
@@ -42,7 +42,7 @@ const LocaleTree = new Tree(LocaleDef, {
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
// Types
|
|
45
|
-
import { responseErrorStruct } from '@ouroboros/body';
|
|
45
|
+
import { responseErrorStruct, responseStruct } from '@ouroboros/body';
|
|
46
46
|
export type LocalesProps = {
|
|
47
47
|
onError: (error: responseErrorStruct) => void,
|
|
48
48
|
onSuccess: (type: string) => void
|
|
@@ -72,9 +72,9 @@ export default function Locales({ onError, onSuccess }: LocalesProps) {
|
|
|
72
72
|
|
|
73
73
|
// If we have read rights
|
|
74
74
|
if(rights.read) {
|
|
75
|
-
mouth.read('locales').then(recordsSet);
|
|
75
|
+
mouth.read('locales').then((res: responseStruct) => recordsSet(res.data));
|
|
76
76
|
} else {
|
|
77
|
-
recordsSet([]);
|
|
77
|
+
recordsSet([ ]);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// If we don't have create rights
|
|
@@ -91,10 +91,26 @@ export default function Locales({ onError, onSuccess }: LocalesProps) {
|
|
|
91
91
|
return new Promise((resolve, reject) => {
|
|
92
92
|
|
|
93
93
|
// Create the new locale
|
|
94
|
-
mouth.create('locale', locale).then((
|
|
94
|
+
mouth.create('locale', locale).then((res: responseStruct) => {
|
|
95
|
+
|
|
96
|
+
// If we failed
|
|
97
|
+
if(res.error) {
|
|
98
|
+
if(res.error.code === errors.body.DB_NO_RECORD) {
|
|
99
|
+
return reject([['_id', 'Already in use']]);
|
|
100
|
+
} else if(res.error.code === errors.body.DATA_FIELDS) {
|
|
101
|
+
return reject(res.error.msg);
|
|
102
|
+
} else {
|
|
103
|
+
if(onError) {
|
|
104
|
+
onError(res.error);
|
|
105
|
+
return reject([ ]);
|
|
106
|
+
} else {
|
|
107
|
+
throw new Error(JSON.stringify(res.error));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
95
111
|
|
|
96
112
|
// If we were successful
|
|
97
|
-
if(data) {
|
|
113
|
+
if(res.data) {
|
|
98
114
|
|
|
99
115
|
// Notify the parent
|
|
100
116
|
if(onSuccess) {
|
|
@@ -114,20 +130,7 @@ export default function Locales({ onError, onSuccess }: LocalesProps) {
|
|
|
114
130
|
}
|
|
115
131
|
|
|
116
132
|
// Resolve with the form
|
|
117
|
-
resolve(data ? true : false);
|
|
118
|
-
|
|
119
|
-
}, (error: responseErrorStruct) => {
|
|
120
|
-
if(error.code === errors.body.DB_NO_RECORD) {
|
|
121
|
-
reject([['_id', 'Already in use']]);
|
|
122
|
-
} else if(error.code === errors.body.DATA_FIELDS) {
|
|
123
|
-
reject(error.msg);
|
|
124
|
-
} else {
|
|
125
|
-
if(onError) {
|
|
126
|
-
onError(error);
|
|
127
|
-
} else {
|
|
128
|
-
throw new Error(JSON.stringify(error));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
133
|
+
resolve(res.data ? true : false);
|
|
131
134
|
});
|
|
132
135
|
});
|
|
133
136
|
}
|
|
@@ -136,10 +139,19 @@ export default function Locales({ onError, onSuccess }: LocalesProps) {
|
|
|
136
139
|
function deleteClick(key: string) {
|
|
137
140
|
|
|
138
141
|
// Delete the existing locale
|
|
139
|
-
mouth.delete('locale', { _id: key }).then((
|
|
142
|
+
mouth.delete('locale', { _id: key }).then((res: responseStruct) => {
|
|
143
|
+
|
|
144
|
+
// If we failed
|
|
145
|
+
if(res.error) {
|
|
146
|
+
if(onError) {
|
|
147
|
+
return onError(res.error);
|
|
148
|
+
} else {
|
|
149
|
+
throw new Error(JSON.stringify(res.error));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
140
152
|
|
|
141
153
|
// If it was successful
|
|
142
|
-
if(data) {
|
|
154
|
+
if(res.data) {
|
|
143
155
|
|
|
144
156
|
// Notify the parent
|
|
145
157
|
if(onSuccess) {
|
|
@@ -162,12 +174,6 @@ export default function Locales({ onError, onSuccess }: LocalesProps) {
|
|
|
162
174
|
locales.set(lRecords);
|
|
163
175
|
}
|
|
164
176
|
}
|
|
165
|
-
}, (error: responseErrorStruct) => {
|
|
166
|
-
if(onError) {
|
|
167
|
-
onError(error);
|
|
168
|
-
} else {
|
|
169
|
-
throw new Error(JSON.stringify(error));
|
|
170
|
-
}
|
|
171
177
|
});
|
|
172
178
|
}
|
|
173
179
|
|
|
@@ -181,10 +187,24 @@ export default function Locales({ onError, onSuccess }: LocalesProps) {
|
|
|
181
187
|
return new Promise((resolve, reject) => {
|
|
182
188
|
|
|
183
189
|
// Update the locale on the server
|
|
184
|
-
mouth.update('locale', locale).then((
|
|
190
|
+
mouth.update('locale', locale).then((res: responseStruct) => {
|
|
191
|
+
|
|
192
|
+
// If we failed
|
|
193
|
+
if(res.error) {
|
|
194
|
+
if(res.error.code === errors.body.DATA_FIELDS) {
|
|
195
|
+
return reject(res.error.msg);
|
|
196
|
+
} else {
|
|
197
|
+
if(onError) {
|
|
198
|
+
onError(res.error);
|
|
199
|
+
return reject([ ]);
|
|
200
|
+
} else {
|
|
201
|
+
throw new Error(JSON.stringify(res.error));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
185
205
|
|
|
186
206
|
// If we were successful
|
|
187
|
-
if(data) {
|
|
207
|
+
if(res.data) {
|
|
188
208
|
|
|
189
209
|
// Notify the parent
|
|
190
210
|
if(onSuccess) {
|
|
@@ -209,18 +229,7 @@ export default function Locales({ onError, onSuccess }: LocalesProps) {
|
|
|
209
229
|
}
|
|
210
230
|
|
|
211
231
|
// Resolve with the Form
|
|
212
|
-
resolve(data);
|
|
213
|
-
|
|
214
|
-
}, (error: responseErrorStruct) => {
|
|
215
|
-
if(error.code === errors.body.DATA_FIELDS) {
|
|
216
|
-
reject(error.msg);
|
|
217
|
-
} else {
|
|
218
|
-
if(onError) {
|
|
219
|
-
onError(error);
|
|
220
|
-
} else {
|
|
221
|
-
throw new Error(JSON.stringify(error));
|
|
222
|
-
}
|
|
223
|
-
}
|
|
232
|
+
resolve(res.data);
|
|
224
233
|
});
|
|
225
234
|
});
|
|
226
235
|
}
|
|
@@ -30,7 +30,7 @@ import Variables from './Template/Variables';
|
|
|
30
30
|
const oNameNode = new Node(TemplateDef.name);
|
|
31
31
|
|
|
32
32
|
// Types
|
|
33
|
-
import { responseErrorStruct } from '@ouroboros/body';
|
|
33
|
+
import { responseErrorStruct, responseStruct } from '@ouroboros/body';
|
|
34
34
|
import { templateStruct } from './Template';
|
|
35
35
|
export interface CreateProps {
|
|
36
36
|
onCancel?: () => void,
|
|
@@ -53,7 +53,7 @@ export default function Create({ onCancel, onCreated, onError }: CreateProps) {
|
|
|
53
53
|
// State
|
|
54
54
|
const [ record, recordSet ] = useState<templateStruct>({
|
|
55
55
|
name: '',
|
|
56
|
-
variables: {}
|
|
56
|
+
variables: { }
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
// Refs
|
|
@@ -72,24 +72,28 @@ export default function Create({ onCancel, onCreated, onError }: CreateProps) {
|
|
|
72
72
|
function create() {
|
|
73
73
|
|
|
74
74
|
// Create the data in the system
|
|
75
|
-
mouth.create('template', record).then((
|
|
75
|
+
mouth.create('template', record).then((res: responseStruct) => {
|
|
76
|
+
|
|
77
|
+
// If we failed
|
|
78
|
+
if(res.error) {
|
|
79
|
+
if(res.error.code === errors.body.DB_DUPLICATE) {
|
|
80
|
+
refName.current?.error('Duplicate');
|
|
81
|
+
} else {
|
|
82
|
+
if(onError) {
|
|
83
|
+
onError(res.error);
|
|
84
|
+
return;
|
|
85
|
+
} else {
|
|
86
|
+
throw new Error(JSON.stringify(res.error));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
76
90
|
|
|
77
91
|
// Add the ID to the record
|
|
78
|
-
record._id = data;
|
|
92
|
+
record._id = res.data;
|
|
79
93
|
|
|
80
94
|
// Let the parent know
|
|
81
95
|
onCreated({ ...record });
|
|
82
|
-
}
|
|
83
|
-
if(error.code === errors.body.DB_DUPLICATE) {
|
|
84
|
-
refName.current?.error('Duplicate');
|
|
85
|
-
} else {
|
|
86
|
-
if(onError) {
|
|
87
|
-
onError(error);
|
|
88
|
-
} else {
|
|
89
|
-
throw new Error(JSON.stringify(error));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
})
|
|
96
|
+
});
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
// Render
|
|
@@ -32,7 +32,7 @@ import SMS from './SMS';
|
|
|
32
32
|
|
|
33
33
|
// Types
|
|
34
34
|
import { contentStruct, typeOption } from '../../';
|
|
35
|
-
import { responseErrorStruct } from '@ouroboros/body';
|
|
35
|
+
import { responseErrorStruct, responseStruct } from '@ouroboros/body';
|
|
36
36
|
export type TemplateContentCreateProps = {
|
|
37
37
|
locales: Record<string, string>,
|
|
38
38
|
onCreated: (content: contentStruct) => void,
|
|
@@ -55,62 +55,66 @@ export default function Create(
|
|
|
55
55
|
) {
|
|
56
56
|
|
|
57
57
|
// State
|
|
58
|
-
const [fieldErrors, fieldErrorsSet] = useState<Record<string, any>>({});
|
|
59
|
-
const [preview, previewSet] = useState(false);
|
|
60
|
-
const [record, recordSet] = useState<Omit<contentStruct, 'type'>>({
|
|
58
|
+
const [ fieldErrors, fieldErrorsSet ] = useState<Record<string, any>>({});
|
|
59
|
+
const [ preview, previewSet ] = useState(false);
|
|
60
|
+
const [ record, recordSet ] = useState<Omit<contentStruct, 'type'>>({
|
|
61
61
|
locale: Object.keys(locales)[0],
|
|
62
62
|
template,
|
|
63
63
|
subject: '',
|
|
64
64
|
text: '',
|
|
65
65
|
html: ''
|
|
66
66
|
})
|
|
67
|
-
const [type, typeSet] = useState<typeOption>('email');
|
|
67
|
+
const [ type, typeSet ] = useState<typeOption>('email');
|
|
68
68
|
|
|
69
69
|
// Called to create the new content record
|
|
70
70
|
function create() {
|
|
71
71
|
|
|
72
72
|
// Send the record data to the server
|
|
73
|
-
mouth.create(`template/${type}`, record).then((
|
|
73
|
+
mouth.create(`template/${type}`, record).then((res: responseStruct) => {
|
|
74
74
|
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
oLines.
|
|
75
|
+
// If we failed
|
|
76
|
+
if(res.error) {
|
|
77
|
+
if(res.error.code === errors.body.DATA_FIELDS) {
|
|
78
|
+
fieldErrorsSet(errorTree(res.error.msg));
|
|
79
|
+
} else if(res.error.code === errors.body.DB_DUPLICATE) {
|
|
80
|
+
fieldErrorsSet({ locale: 'Already used' });
|
|
81
|
+
} else if(res.error.code === errors.TEMPLATE_CONTENT_ERROR) {
|
|
82
|
+
const oLines: { templates: string[], variables: string[] } = { templates: [], variables: [] };
|
|
83
|
+
for(const l of res.error.msg) {
|
|
84
|
+
if(l[0] === 'template') {
|
|
85
|
+
oLines.templates.push(l[1]);
|
|
86
|
+
} else if(l[0] === 'variable') {
|
|
87
|
+
oLines.variables.push(l[1]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const lLines = [];
|
|
91
|
+
if(oLines.templates.length) {
|
|
92
|
+
lLines.push('The following templates are invalid: ' + oLines.templates.join(', '));
|
|
93
|
+
}
|
|
94
|
+
if(oLines.variables.length) {
|
|
95
|
+
lLines.push('The following variables are invalid: ' + oLines.variables.join(', '));
|
|
93
96
|
}
|
|
94
|
-
}
|
|
95
|
-
const lLines = [];
|
|
96
|
-
if(oLines.templates.length) {
|
|
97
|
-
lLines.push('The following templates are invalid: ' + oLines.templates.join(', '));
|
|
98
|
-
}
|
|
99
|
-
if(oLines.variables.length) {
|
|
100
|
-
lLines.push('The following variables are invalid: ' + oLines.variables.join(', '));
|
|
101
|
-
}
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
// Show the errors
|
|
99
|
+
if(onError) {
|
|
100
|
+
onError({ code: 0, msg: lLines.join('\n') });
|
|
101
|
+
} else {
|
|
102
|
+
throw new Error(JSON.stringify(res.error));
|
|
103
|
+
}
|
|
104
|
+
} else if(onError) {
|
|
105
|
+
onError(res.error);
|
|
106
106
|
} else {
|
|
107
|
-
throw new Error(JSON.stringify(error));
|
|
107
|
+
throw new Error(JSON.stringify(res.error));
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
onError(error);
|
|
111
|
-
} else {
|
|
112
|
-
throw new Error(JSON.stringify(error));
|
|
109
|
+
return;
|
|
113
110
|
}
|
|
111
|
+
|
|
112
|
+
// Add the type and ID
|
|
113
|
+
const oRecord = { ...record, type, _id: res.data }
|
|
114
|
+
|
|
115
|
+
// Tell the parent about the new record
|
|
116
|
+
onCreated(oRecord);
|
|
117
|
+
|
|
114
118
|
});
|
|
115
119
|
}
|
|
116
120
|
|
|
@@ -27,7 +27,7 @@ import SMS from './SMS';
|
|
|
27
27
|
|
|
28
28
|
// Types
|
|
29
29
|
import { contentStruct } from '../..';
|
|
30
|
-
import { responseErrorStruct } from '@ouroboros/body';
|
|
30
|
+
import { responseErrorStruct, responseStruct } from '@ouroboros/body';
|
|
31
31
|
export type PreviewProps = {
|
|
32
32
|
onClose: () => void,
|
|
33
33
|
onError?: (error: responseErrorStruct) => void,
|
|
@@ -54,12 +54,21 @@ export default function Preview({ onClose, onError, value }: PreviewProps) {
|
|
|
54
54
|
mouth.create(
|
|
55
55
|
`template/${value.type}/generate`,
|
|
56
56
|
value
|
|
57
|
-
).then(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
).then((res: responseStruct) => {
|
|
58
|
+
|
|
59
|
+
// If we failed
|
|
60
|
+
if(res.error) {
|
|
61
|
+
if(onError) {
|
|
62
|
+
onError(res.error);
|
|
63
|
+
return;
|
|
64
|
+
} else {
|
|
65
|
+
throw new Error(JSON.stringify(res.error));
|
|
66
|
+
}
|
|
62
67
|
}
|
|
68
|
+
|
|
69
|
+
// Set the preview
|
|
70
|
+
previewSet(res.data);
|
|
71
|
+
|
|
63
72
|
})
|
|
64
73
|
}, [ value, onError ]);
|
|
65
74
|
|
|
@@ -26,7 +26,7 @@ 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 = {
|
|
@@ -56,37 +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);
|
|
87
|
-
} else {
|
|
88
|
-
throw new Error(JSON.stringify(error));
|
|
91
|
+
return;
|
|
89
92
|
}
|
|
93
|
+
|
|
94
|
+
// Let the parent know it was updated
|
|
95
|
+
onUpdated({type: value.type, ...record});
|
|
90
96
|
});
|
|
91
97
|
}
|
|
92
98
|
|
|
@@ -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,
|
|
@@ -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
|
}
|
|
@@ -26,7 +26,7 @@ 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
31
|
onError?: (error: responseErrorStruct) => void,
|
|
32
32
|
onSuccess?: (type: string) => void
|
|
@@ -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([]);
|
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
|
/**
|