-
Notifications
You must be signed in to change notification settings - Fork 30
[ENG-9994] Feat(auth): add resend confirmation url page #1055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bodintsov
wants to merge
3
commits into
CenterForOpenScience:feature/pbs-26-18
Choose a base branch
from
bodintsov:feature/add-resend-confirmation
base: feature/pbs-26-18
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,3 @@ | ||
| import { FormControl, FormGroup } from '@angular/forms'; | ||
|
|
||
| export type ResendConfirmationFormGroupType = FormGroup<{ email: FormControl }>; |
31 changes: 31 additions & 0 deletions
31
src/app/features/auth/pages/resend/resend-confirmation.component.html
This file contains hidden or 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,31 @@ | ||
| <div class="flex flex-column my-7"> | ||
| <section class="resend-confirmation-container p-3 md:p-4"> | ||
| <h2 class="text-center">{{ 'auth.resendConfirmation.title' | translate }}</h2> | ||
| <p>{{ 'auth.resendConfirmation.description' | translate }}</p> | ||
|
|
||
| <form [formGroup]="resendConfirmationForm" (ngSubmit)="onSubmit()"> | ||
| <osf-text-input | ||
| [control]="resendConfirmationForm.controls['email']" | ||
| [label]="'common.labels.email'" | ||
| [placeholder]="'common.labels.emailPlaceholder'" | ||
| type="email" | ||
| [maxLength]="emailLimit" | ||
| ></osf-text-input> | ||
|
|
||
| <p-button | ||
| class="btn-full-width block mt-6" | ||
| type="submit" | ||
| [label]="'auth.common.resendConfirmation' | translate" | ||
| [disabled]="!resendConfirmationForm.valid" | ||
| ></p-button> | ||
| </form> | ||
| </section> | ||
|
|
||
| <div class="my-4"> | ||
| @if (message(); as msg) { | ||
| <p-message styleClass="w-full" [severity]="msg.severity" closable="true" (onClose)="onCloseMessage()"> | ||
| {{ msg.content | translate }} | ||
| </p-message> | ||
| } | ||
| </div> | ||
| </div> |
17 changes: 17 additions & 0 deletions
17
src/app/features/auth/pages/resend/resend-confirmation.component.scss
This file contains hidden or 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,17 @@ | ||
| @use "styles/mixins" as mix; | ||
|
|
||
| :host { | ||
| @include mix.flex-center; | ||
| flex: 1; | ||
| background: var(--gradient-3); | ||
| } | ||
|
|
||
| .resend-confirmation-container { | ||
| @include mix.flex-column; | ||
| background: var(--white); | ||
| border-radius: mix.rem(12px); | ||
| box-shadow: 0 2px 4px var(--grey-outline); | ||
| max-width: mix.rem(448px); | ||
| gap: mix.rem(24px); | ||
| flex: 1; | ||
| } |
75 changes: 75 additions & 0 deletions
75
src/app/features/auth/pages/resend/resend-confirmation.component.spec.ts
|
nsemets marked this conversation as resolved.
|
This file contains hidden or 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,75 @@ | ||
| import { MockComponent, MockProvider } from 'ng-mocks'; | ||
|
|
||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { AuthService } from '@core/services/auth.service'; | ||
| import { TextInputComponent } from '@osf/shared/components/text-input/text-input.component'; | ||
|
|
||
| import { provideOSFCore } from '@testing/osf.testing.provider'; | ||
| import { AuthServiceMock, AuthServiceMockType } from '@testing/providers/auth-service.mock'; | ||
|
|
||
| import { ResendConfirmationComponent } from './resend-confirmation.component'; | ||
|
|
||
| describe('ResendConfirmationComponent', () => { | ||
| let component: ResendConfirmationComponent; | ||
| let fixture: ComponentFixture<ResendConfirmationComponent>; | ||
| let authService: AuthServiceMockType; | ||
|
|
||
| beforeEach(() => { | ||
| authService = AuthServiceMock.simple(); | ||
|
|
||
| TestBed.configureTestingModule({ | ||
| imports: [ResendConfirmationComponent, MockComponent(TextInputComponent)], | ||
| providers: [provideOSFCore(), MockProvider(AuthService, authService)], | ||
| }); | ||
|
|
||
| fixture = TestBed.createComponent(ResendConfirmationComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should not call resendConfirmationUrl when form is invalid', () => { | ||
| component.resendConfirmationForm.setValue({ email: '' }); | ||
|
|
||
| component.onSubmit(); | ||
|
|
||
| expect(authService.resendConfirmationUrl).not.toHaveBeenCalled(); | ||
| expect(component.message()).toBeNull(); | ||
| }); | ||
|
|
||
| it('should not call resendConfirmationUrl when email is not a valid email address', () => { | ||
| component.resendConfirmationForm.setValue({ email: 'not-an-email' }); | ||
|
|
||
| component.onSubmit(); | ||
|
|
||
| expect(authService.resendConfirmationUrl).not.toHaveBeenCalled(); | ||
| expect(component.message()).toBeNull(); | ||
| }); | ||
|
|
||
| it('should call resendConfirmationUrl, reset the form, and set the success message when form is valid', () => { | ||
| component.resendConfirmationForm.setValue({ email: 'user@example.com' }); | ||
|
|
||
| component.onSubmit(); | ||
|
|
||
| expect(authService.resendConfirmationUrl).toHaveBeenCalledWith('user@example.com'); | ||
| expect(component.resendConfirmationForm.getRawValue()).toEqual({ email: null }); | ||
| expect(component.message()).toEqual({ | ||
| severity: 'success', | ||
| content: 'auth.resendConfirmation.messages.success', | ||
| }); | ||
| }); | ||
|
|
||
| it('should clear the message on onCloseMessage', () => { | ||
| component.resendConfirmationForm.setValue({ email: 'user@example.com' }); | ||
| component.onSubmit(); | ||
| expect(component.message()).not.toBeNull(); | ||
|
|
||
| component.onCloseMessage(); | ||
|
|
||
| expect(component.message()).toBeNull(); | ||
| }); | ||
| }); |
54 changes: 54 additions & 0 deletions
54
src/app/features/auth/pages/resend/resend-confirmation.component.ts
This file contains hidden or 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,54 @@ | ||
| import { TranslatePipe } from '@ngx-translate/core'; | ||
|
|
||
| import { Button } from 'primeng/button'; | ||
| import { Message } from 'primeng/message'; | ||
|
|
||
| import { Component, inject, signal } from '@angular/core'; | ||
| import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms'; | ||
|
|
||
| import { AuthService } from '@core/services/auth.service'; | ||
| import { MessageInfo } from '@osf/features/auth/models'; | ||
| import { ResendConfirmationFormGroupType } from '@osf/features/auth/models/resend-confirmation.model'; | ||
| import { TextInputComponent } from '@osf/shared/components/text-input/text-input.component'; | ||
| import { InputLimits } from '@osf/shared/constants/input-limits.const'; | ||
| import { CustomValidators } from '@osf/shared/helpers/custom-form-validators.helper'; | ||
|
|
||
| @Component({ | ||
| selector: 'osf-resend-confirmation', | ||
| imports: [ReactiveFormsModule, Button, Message, TextInputComponent, TranslatePipe], | ||
| templateUrl: './resend-confirmation.component.html', | ||
| styleUrl: './resend-confirmation.component.scss', | ||
| }) | ||
| export class ResendConfirmationComponent { | ||
| private readonly fb = inject(FormBuilder); | ||
| private readonly authService = inject(AuthService); | ||
|
|
||
| readonly emailLimit = InputLimits.email.maxLength; | ||
|
|
||
| resendConfirmationForm: ResendConfirmationFormGroupType = this.fb.group({ | ||
| email: ['', [CustomValidators.requiredTrimmed(), Validators.email]], | ||
| }); | ||
|
|
||
| message = signal<MessageInfo | null>(null); | ||
|
|
||
| onSubmit(): void { | ||
| if (this.resendConfirmationForm.invalid) { | ||
| return; | ||
| } | ||
|
|
||
| const emailForm = this.resendConfirmationForm.getRawValue(); | ||
|
|
||
| this.authService.resendConfirmationUrl(emailForm.email).subscribe(() => { | ||
| this.resendConfirmationForm.reset(); | ||
|
|
||
| this.message.set({ | ||
| severity: 'success', | ||
| content: 'auth.resendConfirmation.messages.success', | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| onCloseMessage(): void { | ||
| this.message.set(null); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name file like this:
resend-confirmation.model.ts.