Skip to content

Commit

Permalink
Merge pull request #11 from eduzz/feature-add-types-in-HyperflowSuppo…
Browse files Browse the repository at this point in the history
…rtChat

chore: Refactor HyperflowSupportChat to use types
  • Loading branch information
henriquegomes6 authored Aug 20, 2024
2 parents 1df0bfb + 077d5d3 commit d41f878
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 51 deletions.
42 changes: 36 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Eduzz UI

UI padrão das aplicações, aqui você vai encontrar:

* [Layout](#layout)
* [App Loader](#app-loader)

Expand Down Expand Up @@ -131,6 +133,7 @@ function MyComponent() {
## Props

### Layout props

| prop | tipo | obrigatório | padrão | descrição |
|-------------------------|----------------------------------------|-------------|-----------|----------------------------------------------------------------------------------|
| mode | `'light' \| 'dark'` | `false` | `'light'` | Modo (Dark ou Light mode) |
Expand Down Expand Up @@ -182,15 +185,43 @@ function MyComponent() {

| prop | tipo | obrigatório | padrão | descrição |
|-----------------|----------|-------------|--------|------------------------------------------------------|
| hyperflowConfig | `object` | `true` | - | Tokens dos canais do Hyperflow |
| hyperflowConfig | `HyperflowConfig` | `true` | - | Tokens dos canais do Hyperflow |
| flowId | `string` | `true` | - | Id do flow do Hyperflow |
| currentUser | `object` | `true` | - | Dados do usuário que serão enviados para o Hyperflow |
| currentUser | `CurrentUser` | `true` | - | Dados do usuário que serão enviados para o Hyperflow |

```ts
export type CurrentUser = {
tag: string;
belt: string;
isClubeBlack: boolean;
id: number;
name: string;
email: string;
isAccessPolicy: boolean;
} & (
| {
isAccessPolicy: true;
originalUserId: number;
originalUserName: string;
originalUserEmail: string;
}
| { isAccessPolicy: false }
);

type HyperflowConfig = {
chatUnityID: string;
chatBlackID: string;
chatEliteID: string;
flowId: string;
};
```

### Topbar.ModeSwitcher props

| prop | tipo | obrigatório | padrão | descrição |
|--------------------|----------|-------------|--------|-------------------------------------------------------------|
| tooltip | `string` | `false` | `'Tema'` | Texto para o tooltip do botão. mode) |
| badgeDot | `boolean` | `false` | `false` | Se um badgeDot deve ser adicionado ao botão . |
| tooltip| `string`| `false`| `'Tema'`| Texto para o tooltip do botão. mode |
| badgeDot| `boolean`| `false`| `false`| Se um badgeDot deve ser adicionado ao botão .|

### Sidebar props

Expand Down Expand Up @@ -225,7 +256,6 @@ function MyComponent() {
<br/>
<br/>


# App Loader

Loader de aplicação padrão.
Expand Down Expand Up @@ -280,4 +310,4 @@ function App() {
| prop | tipo | obrigatório | padrão |
|--------------|------------------|-------------|--------------|
| logo | `url\|ReactNode` | `false` | `Eduzz Logo` |
| logoDarkMode | `url\|ReactNode` | `false` | `Eduzz Logo` |
| logoDarkMode | `url\|ReactNode` | `false` | `Eduzz Logo` |
56 changes: 20 additions & 36 deletions Topbar/HyperflowSupportChat/chat.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import useExternalScript from './import';
import { CurrentUser, HyperflowConfig, HyperflowParams, SupportChatProps } from './types';

type HyperflowParams = {
id?: number;
name?: string;
email?: string;
eliteChatToken?: string;
original_id?: number;
original_name?: string;
original_email?: string;
sender?: string;
};

interface SupportChatProps {
jwtToHyperflow: string;
currentUser: any;
hyperflowConfig: any;
}

function getChatTokenID(currentUser: any, hyperflowConfig: any) {
function getChatTokenID(currentUser: CurrentUser, hyperflowConfig: HyperflowConfig) {
const chatUnityID = hyperflowConfig.chatUnityID;
const chatBlackID = hyperflowConfig.chatBlackID;
const chatEliteID = hyperflowConfig.chatEliteID;
Expand All @@ -33,26 +17,26 @@ const HyperflowSupportChat: React.FC<SupportChatProps> = ({ jwtToHyperflow, curr
const hyperflow = useExternalScript('https://webchat.hyperflow.global/sdk.js');
const chatToken = getChatTokenID(currentUser, hyperflowConfig);

if (hyperflow === 'ready') {
Hyperflow.init(chatToken).on('getStarted', () => {
const params: HyperflowParams = {
id: currentUser?.id,
name: currentUser?.name.split(' ')[0],
email: currentUser?.email,
sender: jwtToHyperflow
};

if (currentUser?.isAccessPolicy) {
params.original_id = currentUser?.originalUserId;
params.original_name = currentUser?.originalUserName?.split(' ')[0];
params.original_email = currentUser?.originalUserEmail;
}

Hyperflow.initFlow(hyperflowConfig.flowId, params);
});
if (hyperflow !== 'ready') {
return null;
}

return null;
Hyperflow.init(chatToken).on('getStarted', () => {
const params: HyperflowParams = {
id: currentUser.id,
name: currentUser.name.split(' ')[0],
email: currentUser.email,
sender: jwtToHyperflow
};

if (currentUser?.isAccessPolicy) {
params.original_id = currentUser?.originalUserId;
params.original_name = currentUser?.originalUserName?.split(' ')[0];
params.original_email = currentUser?.originalUserEmail;
}

Hyperflow.initFlow(hyperflowConfig.flowId, params);
});
};

export default HyperflowSupportChat;
8 changes: 1 addition & 7 deletions Topbar/HyperflowSupportChat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import HyperflowSupportChat from './chat';

export interface TopbarHyperflowSupportChatProps {
jwtToHyperflow?: string;
currentUser?: any;
hyperflowConfig?: any;
}
import { TopbarHyperflowSupportChatProps } from './types';

const TopbarHyperflowSupportChat = ({
jwtToHyperflow,
currentUser,
hyperflowConfig
}: TopbarHyperflowSupportChatProps) => {
if (!jwtToHyperflow) return null;

return (
<HyperflowSupportChat jwtToHyperflow={jwtToHyperflow} currentUser={currentUser} hyperflowConfig={hyperflowConfig} />
);
Expand Down
46 changes: 46 additions & 0 deletions Topbar/HyperflowSupportChat/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export type CurrentUser = {
tag: string;
belt: string;
isClubeBlack: boolean;
id: number;
name: string;
email: string;
isAccessPolicy: boolean;
} & (
| {
isAccessPolicy: true;
originalUserId: number;
originalUserName: string;
originalUserEmail: string;
}
| { isAccessPolicy: false }
);

export type HyperflowConfig = {
chatUnityID: string;
chatBlackID: string;
chatEliteID: string;
flowId: string;
};

export type TopbarHyperflowSupportChatProps = {
jwtToHyperflow: string;
currentUser: CurrentUser;
hyperflowConfig: HyperflowConfig;
};

export type HyperflowParams = {
id: number;
name: string;
email: string;
original_id?: number;
original_name?: string;
original_email?: string;
sender: string;
};

export type SupportChatProps = {
jwtToHyperflow: string;
currentUser: CurrentUser;
hyperflowConfig: HyperflowConfig;
};
22 changes: 21 additions & 1 deletion _dev/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,27 @@ function App() {
}}
>
<Topbar.UnitySupportChat />
<Topbar.HyperflowSupportChat />
<Topbar.HyperflowSupportChat
currentUser={{
tag: 'unity',
belt: 'Red Belt',
isClubeBlack: false,
id: 1,
name: 'QA-ORBITA-NAO-ALTERAR-NAO-ALTERAR',
email: '[email protected]',
isAccessPolicy: true,
originalUserId: 1,
originalUserName: 'QA-ORBITA-NAO-ALTERAR-NAO-ALTERAR',
originalUserEmail: '[email protected]'
}}
hyperflowConfig={{
chatBlackID: 'bla',
chatEliteID: 'bla',
chatUnityID: 'bla',
flowId: 'bla'
}}
jwtToHyperflow='bla'
/>

<Topbar.Search onEnter={onSearchEnter} />
<Topbar.ModeSwitcher />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eduzz/ui-layout",
"version": "1.4.1",
"version": "1.4.2",
"keywords": [
"eduzz",
"react",
Expand Down

0 comments on commit d41f878

Please sign in to comment.