Skip to content
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
67 changes: 44 additions & 23 deletions docs/react-samples/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
import React, { useState } from 'react';
import {StationLogin, UserState, store} from '@webex/cc-widgets'
import React, {useState} from 'react';
import {StationLogin, UserState, IncomingTask, TaskList, store} from '@webex/cc-widgets';

function App() {
const [isSdkReady, setIsSdkReady] = useState(false);
const [accessToken, setAccessToken] = useState("");
const [accessToken, setAccessToken] = useState('');
const [isLoggedIn, setIsLoggedIn] = useState(false);

const webexConfig = {
fedramp: false,
logger: {
level: 'log'
}
}
fedramp: false,
logger: {
level: 'log',
},
};

const onLogin = () => {
console.log('Agent login has been succesful');
setIsLoggedIn(true);
}
};

const onLogout = () => {
console.log('Agent logout has been succesful');
setIsLoggedIn(false);
}
};

const onAccepted = () => {
console.log('onAccepted Invoked');
};

const onDeclined = () => {
console.log('onDeclined invoked');
};

const onTaskAccepted = () => {
console.log('onTaskAccepted invoked');
};

const onTaskDeclined = () => {
console.log('onTaskDeclined invoked');
};

return (
<>
Expand All @@ -33,25 +49,30 @@ function App() {
onChange={(e) => setAccessToken(e.target.value)}
/>
<button
disabled={accessToken.trim() === ""}
disabled={accessToken.trim() === ''}
onClick={() => {
store.init({webexConfig, access_token: accessToken}).then(() => {
setIsSdkReady(true);
});
}}
>Init Widgets</button>
{
isSdkReady && (
<>
<StationLogin onLogin={onLogin} onLogout={onLogout} />
{
isLoggedIn && <UserState />
}
</>
)
}
>
Comment thread
sreenara marked this conversation as resolved.
Init Widgets
</button>
{isSdkReady && (
<>
<StationLogin onLogin={onLogin} onLogout={onLogout} />
{isLoggedIn && (
<>
<UserState />
<IncomingTask onAccepted={onAccepted} onDeclined={onDeclined} />
<TaskList onTaskAccepted={onTaskAccepted} onTaskDeclined={onTaskDeclined} />
</>
)}
</>
)}
</>
);
}

// @ts-ignore
window.store = store;
Comment thread
sreenara marked this conversation as resolved.
Comment thread
rsarika marked this conversation as resolved.
export default App;
26 changes: 25 additions & 1 deletion docs/web-component-samples/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const accessTokenElem = document.getElementById('access_token_elem');
const widgetsContainer = document.getElementById('widgets-container');
const ccStationLogin = document.getElementById('cc-station-login');
const ccUserState = document.createElement('widget-cc-user-state');
const ccIncomingTask = document.createElement('widget-cc-incoming-task');
const ccTaskList = document.createElement('widget-cc-task-list');

