diff --git a/components/dashboard/userAccount/detailUser/information/Form.js b/components/dashboard/userAccount/detailUser/information/Form.js
index 05c0ae0..efb01a7 100644
--- a/components/dashboard/userAccount/detailUser/information/Form.js
+++ b/components/dashboard/userAccount/detailUser/information/Form.js
@@ -1,6 +1,7 @@
import Content from "./Content";
import DateBirthday from "./DateBirthday";
-import Field from "./Field";
+import AutoSelector from "./component/AutoSelector";
+import Field from "./component/Field";
import {
gender,
blood_group,
@@ -8,14 +9,22 @@ import {
education,
job,
} from "./listSelector";
-import AutoSelector from "@/app/component/element/AutoSelector";
-function Form({ data, userInfo, insurance, changeData, prevData }) {
+function Form({
+ data,
+ userInfo,
+ insurance,
+ errors,
+ prevInfo,
+ changeData,
+ prevData,
+}) {
const findVal = (list, name) =>
data && list && list.length && list.find((g) => g.id === data[name]);
+ console.log(errors);
return (
-
+
-
+
-
+
-
+
+
+
+
changeData(data === "زن" ? "female" : "male", "value", name)
}
@@ -57,15 +80,17 @@ function Form({ data, userInfo, insurance, changeData, prevData }) {
list={gender}
/>
-
+
-
+
-
+
-
+
changeData(
blood_group.find((g) => g.label === value).id,
@@ -112,8 +145,9 @@ function Form({ data, userInfo, insurance, changeData, prevData }) {
list={blood_group}
/>
-
+
changeData(value === "متاهل" ? "married" : "single", "value", name)
}
@@ -133,8 +167,9 @@ function Form({ data, userInfo, insurance, changeData, prevData }) {
name="home_phone"
/>
-
+
changeData(
education.find((g) => g.label === value).id,
@@ -148,8 +183,9 @@ function Form({ data, userInfo, insurance, changeData, prevData }) {
list={education}
/>
-
+
changeData(value === "آزاد" ? "azad" : "dolati", "value", name)
}
diff --git a/components/dashboard/userAccount/detailUser/information/component/AutoSelector.js b/components/dashboard/userAccount/detailUser/information/component/AutoSelector.js
new file mode 100644
index 0000000..5a506fe
--- /dev/null
+++ b/components/dashboard/userAccount/detailUser/information/component/AutoSelector.js
@@ -0,0 +1,101 @@
+import BottomSelect from "@/components/icons/BottomSelect";
+import { Autocomplete, Button, TextField } from "@mui/material";
+import { styleTextSelectRight } from "@/mui";
+
+function AutoSelector({
+ list,
+ value,
+ isError,
+ updateData,
+ label,
+ error,
+ disabled = false,
+ listboxProps,
+ name,
+}) {
+ return (
+ {
+ if (typeof option === "string") return option;
+ return option?.name || option?.label || "";
+ }}
+ className="!w-full !rounded-lg auto-complete-selector"
+ onChange={(e, newValue) => {
+ updateData(name, newValue?.label || newValue || "");
+ }}
+ sx={{
+ ...styleTextSelectRight,
+ // Hide Icon Number
+ "& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button":
+ {
+ display: "none",
+ },
+ "& input[type=number]": {
+ MozAppearance: "textfield",
+ },
+ "& .MuiInputBase-input": { padding: "12.5px 14px !important" },
+ "& .MuiInputBase-root": {
+ borderRadius: 2,
+ padding: "0 !important",
+ height: {
+ xs: "43px !important",
+ sm: "43px !important",
+ md: "46px !important",
+ lg: "48px !important",
+ },
+ },
+ "& .MuiOutlinedInput-notchedOutline": {
+ border: error
+ ? "1px solid red !important"
+ : "1px solid #D7D7D7 !important",
+ },
+ "& .MuiInput-underline:hover:not(.Mui-disabled):before, .MuiOutlinedInput-notchedOutline":
+ {
+ borderColor: error ? "red !important" : "#D7D7D7 !important",
+ },
+ "& .muirtl-1kiro5a-MuiInputBase-root-MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline":
+ {
+ border: "1px solid #5559CE !important",
+ },
+ "& .MuiOutlinedInput-notchedOutline": {
+ border: isError ? "1px solid red !important" : "",
+ },
+ }}
+ renderOption={(props, option) => (
+
+ )}
+ renderInput={(params) => (
+
+
+
+ ),
+ }}
+ placeholder={label}
+ sx={{
+ borderRadius: "8px",
+ }}
+ />
+ )}
+ />
+ );
+}
+
+export default AutoSelector;
diff --git a/components/dashboard/userAccount/detailUser/information/Field.js b/components/dashboard/userAccount/detailUser/information/component/Field.js
similarity index 87%
rename from components/dashboard/userAccount/detailUser/information/Field.js
rename to components/dashboard/userAccount/detailUser/information/component/Field.js
index 85a12aa..7b7dad7 100644
--- a/components/dashboard/userAccount/detailUser/information/Field.js
+++ b/components/dashboard/userAccount/detailUser/information/component/Field.js
@@ -10,6 +10,7 @@ function Field({
data,
name,
iconGray,
+ error,
isTransparent,
type,
props,
@@ -24,19 +25,22 @@ function Field({
disabled={disable}
type={type || "text"}
placeholder={placeholder || ""}
- className={`!w-full res-field-account dark:!bg-transparent ${
+ className={`!w-full res-field-account dark:!bg-transparent ${
isTransparent ? "!bg-transparent lg:!bg-[#FFF]" : "!bg-[#FFF]"
}`}
onChange={(e) => {
changeData(e.target.value, "value", name);
}}
sx={{
+ // border: "1px solid red !important",
"& .MuiFormLabel-root": {
top: "-4px !important",
},
"& .MuiInputBase-input": { padding: "12.5px 14px" },
"& .MuiOutlinedInput-notchedOutline": {
- border: "1px solid #D7D7D7 !important",
+ border: error
+ ? "1px solid red !important"
+ : "1px solid #D7D7D7 !important",
},
"& .MuiInputBase-root": {
padding: "0 !important",
diff --git a/components/dashboard/userAccount/detailUser/information/index.js b/components/dashboard/userAccount/detailUser/information/index.js
index d106103..2cadc8b 100644
--- a/components/dashboard/userAccount/detailUser/information/index.js
+++ b/components/dashboard/userAccount/detailUser/information/index.js
@@ -10,13 +10,17 @@ function Information({
data,
setData,
userInfo,
+ prevInfo,
dataUser,
initialData,
+ information,
+ setInformation,
updateDataUser,
}) {
const [disable, setDisable] = useState(true);
- const [loading, setLoading] = useState(false);
const [insurance, setInsurance] = useState();
+ const [loading, setLoading] = useState(false);
+ const [errors, setErrors] = useState();
useEffect(() => {
request.getInsuranceType().then((res) => {
@@ -28,43 +32,54 @@ function Information({
}, []);
const changeData = (value, type, name) => {
- disable && setDisable(false);
- setData({
- ...data,
+ setInformation({
+ ...information,
[name]: value,
});
};
+ const validationInfo = () => {};
+
const sendReq = () => {
setLoading(true);
- console.log(data);
+ console.log(prevInfo);
+ console.log(prevInfo ? true : false);
+ if (!validationInfo())
+ request[prevInfo ? "patchUserProfile" : "postUserProfile"](
+ data,
+ prevInfo ? prevInfo.uuid : Cookies.get("uuid")
+ )
+ .then((res) => {
+ console.log(res);
- request[dataUser ? "patchUserProfile" : "postUserProfile"](
- data,
- dataUser ? dataUser.uuid : Cookies.get("uuid")
- )
- .then(() => {
- if (!dataUser) {
- updateDataUser();
- }
- setLoading(false);
- })
- .catch(() => {
- setLoading(false);
- });
+ if (!dataUser) {
+ updateDataUser();
+ }
+ setLoading(false);
+ })
+ .catch((err) => {
+ console.log(err);
+ console.log(err?.response?.data);
+ if (err?.response?.data) {
+ setErrors(err.response.data);
+ }
+
+ setLoading(false);
+ });
};
return (