generated from pagevamp/copilot-custom-app-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
258 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
COPILOT_API_KEY="" | ||
POSTGRES_PRISMA_URL="" | ||
POSTGRES_URL_NON_POOLING="" | ||
COPILOT_API_KEY="b4fa0b79be594f91a2c72c63216d45ec.6463d9dc556351b6" | ||
|
||
# Vercel Database | ||
POSTGRES_PRISMA_URL="postgres://default:2tCAVY7Npmyc@ep-morning-mountain-74331247-pooler.us-east-1.postgres.vercel-storage.com/verceldb?pgbouncer=true&connect_timeout=15" | ||
POSTGRES_URL_NON_POOLING="postgres://default:2tCAVY7Npmyc@ep-morning-mountain-74331247.us-east-1.postgres.vercel-storage.com/verceldb" | ||
|
||
# Local Database | ||
; POSTGRES_PRISMA_URL="postgresql://db:[email protected]:59004/db?schema=public" | ||
; POSTGRES_URL_NON_POOLING="postgresql://db:[email protected]:59004/db?schema=public" | ||
|
||
COPILOT_API_URL="https://api-beta.copilot.com" | ||
COPILOT_ENV="local" | ||
COPILOT_API_URL="" | ||
VERCEL_URL="localhost:3000" | ||
VERCEL_ENV="development" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,115 +3,110 @@ import { AgGridReact } from 'ag-grid-react'; | |
import 'ag-grid-community/styles/ag-grid.css'; // Core CSS | ||
import 'ag-grid-community/styles/ag-theme-quartz.css'; // Theme | ||
import './table.css'; | ||
import { useMemo, useState } from 'react'; | ||
import { useEffect, useMemo, useState } from 'react'; | ||
import { ClientCellRenderer } from './cellRenderers/ClientCellRenderer'; | ||
import { CompanyCellRenderer } from './cellRenderers/CompanyCellRenderer'; | ||
import { HistoryCellRenderer } from './cellRenderers/HistoryCellRenderer'; | ||
import { useAppState } from '@/hooks/useAppState'; | ||
import { getTimeAgo } from '@/utils/getTimeAgo'; | ||
|
||
export const TableCore = () => { | ||
const appState = useAppState(); | ||
|
||
// Row Data: The data to be displayed. | ||
const [rowData, setRowData] = useState<any>([ | ||
{ | ||
Client: { image: 'https://robohash.org/stefan-one', name: 'Tesla', email: '[email protected]', id: 1 }, | ||
company: { image: 'https://robohash.org/generate', name: 'Chase' }, | ||
'Last updated': '1m', | ||
'Phone number': { value: '1928366444', showDot: true }, | ||
Address: 'Texas', | ||
Hobby: 'Music', | ||
}, | ||
{ | ||
Client: { image: 'https://robohash.org/stefan-eleven', name: 'Wongchi', email: '[email protected]', id: 2 }, | ||
company: { image: 'https://robohash.org/generate', name: 'Amazon' }, | ||
'Last updated': '1d', | ||
'Phone number': { value: '9283774466', showDot: false }, | ||
Address: '', | ||
Hobby: 'Dance', | ||
}, | ||
{ | ||
Client: { image: 'https://robohash.org/stefan-hundred', name: 'Holyland', email: '[email protected]', id: 3 }, | ||
company: { image: 'https://robohash.org/generate', name: 'Walt Disney Co.' }, | ||
'Last updated': '', | ||
'Phone number': { value: '2883743322', showDot: true }, | ||
Address: 'New York', | ||
Hobby: 'Flying', | ||
}, | ||
{ | ||
Client: { image: 'https://robohash.org/stefan-five', name: 'Nokia', email: '[email protected]', id: 4 }, | ||
company: { image: 'https://robohash.org/generate', name: 'Scrappy' }, | ||
'Last updated': '2d', | ||
'Phone number': { value: '9182663344', showDot: true }, | ||
Address: 'Hongkong', | ||
Hobby: '', | ||
}, | ||
{ | ||
Client: { image: 'https://robohash.org/stefan-four', name: 'Prolink', email: '[email protected]', id: 5 }, | ||
company: { image: 'https://robohash.org/generate', name: 'Facebook' }, | ||
'Last updated': '1 month', | ||
'Phone number': { value: '', showDot: false }, | ||
Address: 'Manila', | ||
Hobby: 'Diving', | ||
}, | ||
{ | ||
Client: { image: 'https://robohash.org/stefan-three', name: 'Apple', email: '[email protected]', id: 6 }, | ||
company: { image: 'https://robohash.org/generate', name: 'Catch' }, | ||
'Last updated': '12 hours', | ||
'Phone number': { value: '3847228833', showDot: false }, | ||
Address: 'Kathmandu', | ||
Hobby: 'Music', | ||
chobby: 'Music', | ||
}, | ||
]); | ||
const [rowData, setRowData] = useState<any>([]); | ||
// | ||
// Column Definitions: Defines & controls grid columns. | ||
const [colDefs, setColDefs] = useState<any>([]); | ||
|
||
useEffect(() => { | ||
setRowData(appState?.clientProfileUpdates); | ||
|
||
const comparator = (valueA: any, valueB: any) => { | ||
if (valueA < valueB) { | ||
let colDefs: any = []; | ||
if (appState?.clientProfileUpdates.length && appState?.clientProfileUpdates.length) { | ||
const col = appState?.clientProfileUpdates[0]; | ||
delete col.id; | ||
const keys = Object.keys(col); | ||
keys.map((el) => { | ||
if (el === 'client') { | ||
colDefs = [ | ||
...colDefs, | ||
{ | ||
field: 'client', | ||
cellRenderer: ClientCellRenderer, | ||
flex: 1, | ||
comparator: comparatorTypeI, | ||
minWidth: 250, | ||
valueGetter: (params: any) => { | ||
const client = params.data[el]; | ||
return { | ||
avatarImageUrl: client.avatarImageUrl, | ||
name: client.name, | ||
email: client.email, | ||
}; | ||
}, | ||
}, | ||
]; | ||
return; | ||
} | ||
if (el === 'company') { | ||
colDefs = [ | ||
...colDefs, | ||
{ | ||
field: 'company', | ||
cellRenderer: CompanyCellRenderer, | ||
flex: 1, | ||
comparator: comparatorTypeI, | ||
valueGetter: (params: any) => { | ||
const company = params.data[el]; | ||
return { | ||
iconImageUrl: company.iconImageUrl, | ||
name: company.name, | ||
}; | ||
}, | ||
}, | ||
]; | ||
return; | ||
} | ||
if (el === 'lastUpdated') { | ||
colDefs = [ | ||
...colDefs, | ||
{ | ||
field: 'lastUpdated', | ||
flex: 1, | ||
valueGetter: (params: any) => { | ||
const lastUpdated = params.data[el]; | ||
return `${getTimeAgo(lastUpdated)} ago`; | ||
}, | ||
}, | ||
]; | ||
return; | ||
} | ||
|
||
colDefs = [ | ||
...colDefs, | ||
{ | ||
field: el, | ||
flex: 1, | ||
cellRenderer: HistoryCellRenderer, | ||
}, | ||
]; | ||
}); | ||
setColDefs(colDefs); | ||
} | ||
}, [appState?.clientProfileUpdates]); | ||
|
||
const comparatorTypeI = (valueA: any, valueB: any) => { | ||
if (valueA.name < valueB.name) { | ||
return -1; | ||
} | ||
if (valueA > valueB) { | ||
if (valueA.name > valueB.name) { | ||
return 1; | ||
} | ||
|
||
return 0; // names are equal | ||
}; | ||
|
||
// Column Definitions: Defines & controls grid columns. | ||
const [colDefs, setColDefs] = useState<any>([ | ||
{ | ||
field: 'Client', | ||
cellRenderer: ClientCellRenderer, | ||
flex: 1, | ||
comparator, | ||
valueGetter: (params: any) => { | ||
const client = params.data.Client; | ||
return `${client.image} ${client.name} ${client.email}`; | ||
}, | ||
}, | ||
{ | ||
field: 'company', | ||
cellRenderer: CompanyCellRenderer, | ||
flex: 1, | ||
comparator, | ||
valueGetter: (params: any) => { | ||
const company = params.data.company; | ||
return `${company.image} ${company.name}`; | ||
}, | ||
}, | ||
{ field: 'Last updated', flex: 1 }, | ||
{ | ||
field: 'Phone number', | ||
flex: 1, | ||
cellRenderer: HistoryCellRenderer, | ||
valueGetter: (params: any) => { | ||
const phoneProps = params.data['Phone number']; | ||
return `${phoneProps.value} ${phoneProps.showDot}`; | ||
}, | ||
}, | ||
{ field: 'Address', flex: 1 }, | ||
{ field: 'Hobby', flex: 1 }, | ||
]); | ||
|
||
const defaultColDef = useMemo(() => { | ||
return { | ||
resizable: false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.