refactor: extract mapper
This commit is contained in:
@ -6,6 +6,7 @@ import { peopleColumns } from './people-table';
|
|||||||
import { gql, useQuery } from '@apollo/client';
|
import { gql, useQuery } from '@apollo/client';
|
||||||
import { GraphqlPerson, Person } from './types';
|
import { GraphqlPerson, Person } from './types';
|
||||||
import { defaultData } from './default-data';
|
import { defaultData } from './default-data';
|
||||||
|
import { mapPerson } from './mapper';
|
||||||
|
|
||||||
const StyledPeopleContainer = styled.div`
|
const StyledPeopleContainer = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -33,20 +34,7 @@ const GET_PEOPLE = gql`
|
|||||||
function People() {
|
function People() {
|
||||||
const { data } = useQuery<{ person: GraphqlPerson[] }>(GET_PEOPLE);
|
const { data } = useQuery<{ person: GraphqlPerson[] }>(GET_PEOPLE);
|
||||||
|
|
||||||
const mydata: Person[] = data
|
const mydata: Person[] = data ? data.person.map(mapPerson) : defaultData;
|
||||||
? data.person.map((person) => ({
|
|
||||||
fullName: `${person.firstname} ${person.lastname}`,
|
|
||||||
creationDate: new Date(person.created_at),
|
|
||||||
pipe: { name: 'coucou', id: 1, icon: 'faUser' },
|
|
||||||
...person,
|
|
||||||
company: {
|
|
||||||
id: 1,
|
|
||||||
name: person.company.company_name,
|
|
||||||
domain: person.company.company_domain,
|
|
||||||
},
|
|
||||||
countryCode: 'FR',
|
|
||||||
}))
|
|
||||||
: defaultData;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WithTopBarContainer title="People" icon={faUser}>
|
<WithTopBarContainer title="People" icon={faUser}>
|
||||||
|
|||||||
14
front/src/pages/people/mapper.ts
Normal file
14
front/src/pages/people/mapper.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { GraphqlPerson, Person } from './types';
|
||||||
|
|
||||||
|
export const mapPerson = (person: GraphqlPerson): Person => ({
|
||||||
|
fullName: `${person.firstname} ${person.lastname}`,
|
||||||
|
creationDate: new Date(person.created_at),
|
||||||
|
pipe: { name: 'coucou', id: 1, icon: 'faUser' },
|
||||||
|
...person,
|
||||||
|
company: {
|
||||||
|
id: 1,
|
||||||
|
name: person.company.company_name,
|
||||||
|
domain: person.company.company_domain,
|
||||||
|
},
|
||||||
|
countryCode: 'FR',
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user