eleven-solutions-common-website-unique-web 1.0.33 → 1.0.35

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,219 +1,227 @@
1
+ // import React from "react";
2
+ // import { useState, useEffect } from "react";
3
+
4
+ // import { addUserApi, updateUserApi, fetchUserByIdApi } from "../api/user";
5
+
6
+ // const UserForm = () => {
7
+ // const [userName, setUserName] = useState("");
8
+ // const [email, setEmail] = useState("");
9
+ // const [mobile, setMobile] = useState("");
10
+ // const [address, setAddress] = useState("");
11
+ // const [roleType, setRoleType] = useState("");
12
+
13
+ // const [, setUser] = useState<any>(null);
14
+ // const [isEditMode, setIsEditMode] = useState<boolean>(false);
15
+
16
+ // const validateForm = () => {
17
+ // if (!userName || !email || !roleType) {
18
+ // alert(
19
+ // "Please fill in all required fields: User Name, Email, and Role Type."
20
+ // );
21
+ // return false;
22
+ // }
23
+ // return true;
24
+ // };
25
+
26
+ // // const location = useLocation();
27
+ // // // const navigate = useNavigate();
28
+
29
+ // // const { id } = location.state || {};
30
+
31
+ // const queryParams = new URLSearchParams(window.location.search);
32
+ // const id = queryParams.get("id");
33
+
34
+ // useEffect(() => {
35
+ // if (id) {
36
+ // const fetchUserData = async () => {
37
+ // try {
38
+ // const fetchedUser = await fetchUserByIdApi(id);
39
+ // if (fetchedUser) {
40
+ // const user = fetchedUser as {
41
+ // name: string;
42
+ // email: string;
43
+ // mobile: string;
44
+ // address: string;
45
+ // roleType: string;
46
+ // };
47
+ // setIsEditMode(true);
48
+ // setUser(user);
49
+ // setUserName(user.name);
50
+ // setEmail(user.email);
51
+ // setMobile(user.mobile);
52
+ // setAddress(user.address);
53
+ // setRoleType(user.roleType);
54
+ // }
55
+ // } catch (error) {
56
+ // console.error("Unable to fetch user data", error);
57
+ // }
58
+ // };
59
+ // fetchUserData();
60
+ // }
61
+ // }, [id]);
62
+
63
+ // // const handleSubmit = async (event: React.MouseEvent<HTMLButtonElement>) => {
64
+ // // event.preventDefault();
65
+ // // if (!validateForm()) return;
66
+
67
+ // // try {
68
+ // // if (isEditMode) {
69
+ // // await updateUserApi(id, userName, mobile, address, roleType);
70
+ // // alert("User updated successfully");
71
+ // // } else {
72
+ // // await addUserApi(userName, email, mobile, address, roleType);
73
+ // // alert("User added successfully");
74
+ // // }
75
+ // // navigate("/admin/user");
76
+ // // } catch (error) {
77
+ // // console.error("Error adding/updating User:", error);
78
+ // // alert("Failed to add/update User");
79
+ // // }
80
+ // // };
81
+
82
+ // const handleSubmit = async (event: React.MouseEvent<HTMLButtonElement>) => {
83
+ // event.preventDefault();
84
+ // if (!validateForm()) return;
85
+
86
+ // try {
87
+ // if (isEditMode) {
88
+ // await updateUserApi(id, userName, mobile, address, roleType);
89
+ // alert("User updated successfully");
90
+ // } else {
91
+ // await addUserApi(userName, email, mobile, address, roleType);
92
+ // alert("User added successfully");
93
+ // }
94
+ // window.location.href = "/admin/users";
95
+ // } catch (error) {
96
+ // console.error("Error adding/updating User:", error);
97
+ // alert("Failed to add/update User");
98
+ // }
99
+ // };
100
+
101
+ // // const handleCancelClick = () => {
102
+ // // setUserName("");
103
+ // // setEmail("");
104
+ // // setMobile("");
105
+ // // setAddress("");
106
+ // // setRoleType("");
107
+ // // navigate("/admin/user");
108
+ // // };
109
+
110
+ // const handleCancelClick = () => {
111
+ // setUserName("");
112
+ // setEmail("");
113
+ // setMobile("");
114
+ // setAddress("");
115
+ // setRoleType("");
116
+ // window.location.href = "/admin/users";
117
+ // };
118
+
119
+ // return (
120
+ // <div className="max-w-4xl p-6 mx-auto dark:bg-gray-800">
121
+ // <div>
122
+ // <form>
123
+ // <h1 className="text-3xl font-bold text-center text-blue-600 capitalize dark:text-white mb-4">
124
+ // {isEditMode ? "Edit User" : "Add User"}
125
+ // </h1>
126
+
127
+ // <div className="mb-6 w-full">
128
+ // <label className="text-gray-900 dark:text-gray-200 font-semibold">
129
+ // User Name <span className="text-red-500">*</span>
130
+ // </label>
131
+ // <input
132
+ // required
133
+ // value={userName}
134
+ // onChange={(e) => setUserName(e.target.value)}
135
+ // type="text"
136
+ // className="w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"
137
+ // placeholder="Enter User Name"
138
+ // />
139
+ // </div>
140
+ // <div className="mb-6 w-full">
141
+ // <label className="text-gray-900 dark:text-gray-200 font-semibold">
142
+ // Email <span className="text-red-500">*</span>
143
+ // </label>
144
+ // <input
145
+ // required
146
+ // value={email}
147
+ // onChange={(e) => setEmail(e.target.value)}
148
+ // type="email"
149
+ // className="w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"
150
+ // placeholder="Enter Email"
151
+ // disabled={isEditMode}
152
+ // />
153
+ // </div>
154
+ // <div className="mb-6 w-full">
155
+ // <label className="text-gray-900 dark:text-gray-200 font-semibold">
156
+ // Moblie Number
157
+ // </label>
158
+ // <input
159
+ // required
160
+ // value={mobile}
161
+ // onChange={(e) => setMobile(e.target.value)}
162
+ // type="number"
163
+ // className="w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"
164
+ // placeholder="Enter Mobile Number"
165
+ // />
166
+ // </div>
167
+ // <div className="mb-6 w-full">
168
+ // <label className="text-gray-900 dark:text-gray-200 font-semibold">
169
+ // Address
170
+ // </label>
171
+ // <input
172
+ // required
173
+ // value={address}
174
+ // onChange={(e) => setAddress(e.target.value)}
175
+ // type="text"
176
+ // className="w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"
177
+ // placeholder="Address"
178
+ // />
179
+ // </div>
180
+
181
+ // <div className="mb-6 w-full">
182
+ // <label className="text-gray-900 dark:text-gray-200 font-semibold">
183
+ // Role Type <span className="text-red-500">*</span>
184
+ // </label>
185
+ // <select
186
+ // required
187
+ // value={roleType}
188
+ // onChange={(e) => setRoleType(e.target.value)}
189
+ // className="w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"
190
+ // >
191
+ // <option value="">Select a Role Type</option>
192
+ // <option value="1">Guest</option>
193
+ // <option value="2">Admin</option>
194
+ // </select>
195
+ // </div>
196
+
197
+ // <div className="flex space-x-4 mt-6 justify-end">
198
+ // <button
199
+ // type="submit"
200
+ // onClick={handleSubmit}
201
+ // className="px-8 py-2.5 leading-5 text-white transition-colors duration-300 transform bg-blue-600 rounded-md hover:bg-blue-500 focus:outline-none focus:bg-gray-600"
202
+ // >
203
+ // {isEditMode ? "Edit" : "Add"}
204
+ // </button>
205
+ // <button
206
+ // type="button"
207
+ // onClick={handleCancelClick}
208
+ // className="px-8 py-2.5 leading-5 text-white transition-colors duration-300 transform bg-blue-600 rounded-md hover:bg-blue-500 focus:outline-none focus:bg-gray-600"
209
+ // >
210
+ // Cancel
211
+ // </button>
212
+ // </div>
213
+ // </form>
214
+ // </div>
215
+ // </div>
216
+ // );
217
+ // };
218
+
219
+ // export default UserForm;
220
+
1
221
  import React from "react";
