Files
start-os/web/projects/ui/src/app/services/form-dialog.service.ts
Matt Hill f76e822381 port 040 config (#2657)
* port 040 config, WIP

* update fixtures

* use taiga modal for backups too

* fix: update Taiga UI and refactor everything to work

* chore: package-lock

* fix interfaces and mocks for interfaces

* better mocks

* function to transform old spec to new

* delete unused fns

* delete unused FE config utils

* fix exports from sdk

* reorganize exports

* functions to translate config

* rename unionSelectKey and unionValueKey

* Adding in the transformation of the getConfig to the new types.

* chore: add Taiga UI to preloader

---------

Co-authored-by: waterplea <alexander@inkin.ru>
Co-authored-by: Aiden McClelland <me@drbonez.dev>
Co-authored-by: J H <dragondef@gmail.com>
2024-07-10 17:58:02 +00:00

42 lines
1.3 KiB
TypeScript

import { inject, Injectable, Injector, Type } from '@angular/core'
import { TuiDialogOptions, TuiDialogService } from '@taiga-ui/core'
import { TuiDialogFormService, TuiPromptData } from '@taiga-ui/kit'
import { PolymorpheusComponent } from '@tinkoff/ng-polymorpheus'
const PROMPT: Partial<TuiDialogOptions<TuiPromptData>> = {
label: 'Unsaved Changes',
data: {
content: 'You have unsaved changes. Are you sure you want to leave?',
yes: 'Leave',
no: 'Cancel',
},
}
@Injectable({ providedIn: 'root' })
export class FormDialogService {
private readonly dialogs = inject(TuiDialogService)
private readonly formService = new TuiDialogFormService(this.dialogs)
private readonly prompt = this.formService.withPrompt(PROMPT)
private readonly injector = Injector.create({
parent: inject(Injector),
providers: [
{
provide: TuiDialogFormService,
useValue: this.formService,
},
],
})
open<T>(component: Type<any>, options: Partial<TuiDialogOptions<T>> = {}) {
this.dialogs
.open(new PolymorpheusComponent(component, this.injector), {
closeable: this.prompt,
dismissible: this.prompt,
...options,
})
.subscribe({
complete: () => this.formService.markAsPristine(),
})
}
}