if (!ccStationLogin && !ccUserState) {
console.error('Failed to find the required elements');
Expand All @@ -25,6 +27,10 @@ function initWidgets(){
}).then(() => {
ccStationLogin.onLogin = loginSuccess;
ccStationLogin.onLogout = logoutSuccess;
ccIncomingTask.onAccepted = onAccepted;
ccIncomingTask.onDeclined = onDeclined;
ccTaskList.onTaskAccepted = onTaskAccepted;
ccTaskList.onTaskDeclined = onTaskDeclined;
ccStationLogin.classList.remove('disabled');
}).catch((error) => {
console.error('Failed to initialize widgets:', error);
Expand All @@ -35,9 +41,27 @@ function loginSuccess(){
console.log('Agent login has been succesful');
ccUserState.classList.remove('disabled');
widgetsContainer.appendChild(ccUserState);
widgetsContainer.appendChild(ccIncomingTask);
widgetsContainer.appendChild(ccTaskList);
Comment thread
mkesavan13 marked this conversation as resolved.
}

function logoutSuccess(){
console.log('Agent logout has been succesful');
ccUserState.classList.add('disabled');
}
}

function onAccepted(){
console.log('onAccepted Invoked');
};

function onDeclined(){
console.log('onDeclined invoked');
};

function onTaskAccepted(){
console.log('onTaskAccepted invoked');
};

function onTaskDeclined(){
console.log('onTaskDeclined invoked');
};
1 change: 1 addition & 0 deletions packages/contact-center/cc-widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@r2wc/react-to-web-component": "2.0.3",
"@webex/cc-station-login": "workspace:*",
"@webex/cc-store": "workspace:*",
"@webex/cc-task": "workspace:*",
"@webex/cc-user-state": "workspace:*"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/contact-center/cc-widgets/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {StationLogin} from '@webex/cc-station-login';
import {UserState} from '@webex/cc-user-state';
import {IncomingTask, TaskList} from '@webex/cc-task';
import store from '@webex/cc-store';

export {StationLogin, UserState, store};
export {StationLogin, UserState, IncomingTask, TaskList, store};
22 changes: 22 additions & 0 deletions packages/contact-center/cc-widgets/src/wc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@ import r2wc from '@r2wc/react-to-web-component';
import {StationLogin} from '@webex/cc-station-login';
import {UserState} from '@webex/cc-user-state';
import store from '@webex/cc-store';
import {TaskList, IncomingTask} from '@webex/cc-task';

const WebUserState = r2wc(UserState);
const WebIncomingTask = r2wc(IncomingTask, {
props: {
onAccepted: 'function',
onDeclined: 'function',
},
});

const WebTaskList = r2wc(TaskList, {
props: {
onTaskAccepted: 'function',
onTaskDeclined: 'function',
},
});

const WebStationLogin = r2wc(StationLogin, {
props: {
Expand All @@ -20,4 +34,12 @@ if (!customElements.get('widget-cc-station-login')) {
customElements.define('widget-cc-station-login', WebStationLogin);
}

if (!customElements.get('widget-cc-incoming-task')) {
customElements.define('widget-cc-incoming-task', WebIncomingTask);
}

if (!customElements.get('widget-cc-task-list')) {
customElements.define('widget-cc-task-list', WebTaskList);
}

export {store};
Comment thread
sreenara marked this conversation as resolved.
31 changes: 22 additions & 9 deletions packages/contact-center/station-login/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useState} from "react";
import {useState} from 'react';
import {StationLoginSuccess, StationLogoutSuccess} from '@webex/plugin-cc';
import {UseStationLoginProps} from "./station-login/station-login.types";
import {UseStationLoginProps} from './station-login/station-login.types';
Comment thread
sreenara marked this conversation as resolved.
import store from '@webex/cc-store'; // we need to import as we are losing the context of this in store
Comment thread
sreenara marked this conversation as resolved.

export const useStationLogin = (props: UseStationLoginProps) => {
const cc = props.cc;
Expand All @@ -17,10 +18,12 @@ export const useStationLogin = (props: UseStationLoginProps) => {
cc.stationLogin({teamId: team, loginOption: deviceType, dialNumber: dialNumber})
.then((res: StationLoginSuccess) => {
setLoginSuccess(res);
if(loginCb){
store.setSelectedLoginOption(deviceType);
if (loginCb) {
loginCb();
}
}).catch((error: Error) => {
})
.catch((error: Error) => {
console.error(error);
setLoginFailure(error);
});
Expand All @@ -30,14 +33,24 @@ export const useStationLogin = (props: UseStationLoginProps) => {
cc.stationLogout({logoutReason: 'User requested logout'})
.then((res: StationLogoutSuccess) => {
setLogoutSuccess(res);
if(logoutCb){
if (logoutCb) {
logoutCb();
}
}).catch((error: Error) => {
})
.catch((error: Error) => {
console.error(error);
});
};

return {name: 'StationLogin', setDeviceType, setDialNumber, setTeam, login, logout, loginSuccess, loginFailure, logoutSuccess};
}

return {
name: 'StationLogin',
setDeviceType,
setDialNumber,
setTeam,
login,
logout,
loginSuccess,
loginFailure,
logoutSuccess,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface IStationLoginProps {
*/
teams: Team[];

/**
/**
* Station login options available for the agent
*/
loginOptions: string[];
Expand All @@ -43,7 +43,7 @@ export interface IStationLoginProps {
*/
loginFailure?: Error;

/**
/**
* Response data received on agent login success
*/
logoutSuccess?: StationLogoutSuccess;
Expand Down Expand Up @@ -74,8 +74,21 @@ export interface IStationLoginProps {
setTeam: (team: string) => void;
}

export type StationLoginPresentationalProps = Pick<IStationLoginProps, 'name' | 'teams' | 'loginOptions' | 'login' | 'logout' | 'loginSuccess' | 'loginFailure' | 'logoutSuccess' | 'setDeviceType' | 'setDialNumber' | 'setTeam'>;
export type StationLoginPresentationalProps = Pick<
IStationLoginProps,
| 'name'
| 'teams'
| 'loginOptions'
| 'login'
| 'logout'
| 'loginSuccess'
| 'loginFailure'
| 'logoutSuccess'
| 'setDeviceType'
| 'setDialNumber'
| 'setTeam'
>;

export type UseStationLoginProps = Pick<IStationLoginProps, 'cc' | 'onLogin' | 'onLogout'>;

export type StationLoginProps = Pick<IStationLoginProps, 'onLogin' | 'onLogout'>;
export type StationLoginProps = Pick<IStationLoginProps, 'onLogin' | 'onLogout'>;
Loading