[offers][fix] fix list some offer frontend

pull/390/head
Zhang Ziqing 3 years ago
parent 91b41bdca9
commit c34f314bcc

@ -1,11 +1,13 @@
import Link from 'next/link'; import Link from 'next/link';
import type { OfferTableRowData } from '~/components/offers/table/types'; import type { DashboardOffer } from '../../../types/offers';
import { convertCurrencyToString } from '../../../utils/offers/currency';
import { formatDate } from '../../../utils/offers/time';
export type OfferTableRowProps = Readonly<{ row: OfferTableRowData }>; export type OfferTableRowProps = Readonly<{ row: DashboardOffer }>;
export default function OfferTableRow({ export default function OfferTableRow({
row: { company, date, id, profileId, salary, title, yoe }, row: { company, id, income, monthYearReceived, profileId, title, totalYoe },
}: OfferTableRowProps) { }: OfferTableRowProps) {
return ( return (
<tr <tr
@ -14,12 +16,12 @@ export default function OfferTableRow({
<th <th
className="whitespace-nowrap py-4 px-6 font-medium text-gray-900 dark:text-white" className="whitespace-nowrap py-4 px-6 font-medium text-gray-900 dark:text-white"
scope="row"> scope="row">
{company} {company.name}
</th> </th>
<td className="py-4 px-6">{title}</td> <td className="py-4 px-6">{title}</td>
<td className="py-4 px-6">{yoe}</td> <td className="py-4 px-6">{totalYoe}</td>
<td className="py-4 px-6">{salary}</td> <td className="py-4 px-6">{convertCurrencyToString(income)}</td>
<td className="py-4 px-6">{date}</td> <td className="py-4 px-6">{formatDate(monthYearReceived)}</td>
<td className="space-x-4 py-4 px-6"> <td className="space-x-4 py-4 px-6">
<Link <Link
className="font-medium text-indigo-600 hover:underline dark:text-indigo-500" className="font-medium text-indigo-600 hover:underline dark:text-indigo-500"

@ -2,18 +2,15 @@ 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 type {
OfferTableRowData,
PaginationType,
} from '~/components/offers/table/types';
import { YOE_CATEGORY } from '~/components/offers/table/types'; import { YOE_CATEGORY } from '~/components/offers/table/types';
import CurrencySelector from '~/utils/offers/currency/CurrencySelector'; import CurrencySelector from '~/utils/offers/currency/CurrencySelector';
import { formatDate } from '~/utils/offers/time';
import { trpc } from '~/utils/trpc'; import { trpc } from '~/utils/trpc';
import OffersRow from './OffersRow'; import OffersRow from './OffersRow';
import type { DashboardOffer, Paging } from '~/types/offers';
const NUMBER_OF_OFFERS_IN_PAGE = 10; const NUMBER_OF_OFFERS_IN_PAGE = 10;
export type OffersTableProps = Readonly<{ export type OffersTableProps = Readonly<{
companyFilter: string; companyFilter: string;
@ -25,18 +22,18 @@ export default function OffersTable({
}: OffersTableProps) { }: OffersTableProps) {
const [currency, setCurrency] = useState('SGD'); // TODO: Detect location const [currency, setCurrency] = useState('SGD'); // TODO: Detect location
const [selectedTab, setSelectedTab] = useState(YOE_CATEGORY.ENTRY); const [selectedTab, setSelectedTab] = useState(YOE_CATEGORY.ENTRY);
const [pagination, setPagination] = useState<PaginationType>({ const [pagination, setPagination] = useState<Paging>({
currentPage: 1, currentPage: 0,
numOfItems: 1, numOfItems: 0,
numOfPages: 0, numOfPages: 0,
totalItems: 0, totalItems: 0,
}); });
const [offers, setOffers] = useState<Array<OfferTableRowData>>([]); const [offers, setOffers] = useState<Array<DashboardOffer>>([]);
useEffect(() => { useEffect(() => {
setPagination({ setPagination({
currentPage: 1, currentPage: 0,
numOfItems: 1, numOfItems: 0,
numOfPages: 0, numOfPages: 0,
totalItems: 0, totalItems: 0,
}); });
@ -48,7 +45,7 @@ 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: pagination.currentPage - 1, offset: 0,
sortBy: '-monthYearReceived', sortBy: '-monthYearReceived',
title: jobTitleFilter, title: jobTitleFilter,
yoeCategory: selectedTab, yoeCategory: selectedTab,
@ -56,28 +53,19 @@ export default function OffersTable({
], ],
{ {
onSuccess: (response) => { onSuccess: (response) => {
const filteredData = response.data.map((res) => { // Const filteredData = response.data.map((res) => {
return { // return {
company: res.company.name, // company: res.company.name,
date: formatDate(res.monthYearReceived), // date: res.monthYearReceived,
id: res.OffersFullTime // id: res.id,
? res.OffersFullTime!.id // profileId: res.profileId,
: res.OffersIntern!.id, // income: res.income,
profileId: res.profileId, // title: res.title,
salary: res.OffersFullTime // yoe: res.totalYoe,
? res.OffersFullTime?.totalCompensation.value // };
: res.OffersIntern?.monthlySalary.value, // });
title: res.OffersFullTime ? res.OffersFullTime?.level : '', setOffers(response.data);
yoe: 100, setPagination(response.paging);
};
});
setOffers(filteredData);
setPagination({
currentPage: response.paging.currentPage + 1,
numOfItems: response.paging.numOfItems,
numOfPages: response.paging.numOfPages,
totalItems: response.paging.totalItems,
});
}, },
}, },
); );
@ -90,15 +78,15 @@ export default function OffersTable({
label="Table Navigation" label="Table Navigation"
tabs={[ tabs={[
{ {
label: 'Fresh Grad (0-3 YOE)', label: 'Fresh Grad (0-2 YOE)',
value: YOE_CATEGORY.ENTRY, value: YOE_CATEGORY.ENTRY,
}, },
{ {
label: 'Mid (4-7 YOE)', label: 'Mid (3-5 YOE)',
value: YOE_CATEGORY.MID, value: YOE_CATEGORY.MID,
}, },
{ {
label: 'Senior (8+ YOE)', label: 'Senior (6+ YOE)',
value: YOE_CATEGORY.SENIOR, value: YOE_CATEGORY.SENIOR,
}, },
{ {
@ -187,14 +175,11 @@ export default function OffersTable({
)} )}
<OffersTablePagination <OffersTablePagination
endNumber={ endNumber={
(pagination.currentPage - 1) * NUMBER_OF_OFFERS_IN_PAGE + pagination.currentPage * NUMBER_OF_OFFERS_IN_PAGE + offers.length
offers.length
} }
handlePageChange={handlePageChange} handlePageChange={handlePageChange}
pagination={pagination} pagination={pagination}
startNumber={ startNumber={pagination.currentPage * NUMBER_OF_OFFERS_IN_PAGE + 1}
(pagination.currentPage - 1) * NUMBER_OF_OFFERS_IN_PAGE + 1
}
/> />
</div> </div>
</div> </div>

@ -1,11 +1,11 @@
import { Pagination } from '@tih/ui'; import { Pagination } from '@tih/ui';
import type { PaginationType } from '~/components/offers/table/types'; import type { Paging } from '~/types/offers';
type OffersTablePaginationProps = Readonly<{ type OffersTablePaginationProps = Readonly<{
endNumber: number; endNumber: number;
handlePageChange: (page: number) => void; handlePageChange: (page: number) => void;
pagination: PaginationType; pagination: Paging;
startNumber: number; startNumber: number;
}>; }>;
@ -30,13 +30,13 @@ export default function OffersTablePagination({
</span> </span>
</span> </span>
<Pagination <Pagination
current={pagination.currentPage} current={pagination.currentPage + 1}
end={pagination.numOfPages} end={pagination.numOfPages}
label="Pagination" label="Pagination"
pagePadding={1} pagePadding={1}
start={1} start={1}
onSelect={(currPage) => { onSelect={(currPage) => {
handlePageChange(currPage); handlePageChange(currPage - 1);
}} }}
/> />
</nav> </nav>

@ -1,13 +1,3 @@
export type OfferTableRowData = {
company: string;
date: string;
id: string;
profileId: string;
salary: number | undefined;
title: string;
yoe: number;
};
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
export enum YOE_CATEGORY { export enum YOE_CATEGORY {
INTERN = 0, INTERN = 0,

Loading…
Cancel
Save