mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-18 17:12:53 +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.domain_name).toBe('exmaple.com');
|
||||
expect(company.creationDate).toEqual(now);
|
||||
expect(company.accountOwner.id).toBe(
|
||||
expect(company.accountOwner?.id).toBe(
|
||||
'7af20dea-0412-4c4c-8b13-d6f0e6e09e87',
|
||||
);
|
||||
expect(company.accountOwner.email).toBe('john@example.com');
|
||||
expect(company.accountOwner.first_name).toBe('John');
|
||||
expect(company.accountOwner.last_name).toBe('Doe');
|
||||
expect(company.accountOwner?.email).toBe('john@example.com');
|
||||
expect(company.accountOwner?.first_name).toBe('John');
|
||||
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.address).toBe(
|
||||
'1 Infinite Loop, 95014 Cupertino, California, USA',
|
||||
@ -55,11 +76,33 @@ describe('mapCompany', () => {
|
||||
expect(company.name).toBe('ACME');
|
||||
expect(company.domain_name).toBe('exmaple.com');
|
||||
expect(company.created_at).toEqual(now.toUTCString());
|
||||
expect(company.account_owner.id).toBe(
|
||||
expect(company.account_owner?.id).toBe(
|
||||
'522d4ec4-c46b-4360-a0a7-df8df170be81',
|
||||
);
|
||||
expect(company.account_owner.email).toBe('john@example.com');
|
||||
expect(company.account_owner.displayName).toBe('John Doe');
|
||||
expect(company.account_owner?.email).toBe('john@example.com');
|
||||
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.address).toBe(
|
||||
'1 Infinite Loop, 95014 Cupertino, California, USA',
|
||||
|
@ -12,7 +12,7 @@ export interface Company {
|
||||
employees: number;
|
||||
address: string;
|
||||
opportunities: Opportunity[];
|
||||
accountOwner: User;
|
||||
accountOwner?: User;
|
||||
creationDate: Date;
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ export type GraphqlQueryCompany = {
|
||||
id: string;
|
||||
name: string;
|
||||
domain_name: string;
|
||||
account_owner: GraphqlQueryAccountOwner;
|
||||
account_owner?: GraphqlQueryAccountOwner;
|
||||
employees: number;
|
||||
address: string;
|
||||
created_at: string;
|
||||
@ -36,12 +36,17 @@ export const mapCompany = (company: GraphqlQueryCompany): Company => ({
|
||||
...company,
|
||||
name: company.name,
|
||||
domain_name: company.domain_name,
|
||||
accountOwner: {
|
||||
id: company.account_owner.id,
|
||||
email: company.account_owner.email,
|
||||
first_name: company.account_owner.displayName.split(' ').shift() || '',
|
||||
last_name: company.account_owner.displayName.split(' ').slice(1).join(' '),
|
||||
},
|
||||
accountOwner: company.account_owner
|
||||
? {
|
||||
id: company.account_owner.id,
|
||||
email: company.account_owner.email,
|
||||
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),
|
||||
opportunities: [{ name: 'Sales Pipeline', icon: '' }],
|
||||
});
|
||||
@ -51,9 +56,11 @@ export const mapGqlCompany = (company: Company): GraphqlQueryCompany => ({
|
||||
name: company.name,
|
||||
domain_name: company.domain_name,
|
||||
created_at: company.creationDate.toUTCString(),
|
||||
account_owner: {
|
||||
id: company.accountOwner.id,
|
||||
email: company.accountOwner.email,
|
||||
displayName: `${company.accountOwner.first_name} ${company.accountOwner.last_name}`,
|
||||
},
|
||||
account_owner: company.accountOwner
|
||||
? {
|
||||
id: company.accountOwner.id,
|
||||
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" />,
|
||||
cell: (props) => (
|
||||
<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>
|
||||
),
|
||||
}),
|
||||
|
Loading…
Reference in New Issue
Block a user