umwd-components 0.1.658 → 0.1.661

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 (44) hide show
  1. package/.ai/action-patterns.md +170 -0
  2. package/.ai/form-patterns.md +21 -0
  3. package/.ai/instructions/form-patterns.instructions.md +10 -0
  4. package/.ai/prompts/form-patterns.prompt.md +15 -0
  5. package/dist/src/components/e-commerce/enduser/EnduserProfileDisplay.js +7 -0
  6. package/dist/src/components/e-commerce/enduser/EnduserProfileEditForm.js +7 -0
  7. package/dist/src/components/e-commerce/opo/TextualManageOpoForm.js +1 -1
  8. package/dist/src/components/logistics/dispatcher/DispatcherProfileEditForm.js +1 -1
  9. package/dist/src/components/logistics/ipo/AddIPOForm.js +1 -1
  10. package/dist/src/components/logistics/ipo/ManageIPOForm.js +1 -1
  11. package/dist/src/components/logistics/ipo/TextualManageIPOForm.js +1 -1
  12. package/dist/src/data/actions/e-commerce/enduser/profile-actions.js +7 -0
  13. package/dist/src/data/actions/e-commerce/opo/updateOpoAction.js +1 -1
  14. package/dist/src/data/actions/logistics/dispatcher/profile-actions.js +1 -1
  15. package/dist/src/data/actions/logistics/ipo/createIPOAction.js +1 -1
  16. package/dist/src/data/actions/logistics/ipo/updateIpoAction.js +1 -1
  17. package/dist/src/index.js +1 -1
  18. package/dist/tsconfig.build.tsbuildinfo +1 -1
  19. package/dist/types/components/e-commerce/enduser/EnduserProfileDisplay.d.ts +13 -0
  20. package/dist/types/components/e-commerce/enduser/EnduserProfileEditForm.d.ts +9 -0
  21. package/dist/types/components/logistics/dispatcher/DispatcherProfileEditForm.d.ts +3 -1
  22. package/dist/types/components/logistics/ipo/AddIPOForm.d.ts +3 -1
  23. package/dist/types/components/logistics/ipo/TextualManageIPOForm.d.ts +1 -1
  24. package/dist/types/data/actions/e-commerce/enduser/profile-actions.d.ts +1 -0
  25. package/dist/types/data/actions/e-commerce/opo/updateOpoAction.d.ts +1 -1
  26. package/dist/types/data/actions/logistics/dispatcher/profile-actions.d.ts +1 -1
  27. package/dist/types/data/actions/logistics/ipo/updateIpoAction.d.ts +1 -1
  28. package/dist/types/index.d.ts +2 -0
  29. package/dist/types/types/e-commerce/enduser/types.d.ts +14 -0
  30. package/package.json +1 -1
  31. package/src/components/e-commerce/enduser/EnduserProfileDisplay.tsx +100 -0
  32. package/src/components/e-commerce/enduser/EnduserProfileEditForm.tsx +145 -0
  33. package/src/components/e-commerce/opo/TextualManageOpoForm.tsx +54 -29
  34. package/src/components/logistics/dispatcher/DispatcherProfileEditForm.tsx +90 -66
  35. package/src/components/logistics/ipo/AddIPOForm.tsx +58 -21
  36. package/src/components/logistics/ipo/ManageIPOForm.tsx +95 -133
  37. package/src/components/logistics/ipo/TextualManageIPOForm.tsx +165 -118
  38. package/src/data/actions/e-commerce/enduser/profile-actions.ts +47 -0
  39. package/src/data/actions/e-commerce/opo/updateOpoAction.ts +6 -2
  40. package/src/data/actions/logistics/dispatcher/profile-actions.ts +6 -8
  41. package/src/data/actions/logistics/ipo/createIPOAction.ts +8 -9
  42. package/src/data/actions/logistics/ipo/updateIpoAction.ts +12 -7
  43. package/src/index.ts +3 -0
  44. package/src/types/e-commerce/enduser/types.ts +15 -0
@@ -4,10 +4,12 @@ import Divider from "@mui/material/Divider";
4
4
  import Paper from "@mui/material/Paper";
