Skip to content

Commit

Permalink
Merge branch 'develop' into feat/42-dealPage
Browse files Browse the repository at this point in the history
  • Loading branch information
eastfilmm authored Jun 8, 2024
2 parents 1d98307 + 2e5577e commit 124e778
Show file tree
Hide file tree
Showing 24 changed files with 2,243 additions and 2,153 deletions.
3,650 changes: 1,547 additions & 2,103 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/apis/companies/useGetCVData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// import { axiosClient } from '../AxiosClient';
import axios from 'axios';

import { ICVDataProps } from '@finnect/interface/CompanyInterface';

export const useGetCVData = async (): Promise<ICVDataProps> => {
try {
const response = await axios.get(`/api/workspaces/views/company`);

return response.data;
} catch (error) {
console.error(error);
throw error;
}
};
17 changes: 17 additions & 0 deletions src/apis/companies/useGetCVDetailData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// import { axiosClient } from '../AxiosClient';
import axios from 'axios';

import { ICVDetailDataProps } from '@finnect/interface/CompanyInterface';

export const GetCVDetailData = async (
companyId: number
): Promise<ICVDetailDataProps> => {
try {
const response = await axios.get(`/api/workspaces/companies/${companyId}`);

return response.data;
} catch (error) {
console.error(error);
throw error;
}
};
19 changes: 19 additions & 0 deletions src/apis/companies/useGetCVPDetailData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// import { axiosClient } from '../AxiosClient';
import axios from 'axios';

import { ICVPDetailDataProps } from '@finnect/interface/CompanyInterface';

