@deenruv/copy-order-plugin 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +39 -0
  3. package/dist/plugin-server/constants.d.ts +1 -0
  4. package/dist/plugin-server/constants.js +4 -0
  5. package/dist/plugin-server/extensions/admin.extension.d.ts +1 -0
  6. package/dist/plugin-server/extensions/admin.extension.js +18 -0
  7. package/dist/plugin-server/index.d.ts +1 -0
  8. package/dist/plugin-server/index.js +17 -0
  9. package/dist/plugin-server/plugin.d.ts +5 -0
  10. package/dist/plugin-server/plugin.js +35 -0
  11. package/dist/plugin-server/resolvers/admin.resolver.d.ts +9 -0
  12. package/dist/plugin-server/resolvers/admin.resolver.js +40 -0
  13. package/dist/plugin-server/services/copy-order.service.d.ts +16 -0
  14. package/dist/plugin-server/services/copy-order.service.js +105 -0
  15. package/dist/plugin-server/types.d.ts +4 -0
  16. package/dist/plugin-server/types.js +2 -0
  17. package/dist/plugin-server/zeus/const.d.ts +6 -0
  18. package/dist/plugin-server/zeus/const.js +3621 -0
  19. package/dist/plugin-server/zeus/index.d.ts +18436 -0
  20. package/dist/plugin-server/zeus/index.js +1093 -0
  21. package/dist/plugin-server/zeus/typedDocumentNode.d.ts +3 -0
  22. package/dist/plugin-server/zeus/typedDocumentNode.js +16 -0
  23. package/dist/plugin-ui/components/CopyOrderButton.d.ts +2 -0
  24. package/dist/plugin-ui/components/CopyOrderButton.js +40 -0
  25. package/dist/plugin-ui/constants.d.ts +1 -0
  26. package/dist/plugin-ui/constants.js +1 -0
  27. package/dist/plugin-ui/graphql/mutations.d.ts +11 -0
  28. package/dist/plugin-ui/graphql/mutations.js +13 -0
  29. package/dist/plugin-ui/index.d.ts +4 -0
  30. package/dist/plugin-ui/index.js +16 -0
  31. package/dist/plugin-ui/locales/en/index.d.ts +6 -0
  32. package/dist/plugin-ui/locales/en/index.js +2 -0
  33. package/dist/plugin-ui/locales/en/test.json +5 -0
  34. package/dist/plugin-ui/locales/pl/index.d.ts +6 -0
  35. package/dist/plugin-ui/locales/pl/index.js +2 -0
  36. package/dist/plugin-ui/locales/pl/test.json +5 -0
  37. package/dist/plugin-ui/tsconfig.json +18 -0
  38. package/dist/plugin-ui/zeus/const.d.ts +6 -0
  39. package/dist/plugin-ui/zeus/const.js +3618 -0
  40. package/dist/plugin-ui/zeus/index.d.ts +18436 -0
  41. package/dist/plugin-ui/zeus/index.js +1085 -0
  42. package/dist/plugin-ui/zeus/typedDocumentNode.d.ts +3 -0
  43. package/dist/plugin-ui/zeus/typedDocumentNode.js +9 -0
  44. package/package.json +50 -0
