-
Notifications
You must be signed in to change notification settings - Fork 0
AYS-298 | Role Listing Page #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
06a96ab
feat(AYS-298): start of role listing page, (WIP) change/fix these commit
sanshigo345 824ead5
(WIP): rn everything in page stolen from evacuation, TODO adapt it to…
sanshigo345 141713b
AYS-298: (WIP) still need to fix the page
sanshigo345 1e4df94
feat(AYS-298): lot of bugs in the page, TODO fix search and localization
sanshigo345 c9b9270
AYS-298: (WIP) updated page a little bit, TODO fetch looks broken
sanshigo345 0a97163
AYS-298: fix formatDateTime for null dates
sanshigo345 d2b4179
AYS-298: working except order in role name
sanshigo345 6b821a5
AYS-298: add localization
sanshigo345 381cd18
AYS-298: fix localization of status and add colors to status
sanshigo345 a29626d
feat: add sort to createdAt instead name
sanshigo345 b5bee66
fix(AYS-298): add label to ARA created at column
sanshigo345 5512217
AYS-298: remove error condition
sanshigo345 44fac7a
AYS-298: remove error state and delete unused import
sanshigo345 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,97 @@ | ||
'use client' | ||
|
||
import { useEffect, useMemo, useState } from 'react' | ||
import PrivateRoute from '@/app/hocs/isAuth' | ||
import { useTranslation } from 'react-i18next' | ||
import { useToast } from '@/components/ui/use-toast' | ||
import { useSearchParams } from 'next/navigation' | ||
import { Permission } from '@/constants/permissions' | ||
import { postRoleListing } from '@/modules/roleListing/service' | ||
import { searchParamsSchema } from '@/modules/roleListing/constants/searchParamsSchema' | ||
import { RoleListing } from '@/modules/roleListing/constants/types' | ||
import { useDataTable } from '@/app/hocs/useDataTable' | ||
import { Toaster } from '@/components/ui/toaster' | ||
import { DataTable, DataTableToolbar } from '@/components/dataTable' | ||
import { columns } from '@/modules/roleListing/components/columns' | ||
import filterFields from '@/modules/roleListing/constants/filterFields' | ||
|
||
const Page = () => { | ||
const searchParams = useSearchParams() | ||
const search = searchParamsSchema.parse( | ||
Object.fromEntries(searchParams.entries()), | ||
) | ||
|
||
const { t } = useTranslation() | ||
const { toast } = useToast() | ||
const [data, setData] = useState<RoleListing>({ | ||
content: [], | ||
totalPageCount: 0, | ||
}) | ||
const [isLoading, setIsLoading] = useState<boolean>(false) | ||
const [error, setError] = useState<string | null>(null) | ||
const searchParamsString = useMemo(() => JSON.stringify(search), [search]) | ||
|
||
useEffect(() => { | ||
setIsLoading(true) | ||
postRoleListing({ | ||
page: search.page, | ||
per_page: search.per_page, | ||
sort: search.sort, | ||
status: search.status, | ||
name: search.name, | ||
createdAt: search.createdAt, | ||
updatedAt: search.updatedAt, | ||
}) | ||
.then((responseData) => { | ||
setData(responseData.data.response) | ||
}) | ||
.catch((error) => { | ||
setError(error.message) | ||
toast({ | ||
title: t('error'), | ||
description: t('defaultError'), | ||
variant: 'destructive', | ||
}) | ||
}) | ||
.finally(() => setIsLoading(false)) | ||
}, [ | ||
searchParamsString, | ||
search.createdAt, | ||
search.name, | ||
search.page, | ||
search.per_page, | ||
search.sort, | ||
search.status, | ||
search.updatedAt, | ||
t, | ||
toast, | ||
]) | ||
|
||
const { table } = useDataTable({ | ||
data: data.content, | ||
columns, | ||
pageCount: data.totalPageCount, | ||
filterFields, | ||
}) | ||
|
||
return ( | ||
<PrivateRoute requiredPermissions={[Permission.ROLE_LIST]}> | ||
<div className="space-y-1"> | ||
{error && <Toaster />} | ||
<DataTable | ||
className="px-2" | ||
table={table} | ||
loading={isLoading} | ||
enableRowClick | ||
> | ||
<div className="flex flex-col w-full gap-4"> | ||
<h1 className="text-2xl font-medium">{t('roleListing')}</h1> | ||
<DataTableToolbar table={table} filterFields={filterFields} /> | ||
</div> | ||
</DataTable> | ||
</div> | ||
</PrivateRoute> | ||
) | ||
} | ||
|
||
export default Page |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,37 @@ | ||
import { ColumnDef } from '@tanstack/table-core' | ||
import i18next from 'i18next' | ||
import { formatDateTime } from '@/lib/formatDateTime' | ||
import DataTableSort from '@/components/dataTable/dataTableSort' | ||
import { RoleListingTableProps } from '../constants/types'; | ||
import Status from './status'; | ||
|
||
export const columns: ColumnDef<RoleListingTableProps>[] = [ | ||
{ | ||
accessorKey: 'name', | ||
header: () => i18next.t("name"), | ||
cell: ({ row }) => row.original.name, | ||
size: 200, | ||
}, | ||
{ | ||
accessorKey: 'status', | ||
header: () => i18next.t('status'), | ||
cell: ({ row }) => <Status status={row.getValue('status')} />, | ||
size: 100, | ||
}, | ||
{ | ||
accessorKey: 'createdAt', | ||
header: ({ column }) => { | ||
return <DataTableSort column={column} label={i18next.t('createdAt')} /> | ||
}, | ||
cell: ({ row }) => { | ||
return <div className="px-2">{formatDateTime(row.getValue('createdAt'))}</div> | ||
}, | ||
size: 170, | ||
}, | ||
{ | ||
accessorKey: 'updatedAt', | ||
header: () => i18next.t('updatedDateTime'), | ||
cell: ({ row }) => <div className="px-2">{formatDateTime(row.getValue('updatedAt'))}</div>, | ||
size: 170, | ||
}, | ||
]; |
This file contains hidden or 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,37 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { cn } from '@/lib/utils' | ||
import { StatusProps } from '../constants/types' | ||
import { StatusData } from '../constants/status' | ||
|
||
const Status = ({ status }: StatusProps) => { | ||
const [statusData, setStatusData] = useState<{ | ||
label: string | ||
color: string | ||
}>({ label: '', color: '' }) | ||
const { t } = useTranslation() | ||
|
||
const getStatus = (status: string) => { | ||
const statusItem = StatusData.find((item) => item.value === status) | ||
const color = statusItem ? statusItem.color : '' | ||
const label = statusItem ? statusItem.label : '' | ||
return { color, label } | ||
} | ||
|
||
useEffect(() => { | ||
setStatusData(getStatus(status)) | ||
}, [status]) | ||
|
||
return ( | ||
<span | ||
className={cn( | ||
'inline-flex items-center rounded-md px-2 py-1 text-xs', | ||
statusData?.color, | ||
)} | ||
> | ||
{t(`${statusData.label}`)} | ||
</span> | ||
) | ||
} | ||
|
||
export default Status |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.