-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wip] feat: implement ui for editing organizations
- Loading branch information
Showing
14 changed files
with
554 additions
and
11 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
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
33 changes: 33 additions & 0 deletions
33
...src/app/pages/authority-organization-edit-page/authority-organization-edit-page.module.ts
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,33 @@ | ||
/* | ||
* Copyright (c) 2024 sovity GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* sovity GmbH - initial implementation | ||
*/ | ||
import {CommonModule} from '@angular/common'; | ||
import {NgModule} from '@angular/core'; | ||
import {RouterModule} from '@angular/router'; | ||
import {NgxsModule} from '@ngxs/store'; | ||
import {SharedModule} from 'src/app/shared/shared.module'; | ||
import {AuthorityOrganizationEditPageComponent} from './authority-organization-edit-page/authority-organization-edit-page.component'; | ||
import {AuthorityOrganizationEditPageStateImpl} from './state/authority-organization-edit-page-state-impl'; | ||
|
||
@NgModule({ | ||
declarations: [AuthorityOrganizationEditPageComponent], | ||
imports: [ | ||
CommonModule, | ||
RouterModule, | ||
|
||
// NGXS | ||
NgxsModule.forFeature([AuthorityOrganizationEditPageStateImpl]), | ||
|
||
SharedModule, | ||
], | ||
}) | ||
export class AuthorityOrganizationEditPageModule {} |
33 changes: 33 additions & 0 deletions
33
...dit-page/authority-organization-edit-page/authority-organization-edit-page.component.html
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,33 @@ | ||
<section class="my-4 px-8 flex flex-col"> | ||
<app-loading-element | ||
*ngIf="state.organization.isLoading"></app-loading-element> | ||
|
||
<app-error-element | ||
*ngIf="state.organization.isError" | ||
errorMessage="organization"></app-error-element> | ||
|
||
<app-header | ||
*ngIf="state.headerBarConfig" | ||
[headerConfig]="state.headerBarConfig"></app-header> | ||
|
||
<app-organization-edit-form | ||
*ngIf="form" | ||
class="mt-5" | ||
[orgForm]="form.group"></app-organization-edit-form> | ||
|
||
<div *ngIf="form" class="flex justify-end gap-4 mt-6"> | ||
<a | ||
class="btn-accent" | ||
type="button" | ||
routerLink="/authority/organizations/{{state.organization.data.id}}"> | ||
Back | ||
</a> | ||
<button | ||
class="btn-accent" | ||
type="button" | ||
[disabledBtn]="!form.group.valid || state.busy" | ||
(click)="onSubmitClick()"> | ||
Update | ||
</button> | ||
</div> | ||
</section> |
79 changes: 79 additions & 0 deletions
79
...-edit-page/authority-organization-edit-page/authority-organization-edit-page.component.ts
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,79 @@ | ||
/* | ||
* Copyright (c) 2024 sovity GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* sovity GmbH - initial implementation | ||
*/ | ||
import {Component, OnDestroy, OnInit} from '@angular/core'; | ||
import {ActivatedRoute} from '@angular/router'; | ||
import {Subject, takeUntil} from 'rxjs'; | ||
import {take} from 'rxjs/operators'; | ||
import {Store} from '@ngxs/store'; | ||
import { | ||
Reset, | ||
SetOrganizationId, | ||
Submit, | ||
} from '../state/authority-organization-edit-page-action'; | ||
import { | ||
AuthorityOrganizationEditPageState, | ||
DEFAULT_AUTHORITY_ORGANIZATION_EDIT_PAGE_STATE, | ||
} from '../state/authority-organization-edit-page-state'; | ||
import {AuthorityOrganizationEditPageStateImpl} from '../state/authority-organization-edit-page-state-impl'; | ||
import {AuthorityOrganizationEditPageForm} from './authority-organization-edit-page.form'; | ||
|
||
@Component({ | ||
selector: 'app-control-center-organization-edit-page', | ||
templateUrl: './authority-organization-edit-page.component.html', | ||
}) | ||
export class AuthorityOrganizationEditPageComponent | ||
implements OnInit, OnDestroy | ||
{ | ||
form: AuthorityOrganizationEditPageForm | null = null; | ||
state: AuthorityOrganizationEditPageState = | ||
DEFAULT_AUTHORITY_ORGANIZATION_EDIT_PAGE_STATE; | ||
|
||
constructor(private store: Store, private activatedRoute: ActivatedRoute) {} | ||
|
||
ngOnInit(): void { | ||
this.activatedRoute.params.pipe(take(1)).subscribe((params) => { | ||
this.setOrganizationId(params.organizationId); | ||
this.reset(); | ||
this.startListeningToState(); | ||
}); | ||
} | ||
|
||
setOrganizationId(organizationId: string) { | ||
this.store.dispatch(new SetOrganizationId(organizationId)); | ||
} | ||
|
||
reset(): void { | ||
this.store.dispatch(new Reset((form) => (this.form = form))); | ||
} | ||
|
||
startListeningToState(): void { | ||
this.store | ||
.select<AuthorityOrganizationEditPageState>( | ||
AuthorityOrganizationEditPageStateImpl, | ||
) | ||
.pipe(takeUntil(this.ngOnDestroy$)) | ||
.subscribe((state) => { | ||
this.state = state; | ||
}); | ||
} | ||
|
||
ngOnDestroy$ = new Subject(); | ||
ngOnDestroy(): void { | ||
this.ngOnDestroy$.next(null); | ||
this.ngOnDestroy$.complete(); | ||
} | ||
|
||
onSubmitClick(): void { | ||
this.store.dispatch(new Submit(this.form!.value)); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...dit-page/authority-organization-edit-page/authority-organization-edit-page.form-mapper.ts
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,84 @@ | ||
/* | ||
* Copyright (c) 2024 sovity GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* sovity GmbH - initial implementation | ||
*/ | ||
import { | ||
OrganizationDetailsDto, | ||
UpdateOrganizationDto, | ||
} from '@sovity.de/authority-portal-client'; | ||
import {AuthorityOrganizationEditPageFormValue} from './authority-organization-edit-page.form-model'; | ||
|
||
export function buildFormValue( | ||
organization: OrganizationDetailsDto, | ||
): AuthorityOrganizationEditPageFormValue { | ||
let billingAddressSameAsMain = | ||
organization.mainAddress === organization.billingAddress; | ||
let technicalContactSameAsMain = | ||
organization.mainContactName === organization.techContactName && | ||
organization.mainContactPhone === organization.techContactPhone && | ||
organization.mainContactEmail === organization.techContactEmail; | ||
|
||
return { | ||
website: organization.url ?? '', | ||
businessUnit: organization.businessUnit ?? '', | ||
industry: organization.industry ?? '', | ||
description: organization.description ?? '', | ||
|
||
mainAddress: organization.mainAddress ?? '', | ||
billingAddressSameAsMain, | ||
billingAddress: billingAddressSameAsMain | ||
? '' | ||
: organization.billingAddress ?? '', | ||
|
||
mainContactName: organization.mainContactName ?? '', | ||
mainContactPhoneNumber: organization.mainContactPhone ?? '', | ||
mainContactEmail: organization.mainContactEmail ?? '', | ||
technicalContactSameAsMain, | ||
technicalContactName: technicalContactSameAsMain | ||
? '' | ||
: organization.techContactName ?? '', | ||
technicalContactPhoneNumber: technicalContactSameAsMain | ||
? '' | ||
: organization.techContactPhone ?? '', | ||
technicalContactEmail: technicalContactSameAsMain | ||
? '' | ||
: organization.techContactEmail ?? '', | ||
}; | ||
} | ||
|
||
export function buildEditRequest( | ||
formValue: AuthorityOrganizationEditPageFormValue, | ||
): UpdateOrganizationDto { | ||
return { | ||
url: formValue.website, | ||
businessUnit: formValue.businessUnit, | ||
industry: formValue.industry, | ||
description: formValue.description, | ||
|
||
address: formValue.mainAddress, | ||
billingAddress: formValue.billingAddressSameAsMain | ||
? formValue.mainAddress | ||
: formValue.billingAddress, | ||
|
||
mainContactName: formValue.mainContactName, | ||
mainContactPhone: formValue.mainContactPhoneNumber, | ||
mainContactEmail: formValue.mainContactEmail, | ||
techContactName: formValue.technicalContactSameAsMain | ||
? formValue.mainContactName | ||
: formValue.technicalContactName, | ||
techContactPhone: formValue.technicalContactSameAsMain | ||
? formValue.mainContactPhoneNumber | ||
: formValue.technicalContactPhoneNumber, | ||
techContactEmail: formValue.technicalContactSameAsMain | ||
? formValue.mainContactEmail | ||
: formValue.technicalContactEmail, | ||
}; | ||
} |
20 changes: 20 additions & 0 deletions
20
...edit-page/authority-organization-edit-page/authority-organization-edit-page.form-model.ts
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,20 @@ | ||
/* | ||
* Copyright (c) 2024 sovity GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* sovity GmbH - initial implementation | ||
*/ | ||
import {ɵFormGroupRawValue} from '@angular/forms'; | ||
import {OrganizationEditFormModel} from '../../../shared/business/organization-edit-form/organization-edit-form-model'; | ||
|
||
export interface AuthorityOrganizationEditPageFormModel | ||
extends OrganizationEditFormModel {} | ||
|
||
export type AuthorityOrganizationEditPageFormValue = | ||
ɵFormGroupRawValue<AuthorityOrganizationEditPageFormModel>; |
46 changes: 46 additions & 0 deletions
46
...ation-edit-page/authority-organization-edit-page/authority-organization-edit-page.form.ts
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,46 @@ | ||
/* | ||
* Copyright (c) 2024 sovity GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* sovity GmbH - initial implementation | ||
*/ | ||
import {FormBuilder, FormGroup} from '@angular/forms'; | ||
import {switchDisabledControls} from 'src/app/core/utils/form-utils'; | ||
import {buildOrganizationEditForm} from '../../../shared/business/organization-edit-form/organization-edit-form-builder'; | ||
import {organizationEditFormEnabledCtrls} from '../../../shared/business/organization-edit-form/organization-edit-form-enabled-ctrls'; | ||
import { | ||
AuthorityOrganizationEditPageFormModel, | ||
AuthorityOrganizationEditPageFormValue, | ||
} from './authority-organization-edit-page.form-model'; | ||
|
||
export class AuthorityOrganizationEditPageForm { | ||
group = this.buildFormGroup(); | ||
|
||
get value(): AuthorityOrganizationEditPageFormValue { | ||
return this.group.value as AuthorityOrganizationEditPageFormValue; | ||
} | ||
|
||
constructor( | ||
private formBuilder: FormBuilder, | ||
private initialFormValue: AuthorityOrganizationEditPageFormValue, | ||
) {} | ||
|
||
buildFormGroup(): FormGroup<AuthorityOrganizationEditPageFormModel> { | ||
const group: FormGroup<AuthorityOrganizationEditPageFormModel> = | ||
buildOrganizationEditForm(this.formBuilder, this.initialFormValue); | ||
|
||
switchDisabledControls<AuthorityOrganizationEditPageFormValue>( | ||
group, | ||
(value: AuthorityOrganizationEditPageFormValue) => | ||
organizationEditFormEnabledCtrls(value), | ||
); | ||
|
||
return group; | ||
} | ||
} |
Oops, something went wrong.