Browse Source

fix(client): make tag as optional to cover tag creation use case

pull/6893/head
KenTandrian 1 week ago
parent
commit
6a79070c02
  1. 13
      apps/client/src/app/components/admin-tag/admin-tag.component.ts
  2. 4
      apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts
  3. 2
      apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html
  4. 2
      apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/interfaces/interfaces.ts

13
apps/client/src/app/components/admin-tag/admin-tag.component.ts

@ -83,7 +83,9 @@ export class GfAdminTagComponent implements OnInit {
return id === params['tagId']; return id === params['tagId'];
}); });
this.openUpdateTagDialog(tag); if (tag) {
this.openUpdateTagDialog(tag);
}
} else { } else {
this.router.navigate(['.'], { relativeTo: this.route }); this.router.navigate(['.'], { relativeTo: this.route });
} }
@ -153,12 +155,7 @@ export class GfAdminTagComponent implements OnInit {
GfCreateOrUpdateTagDialogComponent, GfCreateOrUpdateTagDialogComponent,
CreateOrUpdateTagDialogParams CreateOrUpdateTagDialogParams
>(GfCreateOrUpdateTagDialogComponent, { >(GfCreateOrUpdateTagDialogComponent, {
data: { data: {} satisfies CreateOrUpdateTagDialogParams,
tag: {
id: null,
name: null
}
},
height: this.deviceType === 'mobile' ? '98vh' : undefined, height: this.deviceType === 'mobile' ? '98vh' : undefined,
width: this.deviceType === 'mobile' ? '100vw' : '50rem' width: this.deviceType === 'mobile' ? '100vw' : '50rem'
}); });
@ -197,7 +194,7 @@ export class GfAdminTagComponent implements OnInit {
id, id,
name name
} }
}, } satisfies CreateOrUpdateTagDialogParams,
height: this.deviceType === 'mobile' ? '98vh' : undefined, height: this.deviceType === 'mobile' ? '98vh' : undefined,
width: this.deviceType === 'mobile' ? '100vw' : '50rem' width: this.deviceType === 'mobile' ? '100vw' : '50rem'
}); });

4
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 private formBuilder: FormBuilder
) { ) {
this.tagForm = this.formBuilder.group({ 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 name: this.tagForm.get('name')?.value
}; };
if (this.data.tag.id) { if (this.data.tag?.id) {
(tag as UpdateTagDto).id = this.data.tag.id; (tag as UpdateTagDto).id = this.data.tag.id;
await validateObjectForForm({ await validateObjectForForm({
classDto: UpdateTagDto, classDto: UpdateTagDto,

2
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()" (keyup.enter)="tagForm.valid && onSubmit()"
(ngSubmit)="onSubmit()" (ngSubmit)="onSubmit()"
> >
@if (data.tag.id) { @if (data.tag?.id) {
<h1 i18n mat-dialog-title>Update tag</h1> <h1 i18n mat-dialog-title>Update tag</h1>
} @else { } @else {
<h1 i18n mat-dialog-title>Add tag</h1> <h1 i18n mat-dialog-title>Add tag</h1>

2
apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/interfaces/interfaces.ts

@ -1,5 +1,5 @@
import { Tag } from '@prisma/client'; import { Tag } from '@prisma/client';
export interface CreateOrUpdateTagDialogParams { export interface CreateOrUpdateTagDialogParams {
tag: Pick<Tag, 'id' | 'name'>; tag?: Pick<Tag, 'id' | 'name'>;
} }

Loading…
Cancel
Save