umwd-components 0.1.705 → 0.1.706
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/dist/node_modules/base64-js/index.js +1 -1
- package/dist/node_modules/ieee754/index.js +1 -1
- package/dist/src/components/common/markdown/MarkdownEditor.js +1 -1
- package/dist/src/components/logistics/note/NoteTakingComponent.js +1 -1
- package/dist/src/data/actions/logistics/note/createNoteAction.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/components/common/markdown/MarkdownEditor.d.ts +3 -1
- package/package.json +1 -1
- package/src/components/common/markdown/MarkdownEditor.tsx +4 -0
- package/src/components/logistics/note/NoteTakingComponent.tsx +9 -0
- package/src/data/actions/logistics/note/createNoteAction.ts +30 -7
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { SxProps } from "@mui/material/styles";
|
|
3
|
-
|
|
3
|
+
import { TextFieldProps } from "@mui/material/TextField";
|
|
4
|
+
export default function MarkdownEditor({ name, label, defaultValue, sx, onChangeCallback, textfieldProps, }: {
|
|
4
5
|
name: string;
|
|
5
6
|
label: string;
|
|
6
7
|
defaultValue?: string;
|
|
7
8
|
sx?: SxProps;
|
|
8
9
|
onChangeCallback?: (value: string) => void;
|
|
10
|
+
textfieldProps?: TextFieldProps;
|
|
9
11
|
}): React.JSX.Element;
|
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ import Stack from "@mui/material/Stack";
|
|
|
7
7
|
import TextField from "@mui/material/TextField";
|
|
8
8
|
import { useTheme, SxProps } from "@mui/material/styles";
|
|
9
9
|
import MarkdownDisplay from "./MarkdownDisplay";
|
|
10
|
+
import { TextFieldProps } from "@mui/material/TextField";
|
|
10
11
|
|
|
11
12
|
export default function MarkdownEditor({
|
|
12
13
|
name,
|
|
@@ -14,12 +15,14 @@ export default function MarkdownEditor({
|
|
|
14
15
|
defaultValue,
|
|
15
16
|
sx,
|
|
16
17
|
onChangeCallback,
|
|
18
|
+
textfieldProps,
|
|
17
19
|
}: {
|
|
18
20
|
name: string;
|
|
19
21
|
label: string;
|
|
20
22
|
defaultValue?: string;
|
|
21
23
|
sx?: SxProps;
|
|
22
24
|
onChangeCallback?: (value: string) => void;
|
|
25
|
+
textfieldProps?: TextFieldProps;
|
|
23
26
|
}) {
|
|
24
27
|
const [markdown, setMarkdown] = React.useState(defaultValue || "");
|
|
25
28
|
const theme = useTheme();
|
|
@@ -47,6 +50,7 @@ export default function MarkdownEditor({
|
|
|
47
50
|
placeholder={`# Heading 1 \n ## Heading 2 \n ### Heading 3 \n **bold** \n *italic*`}
|
|
48
51
|
onChange={(e) => handleChange(`${e.target.value}`)}
|
|
49
52
|
sx={{ flex: 1, whiteSpace: "pre", height: "100%" }}
|
|
53
|
+
{...textfieldProps}
|
|
50
54
|
/>
|
|
51
55
|
<Box sx={{ flex: 1 }}>
|
|
52
56
|
<Paper
|
|
@@ -110,6 +110,15 @@ export default function NoteTakingComponent({
|
|
|
110
110
|
input: { color: "black" },
|
|
111
111
|
div: { color: "black" },
|
|
112
112
|
}}
|
|
113
|
+
textfieldProps={{
|
|
114
|
+
placeholder: "Write your note here...",
|
|
115
|
+
multiline: true,
|
|
116
|
+
minRows: 5,
|
|
117
|
+
maxRows: 10,
|
|
118
|
+
error:
|
|
119
|
+
formState?.zodErrors?.content != undefined ? true : false,
|
|
120
|
+
helperText: formState?.zodErrors?.content || "",
|
|
121
|
+
}}
|
|
113
122
|
/>
|
|
114
123
|
</Stack>
|
|
115
124
|
</Paper>
|
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
|
|
3
|
+
import { z } from "zod";
|
|
3
4
|
import { mutateData } from "../../../services/mutate-data";
|
|
4
5
|
import { flattenAttributes } from "../../../../lib/utils";
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
const schemaUpdate = z.object({
|
|
8
|
+
content: z
|
|
9
|
+
.string()
|
|
10
|
+
.min(10)
|
|
11
|
+
.max(5000, { message: "Description must be at least 10 characters" }),
|
|
12
|
+
});
|
|
7
13
|
|
|
8
14
|
export async function createNoteAction(
|
|
9
15
|
related: any,
|
|
10
16
|
prevState: any,
|
|
11
17
|
formData: FormData
|
|
12
18
|
) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (parsedFormData.data.content.length < 5) {
|
|
19
|
+
if (related === null || related === undefined) {
|
|
16
20
|
return {
|
|
17
21
|
...prevState,
|
|
22
|
+
zodErrors: null,
|
|
18
23
|
strapiErrors: null,
|
|
19
|
-
message: "
|
|
24
|
+
message: "Failed to Create Note. Related entity is missing.",
|
|
20
25
|
severity: "error",
|
|
21
26
|
};
|
|
22
27
|
}
|
|
23
28
|
|
|
29
|
+
const validatedFields = schemaUpdate.safeParse({
|
|
30
|
+
id: formData.get("content"),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (!validatedFields.success) {
|
|
34
|
+
return {
|
|
35
|
+
...prevState,
|
|
36
|
+
zodErrors: validatedFields.error.flatten().fieldErrors,
|
|
37
|
+
strapiErrors: null,
|
|
38
|
+
message: "Missing Fields. Failed to Update Page.",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { data } = validatedFields;
|
|
43
|
+
|
|
24
44
|
const noteData = {
|
|
25
45
|
data: {
|
|
26
|
-
...
|
|
46
|
+
...data,
|
|
27
47
|
related,
|
|
28
48
|
},
|
|
29
49
|
};
|
|
@@ -33,6 +53,7 @@ export async function createNoteAction(
|
|
|
33
53
|
if (!responseData) {
|
|
34
54
|
return {
|
|
35
55
|
...prevState,
|
|
56
|
+
zodErrors: null,
|
|
36
57
|
strapiErrors: null,
|
|
37
58
|
message: "Ops! Something went wrong. Please try again.",
|
|
38
59
|
severity: "error",
|
|
@@ -42,6 +63,7 @@ export async function createNoteAction(
|
|
|
42
63
|
if (responseData.error) {
|
|
43
64
|
return {
|
|
44
65
|
...prevState,
|
|
66
|
+
zodErrors: null,
|
|
45
67
|
strapiErrors: responseData.error,
|
|
46
68
|
message: "Failed to Create Note.",
|
|
47
69
|
severity: "error",
|
|
@@ -52,6 +74,7 @@ export async function createNoteAction(
|
|
|
52
74
|
|
|
53
75
|
return {
|
|
54
76
|
...prevState,
|
|
77
|
+
zodErrors: null,
|
|
55
78
|
message: "New Note Created",
|
|
56
79
|
severity: "success",
|
|
57
80
|
data: flattenedData,
|