Skip to content

Commit

Permalink
HF: typos and changed url for chat metadata to use href instead of or…
Browse files Browse the repository at this point in the history
…igin
  • Loading branch information
cmarker0 committed Mar 22, 2021
1 parent 443e913 commit 125eb21
Show file tree
Hide file tree
Showing 9 changed files with 2,189 additions and 2,066 deletions.
4,143 changes: 2,131 additions & 2,012 deletions package-lock.json

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,37 @@
"eject": "react-scripts eject"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.32",
"@fortawesome/free-solid-svg-icons": "^5.15.1",
"@fortawesome/react-fontawesome": "^0.1.12",
"@twilio/flex-webchat-ui": "^2.6.1",
"axios": "^0.21.0",
"react-scripts": "4.0.1",
"uuid": "^8.3.1"
"@fortawesome/fontawesome-svg-core": "^1.2.35",
"@fortawesome/free-solid-svg-icons": "^5.15.3",
"@fortawesome/react-fontawesome": "^0.1.14",
"@twilio/flex-webchat-ui": "^2.8.1",
"axios": "^0.21.1",
"react-scripts": "4.0.3",
"uuid": "^8.3.2"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.6",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/preset-env": "^7.9.6",
"@babel/preset-react": "^7.9.4",
"@babel/preset-typescript": "^7.9.0",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.9",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@babel/cli": "^7.13.10",
"@babel/core": "^7.13.10",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/preset-env": "^7.13.10",
"@babel/preset-react": "^7.12.13",
"@babel/preset-typescript": "^7.13.0",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.35",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.2",
"@types/uuid": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
"husky": "^4.3.0",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"husky": "^5.1.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.0",
"prettier": "^2.2.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"rimraf": "^3.0.2",
"typescript": "^4.1.2"
"typescript": "^4.2.3"
},
"babel": {
"presets": [
Expand Down
2 changes: 1 addition & 1 deletion src/assets/texts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const preEngagementFormMessage: MultiLangText = {

const entryPointLabel: MultiLangText = {
en: 'Chat with us',
no: 'Snakk med oss',
no: 'Chat med oss',
};

const predefinedMessage: MultiLangText = {
Expand Down
16 changes: 8 additions & 8 deletions src/components/FlexChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const defaultManagerState = {

const FlexChat: React.FC<FlexChatProps> = ({
config,
isDarkMode,
isDarkMode = false,
isDisabled = false,
isDev = false,
enableTranslation = false,
Expand All @@ -48,8 +48,8 @@ const FlexChat: React.FC<FlexChatProps> = ({
const { manager, loading, error } = managerState;
const { flexFlowSid, flexAccountSid, user } = config;
const isNorwegian = user.preferredLanguage?.includes('-NO');
const { toggleChatVisibility } = useChatActions();

const { toggleChatVisibility } = useChatActions();
const { translateTextAsync } = useTranslation();

const translationRef = React.createRef();
Expand Down Expand Up @@ -130,7 +130,7 @@ const FlexChat: React.FC<FlexChatProps> = ({
MessageBubble.Content.add(
<TranslationBubbleBody
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
perferredLanguage={chosenLanguage}
preferredLanguage={chosenLanguage}
key={`translationBody_${uuidv4()}`}
/>,
{
Expand Down Expand Up @@ -179,10 +179,10 @@ const FlexChat: React.FC<FlexChatProps> = ({
(t) => t.to === 'en',
)?.text;

const replacedPaload = Object.assign({}, payload);
replacedPaload.body = translatedText;
const replacedPayload = Object.assign({}, payload);
replacedPayload.body = translatedText;

original(replacedPaload);
original(replacedPayload);
})
.catch(() => original(payload));
});
Expand Down Expand Up @@ -221,7 +221,7 @@ const FlexChat: React.FC<FlexChatProps> = ({
MessageBubble.Content.add(
<TranslationBubbleBody
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
perferredLanguage={value.formData.chosenLanguage}
preferredLanguage={value.formData.chosenLanguage}
ref={translationRef}
key={`translationBody_${uuidv4()}`}
/>,
Expand All @@ -247,7 +247,7 @@ const FlexChat: React.FC<FlexChatProps> = ({
initActions(manager);

if (!config.closeOnInit) {
// Allways open the chat on init
// Always open the chat on init
if (!manager.store.getState().flex.session.isEntryPointExpanded) {
toggleChatVisibility();
}
Expand Down
34 changes: 19 additions & 15 deletions src/components/TranslationBubbleBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import '../styles/TranslationBubbleBody.css';
interface TranslationBubbleBodyProps {
key: string;
message?: any;
perferredLanguage: string;
preferredLanguage: string;
ref?: any;
}

const TranslationBubbleBody: React.FC<TranslationBubbleBodyProps> = (props) => {
const { message, perferredLanguage } = props;
const { message, preferredLanguage } = props;
const { translateTextAsync } = useTranslation();

const [translatedText, setTranslatedText] = useState<undefined | TranslateResponse>();
Expand All @@ -33,37 +33,41 @@ const TranslationBubbleBody: React.FC<TranslationBubbleBodyProps> = (props) => {
marginBottom: '0',
};

// Update default translation language with users perferred language
// Update default translation language with users preferred language
useEffect(() => {
const shortenedLangugeCode = perferredLanguage.split('-')[0];
setCurrentTranslation(shortenedLangugeCode);
}, [perferredLanguage]);
const shortenedLanguageCode = preferredLanguage.split('-')[0];
setCurrentTranslation(shortenedLanguageCode);
}, [preferredLanguage]);

// Make request to translate text
useEffect(() => {
// message.index is populated for messages sent in chat.
if (!message.isFromMe && message.index) {
const shortenedLangugeCode = perferredLanguage.split('-')[0];
const shortenedLanguageCode = preferredLanguage.split('-')[0];

setIsLoading(true);

if (message?.source?.body) {
translateTextAsync(message.source.body, [shortenedLangugeCode, 'en'])
.then((respose) => setTranslatedText(respose.data[0]))

translateTextAsync(message.source.body, [shortenedLanguageCode, 'en'])
.then((res) => setTranslatedText(res.data[0]))
.catch((err) => console.error('Translation error:', err))
.finally(() => setIsLoading(false));

} else if (message?.source?.state?.body) {
translateTextAsync(message.source.state.body, [shortenedLangugeCode, 'en'])
.then((respose) => setTranslatedText(respose.data[0]))

translateTextAsync(message.source.state.body, [shortenedLanguageCode, 'en'])
.then((res) => setTranslatedText(res.data[0]))
.catch((err) => console.error('Translation error:', err))
.finally(() => setIsLoading(false));

}
}
}, [message, perferredLanguage]);
}, [message, preferredLanguage]);

/*
Orger by translation
1. Users perferred language
Order by translation
1. Users preferred language
2. English
3. Original message
*/
Expand All @@ -72,7 +76,7 @@ const TranslationBubbleBody: React.FC<TranslationBubbleBodyProps> = (props) => {
case 'en':
return 'original';
case 'original':
return perferredLanguage.split('-')[0];
return preferredLanguage.split('-')[0];
default:
return 'en';
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/chat/chatAppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const config = (
overrides: generateTheme(isDarkMode, config.theme),
},
context: {
locationOrigin: window.location.origin,
locationOrigin: window.location.href,
friendlyName: config.user.userPrincipalName,
user: config.user,
},
Expand Down
6 changes: 3 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import './styles/FlexChatLoading.css';
import './styles/root.css';

/* import App from './devSetup';
import App from './devSetup';
import React from 'react';
import ReactDOM from 'react-dom'; */
import ReactDOM from 'react-dom';

export * from './interfaces/FlexChat';
export { Manager } from '@twilio/flex-webchat-ui';
Expand All @@ -13,4 +13,4 @@ export { default as UseChatActionsFuncs } from './hooks/useChatActions';

export type { CSSProps, FormAttributes } from '@twilio/flex-webchat-ui';

/* ReactDOM.render(<App />, document.getElementById('root')); */
ReactDOM.render(<App />, document.getElementById('root'));
2 changes: 1 addition & 1 deletion src/interfaces/FlexChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type FlexChatProps = {
children?: ReactNode;
config: ConfigProps;
isDev?: boolean;
isDarkMode: boolean;
isDarkMode?: boolean;
isDisabled?: boolean;
enableTranslation?: boolean;
};
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"resolveJsonModule": true,
"jsx": "react",
"jsx": "react-jsx",
"target": "ES2015",
"moduleResolution": "node",
"noEmit": true,
Expand Down

0 comments on commit 125eb21

Please sign in to comment.