From 3e77ca54b6025abacdbd1c7e32da42e2032a5d27 Mon Sep 17 00:00:00 2001 From: ipula Date: Fri, 20 Sep 2024 13:42:26 +0200 Subject: [PATCH] invitation table view and api integration --- public/globals.js | 43 ++++ .../InvitationManager/InvitationManager.mdx | 9 + .../InvitationManager.stories.js | 50 +++++ .../InvitationManager/InvitationManager.vue | 107 ++++++++++ .../InvitationManagerStore.js | 146 ++++++++++++++ .../InvitationManager/mocks/invitationMock.js | 97 +++++++++ .../AcceptInvitationPage.stories.js | 16 +- .../acceptInvitation/AcceptInvitationPage.vue | 5 +- .../AcceptInvitationPageStore.js | 84 ++++++-- .../AcceptInvitationReview.vue | 104 +++++++--- .../AcceptInvitationUserAccountDetails.vue | 11 +- .../AcceptInvitationUserDetailsForms.vue | 27 ++- .../AcceptInvitationUserRoles.vue | 34 +++- .../AcceptInvitationVerifyOrcid.vue | 1 + .../mocks/invitationNewUserMock.js | 63 ++++-- .../invitationUserNotVerifiedOrcidMock.js | 69 +++++-- .../mocks/invitationUserVerifiedOrcidMock.js | 69 +++++-- .../acceptInvitation/mocks/pageInitConfig.js | 31 +-- .../pageInitConfigUserNotVerifiedOrcid.js | 8 +- .../UserInvitationDetailsFormStep.vue | 48 ++++- .../UserInvitationEmailComposerStep.vue | 21 +- .../UserInvitationPage.stories.js | 53 +++-- .../userInvitation/UserInvitationPage.vue | 19 +- .../userInvitation/UserInvitationPageStore.js | 107 ++++++++-- .../UserInvitationSearchFormStep.vue | 16 +- .../UserInvitationUserGroupsTable.vue | 187 ++++++++++++------ .../userInvitation/mocks/pageInitConfig.js | 44 +++-- 27 files changed, 1193 insertions(+), 276 deletions(-) create mode 100644 src/managers/InvitationManager/InvitationManager.mdx create mode 100644 src/managers/InvitationManager/InvitationManager.stories.js create mode 100755 src/managers/InvitationManager/InvitationManager.vue create mode 100755 src/managers/InvitationManager/InvitationManagerStore.js create mode 100644 src/managers/InvitationManager/mocks/invitationMock.js diff --git a/public/globals.js b/public/globals.js index 52d3e0337..6c25fd115 100644 --- a/public/globals.js +++ b/public/globals.js @@ -695,6 +695,13 @@ window.pkp = { 'submissions.declined': 'Declined', 'submissions.incomplete': 'Incomplete', todo: '##todo##', + 'about.contact.email': 'Email', + 'user.email': 'Email Address', + 'user.orcid': 'ORCID iD', + 'user.username': 'Username', + 'user.password': 'Password', + 'user.givenName': 'Given Name', + 'user.familyName': 'Family Name', 'user.affiliation': 'Affiliation', 'user.email': 'Email', 'user.emailAddress': '##user.emailAddress##', @@ -720,6 +727,42 @@ window.pkp = { 'userInvitation.usernameField.description': '##userInvitation.usernameField.description##', 'validator.required': 'This field is required.', + 'invitation.notification.closeBtn':'View all users', + 'invitation.orcid.acceptInvitation.message':'Not verified. You can verify your ORCID iD from your profile section in OJS', + 'userInvitation.emailField.description':'e.g. aeinstein@example.com', + 'userInvitation.usernameField.description':'e.g. mickeymouse', + 'userInvitation.orcidField.description':'e.g. 0000-0000-0000-0000', + 'userInvitation.roleTable.role':'Role', + 'userInvitation.roleTable.startDate':'Start Date', + 'userInvitation.roleTable.endDate':'End Date', + 'userInvitation.roleTable.journalMasthead':'Journal Masthead', + 'userInvitation.modal.title':'Invitation Sent', + 'userInvitation.modal.message':'{$email} has been invited to new role in OJS.You can be updated about users on the User and Roles page, your ojs notification and/ or your email', + 'userInvitation.modal.button':'View All Users', + 'acceptInvitation.usernameField.description':'It should be 10 characters long and could be a combination of uppercase letters, lowercase letters or numbers', + 'acceptInvitation.passwordField.description':'It should be 12 characters long and should be a combination of uppercase letters, lowercase letters, numbers and symbols', + 'acceptInvitation.review.userDetails':'User Details', + 'acceptInvitation.review.accountDetails':'Account Details', + 'acceptInvitation.verifyOrcid':'Verify ORCID iD', + 'acceptInvitation.skipVerifyOrcid':'Skip ORCID verification', + 'acceptInvitation.modal.title':"You've been assigned a new role in OJS", + 'acceptInvitation.modal.message':'Congratulations on your new role in OJS! You might now have access to new options. If you need assistance navigating the system, please click on the “Help” buttons throughout the interface for guidance', + 'acceptInvitation.modal.button':'View All Submissions', + 'acceptInvitation.privacyStatement.btn':'Privacy Statement', + 'acceptInvitation.privacyStatement.label':'Yes, I agree to have my data collected and stored according to the', + 'invitation.cancel': 'Cancel Invite', + 'invitation.inviteToRole.btn': 'Invite to a role', + 'invitation.header': 'Invitation', + 'invitation.tableHeader.name': 'Name', + 'invitation.searchForm.emptyError': 'At least provide one search criteria.', + 'invitation.cancelInvite.actionName':'Cancel Invite', + 'invitation.cancelInvite.title':'Cancel Invitation', + 'invitation.cancelInvite.message': 'Cancel the invitation sent to {$givenName} {$familyName} will deactivate acceptance link sent via email. Here are the invitation details: ', + 'invitation.role.modifyRole.button':'Modify Role', + 'invitation.masthead.show':'Appear on the masthead', + 'invitation.masthead.hidden':'Does not appear on the masthead', + 'invitation.roles':'Roles', + 'invitation.removeRoles':'Remove Role', }, tinyMCE: { diff --git a/src/managers/InvitationManager/InvitationManager.mdx b/src/managers/InvitationManager/InvitationManager.mdx new file mode 100644 index 000000000..062fa58bc --- /dev/null +++ b/src/managers/InvitationManager/InvitationManager.mdx @@ -0,0 +1,9 @@ +import {Primary, Controls, Stories, Meta, ArgTypes} from '@storybook/blocks'; + +import * as InvitationManager from './InvitationManager.stories.js'; + + + +# Invitation page + + diff --git a/src/managers/InvitationManager/InvitationManager.stories.js b/src/managers/InvitationManager/InvitationManager.stories.js new file mode 100644 index 000000000..ec7e48265 --- /dev/null +++ b/src/managers/InvitationManager/InvitationManager.stories.js @@ -0,0 +1,50 @@ +import InvitationManager from './InvitationManager.vue'; +import {http, HttpResponse} from 'msw'; +import invitationMock from './mocks/invitationMock.js'; + +export default { + title: 'Managers/InvitationManager', + component: InvitationManager, +}; + +export const Init = { + render: (args) => ({ + components: {InvitationManager}, + setup() { + return {args}; + }, + template: '', + }), + parameters: { + msw: { + handlers: [ + http.get( + 'https://mock/index.php/publicknowledge/api/v1/invitations', + async ({request}) => { + const url = new URL(request.url); + const offset = parseInt(url.searchParams.get('offset') || 0); + const count = parseInt(url.searchParams.get('count')); + const invitations = invitationMock.items.slice( + offset, + offset + count, + ); + + return HttpResponse.json({ + itemsMax: invitationMock.itemsMax, + items: invitations, + }); + }, + ), + http.post( + 'https://mock/index.php/publicknowledge/api/v1/invitations/1/cancel', + async ({request}) => { + return HttpResponse.json({ + request, + }); + }, + ), + ], + }, + }, + args: [], +}; diff --git a/src/managers/InvitationManager/InvitationManager.vue b/src/managers/InvitationManager/InvitationManager.vue new file mode 100755 index 000000000..a80196b13 --- /dev/null +++ b/src/managers/InvitationManager/InvitationManager.vue @@ -0,0 +1,107 @@ + + + diff --git a/src/managers/InvitationManager/InvitationManagerStore.js b/src/managers/InvitationManager/InvitationManagerStore.js new file mode 100755 index 000000000..5230a2fb5 --- /dev/null +++ b/src/managers/InvitationManager/InvitationManagerStore.js @@ -0,0 +1,146 @@ +import {defineComponentStore} from '@/utils/defineComponentStore'; +import {useApiUrl} from '@/composables/useApiUrl'; +import {useAnnouncer} from '@/composables/useAnnouncer'; +import {useUrl} from '@/composables/useUrl'; +import {useLocalize} from '@/composables/useLocalize'; +import {useTranslation} from '@/composables/useTranslation'; +import {useFetchPaginated} from '@/composables/useFetchPaginated'; +import {useFetch} from '@/composables/useFetch'; +import {useModal} from '@/composables/useModal'; +import {computed, ref, watch} from 'vue'; + +export const useInvitationManagerStore = defineComponentStore( + 'invitationsPage', + () => { + const {openDialog} = useModal(); + const {localize} = useLocalize(); + const {t} = useTranslation(); + /** Announcer */ + + const {announce} = useAnnouncer(); + /** + * redirect to send invitation page + */ + const {pageUrl} = useUrl('invitation/invite'); + const sendInvitationPageUrl = computed(() => { + return pageUrl.value; + }); + function sendInvitation() { + window.location = sendInvitationPageUrl.value; + } + + /** + * get invitations with paginations + */ + const invitationCount = ref(0); + + const countPerPage = ref(2); + const currentPage = ref(1); + function setCurrentPage(_currentPage) { + currentPage.value = _currentPage; + } + + const {apiUrl} = useApiUrl('invitations'); + const getInvitationApiUrl = computed(() => { + return apiUrl.value; + }); + const { + items: invitations, + pagination: invitationsPagination, + isLoading: isInvitationLoading, + fetch: fetchInvitation, + } = useFetchPaginated(getInvitationApiUrl, { + currentPage, + pageSize: countPerPage, + }); + watch( + [currentPage], + async () => { + announce(t('common.loading')); + + await fetchInvitation(); + announce(t('common.loaded')); + }, + {immediate: true}, + ); + + /** + * create user full name + * @param String givenName + * @param String familyName + * @returns String + */ + function getFullName(givenName, familyName) { + return localize(givenName) + ' ' + localize(familyName); + } + + /** + * get all invited user groups + * @param {Array} userGroups + * @returns + */ + function getAllInvitedRoles(userGroups) { + let roles = ''; + userGroups.forEach((element) => { + roles = roles + localize(element.userGroupName) + ', '; + }); + + return roles; + } + + function handleReviewAction(data) { + openDialog({ + title: t('invitation.cancelInvite.title'), + message: t('invitation.cancelInvite.message', { + givenName: data.givenName, + familyName: data.familyName, + email: data.email, + roles: getAllInvitedRoles(data.userGroupsToAdd), + status: + 'invited ' + new Date(data.createdAt).toLocaleDateString('en-US'), + affiliation: data.affiliation ? data.affiliation : '', + }), + actions: [ + { + label: t('invitation.cancelInvite.title'), + isPrimary: true, + callback: async (close) => { + const {apiUrl: cancelApiUrl} = useUrl( + `invitations/${data.id}/cancel`, + ); + const {fetch: cancelInvitation} = useFetch(cancelApiUrl.value, { + method: 'PUT', + body: {}, + }); + + announce(t('common.loading')); + await cancelInvitation(); + await fetchInvitation(); + announce(t('common.loaded')); + close(); + }, + }, + { + label: t('common.cancel'), + isWarnable: true, + callback: (close) => {}, + }, + ], + }); + } + + return { + invitationCount, + setCurrentPage, + sendInvitation, + currentPage, + invitationsPagination, + pageUrl, + + invitations, + isInvitationLoading, + getFullName, + handleReviewAction, + }; + }, +); diff --git a/src/managers/InvitationManager/mocks/invitationMock.js b/src/managers/InvitationManager/mocks/invitationMock.js new file mode 100644 index 000000000..4355155b5 --- /dev/null +++ b/src/managers/InvitationManager/mocks/invitationMock.js @@ -0,0 +1,97 @@ +export default { + itemsMax: 2, + items: [ + { + id: 1, + status: 'PENDING', + createdAt: '2024-09-10T20:31:10.000000Z', + updatedAt: '2024-09-10T20:31:15.000000Z', + userId: null, + contextId: 1, + expiryDate: '2024-09-13T20:31:13.000000Z', + email: 'test@mailinator.com', + inviterId: 1, + orcid: null, + givenName: 'Test', + familyName: 'Test', + affiliation: null, + country: null, + emailSubject: null, + emailBody: null, + userGroupsToAdd: [ + { + userGroupId: 2, + userGroupName: { + en: 'Journal manager', + fr_CA: 'Directeur-trice de la revue', + }, + masthead: true, + dateStart: '2024-09-10', + dateEnd: null, + }, + ], + userGroupsToRemove: [], + username: null, + sendEmailAddress: 'journalmanager@mailinator.com', + existingUser: null, + }, + { + id: 2, + status: 'PENDING', + createdAt: '2024-09-10T20:24:53.000000Z', + updatedAt: '2024-09-10T20:25:04.000000Z', + userId: 35, + contextId: 1, + expiryDate: '2024-09-13T20:25:02.000000Z', + email: null, + inviterId: 1, + orcid: null, + givenName: null, + familyName: null, + affiliation: null, + country: null, + emailSubject: null, + emailBody: null, + userGroupsToAdd: [ + { + userGroupId: 16, + userGroupName: { + en: 'Reviewer', + fr_CA: '\u00c9valuateur-trice', + }, + masthead: true, + dateStart: '2024-09-10', + dateEnd: null, + }, + ], + userGroupsToRemove: [ + { + userGroupId: 9, + userGroupName: { + en: 'Funding coordinator', + fr_CA: 'Coordonnateur-trice du financement', + }, + masthead: null, + dateStart: null, + dateEnd: null, + }, + ], + username: null, + sendEmailAddress: 'zwoods@mailinator.com', + existingUser: { + email: 'zwoods@mailinator.com', + fullName: 'Zita Woods', + familyName: { + en: 'Woods', + }, + givenName: { + en: 'Zita', + }, + country: 'US', + affiliation: { + en: 'CUNY', + }, + }, + }, + ], +}; diff --git a/src/pages/acceptInvitation/AcceptInvitationPage.stories.js b/src/pages/acceptInvitation/AcceptInvitationPage.stories.js index b76cb54bb..6bc5101b1 100644 --- a/src/pages/acceptInvitation/AcceptInvitationPage.stories.js +++ b/src/pages/acceptInvitation/AcceptInvitationPage.stories.js @@ -35,31 +35,31 @@ export const NewUser = { const postBody = await request.json(); let errors = {}; - if (!Object.keys(postBody).includes('username')) { + if (!Object.keys(postBody.invitationData).includes('username')) { errors['username'] = ['This field is required']; } - if (!Object.keys(postBody).includes('password')) { + if (!Object.keys(postBody.invitationData).includes('password')) { errors['password'] = ['This field is required']; } - if (!Object.keys(postBody).includes('affiliation')) { + if (!Object.keys(postBody.invitationData).includes('affiliation')) { errors['affiliation'] = ['This field is required']; } - if (!Object.keys(postBody).includes('familyName')) { + if (!Object.keys(postBody.invitationData).includes('familyName')) { errors['familyName'] = ['This field is required']; } - if (!Object.keys(postBody).includes('country')) { + if (!Object.keys(postBody.invitationData).includes('userCountry')) { errors['country'] = ['This field is required']; } - Object.keys(postBody).forEach((element) => { + Object.keys(postBody.invitationData).forEach((element) => { if (element !== 'orcid') { - if (postBody[element] === '') { + if (postBody.invitationData[element] === '') { errors[element] = ['This field is required']; } } }); if (Object.keys(errors).length > 0) { - return HttpResponse.json(errors, {status: 422}); + return HttpResponse.json({errors: errors}, {status: 422}); } return HttpResponse.json(postBody, {status: 200}); }, diff --git a/src/pages/acceptInvitation/AcceptInvitationPage.vue b/src/pages/acceptInvitation/AcceptInvitationPage.vue index af7d15907..1015fa3d2 100644 --- a/src/pages/acceptInvitation/AcceptInvitationPage.vue +++ b/src/pages/acceptInvitation/AcceptInvitationPage.vue @@ -1,7 +1,7 @@