umwd-components 0.1.310 → 0.1.311

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 (26) hide show
  1. package/dist/src/components/common/Address.js +1 -1
  2. package/dist/src/components/layout/SideNav.js +1 -1
  3. package/dist/src/data/actions/profile-actions.js +1 -1
  4. package/dist/src/data/loaders.js +1 -1
  5. package/dist/tsconfig.build.tsbuildinfo +1 -1
  6. package/dist/types/components/common/Address.d.ts +1 -5
  7. package/dist/types/components/e-commerce/customer/BusinessCredentials.d.ts +1 -6
  8. package/dist/types/components/public-information/PublicInformationForm.d.ts +5 -0
  9. package/dist/types/data/actions/pagebuilder-actions.d.ts +6 -6
  10. package/dist/types/data/actions/public-information/updatePublicInformationAction.d.ts +1 -0
  11. package/dist/types/data/loaders/public-information/getPublicInformation.d.ts +1 -0
  12. package/dist/types/types/AddressProps.d.ts +5 -1
  13. package/dist/types/types/e-commerce/BusinessCredentialsProps.d.ts +5 -0
  14. package/dist/types/types/public-information/types.d.ts +20 -0
  15. package/package.json +1 -1
  16. package/src/components/common/Address.tsx +6 -8
  17. package/src/components/e-commerce/customer/BusinessCredentials.tsx +3 -6
  18. package/src/components/layout/SideNav.tsx +1 -1
  19. package/src/components/public-information/PublicInformationForm.tsx +175 -0
  20. package/src/data/actions/profile-actions.ts +1 -1
  21. package/src/data/actions/public-information/updatePublicInformationAction.ts +51 -0
  22. package/src/data/loaders/public-information/getPublicInformation.ts +23 -0
  23. package/src/data/loaders.ts +1 -1
  24. package/src/types/AddressProps.tsx +7 -1
  25. package/src/types/e-commerce/BusinessCredentialsProps.tsx +6 -0
  26. package/src/types/public-information/types.tsx +22 -0
@@ -1,10 +1,6 @@
1
1
  import { AddressProps } from "@/types/AddressProps";
2
2
  import React from "react";
3
- export interface AddressFieldsProps {
4
- data?: AddressProps;
5
- componentName: string;
6
- componentReference: string;
7
- }
3
+ import { AddressFieldsProps } from "@/types/AddressProps";
8
4
  export default function Address({ data }: {
9
5
  readonly data: AddressProps;
10
6
  }): React.JSX.Element;
@@ -1,12 +1,7 @@
1
1
  import { BusinessCredentialsProps } from "../../../types/e-commerce/BusinessCredentialsProps";
2
+ import { BusinessCredentialsFieldsProps } from "../../../types/e-commerce/BusinessCredentialsProps";
2
3
  import React from "react";
3
4
  export default function BusinessCredentials({ data, }: {
4
5
  readonly data: BusinessCredentialsProps;
5
6
  }): React.JSX.Element;
6
- interface BusinessCredentialsFieldsProps {
7
- data: BusinessCredentialsProps;
8
- componentName: string;
9
- componentReference: string;
10
- }
11
7
  export declare function BusinessCredentialsFields({ data, componentName, componentReference, }: BusinessCredentialsFieldsProps): React.JSX.Element;
