Skip to content

Commit

Permalink
Merge branch 'dev-version-1' of https://github.com/Five-Fishes/Club-M…
Browse files Browse the repository at this point in the history
…anagement-React-Client into event-attendee

� Conflicts:
�	src/main/webapp/app/entities/event-attendee/event-attendee-create.tsx
�	src/main/webapp/app/entities/event-attendee/event-attendee-delete-dialog.tsx
�	src/main/webapp/app/entities/event-attendee/index.tsx
�	src/main/webapp/i18n/en/eventAttendee.json
�	src/main/webapp/i18n/zh-cn/eventAttendee.json
  • Loading branch information
CarlosSia committed Apr 14, 2021
2 parents 54ca8be + 9730b8b commit bc443ef
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 15 deletions.
162 changes: 162 additions & 0 deletions src/main/webapp/app/entities/event-attendee/event-attendee-create.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import 'app/styles/event-module.scss';
import React from 'react';
import axios from 'axios';
import { connect } from 'react-redux';
import { Link, RouteComponentProps } from 'react-router-dom';
import { Button, Row, Col, Label } from 'reactstrap';
import { AvFeedback, AvForm, AvGroup, AvInput, AvField } from 'availity-reactstrap-validation';
// tslint:disable-next-line:no-unused-variable
import { Translate, translate, ICrudGetAction, ICrudGetAllAction, ICrudPutAction } from 'react-jhipster';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { IRootState } from 'app/shared/reducers';

import { getEntity, updateEntity, createEntity, reset } from './event-attendee.reducer';
import { IEventAttendee } from 'app/shared/model/event-attendee.model';
// tslint:disable-next-line:no-unused-variable
import { IEvent } from 'app/shared/model/event.model';

export interface IEventAttendeeUpdateProps extends StateProps, DispatchProps, RouteComponentProps<{ id: string; eventId: string }> {}

export interface IEventAttendeeUpdateState {
event: IEvent;
}

export class EventAttendeeUpdate extends React.Component<IEventAttendeeUpdateProps, IEventAttendeeUpdateState> {
constructor(props) {
super(props);
this.state = {
event: null
};
}

getEvent = async () => {
const event = await axios.get<IEvent>(`api/events/${this.props.match.params.eventId}`);
this.setState({ event: event.data });
};

componentDidMount() {
this.getEvent();
}

componentWillUpdate(nextProps, nextState) {
if (nextProps.updateSuccess !== this.props.updateSuccess && nextProps.updateSuccess) {
this.handleClose();
}
}

saveEntity = (event, errors, values) => {
if (errors.length === 0) {
const { eventAttendeeEntity } = this.props;
const entity = {
...eventAttendeeEntity,
...values
};

this.props.createEntity(entity);
}
};

handleClose = () => {
this.props.history.push(`/entity/event/${this.props.match.params.eventId}`);
};

render() {
const { userId, loading, updating, match } = this.props;

return (
<div>
<Row className="justify-content-center">
<Col md="8">
<h2 id="clubmanagementApp.eventAttendee.home.createOrEditLabel">
<Translate contentKey="clubmanagementApp.eventAttendee.home.registerLabel">Register as EventAttendee</Translate>
</h2>
</Col>
</Row>
<Row className="justify-content-center">
<Col md="8">
{loading ? (
<p>Loading...</p>
) : (
<AvForm onSubmit={this.saveEntity}>
<AvGroup hidden>
<Label id="userIdLabel" for="event-attendee-userId">
<Translate contentKey="clubmanagementApp.eventAttendee.userId">User</Translate>
</Label>
<AvField id="event-attendee-userId" type="string" className="form-control" name="userId" value={userId} disabled />
</AvGroup>
<AvGroup>
<Label id="eventIdLabel" for="event-attendee-eventId">
<Translate contentKey="clubmanagementApp.event.detail.title">Event</Translate>
</Label>
<AvField
type="string"
className="form-control"
name="event"
value={this.state.event ? this.state.event.name : null}
disabled
/>
<AvField
id="event-attendee-eventId"
type="string"
className="form-control"
name="eventId"
value={match.params.eventId}
disabled
hidden
/>
</AvGroup>
<AvGroup>
<Label id="provideTransportLabel" check>
<AvInput
id="event-attendee-provideTransport"
type="checkbox"
className="form-control transport-checkbox"
name="provideTransport"
/>
<Translate contentKey="clubmanagementApp.eventAttendee.provideTransport">Provide Transport</Translate>
</Label>
</AvGroup>
<div className="text-center mx-4 d-flex justify-content-between justify-content-md-center mb-2">
<Button tag={Link} id="cancel-save" to={`/entity/event/${match.params.eventId}`} replace color="cancel">
<FontAwesomeIcon icon="arrow-left" />
&nbsp;
<Translate contentKey="entity.action.cancel">Cancel</Translate>
</Button>
&nbsp;
<Button color="action" id="save-entity" type="submit" disabled={updating}>
<FontAwesomeIcon icon="save" />
&nbsp;
<Translate contentKey="entity.action.register">Register</Translate>
</Button>
</div>
</AvForm>
)}
</Col>
</Row>
</div>
);
}
}

