Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inbox): fix custom field disappearing in inbox right sidebar #4698

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/erxes-ui/src/components/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export default class Box extends React.Component<BoxProps, BoxState> {

setConfig(STORAGE_KEY, config);

return callback && callback();
if (!isOpen && callback) {
return callback();
}
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BasicInfo, TabContent } from './styles';
import { TabTitle, Tabs } from '@erxes/ui/src/components/tabs';
import { isEnabled, loadDynamicComponent } from '@erxes/ui/src/utils/core';

import Box from '@erxes/ui/src/components/Box';
import CompanySection from '@erxes/ui-contacts/src/companies/components/CompanySection';
Expand All @@ -13,7 +14,6 @@ import Sidebar from '@erxes/ui/src/layout/components/Sidebar';
import WebsiteActivity from '@erxes/ui-contacts/src/customers/components/common/WebsiteActivity';
import { __ } from 'coreui/utils';
import asyncComponent from '@erxes/ui/src/components/AsyncComponent';
import { isEnabled, loadDynamicComponent } from '@erxes/ui/src/utils/core';

const ActionSection = asyncComponent(() =>
import(
Expand Down Expand Up @@ -222,6 +222,7 @@ class Index extends React.Component<IndexProps, IndexState> {
loading={loading}
customer={customer}
isDetail={false}
collapseCallback={toggleSection}
/>
<Box
title={__('Conversation details')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,27 @@ class Sidebar extends React.Component<FinalProps, State> {
}
}

mergeProperties = () => {
const config = getConfig(STORAGE_KEY) || {};

return Object.entries(config)?.reduce((result, [key, value]) => {
const keys = key.replace(/[0-9]+$/, '');
result[keys] = keys in result ? result[keys] || value : value;

return result;
}, {});
};

getCustomerDetail(customerId?: string) {
if (!customerId) {
return null;
}

const sectionParams = getConfig(STORAGE_KEY);

this.setState({ loading: true });

client
.query({
query: gql(queries.generateCustomerDetailQuery(sectionParams)),
query: gql(queries.generateCustomerDetailQuery(this.mergeProperties())),
fetchPolicy: 'network-only',
variables: { _id: customerId }
})
Expand All @@ -99,9 +108,11 @@ class Sidebar extends React.Component<FinalProps, State> {
render() {
const { customer, loading } = this.state;

const mergedProperties = this.mergeProperties();

const taggerRefetchQueries = [
{
query: gql(queries.generateCustomerDetailQuery(getConfig(STORAGE_KEY))),
query: gql(queries.generateCustomerDetailQuery(mergedProperties)),
variables: { _id: customer._id }
}
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import GenerateCustomFields from '@erxes/ui-forms/src/settings/properties/components/GenerateCustomFields';
import * as compose from 'lodash.flowright';

import { EditMutationResponse, ICustomer } from '../types';

import { FIELDS_GROUPS_CONTENT_TYPES } from '@erxes/ui-forms/src/settings/properties/constants';
import { queries as fieldQueries } from '@erxes/ui-forms/src/settings/properties/graphql';
import { FieldsGroupsQueryResponse } from '@erxes/ui-forms/src/settings/properties/types';
import Spinner from '@erxes/ui/src/components/Spinner';
import GenerateCustomFields from '@erxes/ui-forms/src/settings/properties/components/GenerateCustomFields';
import React from 'react';
import Sidebar from '@erxes/ui/src/layout/components/Sidebar';
import { withProps } from '@erxes/ui/src/utils';
import { isEnabled } from '@erxes/ui/src/utils/core';
import Spinner from '@erxes/ui/src/components/Spinner';
import { queries as fieldQueries } from '@erxes/ui-forms/src/settings/properties/graphql';
import { gql } from '@apollo/client';
import * as compose from 'lodash.flowright';
import React from 'react';
import { graphql } from '@apollo/client/react/hoc';

import { isEnabled } from '@erxes/ui/src/utils/core';
import { mutations } from '../graphql';
import { EditMutationResponse, ICustomer } from '../types';
import { withProps } from '@erxes/ui/src/utils';

type Props = {
customer: ICustomer;
loading?: boolean;
isDetail: boolean;
collapseCallback: () => void;
};

type FinalProps = {
Expand All @@ -31,7 +33,8 @@ const CustomFieldsSection = (props: FinalProps) => {
customersEdit,
fieldsGroupsQuery,
loading,
isDetail
isDetail,
collapseCallback
} = props;

if (fieldsGroupsQuery && fieldsGroupsQuery.loading) {
Expand Down Expand Up @@ -62,7 +65,8 @@ const CustomFieldsSection = (props: FinalProps) => {
customFieldsData: customer.customFieldsData,
fieldsGroups: fieldsGroupsQuery ? fieldsGroupsQuery.fieldsGroups : [],
isDetail,
object: customer
object: customer,
collapseCallback
};

return <GenerateCustomFields {...updatedProps} />;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Divider, SidebarContent, SidebarFooter } from '../styles';
import { IField, ILocationOption } from '@erxes/ui/src/types';
import { IFieldGroup, LogicParams } from '../types';
import { getConfig, setConfig } from '@erxes/ui/src/utils/core';

import { Alert } from '@erxes/ui/src/utils';
import Box from '@erxes/ui/src/components/Box';
Expand All @@ -12,6 +13,7 @@ import { ModalTrigger } from '@erxes/ui/src';
import React from 'react';
import Sidebar from '@erxes/ui/src/layout/components/Sidebar';
import Tip from '@erxes/ui/src/components/Tip';
import _ from 'lodash';
import { checkLogic } from '../utils';

declare const navigator: any;
Expand All @@ -31,6 +33,7 @@ type Props = {
callback: (error: Error) => void,
extraValues?: any
) => void;
collapseCallback: () => void;
};

type State = {
Expand All @@ -39,7 +42,7 @@ type State = {
extraValues?: any;
currentLocation: ILocationOption;
};

const STORAGE_KEY = `erxes_sidebar_section_config`;
class GenerateGroup extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
Expand All @@ -52,6 +55,24 @@ class GenerateGroup extends React.Component<Props, State> {
}

async componentDidMount() {
const { fieldGroup, collapseCallback } = this.props;

if (fieldGroup.alwaysOpen) {
const customField = getConfig(STORAGE_KEY) || {};

if (
_.isEmpty(customField) ||
!customField[`showCustomFields${fieldGroup.order}`]
) {
setConfig(STORAGE_KEY, {
...customField,
[`showCustomFields${fieldGroup.order}`]: true
});
// tslint:disable-next-line:no-unused-expression
collapseCallback && collapseCallback();
}
}

if (this.props.fieldGroup.fields.findIndex(e => e.type === 'map') === -1) {
return;
}
Expand Down Expand Up @@ -255,7 +276,7 @@ class GenerateGroup extends React.Component<Props, State> {
<SidebarContent>
{Array(numberToIterate)
.fill(0)
.map((_, groupDataIndex) => {
.map((___, groupDataIndex) => {
const groupDataValue = groupData[groupDataIndex] || {};

const fieldRenders = fields.map((field, index) => {
Expand Down Expand Up @@ -349,7 +370,8 @@ class GenerateGroup extends React.Component<Props, State> {
fieldGroup,
fieldsGroups,
customFieldsData = [],
isDetail
isDetail,
collapseCallback
} = this.props;

const childGroups = fieldsGroups.filter(
Expand Down Expand Up @@ -445,6 +467,7 @@ class GenerateGroup extends React.Component<Props, State> {
save={this.props.save}
saveGroup={saveGroup}
object={this.props.object}
collapseCallback={collapseCallback}
/>
);
});
Expand All @@ -461,7 +484,7 @@ class GenerateGroup extends React.Component<Props, State> {
};

render() {
const { fieldGroup, isDetail } = this.props;
const { fieldGroup, isDetail, collapseCallback } = this.props;
const isVisibleKey = isDetail ? 'isVisibleInDetail' : 'isVisible';
let extraButtons = <></>;
const visibleField = fieldGroup.fields.find(el => el.isVisible === true);
Expand Down Expand Up @@ -516,8 +539,9 @@ class GenerateGroup extends React.Component<Props, State> {
<Box
extraButtons={extraButtons}
title={fieldGroup.name}
name="showCustomFields"
name={`showCustomFields${fieldGroup.order}`}
isOpen={fieldGroup.alwaysOpen}
callback={collapseCallback}
>
{this.renderContent()}
{this.renderButtons()}
Expand All @@ -534,6 +558,7 @@ type GroupsProps = {
loading?: boolean;
object?: any;
save: (data: { customFieldsData: any }, callback: () => any) => void;
collapseCallback: () => void;
};

class GenerateGroups extends React.Component<GroupsProps> {
Expand Down Expand Up @@ -565,7 +590,8 @@ class GenerateGroups extends React.Component<GroupsProps> {
loading,
fieldsGroups = [],
customFieldsData,
isDetail
isDetail,
collapseCallback
} = this.props;

const groups = fieldsGroups.filter(gro => !gro.parentId);
Expand Down Expand Up @@ -638,6 +664,7 @@ class GenerateGroups extends React.Component<GroupsProps> {
object={this.props.object}
saveGroup={this.saveGroup}
save={this.props.save}
collapseCallback={collapseCallback}
/>
);
});
Expand Down
Loading