-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
186 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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
53 changes: 53 additions & 0 deletions
53
src/client/src/app/components/users/user-push-dialog/user-push-dialog.component.html
This file contains 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,53 @@ | ||
<p-dialog | ||
[header]="translations.users_notificationDialog_dialogTitle()" | ||
[visible]="visible()" | ||
(visibleChange)="visible.set($event)" | ||
[modal]="true" | ||
[draggable]="false" | ||
[resizable]="false" | ||
styleClass="min-w-[80vw]" | ||
> | ||
<div class="flex flex-col gap-4" [formGroup]="form"> | ||
<div> | ||
{{ translations.users_notificationDialog_sendTo() | interpolate: user() }} | ||
</div> | ||
|
||
<span class="p-float-label"> | ||
<input | ||
pInputText | ||
[id]="id('title')" | ||
type="text" | ||
formControlName="title" | ||
autocomplete="off" | ||
pAutoFocus | ||
[autofocus]="true" | ||
[placeholder]="translations.users_notificationDialog_titleDefault()" | ||
/> | ||
<label [htmlFor]="id('title')">{{ translations.users_notificationDialog_title() }}</label> | ||
</span> | ||
|
||
<span class="p-float-label"> | ||
<textarea | ||
pInputTextarea | ||
[id]="id('body')" | ||
formControlName="body" | ||
autocomplete="off" | ||
[placeholder]="translations.users_notificationDialog_bodyDefault()" | ||
></textarea> | ||
<label [htmlFor]="id('body')">{{ translations.users_notificationDialog_body() }}</label> | ||
</span> | ||
</div> | ||
<ng-template pTemplate="footer"> | ||
<p-button | ||
[disabled]="isLoading()" | ||
[text]="true" | ||
label="{{ translations.shared_cancel() }}" | ||
(onClick)="close()" | ||
/> | ||
<p-button | ||
[disabled]="isLoading()" | ||
label="{{ translations.shared_send() }}" | ||
(onClick)="submit()" | ||
/> | ||
</ng-template> | ||
</p-dialog> |
82 changes: 82 additions & 0 deletions
82
src/client/src/app/components/users/user-push-dialog/user-push-dialog.component.ts
This file contains 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,82 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core'; | ||
import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; | ||
import { AutoFocusModule } from 'primeng/autofocus'; | ||
import { ButtonModule } from 'primeng/button'; | ||
import { DialogModule } from 'primeng/dialog'; | ||
import { InputTextModule } from 'primeng/inputtext'; | ||
import { InputTextareaModule } from 'primeng/inputtextarea'; | ||
|
||
import { NotificationsService } from '../../../api/services'; | ||
import { InterpolatePipe } from '../../../directives/interpolate.pipe'; | ||
import { User } from '../../../models/parsed-models'; | ||
import { TranslateService } from '../../../services/translate.service'; | ||
|
||
@Component({ | ||
selector: 'app-user-push-dialog', | ||
standalone: true, | ||
imports: [ | ||
AutoFocusModule, | ||
ButtonModule, | ||
CommonModule, | ||
DialogModule, | ||
InputTextModule, | ||
InputTextareaModule, | ||
InterpolatePipe, | ||
ReactiveFormsModule, | ||
], | ||
templateUrl: './user-push-dialog.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class UserPushDialogComponent { | ||
protected readonly translations = inject(TranslateService).translations; | ||
private readonly _randomId = Math.random().toString(36).substring(2, 9); | ||
|
||
private readonly _formBuilder = inject(FormBuilder); | ||
private readonly _notificationsService = inject(NotificationsService); | ||
|
||
protected readonly visible = signal(false); | ||
protected readonly isLoading = signal(false); | ||
protected readonly user = signal<User | undefined>(undefined); | ||
protected readonly form = this._formBuilder.group({ | ||
title: this._formBuilder.control(''), | ||
body: this._formBuilder.control(''), | ||
}); | ||
|
||
public open(user: User): void { | ||
this.user.set(user); | ||
this.visible.set(true); | ||
} | ||
|
||
public close(): void { | ||
this.visible.set(false); | ||
} | ||
|
||
protected async submit() { | ||
if (!this.form.valid) { | ||
this.form.markAllAsTouched(); | ||
return; | ||
} | ||
|
||
const user = this.user(); | ||
if (!user) return; | ||
|
||
this.isLoading.set(true); | ||
try { | ||
await this._notificationsService.sendNotification({ | ||
body: { | ||
userId: user.id, | ||
title: this.form.value.title || this.translations.users_notificationDialog_titleDefault(), | ||
body: this.form.value.body || this.translations.users_notificationDialog_bodyDefault(), | ||
}, | ||
}); | ||
this.close(); | ||
} finally { | ||
this.isLoading.set(false); | ||
} | ||
} | ||
|
||
protected id(purpose: string) { | ||
return `${purpose}-${this._randomId}`; | ||
} | ||
} |
This file contains 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 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 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 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 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