diff --git a/app/frontend/src/javascript/api/member.ts b/app/frontend/src/javascript/api/member.ts index e3610758b..457f9700d 100644 --- a/app/frontend/src/javascript/api/member.ts +++ b/app/frontend/src/javascript/api/member.ts @@ -14,7 +14,7 @@ export default class MemberAPI { if (user.profile_attributes.user_avatar_attributes.attachment_files[0]) { data.set('user[profile_attributes][user_avatar_attributes][attachment]', user.profile_attributes.user_avatar_attributes.attachment_files[0]); } - const res: AxiosResponse = await apiClient.post('/api/members/create', data, { + const res: AxiosResponse = await apiClient.post('/api/members', data, { headers: { 'Content-Type': 'multipart/form-data' } diff --git a/app/frontend/src/javascript/components/user/user-profile-form.tsx b/app/frontend/src/javascript/components/user/user-profile-form.tsx index abd62d62d..6f7b00f5c 100644 --- a/app/frontend/src/javascript/components/user/user-profile-form.tsx +++ b/app/frontend/src/javascript/components/user/user-profile-form.tsx @@ -143,13 +143,13 @@ export const UserProfileForm: React.FC = ({ action, size, return value === true || (t('app.shared.user_profile_form.must_accept_terms') as string); }; - const userNetworks = new UserLib(user).getUserSocialNetworks(user); + const userNetworks = new UserLib(user).getUserSocialNetworks(); return (
- diff --git a/app/frontend/src/javascript/controllers/admin/members.js b/app/frontend/src/javascript/controllers/admin/members.js index bd6cb425b..c01c793dd 100644 --- a/app/frontend/src/javascript/controllers/admin/members.js +++ b/app/frontend/src/javascript/controllers/admin/members.js @@ -816,7 +816,7 @@ Application.Controllers.controller('EditMemberController', ['$scope', '$state', /** * Callback triggered when the user was successfully updated */ - $scope.onUserSuccess = (user) => { + $scope.onUserSuccess = () => { growl.success(_t('app.admin.members_edit.update_success')); $state.go('app.admin.members'); }; @@ -937,8 +937,8 @@ Application.Controllers.controller('EditMemberController', ['$scope', '$state', /** * Controller used in the member's creation page (admin view) */ -Application.Controllers.controller('NewMemberController', ['$scope', '$state', 'Member', 'Training', 'Group', 'CSRF', 'settingsPromise', - function ($scope, $state, Member, Training, Group, CSRF, settingsPromise) { +Application.Controllers.controller('NewMemberController', ['$scope', '$state', 'Member', 'Training', 'Group', 'CSRF', 'settingsPromise', 'growl', '_t', + function ($scope, $state, Member, Training, Group, CSRF, settingsPromise, growl, _t) { CSRF.setMetaTags(); /* PUBLIC SCOPE */ @@ -976,6 +976,21 @@ Application.Controllers.controller('NewMemberController', ['$scope', '$state', ' } }; + /** + * Callback triggered when the user was successfully updated + */ + $scope.onUserSuccess = () => { + growl.success(_t('app.admin.members_new.create_success')); + $state.go('app.admin.members'); + }; + + /** + * Callback triggered in case of error + */ + $scope.onError = (message) => { + growl.error(message); + }; + // Using the MembersController return new MembersController($scope, $state, Group, Training); } diff --git a/app/frontend/src/javascript/lib/user.ts b/app/frontend/src/javascript/lib/user.ts index 043727ae7..c9b3a6b57 100644 --- a/app/frontend/src/javascript/lib/user.ts +++ b/app/frontend/src/javascript/lib/user.ts @@ -1,3 +1,4 @@ +import { isNil, isEmpty } from 'lodash'; import { User } from '../models/user'; import { supportedNetworks, SupportedSocialNetwork } from '../models/social-network'; @@ -24,10 +25,15 @@ export default class UserLib { /** * Filter social networks from the user's profile */ - getUserSocialNetworks = (customer: User): {name: string, url: string}[] => { - const userNetworks = []; + getUserSocialNetworks = (): { name: string, url: string }[] => { + if (!this.isUser()) { + return supportedNetworks.map(network => { + return { name: network, url: '' }; + }); + } - for (const [name, url] of Object.entries(customer.profile_attributes)) { + const userNetworks = []; + for (const [name, url] of Object.entries(this.user.profile_attributes)) { supportedNetworks.includes(name as SupportedSocialNetwork) && userNetworks.push({ name, url }); } return userNetworks; @@ -57,4 +63,13 @@ export default class UserLib { return !(email.match(/^<([^>]+)>.{20}-duplicate$/) === null); } }; + + /** + * Check if the current user is not empty + */ + private isUser = (): boolean => { + if (isNil(this.user)) return false; + + return !(isEmpty(this.user.invoicing_profile_attributes) && isEmpty(this.user.statistic_profile_attributes)); + }; } diff --git a/app/frontend/templates/admin/members/new.html b/app/frontend/templates/admin/members/new.html index 857246d5d..d3763d392 100644 --- a/app/frontend/templates/admin/members/new.html +++ b/app/frontend/templates/admin/members/new.html @@ -29,38 +29,20 @@
-
+
- +
+
-
-
- -
-
-
- - -
-
-
- - - - -
- - - -
- + +
+
diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 0ba505918..26f794002 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -905,6 +905,7 @@ en: members_new: add_a_member: "Add a member" user_is_an_organization: "User is an organization" + create_success: "Member successfully created" #members bulk import members_import: import_members: "Import members"