Skip to content

feat(example): add logout confirmation#1287

Merged
brandonroberts merged 9 commits into
ngrx:masterfrom
koumatsumoto:add-logout-confirmation
Aug 28, 2018
Merged

feat(example): add logout confirmation#1287
brandonroberts merged 9 commits into
ngrx:masterfrom
koumatsumoto:add-logout-confirmation

Conversation

@koumatsumoto

@koumatsumoto koumatsumoto commented Aug 24, 2018

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #1271

What is the new behavior?

Show sample code for handling a confirmation prompt using an Actions and Effects with an Angular Material dialog.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Closes #1271

@coveralls

coveralls commented Aug 24, 2018

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 88.755% when pulling 3ab14fc on kouMatsumoto:add-logout-confirmation into 466e2cd on ngrx:master.

@koumatsumoto koumatsumoto force-pushed the add-logout-confirmation branch 2 times, most recently from 0f6713b to 86f4be8 Compare August 24, 2018 16:05
expect(fixture).toMatchSnapshot();
});

it('should have buttons that are applied [mat-dialog-close]', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test isn't needed, because we already have a snapshot above.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thankyou! I'll remove it.


describe('Logout Confirmation Dialog', () => {
let fixture: ComponentFixture<LogoutConfirmationDialogComponent>;
let instance: LogoutConfirmationDialogComponent;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed


return dialogRef.afterClosed();
}),
filter(result => result === 'OK'),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use LogoutConfirmationDialogResult.OK instead of the string 'OK'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankyou! I'll use string enum instead.

logoutConfirmation$ = this.actions$.pipe(
ofType(AuthActionTypes.LogoutConfirmation),
exhaustMap(() => {
const dialogRef = this.dialog.open<

@timdeschryver timdeschryver Aug 25, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the types aren't needed?

const dialogRef = this.dialog.open(LogoutConfirmationDialogComponent)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think dialog can not infer result value.
Should we omit it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, we can leave it as it is.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change LogoutConfirmatinoDialogResultTypes to boolean. See comment above in dialog component.

@koumatsumoto koumatsumoto force-pushed the add-logout-confirmation branch 2 times, most recently from 744d533 to 9a9373a Compare August 27, 2018 04:34
@koumatsumoto

Copy link
Copy Markdown
Contributor Author

@timdeschryver
I updated changes with your advices.
Please review me, thanks!

`,
})
export class LogoutConfirmationDialogComponent {
successValue = LogoutConfirmationDialogResults.OK;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of an enum, just map OK to true and Cancel to false. The dialog will also dismiss and return false by clicking outside its container.

logoutConfirmation$ = this.actions$.pipe(
ofType(AuthActionTypes.LogoutConfirmation),
exhaustMap(() => {
const dialogRef = this.dialog.open<

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change LogoutConfirmatinoDialogResultTypes to boolean. See comment above in dialog component.

@koumatsumoto koumatsumoto force-pushed the add-logout-confirmation branch 2 times, most recently from 3f70aae to 5d0df04 Compare August 27, 2018 13:11
@koumatsumoto

Copy link
Copy Markdown
Contributor Author

@brandonroberts
Thank you for the review!
I updated my changes, please see it.

@brandonroberts

Copy link
Copy Markdown
Member

@koumatsumoto will you rebase this on master again? Thanks

@Component({
template: `
<h2 mat-dialog-title>Logout</h2>
<mat-dialog-content>Do you really want to logout?</mat-dialog-content>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to Are you sure you want to logout?

<button mat-button [mat-dialog-close]="false">Cancel</button>
<button mat-button [mat-dialog-close]="true">OK</button>
</mat-dialog-actions>
`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some styles to the component

    :host {
      display: block;
      width: 100%;
      max-width: 300px;
    }

    mat-dialog-actions {
      display: flex;
      justify-content: flex-end;
    }

    [mat-button] {
      padding: 0;
    }


beforeEach(() => {
TestBed.configureTestingModule({
imports: [MatButtonModule, MatDialogModule],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports aren't needed for the effects

@koumatsumoto koumatsumoto force-pushed the add-logout-confirmation branch from 5d0df04 to 593f82a Compare August 28, 2018 00:46
@koumatsumoto

Copy link
Copy Markdown
Contributor Author

@brandonroberts
I updated changes, please continue your review 😄

@brandonroberts brandonroberts merged commit ba8d300 into ngrx:master Aug 28, 2018
@koumatsumoto koumatsumoto deleted the add-logout-confirmation branch September 2, 2018 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Example: Add logout confirmation

5 participants