1
1
import { message } from "antd" ;
2
2
import { ActionConfig , ActionExecuteParams } from "../types" ;
3
3
import ApplicationApi from "api/applicationApi" ;
4
- import { getApplicationIdInReducer } from "comps/utils/reduceContext" ;
5
4
import { executeQueryAction } from "lowcoder-core" ;
6
5
import { getPromiseAfterDispatch } from "util/promiseUtils" ;
7
6
import { runScript } from "../utils" ;
8
-
7
+ import { updateAppPermissionInfo } from "redux/reduxActions/applicationActions" ;
8
+ import { reduxStore } from "redux/store/store" ;
9
9
10
10
export const configureAppMetaAction : ActionConfig = {
11
11
key : 'configure-app-meta' ,
@@ -56,10 +56,12 @@ export const publishAppAction: ActionConfig = {
56
56
label : 'Publish app' ,
57
57
category : 'app-configuration' ,
58
58
requiresInput : false ,
59
- execute : async ( ) => {
59
+ execute : async ( params : ActionExecuteParams ) => {
60
+ const { editorState } = params ;
61
+ const applicationIdEditor = editorState . rootComp . preloadId ;
62
+ const applicationId = applicationIdEditor . replace ( 'app-' , '' ) ;
63
+
60
64
try {
61
- const applicationId = getApplicationIdInReducer ( ) ;
62
-
63
65
if ( ! applicationId ) {
64
66
message . error ( 'Application ID not found' ) ;
65
67
return ;
@@ -86,9 +88,50 @@ export const shareAppAction: ActionConfig = {
86
88
label : 'Share app' ,
87
89
category : 'app-configuration' ,
88
90
requiresInput : false ,
89
- execute : async ( ) => {
90
- // TODO: Implement share app
91
- console . log ( 'Share app' ) ;
91
+ execute : async ( params : ActionExecuteParams ) => {
92
+ // TODO: Get app sharing from the user
93
+ const appSharing = {
94
+ public : true ,
95
+ publishMarketplace : false
96
+ }
97
+
98
+ const { editorState } = params ;
99
+ const applicationIdEditor = editorState . rootComp . preloadId ;
100
+ const applicationId = applicationIdEditor . replace ( 'app-' , '' ) ;
101
+
102
+ if ( ! applicationId ) {
103
+ message . error ( 'Application ID not found' ) ;
104
+ return ;
105
+ }
106
+
107
+ try {
108
+ // Update Application Sharig Status
109
+ // Update Redux state to reflect the public change in UI
110
+ const publicResponse = await ApplicationApi . publicToAll ( applicationId , appSharing . public ) ;
111
+
112
+ if ( publicResponse . data . success ) {
113
+ reduxStore . dispatch ( updateAppPermissionInfo ( { publicToAll : appSharing . public } ) ) ;
114
+ message . success ( 'Application is now public!' ) ;
115
+
116
+ // Update Application Marketplace Sharing Status
117
+ try {
118
+ const marketplaceResponse = await ApplicationApi . publicToMarketplace ( applicationId , appSharing . publishMarketplace ) ;
119
+ if ( marketplaceResponse . data . success ) {
120
+ reduxStore . dispatch ( updateAppPermissionInfo ( { publicToMarketplace : appSharing . publishMarketplace } ) ) ;
121
+ message . success ( `Application ${ appSharing . publishMarketplace ? 'published to' : 'unpublished from' } marketplace successfully!` ) ;
122
+ }
123
+ } catch ( marketplaceError ) {
124
+ console . error ( `Error ${ appSharing . publishMarketplace ? 'publishing to' : 'unpublishing from' } marketplace:` , marketplaceError ) ;
125
+ message . warning ( `Application is public but ${ appSharing . publishMarketplace ? 'publishing to' : 'unpublishing from' } marketplace failed` ) ;
126
+ }
127
+
128
+ } else {
129
+ message . error ( 'Failed to make application public' ) ;
130
+ }
131
+ } catch ( publicError ) {
132
+ console . error ( 'Error making application public:' , publicError ) ;
133
+ message . error ( 'Failed to make application public' ) ;
134
+ }
92
135
}
93
136
} ;
94
137
0 commit comments