export const GetCVPDetailData = async (
companyId: number
): Promise<ICVPDetailDataProps> => {
try {
const response = await axios.get(
`/api/workspaces/companies?companyId=${companyId}`
);

return response.data;
} catch (error) {
console.error(error);
throw error;
}
};
2 changes: 1 addition & 1 deletion src/apis/companies/usePostCompanyCol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const postWCompany = async ({
dtype: 'string';
}) => {
try {
const response = await axiosClient.post(`/workspaces`, {
const response = await axiosClient.post(`/workspaces/companies/columns`, {
columnId,
workspaceId,
columnName,
Expand Down
19 changes: 6 additions & 13 deletions src/atoms/company/useCompany.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ColDef } from 'ag-grid-community';
import { atom } from 'recoil';

import { CompanyCategories } from '@finnect/pages/companies/components/CompanyCategories';
import { RowData } from '@finnect/interface/CompanyInterface';

import { CompanyInterface } from '@finnect/interface/CompanyInterface';
import CustomCellRenderer from '@finnect/pages/companies/components/CustomCellRenderer';

export const rowDataState = atom<CompanyInterface[]>({
export const rowDataState = atom<RowData[]>({
key: 'rowDataState',
default: [],
});
Expand All @@ -18,17 +18,10 @@ export const columnDefsState = atom<ColDef[]>({
field: 'companyName',
checkboxSelection: true,
rowDrag: true,
cellRenderer: CustomCellRenderer,
width: 250,
},
{ headerName: 'Domains', field: 'domain' },
{
headerName: 'Categories',
field: 'Categories',
cellEditor: 'agSelectCellEditor',
cellEditorParams: {
values: CompanyCategories,
},
},
{ headerName: 'About', field: 'About' },
{ headerName: 'Domains', field: 'domain', filter: true },
],
});

Expand Down
22 changes: 22 additions & 0 deletions src/atoms/company/useCompanyPeople.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ColDef } from 'ag-grid-community';
import { atom } from 'recoil';

import { IPRowData } from '@finnect/interface/CompanyInterface';

export const rowPDataState = atom<IPRowData[]>({
key: 'rowPDataState',
default: [],
});

export const columnPDefsState = atom<ColDef[]>({
key: 'columnPDefsState',
default: [
{
headerName: 'Person',
field: 'personName',
},
{ headerName: 'Role', field: 'personRole' },
{ headerName: 'Email', field: 'personEmail' },
{ headerName: 'Phone', field: 'personPhone' },
],
});
23 changes: 6 additions & 17 deletions src/hooks/custom-hooks/company/useCompanyData.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
import { useEffect } from 'react';

import { ColDef } from 'ag-grid-community';
import { useRecoilState } from 'recoil';

import {
rowDataState,
columnDefsState,
} from '@finnect/atoms/company/useCompany';
import { columnDefsState } from '@finnect/atoms/company/useCompany';

import { useGetWC } from '@finnect/hooks/queries/company/useGetWC';
import { usePostWC } from '@finnect/hooks/queries/company/usePostWC';

import { CompanyColumnInterface } from '@finnect/interface/CompanyInterface';
import { useGetCV } from '@finnect/hooks/queries/company/useGetCV';

export const useCompanyData = () => {
const [rowData, setRowData] = useRecoilState(rowDataState);
const [columnDefs, setColumnDefs] = useRecoilState(columnDefsState);
const { data, refetch } = useGetWC();
const { refetch: CompanyList } = useGetWC();
const { refetch: CV } = useGetCV();
const { mutate } = usePostWC();

useEffect(() => {
if (data) {
console.log(data.result.companies);
setRowData(data.result.companies);
}
}, [setRowData, data]);

const addColumn = ({ name, type }: CompanyColumnInterface) => {
let newColumnDef: ColDef;

Expand Down Expand Up @@ -57,14 +46,14 @@ export const useCompanyData = () => {
{ companyName: name, domain: domain },
{
onSuccess: () => {
refetch();
CV();
CompanyList();
},
}
);
};

return {
rowData,
columnDefs,
addColumn,
addCompany,
Expand Down
58 changes: 58 additions & 0 deletions src/hooks/custom-hooks/company/useCompanyViewData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// @finnect/hooks/custom-hooks/company/useCompanyData.ts
import { useEffect } from 'react';
import { useRecoilState } from 'recoil';
import {
rowDataState,
columnDefsState,
} from '@finnect/atoms/company/useCompany';
import { useGetCV } from '@finnect/hooks/queries/company/useGetCV';

import { RowData } from '@finnect/interface/CompanyInterface';

export const useCompanyViewData = () => {
const [rowData, setRowData] = useRecoilState(rowDataState);
const [columnDefs, setColumnDefs] = useRecoilState(columnDefsState);
const { data, isPending, isError, error } = useGetCV();

useEffect(() => {
if (
data &&
data.result &&
data.result.viewColumns &&
data.result.viewCompanies
) {
const columnsFromApi = data.result.viewColumns.map((col) => ({
headerName: col.columnName,
field: col.columnName,
sortable: true,
filter: true,
hide: col.hided,
}));

const combinedColumns = [...columnDefs, ...columnsFromApi];

const rows = data.result.viewCompanies.map((company) => {
const row: RowData = {
companyId: company.companyId,
companyName: company.companyName,
domain: company.domain,
};
company.cells.forEach((cell) => {
const column = data.result.viewColumns.find(
(col) => col.columnId === cell.columnId
);
if (column) {
row[column.columnName] = cell.value;
}
});
return row;
});

setColumnDefs(combinedColumns);
setRowData(rows);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [data]);

return { rowData, columnDefs, isPending, isError, error };
};
3 changes: 2 additions & 1 deletion src/hooks/custom-hooks/people/usePeopleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const usePeopleData = () => {
const [columnDefs] = useRecoilState(columnDefsPeopleState);
const { mutate } = usePostPeopleQuery();
const { mutate: deletePerson } = useDeletePeopleQuery();
const { data, isPending, isError, error } = useGetPeopleQuery();
const { data, isPending, isError, error, refetch } = useGetPeopleQuery();
const [selectedPerson, setSelectedPerson] =
useRecoilState(selectedPersonState);

Expand Down Expand Up @@ -53,6 +53,7 @@ export const usePeopleData = () => {
{ personName, personRole, personEmail, personPhone, companyId },
] as IPeopleAxiosProps[]
);
refetch();
},
}
);
Expand Down
13 changes: 13 additions & 0 deletions src/hooks/queries/company/useGetCV.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useGetCVData } from '@finnect/apis/companies/useGetCVData';

import { useQuery } from '@tanstack/react-query';

export const useGetCV = () => {
const { data, isPending, isError, error, refetch } = useQuery({
queryKey: ['getCVData'],
queryFn: useGetCVData,
refetchOnMount: true,
});

return { data, isPending, isError, error, refetch };
};
13 changes: 13 additions & 0 deletions src/hooks/queries/company/useGetCVD.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { GetCVDetailData } from '@finnect/apis/companies/useGetCVDetailData';

import { useQuery } from '@tanstack/react-query';

export const useGetCVD = (companyId: number) => {
const { data, isPending, isError, error, refetch } = useQuery({
queryKey: ['getCVDData'],
queryFn: () => GetCVDetailData(companyId),
refetchOnMount: false,
});

return { data, isPending, isError, error, refetch };
};
13 changes: 13 additions & 0 deletions src/hooks/queries/company/useGetCVP.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { GetCVPDetailData } from '@finnect/apis/companies/useGetCVPDetailData';

import { useQuery } from '@tanstack/react-query';

export const useGetCVP = (companyId: number) => {
const { data, isPending, isError, error, refetch } = useQuery({
queryKey: ['getCVPData'],
queryFn: () => GetCVPDetailData(companyId),
refetchOnMount: false,
});

return { data, isPending, isError, error, refetch };
};
90 changes: 90 additions & 0 deletions src/interface/CompanyInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,93 @@ export interface CompanyColumnInterface {
name: string;
type: string;
}

export interface IViewCompany {
companyId: number;
domain: string;
companyName: string;
rowId: number;
cells: {
columnId: number;
value: string;
peopleId: number;
companyId: number;
userId: number;
}[];
}

export interface IViewColumn {
columnId: number;
index: number;
hided: boolean;
columnType: string;
columnName: string;
sorting: string;
}

export interface ICVDataProps {
status: number;
result: {
viewId: number;
viewName: string;
filters: {
filterId: number;
columnId: number;
condition: string;
value: string;
}[];
viewColumns: IViewColumn[];
viewCompanies: IViewCompany[];
};
}

export interface RowData {
companyId: number;
companyName: string;
domain: string;
[key: string]: any;
}

export interface ICVDetailDataProps {
status: number;
result: {
company: {
companyId: number;
domain: string;
companyName: string;
};
cells: ICVDCellsProps[];
};
}

export interface ICVDCellsProps {
columnId: number;
value: string;
userId: number;
peopleId: number;
columnType: string;
columnName: string;
}

export interface ICVPDetailDataProps {
status: number;
result: {
people: ICVPPeopleProps[];
};
}

export interface ICVPPeopleProps {
companyId: number;
personId: number;
personName: string;
personRole: string;
personEmail: string;
personPhone: string;
}

export interface IPRowData {
personName: string;
personRole: string;
personEmail: string;
personPhone: string;
}
Loading

0 comments on commit 124e778

Please sign in to comment.