5
5
  import Box from "@mui/material/Box";
6
6
  import Stack from "@mui/material/Stack";
7
+ import Grid from "@mui/material/Grid";
7
8
  import Alert from "@mui/material/Alert";
8
9
  import TextField from "@mui/material/TextField";
9
10
  import Typography from "@mui/material/Typography";
10
11
  import Checkbox from "@mui/material/Checkbox";
12
+ import Button from "@mui/material/Button";
11
13
 
12
14
  import { AddressFields } from "../../common/Address";
13
15
  import { AddressProps } from "@/types/AddressProps";
@@ -15,9 +17,9 @@ import { BusinessCredentialsProps } from "@/types/e-commerce/BusinessCredentials
15
17
  import { SubmitButton } from "../../SubmitButton";
16
18
  import { useFormState } from "react-dom";
17
19
  import { updateDispatcherProfileAction } from "../../../data/actions/logistics/dispatcher/profile-actions"; //"@/data/actions/profile-actions";
18
- import { StrapiErrors } from "../../StrapiErrors"; //"@/components/StrapiErrors";
19
20
  import { BusinessCredentialsFields } from "../../e-commerce/customer/BusinessCredentials";
20
21
  import { useSession } from "../../../context/auth/SessionContext";
22
+ import { useSnackbar } from "../../../context/common/SnackbarContext";
21
23
  import React, { useEffect, useState } from "react";
22
24
  import { DispatcherProfileProps } from "../../../types/logistics/dispatcher/types";
23
25
  import { SxProps } from "@mui/material";
@@ -27,89 +29,111 @@ const INITIAL_STATE = {
27
29
  strapiErrors: null,
28
30
  data: null,
29
31
  message: null,
32
+ severity: null,
30
33
  };
31
34
 
