From 94355509615ed39f4f70838be7b7398f6e159c96 Mon Sep 17 00:00:00 2001 From: Clement Date: Wed, 18 Aug 2021 01:37:49 +0800 Subject: [PATCH 1/7] WIP: Integrated with BE on Fetch users' name and add new member --- .../club-family/family-member-create.tsx | 116 ++++++++++++++++++ .../webapp/app/entities/club-family/index.tsx | 2 + .../user-cc-info/user-cc-info-detail.tsx | 9 +- .../user-cc-info/user-cc-info.reducer.ts | 5 + .../entities/user-cc-info/user-cc-info.tsx | 11 +- .../user-management.reducer.ts | 8 ++ .../app/shared/model/user-cc-info.model.ts | 8 +- 7 files changed, 144 insertions(+), 15 deletions(-) create mode 100644 src/main/webapp/app/entities/club-family/family-member-create.tsx diff --git a/src/main/webapp/app/entities/club-family/family-member-create.tsx b/src/main/webapp/app/entities/club-family/family-member-create.tsx new file mode 100644 index 00000000..0ad4d9f4 --- /dev/null +++ b/src/main/webapp/app/entities/club-family/family-member-create.tsx @@ -0,0 +1,116 @@ +import React, { ReactNode } from 'react'; + +import { Link, RouteComponentProps } from 'react-router-dom'; +import { Button, Row, Col, Label } from 'reactstrap'; +import { AvForm, AvGroup, AvInput, AvField } from 'availity-reactstrap-validation'; +import { Translate, translate } from 'react-jhipster'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { connect } from 'react-redux'; +import { getUsersWithoutFamily } from 'app/modules/administration/user-management/user-management.reducer'; +import { createEntity } from 'app/entities/user-cc-info/user-cc-info.reducer'; +import { IRootState } from 'app/shared/reducers'; +import { IUser } from 'app/shared/model/user.model'; + +export interface IFamilyMemberCreateProps extends StateProps, DispatchProps, RouteComponentProps {} + +class FamilyMemberCreate extends React.Component { + componentDidMount() { + this.props.getUsersWithoutFamily(); + } + + renderNames(users: readonly IUser[]): ReactNode { + return users.map((user: IUser) => { + if (user) { + return ; + } + }); + } + + saveEntity = (event: any, errors: any, values: any) => { + if (errors.length === 0) { + const { userEntity } = this.props; + const entity = { + ...userEntity, + ...values, + }; + + this.props.createEntity(entity); + } + }; + + render() { + const { users } = this.props; + return ( +
+ + +

Add Family Member

