umwd-components 0.1.624 → 0.1.625
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/prop-types/node_modules/react-is/index.js +1 -1
- package/dist/node_modules/safe-buffer/index.js +1 -1
- package/dist/src/components/auth/AuthWidget.js +1 -1
- package/dist/src/components/e-commerce/iro/RmaForm.js +1 -1
- package/dist/src/data/actions/e-commerce/iro/requestRmaAction.js +7 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/data/actions/e-commerce/iro/requestRmaAction.d.ts +4 -0
- package/package.json +1 -1
- package/src/components/auth/AuthWidget.tsx +2 -1
- package/src/components/e-commerce/iro/RmaForm.tsx +2 -2
- package/src/data/actions/e-commerce/iro/requestRmaAction.ts +41 -0
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ import { useRouter } from "next/navigation";
|
|
|
17
17
|
import { useSession } from "../../context/auth/SessionContext";
|
|
18
18
|
import Button from "@mui/material/Button";
|
|
19
19
|
import { Typography } from "@mui/material";
|
|
20
|
+
import KeyboardReturnIcon from "@mui/icons-material/KeyboardReturn";
|
|
20
21
|
|
|
21
22
|
interface Action {
|
|
22
23
|
icon: JSX.Element;
|
|
@@ -36,8 +37,8 @@ const defaultActions = {
|
|
|
36
37
|
loggedIn: [
|
|
37
38
|
{ icon: <PersonIcon />, name: "Profile", route: "/user/profile" },
|
|
38
39
|
{ icon: <ListAltIcon />, name: "Orders", route: "/user/orders" },
|
|
40
|
+
{ icon: <KeyboardReturnIcon />, name: "Returns", route: "/user/returns" },
|
|
39
41
|
{ icon: <FolderIcon />, name: "Documents", route: "/user/documents" },
|
|
40
|
-
// TODO { icon: <KeyboardReturnIcon />, name: "Returns", route: "/user/returns" },
|
|
41
42
|
],
|
|
42
43
|
loggedOut: [
|
|
43
44
|
{ icon: <LoginIcon />, name: "Sign-In", route: "/auth/signin" },
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import React, { useEffect, useState } from "react";
|
|
4
4
|
import { useFormState } from "react-dom";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { requestRmaAction } from "../../../data/actions/e-commerce/iro/requestRmaAction";
|
|
7
7
|
import { StrapiErrors } from "../../../components/StrapiErrors";
|
|
8
8
|
import { SubmitButton } from "../../../components/SubmitButton";
|
|
9
9
|
import {
|
|
@@ -144,7 +144,7 @@ export default function RmaForm({
|
|
|
144
144
|
revalidateCallback,
|
|
145
145
|
handleClose,
|
|
146
146
|
}: RMAFormProps) {
|
|
147
|
-
const [formState, formAction] = useFormState(
|
|
147
|
+
const [formState, formAction] = useFormState(requestRmaAction, INITIAL_STATE);
|
|
148
148
|
|
|
149
149
|
const [items, setItems] = useState<NewIroItem[]>([]);
|
|
150
150
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
import { mutateData } from "../../../services/mutate-data";
|
|
4
|
+
import { flattenAttributes } from "../../../../lib/utils";
|
|
5
|
+
import { parseFormData } from "../../../../lib/parseFormData";
|
|
6
|
+
|
|
7
|
+
/** INFO
|
|
8
|
+
* This action is used by the customer to request an rma
|
|
9
|
+
*/
|
|
10
|
+
export async function requestRmaAction(prevState: any, formData: FormData) {
|
|
11
|
+
const rawFormData = Object.fromEntries(formData);
|
|
12
|
+
|
|
13
|
+
const parsedFormData = parseFormData(formData);
|
|
14
|
+
|
|
15
|
+
const responseData = await mutateData("POST", `/api/iros`, parsedFormData);
|
|
16
|
+
|
|
17
|
+
if (!responseData) {
|
|
18
|
+
return {
|
|
19
|
+
...prevState,
|
|
20
|
+
strapiErrors: null,
|
|
21
|
+
message: "Ops! Something went wrong. Please try again.",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (responseData.error) {
|
|
26
|
+
return {
|
|
27
|
+
...prevState,
|
|
28
|
+
strapiErrors: responseData.error,
|
|
29
|
+
message: "Failed to Create Iro.",
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const flattenedData = flattenAttributes(responseData);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
...prevState,
|
|
37
|
+
message: "Iro Created Successfully",
|
|
38
|
+
data: flattenedData,
|
|
39
|
+
strapiErrors: null,
|
|
40
|
+
};
|
|
41
|
+
}
|