Skip to content

Commit

Permalink
fix(contacts): fix reactive changes when delete, tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ganzorig committed Sep 28, 2020
1 parent a6a30c5 commit 3352ef8
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 23 deletions.
50 changes: 38 additions & 12 deletions ui/src/modules/companies/containers/CompaniesList.tsx
Expand Up @@ -152,8 +152,8 @@ class CompanyListContainer extends React.Component<FinalProps, State> {
}
}

const generateParams = ({ queryParams }) => ({
variables: {
const generateParams = ({ queryParams }) => {
return {
...generatePaginationParams(queryParams),
segment: queryParams.segment,
tag: queryParams.tag,
Expand All @@ -165,34 +165,60 @@ const generateParams = ({ queryParams }) => ({
? parseInt(queryParams.sortDirection, 10)
: undefined
}
});
};

const getRefetchQueries = (queryParams?: any) => {
return [
{
query: gql(queries.companiesMain),
variables: { ...generateParams({ queryParams })}
},
{
query: gql(queries.companyCounts),
variables: { only: 'byTag' }
},
{
query: gql(queries.companyCounts),
variables: { only: 'bySegment' }
},
{
query: gql(queries.companyCounts),
variables: { only: 'byBrand' }
}
];
};

export default withProps<Props>(
compose(
graphql<{ queryParams: any }, MainQueryResponse, ListQueryVariables>(
graphql<Props, MainQueryResponse, ListQueryVariables>(
gql(queries.companiesMain),
{
name: 'companiesMainQuery',
options: generateParams
options: ({ queryParams }) => ({
variables: generateParams({ queryParams }),
}),
}
),
graphql<{}, ListConfigQueryResponse, {}>(gql(queries.companiesListConfig), {
graphql<Props, ListConfigQueryResponse, {}>(gql(queries.companiesListConfig), {
name: 'companiesListConfigQuery'
}),
// mutations
graphql<{}, RemoveMutationResponse, RemoveMutationVariables>(
graphql<Props, RemoveMutationResponse, RemoveMutationVariables>(
gql(mutations.companiesRemove),
{
name: 'companiesRemove'
name: 'companiesRemove',
options: ({ queryParams }) => ({
refetchQueries: getRefetchQueries(queryParams)
})
}
),
graphql<{}, MergeMutationResponse, MergeMutationVariables>(
graphql<Props, MergeMutationResponse, MergeMutationVariables>(
gql(mutations.companiesMerge),
{
name: 'companiesMerge',
options: {
refetchQueries: ['companiesMain', 'companyCounts']
}
options: ({ queryParams }) => ({
refetchQueries: getRefetchQueries(queryParams)
})
}
)
)(withRouter<IRouterProps>(CompanyListContainer))
Expand Down
2 changes: 1 addition & 1 deletion ui/src/modules/companies/containers/detail/BasicInfo.tsx
Expand Up @@ -92,7 +92,7 @@ const BasicInfoContainer = (props: FinalProps) => {
};

const generateOptions = () => ({
refetchQueries: ['companieMain', 'companyCounts']
refetchQueries: ['companiesMain', 'companyCounts']
});

export default withProps<Props>(
Expand Down
15 changes: 12 additions & 3 deletions ui/src/modules/customers/components/list/CustomersList.tsx
Expand Up @@ -60,6 +60,7 @@ interface IProps extends IRouterProps {
queryParams: any;
exportData: (bulk: Array<{ _id: string }>) => void;
responseId: string;
refetch?: () => void;
}

type State = {
Expand Down Expand Up @@ -183,6 +184,14 @@ class CustomersList extends React.Component<IProps, State> {
e.target.value = tmpValue;
}

afterTag = () => {
this.props.emptyBulk();

if(this.props.refetch) {
this.props.refetch();
}
}

render() {
const {
type,
Expand Down Expand Up @@ -343,10 +352,10 @@ class CustomersList extends React.Component<IProps, State> {
.catch(e => {
Alert.error(e.message);
});

const refetchQuery = {
query: gql(queries.customerCounts),
variables: { only: 'byTag' }
variables: { type, only: 'byTag' }
};

actionBarLeft = (
Expand All @@ -355,7 +364,7 @@ class CustomersList extends React.Component<IProps, State> {

<TaggerPopover
type="customer"
successCallback={emptyBulk}
successCallback={this.afterTag}
targets={bulk}
trigger={tagButton}
refetchQueries={[refetchQuery]}
Expand Down
51 changes: 44 additions & 7 deletions ui/src/modules/customers/containers/CustomersList.tsx
Expand Up @@ -158,6 +158,10 @@ class CustomerListContainer extends React.Component<FinalProps, State> {
window.open(`${REACT_APP_API_URL}/file-export?${stringified}`, '_blank');
};

const refetch = () => {
this.props.customersMainQuery.refetch();
};

const searchValue = this.props.queryParams.searchValue || '';

const { list = [], totalCount = 0 } =
Expand All @@ -176,16 +180,13 @@ class CustomerListContainer extends React.Component<FinalProps, State> {
removeCustomers,
verifyCustomers,
mergeCustomerLoading: this.state.mergeCustomerLoading,
refetch
};

const content = (props) => {
return <CustomersList {...updatedProps} {...props} />;
};

const refetch = () => {
this.props.customersMainQuery.refetch();
};

return <Bulk content={content} refetch={refetch} />;
}
}
Expand All @@ -211,6 +212,39 @@ const generateParams = ({ queryParams, type }) => {
};
};

const getRefetchQueries = (queryParams?: any, type?: string) => {
return [
{
query: gql(queries.customersMain),
variables: { ...generateParams({ queryParams, type })}
},
{
query: gql(queries.customerCounts),
variables: { type, only: 'byTag' }
},
{
query: gql(queries.customerCounts),
variables: { type, only: 'byForm' }
},
{
query: gql(queries.customerCounts),
variables: { type, only: 'byIntegrationType' }
},
{
query: gql(queries.customerCounts),
variables: { type, only: 'byLeadStatus' }
},
{
query: gql(queries.customerCounts),
variables: { type, only: 'bySegment' }
},
{
query: gql(queries.customerCounts),
variables: { type, only: 'byBrand' }
}
];
};

export default withProps<Props>(
compose(
graphql<Props, MainQueryResponse, ListQueryVariables>(
Expand All @@ -233,15 +267,18 @@ export default withProps<Props>(
gql(mutations.customersRemove),
{
name: 'customersRemove',
options: ({ queryParams, type }) => ({
refetchQueries: getRefetchQueries(queryParams, type)
})
}
),
graphql<Props, MergeMutationResponse, MergeMutationVariables>(
gql(mutations.customersMerge),
{
name: 'customersMerge',
options: {
refetchQueries: ['customersMain', 'customerCounts'],
},
options: ({ queryParams, type }) => ({
refetchQueries: getRefetchQueries(queryParams, type)
})
}
),
graphql<Props, VerifyMutationResponse, VerifyMutationVariables>(
Expand Down

0 comments on commit 3352ef8

Please sign in to comment.