32
- /* interface DispatcherProfileProps {
33
- id: string;
34
- uuid: string;
35
- dispatcher_number: string;
36
- first_name: string;
37
- last_name: string;
38
- email: string;
39
- phone: string;
40
- company_address: AddressProps;
41
- delivery_address: AddressProps;
42
- billing_address: AddressProps;
43
- business_credentials: BusinessCredentialsProps;
44
- } */
45
-
46
35
  export default function DispatcherProfileEditForm({
47
36
  data,
48
37
  sx,
38
+ revalidateCallback,
39
+ handleClose,
49
40
  }: {
50
41
  readonly data: DispatcherProfileProps;
51
42
  sx?: SxProps;
43
+ revalidateCallback?: () => void;
44
+ handleClose?: () => void;
52
45
  }) {
53
46
  const { id, uuid, dispatcher_number, address, business_credentials } = data;
47
+ const boundAction = updateDispatcherProfileAction.bind(null, parseInt(id));
48
+ const [formState, formAction] = useFormState(boundAction, INITIAL_STATE);
49
+ const { handleAddMessage } = useSnackbar();
50
+ const { refreshSession } = useSession();
54
51
 
55
- const [formState, formAction] = useFormState(
56
- updateDispatcherProfileAction,
57
- INITIAL_STATE
58
- );
52
+ useEffect(() => {
53
+ if (formState?.message) {
54
+ handleAddMessage({
55
+ message: formState.message,
56
+ severity: formState.severity || "error",
57
+ });
58
+
59
+ if (formState.severity === "success") {
60
+ refreshSession();
61
+ revalidateCallback && revalidateCallback();
62
+ handleClose && handleClose();
63
+ }
64
+ }
65
+ }, [formState?.message]);
59
66
 
60
- // const { refreshSession } = useSession();
61
- //
62
- // useEffect(() => {
63
- // if (!formState.strapiErrors && formState.message) {
64
- // refreshSession();
65
- // }
66
- // }, [formState]);
67
+ useEffect(() => {
68
+ if (formState?.strapiErrors) {
69
+ handleAddMessage({
70
+ message: formState.strapiErrors.message || "Error performing action",
71
+ severity: "error",
72
+ });
73
+ }
74
+ }, [formState?.strapiErrors]);
67
75
 
68
76
  return (
69
- <Box
70
- sx={[
71
- // You cannot spread `sx` directly because `SxProps` (typeof sx) can be an array.
72
- { p: 2 },
73
- ...(Array.isArray(sx) ? sx : [sx]),
74
- ]}
75
- component={Paper}
76
- >
77
+ <Box sx={[...(Array.isArray(sx) ? sx : [sx])]}>
77
78
  <form action={formAction}>
78
- <Stack spacing={2}>
79
- {/* maybe this could be a repeatble component */}
79
+ <Grid container spacing={2}>
80
+ <Grid item xs={12}>
81
+ <Stack spacing={2}>
82
+ <Typography variant="h3" component="h1" gutterBottom>
83
+ Edit Profile
84
+ </Typography>
85
+ </Stack>
86
+ </Grid>
80
87
 
81
- <input type="hidden" name="id" value={id} />
82
- <Typography variant="h6">Business Credentials</Typography>
83
- <Divider />
84
- <BusinessCredentialsFields
85
- componentName="business_credentials"
86
- componentReference="business.credentials" // common.business-credentials ???
87
- data={business_credentials}
88
- />
89
- <Typography variant="h6">Company Address</Typography>
90
- <Divider />
91
- <AddressFields
92
- componentName="address"
93
- componentReference="common.address"
94
- data={address}
95
- />
88
+ <Grid item xs={12}>
89
+ <Paper sx={{ p: 2 }}>
90
+ <Typography variant="h6" gutterBottom>
91
+ Business Credentials
92
+ </Typography>
93
+ <Divider sx={{ mb: 2 }} />
94
+ <BusinessCredentialsFields
95
+ componentName="business_credentials"
96
+ componentReference="business.credentials"
97
+ data={business_credentials}
98
+ />
99
+ </Paper>
100
+ </Grid>
96
101
 
97
- <Stack
98
- direction="row-reverse"
99
- spacing={2}
100
- alignItems={"center"}
101
- sx={{
102
- py: 1,
103
- }}
104
- >
105
- <SubmitButton text="save changes" loadingText="loading" />
106
- <StrapiErrors error={formState?.strapiErrors} />
102
+ <Grid item xs={12}>
103
+ <Paper sx={{ p: 2 }}>
104
+ <Typography variant="h6" gutterBottom>
105
+ Company Address
106
+ </Typography>
107
+ <Divider sx={{ mb: 2 }} />
108
+ <AddressFields
109
+ componentName="address"
110
+ componentReference="common.address"
111
+ data={address}
112
+ />
113
+ </Paper>
114
+ </Grid>
107
115
 
108
- {formState?.message && (
109
- <Alert severity="error">{formState?.message}</Alert>
110
- )}
111
- </Stack>
112
- </Stack>
116
+ <Grid item xs={12}>
117
+ <Stack
118
+ direction="row"
119
+ justifyContent="space-between"
120
+ spacing={2}
121
+ alignItems="center"
122
+ sx={{ mt: 2 }}
123
+ >
124
+ {handleClose && (
125
+ <Button onClick={handleClose} variant="outlined">
126
+ Cancel
127
+ </Button>
128
+ )}
129
+ <SubmitButton
130
+ text="Save Changes"
131
+ loadingText="Saving..."
132
+ variant="contained"
133
+ />
134
+ </Stack>
135
+ </Grid>
136
+ </Grid>
113
137
  </form>
114
138
  </Box>
115
139
  );
@@ -8,6 +8,7 @@ import Alert from "@mui/material/Alert";
8
8
  import TextField from "@mui/material/TextField";
9
9
  import Typography from "@mui/material/Typography";
10
10
  import Divider from "@mui/material/Divider";
11
+ import Button from "@mui/material/Button";
11
12
 
12
13
  import { SubmitButton } from "../../SubmitButton";
13
14
  import { useFormState } from "react-dom";
@@ -28,7 +29,7 @@ import { SxProps, Theme } from "@mui/material/styles";
28
29
  import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
29
30
  import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
30
31
  import { DatePicker } from "@mui/x-date-pickers/DatePicker";
31
-
32
+ import { useSnackbar } from "../../../context/common/SnackbarContext";
32
33
  // TODO: order date should be set by the user
33
34
 
34
35
  const INITIAL_STATE = {
@@ -36,18 +37,47 @@ const INITIAL_STATE = {
36
37
  strapiErrors: null,
37
38
  data: null,
38
39
  message: null,
40
+ severity: null,
39
41
  };
40
42
 
41
43
  export function AddIPOForm({
42
44
  vendorNamesArr,
43
45
  sx,
46
+ revalidateCallback,
47
+ handleClose,
44
48
  }: {
45
49
  vendorNamesArr: VendorName[];
46
50
  sx?: SxProps<Theme>;
51
+ revalidateCallback?: () => void;
52
+ handleClose?: () => void;
47
53
  }) {
48
54
  const [formState, formAction] = useFormState(createIPOAction, INITIAL_STATE);
49
55
  const [productsArr, setProductsArr] = useState<VendorProductName[]>([]);
50
56
  const [vendorID, setVendorID] = useState<number | null>(null);
57
+ const { handleAddMessage } = useSnackbar();
58
+
59
+ useEffect(() => {
60
+ if (formState?.message) {
61
+ handleAddMessage({
62
+ message: formState.message,
63
+ severity: formState.severity || "error",
64
+ });
65
+
66
+ if (formState.severity === "success") {
67
+ revalidateCallback && revalidateCallback();
68
+ handleClose && handleClose();
69
+ }
70
+ }
71
+ }, [formState?.message]);
72
+
73
+ useEffect(() => {
74
+ if (formState?.strapiErrors) {
75
+ handleAddMessage({
76
+ message: formState.strapiErrors.message || "Error performing action",
77
+ severity: "error",
78
+ });
79
+ }
80
+ }, [formState?.strapiErrors]);
51
81
 
52
82
  const handleVendorSelect = async (selectedVendorID: number | null) => {
53
83
  setVendorID(selectedVendorID);
@@ -71,7 +101,14 @@ export function AddIPOForm({
71
101
  <form action={formAction}>
72
102
  <Grid container spacing={2}>
73
103
  <Grid item xs={12}>
74
- <Typography variant="h5">Add IPO</Typography>
104
+ <Stack spacing={2}>
105
+ <Typography variant="h3" component="h1">
106
+ Add IPO
107
+ </Typography>
108
+ <Typography variant="body1">
109
+ Create a new incoming purchase order
110
+ </Typography>
111
+ </Stack>
75
112
  </Grid>
76
113
 
77
114
  <Grid item xs={12} md={6} sx={{ mt: 1 }}>
@@ -118,25 +155,25 @@ export function AddIPOForm({
118
155
  <Grid item xs={12}>
119
156
  <IPOItemFields productsArr={productsArr} vendorID={vendorID} />
120
157
  </Grid>
121
- </Grid>
122
- <Grid item xs={12}>
123
- <Stack
124
- direction="row-reverse"
125
- spacing={2}
126
- alignItems={"center"}
127
- sx={{
128
- py: 1,
129
- }}
130
- >
131
- <SubmitButton text="create new ipo" loadingText="loading" />
132
- {formState?.strapiErrors && (
133
- <StrapiErrors error={formState?.strapiErrors} />
134
- )}
135
-
136
- {formState?.message && (
137
- <Alert severity="error">{formState?.message}</Alert>
138
- )}
139
- </Stack>
158
+ <Grid item xs={12}>
159
+ <Stack
160
+ direction="row"
161
+ justifyContent="space-between"
162
+ alignItems="center"
163
+ sx={{ mt: 2 }}
164
+ >
165
+ {handleClose && (
166
+ <Button onClick={handleClose} variant="outlined">
167
+ Cancel
168
+ </Button>
169
+ )}
170
+ <SubmitButton
171
+ text="Create IPO"
172
+ loadingText="Creating..."
173
+ variant="contained"
174
+ />
175
+ </Stack>
176
+ </Grid>
140
177
  </Grid>
141
178
  </form>
142
179
  </Box>