+ +
+ + + + + + + + {this.renderNames(users)} + + + + + + + + + + + + + + + + + + + + +
+ +   + +
+
+ +
+
+ ); + } +} + +// Reducer props +const mapStateToProps = (storeState: IRootState) => ({ + users: storeState.userManagement.users, + userEntity: storeState.userCCInfo.entity, +}); + +// Reducer Action Creators +const mapDispatchToProps = { + getUsersWithoutFamily, + createEntity, +}; + +type StateProps = ReturnType; +type DispatchProps = typeof mapDispatchToProps; + +export default connect(mapStateToProps, mapDispatchToProps)(FamilyMemberCreate); diff --git a/src/main/webapp/app/entities/club-family/index.tsx b/src/main/webapp/app/entities/club-family/index.tsx index 7eced991..c5755e02 100644 --- a/src/main/webapp/app/entities/club-family/index.tsx +++ b/src/main/webapp/app/entities/club-family/index.tsx @@ -7,6 +7,7 @@ import ClubFamily from './club-family'; import ClubFamilyDetail from './club-family-detail'; import ClubFamilyUpdate from './club-family-update'; import ClubFamilyDeleteDialog from './club-family-delete-dialog'; +import FamilyMemberCreate from './family-member-create'; const Routes: React.FC = ({ match }) => ( <> @@ -14,6 +15,7 @@ const Routes: React.FC = ({ match }) => ( + diff --git a/src/main/webapp/app/entities/user-cc-info/user-cc-info-detail.tsx b/src/main/webapp/app/entities/user-cc-info/user-cc-info-detail.tsx index 98ad3329..f3b790e0 100644 --- a/src/main/webapp/app/entities/user-cc-info/user-cc-info-detail.tsx +++ b/src/main/webapp/app/entities/user-cc-info/user-cc-info-detail.tsx @@ -39,7 +39,7 @@ export class UserCCInfoDetail extends React.Component { Club Family Id -
{userCCInfoEntity.clubFamilyId}
+
{userCCInfoEntity.clubFamilyCode}
Family Role @@ -79,7 +79,7 @@ export class UserCCInfoDetail extends React.Component { } const mapStateToProps = ({ userCCInfo }: IRootState) => ({ - userCCInfoEntity: userCCInfo.entity + userCCInfoEntity: userCCInfo.entity, }); const mapDispatchToProps = { getEntity }; @@ -87,7 +87,4 @@ const mapDispatchToProps = { getEntity }; type StateProps = ReturnType; type DispatchProps = typeof mapDispatchToProps; -export default connect( - mapStateToProps, - mapDispatchToProps -)(UserCCInfoDetail); +export default connect(mapStateToProps, mapDispatchToProps)(UserCCInfoDetail); diff --git a/src/main/webapp/app/entities/user-cc-info/user-cc-info.reducer.ts b/src/main/webapp/app/entities/user-cc-info/user-cc-info.reducer.ts index b11dcaf6..46ea2264 100644 --- a/src/main/webapp/app/entities/user-cc-info/user-cc-info.reducer.ts +++ b/src/main/webapp/app/entities/user-cc-info/user-cc-info.reducer.ts @@ -120,6 +120,11 @@ export const getEntity: ICrudGetAction = id => { }; }; +export const getUsersWithoutFamily: ICrudGetAllAction = (page, size, sort) => ({ + type: ACTION_TYPES.FETCH_USERCCINFO_LIST, + payload: axios.get(`${apiUrl}?clubFamilyCode.specified=false`), +}); + export const createEntity: ICrudPutAction = entity => async dispatch => { const result = await dispatch({ type: ACTION_TYPES.CREATE_USERCCINFO, diff --git a/src/main/webapp/app/entities/user-cc-info/user-cc-info.tsx b/src/main/webapp/app/entities/user-cc-info/user-cc-info.tsx index aa84ee16..e5e0b4c0 100644 --- a/src/main/webapp/app/entities/user-cc-info/user-cc-info.tsx +++ b/src/main/webapp/app/entities/user-cc-info/user-cc-info.tsx @@ -66,7 +66,7 @@ export class UserCCInfo extends React.Component { {userCCInfo.userId} - {userCCInfo.clubFamilyId} + {userCCInfo.clubFamilyCode} @@ -110,17 +110,14 @@ export class UserCCInfo extends React.Component { } const mapStateToProps = ({ userCCInfo }: IRootState) => ({ - userCCInfoList: userCCInfo.entities + userCCInfoList: userCCInfo.entities, }); const mapDispatchToProps = { - getEntities + getEntities, }; type StateProps = ReturnType; type DispatchProps = typeof mapDispatchToProps; -export default connect( - mapStateToProps, - mapDispatchToProps -)(UserCCInfo); +export default connect(mapStateToProps, mapDispatchToProps)(UserCCInfo); diff --git a/src/main/webapp/app/modules/administration/user-management/user-management.reducer.ts b/src/main/webapp/app/modules/administration/user-management/user-management.reducer.ts index 61fe950e..62203d50 100644 --- a/src/main/webapp/app/modules/administration/user-management/user-management.reducer.ts +++ b/src/main/webapp/app/modules/administration/user-management/user-management.reducer.ts @@ -118,6 +118,14 @@ export default (state: IUserManagementState = initialState, action: AnyAction): const apiUrl = 'api/users'; // Actions + +export const getUsersWithoutFamily: ICrudGetAllAction = () => { + const requestUrl = `${apiUrl}/family`; + return { + type: ACTION_TYPES.FETCH_USERS, + payload: axios.get(requestUrl), + }; +}; export const getUsers: ICrudGetAllAction = (page, size, sort) => { const requestUrl = `${apiUrl}${sort ? `?page=${page}&size=${size}&sort=${sort}` : ''}`; return { diff --git a/src/main/webapp/app/shared/model/user-cc-info.model.ts b/src/main/webapp/app/shared/model/user-cc-info.model.ts index e1c9e3c1..277a8e7a 100644 --- a/src/main/webapp/app/shared/model/user-cc-info.model.ts +++ b/src/main/webapp/app/shared/model/user-cc-info.model.ts @@ -1,3 +1,5 @@ +import { IUser } from './user.model'; + export const enum ClubFamilyRole { FATHER = 'FATHER', MOTHER = 'MOTHER', @@ -6,11 +8,13 @@ export const enum ClubFamilyRole { export interface IUserCCInfo { id?: number; userId?: number; - clubFamilyId?: number; + clubFamilyCode?: number | string; familyRole?: ClubFamilyRole; yearSession?: string; - clubFamilyName?: string; fishLevel?: string; + clubFamilyName?: string; + clubFamilySlogan?: string; + user?: IUser; } export const defaultValue: Readonly = {}; From e4add152f0a765e060e3b2bbf98b7f3ab23664fe Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 20 Aug 2021 21:46:28 +0800 Subject: [PATCH 2/7] Update BE to get user with no assigned family. Update add family member FE url. Add routing after successfully add user to family or cancel adding --- .../club-family/family-member-create.tsx | 30 +++++++++++++++++-- .../webapp/app/entities/club-family/index.tsx | 2 +- .../user-management.reducer.ts | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/webapp/app/entities/club-family/family-member-create.tsx b/src/main/webapp/app/entities/club-family/family-member-create.tsx index 0ad4d9f4..e8dbb662 100644 --- a/src/main/webapp/app/entities/club-family/family-member-create.tsx +++ b/src/main/webapp/app/entities/club-family/family-member-create.tsx @@ -11,9 +11,23 @@ import { createEntity } from 'app/entities/user-cc-info/user-cc-info.reducer'; import { IRootState } from 'app/shared/reducers'; import { IUser } from 'app/shared/model/user.model'; -export interface IFamilyMemberCreateProps extends StateProps, DispatchProps, RouteComponentProps {} +export interface IFamilyMemberCreateProps extends StateProps, DispatchProps, RouteComponentProps<{ id: string }> {} class FamilyMemberCreate extends React.Component { + constructor(props: IFamilyMemberCreateProps) { + super(props); + } + + componentWillUpdate(nextProps: IFamilyMemberCreateProps) { + if (nextProps.updateSuccess !== this.props.updateSuccess && nextProps.updateSuccess) { + this.handleClose(); + } + } + + handleClose = () => { + this.props.history.push(`/entity/club-family/members/${this.props.match.params.id}`); + }; + componentDidMount() { this.props.getUsersWithoutFamily(); } @@ -40,6 +54,7 @@ class FamilyMemberCreate extends React.Component { render() { const { users } = this.props; + const { id: familyCode } = this.props.match.params; return (
@@ -63,7 +78,7 @@ class FamilyMemberCreate extends React.Component { - + @@ -82,7 +97,14 @@ class FamilyMemberCreate extends React.Component {
-   @@ -102,11 +124,13 @@ class FamilyMemberCreate extends React.Component { const mapStateToProps = (storeState: IRootState) => ({ users: storeState.userManagement.users, userEntity: storeState.userCCInfo.entity, + updateSuccess: storeState.userCCInfo.updateSuccess, }); // Reducer Action Creators const mapDispatchToProps = { getUsersWithoutFamily, + createEntity, }; diff --git a/src/main/webapp/app/entities/club-family/index.tsx b/src/main/webapp/app/entities/club-family/index.tsx index c5755e02..d2e7d05a 100644 --- a/src/main/webapp/app/entities/club-family/index.tsx +++ b/src/main/webapp/app/entities/club-family/index.tsx @@ -15,7 +15,7 @@ const Routes: React.FC = ({ match }) => ( - + diff --git a/src/main/webapp/app/modules/administration/user-management/user-management.reducer.ts b/src/main/webapp/app/modules/administration/user-management/user-management.reducer.ts index 62203d50..68e90876 100644 --- a/src/main/webapp/app/modules/administration/user-management/user-management.reducer.ts +++ b/src/main/webapp/app/modules/administration/user-management/user-management.reducer.ts @@ -120,7 +120,7 @@ const apiUrl = 'api/users'; // Actions export const getUsersWithoutFamily: ICrudGetAllAction = () => { - const requestUrl = `${apiUrl}/family`; + const requestUrl = `${apiUrl}/?family=false`; return { type: ACTION_TYPES.FETCH_USERS, payload: axios.get(requestUrl), From 6f32b6e16722cf4c93e55b096a2afef5a9f764bc Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 21 Aug 2021 16:15:54 +0800 Subject: [PATCH 3/7] Update ClubFamilyRole translation --- src/main/webapp/i18n/en/clubFamilyRole.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/webapp/i18n/en/clubFamilyRole.json b/src/main/webapp/i18n/en/clubFamilyRole.json index 08117534..ff13574e 100644 --- a/src/main/webapp/i18n/en/clubFamilyRole.json +++ b/src/main/webapp/i18n/en/clubFamilyRole.json @@ -1,9 +1,9 @@ { "clubmanagementApp": { "ClubFamilyRole": { - "MEMBER": "MEMBER", - "FATHER": "FATHER", - "MOTHER": "MOTHER" + "MEMBER": "Member", + "FATHER": "Father", + "MOTHER": "Mother" } } } From 89be954d13c49d9e772c1ef9dd078443b925e0b2 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 21 Aug 2021 16:31:17 +0800 Subject: [PATCH 4/7] Update clubFamily.member.createLabel translation --- src/main/webapp/i18n/en/clubFamily.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/i18n/en/clubFamily.json b/src/main/webapp/i18n/en/clubFamily.json index df17f189..540c6cec 100644 --- a/src/main/webapp/i18n/en/clubFamily.json +++ b/src/main/webapp/i18n/en/clubFamily.json @@ -9,7 +9,7 @@ }, "member": { "title": "CClub Family Member", - "createLabel": "Add a new Club Family member", + "createLabel": "Add a new Club Family Member", "createOrEditLabel": "Add or edit a Club Family Member", "notFound": "No CC Family Member found" }, From dfc7a4da3bb5aa771571d1c94115bf52c2f87f19 Mon Sep 17 00:00:00 2001 From: Clement Date: Mon, 23 Aug 2021 00:08:20 +0800 Subject: [PATCH 5/7] Updated and applied concatFullName. Update clubFamily en translation --- .../app/entities/club-family/family-member-create.tsx | 7 ++++++- src/main/webapp/app/shared/util/string-util.ts | 2 +- src/main/webapp/i18n/en/clubFamily.json | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/webapp/app/entities/club-family/family-member-create.tsx b/src/main/webapp/app/entities/club-family/family-member-create.tsx index d10ea43e..61c2f658 100644 --- a/src/main/webapp/app/entities/club-family/family-member-create.tsx +++ b/src/main/webapp/app/entities/club-family/family-member-create.tsx @@ -9,6 +9,7 @@ import { getUsersWithoutFamily } from 'app/modules/administration/user-managemen import { createEntity } from 'app/entities/user-cc-info/user-cc-info.reducer'; import { IRootState } from 'app/shared/reducers'; import { IUser } from 'app/shared/model/user.model'; +import { concatFullName } from 'app/shared/util/string-util'; export interface IFamilyMemberCreateProps extends StateProps, DispatchProps, RouteComponentProps<{ id: string }> {} @@ -34,7 +35,11 @@ class FamilyMemberCreate extends React.Component { renderNames(users: readonly IUser[]): ReactNode { return users.map((user: IUser) => { if (user) { - return ; + return ( + + ); } }); } diff --git a/src/main/webapp/app/shared/util/string-util.ts b/src/main/webapp/app/shared/util/string-util.ts index 8931d755..ca33c38b 100644 --- a/src/main/webapp/app/shared/util/string-util.ts +++ b/src/main/webapp/app/shared/util/string-util.ts @@ -1 +1 @@ -export const concatFullName = (firstName: string, lastName: string) => lastName + ' ' + firstName; +export const concatFullName = (firstName?: string, lastName?: string) => `${firstName ?? ''} ${lastName ?? ''}`; diff --git a/src/main/webapp/i18n/en/clubFamily.json b/src/main/webapp/i18n/en/clubFamily.json index 540c6cec..d071560f 100644 --- a/src/main/webapp/i18n/en/clubFamily.json +++ b/src/main/webapp/i18n/en/clubFamily.json @@ -8,9 +8,9 @@ "notFound": "No CC Family found" }, "member": { - "title": "CClub Family Member", - "createLabel": "Add a new Club Family Member", - "createOrEditLabel": "Add or edit a Club Family Member", + "title": "CC Family Member", + "createLabel": "Add a new CC Family Member", + "createOrEditLabel": "Add or edit a CC Family Member", "notFound": "No CC Family Member found" }, "created": "A new Club Family is created with identifier {{ param }}", From 332883dcb44807cd630e1819a471b517e1114ad1 Mon Sep 17 00:00:00 2001 From: Clement Date: Mon, 23 Aug 2021 00:58:40 +0800 Subject: [PATCH 6/7] Reset store.userCCInfo.entity when page did mount --- .../webapp/app/entities/club-family/family-member-create.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/app/entities/club-family/family-member-create.tsx b/src/main/webapp/app/entities/club-family/family-member-create.tsx index 61c2f658..575978f5 100644 --- a/src/main/webapp/app/entities/club-family/family-member-create.tsx +++ b/src/main/webapp/app/entities/club-family/family-member-create.tsx @@ -6,7 +6,7 @@ import { AvForm, AvGroup, AvInput, AvField } from 'availity-reactstrap-validatio import { Translate, translate } from 'react-jhipster'; import { connect } from 'react-redux'; import { getUsersWithoutFamily } from 'app/modules/administration/user-management/user-management.reducer'; -import { createEntity } from 'app/entities/user-cc-info/user-cc-info.reducer'; +import { createEntity, reset } from 'app/entities/user-cc-info/user-cc-info.reducer'; import { IRootState } from 'app/shared/reducers'; import { IUser } from 'app/shared/model/user.model'; import { concatFullName } from 'app/shared/util/string-util'; @@ -29,6 +29,7 @@ class FamilyMemberCreate extends React.Component { }; componentDidMount() { + this.props.reset(); this.props.getUsersWithoutFamily(); } @@ -140,8 +141,8 @@ const mapStateToProps = (storeState: IRootState) => ({ // Reducer Action Creators const mapDispatchToProps = { getUsersWithoutFamily, - createEntity, + reset, }; type StateProps = ReturnType; From ebf86b277835ba7dd9a43f291bdc4d3b60d5c325 Mon Sep 17 00:00:00 2001 From: Clement Date: Mon, 23 Aug 2021 01:17:20 +0800 Subject: [PATCH 7/7] update getUsersWithoutFamily api url --- .../administration/user-management/user-management.reducer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/app/modules/administration/user-management/user-management.reducer.ts b/src/main/webapp/app/modules/administration/user-management/user-management.reducer.ts index 68e90876..4dccc37d 100644 --- a/src/main/webapp/app/modules/administration/user-management/user-management.reducer.ts +++ b/src/main/webapp/app/modules/administration/user-management/user-management.reducer.ts @@ -120,7 +120,7 @@ const apiUrl = 'api/users'; // Actions export const getUsersWithoutFamily: ICrudGetAllAction = () => { - const requestUrl = `${apiUrl}/?family=false`; + const requestUrl = `${apiUrl}/family?hasFamily=false`; return { type: ACTION_TYPES.FETCH_USERS, payload: axios.get(requestUrl),