-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7ece38
commit 76008ba
Showing
131 changed files
with
2,066 additions
and
1,427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import HasPermission from "../../components/HasPermission" | ||
import {Link} from "react-router-dom" | ||
import {useTranslation} from "react-i18next" | ||
import {useState} from "react" | ||
import {createColumnHelper, getCoreRowModel, SortingState, useReactTable} from "@tanstack/react-table" | ||
import AvoRedTable from "../../components/AvoRedTable" | ||
import {getFormattedDate} from "../../lib/common" | ||
import _ from "lodash" | ||
import {useCollectionTable} from "./hooks/useCollectionTable"; | ||
import {CollectionType} from "../../types/collection/CollectionType"; | ||
|
||
export const CollectionTable = (() => { | ||
const [t] = useTranslation("global") | ||
const [sorting, setSorting] = useState<SortingState>([]); | ||
const [pagination, setPagination] = useState({ | ||
pageIndex: 0, //initial page index | ||
pageSize: 10, //default page size | ||
}); | ||
|
||
const customSorting = ((sorting: any) => { | ||
setSorting(sorting) | ||
}) | ||
|
||
const collection_api_table_response = useCollectionTable({ | ||
order: sorting.map((s) => `${s.id}:${s.desc ? 'DESC' : 'ASC'}`).join(','), | ||
page: pagination.pageIndex | ||
}); | ||
const customPagination = (async (pagination: any) => { | ||
setPagination(pagination) | ||
}) | ||
const collections: Array<CollectionType> = _.get(collection_api_table_response, 'data.data.data', []) | ||
|
||
const columnHelper = createColumnHelper<CollectionType>() | ||
const columns = [ | ||
columnHelper.accessor('id', { | ||
cell: info => info.getValue(), | ||
header: t("id") | ||
}), | ||
columnHelper.accessor('name', { | ||
cell: info => info.getValue(), | ||
header: t("name") | ||
}), | ||
columnHelper.accessor('identifier', { | ||
cell: info => info.getValue(), | ||
header: t("identifier") | ||
}), | ||
columnHelper.accessor('created_at', { | ||
id: "created_at", | ||
cell: info => getFormattedDate(info.getValue()), | ||
header: t("created_at") | ||
}), | ||
columnHelper.accessor('created_by', { | ||
cell: info => info.getValue(), | ||
header: t("created_by") | ||
}), | ||
columnHelper.accessor('updated_at', { | ||
cell: info => getFormattedDate(info.getValue()), | ||
header: t("updated_at") | ||
}), | ||
columnHelper.accessor('updated_by', { | ||
cell: info => info.getValue(), | ||
header: t("updated_by") | ||
}), | ||
columnHelper.accessor('action', { | ||
cell: info => { | ||
return ( | ||
<HasPermission displayDenied={false} identifier="collection_edit"> | ||
<Link | ||
className="font-medium text-primary-600 hover:text-primary-800" | ||
to={`/admin/collection-edit/${info.row.original.id}`} | ||
> | ||
{t("edit")} | ||
</Link> | ||
</HasPermission> | ||
) | ||
}, | ||
enableSorting: false, | ||
header: t("action"), | ||
enableHiding: false | ||
}), | ||
] | ||
const table = useReactTable({ | ||
data: collections, | ||
columns, | ||
getCoreRowModel: getCoreRowModel(), | ||
rowCount: collection_api_table_response.data?.data.pagination.total, | ||
onPaginationChange: customPagination, | ||
manualPagination: true, | ||
initialState: { | ||
pagination, | ||
columnVisibility: { | ||
created_at: false, | ||
created_by: false | ||
} | ||
}, | ||
manualSorting: true, | ||
onSortingChange: customSorting, | ||
state: { | ||
sorting, | ||
pagination | ||
}, | ||
}) | ||
|
||
return ( | ||
<> | ||
<div className="px-5"> | ||
<div className="flex items-center"> | ||
<div className="p-5 text-2xl font-semibold text-primary-500"> | ||
{t("collection")} | ||
</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="/admin/collection-create" | ||
> | ||
{t("create")} | ||
</Link> | ||
</HasPermission> | ||
</div> | ||
</div> | ||
|
||
<div className="overflow-x-auto"> | ||
<HasPermission identifier="collection_table"> | ||
<AvoRedTable table={table}/> | ||
</HasPermission> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
}) |
35 changes: 35 additions & 0 deletions
35
react-admin/src/pages/collection/hooks/useCollectionTable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {useQuery} from '@tanstack/react-query' | ||
import { useAxios } from '../../../hooks/useAxios' | ||
import _ from 'lodash' | ||
import {useNavigate} from 'react-router-dom' | ||
import PaginateType from "../../../types/misc/PaginateType"; | ||
|
||
export const useCollectionTable = (query: PaginateType) => { | ||
let params: URLSearchParams = new URLSearchParams(); | ||
if (query.page && query.page > 0) { | ||
params.append("page", query.page.toString()) | ||
} | ||
if (query.order && query.order !== "") { | ||
params.append("order", query.order) | ||
} | ||
let query_string = ""; | ||
if (params.toString() !== "") { | ||
query_string = "?" + params.toString() | ||
} | ||
|
||
const client = useAxios(); | ||
const redirect = useNavigate(); | ||
return useQuery({ | ||
queryKey: ['collection-table', query], | ||
queryFn: (async () => { | ||
try { | ||
return await client.get("/collection" + query_string) | ||
} catch (error) { | ||
if (_.get(error, 'response.status') === 401) { | ||
localStorage.removeItem('AUTH_TOKEN') | ||
redirect("/admin/login") | ||
} | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export type CollectionType = { | ||
id: string; | ||
name: string; | ||
identifier: string; | ||
created_at: string; | ||
updated_at: string; | ||
created_by: string; | ||
updated_by: string; | ||
action?: string; | ||
} |
19 changes: 11 additions & 8 deletions
19
src/api/handlers/admin_user/admin_user_forgot_password_api_handler.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.