resources components refactoring
parent
8eb624f876
commit
234760c1f4
|
@ -14,8 +14,8 @@ import AppearancePage from "../../pages/settings/appearance/components/Appearanc
|
||||||
import ContentFooter from "./ContentFooter";
|
import ContentFooter from "./ContentFooter";
|
||||||
|
|
||||||
// containers
|
// containers
|
||||||
import ResourcesContainer from "../../features/resources/components/ResourcesContainer";
|
import ResourcesContainer from "../../features/resources/list/components/ResourcesContainer";
|
||||||
import ResourceContainer from "../../features/resources/components/ResourceContainer";
|
import ResourceContainer from "../../features/resources/edit/components/ResourceContainer";
|
||||||
|
|
||||||
// context
|
// context
|
||||||
import { useLayoutState } from "../../contexts/LayoutContext";
|
import { useLayoutState } from "../../contexts/LayoutContext";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import useHttpRequest from "./useHttpRequest";
|
import useHttpRequest from "../../../hooks/useHttpRequest";
|
||||||
import { get } from "../utils/axios";
|
import { get } from "../../../utils/axios";
|
||||||
|
|
||||||
const cdn = process.env.REACT_APP_CDN_URL;
|
const cdn = process.env.REACT_APP_CDN_URL;
|
||||||
const endpoints = {
|
const endpoints = {
|
|
@ -1,7 +1,7 @@
|
||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import useHttpRequest from "./useHttpRequest";
|
import useHttpRequest from "../../../hooks/useHttpRequest";
|
||||||
import { get } from "../utils/axios";
|
import { get } from "../../../utils/axios";
|
||||||
import { defaultResourcesFilters } from "../constants/resourcesConstants";
|
import { defaultResourcesFilters } from "../../../constants/resourcesConstants";
|
||||||
|
|
||||||
const cdn = process.env.REACT_APP_CDN_URL;
|
const cdn = process.env.REACT_APP_CDN_URL;
|
||||||
|
|
||||||
|
@ -41,8 +41,18 @@ const useResourcesApi = () => {
|
||||||
[exec]
|
[exec]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const getResource = useCallback(
|
||||||
|
(resourceId, options) => {
|
||||||
|
const endpoint = `${cdn}/admin/resource?ResourceId=${resourceId}`;
|
||||||
|
const promise = exec(() => get(endpoint), options);
|
||||||
|
return promise;
|
||||||
|
},
|
||||||
|
[exec]
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getResources
|
getResources,
|
||||||
|
getResource
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
import React from "react";
|
|
||||||
import PageTitle from "../../../components/PageTitle";
|
|
||||||
import { useParams } from "react-router-dom";
|
|
||||||
|
|
||||||
const ResourceContainer = () => {
|
|
||||||
const params = useParams();
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<PageTitle title={`Resource id: ${params.id}`} />
|
|
||||||
<>.................</>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ResourceContainer;
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
import React, { useState, useMemo, useEffect } from "react";
|
||||||
|
import PageTitle from "../../../../components/PageTitle";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
import { useResourcesApi } from "../../api";
|
||||||
|
import { LoadingText } from "../../../../components";
|
||||||
|
|
||||||
|
const ResourceContainer = () => {
|
||||||
|
const [state, setState] = useState(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const params = useParams();
|
||||||
|
const { getResource } = useResourcesApi();
|
||||||
|
|
||||||
|
const isNew = useMemo(() => params.id === "new", [params.id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isNew) return;
|
||||||
|
const resourceId = parseInt(params.id);
|
||||||
|
setLoading(true);
|
||||||
|
getResource(resourceId).then((resource) => {
|
||||||
|
setState(resource);
|
||||||
|
setLoading(false);
|
||||||
|
});
|
||||||
|
}, [getResource, isNew, params.id]);
|
||||||
|
|
||||||
|
if (loading || state === null) return <LoadingText lines={15} onPaper />;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<PageTitle title={state.resourceName} />
|
||||||
|
<>.................</>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ResourceContainer;
|
|
@ -1,10 +1,10 @@
|
||||||
import React, { useState, useEffect, useMemo, useCallback } from "react";
|
import React, { useState, useEffect, useMemo, useCallback } from "react";
|
||||||
import { Checkbox, FormLabel } from "@material-ui/core";
|
import { Checkbox, FormLabel } from "@material-ui/core";
|
||||||
import MUIDataTable, { debounceSearchRender } from "mui-datatables";
|
import MUIDataTable, { debounceSearchRender } from "mui-datatables";
|
||||||
import { LoadingText } from "../../../components";
|
import { LoadingText } from "../../../../components";
|
||||||
import PageTitle from "../../../components/PageTitle";
|
import PageTitle from "../../../../components/PageTitle";
|
||||||
import { useResourcesApi, useDictionariesApi } from "../../../api";
|
import { useResourcesApi, useDictionariesApi } from "../../api";
|
||||||
import { defaultResourcesFilters } from "../../../constants/resourcesConstants";
|
import { defaultResourcesFilters } from "../../../../constants/resourcesConstants";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import ActionButton from "./ActionButton";
|
import ActionButton from "./ActionButton";
|
||||||
import SecondaryActionsGroup from "./SecondaryActionsGroup";
|
import SecondaryActionsGroup from "./SecondaryActionsGroup";
|
||||||
|
@ -13,7 +13,7 @@ import {
|
||||||
FileCopyOutlined,
|
FileCopyOutlined,
|
||||||
OpenInNewOutlined
|
OpenInNewOutlined
|
||||||
} from "@material-ui/icons";
|
} from "@material-ui/icons";
|
||||||
import { useToast, useResourceSecurity } from "../../../hooks";
|
import { useToast, useResourceSecurity } from "../../../../hooks";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
|
|
||||||
const __ROWS_PER_PAGE_OPTIONS = [10, 20, 50, 100];
|
const __ROWS_PER_PAGE_OPTIONS = [10, 20, 50, 100];
|
|
@ -1,4 +1,5 @@
|
||||||
import { useToast } from "../contexts/ToastContext";
|
import { useToast } from "../contexts/ToastContext";
|
||||||
|
import useHttpRequest from "./useHttpRequest";
|
||||||
import useResourceSecurity from "./useResourceSecurity";
|
import useResourceSecurity from "./useResourceSecurity";
|
||||||
|
|
||||||
export { useToast, useResourceSecurity };
|
export { useToast, useHttpRequest, useResourceSecurity };
|
||||||
|
|
Loading…
Reference in New Issue