Use Graphql types in FE and complete mappers removal (#348)
Fix Typescript build issues
This commit is contained in:
@ -2,19 +2,24 @@ import { CellCommentChip } from '@/comments/components/CellCommentChip';
|
||||
import { useOpenCommentRightDrawer } from '@/comments/hooks/useOpenCommentRightDrawer';
|
||||
import EditableChip from '@/ui/components/editable-cell/types/EditableChip';
|
||||
import { getLogoUrlFromDomainName } from '@/utils/utils';
|
||||
import { CommentableType } from '~/generated/graphql';
|
||||
|
||||
import { Company } from '../interfaces/company.interface';
|
||||
import { updateCompany } from '../services';
|
||||
import {
|
||||
CommentableType,
|
||||
GetCompaniesQuery,
|
||||
useUpdateCompanyMutation,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
import CompanyChip from './CompanyChip';
|
||||
|
||||
type OwnProps = {
|
||||
company: Company;
|
||||
company: Pick<
|
||||
GetCompaniesQuery['companies'][0],
|
||||
'id' | 'name' | 'domainName' | '_commentCount' | 'accountOwner'
|
||||
>;
|
||||
};
|
||||
|
||||
export function CompanyEditableNameChipCell({ company }: OwnProps) {
|
||||
const openCommentRightDrawer = useOpenCommentRightDrawer();
|
||||
const [updateCompany] = useUpdateCompanyMutation();
|
||||
|
||||
function handleCommentClick(event: React.MouseEvent<HTMLDivElement>) {
|
||||
event.preventDefault();
|
||||
@ -35,8 +40,11 @@ export function CompanyEditableNameChipCell({ company }: OwnProps) {
|
||||
picture={getLogoUrlFromDomainName(company.domainName)}
|
||||
changeHandler={(value: string) => {
|
||||
updateCompany({
|
||||
...company,
|
||||
name: value,
|
||||
variables: {
|
||||
...company,
|
||||
name: value,
|
||||
accountOwnerId: company.accountOwner?.id,
|
||||
},
|
||||
});
|
||||
}}
|
||||
ChipComponent={CompanyChip}
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
import { Company as GQLCompany } from '../../../generated/graphql';
|
||||
import { DeepPartial } from '../../utils/utils';
|
||||
|
||||
export type Company = DeepPartial<GQLCompany> & { id: string };
|
||||
|
||||
export type GraphqlQueryCompany = Company;
|
||||
|
||||
export type GraphqlMutationCompany = Company;
|
||||
|
||||
export const mapToCompany = (company: GraphqlQueryCompany): Company => company;
|
||||
|
||||
export const mapToGqlCompany = (company: Company): GraphqlMutationCompany =>
|
||||
company;
|
||||
@ -1,12 +1,4 @@
|
||||
import { FetchResult, gql } from '@apollo/client';
|
||||
import { getOperationName } from '@apollo/client/utilities';
|
||||
|
||||
import { apiClient } from '~/apollo';
|
||||
|
||||
import { UpdateCompanyMutationVariables } from '../../../generated/graphql';
|
||||
import { Company, mapToGqlCompany } from '../interfaces/company.interface';
|
||||
|
||||
import { GET_COMPANIES } from './select';
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const UPDATE_COMPANY = gql`
|
||||
mutation UpdateCompany(
|
||||
@ -80,36 +72,3 @@ export const DELETE_COMPANIES = gql`
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export async function updateCompany(
|
||||
company: UpdateCompanyMutationVariables,
|
||||
): Promise<FetchResult<Company>> {
|
||||
const result = await apiClient.mutate({
|
||||
mutation: UPDATE_COMPANY,
|
||||
variables: company,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function insertCompany(
|
||||
company: Company,
|
||||
): Promise<FetchResult<Company>> {
|
||||
const result = await apiClient.mutate({
|
||||
mutation: INSERT_COMPANY,
|
||||
variables: mapToGqlCompany(company),
|
||||
refetchQueries: [getOperationName(GET_COMPANIES) ?? ''],
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function deleteCompanies(
|
||||
peopleIds: string[],
|
||||
): Promise<FetchResult<Company>> {
|
||||
const result = await apiClient.mutate({
|
||||
mutation: DELETE_COMPANIES,
|
||||
variables: { ids: peopleIds },
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user