Skip to content

Commit 79a2fe5

Browse files
authored
Merge pull request #217 from CenterForOpenScience/fix/fixes
Fix/fixes
2 parents 729b2b7 + ed2a60f commit 79a2fe5

File tree

20 files changed

+402
-247
lines changed

20 files changed

+402
-247
lines changed

src/app/features/moderation/components/registry-submissions/registry-submissions.component.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
77
import { FormsModule } from '@angular/forms';
88

99
import { Primitive } from '@osf/core/helpers';
10-
import { CollectionSubmissionsListComponent } from '@osf/features/moderation/components/collection-submissions-list/collection-submissions-list.component';
1110
import { IconComponent, SelectComponent } from '@osf/shared/components';
1211
import { ALL_SORT_OPTIONS } from '@osf/shared/constants';
1312

@@ -17,15 +16,7 @@ import { pubicReviews } from '../test-data';
1716

1817
@Component({
1918
selector: 'osf-registry-submissions',
20-
imports: [
21-
SelectButton,
22-
TranslatePipe,
23-
FormsModule,
24-
SelectComponent,
25-
CollectionSubmissionsListComponent,
26-
IconComponent,
27-
TitleCasePipe,
28-
],
19+
imports: [SelectButton, TranslatePipe, FormsModule, SelectComponent, IconComponent, TitleCasePipe],
2920
templateUrl: './registry-submissions.component.html',
3021
styleUrl: './registry-submissions.component.scss',
3122
changeDetection: ChangeDetectionStrategy.OnPush,

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

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

7-
@if (index() !== 0) {
8-
<div>
9-
<p-button
10-
[label]="'common.buttons.remove' | translate"
11-
severity="danger"
12-
variant="text"
13-
(click)="remove.emit()"
14-
/>
15-
</div>
16-
}
7+
<div>
8+
<p-button
9+
[label]="'common.buttons.remove' | translate"
10+
severity="danger"
11+
variant="text"
12+
(click)="remove.emit()"
13+
/>
14+
</div>
1715
</div>
1816

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

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

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1717
import { FormArray, FormBuilder, FormGroup, ReactiveFormsModule } from '@angular/forms';
1818

1919
import { UpdateProfileSettingsEducation, UserSelectors } from '@osf/core/store/user';
20-
import { Education } from '@osf/shared/models';
2120
import { CustomConfirmationService, LoaderService, ToastService } from '@osf/shared/services';
22-
import { CustomValidators, findChangedFields } from '@osf/shared/utils';
21+
import { CustomValidators } from '@osf/shared/utils';
2322

2423
import { EducationForm } from '../../models';
24+
import { hasEducationChanges, mapEducationToForm, mapFormToEducation } from '../../utils';
2525
import { EducationFormComponent } from '../education-form/education-form.component';
2626

2727
@Component({
@@ -54,7 +54,11 @@ export class EducationComponent {
5454
}
5555

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

6064
addEducation(): void {
@@ -74,9 +78,10 @@ export class EducationComponent {
7478
this.customConfirmationService.confirmDelete({
7579
headerKey: 'common.discardChangesDialog.header',
7680
messageKey: 'common.discardChangesDialog.message',
81+
acceptLabelKey: 'common.buttons.discardChanges',
7782
onConfirm: () => {
7883
this.setInitialData();
79-
this.cd.markForCheck();
84+
this.toastService.showSuccess('settings.profileSettings.changesDiscarded');
8085
},
8186
});
8287
}
@@ -87,7 +92,7 @@ export class EducationComponent {
8792
return;
8893
}
8994

90-
const formattedEducation = this.educations.value.map((education) => this.mapFormToEducation(education));
95+
const formattedEducation = this.educations.value.map((education) => mapFormToEducation(education));
9196
this.loaderService.show();
9297

9398
this.actions
@@ -111,10 +116,7 @@ export class EducationComponent {
111116
const initialEdu = this.educationItems()[index];
112117
if (!initialEdu) return true;
113118

114-
const formattedFormEducation = this.mapFormToEducation(formEducation);
115-
const changedFields = findChangedFields<Education>(formattedFormEducation, initialEdu);
116-
117-
return Object.keys(changedFields).length > 0;
119+
return hasEducationChanges(formEducation, initialEdu);
118120
});
119121
}
120122

@@ -138,37 +140,9 @@ export class EducationComponent {
138140

139141
this.educations.clear();
140142
educations
141-
.map((education) => this.mapEducationToForm(education))
143+
.map((education) => mapEducationToForm(education))
142144
.forEach((education) => this.educations.push(this.createEducationFormGroup(education)));
143145

144146
this.cd.markForCheck();
145147
}
146-
147-
private mapFormToEducation(education: EducationForm): Education {
148-
return {
149-
institution: education.institution,
150-
department: education.department,
151-
degree: education.degree,
152-
startYear: education.startDate?.getFullYear() ?? new Date().getFullYear(),
153-
startMonth: (education.startDate?.getMonth() ?? 0) + 1,
154-
endYear: education.ongoing ? null : (education.endDate?.getFullYear() ?? null),
155-
endMonth: education.ongoing ? null : education.endDate ? education.endDate.getMonth() + 1 : null,
156-
ongoing: education.ongoing,
157-
};
158-
}
159-
160-
private mapEducationToForm(education: Education): EducationForm {
161-
return {
162-
institution: education.institution,
163-
department: education.department,
164-
degree: education.degree,
165-
startDate: new Date(+education.startYear, education.startMonth - 1),
166-
endDate: education.ongoing
167-
? null
168-
: education.endYear && education.endMonth
169-
? new Date(+education.endYear, education.endMonth - 1)
170-
: null,
171-
ongoing: education.ongoing,
172-
};
173-
}
174148
}

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

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

7-
@if (index() !== 0) {
8-
<div>
9-
<p-button
10-
[label]="'common.buttons.remove' | translate"
11-
severity="danger"
12-
variant="text"
13-
(click)="remove.emit()"
14-
/>
15-
</div>
16-
}
7+
<div>
8+
<p-button
9+
[label]="'common.buttons.remove' | translate"
10+
severity="danger"
11+
variant="text"
12+
(click)="remove.emit()"
13+
/>
14+
</div>
1715
</div>
1816

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

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

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1717
import { FormArray, FormBuilder, FormGroup, ReactiveFormsModule } from '@angular/forms';
1818

1919
import { UpdateProfileSettingsEmployment, UserSelectors } from '@osf/core/store/user';
20-
import { Employment } from '@osf/shared/models';
2120
import { CustomConfirmationService, LoaderService, ToastService } from '@osf/shared/services';
22-
import { CustomValidators, findChangedFields } from '@osf/shared/utils';
21+
import { CustomValidators } from '@osf/shared/utils';
2322

2423
import { EmploymentForm } from '../../models';
24+
import { hasEmploymentChanges, mapEmploymentToForm, mapFormToEmployment } from '../../utils';
2525
import { EmploymentFormComponent } from '../employment-form/employment-form.component';
2626

2727
@Component({
@@ -55,7 +55,11 @@ export class EmploymentComponent {
5555
}
5656

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

6165
addPosition(): void {
@@ -75,9 +79,10 @@ export class EmploymentComponent {
7579
this.customConfirmationService.confirmDelete({
7680
headerKey: 'common.discardChangesDialog.header',
7781
messageKey: 'common.discardChangesDialog.message',
82+
acceptLabelKey: 'common.buttons.discardChanges',
7883
onConfirm: () => {
7984
this.setInitialData();
80-
this.cd.markForCheck();
85+
this.toastService.showSuccess('settings.profileSettings.changesDiscarded');
8186
},
8287
});
8388
}
@@ -88,7 +93,7 @@ export class EmploymentComponent {
8893
return;
8994
}
9095

91-
const formattedEmployment = this.positions.value.map((position) => this.mapFormToEmployment(position));
96+
const formattedEmployment = this.positions.value.map((position) => mapFormToEmployment(position));
9297
this.loaderService.show();
9398

9499
this.actions
@@ -112,10 +117,7 @@ export class EmploymentComponent {
112117
const initial = this.employment()[index];
113118
if (!initial) return true;
114119

115-
const formattedFormEducation = this.mapFormToEmployment(formEmployment);
116-
const changedFields = findChangedFields<Employment>(formattedFormEducation, initial);
117-
118-
return Object.keys(changedFields).length > 0;
120+
return hasEmploymentChanges(formEmployment, initial);
119121
});
120122
}
121123

@@ -139,35 +141,9 @@ export class EmploymentComponent {
139141

140142
this.positions.clear();
141143
employment
142-
.map((x) => this.mapEmploymentToForm(x))
144+
.map((x) => mapEmploymentToForm(x))
143145
.forEach((x) => this.positions.push(this.createEmploymentFormGroup(x)));
144-
}
145-
146-
private mapFormToEmployment(employment: EmploymentForm): Employment {
147-
return {
148-
title: employment.title,
149-
department: employment.department,
150-
institution: employment.institution,
151-
startYear: employment.startDate?.getFullYear() ?? new Date().getFullYear(),
152-
startMonth: (employment.startDate?.getMonth() ?? 0) + 1,
153-
endYear: employment.ongoing ? null : (employment.endDate?.getFullYear() ?? null),
154-
endMonth: employment.ongoing ? null : employment.endDate ? employment.endDate.getMonth() + 1 : null,
155-
ongoing: employment.ongoing,
156-
};
157-
}
158146

159-
private mapEmploymentToForm(employment: Employment): EmploymentForm {
160-
return {
161-
title: employment.title,
162-
department: employment.department,
163-
institution: employment.institution,
164-
startDate: new Date(+employment.startYear, employment.startMonth - 1),
165-
endDate: employment.ongoing
166-
? null
167-
: employment.endYear && employment.endMonth
168-
? new Date(+employment.endYear, employment.endMonth - 1)
169-
: null,
170-
ongoing: employment.ongoing,
171-
};
147+
this.cd.markForCheck();
172148
}
173149
}

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import { FormBuilder } from '@angular/forms';
1010

1111
import { User } from '@osf/core/models';
1212
import { UpdateProfileSettingsUser, UserSelectors } from '@osf/core/store/user';
13-
import { LoaderService, ToastService } from '@osf/shared/services';
13+
import { CustomConfirmationService, LoaderService, ToastService } from '@osf/shared/services';
1414
import { CustomValidators } from '@osf/shared/utils';
1515

1616
import { NameForm } from '../../models';
17+
import { hasNameChanges } from '../../utils';
1718
import { CitationPreviewComponent } from '../citation-preview/citation-preview.component';
1819
import { NameFormComponent } from '../name-form/name-form.component';
1920

@@ -30,6 +31,7 @@ export class NameComponent {
3031
private readonly loaderService = inject(LoaderService);
3132
private readonly toastService = inject(ToastService);
3233
private readonly destroyRef = inject(DestroyRef);
34+
private readonly customConfirmationService = inject(CustomConfirmationService);
3335

3436
readonly actions = createDispatchMap({ updateProfileSettingsUser: UpdateProfileSettingsUser });
3537
readonly currentUser = select(UserSelectors.getUserNames);
@@ -85,13 +87,29 @@ export class NameComponent {
8587
}
8688

8789
discardChanges() {
88-
const user = this.currentUser();
89-
90-
if (!user) {
90+
if (!this.hasFormChanges()) {
9191
return;
9292
}
9393

94-
this.updateForm(user);
94+
this.customConfirmationService.confirmDelete({
95+
headerKey: 'common.discardChangesDialog.header',
96+
messageKey: 'common.discardChangesDialog.message',
97+
acceptLabelKey: 'common.buttons.discardChanges',
98+
onConfirm: () => {
99+
const user = this.currentUser();
100+
if (user) {
101+
this.updateForm(user);
102+
this.toastService.showSuccess('settings.profileSettings.changesDiscarded');
103+
}
104+
},
105+
});
106+
}
107+
108+
private hasFormChanges(): boolean {
109+
const user = this.currentUser();
110+
if (!user) return false;
111+
112+
return hasNameChanges(this.form.controls, user);
95113
}
96114

97115
private updateForm(user: Partial<User>) {

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,31 @@
66
<h2>
77
{{ 'settings.profileSettings.social.title' | translate: { index: index() + 1 } }}
88
</h2>
9-
@if (index() !== 0) {
10-
<div>
11-
<p-button
12-
[label]="'common.buttons.remove' | translate"
13-
severity="danger"
14-
variant="text"
15-
(click)="remove.emit()"
16-
/>
17-
</div>
18-
}
199
</div>
2010

2111
<div class="flex flex-column row-gap-4 w-full md:flex-row md:align-items-end md:column-gap-3">
22-
<div class="w-full md:w-4">
23-
<p class="font-light mb-1">
24-
{{ 'settings.profileSettings.social.socialOutput' | translate }}
25-
</p>
12+
<div class="w-full md:w-12">
13+
<label for="id">{{ label() | translate }}</label>
2614

27-
<p-select formControlName="socialOutput" [options]="socials" optionLabel="label" class="w-full"></p-select>
28-
</div>
15+
<p-inputgroup class="addon-input flex-wrap">
16+
@if (domain()) {
17+
<p-inputgroup-addon class="border-1 grey-border-color md:border-0">
18+
{{ domain() }}
19+
</p-inputgroup-addon>
20+
}
2921

30-
<div class="w-full md:w-8">
31-
<p class="mb-1">
32-
{{ 'settings.profileSettings.social.webAddress' | translate }}
33-
</p>
22+
<input pInputText [placeholder]="placeholder()" formControlName="webAddress" [maxlength]="socialMaxLength" />
3423

35-
<p-inputgroup class="addon-input flex-wrap">
36-
<p-inputgroup-addon class="border-1 grey-border-color md:border-0">
37-
{{ domain }}
38-
</p-inputgroup-addon>
24+
@if (hasLinkedField()) {
25+
<p-inputgroup-addon class="border-1 grey-border-color md:border-0"> .academia.edu/ </p-inputgroup-addon>
3926

40-
<input pInputText [placeholder]="placeholder" formControlName="webAddress" [maxlength]="socialMaxLength" />
27+
<input
28+
pInputText
29+
[placeholder]="linkedPlaceholder()"
30+
formControlName="linkedWebAddress"
31+
[maxlength]="socialMaxLength"
32+
/>
33+
}
4134
</p-inputgroup>
4235
</div>
4336
</div>

0 commit comments

Comments
 (0)