2
- import { useState, useEffect } from "react";
3
-
4
- import { addUserApi, updateUserApi, fetchUserByIdApi } from "../api/user";
5
-
6
- const UserForm = () => {
7
- const [userName, setUserName] = useState("");
8
- const [email, setEmail] = useState("");
9
- const [mobile, setMobile] = useState("");
10
- const [address, setAddress] = useState("");
11
- const [roleType, setRoleType] = useState("");
12
-
13
- const [, setUser] = useState<any>(null);
14
- const [isEditMode, setIsEditMode] = useState<boolean>(false);
15
-
16
- const validateForm = () => {
17
- if (!userName || !email || !roleType) {
18
- alert(
19
- "Please fill in all required fields: User Name, Email, and Role Type."
20
- );
21
- return false;
22
- }
23
- return true;
24
- };
25
-
26
- // const location = useLocation();
27
- // // const navigate = useNavigate();
28
-
29
- // const { id } = location.state || {};
30
-
31
- const queryParams = new URLSearchParams(window.location.search);
32
- const id = queryParams.get("id");
33
-
34
- useEffect(() => {
35
- if (id) {
36
- const fetchUserData = async () => {
37
- try {
38
- const fetchedUser = await fetchUserByIdApi(id);
39
- if (fetchedUser) {
40
- const user = fetchedUser as {
41
- name: string;
42
- email: string;
43
- mobile: string;
44
- address: string;
45
- roleType: string;
46
- };
47
- setIsEditMode(true);
48
- setUser(user);
49
- setUserName(user.name);
50
- setEmail(user.email);
51
- setMobile(user.mobile);
52
- setAddress(user.address);
53
- setRoleType(user.roleType);
54
- }
55
- } catch (error) {
56
- console.error("Unable to fetch user data", error);
57
- }
58
- };
59
- fetchUserData();
60
- }
61
- }, [id]);
62
-
63
- // const handleSubmit = async (event: React.MouseEvent<HTMLButtonElement>) => {
64
- // event.preventDefault();
65
- // if (!validateForm()) return;
66
-
67
- // try {
68
- // if (isEditMode) {
69
- // await updateUserApi(id, userName, mobile, address, roleType);
70
- // alert("User updated successfully");
71
- // } else {
72
- // await addUserApi(userName, email, mobile, address, roleType);
73
- // alert("User added successfully");
74
- // }
75
- // navigate("/admin/user");
76
- // } catch (error) {
77
- // console.error("Error adding/updating User:", error);
78
- // alert("Failed to add/update User");
79
- // }
80
- // };
81
-
82
- const handleSubmit = async (event: React.MouseEvent<HTMLButtonElement>) => {
83
- event.preventDefault();
84
- if (!validateForm()) return;
85
-
86
- try {
87
- if (isEditMode) {
88
- await updateUserApi(id, userName, mobile, address, roleType);
89
- alert("User updated successfully");
90
- } else {
91
- await addUserApi(userName, email, mobile, address, roleType);
92
- alert("User added successfully");
93
- }
94
- window.location.href = "/admin/users";
95
- } catch (error) {
96
- console.error("Error adding/updating User:", error);
97
- alert("Failed to add/update User");
98
- }
99
- };
100
-
101
- // const handleCancelClick = () => {
102
- // setUserName("");
103
- // setEmail("");
104
- // setMobile("");
105
- // setAddress("");
106
- // setRoleType("");
107
- // navigate("/admin/user");
108
- // };
109
-
110
- const handleCancelClick = () => {
111
- setUserName("");
112
- setEmail("");
113
- setMobile("");
114
- setAddress("");
115
- setRoleType("");
116
- window.location.href = "/admin/users";
117
- };
118
-
119
- return (
120
- <div className="max-w-4xl p-6 mx-auto dark:bg-gray-800">
121
- <div>
122
- <form>
123
- <h1 className="text-3xl font-bold text-center text-blue-600 capitalize dark:text-white mb-4">
124
- {isEditMode ? "Edit User" : "Add User"}
125
- </h1>
126
-
127
- <div className="mb-6 w-full">
128
- <label className="text-gray-900 dark:text-gray-200 font-semibold">
129
- User Name <span className="text-red-500">*</span>
130
- </label>
131
- <input
132
- required
133
- value={userName}
134
- onChange={(e) => setUserName(e.target.value)}
135
- type="text"
136
- className="w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"
137
- placeholder="Enter User Name"
138
- />
139
- </div>
140
- <div className="mb-6 w-full">
141
- <label className="text-gray-900 dark:text-gray-200 font-semibold">
142
- Email <span className="text-red-500">*</span>
143
- </label>
144
- <input
145
- required
146
- value={email}
147
- onChange={(e) => setEmail(e.target.value)}
148
- type="email"
149
- className="w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"
150
- placeholder="Enter Email"
151
- disabled={isEditMode}
152
- />
153
- </div>
154
- <div className="mb-6 w-full">
155
- <label className="text-gray-900 dark:text-gray-200 font-semibold">
156
- Moblie Number
157
- </label>
158
- <input
159
- required
160
- value={mobile}
161
- onChange={(e) => setMobile(e.target.value)}
162
- type="number"
163
- className="w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"
164
- placeholder="Enter Mobile Number"
165
- />
166
- </div>
167
- <div className="mb-6 w-full">
168
- <label className="text-gray-900 dark:text-gray-200 font-semibold">
169
- Address
170
- </label>
171
- <input
172
- required
173
- value={address}
174
- onChange={(e) => setAddress(e.target.value)}
175
- type="text"
176
- className="w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"
177
- placeholder="Address"
178
- />
179
- </div>
180
-
181
- <div className="mb-6 w-full">
182
- <label className="text-gray-900 dark:text-gray-200 font-semibold">
183
- Role Type <span className="text-red-500">*</span>
184
- </label>
185
- <select
186
- required
187
- value={roleType}
188
- onChange={(e) => setRoleType(e.target.value)}
189
- className="w-full px-4 py-2 mt-2 text-gray-800 bg-white border border-gray-400 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-800 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"
190
- >
191
- <option value="">Select a Role Type</option>
192
- <option value="1">Guest</option>
193
- <option value="2">Admin</option>
194
- </select>
195
- </div>
196
-
197
- <div className="flex space-x-4 mt-6 justify-end">
198
- <button
199
- type="submit"
200
- onClick={handleSubmit}
201
- className="px-8 py-2.5 leading-5 text-white transition-colors duration-300 transform bg-blue-600 rounded-md hover:bg-blue-500 focus:outline-none focus:bg-gray-600"
202
- >
203
- {isEditMode ? "Edit" : "Add"}
204
- </button>
205
- <button
206
- type="button"
207
- onClick={handleCancelClick}
208
- className="px-8 py-2.5 leading-5 text-white transition-colors duration-300 transform bg-blue-600 rounded-md hover:bg-blue-500 focus:outline-none focus:bg-gray-600"
209
- >
210
- Cancel
211
- </button>
212
- </div>
213
- </form>
214
- </div>
215
- </div>
216
- );
217
- };
222
+
223
+ function UserForm() {
224
+ return <div>UserForm</div>;
225
+ }
218
226
 
219
227
  export default UserForm;