Skip to content
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

[Outreachy Task Submission] - Added confirmation messages and a complete button when posts are added to collections #888

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the changes in this file part of this PR? If not, remove the commits to only include changes for the specific issue you are solving :)

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { CategoriesService } from '@mzima-client/sdk';
import { NotificationService } from '@services';
import { TranslateService } from '@ngx-translate/core';

@Component({
selector: 'app-create',
Expand All @@ -10,7 +12,12 @@ import { CategoriesService } from '@mzima-client/sdk';
export class CreateComponent {
public isFormOnSubmit: boolean;

constructor(private categoriesService: CategoriesService, private router: Router) {}
constructor(
private categoriesService: CategoriesService,
private router: Router,
private notificationService: NotificationService,
private translate: TranslateService,
) {}

public createCategory(category: any): void {
this.isFormOnSubmit = true;
Expand All @@ -21,6 +28,11 @@ export class CreateComponent {
this.router.navigate(['settings/categories']);
},
error: ({ error }) => {
if (error.errors[0].status === 404) {
this.notificationService.showError(
this.translate.instant('An error occured, please try again'),
);
}
this.categoriesService.categoryErrors.next(error.errors.failed_validations);
this.isFormOnSubmit = false;
},
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the changes in this file part of this PR? If not, remove the commits to only include changes for the specific issue you are solving :)

Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,69 @@ export class GeneralComponent implements OnInit {
.pipe(
mergeMap((newImage: any) => {
this.siteConfig.image_header = newImage.result.original_file_url;
console.log(newImage.result.original_file_url);
console.log(this.updateSettings());
return this.updateSettings();
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the console.logs here

}),
)
.subscribe({
complete: () => {
this.loader.hide();
this.submitted = false;
this.notificationService.showError('save successful');

this.notificationService.showSnackbar(
{
// icon: {
// color: 'success',
// name: 'thumb-up',
// },
title: 'notify.export.upload_complete',
buttons: [
{
color: 'primary',
text: 'notify.export.confirmation',
},
],
},
{
duration: 0,
wide: true,
},
);
// alert('uploaded');
},
error: (error) => {
this.loader.hide();
this.submitted = false;
this.notificationService.showError(error.message);
alert('error');
},
});
} else {
this.updateSettings().subscribe({
complete: () => {
this.submitted = false;
this.loader.hide();
this.notificationService.showSnackbar(
{
icon: {
color: 'success',
name: 'thumb-up',
},
title: 'Deployment settings updated successfully',
buttons: [
{
color: 'primary',
text: 'notify.export.confirmation',
},
],
},
{
duration: 3000,
wide: false,
},
);
},
error: (error) => {
this.submitted = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
</app-collection-item>
</div>
</div>

<mat-dialog-actions align="end">
<mzima-client-button (buttonClick)="closeModal()"> Done </mzima-client-button>
</mat-dialog-actions>
</ng-container>
</ng-container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
PostResult,
AccountNotificationsInterface,
} from '@mzima-client/sdk';
// eslint-disable-next-line @nx/enforce-module-boundaries
import { AlertService } from 'libs/sdk/src/lib/services/alerts.service';
import { BaseComponent } from '../../../base.component';
import { ConfirmModalService } from '../../../core/services/confirm-modal.service';
import { Permissions } from '@enums';
Expand Down Expand Up @@ -60,6 +62,7 @@ export class CollectionsComponent extends BaseComponent implements OnInit {
private router: Router,
private rolesService: RolesService,
private notificationsService: NotificationsService,
private alertService: AlertService,
) {
super(sessionService, breakpointService);
this.checkDesktop();
Expand Down Expand Up @@ -169,8 +172,10 @@ export class CollectionsComponent extends BaseComponent implements OnInit {
onCheckChange(isChecked: boolean, item: CollectionResult) {
if (isChecked) {
this.collectionsService.addToCollection(item.id, this.post.id).subscribe();
this.alertService.showMessage(`Post added to the ${item.name} collection`);
} else {
this.collectionsService.removeFromCollection(item.id, this.post.id).subscribe();
this.alertService.showMessage(`Post removed from the ${item.name} collection`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/web-mzima-client/src/env.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"production": true,
"backend_url": "https://mzima-dev-api.staging.ush.zone/",
"backend_url": "http://localhost:8080",
"api_v3": "api/v3/",
"api_v5": "api/v5/",
"mapbox_api_key": "pk.eyJ1IjoidXNoYWhpZGkiLCJhIjoiY2lxaXUzeHBvMDdndmZ0bmVmOWoyMzN6NiJ9.CX56ZmZJv0aUsxvH5huJBw",
Expand Down
27 changes: 27 additions & 0 deletions libs/sdk/src/lib/services/alerts.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Injectable } from '@angular/core';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
// import { SnackbarComponent, SnackbarData } from '../../shared/components';

export interface SnackbarOptions extends MatSnackBarConfig {
wide?: boolean;
}

@Injectable({
providedIn: 'root',
})
export class AlertService {
constructor(public snackBar: MatSnackBar) {}

showError(message: string) {
this.snackBar.open(message, 'Close', { panelClass: ['error'], duration: 3000 });
}

showMessage(message: string) {
this.snackBar.open(message, 'Close', {
panelClass: ['success'],
duration: 2000,
verticalPosition: 'top',
horizontalPosition: 'right',
});
}
}
15 changes: 0 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.