Skip to content

Commit

Permalink
Add user messaging modal to user's tab on institutional dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Dec 4, 2024
1 parent 951bcb2 commit e91a7f1
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/adapters/user-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// app/adapters/user-message.js
import { inject as service } from '@ember/service';
import config from 'ember-osf-web/config/environment';
const { OSF: { apiUrl } } = config;
import OsfAdapter from './osf-adapter';

export default class UserMessageAdapter extends OsfAdapter {
@service session;
urlForCreateRecord(modelName, snapshot) {
const userId = snapshot.record.user;
return `${apiUrl}/v2/users/${userId}/messages/`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ interface InstitutionalUsersListArgs {
export default class InstitutionalUsersList extends Component<InstitutionalUsersListArgs> {
@service analytics!: Analytics;
@service intl!: Intl;
@service store;
@service currentUser!: CurrentUser;

institution?: InstitutionModel;

Expand All @@ -36,6 +38,10 @@ export default class InstitutionalUsersList extends Component<InstitutionalUsers
@tracked sort = 'user_name';
@tracked selectedDepartments: string[] = [];
@tracked filteredUsers = [];
@tracked messageModalShown = false;
@tracked messageText = '';
@tracked selectedUserId = null;
@service toast!: Toast;

@tracked columns: Column[] = [
{
Expand Down Expand Up @@ -238,4 +244,37 @@ export default class InstitutionalUsersList extends Component<InstitutionalUsers
this.hasOrcid = !hasOrcid;
}

@action
openMessageModal(userId: string) {
this.selectedUserId = userId;
this.messageModalShown = true;
}

@action
updateMessageText(event: Event) {
this.messageText = (event.target as HTMLTextAreaElement).value;
}

@action
async sendMessage() {
if (!this.selectedUserId || !this.messageText.trim()) {
return;
}

try {
const userMessage = this.store.createRecord('user-message', {
messageText: this.messageText.trim(),
messageType: 'institutional_request',
institution: this.args.institution,
user: this.selectedUserId,
});
await userMessage.save();
this.toast.success(this.intl.t('institutions.dashboard.send_message_modal.message_sent_success'));
} catch (error) {
this.toast.error(this.intl.t('institutions.dashboard.send_message_modal.message_sent_failed'));
} finally {
this.messageModalShown = false;
this.messageText = '';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,22 @@ input:checked + .slider::before {
justify-content: flex-end;
margin-right: 15px;
}


.icon-message {
opacity: 0;
color: $color-text-blue-dark;
}

.icon-message:hover {
opacity: 1;
color: $color-text-blue-dark;
border: 0 !important;
outline: 0 !important;
background: none !important;
}

.message-textarea {
min-width: 450px;
min-height: 280px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@
<OsfLink @href={{concat '/' institutionalUser.userGuid '/'}}>
{{institutionalUser.userName}}
</OsfLink>
<Button
local-class='icon-message'
{{on 'click' (fn this.openMessageModal institutionalUser.userGuid)}}
>
<FaIcon @icon='comment' />
</Button>
{{else if (eq column.type 'osf_link')}}
<OsfLink @href={{concat '/' institutionalUser.userGuid '/'}}>
{{institutionalUser.userGuid}}
Expand Down Expand Up @@ -185,4 +191,44 @@
{{t 'institutions.dashboard.users_list.empty'}}
</list.empty>
</PaginatedList::HasMany>
<OsfDialog
@isOpen={{this.messageModalShown}}
@onClose={{fn (mut this.messageModalShown) false}}
as |dialog|
>
<dialog.heading>
{{t 'institutions.dashboard.send_message_modal.title'}}
</dialog.heading>
<dialog.main>
<div >
<div for='message-text'>
{{t 'institutions.dashboard.send_message_modal.opening_message_label'}}
</div>
<textarea
id='message-text'
local-class='message-textarea'
value={{this.messageText}}
{{on 'input' this.updateMessageText}}
></textarea>
<div>
{{t 'institutions.dashboard.send_message_modal.closing_message_label' adminName=this.currentUser.user.fullName}}
</div>
</div>
</dialog.main>
<dialog.footer>
<Button
@type='secondary'
{{on 'click' (fn (mut this.messageModalShown) false)}}
>
{{t 'general.cancel'}}
</Button>
<Button
@type='primary'
@disabled={{not this.messageText}}
{{on 'click' (queue this.sendMessage dialog.close)}}
>
{{t 'institutions.dashboard.send_message_modal.send'}}
</Button>
</dialog.footer>
</OsfDialog>
{{/if}}
8 changes: 8 additions & 0 deletions app/models/user-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// app/models/user-message.js
import Model, { attr, belongsTo } from '@ember-data/model';

export default class UserMessageModel extends Model {
@attr('string') messageText;
@attr('string') messageType;
@belongsTo('institution') institution;
}
7 changes: 7 additions & 0 deletions translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,13 @@ institutions:
search_placeholder: 'Search institutions'
load_more: 'Load more institutions'
dashboard:
send_message_modal:
title: 'Send Email'
opening_message_label: 'Comments:'
closing_message_label: 'Sincerely Yours, {adminName}'
message_sent_success: 'Message has been sent'
message_sent_failed: 'Message has failed to send of the issue persists contact your administrator'
send: 'Send'
tabs:
summary: Summary
users: Users
Expand Down

0 comments on commit e91a7f1

Please sign in to comment.