12
- export {};
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ import { PublicInformation } from "../../types/public-information/types";
3
+ export declare function PublicInformationForm({ publicInformation, }: {
4
+ readonly publicInformation: PublicInformation;
5
+ }): React.JSX.Element;
@@ -36,11 +36,11 @@ declare const schemaUpdate: z.ZodObject<{
36
36
  }, "strip", z.ZodTypeAny, {
37
37
  id: string;
38
38
  __component: string;
39
- title?: string | undefined;
40
39
  link?: {
41
40
  text?: string | undefined;
42
41
  url?: string | undefined;
43
42
  } | undefined;
43
+ title?: string | undefined;
44
44
  heading?: string | undefined;
45
45
  subHeading?: string | undefined;
46
46
  subtitle?: string | undefined;
@@ -52,11 +52,11 @@ declare const schemaUpdate: z.ZodObject<{
52
52
  }, {
53
53
  id: string;
54
54
  __component: string;
55
- title?: string | undefined;
56
55
  link?: {
57
56
  text?: string | undefined;
58
57
  url?: string | undefined;
59
58
  } | undefined;
59
+ title?: string | undefined;
60
60
  heading?: string | undefined;
61
61
  subHeading?: string | undefined;
62
62
  subtitle?: string | undefined;
@@ -67,17 +67,17 @@ declare const schemaUpdate: z.ZodObject<{
67
67
  } | undefined;
68
68
  }>, "many">>;
69
69
  }, "strip", z.ZodTypeAny, {
70
- title: string;
71
70
  id: string;
71
+ title: string;
72
72
  description: string;
73
73
  blocks?: {
74
74
  id: string;
75
75
  __component: string;
76
- title?: string | undefined;
77
76
  link?: {
78
77
  text?: string | undefined;
79
78
  url?: string | undefined;
80
79
  } | undefined;
80
+ title?: string | undefined;
81
81
  heading?: string | undefined;
82
82
  subHeading?: string | undefined;
83
83
  subtitle?: string | undefined;
@@ -88,17 +88,17 @@ declare const schemaUpdate: z.ZodObject<{
88
88
  } | undefined;
89
89
  }[] | undefined;
90
90
  }, {
91
- title: string;
92
91
  id: string;
92
+ title: string;
93
93
  description: string;
94
94
  blocks?: {
95
95
  id: string;
96
96
  __component: string;
97
- title?: string | undefined;
98
97
  link?: {
99
98
  text?: string | undefined;
100
99
  url?: string | undefined;
101
100
  } | undefined;
101
+ title?: string | undefined;
102
102
  heading?: string | undefined;
103
103
  subHeading?: string | undefined;
104
104
  subtitle?: string | undefined;
@@ -0,0 +1 @@
1
+ export declare function updatePublicInformationAction(prevState: any, formData: FormData): Promise<any>;
@@ -0,0 +1 @@
1
+ export declare function getPublicInformation(): Promise<any>;
@@ -1,5 +1,9 @@
1
+ export interface AddressFieldsProps {
2
+ data?: AddressProps;
3
+ componentName: string;
4
+ componentReference: string;
5
+ }
1
6
  export interface AddressProps {
2
- title: string;
3
7
  id: string | null;
4
8
  street: string;
5
9
  street_number: number;
@@ -5,3 +5,8 @@ export interface BusinessCredentialsProps {
5
5
  coc_number: string;
6
6
  vat_number: string;
7
7
  }
8
+ export interface BusinessCredentialsFieldsProps {
9
+ data: BusinessCredentialsProps;
10
+ componentName: string;
11
+ componentReference: string;
12
+ }
@@ -0,0 +1,20 @@
1
+ import { AddressProps } from "@/types/AddressProps";
2
+ import { BusinessCredentialsProps } from "@/types/e-commerce/BusinessCredentialsProps";
3
+ export interface PublicInformationFormProps {
4
+ publicInformation: PublicInformation;
5
+ }
6
+ export type PublicInformation = {
7
+ id: string;
8
+ title: string;
9
+ description: string;
10
+ disclaimer_link: string;
11
+ privacypolicy_link: string;
12
+ maxWidth: string;
13
+ email: string;
14
+ phone_number: string;
15
+ business_credentials: BusinessCredentialsProps;
16
+ address: AddressProps;
17
+ socials: string;
18
+ header_logo: string;
19
+ footer_logo: string;
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "umwd-components",
3
- "version": "0.1.310",
3
+ "version": "0.1.311",
4
4
  "description": "UMWD Component library",
5
5
  "main": "dist/src/index.js",
6
6
  "module": "dist/src/index.js",
@@ -4,16 +4,14 @@ import Typography from "@mui/material/Typography";
4
4
  import HomeIcon from "@mui/icons-material/Home";
5
5
  import { AddressProps } from "@/types/AddressProps";
6
6
  import React from "react";
7
+ import { AddressFieldsProps } from "@/types/AddressProps";
7
8
 
8
- export interface AddressFieldsProps {
9
- data?: AddressProps;
10
- componentName: string;
11
- componentReference: string;
12
- }
13
-
9
+ // TODO: This is not the place for title, first of all it should be optional,
10
+ // second it's not on the address entity
11
+ // third it should be outside of the address display component inside of the actual form
14
12
  export default function Address({ data }: { readonly data: AddressProps }) {
15
13
  const {
16
- title,
14
+ /* title, */
17
15
  id,
18
16
  street,
19
17
  street_number,
@@ -27,7 +25,7 @@ export default function Address({ data }: { readonly data: AddressProps }) {
27
25
  <Stack spacing={2} direction="row">
28
26
  <HomeIcon />
29
27
  <Stack>
30
- <Typography variant="h6">{title}</Typography>
28
+ {/* <Typography variant="h6">{title}</Typography> */}
31
29
  <Typography variant="body1" component="p">
32
30
  {street} {street_number} {street_number_addition}
33
31
  </Typography>
@@ -5,8 +5,11 @@ import TextField from "@mui/material/TextField";
5
5
 
6
6
  import BusinessCenterIcon from "@mui/icons-material/BusinessCenter";
7
7
  import { BusinessCredentialsProps } from "../../../types/e-commerce/BusinessCredentialsProps";
8
+ import { BusinessCredentialsFieldsProps } from "../../../types/e-commerce/BusinessCredentialsProps";
8
9
  import React from "react";
9
10
 
11
+ // TODO Move this to common
12
+
10
13
  export default function BusinessCredentials({
11
14
  data,
12
15
  }: {
@@ -35,12 +38,6 @@ export default function BusinessCredentials({
35
38
  );
36
39
  }
37
40
 
38
- interface BusinessCredentialsFieldsProps {
39
- data: BusinessCredentialsProps;
40
- componentName: string;
41
- componentReference: string;
42
- }
43
-
44
41
  export function BusinessCredentialsFields({
45
42
  data,
46
43
  componentName,
@@ -125,7 +125,7 @@ function SideNav({
125
125
  },
126
126
  };
127
127
 
128
- const [open, setOpen] = React.useState(false);
128
+ const [open, setOpen] = React.useState(true);
129
129
 
130
130
  const handleDrawerOpen = () => {
131
131
  setOpen(true);
@@ -0,0 +1,175 @@
1
+ "use client";
2
+
3
+ import Divider from "@mui/material/Divider";
4
+ import Paper from "@mui/material/Paper";
5
+ import Box from "@mui/material/Box";
6
+ import Stack from "@mui/material/Stack";
7
+ import Alert from "@mui/material/Alert";
8
+ import TextField from "@mui/material/TextField";
9
+ import Typography from "@mui/material/Typography";
10
+ import { SubmitButton } from "../SubmitButton";
11
+ import { useFormState } from "react-dom";
12
+ import { StrapiErrors } from "../StrapiErrors"; //"@/components/StrapiErrors";
13
+ import { BusinessCredentialsFields } from "../e-commerce/customer/BusinessCredentials";
14
+ import { useSession } from "../../context/auth/SessionContext";
15
+ import React, { useEffect } from "react";
16
+ import { AddressFields } from "../common/Address";
17
+ import {
18
+ PublicInformation,
19
+ PublicInformationFormProps,
20
+ } from "../../types/public-information/types";
21
+ import { updatePublicInformationAction } from "../../data/actions/public-information/updatePublicInformationAction";
22
+
23
+ const INITIAL_STATE = {
24
+ zodErrors: null,
25
+ strapiErrors: null,
26
+ data: null,
27
+ message: null,
28
+ };
29
+
30
+ export function PublicInformationForm({
31
+ publicInformation,
32
+ }: {
33
+ readonly publicInformation: PublicInformation;
34
+ }) {
35
+ console.log(publicInformation);
36
+
37
+ const {
38
+ id,
39
+ title,
40
+ description,
41
+ disclaimer_link,
42
+ privacypolicy_link,
43
+ maxWidth,
44
+ email,
45
+ phone_number,
46
+ business_credentials,
47
+ address,
48
+ socials,
49
+ header_logo,
50
+ footer_logo,
51
+ } = publicInformation;
52
+
53
+ const [formState, formAction] = useFormState(
54
+ updatePublicInformationAction,
55
+ INITIAL_STATE
56
+ );
57
+
58
+ // TODO useSession doesn't work, this should most definetively be implemented!!
59
+ // const { refreshSession } = useSession();
60
+ //
61
+ // useEffect(() => {
62
+ // if (!formState.strapiErrors && formState.message) {
63
+ // refreshSession();
64
+ // }
65
+ // }, [formState]);
66
+
67
+ return (
68
+ <Box
69
+ /* sx={[
70
+ // You cannot spread `sx` directly because `SxProps` (typeof sx) can be an array.
71
+ ...(Array.isArray(sx) ? sx : [sx]),
72
+ ]} */
73
+ component={Paper}
74
+ sx={{ p: 2 }}
75
+ >
76
+ <form action={formAction}>
77
+ <Stack spacing={2}>
78
+ <Stack
79
+ direction="row-reverse"
80
+ spacing={2}
81
+ alignItems={"center"}
82
+ sx={{
83
+ backgroundColor: "secondary.dark",
84
+ px: 2,
85
+ py: 1,
86
+ }}
87
+ >
88
+ <SubmitButton
89
+ text="save changes"
90
+ loadingText="loading"
91
+ sx={{ color: "secondary.contrastText" }}
92
+ />
93
+ <StrapiErrors error={formState?.strapiErrors} />
94
+
95
+ {formState?.message && (
96
+ <Alert severity="error">{formState?.message}</Alert>
97
+ )}
98
+ </Stack>
99
+ <TextField
100
+ id="title"
101
+ name="title"
102
+ label="Title"
103
+ defaultValue={title}
104
+ // error={}
105
+ // helperText={}
106
+ ></TextField>
107
+ <TextField
108
+ id="description"
109
+ name="description"
110
+ label="Description"
111
+ defaultValue={description}
112
+ // error={}
113
+ // helperText={}
114
+ ></TextField>
115
+ <TextField
116
+ id="email"
117
+ name="email"
118
+ label="email"
119
+ defaultValue={email}
120
+ // error={}
121
+ // helperText={}
122
+ ></TextField>
123
+ <TextField
124
+ id="phone_number"
125
+ name="phone_number"
126
+ label="phone_number"
127
+ defaultValue={phone_number}
128
+ // error={}
129
+ // helperText={}
130
+ ></TextField>
131
+ {/*
132
+ TODO Create public_documents / links component
133
+ <TextField
134
+ id="disclaimer_link"
135
+ name="disclaimer_link"
136
+ label="disclaimer_link"
137
+ defaultValue={disclaimer_link}
138
+ // error={}
139
+ // helperText={}
140
+ ></TextField>
141
+ <TextField
142
+ id="privacypolicy_link"
143
+ name="privacypolicy_link"
144
+ label="privacypolicy_link"
145
+ defaultValue={privacypolicy_link}
146
+ // error={}
147
+ // helperText={}
148
+ ></TextField> */}
149
+ <Typography variant="h6">Company Address</Typography>
150
+ <Divider />
151
+ <AddressFields
152
+ componentName="address"
153
+ componentReference="common.address"
154
+ data={address}
155
+ />
156
+ <Divider />
157
+ <Typography variant="h6">Business Credentials</Typography>
158
+ <BusinessCredentialsFields
159
+ componentName="business_credentials"
160
+ componentReference="business.credentials"
161
+ data={business_credentials}
162
+ />
163
+ {/*links component field <p>{publicInformation.socials}</p> */}
164
+ </Stack>
165
+ </form>
166
+ </Box>
167
+ );
168
+ }
169
+
170
+ /*
171
+ TODO, move to site-settings
172
+ <p>{publicInformation.maxWidth}</p>
173
+ <p>{publicInformation.header_logo}</p>
174
+ <p>{publicInformation.footer_logo}</p>
175
+ */
@@ -1,4 +1,4 @@
1
- "use client"; // this should be use server but while developing it's easier to use client to do console.log
1
+ "use server"; // "use client"; this should be use server but while developing it's easier to use client to do console.log
2
2
 
3
3
  import { mutateData } from "../services/mutate-data";
4
4
  import { flattenAttributes } from "../../lib/utils";
@@ -0,0 +1,51 @@
1
+ "use client"; // TODO: this should be use server but while developing it's easier to use client to do console.log
2
+
3
+ import { mutateData } from "../../services/mutate-data";
4
+ import { flattenAttributes } from "../../../lib/utils";
5
+ import { parseFormData } from "../../../lib/parseFormData";
6
+
7
+ // TODO Not tested or finished
8
+
9
+ export async function updatePublicInformationAction(
10
+ prevState: any,
11
+ formData: FormData
12
+ ) {
13
+ const rawFormData = Object.fromEntries(formData);
14
+ console.log("rawFormData", rawFormData);
15
+
16
+ const parsedFormData = parseFormData(formData); // ?? can i still use this or is it only for the pagebuilder form?
17
+ console.log("parsedFormData", parsedFormData);
18
+
19
+ const id = rawFormData.id;
20
+
21
+ const responseData = await mutateData(
22
+ "PUT",
23
+ `/api/public-information`,
24
+ parsedFormData
25
+ );
26
+
27
+ if (!responseData) {
28
+ return {
29
+ ...prevState,
30
+ strapiErrors: null,
31
+ message: "Ops! Something went wrong. Please try again.",
32
+ };
33
+ }
34
+
35
+ if (responseData.error) {
36
+ return {
37
+ ...prevState,
38
+ strapiErrors: responseData.error,
39
+ message: "Failed to Register.",
40
+ };
41
+ }
42
+
43
+ const flattenedData = flattenAttributes(responseData);
44
+
45
+ return {
46
+ ...prevState,
47
+ message: "Public Information Updated",
48
+ data: flattenedData,
49
+ strapiErrors: null,
50
+ };
51
+ }
@@ -0,0 +1,23 @@
1
+ "use server";
2
+
3
+ import qs from "qs";
4
+ import { fetchData } from "../../loaders";
5
+ import { flattenAttributes, getStrapiURL } from "../../../lib/utils";
6
+ import { unstable_noStore as noStore } from "next/cache";
7
+
8
+ const baseUrl = getStrapiURL();
9
+
10
+ export async function getPublicInformation() {
11
+ noStore();
12
+
13
+ const url = new URL(`/api/public-information`, baseUrl);
14
+
15
+ url.search = qs.stringify({
16
+ populate: {
17
+ address: true,
18
+ business_credentials: true,
19
+ },
20
+ });
21
+
22
+ return flattenAttributes(await fetchData(url.href));
23
+ }
@@ -196,7 +196,7 @@ async function getPageNames() {
196
196
  noStore();
197
197
  const url = new URL("/api/pages", baseUrl);
198
198
  url.search = qs.stringify({
199
- fields: ["slug"],
199
+ fields: ["slug", "title"],
200
200
  });
201
201
 
202
202
  return await fetchData(url.href);
@@ -1,5 +1,11 @@
1
+ export interface AddressFieldsProps {
2
+ data?: AddressProps;
3
+ componentName: string;
4
+ componentReference: string;
5
+ }
6
+
1
7
  export interface AddressProps {
2
- title: string;
8
+ // title: string; // why does an address need a title, shouldn't an address need a type?
3
9
  id: string | null;
4
10
  street: string;
5
11
  street_number: number;
@@ -5,3 +5,9 @@ export interface BusinessCredentialsProps {
5
5
  coc_number: string;
6
6
  vat_number: string;
7
7
  }
8
+
9
+ export interface BusinessCredentialsFieldsProps {
10
+ data: BusinessCredentialsProps;
11
+ componentName: string;
12
+ componentReference: string;
13
+ }
@@ -0,0 +1,22 @@
1
+ import { AddressProps } from "@/types/AddressProps";
2
+ import { BusinessCredentialsProps } from "@/types/e-commerce/BusinessCredentialsProps";
3
+
4
+ export interface PublicInformationFormProps {
5
+ publicInformation: PublicInformation;
6
+ }
7
+
8
+ export type PublicInformation = {
9
+ id: string;
10
+ title: string;
11
+ description: string;
12
+ disclaimer_link: string;
13
+ privacypolicy_link: string;
14
+ maxWidth: string;
15
+ email: string;
16
+ phone_number: string;
17
+ business_credentials: BusinessCredentialsProps;
18
+ address: AddressProps;
19
+ socials: string;
20
+ header_logo: string;
21
+ footer_logo: string;
22
+ };