mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 22:39:46 +00:00
* UI for EOS smtp, missing API layer * implement api * fix errors * switch to external smtp creds * fix things up * fix types * update types for new forms * feat: add new form to emails and marketplace (#2268) * import tuilet module * feat: get rid of old form completely (#2270) * move to builder spec and delete developer menu * update sdk * tiny * getting better * working * done * feat: add step to number config * chore: small fixes * update SDK and step for numbers --------- Co-authored-by: Alex Inkin <alexander@inkin.ru>
77 lines
2.3 KiB
TypeScript
77 lines
2.3 KiB
TypeScript
import { Component } from '@angular/core'
|
|
import { ApiService } from 'src/app/services/api/embassy-api.service'
|
|
import { ErrorService } from '@start9labs/shared'
|
|
import { PatchDB } from 'patch-db-client'
|
|
import { DataModel } from 'src/app/services/patch-db/data-model'
|
|
import { FormService } from 'src/app/services/form.service'
|
|
import { LoadingService } from '../../../modals/loading/loading.service'
|
|
import { TuiDialogService } from '@taiga-ui/core'
|
|
import { switchMap } from 'rxjs/operators'
|
|
import { InputSpec } from '@start9labs/start-sdk/lib/config/configTypes'
|
|
import { configBuilderToSpec } from 'src/app/util/configBuilderToSpec'
|
|
import { customSmtp } from '@start9labs/start-sdk/lib/config/configConstants'
|
|
import { UntypedFormGroup } from '@angular/forms'
|
|
|
|
@Component({
|
|
selector: 'email',
|
|
templateUrl: './email.page.html',
|
|
styleUrls: ['./email.page.scss'],
|
|
})
|
|
export class EmailPage {
|
|
spec: Promise<InputSpec> = configBuilderToSpec(customSmtp)
|
|
testAddress = ''
|
|
readonly form$ = this.patch
|
|
.watch$('server-info', 'smtp')
|
|
.pipe(
|
|
switchMap(async value =>
|
|
this.formService.createForm(await this.spec, value),
|
|
),
|
|
)
|
|
|
|
constructor(
|
|
private readonly dialogs: TuiDialogService,
|
|
private readonly loader: LoadingService,
|
|
private readonly errorService: ErrorService,
|
|
private readonly patch: PatchDB<DataModel>,
|
|
private readonly api: ApiService,
|
|
private readonly formService: FormService,
|
|
) {}
|
|
|
|
async save(value: unknown): Promise<void> {
|
|
const loader = this.loader.open('Saving...').subscribe()
|
|
|
|
try {
|
|
await this.api.configureEmail(customSmtp.validator.unsafeCast(value))
|
|
} catch (e: any) {
|
|
this.errorService.handleError(e)
|
|
} finally {
|
|
loader.unsubscribe()
|
|
}
|
|
}
|
|
|
|
async sendTestEmail(form: UntypedFormGroup) {
|
|
const loader = this.loader.open('Sending...').subscribe()
|
|
|
|
try {
|
|
await this.api.testEmail({
|
|
to: this.testAddress,
|
|
...form.value,
|
|
})
|
|
} catch (e: any) {
|
|
this.errorService.handleError(e)
|
|
} finally {
|
|
loader.unsubscribe()
|
|
}
|
|
|
|
this.dialogs
|
|
.open(
|
|
`A test email has been sent to ${this.testAddress}.<br /><br /><b>Check your spam folder and mark as not spam</b>`,
|
|
{
|
|
label: 'Success',
|
|
size: 's',
|
|
},
|
|
)
|
|
.subscribe()
|
|
}
|
|
}
|