Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Madis Abel committed Oct 17, 2018
0 parents commit 3d1d8a4
Show file tree
Hide file tree
Showing 15 changed files with 410 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PORT=8081
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

appConfig.js
yarn.lock
package-lock.json
webchat-appConfig.js
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Changelog
All notable changes to this project will be documented in this file.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Twilio Flex Web Chat UI Sample

This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).

You can find the most recent version of the guide on how to perform common tasks [here](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md).

This package can only be consumed together with Twilio Flex. Visit http://twilio.com/flex to find out more.

## Instructions

1. Install all dependencies by running:
```
npm install
```
2. Copy webchat-appConfig.sample.js in public/assets folder and configure accordingly to use your Twilio account
```
cp public/assets/webchat-appConfig.sample.js public/assets/webchat-appConfig.js
```
3. Start Flex UI by running:
```
npm start
```
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@twilio/flex-webchat-ui-sample",
"version": "1.0.0",
"private": true,
"dependencies": {
"@twilio/flex-webchat-ui": "^1.0.0",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-scripts": "2.0.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
9 changes: 9 additions & 0 deletions public/assets/webchat-appConfig.sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var appConfig = {
// change the your AccountSid
accountSid: "AC...",
// change to your Flex Flow SID
flexFlowSid: "FO...",
colorTheme: {
overrides: brandedColors
}
}
79 changes: 79 additions & 0 deletions public/assets/webchat-branding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const brandColor1 = "#1976d2";
const brandColor2 = "#233659";
const brandTextColor = "#ffffff";

const personalizedColors = {
darkBlueBackground: "#3C425C",
whiteText: "#FFFFFF",
entryPointBackground: "#3C425C",
lighterBackground: "#ecedf1",
primaryButtonBackground: "#1976d2",
primaryButtonColor: "#FFFFFF",
secondaryButtonBackground: "#6e7180",
secondaryButtonColor: "#FFFFFF"
};

const brandMessageBubbleColors = (bgColor) => ({
Bubble: {
background: bgColor,
color: brandTextColor
},
Avatar: {
background: bgColor,
color: brandTextColor
},
Header: {
color: brandTextColor
}
});

const brandedColors = {
Chat: {
MessageListItem: {
FromOthers: brandMessageBubbleColors(brandColor2),
FromMe: brandMessageBubbleColors(brandColor1),
},
MessageInput: {
Button: {
background: brandColor1,
color: brandTextColor
}
},
MessageCanvasTray: {
Container: {
background: personalizedColors.darkBlueBackground,
color: personalizedColors.whiteText
}
},
},

MainHeader: {
Container: {
background: personalizedColors.darkBlueBackground,
color: personalizedColors.whiteText
},
Logo: {
fill: brandTextColor
}
},

EntryPoint: {
Container: {
background: personalizedColors.entryPointBackground,
color: personalizedColors.whiteText
}
},

PreEngagementCanvas: {
Container: {
background: personalizedColors.lighterBackground
},

Form: {
SubmitButton: {
background: personalizedColors.primaryButtonBackground,
color: personalizedColors.whiteText
}
}
}
};
Binary file added public/img/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions public/img/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Twilio Flex Web Chat</title>
<script src="/assets/webchat-branding.js"></script>
<script src="/assets/webchat-appConfig.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700">
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
35 changes: 35 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import * as FlexWebChat from "@twilio/flex-webchat-ui";

class App extends React.Component {

state = {};

constructor(props) {
super(props);

const { configuration } = props;
FlexWebChat.Manager.create(configuration)
.then(manager => this.setState({ manager }))
.catch(error => this.setState({ error }));
}

render() {
const { manager, error } = this.state;
if (manager) {
return (
<FlexWebChat.ContextProvider manager={manager}>
<FlexWebChat.RootContainer />
</FlexWebChat.ContextProvider>
);
}

if (error) {
console.error("Failed to initialize Flex Web Chat", error);
}

return null;
}
}

export default App;
9 changes: 9 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App config={{}} />, div);
ReactDOM.unmountComponentAtNode(div);
});
28 changes: 28 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
body, #root {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
display: flex;
font-family: 'Open Sans', sans-serif;
}

body {
position: relative;
background-size: cover;
background-image: url("/img/background.png");
background-color: #6D7697;
}

body:after {
content: "";
position: absolute;
top: 50%;
left: 50%;
width: 174px;
height: 182px;
margin-left: -87px;
margin-top: -91px;
opacity: 0.2;
background: url("/img/logo.svg");
}
13 changes: 13 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom';
import 'regenerator-runtime/runtime';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(
<App configuration={window.appConfig} />,
document.getElementById("root")
);

registerServiceWorker();
Loading

0 comments on commit 3d1d8a4

Please sign in to comment.