This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMPROVE] Replace i18n package (#657)
- Loading branch information
1 parent
3cc106a
commit 6a16d3b
Showing
154 changed files
with
7,056 additions
and
11,049 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/build/* | ||
/src/i18n/index.js | ||
!/.storybook | ||
|
||
src/i18next.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+644 Bytes
(100%)
...reference/chrome_Messages_MessageList_with_hidden_agent_info_system_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+637 Bytes
(100%)
.loki/reference/chrome_Messages_MessageList_with_system_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-334 Bytes
(99%)
.loki/reference/chrome_Messages_MessageList_with_typing_users.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+266 Bytes
(110%)
.loki/reference/chrome_Messages_MessageTime_yesterday.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+147 Bytes
(100%)
.loki/reference/chrome_Messages_Message_with_UiKit_blocks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+153 Bytes
(100%)
.loki/reference/chrome_Messages_Message_with_files_attachments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+143 Bytes
(100%)
.loki/reference/chrome_Messages_Message_with_image_attachment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+158 Bytes
(100%)
.loki/reference/chrome_Messages_Message_with_quotation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-11 Bytes
(100%)
.loki/reference/chrome_Routes_Chat_with_trigger_messages.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
"eslint": "eslint src", | ||
"stylelint": "stylelint 'src/**/*.scss'", | ||
"storybook": "start-storybook -p 9001 -c .storybook", | ||
"i18n": "i18nline synch && node_modules/.bin/eslint --fix src/i18n/index.js", | ||
"deploy-storybook": "storybook-to-ghpages", | ||
"release": "gh-release -c master --assets build.tar.gz", | ||
"loki:test": "loki test --chromeDockerImage=chinello/alpine-chrome:latest --chromeFlags=\"--headless --no-sandbox --disable-gpu --disable-features=VizDisplayCompositor\" --verboseRenderer --requireReference --reactUri file:./storybook-static", | ||
|
@@ -62,7 +61,6 @@ | |
"loki": "^0.24.0", | ||
"lorem-ipsum": "^2.0.3", | ||
"mini-css-extract-plugin": "^0.11.0", | ||
"node-sass": "^4.14.1", | ||
"npm-run-all": "^4.1.5", | ||
"postcss-css-variables": "^0.17.0", | ||
"postcss-dir-pseudo-class": "^5.0.0", | ||
|
@@ -72,6 +70,7 @@ | |
"postcss-logical": "^4.0.2", | ||
"postcss-selector-not": "^4.0.0", | ||
"rimraf": "^3.0.2", | ||
"sass": "^1.49.10", | ||
"sass-loader": "^9.0.2", | ||
"serve": "^11.3.2", | ||
"style-loader": "^1.2.1", | ||
|
@@ -93,14 +92,14 @@ | |
"desvg": "^1.0.2", | ||
"emoji-mart": "^3.0.0", | ||
"history": "^5.0.0", | ||
"i18nline": "^2.0.1", | ||
"i18next": "^21.3.3", | ||
"markdown-it": "^11.0.0", | ||
"mem": "^6.1.0", | ||
"mitt": "^2.1.0", | ||
"preact": "^10.4.6", | ||
"preact-i18nline": "^2.0.0", | ||
"preact-router": "^3.2.1", | ||
"query-string": "^6.13.1", | ||
"react-i18next": "^11.13.0", | ||
"whatwg-fetch": "^3.4.0" | ||
}, | ||
"browserslist": [ | ||
|
@@ -113,11 +112,6 @@ | |
"gitEmail": "[email protected]", | ||
"commitMessage": "Deploy Storybook to GitHub Pages [skip ci]" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "run-s i18n && git add -A src/i18n" | ||
} | ||
}, | ||
"houston": { | ||
"updateFiles": [ | ||
"package.json" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
import i18next from 'i18next'; | ||
import { h, Component } from 'preact'; | ||
import { Router, route } from 'preact-router'; | ||
import queryString from 'query-string'; | ||
import { withTranslation } from 'react-i18next'; | ||
|
||
import history from '../../history'; | ||
import Connection from '../../lib/connection'; | ||
import CustomFields from '../../lib/customFields'; | ||
import Hooks from '../../lib/hooks'; | ||
import { parentCall } from '../../lib/parentCall'; | ||
import Triggers from '../../lib/triggers'; | ||
import userPresence from '../../lib/userPresence'; | ||
import { ChatConnector } from '../../routes/Chat'; | ||
import ChatFinished from '../../routes/ChatFinished'; | ||
import GDPRAgreement from '../../routes/GDPRAgreement'; | ||
import LeaveMessage from '../../routes/LeaveMessage'; | ||
import Register from '../../routes/Register'; | ||
import SwitchDepartment from '../../routes/SwitchDepartment'; | ||
import TriggerMessage from '../../routes/TriggerMessage'; | ||
import { store } from '../../store'; | ||
import { visibility, isActiveSession, setInitCookies } from '../helpers'; | ||
|
||
function isRTL(s) { | ||
const rtlChars = '\u0591-\u07FF\u200F\u202B\u202E\uFB1D-\uFDFD\uFE70-\uFEFC'; | ||
const rtlDirCheck = new RegExp(`^[^${ rtlChars }]*?[${ rtlChars }]`); | ||
|
||
return rtlDirCheck.test(s); | ||
} | ||
|
||
export class App extends Component { | ||
state = { | ||
initialized: false, | ||
poppedOut: false, | ||
} | ||
|
||
handleRoute = async () => { | ||
setTimeout(() => { | ||
const { | ||
config: { | ||
settings: { | ||
registrationForm, | ||
nameFieldRegistrationForm, | ||
emailFieldRegistrationForm, | ||
forceAcceptDataProcessingConsent: gdprRequired, | ||
}, | ||
online, | ||
departments = [], | ||
}, | ||
gdpr: { | ||
accepted: gdprAccepted, | ||
}, | ||
triggered, | ||
user, | ||
} = this.props; | ||
|
||
setInitCookies(); | ||
|
||
if (gdprRequired && !gdprAccepted) { | ||
return route('/gdpr'); | ||
} | ||
|
||
if (!online) { | ||
parentCall('callback', 'no-agent-online'); | ||
return route('/leave-message'); | ||
} | ||
|
||
const showDepartment = departments.filter((dept) => dept.showOnRegistration).length > 0; | ||
|
||
const showRegistrationForm = ( | ||
registrationForm | ||
&& (nameFieldRegistrationForm || emailFieldRegistrationForm || showDepartment) | ||
) | ||
&& !triggered | ||
&& !(user && user.token); | ||
if (showRegistrationForm) { | ||
return route('/register'); | ||
} | ||
}, 100); | ||
} | ||
|
||
handleTriggers() { | ||
const { config: { online, enabled } } = this.props; | ||
|
||
Triggers.enabled = online && enabled; | ||
|
||
if (online && enabled) { | ||
Triggers.init(); | ||
} | ||
} | ||
|
||
handleEnableNotifications = () => { | ||
const { dispatch, sound = {} } = this.props; | ||
dispatch({ sound: { ...sound, enabled: true } }); | ||
} | ||
|
||
handleDisableNotifications = () => { | ||
const { dispatch, sound = {} } = this.props; | ||
dispatch({ sound: { ...sound, enabled: false } }); | ||
} | ||
|
||
handleMinimize = () => { | ||
parentCall('minimizeWindow'); | ||
const { dispatch } = this.props; | ||
dispatch({ minimized: true }); | ||
} | ||
|
||
handleRestore = () => { | ||
parentCall('restoreWindow'); | ||
const { dispatch, undocked } = this.props; | ||
const dispatchRestore = () => dispatch({ minimized: false, undocked: false }); | ||
const dispatchEvent = () => { | ||
dispatchRestore(); | ||
store.off('storageSynced', dispatchEvent); | ||
}; | ||
if (undocked) { | ||
store.on('storageSynced', dispatchEvent); | ||
} else { | ||
dispatchRestore(); | ||
} | ||
} | ||
|
||
handleOpenWindow = () => { | ||
parentCall('openPopout'); | ||
const { dispatch } = this.props; | ||
dispatch({ undocked: true, minimized: false }); | ||
} | ||
|
||
handleDismissAlert = (id) => { | ||
const { dispatch, alerts = [] } = this.props; | ||
dispatch({ alerts: alerts.filter((alert) => alert.id !== id) }); | ||
} | ||
|
||
handleVisibilityChange = async () => { | ||
const { dispatch } = this.props; | ||
await dispatch({ visible: !visibility.hidden }); | ||
} | ||
|
||
handleLanguageChange = () => { | ||
this.forceUpdate(); | ||
} | ||
|
||
dismissNotification = () => !isActiveSession(); | ||
|
||
initWidget() { | ||
const { minimized, iframe: { visible }, dispatch } = this.props; | ||
parentCall(minimized ? 'minimizeWindow' : 'restoreWindow'); | ||
parentCall(visible ? 'showWidget' : 'hideWidget'); | ||
|
||
visibility.addListener(this.handleVisibilityChange); | ||
this.handleVisibilityChange(); | ||
window.addEventListener('beforeunload', () => { | ||
visibility.removeListener(this.handleVisibilityChange); | ||
dispatch({ minimized: true, undocked: false }); | ||
}); | ||
|
||
i18next.on('languageChanged', this.handleLanguageChange); | ||
} | ||
|
||
checkPoppedOutWindow() { | ||
// Checking if the window is poppedOut and setting parent minimized if yes for the restore purpose | ||
const { dispatch } = this.props; | ||
const poppedOut = queryString.parse(window.location.search).mode === 'popout'; | ||
this.setState({ poppedOut }); | ||
if (poppedOut) { | ||
dispatch({ minimized: false }); | ||
} | ||
} | ||
|
||
async initialize() { | ||
// TODO: split these behaviors into composable components | ||
await Connection.init(); | ||
this.handleTriggers(); | ||
CustomFields.init(); | ||
Hooks.init(); | ||
userPresence.init(); | ||
this.initWidget(); | ||
this.checkPoppedOutWindow(); | ||
|
||
this.setState({ initialized: true }); | ||
parentCall('ready'); | ||
} | ||
|
||
async finalize() { | ||
CustomFields.reset(); | ||
userPresence.reset(); | ||
visibility.removeListener(this.handleVisibilityChange); | ||
} | ||
|
||
componentDidMount() { | ||
this.initialize(); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.finalize(); | ||
} | ||
|
||
componentDidUpdate() { | ||
const { i18n } = this.props; | ||
document.dir = isRTL(i18n.t('yes')) ? 'rtl' : 'ltr'; | ||
} | ||
|
||
render = ({ | ||
sound, | ||
undocked, | ||
minimized, | ||
expanded, | ||
alerts, | ||
modal, | ||
}, { initialized, poppedOut }) => { | ||
if (!initialized) { | ||
return null; | ||
} | ||
const screenProps = { | ||
notificationsEnabled: sound && sound.enabled, | ||
minimized: !poppedOut && (minimized || undocked), | ||
expanded: !minimized && expanded, | ||
windowed: !minimized && poppedOut, | ||
sound, | ||
alerts, | ||
modal, | ||
onEnableNotifications: this.handleEnableNotifications, | ||
onDisableNotifications: this.handleDisableNotifications, | ||
onMinimize: this.handleMinimize, | ||
onRestore: this.handleRestore, | ||
onOpenWindow: this.handleOpenWindow, | ||
onDismissAlert: this.handleDismissAlert, | ||
dismissNotification: this.dismissNotification, | ||
}; | ||
|
||
return ( | ||
<Router history={history} onChange={this.handleRoute}> | ||
<ChatConnector default path='/' {...screenProps} /> | ||
<ChatFinished path='/chat-finished' {...screenProps} /> | ||
<GDPRAgreement path='/gdpr' {...screenProps} /> | ||
<LeaveMessage path='/leave-message' {...screenProps} /> | ||
<Register path='/register' {...screenProps} /> | ||
<SwitchDepartment path='/switch-department' {...screenProps} /> | ||
<TriggerMessage path='/trigger-messages' {...screenProps} /> | ||
</Router> | ||
); | ||
} | ||
} | ||
|
||
export default withTranslation()(App); |
Oops, something went wrong.