Skip to content

Commit b680df4

Browse files
authored
fix(profile-settings): updated education and employment (#607)
1 parent 992fa5f commit b680df4

File tree

11 files changed

+33
-82
lines changed

11 files changed

+33
-82
lines changed

src/app/features/settings/profile-settings/components/education-form/education-form.component.html

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ <h2>
44
{{ 'settings.profileSettings.education.title' | translate: { index: index() + 1 } }}
55
</h2>
66

7-
@if (showRemove()) {
8-
<p-button
9-
[label]="'common.buttons.remove' | translate"
10-
severity="danger"
11-
variant="text"
12-
(click)="remove.emit()"
13-
/>
14-
}
7+
<p-button
8+
[label]="'common.buttons.remove' | translate"
9+
severity="danger"
10+
variant="text"
11+
(onClick)="remove.emit()"
12+
/>
1513
</div>
1614

1715
<div class="flex flex-column row-gap-4">

src/app/features/settings/profile-settings/components/education-form/education-form.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export class EducationFormComponent implements OnInit {
3232

3333
group = input.required<FormGroup>();
3434
index = input.required<number>();
35-
showRemove = input(false);
3635
remove = output<void>();
3736

3837
get institutionControl() {

src/app/features/settings/profile-settings/components/education/education.component.html

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
<form [formGroup]="educationForm">
22
<div formArrayName="educations" class="flex flex-column row-gap-4">
3-
@if (educations.controls.length) {
4-
@for (education of educations.controls; track $index; let index = $index) {
5-
<osf-education-form
6-
[group]="education"
7-
[index]="index"
8-
[showRemove]="educations.controls.length > 1"
9-
(remove)="removeEducation(index)"
10-
></osf-education-form>
11-
}
3+
@for (education of educations.controls; track $index; let index = $index) {
4+
<osf-education-form [group]="education" [index]="index" (remove)="removeEducation(index)"></osf-education-form>
125
}
136
</div>
147
</form>

src/app/features/settings/profile-settings/components/education/education.component.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ export class EducationComponent {
5454
}
5555

5656
removeEducation(index: number): void {
57-
if (this.educations.length > 1) {
58-
this.educations.removeAt(index);
59-
} else {
60-
this.educations.reset();
61-
}
57+
this.educations.removeAt(index);
6258
}
6359

6460
addEducation(): void {
@@ -157,16 +153,12 @@ export class EducationComponent {
157153

158154
this.educations.clear();
159155

160-
if (!educations?.length) {
161-
this.addEducation();
162-
this.cd.markForCheck();
163-
return;
156+
if (educations?.length) {
157+
educations
158+
.map((education) => mapEducationToForm(education))
159+
.forEach((education) => this.educations.push(this.createEducationFormGroup(education)));
164160
}
165161

166-
educations
167-
.map((education) => mapEducationToForm(education))
168-
.forEach((education) => this.educations.push(this.createEducationFormGroup(education)));
169-
170162
this.cd.markForCheck();
171163
}
172164
}

src/app/features/settings/profile-settings/components/employment-form/employment-form.component.html

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ <h2>
44
{{ 'settings.profileSettings.employment.title' | translate: { index: index() + 1 } }}
55
</h2>
66

7-
@if (showRemove()) {
8-
<p-button
9-
[label]="'common.buttons.remove' | translate"
10-
severity="danger"
11-
variant="text"
12-
(onClick)="remove.emit()"
13-
/>
14-
}
7+
<p-button
8+
[label]="'common.buttons.remove' | translate"
9+
severity="danger"
10+
variant="text"
11+
(onClick)="remove.emit()"
12+
/>
1513
</div>
1614

1715
<div class="flex flex-column row-gap-4">

src/app/features/settings/profile-settings/components/employment-form/employment-form.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export class EmploymentFormComponent implements OnInit {
3232

3333
group = input.required<FormGroup>();
3434
index = input.required<number>();
35-
showRemove = input(false);
3635
remove = output<void>();
3736

3837
get titleControl() {

src/app/features/settings/profile-settings/components/employment/employment.component.html

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
<form [formGroup]="employmentForm">
22
<div formArrayName="positions" class="flex flex-column row-gap-4">
3-
@if (positions.controls.length) {
4-
@for (position of positions.controls; track index; let index = $index) {
5-
<osf-employment-form
6-
[group]="position"
7-
[index]="index"
8-
[showRemove]="positions.controls.length > 1"
9-
(remove)="removePosition(index)"
10-
></osf-employment-form>
11-
}
3+
@for (position of positions.controls; track index; let index = $index) {
4+
<osf-employment-form [group]="position" [index]="index" (remove)="removePosition(index)"></osf-employment-form>
125
}
136
</div>
147
</form>

src/app/features/settings/profile-settings/components/employment/employment.component.ts

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ export class EmploymentComponent {
5555
}
5656

5757
removePosition(index: number): void {
58-
if (this.positions.length > 1) {
59-
this.positions.removeAt(index);
60-
} else {
61-
this.positions.reset();
62-
}
58+
this.positions.removeAt(index);
6359
}
6460

6561
addPosition(): void {
@@ -93,11 +89,11 @@ export class EmploymentComponent {
9389
return;
9490
}
9591

96-
const formattedEmployment = this.positions.value.map((position) => mapFormToEmployment(position));
92+
const employments = this.positions.value.map(mapFormToEmployment);
9793
this.loaderService.show();
9894

9995
this.actions
100-
.updateProfileSettingsEmployment(formattedEmployment)
96+
.updateProfileSettingsEmployment(employments)
10197
.pipe(takeUntilDestroyed(this.destroyRef))
10298
.subscribe({
10399
next: () => {
@@ -112,18 +108,6 @@ export class EmploymentComponent {
112108
const employment = this.employment();
113109
const formPositions = this.positions.value;
114110

115-
if (!employment?.length) {
116-
return formPositions.some(
117-
(position) =>
118-
position.title?.trim() ||
119-
position.institution?.trim() ||
120-
position.department?.trim() ||
121-
position.startDate ||
122-
position.endDate ||
123-
position.ongoing
124-
);
125-
}
126-
127111
if (formPositions.length !== employment.length) {
128112
return true;
129113
}
@@ -157,16 +141,12 @@ export class EmploymentComponent {
157141
const employment = this.employment();
158142
this.positions.clear();
159143

160-
if (!employment?.length) {
161-
this.addPosition();
162-
this.cd.markForCheck();
163-
return;
144+
if (employment?.length) {
145+
employment
146+
.map((x) => mapEmploymentToForm(x))
147+
.forEach((x) => this.positions.push(this.createEmploymentFormGroup(x)));
164148
}
165149

166-
employment
167-
.map((x) => mapEmploymentToForm(x))
168-
.forEach((x) => this.positions.push(this.createEmploymentFormGroup(x)));
169-
170150
this.cd.markForCheck();
171151
}
172152
}

src/app/features/settings/profile-settings/helpers/employment-comparison.helper.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function mapFormToEmployment(employment: EmploymentForm): Employment {
88
title: employment.title,
99
department: employment.department,
1010
institution: employment.institution,
11-
startYear: employment.startDate?.getFullYear() ?? new Date().getFullYear(),
11+
startYear: employment.startDate?.getFullYear() ?? null,
1212
startMonth: employment.startDate?.getMonth() + 1,
1313
endYear: employment.ongoing ? null : (employment.endDate?.getFullYear() ?? null),
1414
endMonth: employment.ongoing ? null : employment.endDate ? employment.endDate.getMonth() + 1 : null,
@@ -21,16 +21,15 @@ export function mapEmploymentToForm(employment: Employment): EmploymentForm {
2121
title: employment.title,
2222
department: employment.department,
2323
institution: employment.institution,
24-
startDate: new Date(+employment.startYear, employment.startMonth - 1),
24+
startDate: new Date(employment.startYear, employment.startMonth - 1),
2525
endDate: employment.ongoing
2626
? null
2727
: employment.endYear && employment.endMonth
28-
? new Date(+employment.endYear, employment.endMonth - 1)
28+
? new Date(employment.endYear, employment.endMonth - 1)
2929
: null,
3030
ongoing: employment.ongoing,
3131
};
3232
}
33-
3433
export function hasEmploymentChanges(formEmployment: EmploymentForm, initialEmployment: Employment): boolean {
3534
const formattedFormEmployment = mapFormToEmployment(formEmployment);
3635

src/app/shared/constants/input-limits.const.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ export const InputLimits = {
3737
},
3838
};
3939

40-
export const forbiddenFileNameCharacters = /[()<>~!@$&*:;,"'\\|/?]/;
40+
export const forbiddenFileNameCharacters = /[()<>~!@$&*#%^:;,"'\\|/?]/;

0 commit comments

Comments
 (0)