@@ -0,0 +1,3 @@
1
+ import { TypedDocumentNode } from '@graphql-typed-document-node/core';
2
+ import { ValueTypes, GenericOperation, OperationOptions, GraphQLTypes, InputType, ScalarDefinition, ThunderGraphQLOptions, ExtractVariables } from './';
3
+ export declare const typedGql: <O extends "query" | "mutation", SCLR extends ScalarDefinition, R extends keyof ValueTypes = GenericOperation<O>>(operation: O, graphqlOptions?: ThunderGraphQLOptions<SCLR> | undefined) => <Z extends ValueTypes[R]>(o: Z & { [P in keyof Z]: P extends keyof ValueTypes[R] ? Z[P] : never; }, ops?: OperationOptions) => TypedDocumentNode<InputType<GraphQLTypes[R], Z, SCLR>, ExtractVariables<Z>>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.typedGql = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const _1 = require("./");
9
+ const typedGql = (operation, graphqlOptions) => (o, ops) => {
10
+ const str = (0, _1.Zeus)(operation, o, {
11
+ operationOptions: ops,
12
+ scalars: graphqlOptions === null || graphqlOptions === void 0 ? void 0 : graphqlOptions.scalars,
13
+ });
14
+ return (0, graphql_tag_1.default)(str);
15
+ };
16
+ exports.typedGql = typedGql;
@@ -0,0 +1,2 @@
1
+ import React from "react";
2
+ export declare const CopyOrderButton: () => React.JSX.Element | null;
@@ -0,0 +1,40 @@
1
+ import React from "react";
2
+ import { useNavigate } from "react-router-dom";
3
+ import { toast } from "sonner";
4
+ import { Button, DropdownMenuItem, ORDER_STATE, Routes, useMutation, useOrder, usePluginStore, useTranslation, } from "@deenruv/react-ui-devkit";
5
+ import { COPY_ORDER } from "../graphql/mutations.js";
6
+ import { PLUGIN_NAME } from "../constants.js";
7
+ const DEFAULT_NOT_ALLOWED = [
8
+ ORDER_STATE.ADDING_ITEMS,
9
+ ORDER_STATE.ARRANGING_PAYMENT,
10
+ ];
11
+ export const CopyOrderButton = () => {
12
+ const { order } = useOrder();
13
+ const { t } = useTranslation("copy-order-plugin");
14
+ const [mutate] = useMutation(COPY_ORDER);
15
+ const navigate = useNavigate();
16
+ const { configs } = usePluginStore();
17
+ const NOT_ALLOWED = configs.get(PLUGIN_NAME)?.notAllowedStates || DEFAULT_NOT_ALLOWED;
18
+ const copyOrder = async () => {
19
+ if (!order)
20
+ return;
21
+ try {
22
+ const result = await mutate({ id: order.id });
23
+ if (result?.copyOrder.__typename === "Order") {
24
+ toast.success(t("copy-order-success"));
25
+ navigate(Routes.orders.to(result.copyOrder.id));
26
+ }
27
+ else {
28
+ toast.error(result?.copyOrder.message);
29
+ }
30
+ }
31
+ catch (error) {
32
+ const errorMessage = error instanceof Error ? error.message : t("copy-order-error");
33
+ toast.error(errorMessage);
34
+ }
35
+ };
36
+ if (!order || NOT_ALLOWED.includes(order.state))
37
+ return null;
38
+ return (React.createElement(DropdownMenuItem, { asChild: true },
39
+ React.createElement(Button, { onClick: copyOrder, variant: "ghost", className: "w-full cursor-pointer justify-start px-4 py-2 text-blue-600 focus-visible:ring-transparent dark:focus-visible:ring-transparent" }, t("copy-order"))));
40
+ };
@@ -0,0 +1 @@
1
+ export declare const PLUGIN_NAME = "Copy Order Plugin";
@@ -0,0 +1 @@
1
+ export const PLUGIN_NAME = "Copy Order Plugin";
@@ -0,0 +1,11 @@
1
+ export declare const COPY_ORDER: import("@graphql-typed-document-node/core").TypedDocumentNode<{
2
+ copyOrder: ({
3
+ __typename: "Order";
4
+ id: string;
5
+ } | {
6
+ __typename: "CopyOrderErrorResponse";
7
+ message: string;
8
+ }) & {};
9
+ }, {} & {
10
+ id: {};
11
+ }>;
@@ -0,0 +1,13 @@
1
+ import { scalars } from "@deenruv/admin-types";
2
+ import { typedGql } from "../zeus/typedDocumentNode.js";
3
+ import { $ } from "../zeus/index.js";
4
+ export const COPY_ORDER = typedGql("mutation", { scalars })({
5
+ copyOrder: [
6
+ { id: $("id", "ID!") },
7
+ {
8
+ __typename: true,
9
+ "...on Order": { id: true },
10
+ "...on CopyOrderErrorResponse": { message: true },
11
+ },
12
+ ],
13
+ });
@@ -0,0 +1,4 @@
1
+ import { ORDER_STATE } from "@deenruv/react-ui-devkit";
2
+ export declare const UIPlugin: import("@deenruv/react-ui-devkit").DeenruvUIPlugin<{
3
+ notAllowedStates: ORDER_STATE[];
4
+ }>;
@@ -0,0 +1,16 @@
1
+ import { createDeenruvUIPlugin, ORDER_STATE } from "@deenruv/react-ui-devkit";
2
+ import pl from "./locales/pl";
3
+ import en from "./locales/en";
4
+ import { CopyOrderButton } from "./components/CopyOrderButton.js";
5
+ import { PLUGIN_NAME } from "./constants.js";
6
+ export const UIPlugin = createDeenruvUIPlugin({
7
+ version: "1.0.0",
8
+ name: PLUGIN_NAME,
9
+ config: {
10
+ notAllowedStates: [ORDER_STATE.ADDING_ITEMS, ORDER_STATE.ARRANGING_PAYMENT],
11
+ },
12
+ translations: { ns: "copy-order-plugin", data: { en, pl } },
13
+ actions: {
14
+ dropdown: [{ id: "orders-detail-view", component: CopyOrderButton }],
15
+ },
16
+ });
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ "copy-order": string;
3
+ "copy-order-error": string;
4
+ "copy-order-success": string;
5
+ }[];
6
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import test from "./test.json";
2
+ export default [test];
@@ -0,0 +1,5 @@
1
+ {
2
+ "copy-order": "Copy order",
3
+ "copy-order-error": "Error copying order",
4
+ "copy-order-success": "Order copied successfully"
5
+ }
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ "copy-order": string;
3
+ "copy-order-error": string;
4
+ "copy-order-success": string;
5
+ }[];
6
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import test from "./test.json";
2
+ export default [test];
@@ -0,0 +1,5 @@
1
+ {
2
+ "copy-order": "Skopiuj zamówienie",
3
+ "copy-order-error": "Błąd kopiowania zamówienia",
4
+ "copy-order-success": "Zamówienie zostało skopiowane pomyślnie"
5
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "ESNext",
4
+ "moduleResolution": "node",
5
+ "target": "ES2020",
6
+ "jsx": "react",
7
+ "outDir": "../../dist/plugin-ui",
8
+ "importHelpers": true,
9
+ "declaration": true,
10
+ "resolveJsonModule": true,
11
+ "skipLibCheck": true,
12
+ "strict": true,
13
+ "noImplicitAny": true,
14
+ "esModuleInterop": true,
15
+ "allowSyntheticDefaultImports": true
16
+ },
17
+ "include": ["./**/*.tsx", "./**/*.json", "./**/*.ts"]
18
+ }
@@ -0,0 +1,6 @@
1
+ export declare const AllTypesProps: Record<string, any>;
2
+ export declare const ReturnTypes: Record<string, any>;
3
+ export declare const Ops: {
4
+ query: "Query";
5
+ mutation: "Mutation";
6
+ };