@ouroboros/mouth-mui 1.3.2 → 2.1.1
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.d.ts +1 -3
- package/lib/components/pages/Locales.js +32 -23
- package/lib/components/pages/Templates/Create.d.ts +1 -1
- package/lib/components/pages/Templates/Create.js +11 -14
- package/lib/components/pages/Templates/Template/Content/Create/Email.d.ts +1 -1
- package/lib/components/pages/Templates/Template/Content/Create/Email.js +6 -10
- package/lib/components/pages/Templates/Template/Content/Create/SMS.d.ts +1 -1
- package/lib/components/pages/Templates/Template/Content/Create/SMS.js +4 -6
- package/lib/components/pages/Templates/Template/Content/Create/index.d.ts +1 -3
- package/lib/components/pages/Templates/Template/Content/Create/index.js +14 -20
- package/lib/components/pages/Templates/Template/Content/Preview/Email.d.ts +1 -3
- package/lib/components/pages/Templates/Template/Content/Preview/Email.js +6 -7
- package/lib/components/pages/Templates/Template/Content/Preview/SMS.d.ts +1 -3
- package/lib/components/pages/Templates/Template/Content/Preview/SMS.js +3 -4
- package/lib/components/pages/Templates/Template/Content/Preview/index.d.ts +1 -3
- package/lib/components/pages/Templates/Template/Content/Preview/index.js +3 -6
- package/lib/components/pages/Templates/Template/Content/Update/Email.d.ts +1 -1
- package/lib/components/pages/Templates/Template/Content/Update/Email.js +6 -11
- package/lib/components/pages/Templates/Template/Content/Update/SMS.d.ts +1 -1
- package/lib/components/pages/Templates/Template/Content/Update/SMS.js +4 -6
- package/lib/components/pages/Templates/Template/Content/Update/index.d.ts +1 -3
- package/lib/components/pages/Templates/Template/Content/Update/index.js +17 -23
- package/lib/components/pages/Templates/Template/Content/View/Email.d.ts +1 -3
- package/lib/components/pages/Templates/Template/Content/View/Email.js +6 -7
- package/lib/components/pages/Templates/Template/Content/View/SMS.d.ts +1 -3
- package/lib/components/pages/Templates/Template/Content/View/SMS.js +3 -4
- package/lib/components/pages/Templates/Template/Content/View/index.d.ts +1 -3
- package/lib/components/pages/Templates/Template/Content/View/index.js +5 -6
- package/lib/components/pages/Templates/Template/Variables.d.ts +1 -1
- package/lib/components/pages/Templates/Template/Variables.js +6 -7
- package/lib/components/pages/Templates/Template/index.d.ts +1 -3
- package/lib/components/pages/Templates/Template/index.js +27 -45
- package/lib/components/pages/Templates/index.d.ts +1 -3
- package/lib/components/pages/Templates/index.js +9 -21
- package/lib/shared.d.ts +12 -0
- package/lib/shared.js +25 -0
- package/package.json +7 -8
- package/src/components/pages/Locales.tsx +40 -27
- package/src/components/pages/Templates/Create.tsx +12 -15
- package/src/components/pages/Templates/Template/Content/Create/Email.tsx +15 -19
- package/src/components/pages/Templates/Template/Content/Create/SMS.tsx +7 -9
- package/src/components/pages/Templates/Template/Content/Create/index.tsx +15 -23
- package/src/components/pages/Templates/Template/Content/Preview/Email.tsx +7 -9
- package/src/components/pages/Templates/Template/Content/Preview/SMS.tsx +3 -9
- package/src/components/pages/Templates/Template/Content/Preview/index.tsx +2 -9
- package/src/components/pages/Templates/Template/Content/Update/Email.tsx +15 -18
- package/src/components/pages/Templates/Template/Content/Update/SMS.tsx +7 -9
- package/src/components/pages/Templates/Template/Content/Update/index.tsx +19 -29
- package/src/components/pages/Templates/Template/Content/View/Email.tsx +6 -8
- package/src/components/pages/Templates/Template/Content/View/SMS.tsx +3 -5
- package/src/components/pages/Templates/Template/Content/View/index.tsx +9 -12
- package/src/components/pages/Templates/Template/Variables.tsx +6 -7
- package/src/components/pages/Templates/Template/index.tsx +37 -59
- package/src/components/pages/Templates/index.tsx +19 -31
- package/src/shared.ts +29 -0
- package/ouroboros-mouth-mui-1.3.2.tgz +0 -0
- package/src/types/xhr2.d.ts +0 -3
|
@@ -10,7 +10,6 @@ import PropTypes from 'prop-types';
|
|
|
10
10
|
import React from 'react';
|
|
11
11
|
import { responseErrorStruct } from '@ouroboros/body';
|
|
12
12
|
export type LocalesProps = {
|
|
13
|
-
mobile: boolean;
|
|
14
13
|
onError: (error: responseErrorStruct) => void;
|
|
15
14
|
onSuccess: (type: string) => void;
|
|
16
15
|
};
|
|
@@ -24,10 +23,9 @@ export type LocalesProps = {
|
|
|
24
23
|
* @param Object props Properties passed to the component
|
|
25
24
|
* @returns React.Component
|
|
26
25
|
*/
|
|
27
|
-
declare function Locales(
|
|
26
|
+
declare function Locales({ onError, onSuccess }: LocalesProps): React.JSX.Element;
|
|
28
27
|
declare namespace Locales {
|
|
29
28
|
var propTypes: {
|
|
30
|
-
mobile: PropTypes.Validator<boolean>;
|
|
31
29
|
onError: PropTypes.Validator<(...args: any[]) => any>;
|
|
32
30
|
onSuccess: PropTypes.Validator<(...args: any[]) => any>;
|
|
33
31
|
};
|
|
@@ -8,11 +8,10 @@
|
|
|
8
8
|
*/
|
|
9
9
|
// Ouroboros modules
|
|
10
10
|
import { useRights } from '@ouroboros/brain-react';
|
|
11
|
-
import clone from '@ouroboros/clone';
|
|
12
11
|
import { Tree } from '@ouroboros/define';
|
|
13
12
|
import { Form, Results } from '@ouroboros/define-mui';
|
|
14
13
|
import mouth, { errors } from '@ouroboros/mouth';
|
|
15
|
-
import LocaleDef from '@ouroboros/mouth/
|
|
14
|
+
import LocaleDef from '@ouroboros/mouth/define/locale.json';
|
|
16
15
|
import { afindi, merge } from '@ouroboros/tools';
|
|
17
16
|
// NPM modules
|
|
18
17
|
import PropTypes from 'prop-types';
|
|
@@ -25,7 +24,16 @@ import Tooltip from '@mui/material/Tooltip';
|
|
|
25
24
|
// Local modules
|
|
26
25
|
import locales from '../../locales';
|
|
27
26
|
// Generate the user Tree
|
|
28
|
-
const LocaleTree = new Tree(LocaleDef
|
|
27
|
+
const LocaleTree = new Tree(LocaleDef, {
|
|
28
|
+
__name__: 'record',
|
|
29
|
+
__ui__: {
|
|
30
|
+
__copyPrimary__: false,
|
|
31
|
+
__create__: ['_id', 'name'],
|
|
32
|
+
__results__: ['_id', 'name'],
|
|
33
|
+
__update__: ['name']
|
|
34
|
+
},
|
|
35
|
+
_id: { __ui__: { __title__: 'ISO-639 - ISO-3166' } }
|
|
36
|
+
});
|
|
29
37
|
/**
|
|
30
38
|
* Locales
|
|
31
39
|
*
|
|
@@ -36,7 +44,7 @@ const LocaleTree = new Tree(LocaleDef);
|
|
|
36
44
|
* @param Object props Properties passed to the component
|
|
37
45
|
* @returns React.Component
|
|
38
46
|
*/
|
|
39
|
-
export default function Locales(
|
|
47
|
+
export default function Locales({ onError, onSuccess }) {
|
|
40
48
|
// State
|
|
41
49
|
const [create, createSet] = useState(false);
|
|
42
50
|
const [records, recordsSet] = useState([]);
|
|
@@ -65,13 +73,12 @@ export default function Locales(props) {
|
|
|
65
73
|
// If we were successful
|
|
66
74
|
if (data) {
|
|
67
75
|
// Notify the parent
|
|
68
|
-
|
|
76
|
+
onSuccess('create');
|
|
69
77
|
// Close the create form
|
|
70
78
|
createSet(false);
|
|
71
|
-
// Clone the records, add the new one to the start, and set
|
|
72
|
-
// records
|
|
73
|
-
const lRecords =
|
|
74
|
-
lRecords.unshift(locale);
|
|
79
|
+
// Clone the records, add the new one to the start, and set
|
|
80
|
+
// the new records
|
|
81
|
+
const lRecords = [locale, ...records];
|
|
75
82
|
recordsSet(lRecords);
|
|
76
83
|
// Send the clone to the locales
|
|
77
84
|
locales.set(lRecords);
|
|
@@ -86,8 +93,8 @@ export default function Locales(props) {
|
|
|
86
93
|
reject(error.msg);
|
|
87
94
|
}
|
|
88
95
|
else {
|
|
89
|
-
if (
|
|
90
|
-
|
|
96
|
+
if (onError) {
|
|
97
|
+
onError(error);
|
|
91
98
|
}
|
|
92
99
|
else {
|
|
93
100
|
throw new Error(JSON.stringify(error));
|
|
@@ -103,13 +110,14 @@ export default function Locales(props) {
|
|
|
103
110
|
// If it was successful
|
|
104
111
|
if (data) {
|
|
105
112
|
// Notify the parent
|
|
106
|
-
|
|
113
|
+
onSuccess('delete');
|
|
107
114
|
// Look for the record
|
|
108
115
|
const i = afindi(records, '_id', key);
|
|
109
116
|
// If it exists
|
|
110
117
|
if (i > -1) {
|
|
111
|
-
// Clone the records, delete the index, and set the new
|
|
112
|
-
|
|
118
|
+
// Clone the records, delete the index, and set the new
|
|
119
|
+
// records
|
|
120
|
+
const lRecords = [...records];
|
|
113
121
|
lRecords.splice(i, 1);
|
|
114
122
|
recordsSet(lRecords);
|
|
115
123
|
// Send the clone to the locales
|
|
@@ -117,8 +125,8 @@ export default function Locales(props) {
|
|
|
117
125
|
}
|
|
118
126
|
}
|
|
119
127
|
}, (error) => {
|
|
120
|
-
if (
|
|
121
|
-
|
|
128
|
+
if (onError) {
|
|
129
|
+
onError(error);
|
|
122
130
|
}
|
|
123
131
|
else {
|
|
124
132
|
throw new Error(JSON.stringify(error));
|
|
@@ -136,13 +144,14 @@ export default function Locales(props) {
|
|
|
136
144
|
// If we were successful
|
|
137
145
|
if (data) {
|
|
138
146
|
// Notify the parent
|
|
139
|
-
|
|
147
|
+
onSuccess('update');
|
|
140
148
|
// Look for the record
|
|
141
149
|
const i = afindi(records, '_id', key);
|
|
142
150
|
// If it exists
|
|
143
151
|
if (i > -1) {
|
|
144
|
-
// Clone the records, update the index, and set the new
|
|
145
|
-
|
|
152
|
+
// Clone the records, update the index, and set the new
|
|
153
|
+
// records
|
|
154
|
+
const lRecords = [...records];
|
|
146
155
|
merge(lRecords[i], locale);
|
|
147
156
|
recordsSet(lRecords);
|
|
148
157
|
// Send the clone to the locales
|
|
@@ -156,8 +165,8 @@ export default function Locales(props) {
|
|
|
156
165
|
reject(error.msg);
|
|
157
166
|
}
|
|
158
167
|
else {
|
|
159
|
-
if (
|
|
160
|
-
|
|
168
|
+
if (onError) {
|
|
169
|
+
onError(error);
|
|
161
170
|
}
|
|
162
171
|
else {
|
|
163
172
|
throw new Error(JSON.stringify(error));
|
|
@@ -174,7 +183,8 @@ export default function Locales(props) {
|
|
|
174
183
|
React.createElement(Box, { className: "flexStatic" },
|
|
175
184
|
React.createElement(Tooltip, { title: "Create new Locale", className: "page_action", onClick: () => createSet(b => !b) },
|
|
176
185
|
React.createElement(IconButton, null,
|
|
177
|
-
React.createElement("i", { className: 'fa-solid fa-plus' +
|
|
186
|
+
React.createElement("i", { className: 'fa-solid fa-plus' +
|
|
187
|
+
(create ? ' open' : '') }))))),
|
|
178
188
|
create &&
|
|
179
189
|
React.createElement(Paper, { className: "padding" },
|
|
180
190
|
React.createElement(Form, { onCancel: () => createSet(false), onSubmit: createSubmit, tree: LocaleTree, type: "create" })),
|
|
@@ -182,7 +192,6 @@ export default function Locales(props) {
|
|
|
182
192
|
}
|
|
183
193
|
// Valid props
|
|
184
194
|
Locales.propTypes = {
|
|
185
|
-
mobile: PropTypes.bool.isRequired,
|
|
186
195
|
onError: PropTypes.func.isRequired,
|
|
187
196
|
onSuccess: PropTypes.func.isRequired
|
|
188
197
|
};
|
|
@@ -25,7 +25,7 @@ export interface CreateProps {
|
|
|
25
25
|
* @param Object props Properties passed to the component
|
|
26
26
|
* @returns React.Component
|
|
27
27
|
*/
|
|
28
|
-
declare function Create(
|
|
28
|
+
declare function Create({ onCancel, onCreated, onError }: CreateProps): React.JSX.Element;
|
|
29
29
|
declare namespace Create {
|
|
30
30
|
var propTypes: {
|
|
31
31
|
onCancel: PropTypes.Requireable<(...args: any[]) => any>;
|
|
@@ -7,11 +7,10 @@
|
|
|
7
7
|
* @created 2023-01-20
|
|
8
8
|
*/
|
|
9
9
|
// Ouroboros modules
|
|
10
|
-
import clone from '@ouroboros/clone';
|
|
11
10
|
import { Node } from '@ouroboros/define';
|
|
12
11
|
import { DefineNode } from '@ouroboros/define-mui';
|
|
13
12
|
import mouth, { errors } from '@ouroboros/mouth';
|
|
14
|
-
import TemplateDef from '@ouroboros/mouth/
|
|
13
|
+
import TemplateDef from '@ouroboros/mouth/define/template.json';
|
|
15
14
|
// NPM modules
|
|
16
15
|
import PropTypes from 'prop-types';
|
|
17
16
|
import React, { useRef, useState } from 'react';
|
|
@@ -34,7 +33,7 @@ const oNameNode = new Node(TemplateDef.name);
|
|
|
34
33
|
* @param Object props Properties passed to the component
|
|
35
34
|
* @returns React.Component
|
|
36
35
|
*/
|
|
37
|
-
export default function Create(
|
|
36
|
+
export default function Create({ onCancel, onCreated, onError }) {
|
|
38
37
|
// State
|
|
39
38
|
const [record, recordSet] = useState({
|
|
40
39
|
name: '',
|
|
@@ -43,12 +42,10 @@ export default function Create(props) {
|
|
|
43
42
|
// Refs
|
|
44
43
|
const refName = useRef(null);
|
|
45
44
|
// Called when record changes
|
|
46
|
-
function change(field,
|
|
45
|
+
function change(field, val) {
|
|
47
46
|
// Set the new record
|
|
48
47
|
recordSet((o) => {
|
|
49
|
-
|
|
50
|
-
oRecord[field] = value;
|
|
51
|
-
return oRecord;
|
|
48
|
+
return { ...o, [field]: val };
|
|
52
49
|
});
|
|
53
50
|
}
|
|
54
51
|
// Called to create the template
|
|
@@ -58,14 +55,14 @@ export default function Create(props) {
|
|
|
58
55
|
// Add the ID to the record
|
|
59
56
|
record._id = data;
|
|
60
57
|
// Let the parent know
|
|
61
|
-
|
|
58
|
+
onCreated({ ...record });
|
|
62
59
|
}, (error) => {
|
|
63
60
|
if (error.code === errors.body.DB_DUPLICATE) {
|
|
64
61
|
refName.current?.error('Duplicate');
|
|
65
62
|
}
|
|
66
63
|
else {
|
|
67
|
-
if (
|
|
68
|
-
|
|
64
|
+
if (onError) {
|
|
65
|
+
onError(error);
|
|
69
66
|
}
|
|
70
67
|
else {
|
|
71
68
|
throw new Error(JSON.stringify(error));
|
|
@@ -80,14 +77,14 @@ export default function Create(props) {
|
|
|
80
77
|
React.createElement(Grid, { item: true, lg: 6, md: 12, className: "field" },
|
|
81
78
|
React.createElement(Typography, null,
|
|
82
79
|
React.createElement("strong", null, "Name")),
|
|
83
|
-
React.createElement(DefineNode, { label: "none", name: "name", node: oNameNode, onChange:
|
|
80
|
+
React.createElement(DefineNode, { label: "none", name: "name", node: oNameNode, onChange: val => change('name', val), onEnterPressed: create, ref: refName, type: "create", value: record.name || null })),
|
|
84
81
|
React.createElement(Grid, { item: true, lg: 6, md: 12 },
|
|
85
82
|
React.createElement(Typography, null,
|
|
86
83
|
React.createElement("strong", null, "Variables")),
|
|
87
|
-
React.createElement(Variables, { onChange:
|
|
84
|
+
React.createElement(Variables, { onChange: val => change('variables', val), value: record.variables || {} })),
|
|
88
85
|
React.createElement(Grid, { item: true, xs: 12, className: "actions" },
|
|
89
|
-
|
|
90
|
-
React.createElement(Button, { variant: "contained", color: "secondary", onClick:
|
|
86
|
+
onCancel &&
|
|
87
|
+
React.createElement(Button, { variant: "contained", color: "secondary", onClick: onCancel }, "Cancel"),
|
|
91
88
|
React.createElement(Button, { variant: "contained", color: "primary", onClick: create }, "Create Template")))));
|
|
92
89
|
}
|
|
93
90
|
// Valid props
|
|
@@ -24,7 +24,7 @@ export type EmailProps = {
|
|
|
24
24
|
* @param Object props Properties passed to the component
|
|
25
25
|
* @returns React.Component
|
|
26
26
|
*/
|
|
27
|
-
declare function Email(
|
|
27
|
+
declare function Email({ errors, onChanged, value }: EmailProps): React.JSX.Element;
|
|
28
28
|
declare namespace Email {
|
|
29
29
|
var propTypes: {
|
|
30
30
|
errors: PropTypes.Validator<object>;
|
|
@@ -7,18 +7,14 @@
|
|
|
7
7
|
* @created 2023-01-22
|
|
8
8
|
*/
|
|
9
9
|
// Ouroboros modules
|
|
10
|
-
import { Node } from '@ouroboros/define';
|
|
11
10
|
import { DefineNode } from '@ouroboros/define-mui';
|
|
12
|
-
import TemplateEmail from '@ouroboros/mouth/definitions/template_email.json';
|
|
13
11
|
// NPM modules
|
|
14
12
|
import PropTypes from 'prop-types';
|
|
15
13
|
import React from 'react';
|
|
16
14
|
// Material UI
|
|
17
15
|
import Grid from '@mui/material/Grid';
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
const oTextNode = new Node(TemplateEmail.text);
|
|
21
|
-
const oHtmlNode = new Node(TemplateEmail.html);
|
|
16
|
+
// Import the shared types
|
|
17
|
+
import { EmailTree } from '../../../../../../shared';
|
|
22
18
|
/**
|
|
23
19
|
* Email
|
|
24
20
|
*
|
|
@@ -29,15 +25,15 @@ const oHtmlNode = new Node(TemplateEmail.html);
|
|
|
29
25
|
* @param Object props Properties passed to the component
|
|
30
26
|
* @returns React.Component
|
|
31
27
|
*/
|
|
32
|
-
export default function Email(
|
|
28
|
+
export default function Email({ errors, onChanged, value }) {
|
|
33
29
|
// Render
|
|
34
30
|
return (React.createElement(Grid, { container: true, className: "content_create_email", spacing: 1 },
|
|
35
31
|
React.createElement(Grid, { item: true, xs: 12, className: "field" },
|
|
36
|
-
React.createElement(DefineNode, { error:
|
|
32
|
+
React.createElement(DefineNode, { error: errors.subject || false, label: "placeholder", name: "subject", node: EmailTree.get('subject'), onChange: val => onChanged('subject', val), type: "create", value: value.subject })),
|
|
37
33
|
React.createElement(Grid, { item: true, xs: 12, lg: 6, className: "field" },
|
|
38
|
-
React.createElement(DefineNode, { error:
|
|
34
|
+
React.createElement(DefineNode, { error: errors.text || false, label: "placeholder", name: "text", node: EmailTree.get('text'), onChange: val => onChanged('text', val), type: "create", value: value.text })),
|
|
39
35
|
React.createElement(Grid, { item: true, xs: 12, lg: 6, className: "field" },
|
|
40
|
-
React.createElement(DefineNode, { error:
|
|
36
|
+
React.createElement(DefineNode, { error: errors.html || false, label: "placeholder", name: "html", node: EmailTree.get('html'), onChange: val => onChanged('html', val), type: "create", value: value.html }))));
|
|
41
37
|
}
|
|
42
38
|
// Valid props
|
|
43
39
|
Email.propTypes = {
|
|
@@ -24,7 +24,7 @@ export type SMSProps = {
|
|
|
24
24
|
* @param Object props Properties passed to the component
|
|
25
25
|
* @returns React.Component
|
|
26
26
|
*/
|
|
27
|
-
declare function SMS(
|
|
27
|
+
declare function SMS({ errors, onChanged, value }: SMSProps): React.JSX.Element;
|
|
28
28
|
declare namespace SMS {
|
|
29
29
|
var propTypes: {
|
|
30
30
|
errors: PropTypes.Validator<object>;
|
|
@@ -7,16 +7,14 @@
|
|
|
7
7
|
* @created 2023-01-22
|
|
8
8
|
*/
|
|
9
9
|
// Ouroboros modules
|
|
10
|
-
import { Node } from '@ouroboros/define';
|
|
11
10
|
import { DefineNode } from '@ouroboros/define-mui';
|
|
12
|
-
import TemplateSMS from '@ouroboros/mouth/definitions/template_sms.json';
|
|
13
11
|
// NPM modules
|
|
14
12
|
import PropTypes from 'prop-types';
|
|
15
13
|
import React from 'react';
|
|
16
14
|
// Material UI
|
|
17
15
|
import Box from '@mui/material/Box';
|
|
18
|
-
//
|
|
19
|
-
|
|
16
|
+
// Import the shared types
|
|
17
|
+
import { SmsTree } from '../../../../../../shared';
|
|
20
18
|
/**
|
|
21
19
|
* SMS
|
|
22
20
|
*
|
|
@@ -27,10 +25,10 @@ const oContentNode = new Node(TemplateSMS.content);
|
|
|
27
25
|
* @param Object props Properties passed to the component
|
|
28
26
|
* @returns React.Component
|
|
29
27
|
*/
|
|
30
|
-
export default function SMS(
|
|
28
|
+
export default function SMS({ errors, onChanged, value }) {
|
|
31
29
|
// Render
|
|
32
30
|
return (React.createElement(Box, { className: "content_create_sms field" },
|
|
33
|
-
React.createElement(DefineNode, { error:
|
|
31
|
+
React.createElement(DefineNode, { error: errors.content || false, label: "placeholder", name: "content", node: SmsTree.get('content'), onChange: val => onChanged('content', val), type: "create", value: value.content })));
|
|
34
32
|
}
|
|
35
33
|
// Valid props
|
|
36
34
|
SMS.propTypes = {
|
|
@@ -12,7 +12,6 @@ import { contentStruct } from '../../';
|
|
|
12
12
|
import { responseErrorStruct } from '@ouroboros/body';
|
|
13
13
|
export type TemplateContentCreateProps = {
|
|
14
14
|
locales: Record<string, string>;
|
|
15
|
-
mobile: boolean;
|
|
16
15
|
onCreated: (content: contentStruct) => void;
|
|
17
16
|
onError: (error: responseErrorStruct) => void;
|
|
18
17
|
template: string;
|
|
@@ -27,13 +26,12 @@ export type TemplateContentCreateProps = {
|
|
|
27
26
|
* @param Object props Properties passed to the component
|
|
28
27
|
* @returns React.Component
|
|
29
28
|
*/
|
|
30
|
-
declare function Create(
|
|
29
|
+
declare function Create({ locales, onCreated, onError, template }: TemplateContentCreateProps): React.JSX.Element;
|
|
31
30
|
declare namespace Create {
|
|
32
31
|
var propTypes: {
|
|
33
32
|
locales: PropTypes.Validator<{
|
|
34
33
|
[x: string]: string | null | undefined;
|
|
35
34
|
}>;
|
|
36
|
-
mobile: PropTypes.Validator<boolean>;
|
|
37
35
|
onCreated: PropTypes.Validator<(...args: any[]) => any>;
|
|
38
36
|
onError: PropTypes.Requireable<(...args: any[]) => any>;
|
|
39
37
|
template: PropTypes.Validator<string>;
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* @created 2023-01-22
|
|
8
8
|
*/
|
|
9
9
|
// Ouroboros modules
|
|
10
|
-
import clone from '@ouroboros/clone';
|
|
11
10
|
import { errorTree } from '@ouroboros/define-mui';
|
|
12
11
|
import mouth, { errors } from '@ouroboros/mouth';
|
|
13
12
|
import RadioButtons from '@ouroboros/react-radiobuttons-mui';
|
|
@@ -36,13 +35,13 @@ import SMS from './SMS';
|
|
|
36
35
|
* @param Object props Properties passed to the component
|
|
37
36
|
* @returns React.Component
|
|
38
37
|
*/
|
|
39
|
-
export default function Create(
|
|
38
|
+
export default function Create({ locales, onCreated, onError, template }) {
|
|
40
39
|
// State
|
|
41
40
|
const [fieldErrors, fieldErrorsSet] = useState({});
|
|
42
41
|
const [preview, previewSet] = useState(false);
|
|
43
42
|
const [record, recordSet] = useState({
|
|
44
|
-
locale: Object.keys(
|
|
45
|
-
template
|
|
43
|
+
locale: Object.keys(locales)[0],
|
|
44
|
+
template,
|
|
46
45
|
subject: '',
|
|
47
46
|
text: '',
|
|
48
47
|
html: ''
|
|
@@ -55,7 +54,7 @@ export default function Create(props) {
|
|
|
55
54
|
// Add the type and ID
|
|
56
55
|
const oRecord = { ...record, type, _id: data };
|
|
57
56
|
// Tell the parent about the new record
|
|
58
|
-
|
|
57
|
+
onCreated(oRecord);
|
|
59
58
|
}, (error) => {
|
|
60
59
|
if (error.code === errors.body.DATA_FIELDS) {
|
|
61
60
|
fieldErrorsSet(errorTree(error.msg));
|
|
@@ -81,12 +80,12 @@ export default function Create(props) {
|
|
|
81
80
|
lLines.push('The following variables are invalid: ' + oLines.variables.join(', '));
|
|
82
81
|
}
|
|
83
82
|
// Show the errors
|
|
84
|
-
if (
|
|
85
|
-
|
|
83
|
+
if (onError) {
|
|
84
|
+
onError({ code: 0, msg: lLines.join('\n') });
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
else {
|
|
89
|
-
|
|
88
|
+
onError(error);
|
|
90
89
|
}
|
|
91
90
|
});
|
|
92
91
|
}
|
|
@@ -94,21 +93,17 @@ export default function Create(props) {
|
|
|
94
93
|
function recordChanged(field, value) {
|
|
95
94
|
// Clear error
|
|
96
95
|
if (field in fieldErrors) {
|
|
97
|
-
const oErrors =
|
|
96
|
+
const oErrors = { ...fieldErrors };
|
|
98
97
|
delete oErrors[field];
|
|
99
98
|
fieldErrorsSet(oErrors);
|
|
100
99
|
}
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
// Update the field
|
|
104
|
-
oRecord[field] = value;
|
|
105
|
-
// Store the new record
|
|
106
|
-
recordSet(oRecord);
|
|
100
|
+
// Set the new record
|
|
101
|
+
recordSet(o => { return { ...o, [field]: value }; });
|
|
107
102
|
}
|
|
108
103
|
// Called when the type is changed
|
|
109
104
|
function typeChanged(value) {
|
|
110
105
|
// Clone the current record
|
|
111
|
-
const oRecord =
|
|
106
|
+
const oRecord = { ...record };
|
|
112
107
|
// If the new type is email
|
|
113
108
|
if (value === 'email') {
|
|
114
109
|
// Store the content in the text field and remove it
|
|
@@ -147,7 +142,7 @@ export default function Create(props) {
|
|
|
147
142
|
React.createElement(Grid, { item: true, xs: 12, md: 6, className: "field" },
|
|
148
143
|
React.createElement(FormControl, { variant: "outlined", error: 'locale' in fieldErrors ? true : false },
|
|
149
144
|
React.createElement(InputLabel, { id: "content_create_locale" }, "Locale"),
|
|
150
|
-
React.createElement(Select, { label: "Locale", labelId: "content_create_locale", native: true, onChange: ev => recordChanged('locale', ev.target.value), value: record.locale }, omap(
|
|
145
|
+
React.createElement(Select, { label: "Locale", labelId: "content_create_locale", native: true, onChange: ev => recordChanged('locale', ev.target.value), value: record.locale }, omap(locales, (v, k) => React.createElement("option", { key: k, value: k }, v))),
|
|
151
146
|
fieldErrors.locale &&
|
|
152
147
|
React.createElement(FormHelperText, null, fieldErrors.locale))),
|
|
153
148
|
React.createElement(Grid, { item: true, xs: 12 }, (type === 'email' &&
|
|
@@ -157,12 +152,12 @@ export default function Create(props) {
|
|
|
157
152
|
React.createElement(Button, { color: "info", onClick: () => previewSet(true), variant: "contained" }, "Preview"),
|
|
158
153
|
React.createElement(Button, { color: "primary", onClick: create, variant: "contained" }, "Add Content"),
|
|
159
154
|
preview &&
|
|
160
|
-
React.createElement(Preview, {
|
|
155
|
+
React.createElement(Preview, { onClose: () => previewSet(false), onError: (error) => {
|
|
161
156
|
if (error.code === errors.body.DATA_FIELDS) {
|
|
162
157
|
fieldErrorsSet(errorTree(error.msg));
|
|
163
158
|
}
|
|
164
159
|
else {
|
|
165
|
-
|
|
160
|
+
onError(error);
|
|
166
161
|
}
|
|
167
162
|
previewSet(false);
|
|
168
163
|
}, value: { ...record, type } }))));
|
|
@@ -170,7 +165,6 @@ export default function Create(props) {
|
|
|
170
165
|
// Valid props
|
|
171
166
|
Create.propTypes = {
|
|
172
167
|
locales: PropTypes.objectOf(PropTypes.string).isRequired,
|
|
173
|
-
mobile: PropTypes.bool.isRequired,
|
|
174
168
|
onCreated: PropTypes.func.isRequired,
|
|
175
169
|
onError: PropTypes.func,
|
|
176
170
|
template: PropTypes.string.isRequired
|
|
@@ -10,7 +10,6 @@ import PropTypes from 'prop-types';
|
|
|
10
10
|
import React from 'react';
|
|
11
11
|
import { contentStruct } from '../..';
|
|
12
12
|
export type EmailProps = {
|
|
13
|
-
mobile: boolean;
|
|
14
13
|
value: contentStruct;
|
|
15
14
|
};
|
|
16
15
|
/**
|
|
@@ -23,10 +22,9 @@ export type EmailProps = {
|
|
|
23
22
|
* @param Object props Properties passed to the component
|
|
24
23
|
* @returns React.Component
|
|
25
24
|
*/
|
|
26
|
-
declare function Email(
|
|
25
|
+
declare function Email({ value }: EmailProps): React.JSX.Element;
|
|
27
26
|
declare namespace Email {
|
|
28
27
|
var propTypes: {
|
|
29
|
-
mobile: PropTypes.Validator<boolean>;
|
|
30
28
|
value: PropTypes.Requireable<PropTypes.InferProps<{
|
|
31
29
|
subject: PropTypes.Requireable<string>;
|
|
32
30
|
text: PropTypes.Requireable<string>;
|
|
@@ -22,27 +22,26 @@ import Typography from '@mui/material/Typography';
|
|
|
22
22
|
* @param Object props Properties passed to the component
|
|
23
23
|
* @returns React.Component
|
|
24
24
|
*/
|
|
25
|
-
export default function Email(
|
|
25
|
+
export default function Email({ value }) {
|
|
26
26
|
// Render
|
|
27
27
|
return (React.createElement(Grid, { container: true, spacing: 2 },
|
|
28
28
|
React.createElement(Grid, { item: true, xs: 12, md: 4, lg: 2, xl: 1 },
|
|
29
29
|
React.createElement(Typography, null,
|
|
30
30
|
React.createElement("strong", null, "Subject"))),
|
|
31
|
-
React.createElement(Grid, { item: true, xs: 12, md: 8, lg: 10, xl: 11 },
|
|
31
|
+
React.createElement(Grid, { item: true, xs: 12, md: 8, lg: 10, xl: 11 }, value.subject),
|
|
32
32
|
React.createElement(Grid, { item: true, xs: 12, md: 4, lg: 2, xl: 1 },
|
|
33
33
|
React.createElement(Typography, null,
|
|
34
34
|
React.createElement("strong", null, "Text"))),
|
|
35
|
-
React.createElement(Grid, { item: true, xs: 12, md: 8, lg: 10, xl: 11 },
|
|
36
|
-
React.createElement(Typography, { style: { whiteSpace: 'pre-wrap' } },
|
|
35
|
+
React.createElement(Grid, { item: true, xs: 12, md: 8, lg: 10, xl: 11 }, value.text &&
|
|
36
|
+
React.createElement(Typography, { style: { whiteSpace: 'pre-wrap' } }, value.text)),
|
|
37
37
|
React.createElement(Grid, { item: true, xs: 12, md: 4, lg: 2, xl: 1 },
|
|
38
38
|
React.createElement(Typography, null,
|
|
39
39
|
React.createElement("strong", null, "HTML"))),
|
|
40
|
-
React.createElement(Grid, { item: true, xs: 12, md: 8, lg: 10, xl: 11 },
|
|
41
|
-
React.createElement("div", { dangerouslySetInnerHTML: { __html:
|
|
40
|
+
React.createElement(Grid, { item: true, xs: 12, md: 8, lg: 10, xl: 11 }, value.html &&
|
|
41
|
+
React.createElement("div", { dangerouslySetInnerHTML: { __html: value.html } }))));
|
|
42
42
|
}
|
|
43
43
|
// Valid props
|
|
44
44
|
Email.propTypes = {
|
|
45
|
-
mobile: PropTypes.bool.isRequired,
|
|
46
45
|
value: PropTypes.shape({
|
|
47
46
|
subject: PropTypes.string,
|
|
48
47
|
text: PropTypes.string,
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
10
|
import React from 'react';
|
|
11
11
|
export type SMSProps = {
|
|
12
|
-
mobile: boolean;
|
|
13
12
|
value: string;
|
|
14
13
|
};
|
|
15
14
|
/**
|
|
@@ -22,10 +21,9 @@ export type SMSProps = {
|
|
|
22
21
|
* @param Object props Properties passed to the component
|
|
23
22
|
* @returns React.Component
|
|
24
23
|
*/
|
|
25
|
-
declare function SMS(
|
|
24
|
+
declare function SMS({ value }: SMSProps): React.JSX.Element;
|
|
26
25
|
declare namespace SMS {
|
|
27
26
|
var propTypes: {
|
|
28
|
-
mobile: PropTypes.Validator<boolean>;
|
|
29
27
|
value: PropTypes.Validator<string>;
|
|
30
28
|
};
|
|
31
29
|
}
|
|
@@ -22,17 +22,16 @@ import Typography from '@mui/material/Typography';
|
|
|
22
22
|
* @param Object props Properties passed to the component
|
|
23
23
|
* @returns React.Component
|
|
24
24
|
*/
|
|
25
|
-
export default function SMS(
|
|
25
|
+
export default function SMS({ value }) {
|
|
26
26
|
// Render
|
|
27
27
|
return (React.createElement(Grid, { container: true, spacing: 2 },
|
|
28
28
|
React.createElement(Grid, { item: true, xs: 12, md: 4, lg: 2, xl: 1 },
|
|
29
29
|
React.createElement(Typography, null,
|
|
30
30
|
React.createElement("strong", null, "Content"))),
|
|
31
|
-
React.createElement(Grid, { item: true, xs: 12, md: 8, lg: 10, xl: 11 },
|
|
32
|
-
React.createElement(Typography, { style: { whiteSpace: 'pre-wrap' } },
|
|
31
|
+
React.createElement(Grid, { item: true, xs: 12, md: 8, lg: 10, xl: 11 }, value &&
|
|
32
|
+
React.createElement(Typography, { style: { whiteSpace: 'pre-wrap' } }, value))));
|
|
33
33
|
}
|
|
34
34
|
// Valid props
|
|
35
35
|
SMS.propTypes = {
|
|
36
|
-
mobile: PropTypes.bool.isRequired,
|
|
37
36
|
value: PropTypes.string.isRequired
|
|
38
37
|
};
|
|
@@ -11,7 +11,6 @@ import React from 'react';
|
|
|
11
11
|
import { contentStruct } from '../..';
|
|
12
12
|
import { responseErrorStruct } from '@ouroboros/body';
|
|
13
13
|
export type PreviewProps = {
|
|
14
|
-
mobile: boolean;
|
|
15
14
|
onClose: () => void;
|
|
16
15
|
onError: (error: responseErrorStruct) => void;
|
|
17
16
|
value: contentStruct;
|
|
@@ -26,10 +25,9 @@ export type PreviewProps = {
|
|
|
26
25
|
* @param Object props Properties passed to the component
|
|
27
26
|
* @returns React.Component
|
|
28
27
|
*/
|
|
29
|
-
declare function Preview(
|
|
28
|
+
declare function Preview({ onClose, onError, value }: PreviewProps): React.JSX.Element;
|
|
30
29
|
declare namespace Preview {
|
|
31
30
|
var propTypes: {
|
|
32
|
-
mobile: PropTypes.Validator<boolean>;
|
|
33
31
|
onClose: PropTypes.Validator<(...args: any[]) => any>;
|
|
34
32
|
onError: PropTypes.Validator<(...args: any[]) => any>;
|
|
35
33
|
value: PropTypes.Requireable<PropTypes.InferProps<{
|
|
@@ -28,9 +28,7 @@ import SMS from './SMS';
|
|
|
28
28
|
* @param Object props Properties passed to the component
|
|
29
29
|
* @returns React.Component
|
|
30
30
|
*/
|
|
31
|
-
export default function Preview(
|
|
32
|
-
// Props
|
|
33
|
-
const { mobile, onClose, onError, value } = props;
|
|
31
|
+
export default function Preview({ onClose, onError, value }) {
|
|
34
32
|
// State
|
|
35
33
|
const [preview, previewSet] = useState(false);
|
|
36
34
|
// Value effect
|
|
@@ -47,12 +45,11 @@ export default function Preview(props) {
|
|
|
47
45
|
React.createElement(DialogContent, { dividers: true, className: "content_preview" }, preview === false ?
|
|
48
46
|
React.createElement(Typography, null, "Loading...")
|
|
49
47
|
: (value.type === 'email' &&
|
|
50
|
-
React.createElement(Email, { key: value.template + '_' + value.locale + '_email',
|
|
51
|
-
React.createElement(SMS, { key: value.template + '_' + value.locale + '_sms',
|
|
48
|
+
React.createElement(Email, { key: value.template + '_' + value.locale + '_email', value: preview })) || (value.type === 'sms' &&
|
|
49
|
+
React.createElement(SMS, { key: value.template + '_' + value.locale + '_sms', value: preview })))));
|
|
52
50
|
}
|
|
53
51
|
// Valid props
|
|
54
52
|
Preview.propTypes = {
|
|
55
|
-
mobile: PropTypes.bool.isRequired,
|
|
56
53
|
onClose: PropTypes.func.isRequired,
|
|
57
54
|
onError: PropTypes.func.isRequired,
|
|
58
55
|
value: PropTypes.shape({
|
|
@@ -24,7 +24,7 @@ export type EmailProps = {
|
|
|
24
24
|
* @param Object props Properties passed to the component
|
|
25
25
|
* @returns React.Component
|
|
26
26
|
*/
|
|
27
|
-
declare function Email(
|
|
27
|
+
declare function Email({ errors, onChanged, value }: EmailProps): React.JSX.Element;
|
|
28
28
|
declare namespace Email {
|
|
29
29
|
var propTypes: {
|
|
30
30
|
errors: PropTypes.Validator<object>;
|