first version

This commit is contained in:
Gerhard Scheikl
2026-04-28 21:56:11 +02:00
parent 0f75dbaccb
commit 5b2aa5d62b
50 changed files with 5514 additions and 481 deletions
@@ -0,0 +1,5 @@
{
"admin.order-details.action.render": {
"main": "dist/invoice-action.js"
}
}
@@ -0,0 +1,10 @@
{
"name": "invoice-order-action",
"version": "1.0.0",
"private": true,
"devDependencies": {
"@shopify/ui-extensions": "^2026.1.0",
"preact": "^10.22.0",
"typescript": "^5.6.0"
}
}
+7
View File
@@ -0,0 +1,7 @@
import '@shopify/ui-extensions';
//@ts-ignore
declare module './src/ActionExtension.tsx' {
const shopify: import('@shopify/ui-extensions/admin.order-details.action.render').Api;
const globalThis: { shopify: typeof shopify };
}
@@ -0,0 +1,11 @@
api_version = "2026-01"
[[extensions]]
name = "Generate invoice"
handle = "invoice-action"
type = "ui_extension"
uid = "linumiq-invoice-order-action"
[[extensions.targeting]]
target = "admin.order-details.action.render"
module = "./src/ActionExtension.tsx"
@@ -0,0 +1,55 @@
import { render } from "preact";
import { useState } from "preact/hooks";
export default async () => {
render(<Extension />, document.body);
};
function Extension() {
const { close, data } = (globalThis as any).shopify;
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const orderGid: string | undefined = data?.selected?.[0]?.id;
const orderId = orderGid ? orderGid.split("/").pop() : undefined;
async function trigger(action: "generate" | "cancel_reissue") {
if (!orderId) {
setError("No order selected");
return;
}
setBusy(true);
setError(null);
try {
const body = new URLSearchParams({ action });
const res = await fetch(`/api/orders/${orderId}/invoice`, {
method: "POST",
body,
});
if (!res.ok) {
const txt = await res.text();
throw new Error(`HTTP ${res.status}: ${txt.slice(0, 200)}`);
}
close();
} catch (e: any) {
setError(e?.message ?? "Failed");
} finally {
setBusy(false);
}
}
return (
<s-admin-action heading="Generate invoice" loading={busy}>
<s-stack gap="200">
<s-text>Create or regenerate the PDF invoice for this order. The file will be uploaded to Shopify Files and linked via order metafields.</s-text>
{error ? <s-banner tone="critical">{error}</s-banner> : null}
</s-stack>
<s-button slot="primary-action" onClick={() => trigger("generate")} disabled={busy}>
Generate / regenerate
</s-button>
<s-button slot="secondary-actions" tone="critical" onClick={() => trigger("cancel_reissue")} disabled={busy}>
Cancel &amp; reissue
</s-button>
</s-admin-action>
);
}
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"jsx": "react-jsx",
"jsxImportSource": "preact",
"strict": true,
"skipLibCheck": true,
"isolatedModules": true,
"noEmit": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"include": ["src/**/*"]
}