Skip to content

Commit

Permalink
Front: Fix eslint "components as pure function" warning (#1798)
Browse files Browse the repository at this point in the history
  • Loading branch information
atrovato authored Jun 2, 2023
1 parent 9261098 commit c389040
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 122 deletions.
58 changes: 0 additions & 58 deletions front/src/actions/forgotPassword.js

This file was deleted.

64 changes: 60 additions & 4 deletions front/src/routes/forgot-password/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,68 @@
import { Component } from 'preact';
import { connect } from 'unistore/preact';
import get from 'get-value';

import validateEmail from '../../utils/validateEmail';
import { ForgotPasswordStatus, RequestStatus } from '../../utils/consts';
import ForgotPasswordPage from './ForgotPasswordPage';
import actions from '../../actions/forgotPassword';

class ForgotPassword extends Component {
render(props, {}) {
return <ForgotPasswordPage {...props} />;
forgotPassword = async e => {
const { forgotPasswordEmail } = this.state;
if (e) {
e.preventDefault();
}

if (!validateEmail(forgotPasswordEmail)) {
return this.setState({
forgotPasswordStatus: ForgotPasswordStatus.WrongEmailError
});
}

this.setState({
forgotPasswordStatus: RequestStatus.Getting
});

try {
await this.props.httpClient.post('/api/v1/forgot_password', {
email: forgotPasswordEmail,
origin: window.location.origin
});

this.setState({
forgotPasswordStatus: RequestStatus.Success
});
} catch (e) {
const status = get(e, 'response.status');
if (!status) {
this.setState({
forgotPasswordStatus: RequestStatus.NetworkError
});
} else if (status === 404) {
this.setState({
forgotPasswordStatus: ForgotPasswordStatus.UserNotFound
});
} else if (status === 429) {
this.setState({
forgotPasswordStatus: RequestStatus.RateLimitError
});
} else {
this.setState({
forgotPasswordStatus: RequestStatus.Error
});
}
}
};

updateEmail = e => {
this.setState({
forgotPasswordEmail: e.target.value
});
};

render({}, state) {
return <ForgotPasswordPage {...state} updateEmail={this.updateEmail} forgotPassword={this.forgotPassword} />;
}
}

export default connect('forgotPasswordStatus,forgotPasswordEmail', actions)(ForgotPassword);
export default connect('httpClient')(ForgotPassword);
25 changes: 10 additions & 15 deletions front/src/routes/integration/all/bluetooth/edit-page/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import { Component } from 'preact';
import { connect } from 'unistore/preact';
import BluetoothPage from '../BluetoothPage';
import UpdateDevice from '../../../../../components/device';

const BLUETOOTH_PAGE_PATH = '/dashboard/integration/device/bluetooth';

class BluetoothEditDevicePage extends Component {
render(props, {}) {
return (
<BluetoothPage>
<UpdateDevice
{...props}
integrationName="bluetooth"
allowModifyFeatures={false}
previousPage={BLUETOOTH_PAGE_PATH}
/>
</BluetoothPage>
);
}
}
const BluetoothEditDevicePage = props => (
<BluetoothPage>
<UpdateDevice
{...props}
integrationName="bluetooth"
allowModifyFeatures={false}
previousPage={BLUETOOTH_PAGE_PATH}
/>
</BluetoothPage>
);

export default connect('user,session,httpClient,currentIntegration,houses', {})(BluetoothEditDevicePage);
15 changes: 5 additions & 10 deletions front/src/routes/integration/all/bluetooth/settings-page/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { Component } from 'preact';
import { connect } from 'unistore/preact';

import BluetoothPage from '../BluetoothPage';
import BluetoothSettingsTab from './BluetoothSettingsTab';
import actions from '../commons/actions';

class BluetoothSettingsPage extends Component {
render(props) {
return (
<BluetoothPage>
<BluetoothSettingsTab {...props} />
</BluetoothPage>
);
}
}
const BluetoothSettingsPage = props => (
<BluetoothPage>
<BluetoothSettingsTab {...props} />
</BluetoothPage>
);

export default connect('user,httpClient,bluetoothStatus', actions)(BluetoothSettingsPage);
25 changes: 10 additions & 15 deletions front/src/routes/integration/all/ewelink/edit-page/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { Component } from 'preact';
import { connect } from 'unistore/preact';
import EweLinkPage from '../EweLinkPage';
import UpdateDevice from '../../../../../components/device';

class EditEweLinkDevice extends Component {
render(props, {}) {
return (
<EweLinkPage user={props.user}>
<UpdateDevice
{...props}
integrationName="ewelink"
allowModifyFeatures={false}
previousPage="/dashboard/integration/device/ewelink"
/>
</EweLinkPage>
);
}
}
const EditEweLinkDevice = props => (
<EweLinkPage user={props.user}>
<UpdateDevice
{...props}
integrationName="ewelink"
allowModifyFeatures={false}
previousPage="/dashboard/integration/device/ewelink"
/>
</EweLinkPage>
);

export default connect('user,session,httpClient,currentIntegration,houses', {})(EditEweLinkDevice);
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { Component } from 'preact';
import { connect } from 'unistore/preact';

import LANManagerPage from '../LANManagerPage';
import LANManagerSettingsTab from './LANManagerSettingsTab';

class LANManagerSettingsPage extends Component {
render(props) {
return (
<LANManagerPage>
<LANManagerSettingsTab {...props} />
</LANManagerPage>
);
}
}
const LANManagerSettingsPage = props => (
<LANManagerPage>
<LANManagerSettingsTab {...props} />
</LANManagerPage>
);

export default connect('user,httpClient')(LANManagerSettingsPage);
15 changes: 5 additions & 10 deletions front/src/routes/integration/all/xiaomi/edit-page/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { Component } from 'preact';
import { connect } from 'unistore/preact';
import actions from '../actions';
import XiaomiLayout from '../XiaomiLayout';
import EditPage from './EditPage';

const XIAOMI_PAGE_PATH = '/dashboard/integration/device/xiaomi';

class EditXiaomiDevice extends Component {
render(props, {}) {
return (
<XiaomiLayout>
<EditPage integrationName="xiaomi" allowModifyFeatures={false} previousPage={XIAOMI_PAGE_PATH} {...props} />
</XiaomiLayout>
);
}
}
const EditXiaomiDevice = props => (
<XiaomiLayout>
<EditPage integrationName="xiaomi" allowModifyFeatures={false} previousPage={XIAOMI_PAGE_PATH} {...props} />
</XiaomiLayout>
);

export default connect('user,session,httpClient,currentIntegration,houses', actions)(EditXiaomiDevice);

0 comments on commit c389040

Please sign in to comment.