umwd-components 0.1.657 → 0.1.660

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 (23) hide show
  1. package/.ai/instructions/form-patterns.instructions.md +140 -0
  2. package/.ai/prompts/form-patterns.prompt.md +156 -0
  3. package/dist/src/components/e-commerce/categories/EditCategoryForm.js +1 -1
  4. package/dist/src/components/e-commerce/customer/CustomerProfileEditForm.js +1 -1
  5. package/dist/src/components/e-commerce/invoice/CreateInvoiceForm.js +1 -1
  6. package/dist/src/components/e-commerce/iro/CreateIROForm.js +1 -1
  7. package/dist/src/components/e-commerce/iro/TextualManageIROForm.js +1 -1
  8. package/dist/src/components/e-commerce/opo/TextualManageOpoForm.js +1 -1
  9. package/dist/src/components/logistics/dispatcher/DispatcherProfileEditForm.js +1 -1
  10. package/dist/src/data/actions/e-commerce/opo/updateOpoAction.js +1 -1
  11. package/dist/tsconfig.build.tsbuildinfo +1 -1
  12. package/dist/types/components/e-commerce/customer/CustomerProfileEditForm.d.ts +3 -1
  13. package/dist/types/components/logistics/dispatcher/DispatcherProfileEditForm.d.ts +3 -1
  14. package/dist/types/data/actions/e-commerce/opo/updateOpoAction.d.ts +1 -1
  15. package/package.json +1 -1
  16. package/src/components/e-commerce/categories/EditCategoryForm.tsx +2 -0
  17. package/src/components/e-commerce/customer/CustomerProfileEditForm.tsx +167 -121
  18. package/src/components/e-commerce/invoice/CreateInvoiceForm.tsx +7 -2
  19. package/src/components/e-commerce/iro/CreateIROForm.tsx +12 -7
  20. package/src/components/e-commerce/iro/TextualManageIROForm.tsx +24 -16
  21. package/src/components/e-commerce/opo/TextualManageOpoForm.tsx +54 -28
  22. package/src/components/logistics/dispatcher/DispatcherProfileEditForm.tsx +90 -63
  23. package/src/data/actions/e-commerce/opo/updateOpoAction.ts +6 -2
@@ -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,114 @@ 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;
54
-
55
47
  const [formState, formAction] = useFormState(
56
48
  updateDispatcherProfileAction,
57
49
  INITIAL_STATE
58
50
  );
51
+ const { handleAddMessage } = useSnackbar();
52
+ const { refreshSession } = useSession();
53
+
54
+ useEffect(() => {
55
+ if (formState?.message) {
56
+ handleAddMessage({
57
+ message: formState.message,
58
+ severity: formState.severity || "error",
59
+ });
60
+
61
+ if (formState.severity === "success") {
62
+ refreshSession();
63
+ revalidateCallback && revalidateCallback();
64
+ handleClose && handleClose();
65
+ }
66
+ }
67
+ }, [formState?.message]);
59
68
 
60
- // const { refreshSession } = useSession();
61
- //
62
- // useEffect(() => {
63
- // if (!formState.strapiErrors && formState.message) {
64
- // refreshSession();
65
- // }
66
- // }, [formState]);
69
+ useEffect(() => {
70
+ if (formState?.strapiErrors) {
71
+ handleAddMessage({
72
+ message: formState.strapiErrors.message || "Error performing action",
73
+ severity: "error",
74
+ });
75
+ }
76
+ }, [formState?.strapiErrors]);
67
77
 
68
78
  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
- >
79
+ <Box sx={[...(Array.isArray(sx) ? sx : [sx])]}>
77
80
  <form action={formAction}>
78
- <Stack spacing={2}>
79
- {/* maybe this could be a repeatble component */}
81
+ <Grid container spacing={2}>
82
+ <Grid item xs={12}>
83
+ <Stack spacing={2}>
84
+ <Typography variant="h3" component="h1" gutterBottom>
85
+ Edit Profile
86
+ </Typography>
87
+ </Stack>
88
+ </Grid>
80
89
 
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
- />
90
+ <Grid item xs={12}>
91
+ <input type="hidden" name="id" value={id} />
92
+ <Paper sx={{ p: 2 }}>
93
+ <Typography variant="h6" gutterBottom>
94
+ Business Credentials
95
+ </Typography>
96
+ <Divider sx={{ mb: 2 }} />
97
+ <BusinessCredentialsFields
98
+ componentName="business_credentials"
99
+ componentReference="business.credentials"
100
+ data={business_credentials}
101
+ />
102
+ </Paper>
103
+ </Grid>
96
104
 
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} />
105
+ <Grid item xs={12}>
106
+ <Paper sx={{ p: 2 }}>
107
+ <Typography variant="h6" gutterBottom>
108
+ Company Address
109
+ </Typography>
110
+ <Divider sx={{ mb: 2 }} />
111
+ <AddressFields
112
+ componentName="address"
113
+ componentReference="common.address"
114
+ data={address}
115
+ />
116
+ </Paper>
117
+ </Grid>
107
118
 
108
- {formState?.message && (
109
- <Alert severity="error">{formState?.message}</Alert>
110
- )}
111
- </Stack>
112
- </Stack>
119
+ <Grid item xs={12}>
120
+ <Stack
121
+ direction="row"
122
+ justifyContent="space-between"
123
+ spacing={2}
124
+ alignItems="center"
125
+ sx={{ mt: 2 }}
126
+ >
127
+ {handleClose && (
128
+ <Button onClick={handleClose} variant="outlined">
129
+ Cancel
130
+ </Button>
131
+ )}
132
+ <SubmitButton
133
+ text="Save Changes"
134
+ loadingText="Saving..."
135
+ variant="contained"
136
+ />
137
+ </Stack>
138
+ </Grid>
139
+ </Grid>
113
140
  </form>
114
141
  </Box>
115
142
  );
@@ -4,7 +4,11 @@ import { mutateData } from "../../../services/mutate-data";
4
4
  import { flattenAttributes } from "../../../../lib/utils";
5
5
  import { parseFormData } from "../../../../lib/parseFormData";
6
6
 
7
- export async function updateOpoAction(prevState: any, formData: FormData) {
7
+ export async function updateOpoAction(
8
+ id: number,
9
+ prevState: any,
10
+ formData: FormData
11
+ ) {
8
12
  const rawFormData = Object.fromEntries(formData);
9
13
 
10
14
  const parsedFormData = parseFormData(formData);
@@ -12,7 +16,7 @@ export async function updateOpoAction(prevState: any, formData: FormData) {
12
16
 
13
17
  const responseData = await mutateData(
14
18
  "PUT",
15
- `/api/opos/${rawFormData.id}`,
19
+ `/api/opos/${id}`,
16
20
  parsedFormData
17
21
  );
18
22