const mapStateToProps = (storeState: IRootState) => ({
userId: storeState.authentication.id,
eventAttendeeEntity: storeState.eventAttendee.entity,
loading: storeState.eventAttendee.loading,
updating: storeState.eventAttendee.updating,
updateSuccess: storeState.eventAttendee.updateSuccess
});

const mapDispatchToProps = {
getEntity,
updateEntity,
createEntity,
reset
};

type StateProps = ReturnType<typeof mapStateToProps>;
type DispatchProps = typeof mapDispatchToProps;

export default connect(
mapStateToProps,
mapDispatchToProps
)(EventAttendeeUpdate);
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React from 'react';
import { connect } from 'react-redux';
import { RouteComponentProps } from 'react-router-dom';
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
import { Translate, ICrudGetAction, ICrudDeleteAction } from 'react-jhipster';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import { IEventAttendee } from 'app/shared/model/event-attendee.model';
import { IRootState } from 'app/shared/reducers';
import { getEntity, deleteEntity } from './event-attendee.reducer';

export interface IEventAttendeeDeleteDialogProps extends StateProps, DispatchProps, RouteComponentProps<{ attendeeId: string }> {}

export class EventAttendeeDeleteDialog extends React.Component<IEventAttendeeDeleteDialogProps> {
componentDidMount() {
this.props.getEntity(this.props.match.params.attendeeId);
}

confirmDelete = event => {
this.props.deleteEntity(this.props.eventAttendeeEntity.id);
this.handleClose(event);
};

handleClose = event => {
event.stopPropagation();
this.props.history.goBack();
};

render() {
const { eventAttendeeEntity } = this.props;
return (
<Modal isOpen toggle={this.handleClose}>
<ModalHeader toggle={this.handleClose}>
<Translate contentKey="entity.delete.title">Confirm delete operation</Translate>
</ModalHeader>
<ModalBody id="clubmanagementApp.eventAttendee.delete.question">
<Translate contentKey="clubmanagementApp.eventAttendee.delete.question">Are you sure you want to unregister?</Translate>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.handleClose}>
<FontAwesomeIcon icon="ban" />
&nbsp;
<Translate contentKey="entity.action.no">No</Translate>
</Button>
<Button id="jhi-confirm-delete-eventAttendee" color="cancel" onClick={this.confirmDelete}>
<FontAwesomeIcon icon="trash" />
&nbsp;
<Translate contentKey="entity.action.yes">Yes</Translate>
</Button>
</ModalFooter>
</Modal>
);
}
}

const mapStateToProps = ({ eventAttendee }: IRootState) => ({
eventAttendeeEntity: eventAttendee.entity
});

const mapDispatchToProps = { getEntity, deleteEntity };

type StateProps = ReturnType<typeof mapStateToProps>;
type DispatchProps = typeof mapDispatchToProps;

export default connect(
mapStateToProps,
mapDispatchToProps
)(EventAttendeeDeleteDialog);
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ export const getEntity: ICrudGetAction<IEventAttendee> = id => {
};
};

export const getEntityByEventIdAndUserId = (eventId, userId) => {
const requestUrl = `${apiUrl}/event/${eventId}/user/${userId}`;
return {
type: ACTION_TYPES.FETCH_EVENTATTENDEE,
payload: axios.get<IEventAttendee>(requestUrl)
};
};

