@webiny/app-scheduler 6.1.0-beta.3 → 6.2.0-beta.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.
@@ -0,0 +1,26 @@
1
+ import type { ScheduleActionType, SchedulerEntry } from "../../../types.js";
2
+ export interface IScheduleDialogPresenterViewModel {
3
+ loading: boolean;
4
+ entry: SchedulerEntry | null;
5
+ }
6
+ export interface IScheduleDialogPresenterLoadParams {
7
+ namespace: string;
8
+ id: string;
9
+ }
10
+ export interface IScheduleDialogPresenterScheduleParams {
11
+ targetId: string;
12
+ namespace: string;
13
+ scheduleOn: Date;
14
+ actionType: ScheduleActionType;
15
+ }
16
+ export interface IScheduleDialogPresenterCancelParams {
17
+ id: string;
18
+ namespace: string;
19
+ }
20
+ export interface IScheduleDialogPresenter {
21
+ get vm(): IScheduleDialogPresenterViewModel;
22
+ load(params: IScheduleDialogPresenterLoadParams): Promise<void>;
23
+ schedule(params: IScheduleDialogPresenterScheduleParams): Promise<void>;
24
+ cancel(params: IScheduleDialogPresenterCancelParams): Promise<void>;
25
+ reset(): void;
26
+ }
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=IScheduleDialogPresenter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["IScheduleDialogPresenter.ts"],"sourcesContent":["import type { ScheduleActionType, SchedulerEntry } from \"~/types.js\";\n\nexport interface IScheduleDialogPresenterViewModel {\n loading: boolean;\n entry: SchedulerEntry | null;\n}\n\nexport interface IScheduleDialogPresenterLoadParams {\n namespace: string;\n id: string;\n}\n\nexport interface IScheduleDialogPresenterScheduleParams {\n targetId: string;\n namespace: string;\n scheduleOn: Date;\n actionType: ScheduleActionType;\n}\n\nexport interface IScheduleDialogPresenterCancelParams {\n id: string;\n namespace: string;\n}\n\nexport interface IScheduleDialogPresenter {\n get vm(): IScheduleDialogPresenterViewModel;\n load(params: IScheduleDialogPresenterLoadParams): Promise<void>;\n schedule(params: IScheduleDialogPresenterScheduleParams): Promise<void>;\n cancel(params: IScheduleDialogPresenterCancelParams): Promise<void>;\n reset(): void;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,22 @@
1
+ import type { ICancelScheduledActionGateway, IGetScheduledActionGateway, ISchedulePublishActionGateway, IScheduleUnpublishActionGateway } from "../../../Gateways/index.js";
2
+ import type { IScheduleDialogPresenter, IScheduleDialogPresenterCancelParams, IScheduleDialogPresenterLoadParams, IScheduleDialogPresenterScheduleParams, IScheduleDialogPresenterViewModel } from "./IScheduleDialogPresenter.js";
3
+ export interface IScheduleDialogPresenterParams {
4
+ getGateway: IGetScheduledActionGateway;
5
+ cancelGateway: ICancelScheduledActionGateway;
6
+ publishGateway: ISchedulePublishActionGateway;
7
+ unpublishGateway: IScheduleUnpublishActionGateway;
8
+ }
9
+ export declare class ScheduleDialogPresenter implements IScheduleDialogPresenter {
10
+ private loading;
11
+ private entry;
12
+ private readonly getGateway;
13
+ private readonly cancelGateway;
14
+ private readonly publishGateway;
15
+ private readonly unpublishGateway;
16
+ constructor(params: IScheduleDialogPresenterParams);
17
+ get vm(): IScheduleDialogPresenterViewModel;
18
+ load(params: IScheduleDialogPresenterLoadParams): Promise<void>;
19
+ schedule(params: IScheduleDialogPresenterScheduleParams): Promise<void>;
20
+ cancel(params: IScheduleDialogPresenterCancelParams): Promise<void>;
21
+ reset(): void;
22
+ }
@@ -0,0 +1,90 @@
1
+ import { makeAutoObservable, runInAction } from "mobx";
2
+ import { ScheduleActionType } from "../../../types.js";
3
+ export class ScheduleDialogPresenter {
4
+ loading = false;
5
+ entry = null;
6
+ constructor(params) {
7
+ this.getGateway = params.getGateway;
8
+ this.cancelGateway = params.cancelGateway;
9
+ this.publishGateway = params.publishGateway;
10
+ this.unpublishGateway = params.unpublishGateway;
11
+ makeAutoObservable(this);
12
+ }
13
+ get vm() {
14
+ return {
15
+ loading: this.loading,
16
+ entry: this.entry
17
+ };
18
+ }
19
+ async load(params) {
20
+ this.loading = true;
21
+ try {
22
+ const entry = await this.getGateway.execute(params);
23
+ runInAction(() => {
24
+ this.entry = entry;
25
+ this.loading = false;
26
+ });
27
+ } catch {
28
+ runInAction(() => {
29
+ this.loading = false;
30
+ });
31
+ }
32
+ }
33
+ async schedule(params) {
34
+ const {
35
+ targetId,
36
+ namespace,
37
+ scheduleOn,
38
+ actionType
39
+ } = params;
40
+ this.loading = true;
41
+ try {
42
+ switch (actionType) {
43
+ case ScheduleActionType.publish:
44
+ await this.publishGateway.execute({
45
+ namespace,
46
+ targetId,
47
+ scheduleOn
48
+ });
49
+ break;
50
+ case ScheduleActionType.unpublish:
51
+ await this.unpublishGateway.execute({
52
+ namespace,
53
+ targetId,
54
+ scheduleOn
55
+ });
56
+ break;
57
+ default:
58
+ throw new Error(`Unsupported action type "${actionType}".`);
59
+ }
60
+ runInAction(() => {
61
+ this.entry = null;
62
+ this.loading = false;
63
+ });
64
+ } catch {
65
+ runInAction(() => {
66
+ this.loading = false;
67
+ });
68
+ }
69
+ }
70
+ async cancel(params) {
71
+ this.loading = true;
72
+ try {
73
+ await this.cancelGateway.execute(params);
74
+ runInAction(() => {
75
+ this.entry = null;
76
+ this.loading = false;
77
+ });
78
+ } catch {
79
+ runInAction(() => {
80
+ this.loading = false;
81
+ });
82
+ }
83
+ }
84
+ reset() {
85
+ this.entry = null;
86
+ this.loading = false;
87
+ }
88
+ }
89
+
90
+ //# sourceMappingURL=ScheduleDialogPresenter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["makeAutoObservable","runInAction","ScheduleActionType","ScheduleDialogPresenter","loading","entry","constructor","params","getGateway","cancelGateway","publishGateway","unpublishGateway","vm","load","execute","schedule","targetId","namespace","scheduleOn","actionType","publish","unpublish","Error","cancel","reset"],"sources":["ScheduleDialogPresenter.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from \"mobx\";\nimport { ScheduleActionType } from \"~/types.js\";\nimport type { SchedulerEntry } from \"~/types.js\";\nimport type {\n ICancelScheduledActionGateway,\n IGetScheduledActionGateway,\n ISchedulePublishActionGateway,\n IScheduleUnpublishActionGateway\n} from \"~/Gateways/index.js\";\nimport type {\n IScheduleDialogPresenter,\n IScheduleDialogPresenterCancelParams,\n IScheduleDialogPresenterLoadParams,\n IScheduleDialogPresenterScheduleParams,\n IScheduleDialogPresenterViewModel\n} from \"./IScheduleDialogPresenter.js\";\n\nexport interface IScheduleDialogPresenterParams {\n getGateway: IGetScheduledActionGateway;\n cancelGateway: ICancelScheduledActionGateway;\n publishGateway: ISchedulePublishActionGateway;\n unpublishGateway: IScheduleUnpublishActionGateway;\n}\n\nexport class ScheduleDialogPresenter implements IScheduleDialogPresenter {\n private loading = false;\n private entry: SchedulerEntry | null = null;\n\n private readonly getGateway: IGetScheduledActionGateway;\n private readonly cancelGateway: ICancelScheduledActionGateway;\n private readonly publishGateway: ISchedulePublishActionGateway;\n private readonly unpublishGateway: IScheduleUnpublishActionGateway;\n\n public constructor(params: IScheduleDialogPresenterParams) {\n this.getGateway = params.getGateway;\n this.cancelGateway = params.cancelGateway;\n this.publishGateway = params.publishGateway;\n this.unpublishGateway = params.unpublishGateway;\n makeAutoObservable(this);\n }\n\n public get vm(): IScheduleDialogPresenterViewModel {\n return {\n loading: this.loading,\n entry: this.entry\n };\n }\n\n public async load(params: IScheduleDialogPresenterLoadParams): Promise<void> {\n this.loading = true;\n\n try {\n const entry = await this.getGateway.execute(params);\n runInAction(() => {\n this.entry = entry;\n this.loading = false;\n });\n } catch {\n runInAction(() => {\n this.loading = false;\n });\n }\n }\n\n public async schedule(params: IScheduleDialogPresenterScheduleParams): Promise<void> {\n const { targetId, namespace, scheduleOn, actionType } = params;\n this.loading = true;\n\n try {\n switch (actionType) {\n case ScheduleActionType.publish:\n await this.publishGateway.execute({ namespace, targetId, scheduleOn });\n break;\n case ScheduleActionType.unpublish:\n await this.unpublishGateway.execute({ namespace, targetId, scheduleOn });\n break;\n default:\n throw new Error(`Unsupported action type \"${actionType}\".`);\n }\n runInAction(() => {\n this.entry = null;\n this.loading = false;\n });\n } catch {\n runInAction(() => {\n this.loading = false;\n });\n }\n }\n\n public async cancel(params: IScheduleDialogPresenterCancelParams): Promise<void> {\n this.loading = true;\n\n try {\n await this.cancelGateway.execute(params);\n runInAction(() => {\n this.entry = null;\n this.loading = false;\n });\n } catch {\n runInAction(() => {\n this.loading = false;\n });\n }\n }\n\n public reset(): void {\n this.entry = null;\n this.loading = false;\n }\n}\n"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,WAAW,QAAQ,MAAM;AACtD,SAASC,kBAAkB;AAuB3B,OAAO,MAAMC,uBAAuB,CAAqC;EAC7DC,OAAO,GAAG,KAAK;EACfC,KAAK,GAA0B,IAAI;EAOpCC,WAAWA,CAACC,MAAsC,EAAE;IACvD,IAAI,CAACC,UAAU,GAAGD,MAAM,CAACC,UAAU;IACnC,IAAI,CAACC,aAAa,GAAGF,MAAM,CAACE,aAAa;IACzC,IAAI,CAACC,cAAc,GAAGH,MAAM,CAACG,cAAc;IAC3C,IAAI,CAACC,gBAAgB,GAAGJ,MAAM,CAACI,gBAAgB;IAC/CX,kBAAkB,CAAC,IAAI,CAAC;EAC5B;EAEA,IAAWY,EAAEA,CAAA,EAAsC;IAC/C,OAAO;MACHR,OAAO,EAAE,IAAI,CAACA,OAAO;MACrBC,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC;EACL;EAEA,MAAaQ,IAAIA,CAACN,MAA0C,EAAiB;IACzE,IAAI,CAACH,OAAO,GAAG,IAAI;IAEnB,IAAI;MACA,MAAMC,KAAK,GAAG,MAAM,IAAI,CAACG,UAAU,CAACM,OAAO,CAACP,MAAM,CAAC;MACnDN,WAAW,CAAC,MAAM;QACd,IAAI,CAACI,KAAK,GAAGA,KAAK;QAClB,IAAI,CAACD,OAAO,GAAG,KAAK;MACxB,CAAC,CAAC;IACN,CAAC,CAAC,MAAM;MACJH,WAAW,CAAC,MAAM;QACd,IAAI,CAACG,OAAO,GAAG,KAAK;MACxB,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G,IAAI;IACjB,IAAI,CAACD,OAAO,GAAG,KAAK;EACxB;AACJ","ignoreList":[]}
@@ -1,2 +1 @@
1
- export * from "./ScheduleDialogAction.js";
2
1
  export * from "./useScheduleDialog.js";
@@ -1,4 +1,3 @@
1
- export * from "./ScheduleDialogAction.js";
2
1
  export * from "./useScheduleDialog.js";
3
2
 
4
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./ScheduleDialogAction.js\";\nexport * from \"./useScheduleDialog.js\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./useScheduleDialog.js\";\n"],"mappings":"AAAA","ignoreList":[]}
@@ -1,8 +1,7 @@
1
1
  import React from "react";
