[offers][feat] add filters for table and fix pagination (#402)

* [offers][feat] add filters for table and fix pagination

* [offers][fix] display currency
This commit is contained in:
Zhang Ziqing
2022-10-20 23:39:07 +08:00
committed by GitHub
parent 7c467d2e0e
commit 0adec461d0
4 changed files with 68 additions and 33 deletions

View File

@ -2,7 +2,12 @@ import { useEffect, useState } from 'react';
import { HorizontalDivider, Select, Spinner, Tabs } from '@tih/ui'; import { HorizontalDivider, Select, Spinner, Tabs } from '@tih/ui';
import OffersTablePagination from '~/components/offers/table/OffersTablePagination'; import OffersTablePagination from '~/components/offers/table/OffersTablePagination';
import { YOE_CATEGORY } from '~/components/offers/table/types'; import {
OfferTableFilterOptions,
OfferTableSortBy,
OfferTableTabOptions,
YOE_CATEGORY,
} from '~/components/offers/table/types';
import CurrencySelector from '~/utils/offers/currency/CurrencySelector'; import CurrencySelector from '~/utils/offers/currency/CurrencySelector';
import { trpc } from '~/utils/trpc'; import { trpc } from '~/utils/trpc';
@ -29,7 +34,9 @@ export default function OffersTable({
totalItems: 0, totalItems: 0,
}); });
const [offers, setOffers] = useState<Array<DashboardOffer>>([]); const [offers, setOffers] = useState<Array<DashboardOffer>>([]);
const [selectedFilter, setSelectedFilter] = useState(
OfferTableFilterOptions[0].value,
);
useEffect(() => { useEffect(() => {
setPagination({ setPagination({
currentPage: 0, currentPage: 0,
@ -45,13 +52,16 @@ export default function OffersTable({
companyId: companyFilter, companyId: companyFilter,
limit: NUMBER_OF_OFFERS_IN_PAGE, limit: NUMBER_OF_OFFERS_IN_PAGE,
location: 'Singapore, Singapore', // TODO: Geolocation location: 'Singapore, Singapore', // TODO: Geolocation
offset: 0, offset: pagination.currentPage,
sortBy: '-monthYearReceived', sortBy: OfferTableSortBy[selectedFilter] ?? '-monthYearReceived',
title: jobTitleFilter, title: jobTitleFilter,
yoeCategory: selectedTab, yoeCategory: selectedTab,
}, },
], ],
{ {
onError: (err) => {
alert(err);
},
onSuccess: (response: GetOffersResponse) => { onSuccess: (response: GetOffersResponse) => {
setOffers(response.data); setOffers(response.data);
setPagination(response.paging); setPagination(response.paging);
@ -65,24 +75,7 @@ export default function OffersTable({
<div className="w-fit"> <div className="w-fit">
<Tabs <Tabs
label="Table Navigation" label="Table Navigation"
tabs={[ tabs={OfferTableTabOptions}
{
label: 'Fresh Grad (0-2 YOE)',
value: YOE_CATEGORY.ENTRY,
},
{
label: 'Mid (3-5 YOE)',
value: YOE_CATEGORY.MID,
},
{
label: 'Senior (6+ YOE)',
value: YOE_CATEGORY.SENIOR,
},
{
label: 'Internship',
value: YOE_CATEGORY.INTERN,
},
]}
value={selectedTab} value={selectedTab}
onChange={(value) => setSelectedTab(value)} onChange={(value) => setSelectedTab(value)}
/> />
@ -102,16 +95,11 @@ export default function OffersTable({
/> />
</div> </div>
<Select <Select
disabled={true}
isLabelHidden={true} isLabelHidden={true}
label="" label=""
options={[ options={OfferTableFilterOptions}
{ value={selectedFilter}
label: 'Latest Submitted', onChange={(value) => setSelectedFilter(value)}
value: 'latest-submitted',
},
]}
value="latest-submitted"
/> />
</div> </div>
); );
@ -139,7 +127,9 @@ export default function OffersTable({
} }
const handlePageChange = (currPage: number) => { const handlePageChange = (currPage: number) => {
setPagination({ ...pagination, currentPage: currPage }); if (0 < currPage && currPage < pagination.numOfPages) {
setPagination({ ...pagination, currentPage: currPage });
}
}; };
return ( return (

View File

@ -33,7 +33,7 @@ export default function OffersTablePagination({
current={pagination.currentPage + 1} current={pagination.currentPage + 1}
end={pagination.numOfPages} end={pagination.numOfPages}
label="Pagination" label="Pagination"
pagePadding={1} pagePadding={2}
start={1} start={1}
onSelect={(currPage) => { onSelect={(currPage) => {
handlePageChange(currPage - 1); handlePageChange(currPage - 1);

View File

@ -5,3 +5,48 @@ export enum YOE_CATEGORY {
MID = 2, MID = 2,
SENIOR = 3, SENIOR = 3,
} }
export const OfferTableTabOptions = [
{
label: 'Fresh Grad (0-2 YOE)',
value: YOE_CATEGORY.ENTRY,
},
{
label: 'Mid (3-5 YOE)',
value: YOE_CATEGORY.MID,
},
{
label: 'Senior (6+ YOE)',
value: YOE_CATEGORY.SENIOR,
},
{
label: 'Internship',
value: YOE_CATEGORY.INTERN,
},
];
export const OfferTableFilterOptions = [
{
label: 'Latest Submitted',
value: 'latest-submitted',
},
{
label: 'Highest Salary',
value: 'highest-salary',
},
{
label: 'Highest YOE first',
value: 'highest-yoe-first',
},
{
label: 'Lowest YOE first',
value: 'lowest-yoe-first',
},
];
export const OfferTableSortBy: Record<string, string> = {
'highest-salary': '-totalCompensation',
'highest-yoe-first': '-totalYoe',
'latest-submitted': '-monthYearReceived',
'lowest-yoe-first': '+totalYoe',
};

View File

@ -10,5 +10,5 @@ export function convertCurrencyToString({ currency, value }: Money) {
minimumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501) minimumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
style: 'currency', style: 'currency',
}); });
return `${formatter.format(10000)}`; /* $2,500.00 */ return `${formatter.format(value)}`;
} }