Skip to content

Commit c00ae0a

Browse files
committed
42083 V14: Integrations (Shopify)
- Add modal, picker property editor for Shopify - update ts config file
1 parent 42a4f75 commit c00ae0a

File tree

5 files changed

+160
-2
lines changed

5 files changed

+160
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { ManifestModal } from "@umbraco-cms/backoffice/extension-registry";
2+
3+
export const manifest: ManifestModal = {
4+
type: "modal",
5+
alias: "Shopify.Modal",
6+
name: "Shopify Modal",
7+
js: () => import("./shopify-modal.element")
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { html, css, state, customElement } from "@umbraco-cms/backoffice/external/lit";
2+
import { UmbModalBaseElement } from "@umbraco-cms/backoffice/modal";
3+
import {
4+
UMB_NOTIFICATION_CONTEXT,
5+
} from "@umbraco-cms/backoffice/notification";
6+
import type { UUIInputEvent } from "@umbraco-cms/backoffice/external/uui";
7+
import type { ShopifyServiceStatus } from "../models/shopify-service.model.js";
8+
import type { ShopifyPickerModalData, ShopifyPickerModalValue } from "./shopify.modal-token.js";
9+
import type { ProductsListDtoModel } from "../generated";
10+
import { SHOPIFY_CONTEXT_TOKEN } from "../context/shopify.context.js";
11+
12+
const elementName = "shopify-modal";
13+
14+
export default class ShopifyModalElement extends UmbModalBaseElement<ShopifyPickerModalData, ShopifyPickerModalValue>{
15+
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { UmbModalToken } from "@umbraco-cms/backoffice/modal";
2+
import type { ProductDtoModel } from "../generated";
3+
4+
export type ShopifyPickerModalData = {
5+
headline: string;
6+
}
7+
8+
export type ShopifyPickerModalValue = {
9+
products: ProductDtoModel;
10+
}
11+
12+
export const SHOPIFY_MODAL_TOKEN = new UmbModalToken<ShopifyPickerModalData, ShopifyPickerModalValue>("Shopify.Modal", {
13+
modal: {
14+
type: "sidebar",
15+
size: "small"
16+
}
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
2+
import { LitElement, customElement, html, css, property, state } from "@umbraco-cms/backoffice/external/lit";
3+
import { UMB_MODAL_MANAGER_CONTEXT } from "@umbraco-cms/backoffice/modal";
4+
import {
5+
UMB_NOTIFICATION_CONTEXT,
6+
} from "@umbraco-cms/backoffice/notification";
7+
import { SHOPIFY_MODAL_TOKEN } from "../modal/shopify.modal-token";
8+
import { ConfigDescription, type ShopifyServiceStatus } from "../models/shopify-service.model";
9+
import { SHOPIFY_CONTEXT_TOKEN } from "../context/shopify.context";
10+
import type { ProductDtoModel } from "../generated/models";
11+
12+
const elementName = "shopify-picker";
13+
export class ShopifyPickerPropertyEditor extends UmbElementMixin(LitElement){
14+
#modalManagerContext?: typeof UMB_MODAL_MANAGER_CONTEXT.TYPE;
15+
#shopifyContext!: typeof SHOPIFY_CONTEXT_TOKEN.TYPE;
16+
17+
@property({ type: String })
18+
public value = "";
19+
20+
@state()
21+
private products: Array<ProductDtoModel> = [];
22+
23+
@state()
24+
private _serviceStatus: ShopifyServiceStatus = {
25+
isValid: false,
26+
type: "",
27+
description: "",
28+
useOAuth: false
29+
};
30+
31+
constructor() {
32+
super();
33+
this.consumeContext(UMB_MODAL_MANAGER_CONTEXT, (instance) => {
34+
this.#modalManagerContext = instance;
35+
});
36+
this.consumeContext(SHOPIFY_CONTEXT_TOKEN, (context) => {
37+
this.#shopifyContext = context;
38+
});
39+
}
40+
41+
async connectedCallback() {
42+
super.connectedCallback();
43+
44+
if (this.value == null || this.value.length == 0) return;
45+
46+
const { data } = await this.#shopifyContext.checkConfiguration();
47+
if (!data || !data.type?.value) return;
48+
49+
this._serviceStatus = {
50+
isValid: data.isValid,
51+
type: data.type.value,
52+
description: "",
53+
useOAuth: data.isValid && data.type.value === "OAuth"
54+
}
55+
56+
if (!this._serviceStatus.isValid) {
57+
this._showError(ConfigDescription.none);
58+
}
59+
60+
const dto: Array<ProductDtoModel> = JSON.parse(JSON.stringify(this.value));
61+
this.products = dto;
62+
}
63+
64+
private async _openModal() {
65+
const pickerContext = this.#modalManagerContext?.open(this, SHOPIFY_MODAL_TOKEN, {
66+
data: {
67+
headline: "HubSpot Forms",
68+
},
69+
});
70+
71+
const data = await pickerContext?.onSubmit();
72+
if (!data) return;
73+
74+
this.value = JSON.stringify(data.products);
75+
console.log(this.value);
76+
this.dispatchEvent(new CustomEvent('property-value-change'));
77+
}
78+
79+
private async _showError(message: string) {
80+
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
81+
notificationContext?.peek("danger", {
82+
data: { message: message },
83+
});
84+
}
85+
86+
render() {
87+
return html`
88+
${this.value == null || this.value.length == 0
89+
? html`
90+
<uui-button
91+
class="add-button"
92+
@click=${this._openModal}
93+
label=${this.localize.term('general_add')}
94+
look="placeholder"></uui-button>
95+
`
96+
: html`
97+
<div></div>
98+
`}
99+
`;
100+
}
101+
102+
static styles = [
103+
css`
104+
.add-button {
105+
width: 100%;
106+
}
107+
`];
108+
}
109+
110+
111+
export default ShopifyPickerPropertyEditor;
112+
113+
declare global {
114+
interface HTMLElementTagNameMap {
115+
[elementName]: ShopifyPickerPropertyEditor;
116+
}
117+
}

src/Umbraco.Cms.Integrations.Commerce.Shopify/Client/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
/* Linting */
1919
"strict": true,
20-
"noUnusedLocals": true,
21-
"noUnusedParameters": true,
20+
"noUnusedLocals": false,
21+
"noUnusedParameters": false,
2222
"noFallthroughCasesInSwitch": true
2323
},
2424
"include": ["src"]

0 commit comments

Comments
 (0)