Skip to content

Commit

Permalink
added some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Jan 11, 2025
1 parent 9568093 commit 4263426
Show file tree
Hide file tree
Showing 21 changed files with 299 additions and 116 deletions.
8 changes: 4 additions & 4 deletions react-admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ import AvoRedApiTesting from "./pages/setting/AvoRedApiTesting";
import SettingPage from "./pages/setting/SettingPage";
import NotFoundPage from "./pages/NotFoundPage";
import ChangePassword from './pages/admin-user/ChangePassword';
import { ModelTablePage } from "./pages/models/ModelTablePage";
import {ModelCreatePage} from "./pages/models/ModelCreatePage";
import { ModelEditPage } from "./pages/models/ModelEditPage";
import {ComponentTablePage} from "./pages/component/ComponentTablePage";
import {CollectionTable} from "./pages/collection/CollectionTable";
import {CollectionEdit} from "./pages/collection/CollectionEdit";
import {CollectionCreate} from "./pages/collection/CollectionCreate";
import {ModelNew} from "./pages/models/ModelNew";
import {ContentTable} from "./pages/content/ContentTable";

function App() {
return (
Expand All @@ -55,10 +54,11 @@ function App() {
<Route path="/admin/role" element={<RoleTable />} />
<Route path="/admin/role-create" element={<RoleCreate />} />
<Route path="/admin/role-edit/:role_id" element={<RoleEdit />} />
<Route path="/admin/models" element={<ModelNew />} />
<Route path="/admin/content" element={<ContentTable />} />

<Route path="/admin/model-create" element={<ModelCreatePage />} />
<Route path="/admin/model-edit/:model_id" element={<ModelEditPage />} />
<Route path="/admin/collection" element={<CollectionTable />} />
<Route path="/admin/collections" element={<CollectionTable />} />
<Route path="/admin/collection-create" element={<CollectionCreate />} />
<Route path="/admin/collection-edit/:collection_id" element={<CollectionEdit />} />
<Route path="/admin/page" element={<PageTable />} />
Expand Down
36 changes: 18 additions & 18 deletions react-admin/src/layouts/partials/AppSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Link, Outlet} from "react-router-dom";
import {Menu} from "@headlessui/react";
import {Menu, MenuButton, MenuItem, MenuItems} from "@headlessui/react";
import {useTranslation} from "react-i18next";
import {
ChevronDownIcon,
Expand Down Expand Up @@ -50,12 +50,12 @@ function AppSidebar() {
</Link>
<Link
className="flex items-center w-full py-1 px-2 mt-3 rounded relative hover:text-white hover:bg-gray-700"
to={`/admin/collection`}
to={`/admin/collections`}
>
<div className="pr-2">
<CircleStackIcon className="h-6 w-6"/>
</div>
<div className="ml-2">{t("collection")}</div>
<div className="ml-2">{t("collections")}</div>
</Link>

<Link
Expand All @@ -79,12 +79,12 @@ function AppSidebar() {

<Link
className="flex items-center w-full py-1 px-2 mt-3 rounded relative hover:text-white hover:bg-gray-700"
to={`/admin/models`}
to={`/admin/content`}
>
<div className="pr-2">
<DeviceTabletIcon className="h-6 w-6"/>
</div>
<div className="ml-2">{t("models")}</div>
<div className="ml-2">{t("content")}</div>
</Link>

</li>
Expand All @@ -95,7 +95,7 @@ function AppSidebar() {
</div>

<Menu as="li" className="text-sm text-gray-500">
<Menu.Button
<MenuButton
className="flex items-center w-full py-1 px-2 mt-3 rounded relative hover:text-white hover:bg-gray-700">
<div className="pr-2">
<RocketLaunchIcon className="h-6 w-6"/>
Expand All @@ -104,40 +104,40 @@ function AppSidebar() {
<div className="absolute right-1.5 transition-transform duration-300">
<ChevronDownIcon className="h-6 w-6"/>
</div>
</Menu.Button>
</MenuButton>

<Menu.Items className="flex flex-col mt-2 pl-2 ml-3 border-l border-gray-700 space-y-1">
<Menu.Item as="li">
{({active}) => (
<MenuItems as="ul" className="flex flex-col mt-2 pl-2 ml-3 border-l border-gray-700 space-y-1">
<MenuItem as="li">
{() => (
<Link
to={`/admin/admin-user`}
className={`flex items-center w-full py-1 px-2 rounded relative hover:text-white hover:bg-gray-700`}
>
<div>{t("sidebar.admin_user")}</div>
</Link>
)}
</Menu.Item>
<Menu.Item as="li">
{({active}) => (
</MenuItem>
<MenuItem as="li">
{() => (
<Link
to={`/admin/role`}
className={`flex items-center w-full py-1 px-2 rounded relative hover:text-white hover:bg-gray-700`}
>
<div>{t("sidebar.role")}</div>
</Link>
)}
</Menu.Item>
<Menu.Item>
{({active}) => (
</MenuItem>
<MenuItem>
{() => (
<Link
to={`/admin/setting`}
className={`flex items-center w-full py-1 px-2 rounded relative hover:text-white hover:bg-gray-700`}
>
{t("sidebar.setting")}
</Link>
)}
</Menu.Item>
</Menu.Items>
</MenuItem>
</MenuItems>
</Menu>
</ul>
</nav>
Expand Down
4 changes: 2 additions & 2 deletions react-admin/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"table": "Table",
"permissions": "Permissions",
"page": "Page",
"collection": "Collection",
"collections": "Collections",
"role": "Role",
"general": "General",
"is_super_admin": "Is super admin",
Expand All @@ -91,7 +91,7 @@
"loading": "Loading...",
"component_information": "Component information",
"page_information": "Page Information",
"models": "Models",
"content": "Content",
"model_information": "Model Information",
"collection_information": "Collection Information",
"components": "Components",
Expand Down
2 changes: 1 addition & 1 deletion react-admin/src/pages/collection/CollectionCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const CollectionCreate = () => {
{t("save")}
</button>
<Link
to="/admin/collection"
to="/admin/collections"
className="ml-auto font-medium text-gray-600 hover:text-gray-500"
>
{t("cancel")}
Expand Down
2 changes: 1 addition & 1 deletion react-admin/src/pages/collection/CollectionEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const CollectionEdit = (() => {
{t("save")}
</button>
<Link
to={`/admin/collection`}
to={`/admin/collections`}
className="ml-auto font-medium text-gray-600 hover:text-gray-500"
>
{t("cancel")}
Expand Down
6 changes: 3 additions & 3 deletions react-admin/src/pages/collection/hooks/useStoreCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import {useMutation} from '@tanstack/react-query'
import { useAxios } from '../../../hooks/useAxios'
import _ from 'lodash'
import {useNavigate} from 'react-router-dom'
import {CreatableModelType} from "../../../types/model/CreatableModelType";
import {CreatableCollectionType} from "../../../types/collection/CreatableCollectionType";

export const useStoreCollection = () => {
const client = useAxios();
const redirect = useNavigate();
return useMutation({
mutationFn: async (data: CreatableModelType) => {
mutationFn: async (data: CreatableCollectionType) => {
return await client.post('/collection', JSON.stringify(data));
},
onSuccess: (res) => {
if (_.get(res, 'data.status') === true) {
redirect("/admin/collection")
redirect("/admin/collections")
}
}
})
Expand Down
37 changes: 37 additions & 0 deletions react-admin/src/pages/content/ContentSidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {Link, useSearchParams} from "react-router-dom";
import {useTranslation} from "react-i18next";
import {useCollectionAll} from "./hooks/useCollectionAll";
import {CollectionType} from "../../types/collection/CollectionType";
import _ from 'lodash';

export const ContentSidebar = (() => {
const [t] = useTranslation("global");
const [searchParams] = useSearchParams()
const collections_api_response = useCollectionAll()
const collections: Array<CollectionType> = _.get(collections_api_response, 'data.data.data', [])
return (
<>
<div className="text-primary-500 font-semibold">
{t("collections")}
</div>

<ul className="mt-5">
{collections.map((collection: CollectionType) => {
return (
<li key={collection.id}>
<Link
to={`/admin/content?type=${encodeURI(collection.identifier)}`}
key={collection.identifier}
className={`rounded block mt-3 p-3 text-sm cursor-pointer ${searchParams.get("type") === collection.identifier ? 'text-primary-600 font-semibold bg-gray-300' : ''} overflow-x-hidden`}
>
{collection.name}
</Link>
</li>
)
})}


</ul>
</>
)
})
42 changes: 42 additions & 0 deletions react-admin/src/pages/content/ContentTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {useTranslation} from "react-i18next";
import {ContentSidebar} from "./ContentSidebar";
import {Link, useSearchParams} from "react-router-dom";
import HasPermission from "../../components/HasPermission";

export const ContentTable = (() => {
const [t] = useTranslation("global");
const [searchParams] = useSearchParams()
const collectionType = searchParams.get("type")

return (
<div className="flex w-full">
<div className="p-5 w-64 bg-gray-50 min-h-screen">
<ContentSidebar />
</div>
<div className="p-5 flex-1">
{collectionType ?
<div className="flex items-center w-full">
<div className="p-5 text-2xl font-semibold text-primary-500">
{t("collection type table title")}
</div>
<div className="ml-auto">
<HasPermission displayDenied={false} identifier="collection_create">
<Link
className="bg-primary-600 py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
to={encodeURI(`/admin/content-create?type=${collectionType}`)}
>
{t("create")}
</Link>
</HasPermission>
</div>
</div>
:
<>
{t('please select a collection from sidebar to see the collections entries.')}
</>
}
</div>
</div>

)
})
25 changes: 25 additions & 0 deletions react-admin/src/pages/content/hooks/useCollectionAll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {useQuery} from '@tanstack/react-query'
import { useAxios } from '../../../hooks/useAxios'
import _ from 'lodash'
import {useNavigate} from 'react-router-dom'

export const useCollectionAll = () => {

const client = useAxios();
const redirect = useNavigate();
return useQuery({
queryKey: ['collection-all'],
queryFn: (async () => {
try {
return await client.get("/collection-all")
} catch (error) {
if (_.get(error, 'response.status') === 401) {
localStorage.removeItem('AUTH_TOKEN')
redirect("/admin/login")
}

console.error(error)
}
})
})
}
Loading

0 comments on commit 4263426

Please sign in to comment.