Skip to content

Commit

Permalink
eWelink: setup and login pages
Browse files Browse the repository at this point in the history
  • Loading branch information
atrovato committed Dec 1, 2023
1 parent ad834b8 commit 0adff6c
Show file tree
Hide file tree
Showing 15 changed files with 785 additions and 121 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions front/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ import EweLinkPage from '../routes/integration/all/ewelink/device-page';
import EweLinkEditPage from '../routes/integration/all/ewelink/edit-page';
import EweLinkDiscoverPage from '../routes/integration/all/ewelink/discover-page';
import EweLinkSetupPage from '../routes/integration/all/ewelink/setup-page';
import EweLinkSetupLoginPage from '../routes/integration/all/ewelink/setup-page/login';

// OpenAI integration
import OpenAIPage from '../routes/integration/all/openai/index';
Expand Down Expand Up @@ -271,6 +272,7 @@ const AppRouter = connect(
<EweLinkEditPage path="/dashboard/integration/device/ewelink/edit/:deviceSelector" />
<EweLinkDiscoverPage path="/dashboard/integration/device/ewelink/discover" />
<EweLinkSetupPage path="/dashboard/integration/device/ewelink/setup" />
<EweLinkSetupLoginPage path="/dashboard/integration/device/ewelink/setup/login" />
<HomeKitPage path="/dashboard/integration/communication/homekit" />
<OpenAIPage path="/dashboard/integration/communication/openai" />

Expand Down
3 changes: 2 additions & 1 deletion front/src/components/header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const PAGES_WITHOUT_HEADER = [
'/confirm-email',
'/dashboard/integration/device/google-home/authorize',
'/dashboard/integration/device/alexa/authorize',
'/locked'
'/locked',
'/dashboard/integration/device/ewelink/setup/login'
];

const Header = ({ ...props }) => {
Expand Down
15 changes: 15 additions & 0 deletions front/src/config/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3132,6 +3132,21 @@ const data = {
]
}
],
'get /api/v1/service/ewelink/status': {
configured: true,
connected: true
},
'get /api/v1/service/ewelink/config': {
application_id: 'ewelink_APPID',
application_secret: 'ewelink_APP_SECRET',
application_region: 'eu'
},
'post /api/v1/service/ewelink/config': {
application_id: 'ewelink_APPID',
application_secret: 'ewelink_APP_SECRET',
application_region: 'eu'
},
'post /api/v1/service/ewelink/token': {},
'get /api/v1/service/tp-link': {
id: 'c9fe2705-35dc-417b-b6fc-c4bbb9c69886',
pod_id: null,
Expand Down
32 changes: 23 additions & 9 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"degreeValue": "{{value}}°",
"workInProgress": "Work in progress...",
"save": "Save",
"edit": "Edit",
"cancel": "Cancel",
"celsius": "C",
"fahrenheit": "F",
"metersPerSec": "m/s",
Expand Down Expand Up @@ -1430,15 +1432,27 @@
"setup": {
"title": "eWeLink configuration",
"eweLinkDescription": "You can connect Gladys to your eWeLink cloud account to command the associated devices.",
"userLabel": "Username",
"userPlaceholder": "Enter eWeLink username",
"passwordLabel": "Password",
"passwordPlaceholder": "Enter eWeLink password",
"saveLabel": "Save configuration",
"error": "An error occured while saving configuration.",
"connecting": "Configuration saved. Now connecting to your eWeLink cloud account...",
"connected": "Connected to the eWeLink cloud account with success !",
"connectionError": "Error while connecting, please check your configuration."
"applicationSetupLabel": "eWeLink application setup",
"applicationIdLabel": "Application Identifier (APPID)",
"applicationIdPlaceholder": "Enter APPID value",
"applicationSecretLabel": "Application Secret (APP SECRET)",
"applicationSecretPlaceholder": "Enter APP SECRET value",
"applicationRegionLabel": "Region",
"userConnectedLabel": "Connected",
"userNotConnectedLabel": "No user connected",
"connectLabel": "Connect",
"disconnectLabel": "Disconnect",
"loadStatusError": "An error occured while fetching eWeLink integration status. Gladys may be not reachable.",
"saveConfigError": "Unable to save eWeLink application configuration. Gladys may be not reachable.",
"loginRedirectError": "An error occured while connecting to eWeLink, please contact Gladys community.",
"exchangeTokenError": "An error occured while connecting to exchanging eWeLink user token, please contact Gladys community.",
"exchangeTokenSuccess": "Authentication succeed, current tab can be closed.",
"regions": {
"cn": "Mainland China",
"as": "Asia",
"us": "Americas",
"eu": "Europe"
}
},
"error": {
"defaultError": "There was an error saving the device.",
Expand Down
32 changes: 23 additions & 9 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"degreeValue": "{{value}}°",
"workInProgress": "Travail en cours...",
"save": "Enregistrer",
"edit": "Modifier",
"cancel": "Annuler",
"celsius": "C",
"fahrenheit": "F",
"metersPerSec": "m/s",
Expand Down Expand Up @@ -1432,15 +1434,27 @@
"setup": {
"title": "Configuration eWeLink",
"eweLinkDescription": "Vous pouvez connecter Gladys à votre compte cloud eWeLink pour commander les appareils associés.",
"userLabel": "Nom d'utilisateur",
"userPlaceholder": "Entrez le nom d'utilisateur eWeLink",
"passwordLabel": "Mot de passe",
"passwordPlaceholder": "Entrez le mot de passe utilisateur eWeLink",
"saveLabel": "Enregistrer la configuration",
"error": "Une erreur s'est produite lors de la sauvegarde de la configuration.",
"connecting": "Configuration sauvegardée. Connexion à votre compte cloud eWeLink...",
"connected": "Connexion réussie au compte cloud eWeLink !",
"connectionError": "Erreur lors de la connexion, veuillez vérifier votre configuration."
"applicationSetupLabel": "Configurationde l'application eWeLink",
"applicationIdLabel": "Identifiant de l'application (APPID)",
"applicationIdPlaceholder": "Entrez la valeur de APPID",
"applicationSecretLabel": "Secret de l'application (APP SECRET)",
"applicationSecretPlaceholder": "Entrez la valeur de APP SECRET",
"applicationRegionLabel": "Region",
"userConnectedLabel": "Connecté",
"userNotConnectedLabel": "Aucun utilisateur connecté",
"connectLabel": "Connexion",
"disconnectLabel": "Déconnexion",
"loadStatusError": "Impossible de remonter les informations sur l'état de l'intégration eWeLink. Gladys ne semble pas joignable.",
"saveConfigError": "Impossible d'enregistrer la configuration de l'application eWeLink. Gladys ne semble pas joignable.",
"loginRedirectError": "Une erreur est survenue lors de la connexion à eWeLink, merci de contacter la communauté.",
"exchangeTokenError": "Une erreur est survenue lors de la génération du jeton utilisateur eWeLink, merci de contacter la communauté.",
"exchangeTokenSuccess": "L'authentification est un succès, cette page peut être fermée.",
"regions": {
"cn": "Chine",
"as": "Asie",
"us": "Ameriques",
"eu": "Europe"
}
},
"error": {
"defaultError": "Une erreur s'est produite lors de l'enregistrement de l'appareil.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import { Component } from 'preact';
import { Localizer, Text } from 'preact-i18n';
import cx from 'classnames';

import { REGIONS } from './constants';

class ApplicationSetup extends Component {
showPasswordTimer = null;

updateApplicationId = event => {
const { value: applicationId } = event.target;
this.setState({ applicationId });
};

updateApplicationSecret = event => {
const { value: applicationSecret } = event.target;
this.setState({ applicationSecret });
};

updateApplicationRegion = event => {
const { value: applicationRegion } = event.target;
this.setState({ applicationRegion });
};

saveConfiguration = async event => {
event.preventDefault();
const { applicationId, applicationSecret, applicationRegion } = this.state;
const configuration = { applicationId, applicationSecret, applicationRegion };
this.props.saveConfiguration(configuration);
};

resetConfiguration = event => {
event.preventDefault();
const { ewelinkConfig = {} } = this.props;
const { applicationId = '', applicationSecret = '', applicationRegion } = ewelinkConfig;
this.setState({ applicationId, applicationSecret, applicationRegion });
this.props.resetConfiguration();
};

togglePassword = () => {
const { showPassword } = this.state;

if (this.showPasswordTimer) {
clearTimeout(this.showPasswordTimer);
this.showPasswordTimer = null;
}

this.setState({ showPassword: !showPassword });

if (!showPassword) {
this.showPasswordTimer = setTimeout(() => this.setState({ showPassword: false }), 5000);
}
};

constructor(props) {
super(props);

const { ewelinkConfig = {} } = props;
const { applicationId = '', applicationSecret = '', applicationRegion } = ewelinkConfig;
this.state = {
applicationId,
applicationSecret,
applicationRegion
};
}

componentWillUnmount() {
if (this.showPasswordTimer) {
clearTimeout(this.showPasswordTimer);
this.showPasswordTimer = null;
}
}

componentWillReceiveProps(nextProps) {
const { ewelinkConfig = {} } = nextProps;
const { applicationId = '', applicationSecret = '', applicationRegion } = ewelinkConfig;
const {
applicationId: currentApplicationId,
applicationSecret: currentApplicationSecret,
applicationRegion: currentApplicationRegion
} = this.state;

if (
applicationId !== currentApplicationId ||
applicationSecret !== currentApplicationSecret ||
applicationRegion !== currentApplicationRegion
) {
this.setState({ applicationId, applicationSecret, applicationRegion });
}
}

render({ disabled }, { applicationId, applicationSecret, applicationRegion, showPassword }) {
const saveDisabled = applicationId === '' || applicationSecret === '' || !applicationRegion;
return (
<form onSubmit={this.saveConfiguration} autocomplete="off" data-cy="ewelink-application-setup-form">
<div class="form-group">
<label for="eweLinkAppId" class="form-label">
<Text id={'integration.eWeLink.setup.applicationIdLabel'} />
</label>
<Localizer>
<input
id="eweLinkAppId"
class="form-control"
placeholder={<Text id="integration.eWeLink.setup.applicationIdPlaceholder" />}
value={applicationId}
onInput={this.updateApplicationId}
disabled={disabled}
autocomplete="off"
required
data-cy="ewelink-application-setup-app-id"
/>
</Localizer>
</div>
<div class="form-group">
<label for="eweLinkAppSecret" class="form-label">
<Text id={'integration.eWeLink.setup.applicationSecretLabel'} />
</label>
<div class="input-icon mb-3">
<Localizer>
<input
id="eweLinkAppSecret"
class="form-control"
type={showPassword ? 'text' : 'password'}
placeholder={<Text id="integration.eWeLink.setup.applicationSecretPlaceholder" />}
value={applicationSecret}
onInput={this.updateApplicationSecret}
disabled={disabled}
autocomplete="off"
required
data-cy="ewelink-application-setup-app-secret"
/>
</Localizer>
<span class="input-icon-addon cursor-pointer" onClick={this.togglePassword}>
<i
class={cx('fe', {
'fe-eye': !showPassword,
'fe-eye-off': showPassword
})}
/>
</span>
</div>
</div>
<div class="form-group">
<label for="eweLinkAppRegion" class="form-label">
<Text id={'integration.eWeLink.setup.applicationRegionLabel'} />
</label>
<div class="input-icon mb-3">
<Localizer>
<select
id="eweLinkAppRegion"
class="form-control"
onChange={this.updateApplicationRegion}
disabled={disabled}
required
data-cy="ewelink-application-setup-app-region"
value={applicationRegion}
>
{REGIONS.map(region => (
<option value={region}>
<Text id={`integration.eWeLink.setup.regions.${region}`}>{region}</Text>
</option>
))}
</select>
</Localizer>
</div>
</div>
<div class="d-flex form-group">
<button
type="submit"
class="btn btn-success mx-auto"
disabled={saveDisabled || disabled}
data-cy="ewelink-application-setup-save"
>
<i class="fe fe-save mr-2" />
<Text id="global.save" />
</button>
<button
class="btn btn-primary mx-auto"
onClick={this.resetConfiguration}
disabled={disabled}
data-cy="ewelink-application-setup-cancel"
>
<i class="fe fe-rotate-ccw mr-2" />
<Text id="global.cancel" />
</button>
</div>
</form>
);
}
}

export default ApplicationSetup;
Loading

0 comments on commit 0adff6c

Please sign in to comment.