export const createEntity: ICrudPutAction<IEventAttendee> = entity => async dispatch => {
const result = await dispatch({
type: ACTION_TYPES.CREATE_EVENTATTENDEE,
Expand Down
10 changes: 9 additions & 1 deletion src/main/webapp/app/entities/event-attendee/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React from 'react';
import { Switch } from 'react-router-dom';

import ErrorBoundaryRoute from 'app/shared/error/error-boundary-route';

import EventAttendee from './event-attendee';
import EventAttendeeDetail from './event-attendee-detail';
import EventAttendeeUpdate from './event-attendee-create';

const Routes = ({ match }) => (
<>
<ErrorBoundaryRoute exact path={`${match.url}/event/:eventId`} component={EventAttendee} />
<Switch>
<ErrorBoundaryRoute exact path={`${match.url}/event/:eventId/new`} component={EventAttendeeUpdate} />
<ErrorBoundaryRoute exact path={`${match.url}/:id/edit`} component={EventAttendeeUpdate} />
<ErrorBoundaryRoute exact path={`${match.url}/:id`} component={EventAttendeeDetail} />
<ErrorBoundaryRoute exact path={`${match.url}/event/:eventId`} component={EventAttendee} />
</Switch>
</>
);

Expand Down
34 changes: 27 additions & 7 deletions src/main/webapp/app/entities/event/event-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import { IRootState } from 'app/shared/reducers';
import { getEntity } from './event.reducer';
import { getEntityByEventIdAndUserId } from '../event-attendee/event-attendee.reducer';

// tslint:disable-next-line:no-unused-variable
import { APP_LOCAL_TIME_FORMAT, APP_LOCAL_DATE_FORMAT } from 'app/config/constants';
Expand All @@ -23,8 +24,14 @@ export class EventDetail extends React.Component<IEventDetailProps> {
this.props.getEntity(this.props.match.params.id);
}

componentDidUpdate(prevProps) {
if (prevProps.userId !== this.props.userId && !isNaN(this.props.userId)) {
this.props.getEntityByEventIdAndUserId(this.props.match.params.id, this.props.userId);
}
}

render() {
const { eventEntity } = this.props;
const { eventEntity, eventAttendeeEntity } = this.props;
const eventId = this.props.match.params.id;
return (
<Container>
Expand Down Expand Up @@ -70,9 +77,20 @@ export class EventDetail extends React.Component<IEventDetailProps> {
<Button tag={Link} to={`/entity/event/${eventEntity.id}/edit`} replace className="my-1" color="secondary">
Update
</Button>
<Button className="my-1" color="action">
Register
</Button>
{eventAttendeeEntity.userId ? (
<Button
tag={Link}
to={`/entity/event/${eventEntity.id}/eventAttendee/${eventAttendeeEntity.id}/delete`}
className="my-1"
color="cancel"
>
Deregister
</Button>
) : (
<Button tag={Link} to={`/entity/event-attendee/event/${eventEntity.id}/new`} className="my-1" color="action">
Register
</Button>
)}
</div>
</div>
</div>
Expand All @@ -81,11 +99,13 @@ export class EventDetail extends React.Component<IEventDetailProps> {
}
}

const mapStateToProps = ({ event }: IRootState) => ({
eventEntity: event.entity
const mapStateToProps = ({ event, authentication, eventAttendee }: IRootState) => ({
eventEntity: event.entity,
userId: authentication.id,
eventAttendeeEntity: eventAttendee.entity
});

const mapDispatchToProps = { getEntity };
const mapDispatchToProps = { getEntity, getEntityByEventIdAndUserId };

type StateProps = ReturnType<typeof mapStateToProps>;
type DispatchProps = typeof mapDispatchToProps;
Expand Down
6 changes: 4 additions & 2 deletions src/main/webapp/app/entities/event/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import Event from './event';
import EventDetail from './event-detail';
import EventUpdate from './event-update';
import EventDeleteDialog from './event-delete-dialog';
import EventAttendeeDeleteDialog from '../event-attendee/event-attendee-delete-dialog';

const Routes = ({ match }) => (
<>
<Switch>
<ErrorBoundaryRoute exact path={`${match.url}/new`} component={EventUpdate} />
<ErrorBoundaryRoute exact path={`${match.url}/:id/edit`} component={EventUpdate} />
<ErrorBoundaryRoute exact path={`${match.url}/:id`} component={EventDetail} />
<ErrorBoundaryRoute path={match.url} component={Event} />
<ErrorBoundaryRoute path={`${match.url}/:id`} component={EventDetail} />
<ErrorBoundaryRoute exact path={match.url} component={Event} />
</Switch>
<ErrorBoundaryRoute path={`${match.url}/:id/delete`} component={EventDeleteDialog} />
<ErrorBoundaryRoute path={`${match.url}/:id/eventAttendee/:attendeeId/delete`} component={EventAttendeeDeleteDialog} />
</>
);

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/app/entities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Routes = ({ match }) => (
<ErrorBoundaryRoute path={`${match.url}/event-attendee`} component={EventAttendee} />
<ErrorBoundaryRoute path={`${match.url}/event-budget`} component={Budget} />
<ErrorBoundaryRoute path={`${match.url}/event-activity`} component={EventActivity} />
<ErrorBoundaryRoute path={`${match.url}/event-checklists`} component={EventChecklist} />
<ErrorBoundaryRoute path={`${match.url}/event-checklist`} component={EventChecklist} />
<ErrorBoundaryRoute path={`${match.url}/transaction`} component={Transaction} />
<ErrorBoundaryRoute path={`${match.url}/claim`} component={Claim} />
<ErrorBoundaryRoute path={`${match.url}/debt`} component={Debt} />
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/app/styles/event-module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
color: #0e516d !important;
font-size: 32px;
}

.transport-checkbox {
height: 25px !important;
margin-top: 0px;
}
3 changes: 2 additions & 1 deletion src/main/webapp/i18n/en/eventAttendee.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"title": "Event Attendees",
"createLabel": "Create a new Event Attendee",
"createOrEditLabel": "Create or edit a Event Attendee",
"registerLabel": "Register as Event Attendee",
"notFound": "No Event Attendee found",
"sortBy": "Sort By"
},
Expand All @@ -20,7 +21,7 @@
"updated": "A Event Attendee is updated with identifier {{ param }}",
"deleted": "A Event Attendee is deleted with identifier {{ param }}",
"delete": {
"question": "Are you sure you want to delete Event Attendee {{ id }}?"
"question": "Are you sure you want to deregister?"
},
"detail": {
"title": "Event Attendee"
Expand Down
Loading

0 comments on commit bc443ef

Please sign in to comment.