-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new Free Mobile SMS integration (#2157)
Co-authored-by: Pierre-Gilles Leymarie <[email protected]>
- Loading branch information
1 parent
5182656
commit 88f8b13
Showing
19 changed files
with
650 additions
and
4 deletions.
There are no files selected for viewing
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
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
112 changes: 112 additions & 0 deletions
112
front/src/routes/integration/all/free-mobile/FreeMobile.jsx
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,112 @@ | ||
import { Text, MarkupText, Localizer } from 'preact-i18n'; | ||
import cx from 'classnames'; | ||
import { RequestStatus } from '../../../../utils/consts'; | ||
import DeviceConfigurationLink from '../../../../components/documentation/DeviceConfigurationLink'; | ||
|
||
const FreeMobilePage = ({ children, ...props }) => ( | ||
<div class="page"> | ||
<div class="page-main"> | ||
<div class="my-3 my-md-5"> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-lg-3"> | ||
<h3 class="page-title mb-5"> | ||
<Text id="integration.free-mobile.title" /> | ||
</h3> | ||
<div> | ||
<div class="list-group list-group-transparent mb-0"> | ||
<DeviceConfigurationLink | ||
user={props.user} | ||
configurationKey="integrations" | ||
documentKey="free-mobile" | ||
linkClass="list-group-item list-group-item-action d-flex align-items-center" | ||
> | ||
<span class="icon mr-3"> | ||
<i class="fe fe-book-open" /> | ||
</span> | ||
<Text id="integration.free-mobile.documentation" /> | ||
</DeviceConfigurationLink> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="col-lg-9"> | ||
<div class="card"> | ||
<div class="card-header"> | ||
<h1 class="card-title"> | ||
<Text id="integration.free-mobile.title" /> | ||
</h1> | ||
</div> | ||
<div class="card-body"> | ||
<div | ||
class={cx('dimmer', { | ||
active: props.loading | ||
})} | ||
> | ||
<div class="loader" /> | ||
<div class="dimmer-content"> | ||
<p> | ||
<MarkupText id="integration.free-mobile.introduction" /> | ||
</p> | ||
{props.freeMobileSaveSettingsStatus === RequestStatus.Error && ( | ||
<div class="alert alert-danger"> | ||
<Text id="integration.free-mobile.configurationError" /> | ||
</div> | ||
)} | ||
{props.freeMobileSaveSettingsStatus === RequestStatus.Success && ( | ||
<div class="alert alert-info"> | ||
<Text id="integration.free-mobile.configurationSuccess" /> | ||
</div> | ||
)} | ||
<form onSubmit={props.saveFreeMobileSettings}> | ||
<div class="form-group"> | ||
<div class="form-label"> | ||
<Text id={`integration.free-mobile.username`} /> | ||
</div> | ||
<Localizer> | ||
<input | ||
type="text" | ||
class="form-control" | ||
placeholder={<Text id="integration.free-mobile.username" />} | ||
onInput={props.updateFreeMobileUsername} | ||
value={props.freeMobileUsername} | ||
/> | ||
</Localizer> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="form-label"> | ||
<Text id={`integration.free-mobile.key`} /> | ||
</div> | ||
<Localizer> | ||
<input | ||
type="text" | ||
class="form-control" | ||
placeholder={<Text id="integration.free-mobile.key" />} | ||
onInput={props.updateFreeMobileAccessToken} | ||
value={props.freeMobileAccessToken} | ||
/> | ||
</Localizer> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<span class="input-group-append"> | ||
<button type="submit" class="btn btn-primary"> | ||
<Text id={`integration.free-mobile.saveButton`} /> | ||
</button> | ||
</span> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
export default FreeMobilePage; |
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,68 @@ | ||
import { RequestStatus } from '../../../../utils/consts'; | ||
|
||
const actions = store => ({ | ||
updateFreeMobileUsername(state, e) { | ||
store.setState({ | ||
freeMobileUsername: e.target.value | ||
}); | ||
}, | ||
|
||
updateFreeMobileAccessToken(state, e) { | ||
store.setState({ | ||
freeMobileAccessToken: e.target.value | ||
}); | ||
}, | ||
|
||
async getFreeMobileSettings(state) { | ||
store.setState({ | ||
freeMobileGetSettingsStatus: RequestStatus.Getting | ||
}); | ||
try { | ||
const username = await state.httpClient.get('/api/v1/service/free-mobile/variable/FREE_MOBILE_USERNAME'); | ||
store.setState({ | ||
freeMobileUsername: username.value | ||
}); | ||
|
||
const accessToken = await state.httpClient.get('/api/v1/service/free-mobile/variable/FREE_MOBILE_ACCESS_TOKEN'); | ||
store.setState({ | ||
freeMobileAccessToken: accessToken.value, | ||
freeMobileGetSettingsStatus: RequestStatus.Success | ||
}); | ||
} catch (e) { | ||
store.setState({ | ||
freeMobileGetSettingsStatus: RequestStatus.Error | ||
}); | ||
} | ||
}, | ||
|
||
async saveFreeMobileSettings(state, e) { | ||
e.preventDefault(); | ||
store.setState({ | ||
freeMobileSaveSettingsStatus: RequestStatus.Getting | ||
}); | ||
try { | ||
store.setState({ | ||
freeMobileUsername: state.freeMobileUsername.trim(), | ||
freeMobileAccessToken: state.freeMobileAccessToken.trim() | ||
}); | ||
await state.httpClient.post('/api/v1/service/free-mobile/variable/FREE_MOBILE_USERNAME', { | ||
value: state.freeMobileUsername.trim() | ||
}); | ||
await state.httpClient.post('/api/v1/service/free-mobile/variable/FREE_MOBILE_ACCESS_TOKEN', { | ||
value: state.freeMobileAccessToken.trim() | ||
}); | ||
|
||
// start service | ||
await state.httpClient.post('/api/v1/service/free-mobile/start'); | ||
store.setState({ | ||
freeMobileSaveSettingsStatus: RequestStatus.Success | ||
}); | ||
} catch (e) { | ||
store.setState({ | ||
freeMobileSaveSettingsStatus: RequestStatus.Error | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
export default actions; |
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,23 @@ | ||
import { Component } from 'preact'; | ||
import { connect } from 'unistore/preact'; | ||
import actions from './actions'; | ||
import FreeMobilePage from './FreeMobile'; | ||
import { RequestStatus } from '../../../../utils/consts'; | ||
|
||
class FreeMobileIntegration extends Component { | ||
componentWillMount() { | ||
this.props.getFreeMobileSettings(); | ||
} | ||
|
||
render(props, {}) { | ||
const loading = | ||
props.freeMobileGetSettingsStatus === RequestStatus.Getting || | ||
props.freeMobileSaveSettingsStatus === RequestStatus.Getting; | ||
return <FreeMobilePage {...props} loading={loading} />; | ||
} | ||
} | ||
|
||
export default connect( | ||
'user,freeMobileUsername,freeMobileAccessToken,freeMobileGetSettingsStatus,freeMobileSaveSettingsStatus', | ||
actions | ||
)(FreeMobileIntegration); |
Oops, something went wrong.