@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.
Files changed (57) hide show
  1. package/lib/components/pages/Locales.d.ts +1 -3
  2. package/lib/components/pages/Locales.js +32 -23
  3. package/lib/components/pages/Templates/Create.d.ts +1 -1
  4. package/lib/components/pages/Templates/Create.js +11 -14
  5. package/lib/components/pages/Templates/Template/Content/Create/Email.d.ts +1 -1
  6. package/lib/components/pages/Templates/Template/Content/Create/Email.js +6 -10
  7. package/lib/components/pages/Templates/Template/Content/Create/SMS.d.ts +1 -1
  8. package/lib/components/pages/Templates/Template/Content/Create/SMS.js +4 -6
  9. package/lib/components/pages/Templates/Template/Content/Create/index.d.ts +1 -3
  10. package/lib/components/pages/Templates/Template/Content/Create/index.js +14 -20
  11. package/lib/components/pages/Templates/Template/Content/Preview/Email.d.ts +1 -3
  12. package/lib/components/pages/Templates/Template/Content/Preview/Email.js +6 -7
  13. package/lib/components/pages/Templates/Template/Content/Preview/SMS.d.ts +1 -3
  14. package/lib/components/pages/Templates/Template/Content/Preview/SMS.js +3 -4
  15. package/lib/components/pages/Templates/Template/Content/Preview/index.d.ts +1 -3
  16. package/lib/components/pages/Templates/Template/Content/Preview/index.js +3 -6
  17. package/lib/components/pages/Templates/Template/Content/Update/Email.d.ts +1 -1
  18. package/lib/components/pages/Templates/Template/Content/Update/Email.js +6 -11
  19. package/lib/components/pages/Templates/Template/Content/Update/SMS.d.ts +1 -1
  20. package/lib/components/pages/Templates/Template/Content/Update/SMS.js +4 -6
  21. package/lib/components/pages/Templates/Template/Content/Update/index.d.ts +1 -3
  22. package/lib/components/pages/Templates/Template/Content/Update/index.js +17 -23
  23. package/lib/components/pages/Templates/Template/Content/View/Email.d.ts +1 -3
  24. package/lib/components/pages/Templates/Template/Content/View/Email.js +6 -7
  25. package/lib/components/pages/Templates/Template/Content/View/SMS.d.ts +1 -3
  26. package/lib/components/pages/Templates/Template/Content/View/SMS.js +3 -4
  27. package/lib/components/pages/Templates/Template/Content/View/index.d.ts +1 -3
  28. package/lib/components/pages/Templates/Template/Content/View/index.js +5 -6
  29. package/lib/components/pages/Templates/Template/Variables.d.ts +1 -1
  30. package/lib/components/pages/Templates/Template/Variables.js +6 -7
  31. package/lib/components/pages/Templates/Template/index.d.ts +1 -3
  32. package/lib/components/pages/Templates/Template/index.js +27 -45
  33. package/lib/components/pages/Templates/index.d.ts +1 -3
  34. package/lib/components/pages/Templates/index.js +9 -21
  35. package/lib/shared.d.ts +12 -0
  36. package/lib/shared.js +25 -0
  37. package/package.json +7 -8
  38. package/src/components/pages/Locales.tsx +40 -27
  39. package/src/components/pages/Templates/Create.tsx +12 -15
  40. package/src/components/pages/Templates/Template/Content/Create/Email.tsx +15 -19
  41. package/src/components/pages/Templates/Template/Content/Create/SMS.tsx +7 -9
  42. package/src/components/pages/Templates/Template/Content/Create/index.tsx +15 -23
  43. package/src/components/pages/Templates/Template/Content/Preview/Email.tsx +7 -9
  44. package/src/components/pages/Templates/Template/Content/Preview/SMS.tsx +3 -9
  45. package/src/components/pages/Templates/Template/Content/Preview/index.tsx +2 -9
  46. package/src/components/pages/Templates/Template/Content/Update/Email.tsx +15 -18
  47. package/src/components/pages/Templates/Template/Content/Update/SMS.tsx +7 -9
  48. package/src/components/pages/Templates/Template/Content/Update/index.tsx +19 -29
  49. package/src/components/pages/Templates/Template/Content/View/Email.tsx +6 -8
  50. package/src/components/pages/Templates/Template/Content/View/SMS.tsx +3 -5
  51. package/src/components/pages/Templates/Template/Content/View/index.tsx +9 -12
  52. package/src/components/pages/Templates/Template/Variables.tsx +6 -7
  53. package/src/components/pages/Templates/Template/index.tsx +37 -59
  54. package/src/components/pages/Templates/index.tsx +19 -31
  55. package/src/shared.ts +29 -0
  56. package/ouroboros-mouth-mui-1.3.2.tgz +0 -0
  57. package/src/types/xhr2.d.ts +0 -3
