The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Handle missing account owner (#89)
Anders Borchd5c1bd6365f8
diff --git a/front/src/interfaces/company.interface.test.ts b/front/src/interfaces/company.interface.test.tsindex 765f357adcd..4f71d4611c6 100644--- a/front/src/interfaces/company.interface.test.ts+++ b/front/src/interfaces/company.interface.test.ts@@ -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('[email protected]');- expect(company.accountOwner.first_name).toBe('John');- expect(company.accountOwner.last_name).toBe('Doe');+ expect(company.accountOwner?.email).toBe('[email protected]');+ 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('[email protected]');- expect(company.account_owner.displayName).toBe('John Doe');+ expect(company.account_owner?.email).toBe('[email protected]');+ 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',diff --git a/front/src/interfaces/company.interface.ts b/front/src/interfaces/company.interface.tsindex fd3cee50c14..a775f9a4104 100644--- a/front/src/interfaces/company.interface.ts+++ b/front/src/interfaces/company.interface.ts@@ -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,});diff --git a/front/src/pages/companies/companies-table.tsx b/front/src/pages/companies/companies-table.tsxindex 69a68572175..c07bf128713 100644--- a/front/src/pages/companies/companies-table.tsx+++ b/front/src/pages/companies/companies-table.tsx@@ -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>),}),