Skip to content

Commit

Permalink
Merge branch 'test'
Browse files Browse the repository at this point in the history
  • Loading branch information
neophyte57 committed Dec 17, 2024
2 parents a6901af + 963cb46 commit c840636
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { BusinessLicenceDocument } from '@registration/shared/models/business-li
import { BusinessLicenceForm } from './business-licence-form.model';
import { FormUtilsService } from '@core/services/form-utils.service';
import { CareSettingEnum } from '@shared/enums/care-setting.enum';
import { SiteService } from '@registration/shared/services/site.service';
import { Site } from '@registration/shared/models/site.model';

export class BusinessLicenceFormState extends AbstractFormState<BusinessLicenceForm> {
private siteId: number;
Expand All @@ -21,12 +23,17 @@ export class BusinessLicenceFormState extends AbstractFormState<BusinessLicenceF
private fb: FormBuilder,
private siteResource: SiteResource,
private formUtilsService: FormUtilsService,
private siteService: SiteService,
) {
super();
this.businessLicenceUpdated = false;
this.buildForm();
}

public get filename(): FormControl {
return this.formInstance.get('filename') as FormControl;
}

public get businessLicenceGuid(): FormControl {
return this.formInstance.get('businessLicenceGuid') as FormControl;
}
Expand Down Expand Up @@ -121,6 +128,7 @@ export class BusinessLicenceFormState extends AbstractFormState<BusinessLicenceF

