diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts index a0c463540..fe572241a 100644 --- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts +++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts @@ -50,8 +50,8 @@ import { Router } from '@angular/router'; import { Account, MarketData, Tag } from '@prisma/client'; import { format, isSameMonth, isToday, parseISO } from 'date-fns'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; -import { forkJoin, Subject } from 'rxjs'; -import { map, switchMap, takeUntil } from 'rxjs/operators'; +import { Subject } from 'rxjs'; +import { switchMap, takeUntil } from 'rxjs/operators'; import { HoldingDetailDialogParams } from './interfaces/interfaces'; @@ -99,7 +99,7 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { public dividendYieldPercentWithCurrencyEffect: number; public feeInBaseCurrency: number; public firstBuyDate: string; - public hasPermissionToCreateTags: boolean; + public hasPermissionToCreateTag: boolean; public hasPermissionToReadMarketDataOfOwnAssetProfile: boolean; public historicalDataItems: LineChartItem[]; public investment: number; @@ -157,29 +157,24 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { .get('tags') .valueChanges.pipe(takeUntil(this.unsubscribeSubject)) .subscribe((tags: Tag[]) => { - const newTags = tags.filter((tag) => { - return tag.id === undefined; + const newTag = tags.find(({ id }) => { + return id === undefined; }); - if (this.hasPermissionToCreateTags && newTags.length > 0) { - const createTagObservables = newTags.map((newTag) => { - return this.adminService.postTag({ name: newTag.name }).pipe(); - }); - - forkJoin(createTagObservables) + if (newTag && this.hasPermissionToCreateTag) { + this.adminService + .postTag(newTag) .pipe( - map((createdTags) => [ - ...tags.filter((tag) => tag.id !== undefined), - ...createdTags - ]), - switchMap((updatedTags) => { - this.activityForm - .get('tags') - .setValue(updatedTags, { emitEvent: false }); + switchMap((createdTag) => { return this.dataService.putHoldingTags({ - tags: updatedTags, dataSource: this.data.dataSource, - symbol: this.data.symbol + symbol: this.data.symbol, + tags: [ + ...tags.filter(({ id }) => { + return id !== undefined; + }), + createdTag + ] }); }), takeUntil(this.unsubscribeSubject) @@ -453,7 +448,7 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { if (state?.user) { this.user = state.user; - this.hasPermissionToCreateTags = hasPermission( + this.hasPermissionToCreateTag = hasPermission( this.user.permissions, permissions.createTag ); diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html index 951e0f9c9..c7d5c2627 100644 --- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html +++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html @@ -388,7 +388,7 @@ } - @if (hasPermissionToCreateTags && tagInputControl.value) { + @if (hasPermissionToCreateTag && tagInputControl.value) { diff --git a/libs/ui/src/lib/tags-selector/tags-selector.component.stories.ts b/libs/ui/src/lib/tags-selector/tags-selector.component.stories.ts index 65efee4d9..42fb68876 100644 --- a/libs/ui/src/lib/tags-selector/tags-selector.component.stories.ts +++ b/libs/ui/src/lib/tags-selector/tags-selector.component.stories.ts @@ -50,7 +50,7 @@ export const Default: Story = { export const CreateCustomTags: Story = { args: { - hasPermissionToCreateTags: true, + hasPermissionToCreateTag: true, tags: [ { id: 'EMERGENCY_FUND', diff --git a/libs/ui/src/lib/tags-selector/tags-selector.component.ts b/libs/ui/src/lib/tags-selector/tags-selector.component.ts index 611c1e938..02b3a0a95 100644 --- a/libs/ui/src/lib/tags-selector/tags-selector.component.ts +++ b/libs/ui/src/lib/tags-selector/tags-selector.component.ts @@ -42,7 +42,7 @@ import { BehaviorSubject, Subject, takeUntil } from 'rxjs'; templateUrl: 'tags-selector.component.html' }) export class GfTagsSelectorComponent implements OnInit, OnChanges, OnDestroy { - @Input() hasPermissionToCreateTags = false; + @Input() hasPermissionToCreateTag = false; @Input() readonly = false; @Input() tags: Tag[]; @Input() tagsAvailable: Tag[]; @@ -81,7 +81,7 @@ export class GfTagsSelectorComponent implements OnInit, OnChanges, OnDestroy { return id === event.option.value; }); - if (!tag && this.hasPermissionToCreateTags) { + if (!tag && this.hasPermissionToCreateTag) { tag = { id: undefined, name: event.option.value as string,