2
2
  import { type BindComponentRenderProp } from "@webiny/form";
3
- import type { CmsContentEntryStatusType } from "@webiny/app-headless-cms-common/types/index.js";
4
3
  import ApolloClient from "apollo-client/ApolloClient.js";
5
- export type ShowDialogParamsEntryStatus = CmsContentEntryStatusType;
4
+ export type ShowDialogParamsEntryStatus = "published" | "unpublished" | "draft" | string;
6
5
  export interface IShowDialogParamsEntry {
7
6
  id: string;
8
7
  status: ShowDialogParamsEntryStatus;
@@ -7,12 +7,11 @@ import { validation } from "@webiny/validation";
7
7
  import { ScheduleActionType } from "../../../types.js";
8
8
  import ValidationError from "@webiny/validation/validationError.js";
9
9
  import { makeDecoratable } from "@webiny/react-composition";
10
- import { ScheduleDialogAction } from "../../index.js";
11
10
  import { SchedulerCancelGraphQLGateway } from "../../../Gateways/SchedulerCancelGraphQLGateway.js";
12
11
  import { SchedulerPublishGraphQLGateway } from "../../../Gateways/SchedulerPublishGraphQLGateway.js";
13
12
  import { SchedulerUnpublishGraphQLGateway } from "../../../Gateways/SchedulerUnpublishGraphQLGateway.js";
14
- import { useGetScheduledAction } from "./useGetScheduledAction.js";
15
13
  import { SchedulerGetGraphQLGateway } from "../../../Gateways/SchedulerGetGraphQLGateway.js";
14
+ import { ScheduleDialogPresenter } from "./ScheduleDialogPresenter.js";
16
15
  const dateToLocaleStringFormatter = new Intl.DateTimeFormat(undefined, {
17
16
  year: "numeric",
18
17
  month: "2-digit",
@@ -120,24 +119,14 @@ export const useScheduleDialog = props => {
120
119
  const {
121
120
  showSnackbar
122
121
  } = useSnackbar();
123
- const action = useMemo(() => {
124
- const cancelGateway = new SchedulerCancelGraphQLGateway(client);
125
- const publishGateway = new SchedulerPublishGraphQLGateway(client);
126
- const unpublishGateway = new SchedulerUnpublishGraphQLGateway(client);
127
- return new ScheduleDialogAction({
128
- cancelGateway,
129
- publishGateway,
130
- unpublishGateway
122
+ const presenter = useMemo(() => {
123
+ return new ScheduleDialogPresenter({
124
+ getGateway: new SchedulerGetGraphQLGateway(client),
125
+ cancelGateway: new SchedulerCancelGraphQLGateway(client),
126
+ publishGateway: new SchedulerPublishGraphQLGateway(client),
127
+ unpublishGateway: new SchedulerUnpublishGraphQLGateway(client)
131
128
  });
132
129
  }, [client]);
133
- const getGateway = useMemo(() => {
134
- return new SchedulerGetGraphQLGateway(client);
135
- }, [client]);
136
- const schedulerEntry = useGetScheduledAction({
137
- gateway: getGateway,
138
- namespace,
139
- id: target.id
140
- });
141
130
  const dialogClose = useRef(() => {
142
131
  return;
143
132
  });
@@ -147,7 +136,7 @@ export const useScheduleDialog = props => {
147
136
  actionType
148
137
  } = params;
149
138
  try {
150
- await action.schedule({
139
+ await presenter.schedule({
151
140
  targetId: target.id,
152
141
  namespace,
153
142
  scheduleOn,
@@ -158,9 +147,10 @@ export const useScheduleDialog = props => {
158
147
  showSnackbar(error.message);
159
148
  console.error(error);
160
149
  }
161
- }, []);
150
+ }, [presenter.vm]);
162
151
  const onCancel = useCallback(async () => {
163
- if (!schedulerEntry) {
152
+ const entry = presenter.vm.entry;
153
+ if (!entry) {
164
154
  showSnackbar(`No scheduled action found for "${target.title}"!`);
165
155
  if (dialogClose.current) {
166
156
  dialogClose.current();
@@ -169,11 +159,11 @@ export const useScheduleDialog = props => {
169
159
  return;
170
160
  }
171
161
  try {
172
- await action.cancel({
173
- id: schedulerEntry.id,
174
- namespace: schedulerEntry.namespace
162
+ await presenter.cancel({
163
+ id: entry.id,
164
+ namespace: entry.namespace
175
165
  });
176
- showSnackbar(`Canceled scheduled ${schedulerEntry.actionType} on "${schedulerEntry.title}"!`);
166
+ showSnackbar(`Canceled scheduled ${entry.actionType} on "${entry.title}"!`);
177
167
  } catch (error) {
178
168
  showSnackbar(error.message);
179
169
  }
@@ -182,14 +172,19 @@ export const useScheduleDialog = props => {
182
172
  }
183
173
  dialogClose.current();
184
174
  dialogClose.current = null;
185
- }, [schedulerEntry?.id]);
186
- const showDialog = () => {
175
+ }, [presenter.vm]);
176
+ const showDialog = async () => {
177
+ await presenter.load({
178
+ namespace,
179
+ id: target.id
180
+ });
187
181
  const isPublished = target.status === "published";
188
- const scheduleOn = schedulerEntry?.publishOn || schedulerEntry?.unpublishOn;
182
+ const entry = presenter.vm.entry;
183
+ const scheduleOn = entry?.publishOn || entry?.unpublishOn;
189
184
  dialogClose.current = dialog.showDialog({
190
185
  title: `Schedule "${target.title}"`,
191
186
  content: /*#__PURE__*/React.createElement(FormComponent, {
192
- actionType: schedulerEntry?.actionType,
187
+ actionType: entry?.actionType,
193
188
  scheduleOn: scheduleOn
194
189
  }),
195
190
  formData: {
@@ -1 +1 @@
1
- {"version":3,"names":["React","useCallback","useMemo","useRef","Alert","Button","Grid","Input","ReactComponent","DeleteIcon","useDialogs","useSnackbar","Bind","validation","ScheduleActionType","ValidationError","makeDecoratable","ScheduleDialogAction","SchedulerCancelGraphQLGateway","SchedulerPublishGraphQLGateway","SchedulerUnpublishGraphQLGateway","useGetScheduledAction","SchedulerGetGraphQLGateway","dateToLocaleStringFormatter","Intl","DateTimeFormat","undefined","year","month","day","hour","minute","second","hour12","ReschedulingAlert","scheduleOn","actionType","actionName","publish","createElement","type","Fragment","format","padLeft","num","String","padStart","formatDateForDateTimeLocal","date","Date","getFullYear","getMonth","getDate","hours","getHours","minutes","getMinutes","minDateValidator","input","value","minDate","getTime","validatorName","CancelButtonComponent","enabled","onCancel","variant","onClick","text","size","icon","iconPosition","SchedulerDialogFormComponentDateTimeInput","props","bind","Object","assign","title","label","required","autoFocus","FormComponent","Column","span","name","validators","create","useScheduleDialog","client","target","namespace","dialog","showSnackbar","action","cancelGateway","publishGateway","unpublishGateway","getGateway","schedulerEntry","gateway","id","dialogClose","onAccept","params","schedule","targetId","error","message","console","current","cancel","showDialog","isPublished","status","publishOn","unpublishOn","content","formData","acceptLabel","cancelLabel","loadingLabel","info","data","ex","unpublish"],"sources":["useScheduleDialog.tsx"],"sourcesContent":["import React, { useCallback, useMemo, useRef } from \"react\";\nimport { Alert, Button, Grid, Input } from \"@webiny/admin-ui\";\nimport { ReactComponent as DeleteIcon } from \"@webiny/icons/delete.svg\";\nimport { useDialogs, useSnackbar } from \"@webiny/app-admin\";\nimport { Bind, type BindComponentRenderProp } from \"@webiny/form\";\nimport { validation } from \"@webiny/validation\";\nimport { ScheduleActionType } from \"~/types.js\";\nimport type { CmsContentEntryStatusType } from \"@webiny/app-headless-cms-common/types/index.js\";\nimport type { Validator } from \"@webiny/validation/types.js\";\nimport ValidationError from \"@webiny/validation/validationError.js\";\nimport { makeDecoratable } from \"@webiny/react-composition\";\nimport ApolloClient from \"apollo-client/ApolloClient.js\";\nimport { ScheduleDialogAction } from \"~/Presentation/index.js\";\nimport { SchedulerCancelGraphQLGateway } from \"~/Gateways/SchedulerCancelGraphQLGateway.js\";\nimport { SchedulerPublishGraphQLGateway } from \"~/Gateways/SchedulerPublishGraphQLGateway.js\";\nimport { SchedulerUnpublishGraphQLGateway } from \"~/Gateways/SchedulerUnpublishGraphQLGateway.js\";\nimport { useGetScheduledAction } from \"~/Presentation/components/ScheduleDialog/useGetScheduledAction.js\";\nimport { SchedulerGetGraphQLGateway } from \"~/Gateways/SchedulerGetGraphQLGateway.js\";\n\nexport type ShowDialogParamsEntryStatus = CmsContentEntryStatusType;\n\nexport interface IShowDialogParamsEntry {\n id: string;\n status: ShowDialogParamsEntryStatus;\n title: string;\n}\n\ninterface UseShowScheduleDialogResponse {\n showDialog: () => void;\n}\n\ninterface FormComponentProps {\n scheduleOn: Date | undefined;\n actionType: ScheduleActionType | undefined;\n}\n\nconst dateToLocaleStringFormatter = new Intl.DateTimeFormat(undefined, {\n year: \"numeric\",\n month: \"2-digit\",\n day: \"2-digit\",\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: undefined,\n hour12: false\n});\n\ninterface IReschedulingAlertProps {\n scheduleOn: Date | undefined;\n actionType: ScheduleActionType | undefined;\n}\n\nconst ReschedulingAlert = ({ scheduleOn, actionType }: IReschedulingAlertProps) => {\n if (!scheduleOn || !actionType) {\n return null;\n }\n const actionName = actionType === ScheduleActionType.publish ? \"publish\" : \"unpublish\";\n return (\n <Alert type={\"danger\"}>\n <>\n A {actionName} is already scheduled at\n <br />\n <strong>{dateToLocaleStringFormatter.format(scheduleOn)}</strong>.\n </>\n </Alert>\n );\n};\n/**\n * DO NOT use a library for this!\n */\nconst padLeft = (num: number) => {\n return String(num).padStart(2, \"0\");\n};\n\nconst formatDateForDateTimeLocal = (date?: Date | string): string | undefined => {\n if (!date) {\n return undefined;\n } else if (typeof date === \"string\") {\n date = new Date(date);\n }\n\n const year = date.getFullYear();\n const month = padLeft(date.getMonth() + 1);\n const day = padLeft(date.getDate());\n const hours = padLeft(date.getHours());\n const minutes = padLeft(date.getMinutes());\n\n return `${year}-${month}-${day}T${hours}:${minutes}`;\n};\n\nconst minDateValidator: Validator = (input: string) => {\n const value = new Date(input);\n const minDate = new Date(new Date().getTime() + 120 * 1000);\n if (minDate < value) {\n return;\n }\n throw new ValidationError(\n `The date must be at least 2 minutes in the future. Current minimum date is ${dateToLocaleStringFormatter.format(\n minDate\n )}.`\n );\n};\n\nminDateValidator.validatorName = \"minDateValidator\";\n\nexport interface ISchedulerDialogFormComponentDateTimeInputProps {\n bind: BindComponentRenderProp<Date>;\n}\n\ninterface ICancelButtonComponentProps {\n enabled: boolean;\n onCancel: OnCancelCallable;\n}\nconst CancelButtonComponent = ({ enabled, onCancel }: ICancelButtonComponentProps) => {\n if (!enabled) {\n return null;\n }\n return (\n <Button\n variant=\"ghost\"\n onClick={onCancel}\n text={\"Cancel Schedule\"}\n size=\"md\"\n icon={<DeleteIcon />}\n iconPosition=\"start\"\n />\n );\n};\n\nexport const SchedulerDialogFormComponentDateTimeInput = makeDecoratable(\n \"SchedulerDialogFormComponentDateTimeInput\",\n (props: ISchedulerDialogFormComponentDateTimeInputProps) => {\n const { bind } = props;\n\n return (\n <Input\n {...bind}\n value={formatDateForDateTimeLocal(bind.value)}\n title={\"Schedule On\"}\n label={\"Schedule On\"}\n size={\"lg\"}\n type={\"datetime-local\"}\n required\n autoFocus\n />\n );\n }\n);\n\nconst FormComponent = ({ scheduleOn, actionType }: FormComponentProps) => {\n return (\n <>\n {<ReschedulingAlert actionType={actionType} scheduleOn={scheduleOn} />}\n <Grid>\n <Grid.Column span={12}>\n <Bind\n name={\"scheduleOn\"}\n validators={[validation.create(\"required\"), minDateValidator]}\n >\n {bind => {\n return <SchedulerDialogFormComponentDateTimeInput bind={bind} />;\n }}\n </Bind>\n </Grid.Column>\n </Grid>\n </>\n );\n};\n\ninterface ScheduleFormData {\n scheduleOn?: string;\n}\n\ninterface IOnAcceptParams {\n scheduleOn: Date;\n actionType: ScheduleActionType;\n}\n\ninterface OnCancelCallable {\n (): Promise<void>;\n}\n\nexport interface IUseScheduleDialogProps {\n client: ApolloClient<object>;\n namespace: string;\n target: IShowDialogParamsEntry;\n}\n\nexport const useScheduleDialog = (\n props: IUseScheduleDialogProps\n): UseShowScheduleDialogResponse => {\n const { client, target, namespace } = props;\n const dialog = useDialogs();\n const { showSnackbar } = useSnackbar();\n\n const action = useMemo(() => {\n const cancelGateway = new SchedulerCancelGraphQLGateway(client);\n const publishGateway = new SchedulerPublishGraphQLGateway(client);\n const unpublishGateway = new SchedulerUnpublishGraphQLGateway(client);\n\n return new ScheduleDialogAction({\n cancelGateway,\n publishGateway,\n unpublishGateway\n });\n }, [client]);\n\n const getGateway = useMemo(() => {\n return new SchedulerGetGraphQLGateway(client);\n }, [client]);\n\n const schedulerEntry = useGetScheduledAction({\n gateway: getGateway,\n namespace,\n id: target.id\n });\n\n const dialogClose = useRef<null | (() => void)>(() => {\n return;\n });\n\n const onAccept = useCallback(async (params: IOnAcceptParams) => {\n const { scheduleOn, actionType } = params;\n\n try {\n await action.schedule({\n targetId: target.id,\n namespace,\n scheduleOn,\n actionType\n });\n showSnackbar(`Scheduled ${actionType} action for \"${target.title}\"!`);\n } catch (error) {\n showSnackbar(error.message);\n console.error(error);\n }\n }, []);\n\n const onCancel = useCallback(async () => {\n if (!schedulerEntry) {\n showSnackbar(`No scheduled action found for \"${target.title}\"!`);\n if (dialogClose.current) {\n dialogClose.current();\n dialogClose.current = null;\n }\n return;\n }\n try {\n await action.cancel({\n id: schedulerEntry.id,\n namespace: schedulerEntry.namespace\n });\n showSnackbar(\n `Canceled scheduled ${schedulerEntry.actionType} on \"${schedulerEntry.title}\"!`\n );\n } catch (error) {\n showSnackbar(error.message);\n }\n if (!dialogClose.current) {\n return;\n }\n dialogClose.current();\n dialogClose.current = null;\n }, [schedulerEntry?.id]);\n\n const showDialog = () => {\n const isPublished = target.status === \"published\";\n const scheduleOn = schedulerEntry?.publishOn || schedulerEntry?.unpublishOn;\n\n dialogClose.current = dialog.showDialog({\n title: `Schedule \"${target.title}\"`,\n content: (\n <FormComponent actionType={schedulerEntry?.actionType} scheduleOn={scheduleOn} />\n ),\n formData: {\n scheduleOn\n },\n acceptLabel: isPublished ? \"Schedule Unpublish\" : \"Schedule Publish\",\n cancelLabel: \"Discard\",\n loadingLabel: \"Scheduling...\",\n info: <CancelButtonComponent enabled={!!scheduleOn} onCancel={onCancel} />,\n onAccept: (data: Partial<ScheduleFormData>) => {\n if (!data.scheduleOn) {\n showSnackbar(`Missing \"Schedule On\" date!`);\n return;\n }\n /**\n * We need to convert scheduleOn from local string to the ISO String (UTC) format.\n * This is important because the date will be stored in the database in UTC format.\n *\n * We display the date (in the UI) in users timezone time.\n */\n let scheduleOn: Date;\n try {\n scheduleOn = new Date(data.scheduleOn);\n } catch (ex) {\n showSnackbar(`Invalid \"Schedule On\" date!`, {\n value: data.scheduleOn\n });\n console.error(ex);\n return;\n }\n\n const actionType = isPublished\n ? ScheduleActionType.unpublish\n : ScheduleActionType.publish;\n\n return onAccept({\n scheduleOn,\n actionType\n });\n }\n });\n };\n\n return {\n showDialog\n };\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAC3D,SAASC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,KAAK,QAAQ,kBAAkB;AAC7D,SAASC,cAAc,IAAIC,UAAU,QAAQ,0BAA0B;AACvE,SAASC,UAAU,EAAEC,WAAW,QAAQ,mBAAmB;AAC3D,SAASC,IAAI,QAAsC,cAAc;AACjE,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,SAASC,kBAAkB;AAG3B,OAAOC,eAAe,MAAM,uCAAuC;AACnE,SAASC,eAAe,QAAQ,2BAA2B;AAE3D,SAASC,oBAAoB;AAC7B,SAASC,6BAA6B;AACtC,SAASC,8BAA8B;AACvC,SAASC,gCAAgC;AACzC,SAASC,qBAAqB;AAC9B,SAASC,0BAA0B;AAmBnC,MAAMC,2BAA2B,GAAG,IAAIC,IAAI,CAACC,cAAc,CAACC,SAAS,EAAE;EACnEC,IAAI,EAAE,SAAS;EACfC,KAAK,EAAE,SAAS;EAChBC,GAAG,EAAE,SAAS;EACdC,IAAI,EAAE,SAAS;EACfC,MAAM,EAAE,SAAS;EACjBC,MAAM,EAAEN,SAAS;EACjBO,MAAM,EAAE;AACZ,CAAC,CAAC;AAOF,MAAMC,iBAAiB,GAAGA,CAAC;EAAEC,UAAU;EAAEC;AAAoC,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AEA;MAAS,CAAE,CAAC;MAC1EqC,QAAQ,EAAGoB,IAA+B,IAAK;QAC3C,IAAI,CAACA,IAAI,CAACvF,UAAU,EAAE;UAClByD,YAAY,CAAC,6BAA6B,CAAC;UAC3C;QACJ;QACA;AAChB;AACA;AACA;AACA;AACA;QACgB,IAAIzD,UAAgB;QACpB,IAAI;UACAA,UAAU,GAAG,IAAIc,IAAI,CAACyE,IAAI,CAACvF,UAAU,CAAC;QAC1C,CAAC,CAAC,OAAOwF,EAAE,EAAE;UACT/B,YAAY,CAAC,6BAA6B,EAAE;YACxCjC,KAAK,EAAE+D,IAAI,CAACvF;UAChB,CAAC,CAAC;UACFyE,OAAO,CAACF,KAAK,CAACiB,EAAE,CAAC;UACjB;QACJ;QAEA,MAAMvF,UAAU,GAAG4E,WAAW,GACxBlG,kBAAkB,CAAC8G,SAAS,GAC5B9G,kBAAkB,CAACwB,OAAO;QAEhC,OAAOgE,QAAQ,CAAC;UACZnE,UAAU;UACVC;QACJ,CAAC,CAAC;MACN;IACJ,CAAC,CAAC;EACN,CAAC;EAED,OAAO;IACH2E;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useCallback","useMemo","useRef","Alert","Button","Grid","Input","ReactComponent","DeleteIcon","useDialogs","useSnackbar","Bind","validation","ScheduleActionType","ValidationError","makeDecoratable","SchedulerCancelGraphQLGateway","SchedulerPublishGraphQLGateway","SchedulerUnpublishGraphQLGateway","SchedulerGetGraphQLGateway","ScheduleDialogPresenter","dateToLocaleStringFormatter","Intl","DateTimeFormat","undefined","year","month","day","hour","minute","second","hour12","ReschedulingAlert","scheduleOn","actionType","actionName","publish","createElement","type","Fragment","format","padLeft","num","String","padStart","formatDateForDateTimeLocal","date","Date","getFullYear","getMonth","getDate","hours","getHours","minutes","getMinutes","minDateValidator","input","value","minDate","getTime","validatorName","CancelButtonComponent","enabled","onCancel","variant","onClick","text","size","icon","iconPosition","SchedulerDialogFormComponentDateTimeInput","props","bind","Object","assign","title","label","required","autoFocus","FormComponent","Column","span","name","validators","create","useScheduleDialog","client","target","namespace","dialog","showSnackbar","presenter","getGateway","cancelGateway","publishGateway","unpublishGateway","dialogClose","onAccept","params","schedule","targetId","id","error","message","console","vm","entry","current","cancel","showDialog","load","isPublished","status","publishOn","unpublishOn","content","formData","acceptLabel","cancelLabel","loadingLabel","info","data","ex","unpublish"],"sources":["useScheduleDialog.tsx"],"sourcesContent":["import React, { useCallback, useMemo, useRef } from \"react\";\nimport { Alert, Button, Grid, Input } from \"@webiny/admin-ui\";\nimport { ReactComponent as DeleteIcon } from \"@webiny/icons/delete.svg\";\nimport { useDialogs, useSnackbar } from \"@webiny/app-admin\";\nimport { Bind, type BindComponentRenderProp } from \"@webiny/form\";\nimport { validation } from \"@webiny/validation\";\nimport { ScheduleActionType } from \"~/types.js\";\nimport type { Validator } from \"@webiny/validation/types.js\";\nimport ValidationError from \"@webiny/validation/validationError.js\";\nimport { makeDecoratable } from \"@webiny/react-composition\";\nimport ApolloClient from \"apollo-client/ApolloClient.js\";\nimport { SchedulerCancelGraphQLGateway } from \"~/Gateways/SchedulerCancelGraphQLGateway.js\";\nimport { SchedulerPublishGraphQLGateway } from \"~/Gateways/SchedulerPublishGraphQLGateway.js\";\nimport { SchedulerUnpublishGraphQLGateway } from \"~/Gateways/SchedulerUnpublishGraphQLGateway.js\";\nimport { SchedulerGetGraphQLGateway } from \"~/Gateways/SchedulerGetGraphQLGateway.js\";\nimport { ScheduleDialogPresenter } from \"./ScheduleDialogPresenter.js\";\n\nexport type ShowDialogParamsEntryStatus = \"published\" | \"unpublished\" | \"draft\" | string;\n\nexport interface IShowDialogParamsEntry {\n id: string;\n status: ShowDialogParamsEntryStatus;\n title: string;\n}\n\ninterface UseShowScheduleDialogResponse {\n showDialog: () => void;\n}\n\ninterface FormComponentProps {\n scheduleOn: Date | undefined;\n actionType: ScheduleActionType | undefined;\n}\n\nconst dateToLocaleStringFormatter = new Intl.DateTimeFormat(undefined, {\n year: \"numeric\",\n month: \"2-digit\",\n day: \"2-digit\",\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: undefined,\n hour12: false\n});\n\ninterface IReschedulingAlertProps {\n scheduleOn: Date | undefined;\n actionType: ScheduleActionType | undefined;\n}\n\nconst ReschedulingAlert = ({ scheduleOn, actionType }: IReschedulingAlertProps) => {\n if (!scheduleOn || !actionType) {\n return null;\n }\n const actionName = actionType === ScheduleActionType.publish ? \"publish\" : \"unpublish\";\n return (\n <Alert type={\"danger\"}>\n <>\n A {actionName} is already scheduled at\n <br />\n <strong>{dateToLocaleStringFormatter.format(scheduleOn)}</strong>.\n </>\n </Alert>\n );\n};\n/**\n * DO NOT use a library for this!\n */\nconst padLeft = (num: number) => {\n return String(num).padStart(2, \"0\");\n};\n\nconst formatDateForDateTimeLocal = (date?: Date | string): string | undefined => {\n if (!date) {\n return undefined;\n } else if (typeof date === \"string\") {\n date = new Date(date);\n }\n\n const year = date.getFullYear();\n const month = padLeft(date.getMonth() + 1);\n const day = padLeft(date.getDate());\n const hours = padLeft(date.getHours());\n const minutes = padLeft(date.getMinutes());\n\n return `${year}-${month}-${day}T${hours}:${minutes}`;\n};\n\nconst minDateValidator: Validator = (input: string) => {\n const value = new Date(input);\n const minDate = new Date(new Date().getTime() + 120 * 1000);\n if (minDate < value) {\n return;\n }\n throw new ValidationError(\n `The date must be at least 2 minutes in the future. Current minimum date is ${dateToLocaleStringFormatter.format(\n minDate\n )}.`\n );\n};\n\nminDateValidator.validatorName = \"minDateValidator\";\n\nexport interface ISchedulerDialogFormComponentDateTimeInputProps {\n bind: BindComponentRenderProp<Date>;\n}\n\ninterface ICancelButtonComponentProps {\n enabled: boolean;\n onCancel: OnCancelCallable;\n}\nconst CancelButtonComponent = ({ enabled, onCancel }: ICancelButtonComponentProps) => {\n if (!enabled) {\n return null;\n }\n return (\n <Button\n variant=\"ghost\"\n onClick={onCancel}\n text={\"Cancel Schedule\"}\n size=\"md\"\n icon={<DeleteIcon />}\n iconPosition=\"start\"\n />\n );\n};\n\nexport const SchedulerDialogFormComponentDateTimeInput = makeDecoratable(\n \"SchedulerDialogFormComponentDateTimeInput\",\n (props: ISchedulerDialogFormComponentDateTimeInputProps) => {\n const { bind } = props;\n\n return (\n <Input\n {...bind}\n value={formatDateForDateTimeLocal(bind.value)}\n title={\"Schedule On\"}\n label={\"Schedule On\"}\n size={\"lg\"}\n type={\"datetime-local\"}\n required\n autoFocus\n />\n );\n }\n);\n\nconst FormComponent = ({ scheduleOn, actionType }: FormComponentProps) => {\n return (\n <>\n {<ReschedulingAlert actionType={actionType} scheduleOn={scheduleOn} />}\n <Grid>\n <Grid.Column span={12}>\n <Bind\n name={\"scheduleOn\"}\n validators={[validation.create(\"required\"), minDateValidator]}\n >\n {bind => {\n return <SchedulerDialogFormComponentDateTimeInput bind={bind} />;\n }}\n </Bind>\n </Grid.Column>\n </Grid>\n </>\n );\n};\n\ninterface ScheduleFormData {\n scheduleOn?: string;\n}\n\ninterface IOnAcceptParams {\n scheduleOn: Date;\n actionType: ScheduleActionType;\n}\n\ninterface OnCancelCallable {\n (): Promise<void>;\n}\n\nexport interface IUseScheduleDialogProps {\n client: ApolloClient<object>;\n namespace: string;\n target: IShowDialogParamsEntry;\n}\n\nexport const useScheduleDialog = (\n props: IUseScheduleDialogProps\n): UseShowScheduleDialogResponse => {\n const { client, target, namespace } = props;\n const dialog = useDialogs();\n const { showSnackbar } = useSnackbar();\n\n const presenter = useMemo(() => {\n return new ScheduleDialogPresenter({\n getGateway: new SchedulerGetGraphQLGateway(client),\n cancelGateway: new SchedulerCancelGraphQLGateway(client),\n publishGateway: new SchedulerPublishGraphQLGateway(client),\n unpublishGateway: new SchedulerUnpublishGraphQLGateway(client)\n });\n }, [client]);\n\n const dialogClose = useRef<null | (() => void)>(() => {\n return;\n });\n\n const onAccept = useCallback(\n async (params: IOnAcceptParams) => {\n const { scheduleOn, actionType } = params;\n\n try {\n await presenter.schedule({\n targetId: target.id,\n namespace,\n scheduleOn,\n actionType\n });\n showSnackbar(`Scheduled ${actionType} action for \"${target.title}\"!`);\n } catch (error) {\n showSnackbar(error.message);\n console.error(error);\n }\n },\n [presenter.vm]\n );\n\n const onCancel = useCallback(async () => {\n const entry = presenter.vm.entry;\n if (!entry) {\n showSnackbar(`No scheduled action found for \"${target.title}\"!`);\n if (dialogClose.current) {\n dialogClose.current();\n dialogClose.current = null;\n }\n return;\n }\n try {\n await presenter.cancel({\n id: entry.id,\n namespace: entry.namespace\n });\n showSnackbar(`Canceled scheduled ${entry.actionType} on \"${entry.title}\"!`);\n } catch (error) {\n showSnackbar(error.message);\n }\n if (!dialogClose.current) {\n return;\n }\n dialogClose.current();\n dialogClose.current = null;\n }, [presenter.vm]);\n\n const showDialog = async () => {\n await presenter.load({ namespace, id: target.id });\n\n const isPublished = target.status === \"published\";\n const entry = presenter.vm.entry;\n const scheduleOn = entry?.publishOn || entry?.unpublishOn;\n\n dialogClose.current = dialog.showDialog({\n title: `Schedule \"${target.title}\"`,\n content: <FormComponent actionType={entry?.actionType} scheduleOn={scheduleOn} />,\n formData: {\n scheduleOn\n },\n acceptLabel: isPublished ? \"Schedule Unpublish\" : \"Schedule Publish\",\n cancelLabel: \"Discard\",\n loadingLabel: \"Scheduling...\",\n info: <CancelButtonComponent enabled={!!scheduleOn} onCancel={onCancel} />,\n onAccept: (data: Partial<ScheduleFormData>) => {\n if (!data.scheduleOn) {\n showSnackbar(`Missing \"Schedule On\" date!`);\n return;\n }\n /**\n * We need to convert scheduleOn from local string to the ISO String (UTC) format.\n * This is important because the date will be stored in the database in UTC format.\n *\n * We display the date (in the UI) in users timezone time.\n */\n let scheduleOn: Date;\n try {\n scheduleOn = new Date(data.scheduleOn);\n } catch (ex) {\n showSnackbar(`Invalid \"Schedule On\" date!`, {\n value: data.scheduleOn\n });\n console.error(ex);\n return;\n }\n\n const actionType = isPublished\n ? ScheduleActionType.unpublish\n : ScheduleActionType.publish;\n\n return onAccept({\n scheduleOn,\n actionType\n });\n }\n });\n };\n\n return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E,OAAO,CAACF,KAAK,CAACoB,EAAE,CAAC;UACjB;QACJ;QAEA,MAAMxF,UAAU,GAAG6E,WAAW,GACxBlG,kBAAkB,CAAC8G,SAAS,GAC5B9G,kBAAkB,CAACuB,OAAO;QAEhC,OAAO6D,QAAQ,CAAC;UACZhE,UAAU;UACVC;QACJ,CAAC,CAAC;MACN;IACJ,CAAC,CAAC;EACN,CAAC;EAED,OAAO;IACH2E;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/app-scheduler",
3
- "version": "6.1.0-beta.3",
3
+ "version": "6.2.0-beta.0",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -13,32 +13,31 @@
13
13
  "@emotion/react": "11.14.0",
14
14
  "@emotion/styled": "11.14.1",
15
15
  "@material-design-icons/svg": "0.14.15",
16
- "@webiny/admin-ui": "6.1.0-beta.3",
17
- "@webiny/app-aco": "6.1.0-beta.3",
18
- "@webiny/app-admin": "6.1.0-beta.3",
19
- "@webiny/app-headless-cms-common": "6.1.0-beta.3",
20
- "@webiny/app-utils": "6.1.0-beta.3",
21
- "@webiny/form": "6.1.0-beta.3",
22
- "@webiny/icons": "6.1.0-beta.3",
23
- "@webiny/react-composition": "6.1.0-beta.3",
24
- "@webiny/react-properties": "6.1.0-beta.3",
25
- "@webiny/ui": "6.1.0-beta.3",
26
- "@webiny/utils": "6.1.0-beta.3",
27
- "@webiny/validation": "6.1.0-beta.3",
16
+ "@webiny/admin-ui": "6.2.0-beta.0",
17
+ "@webiny/app-aco": "6.2.0-beta.0",
18
+ "@webiny/app-admin": "6.2.0-beta.0",
19
+ "@webiny/app-headless-cms-common": "6.2.0-beta.0",
20
+ "@webiny/app-utils": "6.2.0-beta.0",
21
+ "@webiny/form": "6.2.0-beta.0",
22
+ "@webiny/icons": "6.2.0-beta.0",
23
+ "@webiny/react-composition": "6.2.0-beta.0",
24
+ "@webiny/react-properties": "6.2.0-beta.0",
25
+ "@webiny/ui": "6.2.0-beta.0",
26
+ "@webiny/utils": "6.2.0-beta.0",
27
+ "@webiny/validation": "6.2.0-beta.0",
28
28
  "apollo-client": "2.6.10",
29
29
  "graphql-tag": "2.12.6",
30
- "lodash": "4.17.23",
30
+ "lodash": "4.18.1",
31
31
  "mobx": "6.15.0",
32
32
  "mobx-react-lite": "4.1.1",
33
- "prop-types": "15.8.1",
34
- "react": "18.2.0",
35
- "react-dom": "18.2.0",
33
+ "react": "18.3.1",
34
+ "react-dom": "18.3.1",
36
35
  "zod": "4.3.6"
37
36
  },
38
37
  "devDependencies": {
39
38
  "@emotion/babel-plugin": "11.13.5",
40
- "@types/react": "18.2.79",
41
- "@webiny/build-tools": "6.1.0-beta.3",
39
+ "@types/react": "18.3.28",
40
+ "@webiny/build-tools": "6.2.0-beta.0",
42
41
  "rimraf": "6.1.3",
43
42
  "typescript": "5.9.3"
44
43
  },
@@ -51,5 +50,5 @@
51
50
  "removeViewBox": false
52
51
  }
53
52
  },
54
- "gitHead": "65e0ac1889b3392c99b8cac6cde508e1e831c715"
53
+ "gitHead": "3d3148358b6febbc857371930871743bec3b3939"
55
54
  }
@@ -1,15 +0,0 @@
1
- import type { ICancelScheduledActionGateway, ISchedulePublishActionGateway, IScheduleUnpublishActionGateway } from "../../../Gateways/index.js";
2
- import type { IScheduleDialogAction, IScheduleDialogCancelActionExecuteParams, IScheduleDialogScheduledActionExecuteParams } from "./types.js";
3
- export interface IScheduleDialogActionParams {
4
- cancelGateway: ICancelScheduledActionGateway;
5
- publishGateway: ISchedulePublishActionGateway;
6
- unpublishGateway: IScheduleUnpublishActionGateway;
7
- }
8
- export declare class ScheduleDialogAction implements IScheduleDialogAction {
9
- readonly cancelGateway: ICancelScheduledActionGateway;
10
- readonly publishGateway: ISchedulePublishActionGateway;
11
- readonly unpublishGateway: IScheduleUnpublishActionGateway;
12
- constructor(params: IScheduleDialogActionParams);
13
- schedule(params: IScheduleDialogScheduledActionExecuteParams): Promise<void>;
14
- cancel(params: IScheduleDialogCancelActionExecuteParams): Promise<void>;
15
- }
@@ -1,51 +0,0 @@
1
- import { ScheduleActionType } from "../../../types.js";
2
- export class ScheduleDialogAction {
3
- constructor(params) {
4
- const {
5
- publishGateway,
6
- unpublishGateway,
7
- cancelGateway
8
- } = params;
9
- this.cancelGateway = cancelGateway;
10
- this.publishGateway = publishGateway;
11
- this.unpublishGateway = unpublishGateway;
12
- }
13
- async schedule(params) {
14
- const {
15
- targetId,
16
- namespace,
17
- actionType,
18
- scheduleOn
19
- } = params;
20
- switch (actionType) {
21
- case ScheduleActionType.publish:
22
- await this.publishGateway.execute({
23
- namespace,
24
- targetId,
25
- scheduleOn
26
- });
27
- return;
28
- case ScheduleActionType.unpublish:
29
- await this.unpublishGateway.execute({
30
- namespace,
31
- targetId,
32
- scheduleOn
33
- });
34
- return;
35
- default:
36
- throw new Error(`Unsupported schedule type "${actionType}" for target "${targetId}" and namespace "${namespace}".`);
37
- }
38
- }
39
- async cancel(params) {
40
- const {
41
- id,
42
- namespace
43
- } = params;
44
- await this.cancelGateway.execute({
45
- namespace,
46
- id
47
- });
48
- }
49
- }
50
-
51
- //# sourceMappingURL=ScheduleDialogAction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["ScheduleActionType","ScheduleDialogAction","constructor","params","publishGateway","unpublishGateway","cancelGateway","schedule","targetId","namespace","actionType","scheduleOn","publish","execute","unpublish","Error","cancel","id"],"sources":["ScheduleDialogAction.ts"],"sourcesContent":["import { ScheduleActionType } from \"~/types.js\";\nimport type {\n ICancelScheduledActionGateway,\n ISchedulePublishActionGateway,\n IScheduleUnpublishActionGateway\n} from \"~/Gateways/index.js\";\nimport type {\n IScheduleDialogAction,\n IScheduleDialogCancelActionExecuteParams,\n IScheduleDialogScheduledActionExecuteParams\n} from \"./types.js\";\n\nexport interface IScheduleDialogActionParams {\n cancelGateway: ICancelScheduledActionGateway;\n publishGateway: ISchedulePublishActionGateway;\n unpublishGateway: IScheduleUnpublishActionGateway;\n}\n\nexport class ScheduleDialogAction implements IScheduleDialogAction {\n public readonly cancelGateway: ICancelScheduledActionGateway;\n public readonly publishGateway: ISchedulePublishActionGateway;\n public readonly unpublishGateway: IScheduleUnpublishActionGateway;\n\n public constructor(params: IScheduleDialogActionParams) {\n const { publishGateway, unpublishGateway, cancelGateway } = params;\n\n this.cancelGateway = cancelGateway;\n this.publishGateway = publishGateway;\n this.unpublishGateway = unpublishGateway;\n }\n\n public async schedule(params: IScheduleDialogScheduledActionExecuteParams): Promise<void> {\n const { targetId, namespace, actionType, scheduleOn } = params;\n\n switch (actionType) {\n case ScheduleActionType.publish:\n await this.publishGateway.execute({\n namespace,\n targetId,\n scheduleOn\n });\n return;\n case ScheduleActionType.unpublish:\n await this.unpublishGateway.execute({\n namespace,\n targetId,\n scheduleOn\n });\n return;\n default:\n throw new Error(\n `Unsupported schedule type \"${actionType}\" for target \"${targetId}\" and namespace \"${namespace}\".`\n );\n }\n }\n\n public async cancel(params: IScheduleDialogCancelActionExecuteParams): Promise<void> {\n const { id, namespace } = params;\n await this.cancelGateway.execute({\n namespace,\n id\n });\n }\n}\n"],"mappings":"AAAA,SAASA,kBAAkB;AAkB3B,OAAO,MAAMC,oBAAoB,CAAkC;EAKxDC,WAAWA,CAACC,MAAmC,EAAE;IACpD,MAAM;MAAEC,cAAc;MAAEC,gBAAgB;MAAEC;IAAc,CAAC,GAAGH,MAAM;IAElE,IAAI,CAACG,aAAa,GAAGA,aAAa;IAClC,IAAI,CAACF,cAAc,GAAGA,cAAc;IACpC,IAAI,CAACC,gBAAgB,GAAGA,gBAAgB;EAC5C;EAEA,MAAaE,QAAQA,CAACJ,MAAmD,EAAiB;IACtF,MAAM;MAAEK,QAAQ;MAAEC,SAAS;MAAEC,UAAU;MAAEC;IAAW,CAAC,GAAGR,MAAM;IAE9D,QAAQO,UAAU;MACd,KAAKV,kBAAkB,CAACY,OAAO;QAC3B,MAAM,IAAI,CAACR,cAAc,CAACS,OAAO,CAAC;UAC9BJ,SAAS;UACTD,QAAQ;UACRG;QACJ,CAAC,CAAC;QACF;MACJ,KAAKX,kBAAkB,CAACc,SAAS;QAC7B,MAAM,IAAI,CAACT,gBAAgB,CAACQ,OAAO,CAAC;UAChCJ,SAAS;UACTD,QAAQ;UACRG;QACJ,CAAC,CAAC;QACF;MACJ;QACI,MAAM,IAAII,KAAK,CACX,8BAA8BL,UAAU,iBAAiBF,QAAQ,oBAAoBC,SAAS,IAClG,CAAC;IACT;EACJ;EAEA,MAAaO,MAAMA,CAACb,MAAgD,EAAiB;IACjF,MAAM;MAAEc,EAAE;MAAER;IAAU,CAAC,GAAGN,MAAM;IAChC,MAAM,IAAI,CAACG,aAAa,CAACO,OAAO,CAAC;MAC7BJ,SAAS;MACTQ;IACJ,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
@@ -1,7 +0,0 @@
1
- import type { IGetScheduledActionGateway, IGetScheduledActionGatewayResponse } from "../../../Gateways/index.js";
2
- export interface IGetScheduledActionParams {
3
- namespace: string;
4
- id: string;
5
- gateway: IGetScheduledActionGateway;
6
- }
7
- export declare const useGetScheduledAction: (params: IGetScheduledActionParams) => IGetScheduledActionGatewayResponse | null;
@@ -1,31 +0,0 @@
1
- import { useEffect, useState } from "react";
2
- import { useSnackbar } from "@webiny/app-admin";
3
- export const useGetScheduledAction = params => {
4
- const {
5
- gateway,
6
- namespace,
7
- id
8
- } = params;
9
- const {
10
- showSnackbar
11
- } = useSnackbar();
12
- const [response, setResponse] = useState(null);
13
- useEffect(() => {
14
- const fetchData = async () => {
15
- try {
16
- const data = await gateway.execute({
17
- namespace,
18
- id
19
- });
20
- setResponse(data);
21
- } catch (err) {
22
- console.error(err);
23
- showSnackbar(err.message);
24
- }
25
- };
26
- fetchData();
27
- }, []);
28
- return response;
29
- };
30
-
31
- //# sourceMappingURL=useGetScheduledAction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useEffect","useState","useSnackbar","useGetScheduledAction","params","gateway","namespace","id","showSnackbar","response","setResponse","fetchData","data","execute","err","console","error","message"],"sources":["useGetScheduledAction.ts"],"sourcesContent":["import type {\n IGetScheduledActionGateway,\n IGetScheduledActionGatewayResponse\n} from \"~/Gateways/index.js\";\nimport { useEffect, useState } from \"react\";\nimport { useSnackbar } from \"@webiny/app-admin\";\n\nexport interface IGetScheduledActionParams {\n namespace: string;\n id: string;\n gateway: IGetScheduledActionGateway;\n}\n\nexport const useGetScheduledAction = (\n params: IGetScheduledActionParams\n): IGetScheduledActionGatewayResponse | null => {\n const { gateway, namespace, id } = params;\n\n const { showSnackbar } = useSnackbar();\n\n const [response, setResponse] = useState<IGetScheduledActionGatewayResponse | null>(null);\n\n useEffect(() => {\n const fetchData = async () => {\n try {\n const data = await gateway.execute({\n namespace,\n id\n });\n setResponse(data);\n } catch (err) {\n console.error(err);\n showSnackbar(err.message);\n }\n };\n fetchData();\n }, []);\n\n return response;\n};\n"],"mappings":"AAIA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,WAAW,QAAQ,mBAAmB;AAQ/C,OAAO,MAAMC,qBAAqB,GAC9BC,MAAiC,IACW;EAC5C,MAAM;IAAEC,OAAO;IAAEC,SAAS;IAAEC;EAAG,CAAC,GAAGH,MAAM;EAEzC,MAAM;IAAEI;EAAa,CAAC,GAAGN,WAAW,CAAC,CAAC;EAEtC,MAAM,CAACO,QAAQ,EAAEC,WAAW,CAAC,GAAGT,QAAQ,CAA4C,IAAI,CAAC;EAEzFD,SAAS,CAAC,MAAM;IACZ,MAAMW,SAAS,GAAG,MAAAA,CAAA,KAAY;MAC1B,IAAI;QACA,MAAMC,IAAI,GAAG,MAAMP,OAAO,CAACQ,OAAO,CAAC;UAC/BP,SAAS;UACTC;QACJ,CAAC,CAAC;QACFG,WAAW,CAACE,IAAI,CAAC;MACrB,CAAC,CAAC,OAAOE,GAAG,EAAE;QACVC,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC;QAClBN,YAAY,CAACM,GAAG,CAACG,OAAO,CAAC;MAC7B;IACJ,CAAC;IACDN,SAAS,CAAC,CAAC;EACf,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOF,QAAQ;AACnB,CAAC","ignoreList":[]}