|
1 | 1 | import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
|
2 |
| -import { css, html, nothing, customElement, state, query, property } from '@umbraco-cms/backoffice/external/lit'; |
| 2 | +import { css, html, nothing, customElement, state } from '@umbraco-cms/backoffice/external/lit'; |
| 3 | +import { ZAPIER_CONTEXT_TOKEN } from '../context/zapier.context'; |
| 4 | +import { GetAllResponse, SubscriptionDtoModel } from '@umbraco-integrations/zapier/generated'; |
| 5 | +import type { UmbTableColumn, UmbTableItem } from '@umbraco-cms/backoffice/components'; |
| 6 | +import { UUIPaginationEvent } from '@umbraco-cms/backoffice/external/uui'; |
| 7 | +import { UmbPaginationManager } from "@umbraco-cms/backoffice/utils"; |
3 | 8 |
|
4 | 9 | const elementName = "zapier-management-dashboard";
|
5 | 10 | @customElement(elementName)
|
6 | 11 | export class ZapierManagementDashboardElement extends UmbLitElement {
|
| 12 | + #zapierContext?: typeof ZAPIER_CONTEXT_TOKEN.TYPE; |
| 13 | + #paginationManager = new UmbPaginationManager(); |
| 14 | + #itemList: GetAllResponse | undefined; |
| 15 | + #isFormsExtensionInstalled: boolean | undefined = false; |
| 16 | + |
| 17 | + @state() |
| 18 | + private _tableItems: Array<UmbTableItem> = []; |
| 19 | + |
| 20 | + @state() |
| 21 | + _currentPageNumber = 1; |
| 22 | + |
| 23 | + @state() |
| 24 | + _totalPages = 1; |
| 25 | + |
| 26 | + @state() |
| 27 | + _nextPageInfo?: string; |
| 28 | + |
| 29 | + @state() |
| 30 | + _previousPageInfo?: string; |
| 31 | + |
| 32 | + @state() |
| 33 | + private _tableColumns: Array<UmbTableColumn> = [ |
| 34 | + { |
| 35 | + name: 'Identifer', |
| 36 | + alias: 'identifer' |
| 37 | + }, |
| 38 | + { |
| 39 | + name: 'Entity Type', |
| 40 | + alias: 'entityType', |
| 41 | + }, |
| 42 | + { |
| 43 | + name: 'Hook URL', |
| 44 | + alias: 'hookUrl' |
| 45 | + } |
| 46 | + ]; |
| 47 | + |
| 48 | + constructor() { |
| 49 | + super(); |
| 50 | + this.consumeContext(ZAPIER_CONTEXT_TOKEN, (instance) => { |
| 51 | + this.#zapierContext = instance; |
| 52 | + }); |
| 53 | + } |
| 54 | + |
| 55 | + async connectedCallback(){ |
| 56 | + super.connectedCallback(); |
| 57 | + |
| 58 | + await this.getAll(); |
| 59 | + await this.checkFormsExtension(); |
| 60 | + } |
| 61 | + |
| 62 | + async getAll(){ |
| 63 | + debugger; |
| 64 | + const data = await this.#zapierContext?.getAll(); |
| 65 | + if (!data) return; |
| 66 | + |
| 67 | + this.#itemList = data.data; |
| 68 | + |
| 69 | + const lst : Array<SubscriptionDtoModel> = [{ |
| 70 | + entityId: "docType1", |
| 71 | + typeName: "Content", |
| 72 | + hookUrl: "wwww.google.com", |
| 73 | + id: 1, |
| 74 | + subscribeHook: true, |
| 75 | + type: 1 |
| 76 | + }, { |
| 77 | + entityId: "docType1", |
| 78 | + typeName: "Content", |
| 79 | + hookUrl: "wwww.google.com", |
| 80 | + id: 1, |
| 81 | + subscribeHook: true, |
| 82 | + type: 1 |
| 83 | + }, { |
| 84 | + entityId: "docType1", |
| 85 | + typeName: "Content", |
| 86 | + hookUrl: "wwww.google.com", |
| 87 | + id: 1, |
| 88 | + subscribeHook: true, |
| 89 | + type: 1 |
| 90 | + }]; |
| 91 | + |
| 92 | + this.#createTableItems(lst); |
| 93 | + } |
| 94 | + |
| 95 | + async checkFormsExtension(){ |
| 96 | + const data = await this.#zapierContext?.isFormsExtensionInstalled(); |
| 97 | + if (!data) return; |
| 98 | + |
| 99 | + this.#isFormsExtensionInstalled = data.data; |
| 100 | + } |
| 101 | + |
| 102 | + #createTableItems(products: Array<SubscriptionDtoModel>) { |
| 103 | + this._tableItems = products.map((product) => { |
| 104 | + return { |
| 105 | + id: product.id.toString(), |
| 106 | + data: [{ |
| 107 | + columnAlias: "identifer", |
| 108 | + value: product.entityId, |
| 109 | + }, |
| 110 | + { |
| 111 | + columnAlias: "entityType", |
| 112 | + value: product.type, |
| 113 | + }, |
| 114 | + { |
| 115 | + columnAlias: "hookUrl", |
| 116 | + value: product.hookUrl, |
| 117 | + } |
| 118 | + ] |
| 119 | + } |
| 120 | + }); |
| 121 | + } |
| 122 | + |
7 | 123 | override render() {
|
8 | 124 | return html`
|
9 |
| - <div>This is new Zapier dashboard</div> |
| 125 | + <div class="zapier-content"> |
| 126 | + <umb-body-layout> |
| 127 | + <uui-box headline="Content Properties"> |
| 128 | + <p> |
| 129 | + <a href="https://zapier.com/">Zapier</a> is an online platform that helps you automate workflows by connecting your apps and services you use. |
| 130 | + This allows you to automate tasks without having to build this integration yourself. |
| 131 | + When an event happens in one app, Zapier can tell another app to perform (or do) a particular action - no code necessary. |
| 132 | + </p> |
| 133 | + <p> |
| 134 | + The heart of any automation boils down to this simple command: <b>WHEN</b> <span>this happens</span> <b>THEN</b> <span>do that</span>. |
| 135 | + </p> |
| 136 | + <p> |
| 137 | + A Zap is an automated workflow that tells your apps to follow this simple command: "When this happens, do that." |
| 138 | + Every Zap has a trigger and one or more actions. A trigger is an event that starts a Zap, and an action is what your Zap does for you. |
| 139 | + </p> |
| 140 | + <p> |
| 141 | + Zap triggers use webhooks to execute the actions. Webhooks are automated messages sent from apps when something happens. |
| 142 | + </p> |
| 143 | + ${!this.#isFormsExtensionInstalled ? html` |
| 144 | + <p> |
| 145 | + You can initiate your automation when a content item of a particular document type is published in Umbraco. |
| 146 | + </p> |
| 147 | + ` : html` |
| 148 | + <p> |
| 149 | + You can initiate your automation when a content item of a particular document type is published or a form is submitted in Umbraco. |
| 150 | + </p> |
| 151 | + ` |
| 152 | + } |
| 153 | + <p> |
| 154 | + The integration uses Zapier subscription hook triggers, allowing Zapier to set up and remove hook subscriptions when Zaps are created or removed on the platform. |
| 155 | + </p> |
| 156 | + </uui-box> |
| 157 | + </umb-body-layout> |
| 158 | + </div> |
| 159 | +
|
| 160 | + <div> |
| 161 | + <umb-body-layout> |
| 162 | + <uui-box headline="Registed Subscription Hooks"> |
| 163 | + <umb-table |
| 164 | + .columns=${this._tableColumns} |
| 165 | + .items=${this._tableItems}> |
| 166 | + </umb-table> |
| 167 | + ${this.#renderPagination()} |
| 168 | + </uui-box> |
| 169 | + </umb-body-layout> |
| 170 | + </div> |
10 | 171 | `;
|
11 | 172 | }
|
| 173 | + |
| 174 | + #renderPagination() { |
| 175 | + return html` |
| 176 | + ${this._totalPages > 1 |
| 177 | + ? html` |
| 178 | + <div class="shopify-pagination"> |
| 179 | + <uui-pagination |
| 180 | + class="pagination" |
| 181 | + .current=${this._currentPageNumber} |
| 182 | + .total=${this._totalPages} |
| 183 | + @change=${this.#onPageChange}></uui-pagination> |
| 184 | + </div> |
| 185 | + ` |
| 186 | + : nothing} |
| 187 | + `; |
| 188 | + } |
| 189 | + |
| 190 | + #onPageChange(event: UUIPaginationEvent) { |
| 191 | + const forward = event.target?.current > this._currentPageNumber; |
| 192 | + |
| 193 | + const currentPageNumber = forward ? this._currentPageNumber + 1 : this._currentPageNumber - 1 |
| 194 | + |
| 195 | + this.#paginationManager.setCurrentPageNumber(currentPageNumber); |
| 196 | + |
| 197 | + this._currentPageNumber = currentPageNumber; |
| 198 | + } |
| 199 | + |
| 200 | + static styles = [css` |
| 201 | + .zapier-content p:first-child { |
| 202 | + margin-top: 0 !important; |
| 203 | + } |
| 204 | + `]; |
12 | 205 | }
|
13 | 206 |
|
14 | 207 | export default ZapierManagementDashboardElement;
|
|
0 commit comments