diff --git a/public/globals.js b/public/globals.js index 52d3e0337..65c36bcf9 100644 --- a/public/globals.js +++ b/public/globals.js @@ -119,23 +119,6 @@ window.pkp = { * Locale keys loaded on the server-side */ localeKeys: { - 'acceptInvitation.modal.button': '##acceptInvitation.modal.button##', - 'acceptInvitation.modal.message': '##acceptInvitation.modal.message##', - 'acceptInvitation.modal.title': '##acceptInvitation.modal.title##', - 'acceptInvitation.passwordField.description': - '##acceptInvitation.passwordField.description##', - 'acceptInvitation.privacyStatement.btn': - '##acceptInvitation.privacyStatement.btn##', - 'acceptInvitation.privacyStatement.label': - '##acceptInvitation.privacyStatement.label##', - 'acceptInvitation.review.accountDetails': - '##acceptInvitation.review.accountDetails##', - 'acceptInvitation.review.userDetails': - '##acceptInvitation.review.userDetails##', - 'acceptInvitation.skipVerifyOrcid': '##acceptInvitation.skipVerifyOrcid##', - 'acceptInvitation.usernameField.description': - '##acceptInvitation.usernameField.description##', - 'acceptInvitation.verifyOrcid': '##acceptInvitation.verifyOrcid##', 'admin.jobs.failed.action.redispatch': 'Try Again', 'admin.jobs.failed.action.redispatch.all': 'Requeue All Failed Jobs', 'article.article': 'Article', @@ -441,14 +424,12 @@ window.pkp = { 'Log in as this user? All actions you perform will be attributed to this user.', 'help.help': 'Help', 'informationCenter.informationCenter': 'Information Center', - 'invitation.orcid.acceptInvitation.message': - '##invitation.orcid.acceptInvitation.message##', - 'invitation.role.addRole.button': '##invitation.role.addRole.button##', - 'invitation.role.dateStart': '##invitation.role.dateStart##', - 'invitation.role.masthead': '##invitation.role.masthead##', + 'invitation.role.addRole.button': 'Add Another Role', + 'invitation.role.dateStart': 'Start Date', + 'invitation.role.masthead': 'Journal Masthead', 'invitation.role.removeRole.button': - '##invitation.role.removeRole.button##', - 'invitation.role.selectRole': '##invitation.role.selectRole##', + 'Remove Role', + 'invitation.role.selectRole': 'Select a new role', 'invitation.wizard.completeSteps': '##invitation.wizard.completeSteps##', 'invitation.wizard.errors': '##invitation.wizard.errors##', 'issue.issue': 'Issue', @@ -695,31 +676,52 @@ window.pkp = { 'submissions.declined': 'Declined', 'submissions.incomplete': 'Incomplete', todo: '##todo##', + 'about.contact.email': 'Email', + 'user.email': 'Email Address', 'user.affiliation': 'Affiliation', - 'user.email': 'Email', - 'user.emailAddress': '##user.emailAddress##', 'user.familyName': 'Family Name', 'user.givenName': 'Given Name', 'user.gossip': 'Editorial Notes', 'user.orcid': 'ORCID iD', 'user.password': 'Password', 'user.username': 'Username', - 'userInvitation.emailField.description': - '##userInvitation.emailField.description##', - 'userInvitation.modal.button': '##userInvitation.modal.button##', - 'userInvitation.modal.message': '##userInvitation.modal.message##', - 'userInvitation.modal.title': '##userInvitation.modal.title##', - 'userInvitation.orcidField.description': - '##userInvitation.orcidField.description##', - 'userInvitation.roleTable.endDate': '##userInvitation.roleTable.endDate##', - 'userInvitation.roleTable.journalMasthead': - '##userInvitation.roleTable.journalMasthead##', - 'userInvitation.roleTable.role': '##userInvitation.roleTable.role##', - 'userInvitation.roleTable.startDate': - '##userInvitation.roleTable.startDate##', - '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 @@