[add] Jhipster base
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import axios from 'axios';
|
||||
|
||||
import { REQUEST, SUCCESS, FAILURE } from 'app/shared/reducers/action-type.util';
|
||||
|
||||
export const ACTION_TYPES = {
|
||||
ACTIVATE_ACCOUNT: 'activate/ACTIVATE_ACCOUNT',
|
||||
RESET: 'activate/RESET'
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
activationSuccess: false,
|
||||
activationFailure: false
|
||||
};
|
||||
|
||||
export type ActivateState = Readonly<typeof initialState>;
|
||||
|
||||
// Reducer
|
||||
export default (state: ActivateState = initialState, action): ActivateState => {
|
||||
switch (action.type) {
|
||||
case REQUEST(ACTION_TYPES.ACTIVATE_ACCOUNT):
|
||||
return {
|
||||
...state
|
||||
};
|
||||
case FAILURE(ACTION_TYPES.ACTIVATE_ACCOUNT):
|
||||
return {
|
||||
...state,
|
||||
activationFailure: true
|
||||
};
|
||||
case SUCCESS(ACTION_TYPES.ACTIVATE_ACCOUNT):
|
||||
return {
|
||||
...state,
|
||||
activationSuccess: true
|
||||
};
|
||||
case ACTION_TYPES.RESET:
|
||||
return {
|
||||
...initialState
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
// Actions
|
||||
export const activateAction = key => ({
|
||||
type: ACTION_TYPES.ACTIVATE_ACCOUNT,
|
||||
payload: axios.get('api/activate?key=' + key)
|
||||
});
|
||||
|
||||
export const reset = () => ({
|
||||
type: ACTION_TYPES.RESET
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Link, RouteComponentProps } from 'react-router-dom';
|
||||
import { Row, Col, Alert } from 'reactstrap';
|
||||
|
||||
import { IRootState } from 'app/shared/reducers';
|
||||
import { activateAction, reset } from './activate.reducer';
|
||||
|
||||
const successAlert = (
|
||||
<Alert color="success">
|
||||
<strong>Your user account has been activated.</strong> Please
|
||||
<Link to="/login" className="alert-link">
|
||||
sign in
|
||||
</Link>.
|
||||
</Alert>
|
||||
);
|
||||
|
||||
const failureAlert = (
|
||||
<Alert color="danger">
|
||||
<strong>Your user could not be activated.</strong> Please use the registration form to sign up.
|
||||
</Alert>
|
||||
);
|
||||
|
||||
export interface IActivateProps extends StateProps, DispatchProps, RouteComponentProps<{ key: any }> {}
|
||||
|
||||
export class ActivatePage extends React.Component<IActivateProps> {
|
||||
componentWillUnmount() {
|
||||
this.props.reset();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { key } = this.props.match.params;
|
||||
this.props.activateAction(key);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { activationSuccess, activationFailure } = this.props;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Row className="justify-content-center">
|
||||
<Col md="8">
|
||||
<h1>Activation</h1>
|
||||
{activationSuccess ? successAlert : undefined}
|
||||
{activationFailure ? failureAlert : undefined}
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = ({ activate }: IRootState) => ({
|
||||
activationSuccess: activate.activationSuccess,
|
||||
activationFailure: activate.activationFailure
|
||||
});
|
||||
|
||||
const mapDispatchToProps = { activateAction, reset };
|
||||
|
||||
type StateProps = ReturnType<typeof mapStateToProps>;
|
||||
type DispatchProps = typeof mapDispatchToProps;
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(ActivatePage);
|
||||
Reference in New Issue
Block a user