|
@@ -13,6 +13,18 @@ import { actionUploadFile } from "../../../actions/actionUploadFile";
|
|
import { ProfileImageEditor } from "../../common/ProfileImageEditor";
|
|
import { ProfileImageEditor } from "../../common/ProfileImageEditor";
|
|
import { actionPromisesClear } from "../../../actions/actionPromisesClear";
|
|
import { actionPromisesClear } from "../../../actions/actionPromisesClear";
|
|
|
|
|
|
|
|
+const styles = {
|
|
|
|
+ multiValue: (base, state) => {
|
|
|
|
+ return state.data.isFixed ? { ...base, backgroundColor: "gray" } : base;
|
|
|
|
+ },
|
|
|
|
+ multiValueLabel: (base, state) => {
|
|
|
|
+ return state.data.isFixed ? { ...base, fontWeight: "bold", color: "white", paddingRight: 6 } : base;
|
|
|
|
+ },
|
|
|
|
+ multiValueRemove: (base, state) => {
|
|
|
|
+ return state.data.isFixed ? { ...base, display: "none" } : base;
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+
|
|
const CProfileImageEditor = connect(null, {
|
|
const CProfileImageEditor = connect(null, {
|
|
onFileDrop: (acceptedFiles) => actionUploadFile(acceptedFiles[0]),
|
|
onFileDrop: (acceptedFiles) => actionUploadFile(acceptedFiles[0]),
|
|
})(ProfileImageEditor);
|
|
})(ProfileImageEditor);
|
|
@@ -42,6 +54,10 @@ export const UserForm = ({
|
|
const [acl, setAcl] = useState([]);
|
|
const [acl, setAcl] = useState([]);
|
|
const navigate = useNavigate();
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ console.log(promiseStatus);
|
|
|
|
+ }, [promiseStatus]);
|
|
|
|
+
|
|
const formik = useFormik({
|
|
const formik = useFormik({
|
|
initialValues: {
|
|
initialValues: {
|
|
name: "",
|
|
name: "",
|
|
@@ -55,7 +71,7 @@ export const UserForm = ({
|
|
let userToSave = {};
|
|
let userToSave = {};
|
|
userToSave = formik.values;
|
|
userToSave = formik.values;
|
|
user?._id && (userToSave._id = user._id);
|
|
user?._id && (userToSave._id = user._id);
|
|
- userToSave.acl = acl;
|
|
|
|
|
|
+ userToSave.acl = acl.map(({ value }) => value);
|
|
avatar ? (userToSave.avatar = avatar) : delete userToSave.avatar;
|
|
avatar ? (userToSave.avatar = avatar) : delete userToSave.avatar;
|
|
onSaveClick && onSaveClick();
|
|
onSaveClick && onSaveClick();
|
|
onSave(userToSave);
|
|
onSave(userToSave);
|
|
@@ -63,6 +79,27 @@ export const UserForm = ({
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ const orderOptions = (values) => {
|
|
|
|
+ return values.filter((v) => v.isFixed).concat(values.filter((v) => !v.isFixed));
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const onChange = (values, actionMeta) => {
|
|
|
|
+ switch (actionMeta.action) {
|
|
|
|
+ case "remove-value":
|
|
|
|
+ case "pop-value":
|
|
|
|
+ if (actionMeta.removedValue.isFixed) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "clear":
|
|
|
|
+ values = aclList.filter((acl) => acl.isFixed);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ values = orderOptions(values);
|
|
|
|
+ setAcl(values);
|
|
|
|
+ };
|
|
|
|
+
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
return () => {
|
|
return () => {
|
|
promiseTimeOut && clearTimeout(promiseTimeOut);
|
|
promiseTimeOut && clearTimeout(promiseTimeOut);
|
|
@@ -75,6 +112,7 @@ export const UserForm = ({
|
|
formik.setSubmitting(false);
|
|
formik.setSubmitting(false);
|
|
promiseTimeOut && clearTimeout(promiseTimeOut);
|
|
promiseTimeOut && clearTimeout(promiseTimeOut);
|
|
setPromiseTimeOut(null);
|
|
setPromiseTimeOut(null);
|
|
|
|
+
|
|
setAlert({
|
|
setAlert({
|
|
show: true,
|
|
show: true,
|
|
severity: "success",
|
|
severity: "success",
|
|
@@ -115,7 +153,7 @@ export const UserForm = ({
|
|
}, [deletePromiseStatus]);
|
|
}, [deletePromiseStatus]);
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- setAcl(user?.acl || []);
|
|
|
|
|
|
+ setAcl(orderOptions(aclList.filter((item) => user?.acl?.includes(item.value)) || []));
|
|
formik.setFieldValue("name", user.name || "");
|
|
formik.setFieldValue("name", user.name || "");
|
|
formik.setFieldValue("username", user.username || "");
|
|
formik.setFieldValue("username", user.username || "");
|
|
formik.setFieldValue("nick", user.nick || "");
|
|
formik.setFieldValue("nick", user.nick || "");
|
|
@@ -131,7 +169,7 @@ export const UserForm = ({
|
|
|
|
|
|
return (
|
|
return (
|
|
<Box className="UserForm" component="form" onSubmit={formik.handleSubmit}>
|
|
<Box className="UserForm" component="form" onSubmit={formik.handleSubmit}>
|
|
- <Grid container>
|
|
|
|
|
|
+ <Grid container spacing={2}>
|
|
<Grid item xs={5}>
|
|
<Grid item xs={5}>
|
|
<CProfileImageEditor avatar={avatar} />
|
|
<CProfileImageEditor avatar={avatar} />
|
|
</Grid>
|
|
</Grid>
|
|
@@ -210,11 +248,13 @@ export const UserForm = ({
|
|
<InputLabel>Permissions</InputLabel>
|
|
<InputLabel>Permissions</InputLabel>
|
|
<Select
|
|
<Select
|
|
placeholder="Обрати категорії"
|
|
placeholder="Обрати категорії"
|
|
- value={acl.map((value) => ({ value, label: value }))}
|
|
|
|
|
|
+ value={acl}
|
|
closeMenuOnSelect={false}
|
|
closeMenuOnSelect={false}
|
|
- onChange={(e) => setAcl(e.map(({ value }) => value))}
|
|
|
|
|
|
+ onChange={onChange}
|
|
options={aclList}
|
|
options={aclList}
|
|
|
|
+ isClearable={acl?.some((acl) => !acl.isFixed)}
|
|
isMulti={true}
|
|
isMulti={true}
|
|
|
|
+ styles={styles}
|
|
/>
|
|
/>
|
|
</Box>
|
|
</Box>
|
|
</Grid>
|
|
</Grid>
|