Skip to content

Commit

Permalink
Merge pull request #4 from UMNLibraries/work-delivery-addr
Browse files Browse the repository at this point in the history
Add optional address for work delivery
  • Loading branch information
gpeterso authored Jan 5, 2024
2 parents 8cfd081 + 8978abd commit 75da4bb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,19 @@ describe("prmRequestAfterComponent", () => {
};
ctrl.$onInit();
ctrl.customFormChangeHandler(newFormData, null);
expect(commentField.mandatory).toBeTrue;
expect(commentField.label).toEqual(ctrl.customCommentLabel);
expect(commentField.mandatory).toEqual(true);
expect(commentField.label).toEqual(ctrl.homeAddressCommentLabel);
});

it("makes the comment field optional when work delivery is selected", () => {
const newFormData: FormData = {
requestType: "hold",
pickupLocation: "123456789$$USER_WORK_ADDRESS",
};
ctrl.$onInit();
ctrl.customFormChangeHandler(newFormData, null);
expect(commentField.mandatory).toEqual(false);
expect(commentField.label).toEqual(ctrl.workAddressCommentLabel);
});

it("hides the comment field by default", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ export interface FormData {
/**
* Replaces the parent controller's `onFormInputChange` method with a custom
* implementation that requires users to provide an address in the comments
* field when "home delivery" is selected as a pickup location in hold requests
* field when home or office is selected as a pickup location in hold requests
*/
export class PrmRequestAfterController implements ng.IController {
private parentCtrl: ng.IController;
private originalFormChangeHandler: Function;
readonly defaultCommentLabel: string = "almaRequest.comment";
readonly customCommentLabel: string = "umn.almaRequest.homeDeliveryAddress";
readonly homeAddressCommentLabel: string =
"umn.almaRequest.homeDeliveryAddress";
readonly workAddressCommentLabel: string =
"umn.almaRequest.workDeliveryAddress";

$onInit() {
this.originalFormChangeHandler = this.parentCtrl.onFormInputChange.bind(
Expand All @@ -33,10 +36,14 @@ export class PrmRequestAfterController implements ng.IController {
const comment = this.findCommentField();
comment.uiType = "hidden";
if (this.isHomeDeliverySelected(newData)) {
comment.label = this.customCommentLabel;
comment.label = this.homeAddressCommentLabel;
comment.mandatory = true;
comment.uiType = "text";
} else if (comment?.label === this.customCommentLabel) {
} else if (this.isWorkDeliverySelected(newData)) {
comment.label = this.workAddressCommentLabel;
comment.mandatory = false; // office address should be optional
comment.uiType = "text";
} else if (comment?.label !== this.defaultCommentLabel) {
comment.label = this.defaultCommentLabel;
comment.mandatory = false;
}
Expand All @@ -52,6 +59,10 @@ export class PrmRequestAfterController implements ng.IController {
return formData?.pickupLocation?.endsWith("USER_HOME_ADDRESS");
}

private isWorkDeliverySelected(formData: FormData): boolean {
return formData?.pickupLocation?.endsWith("USER_WORK_ADDRESS");
}

private findCommentField(): FormField | undefined {
const formFields = this.parentCtrl.form as FormField[];
return formFields.find((field) => field.key === "comment");
Expand Down

0 comments on commit 75da4bb

Please sign in to comment.