public buildForm(): void {
this.formInstance = this.fb.group({
filename: [null, []],
businessLicenceGuid: [
// Will never be patched when the form is built, and is
// only updated based on a document upload occurring.
Expand Down Expand Up @@ -195,7 +203,7 @@ export class BusinessLicenceFormState extends AbstractFormState<BusinessLicenceF
const careSettingCode = form.get("careSettingCode");

if ((careSettingCode.value === CareSettingEnum.COMMUNITY_PHARMACIST || careSettingCode.value === CareSettingEnum.DEVICE_PROVIDER) &&
!(isNewWOSiteId.value || isNewWSiteId.value || activeBeforeRegistration.value)) {
!(isNewWOSiteId.value || isNewWSiteId.value || activeBeforeRegistration.value) && this.siteService.site?.approvedDate === null) {
return { 'checkboxRequired': true };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class BusinessLicenceRenewalPageFormState extends AbstractFormState<Busin
this.buildForm();
}

public get filename(): FormControl {
return this.formInstance.get('filename') as FormControl;
}

public get businessLicenceGuid(): FormControl {
return this.formInstance.get('businessLicenceGuid') as FormControl;
}
Expand Down Expand Up @@ -55,6 +59,7 @@ export class BusinessLicenceRenewalPageFormState extends AbstractFormState<Busin

public buildForm(): void {
this.formInstance = this.fb.group({
filename: [null, []],
businessLicenceGuid: [
// Will never be patched when the form is built, and is
// only updated based on a document upload occurring.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class BusinessLicenceRenewalPageComponent extends AbstractCommunitySiteRe
this.formState.businessLicenceGuid.patchValue(document.documentGuid);
this.uploadedFile = true;
this.hasNoBusinessLicenceError = false;
this.formState.filename.patchValue(document.filename);
}

public onRemoveDocument(_: string): void {
Expand Down Expand Up @@ -123,9 +124,10 @@ export class BusinessLicenceRenewalPageComponent extends AbstractCommunitySiteRe
protected performSubmission(): Observable<void> {
// Transfer business licence renewal updates
// to the form state service for submission
const { businessLicenceGuid, businessLicenceExpiry } = this.siteFormStateService.businessLicenceFormState;
const { businessLicenceGuid, businessLicenceExpiry, filename } = this.siteFormStateService.businessLicenceFormState;
businessLicenceGuid.patchValue(this.formState.businessLicenceGuid.value);
businessLicenceExpiry.patchValue(this.formState.businessLicenceExpiry.value);
filename.patchValue(this.formState.filename.value);

this.siteFormStateService.businessLicenceFormState.flagBusinessLicenceUpdated();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
[organization]="organization"
[site]="site"
[siteErrors]="siteErrors"
[businessLicenceUpdated]="isBusinessLicenceUpdated"></app-overview-container>
[businessLicenceUpdated]="isBusinessLicenceUpdated"
[filename]="uploadedFilename"></app-overview-container>

<ng-container *ngIf="showSubmissionAction; else showBack">
<div class="footer mb-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class OverviewPageComponent implements OnInit {
public routeUtils: RouteUtils;
public siteErrors: ValidationErrors;
public isBusinessLicenceUpdated: boolean;
public uploadedFilename: string;
public isCompleted: boolean;

public SiteRoutes = SiteRoutes;
Expand Down Expand Up @@ -206,6 +207,8 @@ export class OverviewPageComponent implements OnInit {
this.isBusinessLicenceUpdated = this.siteFormStateService.businessLicenceFormState.isBusinessLicenceUpdated
|| (this.siteFormStateService.businessLicenceFormState.businessLicenceGuid.value && !this.site.businessLicence?.businessLicenceDocument);

this.uploadedFilename = this.siteFormStateService.businessLicenceFormState.filename.value;

this.siteErrors = this.getSiteErrors(site);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ export class BusinessLicenceExpiryComponent implements OnInit {
public onChange(event: MatSlideToggleChange): void {
this.showExpiryDate = !event.checked
let expiryDateControl = this.form.get('expiryDate');

if (event.checked) {
expiryDateControl.reset();
expiryDateControl.clearValidators();
expiryDateControl.updateValueAndValidity();
} else {
expiryDateControl.setValidators([Validators.required]);
expiryDateControl.updateValueAndValidity();
}
this.form.markAsUntouched();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CareSettingPageFormState } from '@registration/pages/care-setting-page/
import { BusinessLicenceFormState } from '@registration/pages/business-licence-page/business-licence-form-state.class';
import { BusinessLicenceRenewalPageFormState } from '@registration/pages/business-licence-renewal-page/business-licence-renewal-form-state.class';
import { DeviceProviderPageFormState } from '@registration/pages/device-provider-page/device-provider-page-form-state.class';
import { SiteService } from './site.service';

@Injectable({
providedIn: 'root'
Expand All @@ -32,6 +33,7 @@ export class SiteFormStateService extends AbstractFormStateService<Site> {
public privacyOfficerFormState: PrivacyOfficerPageFormState;
public technicalSupportFormState: TechnicalSupportPageFormState;
public deviceProviderFormState: DeviceProviderPageFormState;
public businessLicenceRenewalPageFormState: BusinessLicenceRenewalPageFormState;

private siteId: number;
private organizationId: number;
Expand All @@ -49,7 +51,8 @@ export class SiteFormStateService extends AbstractFormStateService<Site> {
protected routeStateService: RouteStateService,
protected logger: ConsoleLoggerService,
private formUtilsService: FormUtilsService,
private siteResource: SiteResource
private siteResource: SiteResource,
private siteService: SiteService,
) {
super(fb, routeStateService, logger);

Expand Down Expand Up @@ -231,7 +234,7 @@ export class SiteFormStateService extends AbstractFormStateService<Site> {
*/
protected buildForms(): void {
this.careSettingPageFormState = new CareSettingPageFormState(this.fb);
this.businessLicenceFormState = new BusinessLicenceFormState(this.fb, this.siteResource, this.formUtilsService);
this.businessLicenceFormState = new BusinessLicenceFormState(this.fb, this.siteResource, this.formUtilsService, this.siteService);
this.hoursOperationPageFormState = new HoursOperationPageFormState(this.fb);
this.remoteUsersPageFormState = new RemoteUsersPageFormState(this.fb);
this.administratorPharmaNetFormState = new AdministratorPageFormState(this.fb, this.formUtilsService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@

<ng-container *ngIf="!admin; else businessLicenceListView">
<ng-container *ngIf="site.businessLicence?.businessLicenceDocument; else deferredLicence">

<app-enrollee-property title="Expiry"
[hasError]="!site.businessLicence?.expiryDate && withinRenewalPeriod"
[errorMessage]="'Business licence expiry date is required'">
[hasError]="site.businessLicence?.expiryDate && withinRenewalPeriod"
[errorMessage]="'Please update business licence'">
{{ site.businessLicence?.expiryDate | formatDate | default }}
</app-enrollee-property>

<app-enrollee-property title="Filename">
<app-enrollee-property title="Filename"
[hasError]="!site.businessLicence?.expiryDate && withinRenewalPeriod && !businessLicenceUpdated"
[errorMessage]="'Please update business licence'">
<ng-container *ngIf="!businessLicenceUpdated; else businessLicenceUpdatedMessage">
<button mat-stroked-button
color="primary"
Expand All @@ -115,7 +116,7 @@
</button>
</ng-container>
<ng-template #businessLicenceUpdatedMessage>
New business licence document has been uploaded for submission
(New) {{filename}}
</ng-template>
</app-enrollee-property>
<app-enrollee-property *ngIf="site.businessLicence.deferredLicenceReason"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class OverviewContainerComponent implements OnInit {
@Input() public admin: boolean;
@Input() public siteErrors: ValidationErrors;
@Input() public businessLicenceUpdated: boolean;
@Input() public filename: string;

public withinRenewalPeriod: boolean;
public routeUtils: RouteUtils;
Expand Down

0 comments on commit c840636

Please sign in to comment.