-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7608 from stopfstedt/schooladmin_emails
adds UI for managing emails in the school configuration screen.
- Loading branch information
Showing
19 changed files
with
556 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{{#let (unique-id) as |templateId|}} | ||
<section | ||
class="school-emails-editor" | ||
data-test-school-emails-editor | ||
...attributes | ||
{{did-insert this.load}} | ||
{{did-update this.load}} | ||
> | ||
<div class="header"> | ||
<div class="title">{{t "general.emails"}}</div> | ||
<div class="actions"> | ||
<button type="button" class="bigadd" {{on "click" (perform this.save)}} data-test-save> | ||
<FaIcon | ||
@icon={{if this.save.isRunning "spinner" "check"}} | ||
@spin={{this.save.isRunning}} | ||
/> | ||
</button> | ||
<button type="button" class="bigcancel" {{on "click" @cancel}} data-test-cancel> | ||
<FaIcon @icon="arrow-rotate-left" /> | ||
</button> | ||
</div> | ||
</div> | ||
<div class="content"> | ||
<div class="form"> | ||
<div class="item" data-test-administrator-email> | ||
<label for="administrator-email-{{templateId}}"> | ||
{{t "general.administratorEmail"}} | ||
</label> | ||
<input | ||
id="administrator-email-{{templateId}}" | ||
type="text" | ||
value={{this.administratorEmail}} | ||
placeholder={{this.administratorEmailPlaceholder}} | ||
{{on "input" (pick "target.value" (set this.administratorEmail))}} | ||
{{on "keyup" | ||
(queue | ||
(fn this.addErrorDisplayFor "administratorEmail") | ||
(perform this.saveOrCancel) | ||
) | ||
}} | ||
> | ||
<ValidationError @errors={{get-errors-for this.administratorEmail}} /> | ||
</div> | ||
<div class="item" data-test-change-alert-recipients> | ||
<label for="change-alert-recipients-{{templateId}}"> | ||
{{t "general.changeAlertRecipients"}} | ||
</label> | ||
<input | ||
id="change-alert-recipients-{{templateId}}" | ||
type="text" | ||
value={{this.changeAlertRecipients}} | ||
placeholder={{this.changeAlertRecipientsPlaceholder}} | ||
{{on "input" (pick "target.value" (set this.changeAlertRecipients))}} | ||
{{on "keyup" | ||
(queue | ||
(fn this.addErrorDisplayFor "changeAlertRecipients") | ||
(perform this.saveOrCancel) | ||
) | ||
}} | ||
> | ||
<ValidationError @errors={{get-errors-for this.changeAlertRecipients}} /> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
{{/let}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { dropTask } from 'ember-concurrency'; | ||
import { validatable, Custom, IsEmail, Length } from 'ilios-common/decorators/validation'; | ||
import { action } from '@ember/object'; | ||
import { service } from '@ember/service'; | ||
import { isBlank, typeOf } from '@ember/utils'; | ||
import EmailValidator from 'validator/es/lib/isEmail'; | ||
|
||
@validatable | ||
export default class SchoolEmailsEditorComponent extends Component { | ||
@service intl; | ||
|
||
@tracked @Length(0, 100) @IsEmail() administratorEmail; | ||
@tracked | ||
@Length(0, 300) | ||
@Custom('validateChangeAlertRecipientsCallBack', 'validateChangeAlertRecipientsMessageCallBack') | ||
changeAlertRecipients; | ||
|
||
get changeAlertRecipientsFormatted() { | ||
return this.changeAlertRecipients | ||
.trim() | ||
.split(',') | ||
.map((email) => email.trim()) | ||
.filter((email) => !isBlank(email)) | ||
.join(', '); | ||
} | ||
|
||
@action | ||
load() { | ||
this.administratorEmail = this.args.school.iliosAdministratorEmail; | ||
this.changeAlertRecipients = this.args.school.changeAlertRecipients; | ||
} | ||
|
||
@action | ||
validateChangeAlertRecipientsCallBack() { | ||
if ('string' !== typeOf(this.changeAlertRecipients)) { | ||
return true; | ||
} | ||
const emails = this.changeAlertRecipients | ||
.trim() | ||
.split(',') | ||
.map((email) => email.trim()) | ||
.filter((email) => !isBlank(email)); | ||
return emails.reduce((valid, email) => EmailValidator(email) && valid, true); | ||
} | ||
|
||
@action | ||
validateChangeAlertRecipientsMessageCallBack() { | ||
return this.intl.t('errors.invalidChangeAlertRecipients'); | ||
} | ||
|
||
@dropTask | ||
*save() { | ||
this.addErrorDisplaysFor(['administratorEmail', 'changeAlertRecipients']); | ||
const isValid = yield this.isValid(); | ||
if (!isValid) { | ||
return false; | ||
} | ||
|
||
yield this.args.save(this.administratorEmail, this.changeAlertRecipientsFormatted); | ||
this.clearErrorDisplay(); | ||
this.args.cancel(); | ||
} | ||
|
||
@dropTask | ||
*saveOrCancel(event) { | ||
const keyCode = event.keyCode; | ||
if (13 === keyCode) { | ||
yield this.save.perform(); | ||
} else if (27 === keyCode) { | ||
this.args.cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<section | ||
class="school-emails" | ||
data-test-school-emails | ||
...attributes | ||
> | ||
<div class="header"> | ||
<div class="title" data-test-title>{{t "general.emails"}}</div> | ||
<div class="actions"> | ||
{{#if @canUpdate}} | ||
<button | ||
type="button" | ||
{{on "click" (fn @manage true)}} | ||
data-test-manage | ||
> | ||
{{t "general.manageEmails"}} | ||
</button> | ||
{{/if}} | ||
</div> | ||
</div> | ||
<div class="content"> | ||
<div data-test-administrator-email> | ||
<strong>{{t "general.administratorEmail"}}:</strong> | ||
<span>{{@school.iliosAdministratorEmail}}</span> | ||
</div> | ||
<div data-test-change-alert-recipients> | ||
<strong>{{t "general.changeAlertRecipients"}}:</strong> | ||
<span>{{@school.changeAlertRecipients}}</span> | ||
</div> | ||
</div> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/frontend/app/styles/components/school/emails-editor.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@use "../../ilios-common/colors" as c; | ||
@use "../../ilios-common/mixins" as m; | ||
|
||
.school-emails-editor { | ||
@include m.detail-container(c.$orange); | ||
|
||
.header { | ||
@include m.detail-container-header; | ||
|
||
.title { | ||
@include m.detail-container-title; | ||
} | ||
|
||
.actions { | ||
@include m.detail-container-actions; | ||
} | ||
} | ||
|
||
.content { | ||
@include m.detail-container-content; | ||
|
||
.form { | ||
@include m.ilios-form; | ||
grid-template-columns: 1fr; | ||
margin-top: 1em; | ||
|
||
@include m.for-laptop-and-up { | ||
grid-template-columns: 1fr 1fr; | ||
} | ||
} | ||
|
||
.validation-error-message { | ||
color: c.$crimson; | ||
display: block; | ||
@include m.font-size("small"); | ||
font-style: italic; | ||
margin-top: 0.25rem; | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/frontend/app/styles/components/school/emails.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@use "../../ilios-common/colors" as c; | ||
@use "../../ilios-common/mixins" as m; | ||
|
||
.school-emails { | ||
@include m.detail-container(c.$orange); | ||
|
||
.header { | ||
@include m.detail-container-header; | ||
|
||
.title { | ||
@include m.detail-container-title; | ||
} | ||
|
||
.actions { | ||
@include m.detail-container-actions; | ||
} | ||
} | ||
|
||
.content { | ||
@include m.collapsed-container-content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.