umwd-components 0.1.705 → 0.1.707

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.
@@ -1,9 +1,11 @@
1
1
  import React from "react";
2
2
  import { SxProps } from "@mui/material/styles";
3
- export default function MarkdownEditor({ name, label, defaultValue, sx, onChangeCallback, }: {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "umwd-components",
3
- "version": "0.1.705",
3
+ "version": "0.1.707",
4
4
  "description": "UMWD Component library",
5
5
  "main": "dist/src/index.js",
6
6
  "module": "dist/src/index.js",
@@ -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,16 @@ export default function NoteTakingComponent({
110
110
  input: { color: "black" },
111
111
  div: { color: "black" },
112
112
  }}
113
+ textfieldProps={{
114
+ id: "content",
115
+ placeholder: "Write your note here...",
116
+ multiline: true,
117
+ minRows: 5,
118
+ maxRows: 10,
119
+ error:
120
+ formState?.zodErrors?.content != undefined ? true : false,
121
+ helperText: formState?.zodErrors?.content || "",
122
+ }}
113
123
  />
114
124
  </Stack>
115
125
  </Paper>
@@ -1,29 +1,48 @@
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
- import { parseFormData } from "../../../../lib/parseFormData";
6
- // import { format } from "date-fns";
6
+
7
+ const schemaUpdate = z.object({
8
+ content: z
9
+ .string()
10
+ .min(10, "Description must be at least 10 characters long")
11
+ .max(5000, "Description cannot be more than 5000 characters long"),
12
+ });
7
13
 
8
14
  export async function createNoteAction(
9
15
  related: any,
10
16
  prevState: any,
11
17
  formData: FormData
12
18
  ) {
13
- const parsedFormData = parseFormData(formData);
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: "Content cannot be empty.",
24
+ message: "Failed to Create Note. Related entity is missing.",
20
25
  severity: "error",
21
26
  };
22
27
  }
28
+ const validatedFields = schemaUpdate.safeParse({
29
+ content: formData.get("content"),
30
+ });
31
+
32
+ if (!validatedFields.success) {
33
+ return {
34
+ ...prevState,
35
+ zodErrors: validatedFields.error.flatten().fieldErrors,
36
+ strapiErrors: null,
37
+ message: "null",
38
+ };
39
+ }
40
+
41
+ const { data } = validatedFields;
23
42
 
24
43
  const noteData = {
25
44
  data: {
26
- ...parsedFormData.data,
45
+ ...data,
27
46
  related,
28
47
  },
29
48
  };
@@ -33,6 +52,7 @@ export async function createNoteAction(
33
52
  if (!responseData) {
34
53
  return {
35
54
  ...prevState,
55
+ zodErrors: null,
36
56
  strapiErrors: null,
37
57
  message: "Ops! Something went wrong. Please try again.",
38
58
  severity: "error",
@@ -42,6 +62,7 @@ export async function createNoteAction(
42
62
  if (responseData.error) {
43
63
  return {
44
64
  ...prevState,
65
+ zodErrors: null,
45
66
  strapiErrors: responseData.error,
46
67
  message: "Failed to Create Note.",
47
68
  severity: "error",
@@ -52,6 +73,7 @@ export async function createNoteAction(
52
73
 
53
74
  return {
54
75
  ...prevState,
76
+ zodErrors: null,
55
77
  message: "New Note Created",
56
78
  severity: "success",
57
79
  data: flattenedData,