* Added comments and authors on drawer with proper resolving * Fixed generated front graphql from rebase * Fixed comment chip * wip * wip 2 * - Added string typing for DateTime scalar - Refactored user in a recoil state and workspace using it - Added comment creation * Put theme and user state in generic providers * Fix from rebase * Fixed app theme provider removed from storybook * Wip * Fix graphql front * Fixed backend bug * - Added comment fetching in creation mode - Fixed drawer overflows and heights * - Fixed autosize validation button CSS bug * Fixed CSS bug with drawer changing height if overflow * Fixed text input too many event catched and useless error message * Removed console.log * Fixed comment cell chip * Create comment thread on each comment action bar click * Fixed lint * Fixed TopBar height
101 lines
3.0 KiB
TypeScript
101 lines
3.0 KiB
TypeScript
import { useCallback, useState } from 'react';
|
|
import { FaList } from 'react-icons/fa';
|
|
import { TbUser } from 'react-icons/tb';
|
|
import styled from '@emotion/styled';
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
import {
|
|
reduceFiltersToWhere,
|
|
reduceSortsToOrderBy,
|
|
} from '@/filters-and-sorts/helpers';
|
|
import { SelectedFilterType } from '@/filters-and-sorts/interfaces/filters/interface';
|
|
import { mapToPerson, Person } from '@/people/interfaces/person.interface';
|
|
import {
|
|
defaultOrderBy,
|
|
insertPerson,
|
|
PeopleSelectedSortType,
|
|
usePeopleQuery,
|
|
} from '@/people/services';
|
|
import { EntityTableActionBar } from '@/ui/components/table/action-bar/EntityTableActionBar';
|
|
import { EntityTable } from '@/ui/components/table/EntityTable';
|
|
import { WithTopBarContainer } from '@/ui/layout/containers/WithTopBarContainer';
|
|
import { BoolExpType } from '@/utils/interfaces/generic.interface';
|
|
|
|
import { TableActionBarButtonCreateCommentThreadPeople } from './table/TableActionBarButtonCreateCommentThreadPeople';
|
|
import { TableActionBarButtonDeletePeople } from './table/TableActionBarButtonDeletePeople';
|
|
import { usePeopleColumns } from './people-columns';
|
|
import { availableFilters } from './people-filters';
|
|
import { availableSorts } from './people-sorts';
|
|
|
|
const StyledPeopleContainer = styled.div`
|
|
display: flex;
|
|
width: 100%;
|
|
height: 100%;
|
|
`;
|
|
|
|
export function People() {
|
|
const [orderBy, setOrderBy] = useState(defaultOrderBy);
|
|
const [where, setWhere] = useState<BoolExpType<Person>>({});
|
|
|
|
const updateSorts = useCallback((sorts: Array<PeopleSelectedSortType>) => {
|
|
setOrderBy(sorts.length ? reduceSortsToOrderBy(sorts) : defaultOrderBy);
|
|
}, []);
|
|
|
|
const updateFilters = useCallback(
|
|
(filters: Array<SelectedFilterType<Person>>) => {
|
|
setWhere(reduceFiltersToWhere(filters));
|
|
},
|
|
[],
|
|
);
|
|
|
|
const { data } = usePeopleQuery(orderBy, where);
|
|
|
|
const people = data?.people.map(mapToPerson) ?? [];
|
|
|
|
async function handleAddButtonClick() {
|
|
const newPerson: Person = {
|
|
__typename: 'people',
|
|
id: uuidv4(),
|
|
firstname: '',
|
|
lastname: '',
|
|
email: '',
|
|
phone: '',
|
|
company: null,
|
|
pipes: [],
|
|
createdAt: new Date(),
|
|
city: '',
|
|
};
|
|
|
|
await insertPerson(newPerson);
|
|
}
|
|
|
|
const peopleColumns = usePeopleColumns();
|
|
|
|
return (
|
|
<WithTopBarContainer
|
|
title="People"
|
|
icon={<TbUser size={16} />}
|
|
onAddButtonClick={handleAddButtonClick}
|
|
>
|
|
<>
|
|
<StyledPeopleContainer>
|
|
<EntityTable
|
|
data={people}
|
|
columns={peopleColumns}
|
|
viewName="All People"
|
|
viewIcon={<FaList />}
|
|
availableSorts={availableSorts}
|
|
availableFilters={availableFilters}
|
|
onSortsUpdate={updateSorts}
|
|
onFiltersUpdate={updateFilters}
|
|
/>
|
|
</StyledPeopleContainer>
|
|
<EntityTableActionBar>
|
|
<TableActionBarButtonCreateCommentThreadPeople />
|
|
<TableActionBarButtonDeletePeople />
|
|
</EntityTableActionBar>
|
|
</>
|
|
</WithTopBarContainer>
|
|
);
|
|
}
|