* refactor: use safe css selector * feature: onclick update the order option * feature: set option in the dropdown * feature: display icon for sort options * refactor: indent key so react does not complain of conflicting keys * feature: align icon and text * feature: fix size of icon to align text * feature: create design for TopOption in dropdown * refactor: set font weight in style * feature: finalise design of TopOption * refactor: rename option to sort * refactor: remove order from the sortType * refactor: move sort mapper in service * test: selection of Descending in SortDropdownButton * refactor: fix styme-component warning * feature: add sorting by people * refactor: set SortFields types for tables * feature: add sort by company * refactor: rename sortFields to singular * refactor: rename option to SortDirection
138 lines
4.3 KiB
TypeScript
138 lines
4.3 KiB
TypeScript
import {
|
|
faBuildings,
|
|
faCalendar,
|
|
faEnvelope,
|
|
faUser,
|
|
faMapPin,
|
|
faPhone,
|
|
faRectangleHistory,
|
|
} from '@fortawesome/pro-regular-svg-icons';
|
|
import { createColumnHelper } from '@tanstack/react-table';
|
|
import ClickableCell from '../../components/table/ClickableCell';
|
|
import ColumnHead from '../../components/table/ColumnHead';
|
|
import { parsePhoneNumber, CountryCode } from 'libphonenumber-js';
|
|
import Checkbox from '../../components/form/Checkbox';
|
|
import HorizontalyAlignedContainer from '../../layout/containers/HorizontalyAlignedContainer';
|
|
import CompanyChip from '../../components/chips/CompanyChip';
|
|
import PersonChip from '../../components/chips/PersonChip';
|
|
import { Person } from '../../interfaces/person.interface';
|
|
import PipeChip from '../../components/chips/PipeChip';
|
|
import { SortType } from '../../components/table/table-header/SortAndFilterBar';
|
|
import EditableCell from '../../components/table/EditableCell';
|
|
import { OrderByFields, updatePerson } from '../../services/people';
|
|
|
|
export const sortsAvailable = [
|
|
{
|
|
id: 'fullname',
|
|
label: 'People',
|
|
icon: faUser,
|
|
},
|
|
{
|
|
id: 'company_name',
|
|
label: 'Company',
|
|
icon: faBuildings,
|
|
},
|
|
{
|
|
id: 'email',
|
|
label: 'Email',
|
|
icon: faEnvelope,
|
|
},
|
|
{ id: 'phone', label: 'Phone', icon: faPhone },
|
|
{
|
|
id: 'created_at',
|
|
label: 'Created at',
|
|
icon: faCalendar,
|
|
},
|
|
{ id: 'city', label: 'City', icon: faMapPin },
|
|
] satisfies Array<SortType<OrderByFields>>;
|
|
|
|
const columnHelper = createColumnHelper<Person>();
|
|
export const peopleColumns = [
|
|
columnHelper.accessor('fullName', {
|
|
header: () => <ColumnHead viewName="People" viewIcon={faUser} />,
|
|
cell: (props) => (
|
|
<>
|
|
<HorizontalyAlignedContainer>
|
|
<Checkbox
|
|
id={`person-selected-${props.row.original.email}`}
|
|
name={`person-selected-${props.row.original.email}`}
|
|
/>
|
|
<PersonChip
|
|
name={props.row.original.fullName}
|
|
picture={props.row.original.picture}
|
|
/>
|
|
</HorizontalyAlignedContainer>
|
|
</>
|
|
),
|
|
}),
|
|
columnHelper.accessor('email', {
|
|
header: () => <ColumnHead viewName="Email" viewIcon={faEnvelope} />,
|
|
cell: (props) => (
|
|
<EditableCell
|
|
content={props.row.original.email}
|
|
changeHandler={(value) => {
|
|
const person = props.row.original;
|
|
person.email = value;
|
|
updatePerson(person).catch((error) => console.error(error)); // TODO: handle error
|
|
}}
|
|
/>
|
|
),
|
|
}),
|
|
columnHelper.accessor('company', {
|
|
header: () => <ColumnHead viewName="Company" viewIcon={faBuildings} />,
|
|
cell: (props) => (
|
|
<ClickableCell href="#">
|
|
<CompanyChip
|
|
name={props.row.original.company.name}
|
|
picture={`https://www.google.com/s2/favicons?domain=${props.row.original.company.domain}&sz=256`}
|
|
/>
|
|
</ClickableCell>
|
|
),
|
|
}),
|
|
columnHelper.accessor('phone', {
|
|
header: () => <ColumnHead viewName="Phone" viewIcon={faPhone} />,
|
|
cell: (props) => (
|
|
<ClickableCell
|
|
href={parsePhoneNumber(
|
|
props.row.original.phone,
|
|
props.row.original.countryCode as CountryCode,
|
|
)?.getURI()}
|
|
>
|
|
{parsePhoneNumber(
|
|
props.row.original.phone,
|
|
props.row.original.countryCode as CountryCode,
|
|
)?.formatInternational() || props.row.original.phone}
|
|
</ClickableCell>
|
|
),
|
|
}),
|
|
columnHelper.accessor('creationDate', {
|
|
header: () => <ColumnHead viewName="Creation" viewIcon={faCalendar} />,
|
|
cell: (props) => (
|
|
<ClickableCell href="#">
|
|
{new Intl.DateTimeFormat(undefined, {
|
|
month: 'short',
|
|
day: 'numeric',
|
|
year: 'numeric',
|
|
}).format(props.row.original.creationDate)}
|
|
</ClickableCell>
|
|
),
|
|
}),
|
|
columnHelper.accessor('pipe', {
|
|
header: () => <ColumnHead viewName="Pipe" viewIcon={faRectangleHistory} />,
|
|
cell: (props) => (
|
|
<ClickableCell href="#">
|
|
<PipeChip
|
|
name={props.row.original.pipe.name}
|
|
picture={props.row.original.pipe.icon}
|
|
/>
|
|
</ClickableCell>
|
|
),
|
|
}),
|
|
columnHelper.accessor('city', {
|
|
header: () => <ColumnHead viewName="City" viewIcon={faMapPin} />,
|
|
cell: (props) => (
|
|
<ClickableCell href="#">{props.row.original.city}</ClickableCell>
|
|
),
|
|
}),
|
|
];
|