Skip to content

Commit

Permalink
Merge branch 'master' into bug/checkbox-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
kurund authored Aug 30, 2022
2 parents 030f573 + 94aebec commit ddb6c15
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
6 changes: 6 additions & 0 deletions src/components/UI/SearchDialogBox/SearchDialogBox.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@
.Autocomplete {
margin-bottom: 10px !important;
}

.Description {
font-size: 16px;
color: #93a29b;
margin-bottom: 8px;
}
36 changes: 25 additions & 11 deletions src/components/UI/SearchDialogBox/SearchDialogBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface SearchDialogBoxProps {
handleOk: Function;
handleCancel: Function;
options: any;
selectedOptions: any;
selectedOptions?: any;
icon?: any;
optionLabel?: string;
additionalOptionLabel?: string;
Expand All @@ -21,14 +21,17 @@ export interface SearchDialogBoxProps {
searchLabel?: string;
renderTags?: boolean;
textFieldPlaceholder?: any;
multiple?: boolean;
buttonOk?: string;
description?: string;
}

export const SearchDialogBox = (props: SearchDialogBoxProps) => {
const {
asyncSearch,
icon,
options,
selectedOptions,
selectedOptions = null,
title,
handleOk,
optionLabel,
Expand All @@ -39,15 +42,22 @@ export const SearchDialogBox = (props: SearchDialogBoxProps) => {
searchLabel = 'Search',
renderTags = true,
textFieldPlaceholder = '',
multiple = true,
buttonOk = 'Save',
description = '',
} = props;

const [selectedOption, setSelectedOptions] = useState<Array<string>>([]);
const [selectedOption, setSelectedOptions] = useState<any>(multiple ? [] : '');
const [asyncSelectedOptions, setAsyncSelectedOptions] = useState<Array<any>>([]);
const { t } = useTranslation();

useEffect(() => {
if (!asyncSearch) {
setSelectedOptions(options.filter((option: any) => selectedOptions.includes(option.id)));
setSelectedOptions(
multiple
? options.filter((option: any) => selectedOptions.includes(option.id))
: selectedOptions
);
}
}, [selectedOptions, options]);

Expand All @@ -61,21 +71,21 @@ export const SearchDialogBox = (props: SearchDialogBoxProps) => {
setSelectedOptions(value);
};

const selectedOptionsIds = selectedOptions.map(({ id }: { id: any }) => id);
const selectedOptionsIds = multiple
? selectedOptions.map(({ id }: { id: any }) => id)
: selectedOptions?.id;

const getIds = multiple ? selectedOption?.map((option: any) => option.id) : selectedOption?.id;

return (
<DialogBox
title={title}
handleOk={() =>
handleOk(
asyncSearch
? asyncSelectedOptions.map((option: any) => option.id)
: selectedOption.map((option: any) => option.id)
)
handleOk(asyncSearch ? asyncSelectedOptions.map((option: any) => option.id) : getIds)
}
handleCancel={handleCancel}
titleAlign="left"
buttonOk={t('Save')}
buttonOk={t(buttonOk)}
>
<div className={styles.DialogBox}>
<FormControl fullWidth>
Expand All @@ -101,8 +111,12 @@ export const SearchDialogBox = (props: SearchDialogBoxProps) => {
chipIcon={icon}
renderTags={renderTags}
selectedOptionsIds={selectedOptionsIds}
multiple={multiple}
/>
</FormControl>
<div className={styles.Description} data-testid="description">
{description}
</div>
</div>
</DialogBox>
);
Expand Down
9 changes: 6 additions & 3 deletions src/containers/Chat/ChatMessages/ContactBar/ContactBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import {
setVariables,
} from '../../../../common/constants';
import { Timer } from '../../../../components/UI/Timer/Timer';
import { DropdownDialog } from '../../../../components/UI/DropdownDialog/DropdownDialog';
import { DialogBox } from '../../../../components/UI/DialogBox/DialogBox';
import { Tooltip } from '../../../../components/UI/Tooltip/Tooltip';
import { CLEAR_MESSAGES } from '../../../../graphql/mutations/Chat';
Expand Down Expand Up @@ -247,6 +246,7 @@ export const ContactBar: React.SFC<ContactBarProps> = (props) => {
}

const handleFlowSubmit = (flowId: any) => {
if (!flowId) return;
const flowVariables: any = {
flowId,
};
Expand Down Expand Up @@ -274,12 +274,15 @@ export const ContactBar: React.SFC<ContactBarProps> = (props) => {

if (showFlowDialog) {
dialogBox = (
<DropdownDialog
<SearchDialogBox
title={t('Select flow')}
handleOk={handleFlowSubmit}
handleCancel={closeFlowDialogBox}
options={flowOptions}
placeholder={t('Select flow')}
optionLabel="name"
multiple={false}
buttonOk="Start"
searchLabel={t('Select flow')}
description={t('The contact will be responded as per the messages planned in the flow.')}
/>
);
Expand Down
1 change: 1 addition & 0 deletions src/mocks/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ export const conversationQuery = getConversationQuery({
status: 'VALID',
bspStatus: 'SESSION_AND_HSM',
isOrgRead: true,
fields: '{}',
},
messages: [
{
Expand Down
12 changes: 7 additions & 5 deletions src/mocks/Contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,13 @@ export const blockContactQuery = {
},
result: {
data: {
contact: {
id: '2',
name: 'Default Receiver',
phone: '99399393303',
language: null,
updateContact: {
contact: {
id: '2',
name: 'Default Receiver',
phone: '99399393303',
language: null,
},
},
},
},
Expand Down

0 comments on commit ddb6c15

Please sign in to comment.