|
@@ -14,11 +14,11 @@ import { LackPermissions } from './LackPermissions';
|
|
import { CCategoryDropDownList } from './DropDownList';
|
|
import { CCategoryDropDownList } from './DropDownList';
|
|
|
|
|
|
|
|
|
|
-const EditableGood = ({ good: goodExt, maxWidth = 'md', saveGood, uploadFile }) => {
|
|
|
|
- const copyGood = goodExt => ({ ...goodExt, images: [ ...goodExt.images ] });
|
|
|
|
|
|
+const EditableGood = ({ good: goodExt, maxWidth = 'md', saveGood }) => {
|
|
|
|
+ const copyGood = goodExt => ({ ...goodExt, images: [ ...(goodExt.images ?? []) ] });
|
|
let [good, setGood] = useState(copyGood(goodExt));
|
|
let [good, setGood] = useState(copyGood(goodExt));
|
|
let [showPreview, setShowPreview] = useState(false);
|
|
let [showPreview, setShowPreview] = useState(false);
|
|
- let [imagesContainer, setImagesContainer] = useState({ images: [...goodExt.images] });
|
|
|
|
|
|
+ let [imagesContainer, setImagesContainer] = useState({ images: [...(goodExt.images ?? [])] });
|
|
|
|
|
|
const onSetCategory = (catItem) => {
|
|
const onSetCategory = (catItem) => {
|
|
good.categories = catItem.cat ? [{ _id: catItem.cat._id }] : [];
|
|
good.categories = catItem.cat ? [{ _id: catItem.cat._id }] : [];
|
|
@@ -152,8 +152,9 @@ const EditableGood = ({ good: goodExt, maxWidth = 'md', saveGood, uploadFile })
|
|
|
|
|
|
const CEditableGood = ({ maxWidth = 'md' }) => {
|
|
const CEditableGood = ({ maxWidth = 'md' }) => {
|
|
const { _id } = useParams();
|
|
const { _id } = useParams();
|
|
- const { isLoading, data } = useGetGoodByIdQuery(_id || 'fwkjelnfvkjwe');
|
|
|
|
- let good = isLoading ? { name: 'loading', goods: [] } : data?.GoodFindOne;
|
|
|
|
|
|
+ let { isLoading, data } = useGetGoodByIdQuery(_id || 'fwkjelnfvkjwe');
|
|
|
|
+ isLoading = _id ? isLoading : false;
|
|
|
|
+ let good = isLoading ? { name: 'loading', categories: [] } : data?.GoodFindOne;
|
|
const [saveGoodMutation, { }] = useSaveGoodMutation();
|
|
const [saveGoodMutation, { }] = useSaveGoodMutation();
|
|
const state = useSelector(state => state);
|
|
const state = useSelector(state => state);
|
|
let currentCategory = getCurrentEntity(frontEndNames.category, state)
|
|
let currentCategory = getCurrentEntity(frontEndNames.category, state)
|
|
@@ -162,10 +163,10 @@ const CEditableGood = ({ maxWidth = 'md' }) => {
|
|
|
|
|
|
if (!isLoading && !good && isAdmin) {
|
|
if (!isLoading && !good && isAdmin) {
|
|
let categories = currentCategory ? [{ _id: currentCategory._id, name: currentCategory.name }] : [];
|
|
let categories = currentCategory ? [{ _id: currentCategory._id, name: currentCategory.name }] : [];
|
|
- good = { _id: undefined, categories };
|
|
|
|
|
|
+ good = { _id: undefined, categories, images: [] };
|
|
}
|
|
}
|
|
|
|
|
|
- return !isLoading &&
|
|
|
|
|
|
+ return !isLoading &&
|
|
(isAdmin ? <EditableGood good={good} saveGood={saveGoodMutation} maxWidth={maxWidth} /> : <LackPermissions name="good" />)
|
|
(isAdmin ? <EditableGood good={good} saveGood={saveGoodMutation} maxWidth={maxWidth} /> : <LackPermissions name="good" />)
|
|
}
|
|
}
|
|
|
|
|