@@ -17,12 +17,11 @@ import Typography from '@mui/material/Typography';
17
17
 
18
18
  // UI Shared components
19
19
  //import FreeText from 'ui-shared/components/elements/FreeText';
20
- //<FreeText content={props.value.text} />
20
+ //<FreeText content={value.text} />
21
21
 
22
22
  // Types
23
23
  import { contentStruct } from '../..';
24
24
  export type EmailProps = {
25
- mobile: boolean,
26
25
  value: contentStruct
27
26
  }
28
27
 
@@ -36,7 +35,7 @@ export type EmailProps = {
36
35
  * @param Object props Properties passed to the component
37
36
  * @returns React.Component
38
37
  */
39
- export default function Email(props: EmailProps) {
38
+ export default function Email({ value }: EmailProps) {
40
39
 
41
40
  // Render
42
41
  return (
@@ -45,22 +44,22 @@ export default function Email(props: EmailProps) {
45
44
  <Typography><strong>Subject</strong></Typography>
46
45
  </Grid>
47
46
  <Grid item xs={12} md={8} lg={10} xl={11}>
48
- {props.value.subject}
47
+ {value.subject}
49
48
  </Grid>
50
49
  <Grid item xs={12} md={4} lg={2} xl={1}>
51
50
  <Typography><strong>Text</strong></Typography>
52
51
  </Grid>
53
52
  <Grid item xs={12} md={8} lg={10} xl={11}>
54
- {props.value.text &&
55
- <Typography style={{whiteSpace: 'pre-wrap'}}>{props.value.text}</Typography>
53
+ {value.text &&
54
+ <Typography style={{whiteSpace: 'pre-wrap'}}>{value.text}</Typography>
56
55
  }
57
56
  </Grid>
58
57
  <Grid item xs={12} md={4} lg={2} xl={1}>
59
58
  <Typography><strong>HTML</strong></Typography>
60
59
  </Grid>
61
60
  <Grid item xs={12} md={8} lg={10} xl={11}>
62
- {props.value.html &&
63
- <div dangerouslySetInnerHTML={{__html: props.value.html}} />
61
+ {value.html &&
62
+ <div dangerouslySetInnerHTML={{__html: value.html}} />
64
63
  }
65
64
  </Grid>
66
65
  </Grid>
@@ -69,7 +68,6 @@ export default function Email(props: EmailProps) {
69
68
 
70
69
  // Valid props
71
70
  Email.propTypes = {
72
- mobile: PropTypes.bool.isRequired,
73
71
  value: PropTypes.shape({
74
72
  subject: PropTypes.string,
75
73
  text: PropTypes.string,
@@ -15,13 +15,8 @@ import React from 'react';
15
15
  import Grid from '@mui/material/Grid';
16
16
  import Typography from '@mui/material/Typography';
17
17
 
18
- // UI Shared components
19
- //import FreeText from 'ui-shared/components/elements/FreeText';
20
- //<FreeText content={props.value} />
21
-
22
18
  // Type
23
19
  export type SMSProps = {
24
- mobile: boolean
25
20
  value: string
26
21
  }
27
22
 
@@ -35,7 +30,7 @@ export type SMSProps = {
35
30
  * @param Object props Properties passed to the component
36
31
  * @returns React.Component
37
32
  */
38
- export default function SMS(props: SMSProps) {
33
+ export default function SMS({ value }: SMSProps) {
39
34
 
40
35
  // Render
41
36
  return (
@@ -44,8 +39,8 @@ export default function SMS(props: SMSProps) {
44
39
  <Typography><strong>Content</strong></Typography>
45
40
  </Grid>
46
41
  <Grid item xs={12} md={8} lg={10} xl={11}>
47
- {props.value &&
48
- <Typography style={{whiteSpace: 'pre-wrap'}}>{props.value}</Typography>
42
+ {value &&
43
+ <Typography style={{whiteSpace: 'pre-wrap'}}>{value}</Typography>
49
44
  }
50
45
  </Grid>
51
46
  </Grid>
@@ -54,6 +49,5 @@ export default function SMS(props: SMSProps) {
54
49
 
55
50
  // Valid props
56
51
  SMS.propTypes = {
57
- mobile: PropTypes.bool.isRequired,
58
52
  value: PropTypes.string.isRequired
59
53
  }
@@ -29,7 +29,6 @@ import SMS from './SMS';
29
29
  import { contentStruct } from '../..';
30
30
  import { responseErrorStruct } from '@ouroboros/body';
31
31
  export type PreviewProps = {
32
- mobile: boolean,
33
32
  onClose: () => void,
34
33
  onError: (error: responseErrorStruct) => void,
35
34
  value: contentStruct
@@ -45,13 +44,10 @@ export type PreviewProps = {
45
44
  * @param Object props Properties passed to the component
46
45
  * @returns React.Component
47
46
  */
48
- export default function Preview(props: PreviewProps) {
49
-
50
- // Props
51
- const { mobile, onClose, onError, value } = props;
47
+ export default function Preview({ onClose, onError, value }: PreviewProps) {
52
48
 
53
49
  // State
54
- const [preview, previewSet] = useState<contentStruct | string | false>(false);
50
+ const [ preview, previewSet ] = useState<contentStruct | string | false>(false);
55
51
 
56
52
  // Value effect
57
53
  useEffect(() => {
@@ -78,14 +74,12 @@ export default function Preview(props: PreviewProps) {
78
74
  value.type === 'email' &&
79
75
  <Email
80
76
  key={value.template + '_' + value.locale + '_email'}
81
- mobile={mobile}
82
77
  value={preview as contentStruct}
83
78
  />
84
79
  ) || (
85
80
  value.type === 'sms' &&
86
81
  <SMS
87
82
  key={value.template + '_' + value.locale + '_sms'}
88
- mobile={mobile}
89
83
  value={preview as string}
90
84
  />
91
85
  )}
@@ -96,7 +90,6 @@ export default function Preview(props: PreviewProps) {
96
90
 
97
91
  // Valid props
98
92
  Preview.propTypes = {
99
- mobile: PropTypes.bool.isRequired,
100
93
  onClose: PropTypes.func.isRequired,
101
94
  onError: PropTypes.func.isRequired,
102
95
  value: PropTypes.shape({
@@ -10,7 +10,6 @@
10
10
  // Ouroboros modules
11
11
  import { Node } from '@ouroboros/define';
12
12
  import { DefineNode } from '@ouroboros/define-mui';
13
- import TemplateEmail from '@ouroboros/mouth/definitions/template_email.json';
14
13
 
15
14
  // NPM modules
16
15
  import PropTypes from 'prop-types';
@@ -19,10 +18,8 @@ import React from 'react';
19
18
  // Material UI
20
19
  import Grid from '@mui/material/Grid';
21
20
 
22
- // Record Nodes
23
- const oSubjectNode = new Node(TemplateEmail.subject);
24
- const oTextNode = new Node(TemplateEmail.text);
25
- const oHtmlNode = new Node(TemplateEmail.html);
21
+ // Import the shared types
22
+ import { EmailTree } from '../../../../../../shared';
26
23
 
27
24
  // Types
28
25
  import { contentStruct } from '../../';
@@ -42,42 +39,42 @@ export type EmailProps = {
42
39
  * @param Object props Properties passed to the component
43
40
  * @returns React.Component
44
41
  */
45
- export default function Email(props: EmailProps) {
42
+ export default function Email({ errors, onChanged, value }: EmailProps) {
46
43
 
47
44
  // Render
48
45
  return (
49
46
  <Grid container className="content_update_email" spacing={1}>
50
47
  <Grid item xs={12} className="field">
51
48
  <DefineNode
52
- error={props.errors.subject || false}
49
+ error={errors.subject || false}
53
50
  label="placeholder"
54
51
  name="subject"
55
- node={oSubjectNode}
56
- onChange={val => props.onChanged('subject', val)}
52
+ node={EmailTree.get('subject') as Node}
53
+ onChange={val => onChanged('subject', val)}
57
54
  type="update"
58
- value={props.value.subject}
55
+ value={value.subject}
59
56
  />
60
57
  </Grid>
61
58
  <Grid item xs={12} lg={6} className="field">
62
59
  <DefineNode
63
- error={props.errors.text || false}
60
+ error={errors.text || false}
64
61
  label="placeholder"
65
62
  name="text"
66
- node={oTextNode}
67
- onChange={val => props.onChanged('text', val)}
63
+ node={EmailTree.get('text') as Node}
64
+ onChange={val => onChanged('text', val)}
68
65
  type="update"
69
- value={props.value.text}
66
+ value={value.text}
70
67
  />
71
68
  </Grid>
72
69
  <Grid item xs={12} lg={6} className="field">
73
70
  <DefineNode
74
- error={props.errors.html || false}
71
+ error={errors.html || false}
75
72
  label="placeholder"
76
73
  name="html"
77
- node={oHtmlNode}
78
- onChange={val => props.onChanged('html', val)}
74
+ node={EmailTree.get('html') as Node}
75
+ onChange={val => onChanged('html', val)}
79
76
  type="update"
80
- value={props.value.html}
77
+ value={value.html}
81
78
  />
82
79
  </Grid>
83
80
  </Grid>
@@ -8,9 +8,7 @@
8
8
  */
9
9
 
10
10
  // Ouroboros modules
11
- import { Node } from '@ouroboros/define';
12
11
  import { DefineNode } from '@ouroboros/define-mui';
13
- import TemplateSMS from '@ouroboros/mouth/definitions/template_sms.json';
14
12
 
15
13
  // NPM modules
16
14
  import PropTypes from 'prop-types';
@@ -19,8 +17,8 @@ import React from 'react';
19
17
  // Material UI
20
18
  import Box from '@mui/material/Box';
21
19
 
22
- // Record Nodes
23
- const oContentNode = new Node(TemplateSMS.content);
20
+ // Import the shared types
21
+ import { SmsTree } from '../../../../../../shared';
24
22
 
25
23
  // Types
26
24
  import { contentStruct } from '../../';
@@ -40,19 +38,19 @@ export type SMSProps = {
40
38
  * @param Object props Properties passed to the component
41
39
  * @returns React.Component
42
40
  */
43
- export default function SMS(props: SMSProps) {
41
+ export default function SMS({ errors, onChanged, value }: SMSProps) {
44
42
 
45
43
  // Render
46
44
  return (
47
45
  <Box className="content_update_sms field">
48
46
  <DefineNode
49
- error={props.errors.content || false}
47
+ error={errors.content || false}
50
48
  label="placeholder"
51
49
  name="content"
52
- node={oContentNode}
53
- onChange={val => props.onChanged('content', val)}
50
+ node={SmsTree.get('content') as any}
51
+ onChange={val => onChanged('content', val)}
54
52
  type="update"
55
- value={props.value.content}
53
+ value={value.content}
56
54
  />
57
55
  </Box>
58
56
  );
@@ -8,7 +8,6 @@
8
8
  */
9
9
 
10
10
  // Ouroboros modules
11
- import clone from '@ouroboros/clone';
12
11
  import { errorTree } from '@ouroboros/define-mui';
13
12
  import mouth, { errors } from '@ouroboros/mouth';
14
13
  import { owithout } from '@ouroboros/tools';
@@ -31,7 +30,6 @@ import { responseErrorStruct } from '@ouroboros/body';
31
30
  import { contentStruct } from '../..';
32
31
  export type updateStruct = Omit<contentStruct, 'type'>;
33
32
  export type UpdateProps = {
34
- mobile: boolean,
35
33
  onError: (error: responseErrorStruct) => void,
36
34
  onUpdated: (content: contentStruct) => void,
37
35
  value: contentStruct
@@ -47,19 +45,19 @@ export type UpdateProps = {
47
45
  * @param Object props Properties passed to the component
48
46
  * @returns React.Component
49
47
  */
50
- export default function Update(props: UpdateProps) {
48
+ export default function Update({ onError, onUpdated, value }: UpdateProps) {
51
49
 
52
50
  // State
53
- const [fieldErrors, fieldErrorsSet] = useState<Record<string, string>>({});
54
- const [preview, previewSet] = useState<contentStruct | boolean>(false);
55
- const [record, recordSet] = useState<updateStruct>(owithout(props.value, 'type') as updateStruct);
51
+ const [ fieldErrors, fieldErrorsSet ] = useState<Record<string, string>>({});
52
+ const [ preview, previewSet ] = useState<contentStruct | boolean>(false);
53
+ const [ record, recordSet ] = useState<updateStruct>(owithout(value, 'type') as updateStruct);
56
54
 
57
55
  // Called to create the new content record
58
56
  function update() {
59
57
 
60
58
  // Send the record data to the server
61
- mouth.update(`template/${props.value.type}`, record).then(() => {
62
- props.onUpdated({type: props.value.type, ...record});
59
+ mouth.update(`template/${value.type}`, record).then(() => {
60
+ onUpdated({type: value.type, ...record});
63
61
  }, (error: responseErrorStruct) => {
64
62
  if(error.code === errors.body.DATA_FIELDS) {
65
63
  fieldErrorsSet(errorTree(error.msg));
@@ -81,68 +79,61 @@ export default function Update(props: UpdateProps) {
81
79
  }
82
80
 
83
81
  // Show the errors
84
- if(props.onError) {
85
- props.onError({ code: 0, msg: lLines.join('\n') });
82
+ if(onError) {
83
+ onError({ code: 0, msg: lLines.join('\n') });
86
84
  }
87
85
  } else {
88
- props.onError(error);
86
+ onError(error);
89
87
  }
90
88
  });
91
89
  }
92
90
 
93
91
  // Called when any fields in the record are changed
94
- function recordChanged(field: string, value: any) {
92
+ function recordChanged(field: string, val: any) {
95
93
 
96
94
  // Clear error
97
95
  if(field in fieldErrors) {
98
96
  delete fieldErrors.field;
99
97
  }
100
98
 
101
- // Clone the record
102
- const oRecord = clone(record);
103
-
104
- // Update the field
105
- oRecord[field] = value;
106
-
107
- // Store the new record
108
- recordSet(oRecord);
99
+ // Set the new record
100
+ recordSet(o => { return { ...o, [field]: val } });
109
101
  }
110
102
 
111
103
  // Render
112
104
  return (
113
105
  <Box className="content_update">
114
- {(props.value.type === 'email' &&
106
+ {(value.type === 'email' &&
115
107
  <Email
116
108
  errors={fieldErrors}
117
- key={props.value._id}
109
+ key={value._id}
118
110
  onChanged={recordChanged}
119
111
  value={record}
120
112
  />
121
- ) || (props.value.type === 'sms' &&
113
+ ) || (value.type === 'sms' &&
122
114
  <SMS
123
115
  errors={fieldErrors}
124
- key={props.value._id}
116
+ key={value._id}
125
117
  onChanged={recordChanged}
126
118
  value={record}
127
119
  />
128
120
  )}
129
121
  <Box className="actions">
130
- <Button color="secondary" onClick={() => recordSet(owithout(props.value, 'type') as updateStruct)} variant="contained">Cancel</Button>
122
+ <Button color="secondary" onClick={() => recordSet(owithout(value, 'type') as updateStruct)} variant="contained">Cancel</Button>
131
123
  <Button color="info" onClick={() => previewSet(true)} variant="contained">Preview</Button>
132
124
  <Button color="primary" onClick={update} variant="contained">Save Content</Button>
133
125
  {preview &&
134
126
  <Preview
135
- mobile={props.mobile}
136
127
  onClose={() => previewSet(false)}
137
128
  onError={(error: responseErrorStruct) => {
138
129
  if(error.code === errors.body.DATA_FIELDS) {
139
130
  fieldErrorsSet(errorTree(error.msg));
140
131
  } else {
141
- props.onError(error);
132
+ onError(error);
142
133
  }
143
134
  previewSet(false);
144
135
  }}
145
- value={{...record, type: props.value.type}}
136
+ value={{ ...record, type: value.type }}
146
137
  />
147
138
  }
148
139
  </Box>
@@ -152,7 +143,6 @@ export default function Update(props: UpdateProps) {
152
143
 
153
144
  // Valid props
154
145
  Update.propTypes = {
155
- mobile: PropTypes.bool.isRequired,
156
146
  onError: PropTypes.func.isRequired,
157
147
  onUpdated: PropTypes.func.isRequired,
158
148
  value: PropTypes.shape({
@@ -18,7 +18,6 @@ import Typography from '@mui/material/Typography';
18
18
  // Types
19
19
  import { contentStruct } from '../../';
20
20
  export type EmailProps = {
21
- mobile: boolean,
22
21
  value: contentStruct
23
22
  }
24
23
 
@@ -32,7 +31,7 @@ export type EmailProps = {
32
31
  * @param Object props Properties passed to the component
33
32
  * @returns React.Component
34
33
  */
35
- export default function Email(props: EmailProps) {
34
+ export default function Email({ value }: EmailProps) {
36
35
 
37
36
  // Render
38
37
  return (
@@ -41,22 +40,22 @@ export default function Email(props: EmailProps) {
41
40
  <Typography><strong>Subject</strong></Typography>
42
41
  </Grid>
43
42
  <Grid item xs={12} md={8} lg={10} xl={11}>
44
- {props.value.subject}
43
+ {value.subject}
45
44
  </Grid>
46
45
  <Grid item xs={12} md={4} lg={2} xl={1}>
47
46
  <Typography><strong>Text</strong></Typography>
48
47
  </Grid>
49
48
  <Grid item xs={12} md={8} lg={10} xl={11}>
50
- {props.value.text &&
51
- <Typography style={{whiteSpace: 'pre-wrap'}}>{props.value.text}</Typography>
49
+ {value.text &&
50
+ <Typography style={{whiteSpace: 'pre-wrap'}}>{value.text}</Typography>
52
51
  }
53
52
  </Grid>
54
53
  <Grid item xs={12} md={4} lg={2} xl={1}>
55
54
  <Typography><strong>HTML</strong></Typography>
56
55
  </Grid>
57
56
  <Grid item xs={12} md={8} lg={10} xl={11}>
58
- {props.value.html &&
59
- <Typography style={{whiteSpace: 'pre-wrap'}}>{props.value.html}</Typography>
57
+ {value.html &&
58
+ <Typography style={{whiteSpace: 'pre-wrap'}}>{value.html}</Typography>
60
59
  }
61
60
  </Grid>
62
61
  </Grid>
@@ -65,7 +64,6 @@ export default function Email(props: EmailProps) {
65
64
 
66
65
  // Valid props
67
66
  Email.propTypes = {
68
- mobile: PropTypes.bool.isRequired,
69
67
  value: PropTypes.exact({
70
68
  _id: PropTypes.string.isRequired,
71
69
  _created: PropTypes.number,
@@ -18,7 +18,6 @@ import Typography from '@mui/material/Typography';
18
18
  // Types
19
19
  import { contentStruct } from '../../';
20
20
  export type SMSProps = {
21
- mobile: boolean,
22
21
  value: contentStruct
23
22
  }
24
23
 
@@ -32,7 +31,7 @@ export type SMSProps = {
32
31
  * @param Object props Properties passed to the component
33
32
  * @returns React.Component
34
33
  */
35
- export default function SMS(props: SMSProps) {
34
+ export default function SMS({ value }: SMSProps) {
36
35
 
37
36
  // Render
38
37
  return (
@@ -41,8 +40,8 @@ export default function SMS(props: SMSProps) {
41
40
  <Typography><strong>Content</strong></Typography>
42
41
  </Grid>
43
42
  <Grid item xs={12} md={8} lg={10} xl={11}>
44
- {props.value.content &&
45
- <Typography style={{whiteSpace: 'pre-wrap'}}>{props.value.content}</Typography>
43
+ {value.content &&
44
+ <Typography style={{whiteSpace: 'pre-wrap'}}>{value.content}</Typography>
46
45
  }
47
46
  </Grid>
48
47
  </Grid>
@@ -51,7 +50,6 @@ export default function SMS(props: SMSProps) {
51
50
 
52
51
  // Valid props
53
52
  SMS.propTypes = {
54
- mobile: PropTypes.bool.isRequired,
55
53
  value: PropTypes.exact({
56
54
  _id: PropTypes.string.isRequired,
57
55
  _created: PropTypes.number,
@@ -24,7 +24,6 @@ import SMS from './SMS';
24
24
  import { responseErrorStruct } from '@ouroboros/body';
25
25
  import { contentStruct } from '../..';
26
26
  export type ViewProps = {
27
- mobile: boolean,
28
27
  onError: (error: responseErrorStruct) => void,
29
28
  value: contentStruct
30
29
  }
@@ -39,27 +38,26 @@ export type ViewProps = {
39
38
  * @param Object props Properties passed to the component
40
39
  * @returns React.Component
41
40
  */
42
- export default function View(props: ViewProps) {
41
+ export default function View({ onError, value }: ViewProps) {
43
42
 
44
43
  // State
45
- const [preview, previewSet] = useState(false);
44
+ const [ preview, previewSet ] = useState(false);
46
45
 
47
46
  // Render
48
47
  return (
49
48
  <Box className="content_view">
50
- {(props.value.type === 'email' &&
51
- <Email {...props} key={props.value._id} />
52
- ) || (props.value.type === 'sms' &&
53
- <SMS {...props} key={props.value._id} />
49
+ {(value.type === 'email' &&
50
+ <Email key={value._id} value={value} />
51
+ ) || (value.type === 'sms' &&
52
+ <SMS key={value._id} value={value} />
54
53
  )}
55
54
  <Box className="actions">
56
55
  <Button color="info" onClick={() => previewSet(true)} variant="contained">Preview</Button>
57
56
  {preview &&
58
57
  <Preview
59
- mobile={props.mobile}
60
58
  onClose={() => previewSet(false)}
61
- onError={props.onError}
62
- value={props.value}
59
+ onError={onError}
60
+ value={value}
63
61
  />
64
62
  }
65
63
  </Box>
@@ -69,10 +67,9 @@ export default function View(props: ViewProps) {
69
67
 
70
68
  // Valid props
71
69
  View.propTypes = {
72
- mobile: PropTypes.bool.isRequired,
73
70
  onError: PropTypes.func.isRequired,
74
71
  value: PropTypes.shape({
75
72
  _id: PropTypes.string.isRequired,
76
- type: PropTypes.oneOf(['email', 'sms']).isRequired
73
+ type: PropTypes.oneOf([ 'email', 'sms' ]).isRequired
77
74
  })
78
75
  }
@@ -8,7 +8,6 @@
8
8
  */
9
9
 
10
10
  // Ouroboros modules
11
- import clone from '@ouroboros/clone';
12
11
  import { Node } from '@ouroboros/define';
13
12
  import { DefineNode } from '@ouroboros/define-mui';
14
13
  import { omap } from '@ouroboros/tools';
@@ -46,7 +45,7 @@ export type VariablesProps = {
46
45
  * @param Object props Properties passed to the component
47
46
  * @returns React.Component
48
47
  */
49
- export default function Variables(props: VariablesProps) {
48
+ export default function Variables({ onChange, value }: VariablesProps) {
50
49
 
51
50
  // Refs
52
51
  const refName = useRef<DefineNode>(null);
@@ -56,7 +55,7 @@ export default function Variables(props: VariablesProps) {
56
55
  function add() {
57
56
 
58
57
  // Clone the current value
59
- const oValue: Record<string, string> = clone(props.value);
58
+ const oValue: Record<string, string> = { ...value };
60
59
 
61
60
  // If we have references to the inputs
62
61
  if(refName.current && refValue.current) {
@@ -70,14 +69,14 @@ export default function Variables(props: VariablesProps) {
70
69
  }
71
70
 
72
71
  // Let the parent know
73
- props.onChange(oValue);
72
+ onChange(oValue);
74
73
  }
75
74
 
76
75
  // Called when an existing variables needs to be removed
77
76
  function remove(name: string) {
78
77
 
79
78
  // Clone the current value
80
- const oValue = clone(props.value);
79
+ const oValue = { ...value };
81
80
 
82
81
  // Delete the given key if it exists
83
82
  if(name in oValue) {
@@ -85,14 +84,14 @@ export default function Variables(props: VariablesProps) {
85
84
  }
86
85
 
87
86
  // Let the parent know
88
- props.onChange(oValue);
87
+ onChange(oValue);
89
88
  }
90
89
 
91
90
  // Render
92
91
  return (
93
92
  <Box>
94
93
  <Grid container spacing={1}>
95
- {omap(props.value, (v,k) =>
94
+ {omap(value, (v,k) =>
96
95
  <React.Fragment key={k}>
97
96
  <Grid item xs={5}>{k}</Grid>
98
97
  <Grid item xs={5}>{v}</Grid>