Skip to content

Commit

Permalink
fix(*): Clean up (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arminmow authored Aug 23, 2024
1 parent 8acc2f7 commit 71b889a
Show file tree
Hide file tree
Showing 22 changed files with 247 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ActivatedRoute } from '@angular/router';
import { UserService } from '../../../services/user/user.service';
import { NotificationService } from '../../../services/notification/notification.service';
import { HttpErrorResponse } from '@angular/common/http';
import { formControl } from '../../../models/form-control';

@Component({
selector: 'app-edit-password',
Expand All @@ -24,39 +25,44 @@ import { HttpErrorResponse } from '@angular/common/http';
styleUrl: './edit-password.component.scss',
})
export class EditPasswordComponent implements OnInit {
protected passwordForm: FormGroup;
protected passwordForm!: FormGroup;
protected isSubmitted = false;
protected isUpdatingProfile = false;
private userID = 0;
protected formControls: {
name: string;
type: string;
placeholder: string;
minLength: number;
}[] = [
protected formControls: formControl[] = [
{ name: 'oldpassword', type: 'password', placeholder: 'Current Password', minLength: 4 },
{ name: 'newpassword', type: 'password', placeholder: 'New Password', minLength: 4 },
{ name: 'confirmPassword', type: 'password', placeholder: 'Confirm New Password', minLength: 4 },
];
protected isUpdatingProfile = false;

constructor(
private fb: FormBuilder,
private activeRoute: ActivatedRoute,
private userService: UserService,
private notificationService: NotificationService
) {
) {}

ngOnInit(): void {
this.initializePasswordForm();
this.setupFormValueChangeHandlers();
this.subscribeToQueryParams();
}

private initializePasswordForm(): void {
this.passwordForm = this.fb.group({
oldpassword: ['', [Validators.required, Validators.minLength(4)]],
newpassword: ['', [Validators.required, Validators.minLength(4)]],
confirmPassword: ['', [Validators.required, Validators.minLength(4), this.matchPassword('newpassword')]],
});
}

private setupFormValueChangeHandlers(): void {
this.passwordForm.get('newpassword')?.valueChanges.subscribe(() => {
this.passwordForm.get('confirmPassword')?.updateValueAndValidity();
});
}

ngOnInit(): void {
private subscribeToQueryParams(): void {
this.activeRoute.queryParams.subscribe(async (params) => {
this.userID = params['id'];
this.isUpdatingProfile = this.userID ? false : true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, OnChanges } from '@angular/core';
import { Component, Input, OnChanges, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
import { NzModalModule } from 'ng-zorro-antd/modal';
import { NgIf, NgFor, NgClass } from '@angular/common';
Expand All @@ -12,30 +12,20 @@ import { NzTypographyModule } from 'ng-zorro-antd/typography';
@Component({
selector: 'app-edit-profile',
standalone: true,
imports: [NzModalModule, NgIf, NgFor, NgClass, ReactiveFormsModule , NzTypographyModule],
imports: [NzModalModule, NgIf, NgFor, NgClass, ReactiveFormsModule, NzTypographyModule],
providers: [FormBuilder, Validators],
templateUrl: './edit-profile.component.html',
styleUrls: ['./edit-profile.component.scss'],
})
export class EditProfileComponent implements OnChanges {
export class EditProfileComponent implements OnChanges, OnInit {
@Input() userData!: UserData;
protected userForm!: FormGroup;
protected isSubmitted = false;
protected isUpdatingProfile = false;

formControls = [
{
name: 'firstName',
type: 'text',
placeholder: 'First Name',
minLength: 1,
},
{
name: 'lastName',
type: 'text',
placeholder: 'Last Name',
minLength: 1,
},
{ name: 'firstName', type: 'text', placeholder: 'First Name', minLength: 1 },
{ name: 'lastName', type: 'text', placeholder: 'Last Name', minLength: 1 },
{ name: 'email', type: 'email', placeholder: 'Email', minLength: 1 },
{ name: 'username', type: 'text', placeholder: 'User Name', minLength: 3 },
];
Expand All @@ -46,13 +36,19 @@ export class EditProfileComponent implements OnChanges {
private userService: UserService,
private notificationService: NotificationService,
private router: Router
) {
) {}

ngOnInit(): void {
this.initializeForm();
}

ngOnChanges(): void {
this.initializeForm();

this.subscribeToQueryParams();
}

private subscribeToQueryParams() {
this.activeRoute.queryParams.subscribe(async (params) => {
this.isUpdatingProfile = params['id'] ? false : true;
});
Expand Down Expand Up @@ -89,7 +85,7 @@ export class EditProfileComponent implements OnChanges {
if (response.message === 'User updated successfully!') {
const successMessage = 'Success';
this.notificationService.createNotification('success', successMessage, response.message);
console.log('hey')
console.log('hey');
this.logout();
} else {
const errorMessage = this.isUpdatingProfile ? 'Error Updating Profile' : 'Error Updating User';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, OnChanges } from '@angular/core';
import { Component, Input, OnChanges, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, ReactiveFormsModule } from '@angular/forms';
import { NgClass, NgIf, NgFor } from '@angular/common';
import { NzSelectModule } from 'ng-zorro-antd/select';
Expand All @@ -15,19 +15,29 @@ import { HttpErrorResponse } from '@angular/common/http';
templateUrl: './edit-role.component.html',
styleUrl: './edit-role.component.scss',
})
export class EditRoleComponent implements OnChanges {
protected roleForm: FormGroup;
export class EditRoleComponent implements OnChanges, OnInit {
@Input({ required: true }) userData: UserData | undefined;

protected roleForm!: FormGroup;
protected formControls = [{ name: 'role', type: 'text', placeholder: 'Role', minLength: 1 }];
protected listOfOption: { label: string; value: string }[] = [
protected listOfTagOptions: string[] = [];
protected isSubmitted = false;
protected listOfOption = [
{ label: 'System Administrator', value: 'Admin' },
{ label: 'Data Admin', value: 'DataAdmin' },
{ label: 'Data Analyst', value: 'DataAnalyst' },
];
protected listOfTagOptions: string[] = [];
protected isSubmitted = false;
@Input({ required: true }) userData: UserData | undefined;

constructor(private fb: FormBuilder, private userService: UserService, private notificationService: NotificationService) {
constructor(
private fb: FormBuilder,
private userService: UserService,
private notificationService: NotificationService
) {}
ngOnInit(): void {
this.initializeForm();
}

initializeForm() {
this.roleForm = this.fb.group({
role: ['', [Validators.required]],
});
Expand Down Expand Up @@ -60,7 +70,7 @@ export class EditRoleComponent implements OnChanges {
} else if (error.status === 400) {
errorMessage = 'Bad Request: Please check your input';
}

this.notificationService.createNotification('error', 'Unexpected Error', errorMessage);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
min-height: 100%;
inline-size: 100%;
overflow-y: auto;
padding-top: 0.5rem;
}

&__panel-block {
flex-shrink: 0;
padding: 2rem;
padding: 1.5rem;
box-sizing: border-box;
display: flex;
flex-direction: column;
Expand All @@ -32,6 +31,7 @@

&__title {
font-size: 2.3rem;
text-align: center;
}

&__inner {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#sigma-container {
flex-grow: 1;
width: calc(
100vw - 35rem - 6.4rem
);
height: 100vh;
background-color: #F8F6F4;
width: calc(100vw - 35rem - 6.4rem);
height: 100vh;
background-color: #f8f6f4;
}

.sigma-container {
flex-grow: 1;
height: 100%;
position: relative;
position: relative;

&__toolbar-container{
&__toolbar-container {
right: 10px;
bottom: 10px;
padding: 1rem;
Expand All @@ -21,16 +19,15 @@ position: relative;
display: flex;
flex-direction: column;
gap: 1rem;
position: absolute;
&__btn{
padding: 1rem;
background-color: black;
border: none;
border-radius: 1rem;
color: #fff;
font-size: 1.5rem;
cursor: pointer;
}
position: absolute;
&__btn {
padding: 1rem;
background-color: black;
border: none;
border-radius: 1rem;
color: #fff;
font-size: 1.5rem;
cursor: pointer;
}
}

}
Loading

0 comments on commit 71b889a

Please sign in to comment.