Skip to content

Commit

Permalink
chore: code tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismclarke committed Mar 4, 2025
1 parent 9dae85d commit df9f227
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- ready status template -->
<div class="status-container" [attr.data-status]="status">
<div class="status-container" [attr.data-status]="status()">
@if(options().showStatusCode){
<span class="status-code" [attr.data-status]="status">{{code() || ''}}</span>
<span class="status-code" [attr.data-status]="status()">{{code() || ''}}</span>
} @if(options().labels?.ready; as readyLabel){
<div class="status-label">{{readyLabel}}</div>
} @if(options().events?.refresh; as refreshEvent){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,69 @@ <h1 mat-dialog-title>{{ title }}</h1>
<form [formGroup]="form">
<mat-form-field>
<mat-label>Email</mat-label>
<input type="email" matInput formControlName="email" autocomplete="picsa-email"
[errorStateMatcher]="errorMatcher" />
<input
type="email"
matInput
formControlName="email"
autocomplete="picsa-email"
[errorStateMatcher]="errorMatcher"
/>
@if (form.controls.email.errors) {
<mat-error>Please enter a valid email address</mat-error>
}
</mat-form-field>
@if (template !== 'reset') {<mat-form-field>
<mat-label>Password</mat-label>
<input type="password" matInput autocomplete="picsa-password" formControlName="password" />
</mat-form-field>}
@if(template==='register'){
<input type="password" matInput autocomplete="picsa-password" formControlName="password" /> </mat-form-field
>} @if(template==='register'){
<mat-form-field>
<mat-label>Repeat Password</mat-label>
<input type="password" matInput autocomplete="off" formControlName="passwordConfirm"
[errorStateMatcher]="errorMatcher" />
<input
type="password"
matInput
autocomplete="off"
formControlName="passwordConfirm"
[errorStateMatcher]="errorMatcher"
/>
@if (form.controls.passwordConfirm?.errors) {
<mat-error>Password must match</mat-error>
}
</mat-form-field>
}
</form>
</mat-dialog-content>
<mat-dialog-actions style="display: flex; flex-direction: column;" align="start">
<mat-dialog-actions class="flex flex-col">
@if(template==='signIn'){
<div class="action-buttons-container">
<button mat-button (click)="enableRegisterMode()">Create new account</button>
<button mat-button cdkFocusInitial (click)="handleSignIn()" style="margin-left: auto"
[disabled]="!form.valid || form.disabled">
<button mat-button (click)="enableRegisterMode()" class="flex-1">Create Account</button>
<button
mat-button
cdkFocusInitial
(click)="handleSignIn()"
class="flex-1"
[disabled]="!form.valid || form.disabled"
>
Sign In
</button>
</div>
<button mat-button (click)="enableResetMode()">Reset Password</button>
<button class="mt-2" mat-button (click)="enableResetMode()">Forgot Password</button>
} @if(template==='register'){
<div class="action-buttons-container">
<button mat-button (click)="enableSignInMode()">Sign in</button>
<button mat-button cdkFocusInitial (click)="handleRegister()" style="margin-left: auto"
[disabled]="!form.valid || form.disabled">
<button
mat-button
cdkFocusInitial
(click)="handleRegister()"
class="ml-auto"
[disabled]="!form.valid || form.disabled"
>
Register
</button>
</div>
}
@if(template==='reset'){
} @if(template==='reset'){
<div class="action-buttons-container">
<button mat-button (click)="enableSignInMode()">Sign in</button>
<button mat-button (click)="handleReset()" style="margin-left: auto"
[disabled]="!form.controls.email.valid || form.disabled">
Send Reset Email
<button mat-button (click)="handleReset()" class="ml-auto" [disabled]="!form.controls.email.valid || form.disabled">
Reset
</button>
</div>
}
</mat-dialog-actions>
</mat-dialog-actions>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import {
FormControl,
FormGroup,
Expand Down Expand Up @@ -50,8 +50,9 @@ export class SupabaseSignInDialogComponent {
password: new FormControl('', Validators.required),
});

private readonly dialogRef = inject(MatDialogRef<SupabaseSignInDialogComponent>);

constructor(
private dialogRef: MatDialogRef<SupabaseSignInDialogComponent>,
private notificationService: PicsaNotificationService,
private supabaseAuthService: SupabaseAuthService
) {}
Expand Down Expand Up @@ -83,8 +84,8 @@ export class SupabaseSignInDialogComponent {
const { data, error } = await this.supabaseAuthService.signInUser(email, password);
console.log({ data, error });
if (error) {
throw new Error(error.message);
this.form.enable();
throw new Error(error.message);
} else {
this.dialogRef.close();
}
Expand All @@ -94,20 +95,21 @@ export class SupabaseSignInDialogComponent {
const { email, password } = this.form.value;
const { error } = await this.supabaseAuthService.signUpUser(email, password);
if (error) {
throw new Error(error.message);
this.form.enable();
throw new Error(error.message);
} else {
this.dialogRef.close();
}
}
public async handleReset() {
this.form.disable();
this.form.disable();
const { email } = this.form.value;
const { error } = await this.supabaseAuthService.resetEmailPassword(email);
if (error) {
throw new Error(error.message);
this.form.enable();
throw new Error(error.message);
} else {
this.notificationService.showSuccessNotification(`Reset email sent, please check your inbox`,{duration:5000});
this.dialogRef.close();
}
}
Expand Down

0 comments on commit df9f227

Please sign in to comment.