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

[#660] Enable users to connect via Airy Live Chat #1078

Merged
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
7 changes: 4 additions & 3 deletions frontend/assets/images/icons/plus-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion frontend/assets/scss/colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
--color-red-alert: #d51548;
--color-accent-magenta: #f7147d;
--color-error-background: #fae6e9;
--color-red-alert: #bf1a2f;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate, remove this one because it didn't match the colors from platform.

--color-highlight-yellow: #fbbd54;
--color-background-yellow: #fbf9ee;
--color-background-red: #fff7f9;
Expand Down
10 changes: 4 additions & 6 deletions frontend/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
<title>Airy UI</title>
<meta charset="utf-8" />
<link rel="shortcut icon" href="/favicon.ico" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="theme-color" content="#000000" />

<!--
Expand All @@ -17,8 +14,9 @@
<link rel="manifest" href="/manifest.json" />
<script>
window.AIRY_TEMPLATED_STATE = {
"API_HOST": "{{API_HOST}}"
}
API_HOST: '{{API_HOST}}',
CHATPLUGIN_HOST: '{{CHATPLUGIN_HOST}}',
};
</script>
</head>

Expand Down
2 changes: 2 additions & 0 deletions frontend/ui/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ events {
# By default nginx does not make any env variables accessible to lua
# http://nginx.org/en/docs/ngx_core_module.html#env
env API_HOST;
env CHATPLUGIN_HOST;

http {
include /etc/nginx/mime.types;
Expand Down Expand Up @@ -48,6 +49,7 @@ http {
local template_string = ngx.location.capture("/index.html")
template.render(template_string.body, {
API_HOST = os.getenv("API_HOST")
CHATPLUGIN_HOST = os.getenv("CHATPLUGIN_HOST")
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class App extends Component<ConnectedProps<typeof connector> & RouteComponentPro
<Route exact path={LOGIN_ROUTE} component={Login} />
<Route path={INBOX_ROUTE} component={Inbox} />
<Route exact path={LOGOUT_ROUTE} component={Logout} />
<Route exact path={CHANNELS_ROUTE} component={Channels} />
<Route path={CHANNELS_ROUTE} component={Channels} />
<Route component={NotFound} />
</Switch>
</div>
Expand Down
22 changes: 19 additions & 3 deletions frontend/ui/src/actions/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ import {
ConnectChannelRequestPayload,
ExploreChannelRequestPayload,
DisconnectChannelRequestPayload,
ConnectChatPluginRequestPayload,
UpdateChannelRequestPayload,
} from 'httpclient';
import {HttpClientInstance} from '../../InitializeAiryApi';

const SET_CURRENT_CHANNELS = '@@channel/SET_CHANNELS';
const ADD_CHANNELS = '@@channel/ADD_CHANNELS';
const SET_CHANNEL = '@@channel/SET_CHANNEL';
const DELETE_CHANNEL = '@@channel/DELETE_CHANNEL';

export const setCurrentChannelsAction = createAction(SET_CURRENT_CHANNELS, resolve => (channels: Channel[]) =>
resolve(channels)
);

export const addChannelsAction = createAction(ADD_CHANNELS, resolve => (channels: Channel[]) => resolve(channels));
export const setChannelAction = createAction(SET_CHANNEL, resolve => (channel: Channel) => resolve(channel));
export const deleteChannelAction = createAction(DELETE_CHANNEL, resolve => (channelId: string) => resolve(channelId));

export const listChannels = () => async (dispatch: Dispatch<any>) =>
HttpClientInstance.listChannels().then((response: Channel[]) => {
Expand All @@ -39,10 +43,22 @@ export const connectChannel = (requestPayload: ConnectChannelRequestPayload) =>
return Promise.resolve(response);
});

export const connectChatPlugin = (requestPayload: ConnectChatPluginRequestPayload) => async (dispatch: Dispatch<any>) =>
HttpClientInstance.connectChatPluginChannel(requestPayload).then((response: Channel) => {
dispatch(addChannelsAction([response]));
return Promise.resolve(response);
});

export const updateChannel = (requestPayload: UpdateChannelRequestPayload) => async (dispatch: Dispatch<any>) =>
HttpClientInstance.updateChannel(requestPayload).then((response: Channel) => {
dispatch(setChannelAction(response));
return Promise.resolve(response);
});

export const disconnectChannel = (source: string, requestPayload: DisconnectChannelRequestPayload) => async (
dispatch: Dispatch<any>
) =>
HttpClientInstance.disconnectChannel(source, requestPayload).then((response: Channel[]) => {
dispatch(setCurrentChannelsAction(response));
return Promise.resolve(response);
HttpClientInstance.disconnectChannel(source, requestPayload).then(() => {
dispatch(deleteChannelAction(requestPayload.channelId));
return Promise.resolve(true);
});
4 changes: 2 additions & 2 deletions frontend/ui/src/components/IconChannel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ const IconChannel: React.FC<IconChannelProps> = ({
return (
<div className={styles.iconName}>
{channelInfo.icon()}
<p>{channel.metadata.name}</p>
<p>{channel.metadata?.name}</p>
</div>
);
} else if (showAvatar && showName) {
return (
<div className={styles.avatarName}>
{channelInfo.avatar()}
<p>{channel.metadata.name}</p>
<p>{channel.metadata?.name}</p>
</div>
);
} else if (icon && text) {
Expand Down
2 changes: 2 additions & 0 deletions frontend/ui/src/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface Env {
API_HOST?: string;
CHATPLUGIN_HOST?: string;
}

declare const window: {
Expand All @@ -10,4 +11,5 @@ const templatedState: Env = window.AIRY_TEMPLATED_STATE || {};

export const env: Env = {
API_HOST: templatedState.API_HOST || 'api.airy',
CHATPLUGIN_HOST: templatedState.CHATPLUGIN_HOST || 'chatplugin.airy',
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import styles from './index.module.scss';
import {ReactComponent as AddIcon} from 'assets/images/icons/plus-circle.svg';

type SourceDescriptionProps = {
image: JSX.Element;
title: string;
text: string;
buttonIcon: JSX.Element;
displayButton: boolean;
onAddChannelClick?: () => void;
};

const SourceDescription = (props: SourceDescriptionProps) => {
Expand All @@ -22,9 +23,9 @@ const SourceDescription = (props: SourceDescriptionProps) => {

{props.displayButton && (
<div className={styles.channelButton}>
<button type="button" className={styles.addChannelButton}>
<button type="button" className={styles.addChannelButton} onClick={props.onAddChannelClick}>
<div className={styles.channelButtonIcon} title="Add a channel">
{props.buttonIcon}
<AddIcon />
</div>
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,18 @@
}

.connectedChannelData {
@include font-base;
display: flex;
align-items: center;
margin: 4px;
align-items: flex-start;
border: none;
background-color: inherit;
text-align: left;
cursor: pointer;

&:hover {
text-decoration: underline;
}
}

.channelListEntry {
Expand All @@ -81,12 +90,16 @@

.connectedChannelName {
min-width: 168px;
height: 24px;
margin: 0 4px 0 4px;
max-width: 200px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
margin-right: 7px;
}

.channelId {
padding-top: 10px;
}

.channelButton {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import {Channel} from 'httpclient';
import {LinkButton} from '@airyhq/components';
import {ReactComponent as AddChannel} from 'assets/images/icons/plus-circle.svg';
import styles from './index.module.scss';

type SourceInfoProps = {
Expand All @@ -9,7 +10,9 @@ type SourceInfoProps = {
connected: string;
placeholderImage?: JSX.Element;
isConnected: string;
addAChannel: JSX.Element;
onAddChannelClick?: () => void;
onMoreChannelsClick?: () => void;
onChannelClick?: (channel: Channel) => void;
};

const SourceInfo = (props: SourceInfoProps) => {
Expand Down Expand Up @@ -37,28 +40,28 @@ const SourceInfo = (props: SourceInfoProps) => {
{channels.slice(0, channelsToShow).map((channel: Channel) => {
return (
<li key={channel.sourceChannelId} className={styles.channelListEntry}>
<div className={styles.connectedChannelData}>
{source === 'facebook' && channel.metadata.imageUrl ? (
<button className={styles.connectedChannelData} onClick={() => props.onChannelClick(channel)}>
{channel.metadata?.imageUrl ? (
<img
src={channel.metadata.imageUrl}
alt={channel.metadata.name}
src={channel.metadata?.imageUrl}
alt={channel.metadata?.name}
className={styles.facebookImage}
/>
) : (
<div className={styles.placeholderLogo}>{props.placeholderImage} </div>
)}
<div className={styles.connectedChannelName}>{channel.metadata.name}</div>
<div className={styles.connectedChannelName}>{channel.metadata?.name}</div>
{isPhoneNumberSource() && (
<div className={styles.extraPhoneInfo}>{channel.sourceChannelId}</div>
)}
</div>
</button>
</li>
);
})}
</div>
<div className={styles.extraChannel}>
{hasExtraChannels && (
<LinkButton>
<LinkButton onClick={props.onMoreChannelsClick}>
+{channels.length - channelsToShow} {props.isConnected}
</LinkButton>
)}
Expand All @@ -67,9 +70,9 @@ const SourceInfo = (props: SourceInfoProps) => {
</div>

<div className={styles.channelButton}>
<button type="button" className={styles.addChannelButton}>
<button type="button" className={styles.addChannelButton} onClick={props.onAddChannelClick}>
<div className={styles.channelButtonIcon} title="Add a channel">
{props.addAChannel}
<AddChannel />
</div>
</button>
</div>
Expand Down
Loading