import * as appstate from '../appstate.js'; import * as shared from './shared/index.js'; import { css, cssManager, customElement, DeesElement, html, state, type TemplateResult, } from '@design.estate/dees-element'; @customElement('sg-view-admin') export class SgViewAdmin extends DeesElement { @state() accessor adminState: appstate.IAdminState = { providers: [], platformSettings: null }; @state() accessor editingProviderId: string | null = null; constructor() { super(); const sub = appstate.adminStatePart .select((s) => s) .subscribe((s) => { this.adminState = s; }); this.rxSubscriptions.push(sub); } public static styles = [ cssManager.defaultStyles, shared.viewHostCss, ]; async connectedCallback() { super.connectedCallback(); await appstate.adminStatePart.dispatchAction(appstate.fetchAdminProvidersAction, null); await appstate.adminStatePart.dispatchAction(appstate.fetchPlatformSettingsAction, null); } public render(): TemplateResult { if (this.editingProviderId !== null) { const provider = this.editingProviderId ? this.adminState.providers.find((p) => p.id === this.editingProviderId) || null : null; return html` `; } return html` `; } private async saveProvider(detail: any) { // TODO: implement create/update provider this.editingProviderId = null; } private async deleteProvider(providerId: string) { await appstate.adminStatePart.dispatchAction( appstate.deleteAdminProviderAction, { providerId }, ); } private async testProvider(providerId: string) { await appstate.adminStatePart.dispatchAction( appstate.testAdminProviderAction, { providerId }, ); } private async saveSettings(settings: any) { await appstate.adminStatePart.dispatchAction( appstate.updatePlatformSettingsAction, { auth: settings }, ); } }