mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-20 01:51:54 +03:00
Handle missing account owner (#89)
This commit is contained in:
parent
571cb6ed5c
commit
d5c1bd6365
@ -21,12 +21,33 @@ describe('mapCompany', () => {
|
|||||||
expect(company.name).toBe('ACME');
|
expect(company.name).toBe('ACME');
|
||||||
expect(company.domain_name).toBe('exmaple.com');
|
expect(company.domain_name).toBe('exmaple.com');
|
||||||
expect(company.creationDate).toEqual(now);
|
expect(company.creationDate).toEqual(now);
|
||||||
expect(company.accountOwner.id).toBe(
|
expect(company.accountOwner?.id).toBe(
|
||||||
'7af20dea-0412-4c4c-8b13-d6f0e6e09e87',
|
'7af20dea-0412-4c4c-8b13-d6f0e6e09e87',
|
||||||
);
|
);
|
||||||
expect(company.accountOwner.email).toBe('john@example.com');
|
expect(company.accountOwner?.email).toBe('john@example.com');
|
||||||
expect(company.accountOwner.first_name).toBe('John');
|
expect(company.accountOwner?.first_name).toBe('John');
|
||||||
expect(company.accountOwner.last_name).toBe('Doe');
|
expect(company.accountOwner?.last_name).toBe('Doe');
|
||||||
|
expect(company.employees).toBe(10);
|
||||||
|
expect(company.address).toBe(
|
||||||
|
'1 Infinite Loop, 95014 Cupertino, California, USA',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should map company with no account owner', () => {
|
||||||
|
const now = new Date();
|
||||||
|
now.setMilliseconds(0);
|
||||||
|
const company = mapCompany({
|
||||||
|
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
|
||||||
|
name: 'ACME',
|
||||||
|
domain_name: 'exmaple.com',
|
||||||
|
created_at: now.toUTCString(),
|
||||||
|
employees: 10,
|
||||||
|
address: '1 Infinite Loop, 95014 Cupertino, California, USA',
|
||||||
|
});
|
||||||
|
expect(company.id).toBe('7dfbc3f7-6e5e-4128-957e-8d86808cdf6b');
|
||||||
|
expect(company.name).toBe('ACME');
|
||||||
|
expect(company.domain_name).toBe('exmaple.com');
|
||||||
|
expect(company.creationDate).toEqual(now);
|
||||||
expect(company.employees).toBe(10);
|
expect(company.employees).toBe(10);
|
||||||
expect(company.address).toBe(
|
expect(company.address).toBe(
|
||||||
'1 Infinite Loop, 95014 Cupertino, California, USA',
|
'1 Infinite Loop, 95014 Cupertino, California, USA',
|
||||||
@ -55,11 +76,33 @@ describe('mapCompany', () => {
|
|||||||
expect(company.name).toBe('ACME');
|
expect(company.name).toBe('ACME');
|
||||||
expect(company.domain_name).toBe('exmaple.com');
|
expect(company.domain_name).toBe('exmaple.com');
|
||||||
expect(company.created_at).toEqual(now.toUTCString());
|
expect(company.created_at).toEqual(now.toUTCString());
|
||||||
expect(company.account_owner.id).toBe(
|
expect(company.account_owner?.id).toBe(
|
||||||
'522d4ec4-c46b-4360-a0a7-df8df170be81',
|
'522d4ec4-c46b-4360-a0a7-df8df170be81',
|
||||||
);
|
);
|
||||||
expect(company.account_owner.email).toBe('john@example.com');
|
expect(company.account_owner?.email).toBe('john@example.com');
|
||||||
expect(company.account_owner.displayName).toBe('John Doe');
|
expect(company.account_owner?.displayName).toBe('John Doe');
|
||||||
|
expect(company.employees).toBe(10);
|
||||||
|
expect(company.address).toBe(
|
||||||
|
'1 Infinite Loop, 95014 Cupertino, California, USA',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should map company with no account owner back', () => {
|
||||||
|
const now = new Date();
|
||||||
|
now.setMilliseconds(0);
|
||||||
|
const company = mapGqlCompany({
|
||||||
|
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
|
||||||
|
name: 'ACME',
|
||||||
|
domain_name: 'exmaple.com',
|
||||||
|
employees: 10,
|
||||||
|
address: '1 Infinite Loop, 95014 Cupertino, California, USA',
|
||||||
|
opportunities: [],
|
||||||
|
creationDate: now,
|
||||||
|
});
|
||||||
|
expect(company.id).toBe('7dfbc3f7-6e5e-4128-957e-8d86808cdf6b');
|
||||||
|
expect(company.name).toBe('ACME');
|
||||||
|
expect(company.domain_name).toBe('exmaple.com');
|
||||||
|
expect(company.created_at).toEqual(now.toUTCString());
|
||||||
expect(company.employees).toBe(10);
|
expect(company.employees).toBe(10);
|
||||||
expect(company.address).toBe(
|
expect(company.address).toBe(
|
||||||
'1 Infinite Loop, 95014 Cupertino, California, USA',
|
'1 Infinite Loop, 95014 Cupertino, California, USA',
|
||||||
|
@ -12,7 +12,7 @@ export interface Company {
|
|||||||
employees: number;
|
employees: number;
|
||||||
address: string;
|
address: string;
|
||||||
opportunities: Opportunity[];
|
opportunities: Opportunity[];
|
||||||
accountOwner: User;
|
accountOwner?: User;
|
||||||
creationDate: Date;
|
creationDate: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ export type GraphqlQueryCompany = {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
domain_name: string;
|
domain_name: string;
|
||||||
account_owner: GraphqlQueryAccountOwner;
|
account_owner?: GraphqlQueryAccountOwner;
|
||||||
employees: number;
|
employees: number;
|
||||||
address: string;
|
address: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
@ -36,12 +36,17 @@ export const mapCompany = (company: GraphqlQueryCompany): Company => ({
|
|||||||
...company,
|
...company,
|
||||||
name: company.name,
|
name: company.name,
|
||||||
domain_name: company.domain_name,
|
domain_name: company.domain_name,
|
||||||
accountOwner: {
|
accountOwner: company.account_owner
|
||||||
id: company.account_owner.id,
|
? {
|
||||||
email: company.account_owner.email,
|
id: company.account_owner.id,
|
||||||
first_name: company.account_owner.displayName.split(' ').shift() || '',
|
email: company.account_owner.email,
|
||||||
last_name: company.account_owner.displayName.split(' ').slice(1).join(' '),
|
first_name: company.account_owner.displayName.split(' ').shift() || '',
|
||||||
},
|
last_name: company.account_owner.displayName
|
||||||
|
.split(' ')
|
||||||
|
.slice(1)
|
||||||
|
.join(' '),
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
creationDate: new Date(company.created_at),
|
creationDate: new Date(company.created_at),
|
||||||
opportunities: [{ name: 'Sales Pipeline', icon: '' }],
|
opportunities: [{ name: 'Sales Pipeline', icon: '' }],
|
||||||
});
|
});
|
||||||
@ -51,9 +56,11 @@ export const mapGqlCompany = (company: Company): GraphqlQueryCompany => ({
|
|||||||
name: company.name,
|
name: company.name,
|
||||||
domain_name: company.domain_name,
|
domain_name: company.domain_name,
|
||||||
created_at: company.creationDate.toUTCString(),
|
created_at: company.creationDate.toUTCString(),
|
||||||
account_owner: {
|
account_owner: company.accountOwner
|
||||||
id: company.accountOwner.id,
|
? {
|
||||||
email: company.accountOwner.email,
|
id: company.accountOwner.id,
|
||||||
displayName: `${company.accountOwner.first_name} ${company.accountOwner.last_name}`,
|
email: company.accountOwner.email,
|
||||||
},
|
displayName: `${company.accountOwner.first_name} ${company.accountOwner.last_name}`,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
});
|
});
|
||||||
|
@ -107,9 +107,15 @@ export const companiesColumns = [
|
|||||||
header: () => <ColumnHead viewName="Account Owner" />,
|
header: () => <ColumnHead viewName="Account Owner" />,
|
||||||
cell: (props) => (
|
cell: (props) => (
|
||||||
<HorizontalyAlignedContainer>
|
<HorizontalyAlignedContainer>
|
||||||
<PersonChip
|
<>
|
||||||
name={`${props.row.original.accountOwner.first_name} ${props.row.original.accountOwner.last_name}`}
|
{props.row.original.accountOwner && (
|
||||||
/>
|
<PersonChip
|
||||||
|
name={`${props.row.original.accountOwner?.first_name || ''} ${
|
||||||
|
props.row.original.accountOwner?.last_name || ''
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
</HorizontalyAlignedContainer>
|
</HorizontalyAlignedContainer>
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
|
Loading…
Reference in New Issue
Block a user