From 6a79070c02c3e229dae92ffbb1775a0a69f4099d Mon Sep 17 00:00:00 2001 From: KenTandrian Date: Sun, 17 May 2026 16:16:18 +0700 Subject: [PATCH] fix(client): make tag as optional to cover tag creation use case --- .../app/components/admin-tag/admin-tag.component.ts | 13 +++++-------- .../create-or-update-tag-dialog.component.ts | 4 ++-- .../create-or-update-tag-dialog.html | 2 +- .../interfaces/interfaces.ts | 2 +- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/apps/client/src/app/components/admin-tag/admin-tag.component.ts b/apps/client/src/app/components/admin-tag/admin-tag.component.ts index 56544f784..de891418d 100644 --- a/apps/client/src/app/components/admin-tag/admin-tag.component.ts +++ b/apps/client/src/app/components/admin-tag/admin-tag.component.ts @@ -83,7 +83,9 @@ export class GfAdminTagComponent implements OnInit { return id === params['tagId']; }); - this.openUpdateTagDialog(tag); + if (tag) { + this.openUpdateTagDialog(tag); + } } else { this.router.navigate(['.'], { relativeTo: this.route }); } @@ -153,12 +155,7 @@ export class GfAdminTagComponent implements OnInit { GfCreateOrUpdateTagDialogComponent, CreateOrUpdateTagDialogParams >(GfCreateOrUpdateTagDialogComponent, { - data: { - tag: { - id: null, - name: null - } - }, + data: {} satisfies CreateOrUpdateTagDialogParams, height: this.deviceType === 'mobile' ? '98vh' : undefined, width: this.deviceType === 'mobile' ? '100vw' : '50rem' }); @@ -197,7 +194,7 @@ export class GfAdminTagComponent implements OnInit { id, name } - }, + } satisfies CreateOrUpdateTagDialogParams, height: this.deviceType === 'mobile' ? '98vh' : undefined, width: this.deviceType === 'mobile' ? '100vw' : '50rem' }); diff --git a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts index e22c73478..dac4ea412 100644 --- a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts +++ b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts @@ -43,7 +43,7 @@ export class GfCreateOrUpdateTagDialogComponent { private formBuilder: FormBuilder ) { this.tagForm = this.formBuilder.group({ - name: [this.data.tag.name] + name: [this.data.tag?.name] }); } @@ -57,7 +57,7 @@ export class GfCreateOrUpdateTagDialogComponent { name: this.tagForm.get('name')?.value }; - if (this.data.tag.id) { + if (this.data.tag?.id) { (tag as UpdateTagDto).id = this.data.tag.id; await validateObjectForForm({ classDto: UpdateTagDto, diff --git a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html index d2fdad30e..876db206c 100644 --- a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html +++ b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html @@ -4,7 +4,7 @@ (keyup.enter)="tagForm.valid && onSubmit()" (ngSubmit)="onSubmit()" > - @if (data.tag.id) { + @if (data.tag?.id) {

Update tag

} @else {

Add tag

diff --git a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/interfaces/interfaces.ts b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/interfaces/interfaces.ts index 4b7f83e93..f4b1104d0 100644 --- a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/interfaces/interfaces.ts +++ b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/interfaces/interfaces.ts @@ -1,5 +1,5 @@ import { Tag } from '@prisma/client'; export interface CreateOrUpdateTagDialogParams { - tag: Pick; + tag?: Pick; }