|
|
@ -1,16 +1,21 @@
|
|
|
|
import clsx from 'clsx';
|
|
|
|
|
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
|
import { JobType } from '@prisma/client';
|
|
|
|
import { JobType } from '@prisma/client';
|
|
|
|
import { DropdownMenu, Spinner, useToast } from '@tih/ui';
|
|
|
|
import { DropdownMenu, Spinner, useToast } from '@tih/ui';
|
|
|
|
|
|
|
|
|
|
|
|
import { useGoogleAnalytics } from '~/components/global/GoogleAnalytics';
|
|
|
|
import { useGoogleAnalytics } from '~/components/global/GoogleAnalytics';
|
|
|
|
|
|
|
|
import OffersRow from '~/components/offers/table//OffersRow';
|
|
|
|
|
|
|
|
import OffersHeader from '~/components/offers/table/OffersHeader';
|
|
|
|
import OffersTablePagination from '~/components/offers/table/OffersTablePagination';
|
|
|
|
import OffersTablePagination from '~/components/offers/table/OffersTablePagination';
|
|
|
|
import type { OfferTableSortByType } from '~/components/offers/table/types';
|
|
|
|
import type {
|
|
|
|
|
|
|
|
OfferTableColumn,
|
|
|
|
|
|
|
|
OfferTableSortType,
|
|
|
|
|
|
|
|
} from '~/components/offers/table/types';
|
|
|
|
|
|
|
|
import { OFFER_TABLE_SORT_ORDER } from '~/components/offers/table/types';
|
|
|
|
|
|
|
|
import { InternOfferTableColumns } from '~/components/offers/table/types';
|
|
|
|
|
|
|
|
import { FullTimeOfferTableColumns } from '~/components/offers/table/types';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
OfferTableFilterOptions,
|
|
|
|
|
|
|
|
OfferTableYoeOptions,
|
|
|
|
OfferTableYoeOptions,
|
|
|
|
YOE_CATEGORY,
|
|
|
|
|
|
|
|
YOE_CATEGORY_PARAM,
|
|
|
|
YOE_CATEGORY_PARAM,
|
|
|
|
} from '~/components/offers/table/types';
|
|
|
|
} from '~/components/offers/table/types';
|
|
|
|
|
|
|
|
|
|
|
@ -19,8 +24,6 @@ import CurrencySelector from '~/utils/offers/currency/CurrencySelector';
|
|
|
|
import { useSearchParamSingle } from '~/utils/offers/useSearchParam';
|
|
|
|
import { useSearchParamSingle } from '~/utils/offers/useSearchParam';
|
|
|
|
import { trpc } from '~/utils/trpc';
|
|
|
|
import { trpc } from '~/utils/trpc';
|
|
|
|
|
|
|
|
|
|
|
|
import OffersRow from './OffersRow';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import type { DashboardOffer, GetOffersResponse, Paging } from '~/types/offers';
|
|
|
|
import type { DashboardOffer, GetOffersResponse, Paging } from '~/types/offers';
|
|
|
|
|
|
|
|
|
|
|
|
const NUMBER_OF_OFFERS_PER_PAGE = 20;
|
|
|
|
const NUMBER_OF_OFFERS_PER_PAGE = 20;
|
|
|
@ -63,12 +66,26 @@ export default function OffersTable({
|
|
|
|
isYoeCategoryInitialized,
|
|
|
|
isYoeCategoryInitialized,
|
|
|
|
] = useSearchParamSingle<keyof typeof YOE_CATEGORY_PARAM>('yoeCategory');
|
|
|
|
] = useSearchParamSingle<keyof typeof YOE_CATEGORY_PARAM>('yoeCategory');
|
|
|
|
|
|
|
|
|
|
|
|
const [selectedSortBy, setSelectedSortBy, isSortByInitialized] =
|
|
|
|
const [
|
|
|
|
useSearchParamSingle<OfferTableSortByType>('sortBy');
|
|
|
|
selectedSortDirection,
|
|
|
|
|
|
|
|
setSelectedSortDirection,
|
|
|
|
|
|
|
|
isSortDirectionInitialized,
|
|
|
|
|
|
|
|
] = useSearchParamSingle<OFFER_TABLE_SORT_ORDER>('sortDirection');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [selectedSortType, setSelectedSortType, isSortTypeInitialized] =
|
|
|
|
|
|
|
|
useSearchParamSingle<OfferTableSortType>('sortType');
|
|
|
|
|
|
|
|
|
|
|
|
const areFilterParamsInitialized = useMemo(() => {
|
|
|
|
const areFilterParamsInitialized = useMemo(() => {
|
|
|
|
return isYoeCategoryInitialized && isSortByInitialized;
|
|
|
|
return (
|
|
|
|
}, [isYoeCategoryInitialized, isSortByInitialized]);
|
|
|
|
isYoeCategoryInitialized &&
|
|
|
|
|
|
|
|
isSortDirectionInitialized &&
|
|
|
|
|
|
|
|
isSortTypeInitialized
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}, [
|
|
|
|
|
|
|
|
isYoeCategoryInitialized,
|
|
|
|
|
|
|
|
isSortDirectionInitialized,
|
|
|
|
|
|
|
|
isSortTypeInitialized,
|
|
|
|
|
|
|
|
]);
|
|
|
|
const { pathname } = router;
|
|
|
|
const { pathname } = router;
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
@ -80,7 +97,8 @@ export default function OffersTable({
|
|
|
|
companyId: companyFilter,
|
|
|
|
companyId: companyFilter,
|
|
|
|
companyName,
|
|
|
|
companyName,
|
|
|
|
jobTitleId: jobTitleFilter,
|
|
|
|
jobTitleId: jobTitleFilter,
|
|
|
|
sortBy: selectedSortBy,
|
|
|
|
sortDirection: selectedSortDirection,
|
|
|
|
|
|
|
|
sortType: selectedSortType,
|
|
|
|
yoeCategory: selectedYoeCategory,
|
|
|
|
yoeCategory: selectedYoeCategory,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -102,11 +120,16 @@ export default function OffersTable({
|
|
|
|
countryFilter,
|
|
|
|
countryFilter,
|
|
|
|
companyFilter,
|
|
|
|
companyFilter,
|
|
|
|
jobTitleFilter,
|
|
|
|
jobTitleFilter,
|
|
|
|
selectedSortBy,
|
|
|
|
selectedSortDirection,
|
|
|
|
|
|
|
|
selectedSortType,
|
|
|
|
selectedYoeCategory,
|
|
|
|
selectedYoeCategory,
|
|
|
|
pathname,
|
|
|
|
pathname,
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
setSelectedSortDirection(OFFER_TABLE_SORT_ORDER.UNSORTED);
|
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
|
|
|
}, [selectedYoeCategory]);
|
|
|
|
const topRef = useRef<HTMLDivElement>(null);
|
|
|
|
const topRef = useRef<HTMLDivElement>(null);
|
|
|
|
const { showToast } = useToast();
|
|
|
|
const { showToast } = useToast();
|
|
|
|
const { isLoading: isResultsLoading } = trpc.useQuery(
|
|
|
|
const { isLoading: isResultsLoading } = trpc.useQuery(
|
|
|
@ -118,7 +141,11 @@ export default function OffersTable({
|
|
|
|
currency,
|
|
|
|
currency,
|
|
|
|
limit: NUMBER_OF_OFFERS_PER_PAGE,
|
|
|
|
limit: NUMBER_OF_OFFERS_PER_PAGE,
|
|
|
|
offset: pagination.currentPage,
|
|
|
|
offset: pagination.currentPage,
|
|
|
|
sortBy: selectedSortBy ?? '-monthYearReceived',
|
|
|
|
// SortBy: selectedSortBy ?? '-monthYearReceived',
|
|
|
|
|
|
|
|
sortBy:
|
|
|
|
|
|
|
|
selectedSortDirection && selectedSortType
|
|
|
|
|
|
|
|
? `${selectedSortDirection}${selectedSortType}`
|
|
|
|
|
|
|
|
: '-monthYearReceived',
|
|
|
|
title: jobTitleFilter,
|
|
|
|
title: jobTitleFilter,
|
|
|
|
yoeCategory: selectedYoeCategory
|
|
|
|
yoeCategory: selectedYoeCategory
|
|
|
|
? YOE_CATEGORY_PARAM[selectedYoeCategory as string]
|
|
|
|
? YOE_CATEGORY_PARAM[selectedYoeCategory as string]
|
|
|
@ -131,6 +158,7 @@ export default function OffersTable({
|
|
|
|
title: 'Error loading the page.',
|
|
|
|
title: 'Error loading the page.',
|
|
|
|
variant: 'failure',
|
|
|
|
variant: 'failure',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
setIsLoading(false);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onSuccess: (response: GetOffersResponse) => {
|
|
|
|
onSuccess: (response: GetOffersResponse) => {
|
|
|
|
setOffers(response.data);
|
|
|
|
setOffers(response.data);
|
|
|
@ -141,6 +169,19 @@ export default function OffersTable({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const onSort = (
|
|
|
|
|
|
|
|
sortDirection: OFFER_TABLE_SORT_ORDER,
|
|
|
|
|
|
|
|
sortType: OfferTableSortType,
|
|
|
|
|
|
|
|
) => {
|
|
|
|
|
|
|
|
gaEvent({
|
|
|
|
|
|
|
|
action: 'offers_table_sort',
|
|
|
|
|
|
|
|
category: 'engagement',
|
|
|
|
|
|
|
|
label: `${sortType} - ${sortDirection}`,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
setSelectedSortType(sortType);
|
|
|
|
|
|
|
|
setSelectedSortDirection(sortDirection);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function renderFilters() {
|
|
|
|
function renderFilters() {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="flex items-center justify-between p-4 text-xs text-slate-700 sm:grid-cols-4 sm:text-sm md:text-base">
|
|
|
|
<div className="flex items-center justify-between p-4 text-xs text-slate-700 sm:grid-cols-4 sm:text-sm md:text-base">
|
|
|
@ -182,75 +223,33 @@ export default function OffersTable({
|
|
|
|
selectedCurrency={currency}
|
|
|
|
selectedCurrency={currency}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="pl-4">
|
|
|
|
|
|
|
|
<DropdownMenu
|
|
|
|
|
|
|
|
align="end"
|
|
|
|
|
|
|
|
label={
|
|
|
|
|
|
|
|
OfferTableFilterOptions.filter(
|
|
|
|
|
|
|
|
({ value: itemValue }) => itemValue === selectedSortBy,
|
|
|
|
|
|
|
|
).length > 0
|
|
|
|
|
|
|
|
? OfferTableFilterOptions.filter(
|
|
|
|
|
|
|
|
({ value: itemValue }) => itemValue === selectedSortBy,
|
|
|
|
|
|
|
|
)[0].label
|
|
|
|
|
|
|
|
: OfferTableFilterOptions[0].label
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
size="inherit">
|
|
|
|
|
|
|
|
{OfferTableFilterOptions.map(({ label: itemLabel, value }) => (
|
|
|
|
|
|
|
|
<DropdownMenu.Item
|
|
|
|
|
|
|
|
key={value}
|
|
|
|
|
|
|
|
isSelected={value === selectedSortBy}
|
|
|
|
|
|
|
|
label={itemLabel}
|
|
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
|
|
setSelectedSortBy(value as OfferTableSortByType);
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function renderHeader() {
|
|
|
|
function renderHeader() {
|
|
|
|
let columns = [
|
|
|
|
const columns: Array<OfferTableColumn> =
|
|
|
|
'Company',
|
|
|
|
jobType === JobType.FULLTIME
|
|
|
|
'Title',
|
|
|
|
? FullTimeOfferTableColumns
|
|
|
|
'YOE',
|
|
|
|
: InternOfferTableColumns;
|
|
|
|
selectedYoeCategory === YOE_CATEGORY.INTERN
|
|
|
|
|
|
|
|
? 'Monthly Salary'
|
|
|
|
|
|
|
|
: 'Annual TC',
|
|
|
|
|
|
|
|
'Date Offered',
|
|
|
|
|
|
|
|
'Actions',
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
if (jobType === JobType.FULLTIME) {
|
|
|
|
|
|
|
|
columns = [
|
|
|
|
|
|
|
|
'Company',
|
|
|
|
|
|
|
|
'Title',
|
|
|
|
|
|
|
|
'YOE',
|
|
|
|
|
|
|
|
'Annual TC',
|
|
|
|
|
|
|
|
'Annual Base / Bonus / Stocks',
|
|
|
|
|
|
|
|
'Date Offered',
|
|
|
|
|
|
|
|
'Actions',
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<thead className="font-semibold">
|
|
|
|
<thead className="font-semibold">
|
|
|
|
<tr className="divide-x divide-slate-200">
|
|
|
|
<tr className="divide-x divide-slate-200">
|
|
|
|
{columns.map((header, index) => (
|
|
|
|
{columns.map((header, index) => (
|
|
|
|
<th
|
|
|
|
<OffersHeader
|
|
|
|
key={header}
|
|
|
|
key={header.label}
|
|
|
|
className={clsx(
|
|
|
|
header={header.label}
|
|
|
|
'bg-slate-100 py-3 px-4',
|
|
|
|
isLastColumn={index === columns.length - 1}
|
|
|
|
header !== 'Company' && 'whitespace-nowrap',
|
|
|
|
sortDirection={
|
|
|
|
// Make last column sticky.
|
|
|
|
header.sortType === selectedSortType
|
|
|
|
index === columns.length - 1 &&
|
|
|
|
? selectedSortDirection
|
|
|
|
'sticky right-0 drop-shadow md:drop-shadow-none',
|
|
|
|
: undefined
|
|
|
|
)}
|
|
|
|
}
|
|
|
|
scope="col">
|
|
|
|
sortType={header.sortType}
|
|
|
|
{header}
|
|
|
|
onSort={onSort}
|
|
|
|
</th>
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
))}
|
|
|
|
</tr>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
</thead>
|
|
|
@ -276,28 +275,29 @@ export default function OffersTable({
|
|
|
|
pagination={pagination}
|
|
|
|
pagination={pagination}
|
|
|
|
startNumber={pagination.currentPage * NUMBER_OF_OFFERS_PER_PAGE + 1}
|
|
|
|
startNumber={pagination.currentPage * NUMBER_OF_OFFERS_PER_PAGE + 1}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
{isLoading ? (
|
|
|
|
|
|
|
|
<div className="col-span-10 py-32">
|
|
|
|
|
|
|
|
<Spinner display="block" size="lg" />
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
) : (
|
|
|
|
|
|
|
|
<div className="overflow-x-auto text-slate-600">
|
|
|
|
<div className="overflow-x-auto text-slate-600">
|
|
|
|
<table className="w-full divide-y divide-slate-200 text-left text-xs text-slate-700 sm:text-sm">
|
|
|
|
<table className="w-full divide-y divide-slate-200 text-left text-xs text-slate-700 sm:text-sm">
|
|
|
|
{renderHeader()}
|
|
|
|
{renderHeader()}
|
|
|
|
|
|
|
|
{!isLoading && (
|
|
|
|
<tbody className="divide-y divide-slate-200">
|
|
|
|
<tbody className="divide-y divide-slate-200">
|
|
|
|
{offers.map((offer) => (
|
|
|
|
{offers.map((offer) => (
|
|
|
|
<OffersRow key={offer.id} jobType={jobType} row={offer} />
|
|
|
|
<OffersRow key={offer.id} jobType={jobType} row={offer} />
|
|
|
|
))}
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
</tbody>
|
|
|
|
|
|
|
|
)}
|
|
|
|
</table>
|
|
|
|
</table>
|
|
|
|
{!offers ||
|
|
|
|
{isLoading && (
|
|
|
|
|
|
|
|
<div className="flex justify-center py-32">
|
|
|
|
|
|
|
|
<Spinner display="block" size="lg" />
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
{(!isLoading && !offers) ||
|
|
|
|
(offers.length === 0 && (
|
|
|
|
(offers.length === 0 && (
|
|
|
|
<div className="py-16 text-lg">
|
|
|
|
<div className="py-16 text-lg">
|
|
|
|
<div className="flex justify-center">No data yet 🥺</div>
|
|
|
|
<div className="flex justify-center">No data yet 🥺</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<OffersTablePagination
|
|
|
|
<OffersTablePagination
|
|
|
|
endNumber={
|
|
|
|
endNumber={
|
|
|
|
pagination.currentPage * NUMBER_OF_OFFERS_PER_PAGE + offers.length
|
|
|
|
pagination.currentPage * NUMBER_OF_OFFERS_PER_PAGE + offers.length
|
|
|
|